Skip to content

Commit 64297c5

Browse files
committed
Remove GlobalHotkey, use LowLevelHotkey
Extend the custom hotkey handling to support this use case. This change has the effect that even system-registered hotkeys can be used from FancyWM, with the FancyWM hotkeys taking precedence.
1 parent ba5629f commit 64297c5

File tree

4 files changed

+10
-171
lines changed

4 files changed

+10
-171
lines changed

FancyWM.Tests/Utilities/GlobalHotkeyTest.cs

Lines changed: 0 additions & 27 deletions
This file was deleted.

FancyWM/MainWindow.xaml.cs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public partial class MainWindow : Window, IDisposable
7979
private bool m_showFocusDuringAction;
8080
private bool m_autoCollapse;
8181
private bool m_notifyVirtualDesktopServiceIncompatibility;
82-
private GlobalHotkey[] m_directHks = [];
82+
private LowLevelHotkey[] m_directHks = [];
8383

8484
#pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.
8585
public MainWindow()
@@ -387,17 +387,21 @@ private void RebindDirectHotkeys(KeybindingDictionary keybindings)
387387
hk.Dispose();
388388
}
389389

390-
var newHotkeys = new List<GlobalHotkey>();
390+
var newHotkeys = new List<LowLevelHotkey>();
391391
var failedHotkeys = new List<Keybinding>();
392392
foreach (var x in keybindings
393393
.Where(x => x.Value?.IsDirectMode == true))
394394
{
395395
try
396396
{
397397
var (modifiers, key) = KeyCodeHelper.GetModifierAndKeyCode(x.Value!.Keys);
398-
var hk = new GlobalHotkey(m_hwnd, modifiers, key);
398+
var hk = new LowLevelHotkey(m_llkbdHook, modifiers, key)
399+
{
400+
HideKeyPress = true,
401+
ScanOnRelease = false,
402+
ClearModifiersOnMiss = false,
403+
};
399404
hk.Pressed += delegate { OnDirectHotkeyPressed(x.Key); };
400-
hk.Register();
401405
newHotkeys.Add(hk);
402406
}
403407
catch (Win32Exception)

FancyWM/Utilities/GlobalHotkey.cs

Lines changed: 0 additions & 139 deletions
This file was deleted.

FancyWM/Utilities/LowLevelHotkey.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ internal class LowLevelHotkey : IDisposable
1515
public KeyCode Key { get; }
1616
public bool ScanOnRelease { get; init; } = false;
1717
public bool HideKeyPress { get; init; } = true;
18+
public bool ClearModifiersOnMiss { get; init; } = false;
1819

1920
private readonly KeyCode[] m_modifiers;
2021
private readonly bool[] m_pressedModifiers;
@@ -62,7 +63,7 @@ bool Scan(ref LowLevelKeyboardHook.KeyStateChangedEventArgs e)
6263
{
6364
m_pressedModifiers[modifierIndex] = true;
6465
}
65-
else if (e.KeyCode != Key)
66+
else if (e.KeyCode != Key && ClearModifiersOnMiss)
6667
{
6768
// A non-modifier, non-main key was pressed, in which case
6869
// we reset the state, to allow other hotkeys to trigger.

0 commit comments

Comments
 (0)