Skip to content

Commit

Permalink
Merge pull request #178 from EVEJay/master
Browse files Browse the repository at this point in the history
Moved hotkey handling to main window and fixed a possible crash.
  • Loading branch information
Slazanger authored Sep 8, 2024
2 parents e0467ae + cfa3306 commit a687782
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 11 deletions.
27 changes: 27 additions & 0 deletions SMT/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
using System.Xml.Serialization;
using Microsoft.Toolkit.Uwp.Notifications;
using Microsoft.Win32;
using NHotkey;
using NHotkey.Wpf;
using SMT.EVEData;

namespace SMT
Expand Down Expand Up @@ -2546,6 +2548,15 @@ private void OverlayWindow_MenuItem_Click(object sender, RoutedEventArgs e)
return;
}
}

// Set up hotkeys
try
{
HotkeyManager.Current.AddOrReplace("Toggle click trough overlay windows.", Key.T, ModifierKeys.Alt | ModifierKeys.Control | ModifierKeys.Shift, OverlayWindows_ToggleClicktrough_HotkeyTrigger);
}
catch (NHotkey.HotkeyAlreadyRegisteredException exception)

Check warning on line 2557 in SMT/MainWindow.xaml.cs

View workflow job for this annotation

GitHub Actions / build

The variable 'exception' is declared but never used

Check warning on line 2557 in SMT/MainWindow.xaml.cs

View workflow job for this annotation

GitHub Actions / build

The variable 'exception' is declared but never used

Check warning on line 2557 in SMT/MainWindow.xaml.cs

View workflow job for this annotation

GitHub Actions / build

The variable 'exception' is declared but never used

Check warning on line 2557 in SMT/MainWindow.xaml.cs

View workflow job for this annotation

GitHub Actions / build

The variable 'exception' is declared but never used
{
}

Overlay newOverlayWindow = new Overlay(this);
newOverlayWindow.Closing += OnOverlayWindowClosing;
Expand All @@ -2558,6 +2569,11 @@ private void OverlayClickTroughToggle_MenuItem_Click(object sender, RoutedEventA
OverlayWindow_ToggleClickTrough();
}

private void OverlayWindows_ToggleClicktrough_HotkeyTrigger(object sender, HotkeyEventArgs eventArgs)
{
OverlayWindow_ToggleClickTrough();
}

public void OverlayWindow_ToggleClickTrough()
{
overlayWindowsAreClickTrough = !overlayWindowsAreClickTrough;
Expand All @@ -2570,6 +2586,17 @@ public void OverlayWindow_ToggleClickTrough()
public void OnOverlayWindowClosing(object sender, CancelEventArgs e)
{
overlayWindows.Remove((Overlay)sender);

if (overlayWindows.Count < 1)
{
try
{
HotkeyManager.Current.Remove("Toggle click trough overlay windows.");
}
catch
{
}
}
}
}

Expand Down
12 changes: 1 addition & 11 deletions SMT/Overlay.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using NHotkey.Wpf;
using System;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
Expand All @@ -19,7 +18,6 @@
using Windows.Services;
using Microsoft.IdentityModel.Tokens;
using Microsoft.VisualBasic.Logging;
using NHotkey;
using SMT.EVEData;
using static SMT.EVEData.Navigation;

Expand Down Expand Up @@ -407,9 +405,6 @@ public Overlay(MainWindow mw)
Closing += Overlay_Closing;
// We can only redraw stuff when the canvas is actually resized, otherwise dimensions will be wrong!
overlay_Canvas.SizeChanged += OnCanvasSizeChanged;

// Set up hotkeys
HotkeyManager.Current.AddOrReplace("Toggle click trough overlay windows.", Key.T, ModifierKeys.Alt | ModifierKeys.Control | ModifierKeys.Shift, OnClickTroughToggle);

// Update settings
intelUrgentPeriod = mainWindow.MapConf.IntelFreshTime;
Expand Down Expand Up @@ -450,11 +445,6 @@ public Overlay(MainWindow mw)
dataUpdateTimer.Start();
}

private void OnClickTroughToggle(object sender, HotkeyEventArgs e)
{
mainWindow.OverlayWindow_ToggleClickTrough();
}

public void ToggleClickTrough(bool isClickTrough)
{
var hwnd = new WindowInteropHelper(this).Handle;
Expand Down

0 comments on commit a687782

Please sign in to comment.