Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Moved hotkey handling to main window and fixed a possible crash. #178

Merged
merged 1 commit into from
Sep 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -2509,6 +2511,15 @@
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 2520 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 2520 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 2520 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 2520 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 @@ -2521,6 +2532,11 @@
OverlayWindow_ToggleClickTrough();
}

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

public void OverlayWindow_ToggleClickTrough()
{
overlayWindowsAreClickTrough = !overlayWindowsAreClickTrough;
Expand All @@ -2533,6 +2549,17 @@
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 @@ -270,7 +268,7 @@

private int overlayDepth = 8;
private Dictionary<LocalCharacter, OverlaySystemData> currentPlayersSystemData = new ();
private OverlaySystemData currentPlayerSystemData;

Check warning on line 271 in SMT/Overlay.xaml.cs

View workflow job for this annotation

GitHub Actions / build

The field 'Overlay.currentPlayerSystemData' is never used

Check warning on line 271 in SMT/Overlay.xaml.cs

View workflow job for this annotation

GitHub Actions / build

The field 'Overlay.currentPlayerSystemData' is never used

Check warning on line 271 in SMT/Overlay.xaml.cs

View workflow job for this annotation

GitHub Actions / build

The field 'Overlay.currentPlayerSystemData' is never used

Check warning on line 271 in SMT/Overlay.xaml.cs

View workflow job for this annotation

GitHub Actions / build

The field 'Overlay.currentPlayerSystemData' is never used
private OverlayCanvasData canvasData = new OverlayCanvasData();

private float intelUrgentPeriod = 300;
Expand Down Expand Up @@ -407,9 +405,6 @@
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 @@
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
Loading