From a2e004a5b19da42b0c1e9513d1d56c6930165d70 Mon Sep 17 00:00:00 2001 From: Jeremy Date: Thu, 20 Feb 2025 21:01:37 +1100 Subject: [PATCH 1/5] enable the use of Win hotkey --- .../Hotkey/HotkeyModel.cs | 5 ++- Flow.Launcher/Flow.Launcher.csproj | 1 + Flow.Launcher/Helper/HotKeyMapper.cs | 39 +++++++++++++++++++ Flow.Launcher/HotkeyControlDialog.xaml.cs | 13 +++++++ 4 files changed, 56 insertions(+), 2 deletions(-) diff --git a/Flow.Launcher.Infrastructure/Hotkey/HotkeyModel.cs b/Flow.Launcher.Infrastructure/Hotkey/HotkeyModel.cs index 25bc75a56c1..17d414d82ed 100644 --- a/Flow.Launcher.Infrastructure/Hotkey/HotkeyModel.cs +++ b/Flow.Launcher.Infrastructure/Hotkey/HotkeyModel.cs @@ -167,10 +167,11 @@ public bool Validate(bool validateKeyGestrue = false) case Key.RightCtrl: case Key.LeftShift: case Key.RightShift: - case Key.LWin: - case Key.RWin: case Key.None: return false; + case Key.LWin: + case Key.RWin: + return true; default: if (validateKeyGestrue) { diff --git a/Flow.Launcher/Flow.Launcher.csproj b/Flow.Launcher/Flow.Launcher.csproj index 16228258f5f..2f26017a674 100644 --- a/Flow.Launcher/Flow.Launcher.csproj +++ b/Flow.Launcher/Flow.Launcher.csproj @@ -83,6 +83,7 @@ + all diff --git a/Flow.Launcher/Helper/HotKeyMapper.cs b/Flow.Launcher/Helper/HotKeyMapper.cs index 8b30b8be1f5..64434b49c08 100644 --- a/Flow.Launcher/Helper/HotKeyMapper.cs +++ b/Flow.Launcher/Helper/HotKeyMapper.cs @@ -6,6 +6,8 @@ using Flow.Launcher.Core.Resource; using Flow.Launcher.ViewModel; using Flow.Launcher.Core; +using ChefKeys; +using System.Globalization; namespace Flow.Launcher.Helper; @@ -29,15 +31,40 @@ internal static void OnToggleHotkey(object sender, HotkeyEventArgs args) _mainViewModel.ToggleFlowLauncher(); } + internal static void OnToggleHotkeyWithChefKeys() + { + if (!_mainViewModel.ShouldIgnoreHotkeys()) + _mainViewModel.ToggleFlowLauncher(); + } + private static void SetHotkey(string hotkeyStr, EventHandler action) { + if (hotkeyStr == "LWin" || hotkeyStr == "RWin") + { + SetWithChefKeys(hotkeyStr); + return; + } + var hotkey = new HotkeyModel(hotkeyStr); SetHotkey(hotkey, action); } + private static void SetWithChefKeys(string hotkeyStr) + { + ChefKeysManager.RegisterHotkey(hotkeyStr, hotkeyStr, OnToggleHotkeyWithChefKeys); + ChefKeysManager.Start(); + } + internal static void SetHotkey(HotkeyModel hotkey, EventHandler action) { string hotkeyStr = hotkey.ToString(); + + if (hotkeyStr == "LWin" || hotkeyStr == "RWin") + { + SetWithChefKeys(hotkeyStr); + return; + } + try { HotkeyManager.Current.AddOrReplace(hotkeyStr, hotkey.CharKey, hotkey.ModifierKeys, action); @@ -52,12 +79,24 @@ internal static void SetHotkey(HotkeyModel hotkey, EventHandler internal static void RemoveHotkey(string hotkeyStr) { + if (hotkeyStr == "LWin" || hotkeyStr == "RWin") + { + RemoveWithChefKeys(hotkeyStr); + return; + } + if (!string.IsNullOrEmpty(hotkeyStr)) { HotkeyManager.Current.Remove(hotkeyStr); } } + private static void RemoveWithChefKeys(string hotkeyStr) + { + ChefKeysManager.UnregisterHotkey(hotkeyStr); + ChefKeysManager.Stop(); + } + internal static void LoadCustomPluginHotkey() { if (_settings.CustomPluginHotkeys == null) diff --git a/Flow.Launcher/HotkeyControlDialog.xaml.cs b/Flow.Launcher/HotkeyControlDialog.xaml.cs index a7b99f6704b..bf01419c448 100644 --- a/Flow.Launcher/HotkeyControlDialog.xaml.cs +++ b/Flow.Launcher/HotkeyControlDialog.xaml.cs @@ -3,6 +3,7 @@ using System.Linq; using System.Windows; using System.Windows.Input; +using ChefKeys; using Flow.Launcher.Core.Resource; using Flow.Launcher.Helper; using Flow.Launcher.Infrastructure.Hotkey; @@ -46,6 +47,9 @@ public HotkeyControlDialog(string hotkey, string defaultHotkey, IHotkeySettings SetKeysToDisplay(CurrentHotkey); InitializeComponent(); + + ChefKeysManager.StartMenuEnableBlocking = true; + ChefKeysManager.Start(); } private void Reset(object sender, RoutedEventArgs routedEventArgs) @@ -61,12 +65,18 @@ private void Delete(object sender, RoutedEventArgs routedEventArgs) private void Cancel(object sender, RoutedEventArgs routedEventArgs) { + ChefKeysManager.StartMenuEnableBlocking = false; + ChefKeysManager.Stop(); + ResultType = EResultType.Cancel; Hide(); } private void Save(object sender, RoutedEventArgs routedEventArgs) { + ChefKeysManager.StartMenuEnableBlocking = false; + ChefKeysManager.Stop(); + if (KeysToDisplay.Count == 1 && KeysToDisplay[0] == EmptyHotkey) { ResultType = EResultType.Delete; @@ -85,6 +95,9 @@ private void OnPreviewKeyDown(object sender, KeyEventArgs e) //when alt is pressed, the real key should be e.SystemKey Key key = e.Key == Key.System ? e.SystemKey : e.Key; + if (ChefKeysManager.StartMenuBlocked && key.ToString() == ChefKeysManager.StartMenuSimulatedKey) + return; + SpecialKeyState specialKeyState = GlobalHotkey.CheckModifiers(); var hotkeyModel = new HotkeyModel( From 66a22847933e6707c9dfb6605ea2dca18f49fc6a Mon Sep 17 00:00:00 2001 From: Jeremy Date: Thu, 20 Feb 2025 21:18:08 +1100 Subject: [PATCH 2/5] prevent win key combo --- Flow.Launcher.Infrastructure/Hotkey/HotkeyModel.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Flow.Launcher.Infrastructure/Hotkey/HotkeyModel.cs b/Flow.Launcher.Infrastructure/Hotkey/HotkeyModel.cs index 17d414d82ed..aef89ff5c84 100644 --- a/Flow.Launcher.Infrastructure/Hotkey/HotkeyModel.cs +++ b/Flow.Launcher.Infrastructure/Hotkey/HotkeyModel.cs @@ -169,8 +169,8 @@ public bool Validate(bool validateKeyGestrue = false) case Key.RightShift: case Key.None: return false; - case Key.LWin: - case Key.RWin: + case Key.LWin when ModifierKeys == ModifierKeys.Windows: + case Key.RWin when ModifierKeys == ModifierKeys.Windows: return true; default: if (validateKeyGestrue) From 8c509ea48513aafde9a327801f2b546028395100 Mon Sep 17 00:00:00 2001 From: Jeremy Date: Fri, 21 Feb 2025 18:27:03 +1100 Subject: [PATCH 3/5] restrict to open flow hotkey control only --- .../Hotkey/HotkeyModel.cs | 5 ++--- Flow.Launcher/HotkeyControlDialog.xaml.cs | 15 +++++++++++++-- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/Flow.Launcher.Infrastructure/Hotkey/HotkeyModel.cs b/Flow.Launcher.Infrastructure/Hotkey/HotkeyModel.cs index aef89ff5c84..25bc75a56c1 100644 --- a/Flow.Launcher.Infrastructure/Hotkey/HotkeyModel.cs +++ b/Flow.Launcher.Infrastructure/Hotkey/HotkeyModel.cs @@ -167,11 +167,10 @@ public bool Validate(bool validateKeyGestrue = false) case Key.RightCtrl: case Key.LeftShift: case Key.RightShift: + case Key.LWin: + case Key.RWin: case Key.None: return false; - case Key.LWin when ModifierKeys == ModifierKeys.Windows: - case Key.RWin when ModifierKeys == ModifierKeys.Windows: - return true; default: if (validateKeyGestrue) { diff --git a/Flow.Launcher/HotkeyControlDialog.xaml.cs b/Flow.Launcher/HotkeyControlDialog.xaml.cs index bf01419c448..79d67b6d346 100644 --- a/Flow.Launcher/HotkeyControlDialog.xaml.cs +++ b/Flow.Launcher/HotkeyControlDialog.xaml.cs @@ -34,6 +34,8 @@ public enum EResultType public string ResultValue { get; private set; } = string.Empty; public static string EmptyHotkey => InternationalizationManager.Instance.GetTranslation("none"); + private static bool isOpenFlowHotkey; + public HotkeyControlDialog(string hotkey, string defaultHotkey, IHotkeySettings hotkeySettings, string windowTitle = "") { WindowTitle = windowTitle switch @@ -48,6 +50,10 @@ public HotkeyControlDialog(string hotkey, string defaultHotkey, IHotkeySettings InitializeComponent(); + isOpenFlowHotkey = _hotkeySettings.RegisteredHotkeys + .Any(x => x.DescriptionResourceKey == "flowlauncherHotkey" + && x.Hotkey.ToString() == hotkey); + ChefKeysManager.StartMenuEnableBlocking = true; ChefKeysManager.Start(); } @@ -181,8 +187,13 @@ private void SetKeysToDisplay(HotkeyModel? hotkey) } } - private static bool CheckHotkeyAvailability(HotkeyModel hotkey, bool validateKeyGesture) => - hotkey.Validate(validateKeyGesture) && HotKeyMapper.CheckAvailability(hotkey); + private static bool CheckHotkeyAvailability(HotkeyModel hotkey, bool validateKeyGesture) + { + if (isOpenFlowHotkey && (hotkey.ToString() == "LWin" || hotkey.ToString() == "RWin")) + return true; + + return hotkey.Validate(validateKeyGesture) && HotKeyMapper.CheckAvailability(hotkey); + } private void Overwrite(object sender, RoutedEventArgs e) { From 50bc940c7c25c348ba696ab23892615397d39cb4 Mon Sep 17 00:00:00 2001 From: Jeremy Date: Fri, 21 Feb 2025 19:53:51 +1100 Subject: [PATCH 4/5] validation for open search hotkey --- Flow.Launcher/HotkeyControl.xaml.cs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/Flow.Launcher/HotkeyControl.xaml.cs b/Flow.Launcher/HotkeyControl.xaml.cs index a42bde7c9cd..25fcf3eee51 100644 --- a/Flow.Launcher/HotkeyControl.xaml.cs +++ b/Flow.Launcher/HotkeyControl.xaml.cs @@ -1,4 +1,4 @@ -#nullable enable +#nullable enable using System.Collections.ObjectModel; using System.Threading.Tasks; @@ -154,7 +154,15 @@ private void SetHotkey(HotkeyModel keyModel, bool triggerValidate = true) { if (triggerValidate) { - bool hotkeyAvailable = CheckHotkeyAvailability(keyModel, ValidateKeyGesture); + bool hotkeyAvailable = false; + if (keyModel.ToString() == "LWin" || keyModel.ToString() == "RWin") + { + hotkeyAvailable = true; + } + else + { + hotkeyAvailable = CheckHotkeyAvailability(keyModel, ValidateKeyGesture); + } if (!hotkeyAvailable) { From 5155fdcfdb4f655e1d3820d76f613f08cc6bb31a Mon Sep 17 00:00:00 2001 From: Jeremy Date: Fri, 21 Feb 2025 20:02:27 +1100 Subject: [PATCH 5/5] add comments --- Flow.Launcher/HotkeyControl.xaml.cs | 3 ++- Flow.Launcher/HotkeyControlDialog.xaml.cs | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/Flow.Launcher/HotkeyControl.xaml.cs b/Flow.Launcher/HotkeyControl.xaml.cs index 25fcf3eee51..e1dfc1108ef 100644 --- a/Flow.Launcher/HotkeyControl.xaml.cs +++ b/Flow.Launcher/HotkeyControl.xaml.cs @@ -1,4 +1,4 @@ -#nullable enable +#nullable enable using System.Collections.ObjectModel; using System.Threading.Tasks; @@ -155,6 +155,7 @@ private void SetHotkey(HotkeyModel keyModel, bool triggerValidate = true) if (triggerValidate) { bool hotkeyAvailable = false; + // TODO: This is a temporary way to enforce changing only the open flow hotkey to Win, and will be removed by PR #3157 if (keyModel.ToString() == "LWin" || keyModel.ToString() == "RWin") { hotkeyAvailable = true; diff --git a/Flow.Launcher/HotkeyControlDialog.xaml.cs b/Flow.Launcher/HotkeyControlDialog.xaml.cs index 79d67b6d346..a4d21a7827b 100644 --- a/Flow.Launcher/HotkeyControlDialog.xaml.cs +++ b/Flow.Launcher/HotkeyControlDialog.xaml.cs @@ -50,6 +50,7 @@ public HotkeyControlDialog(string hotkey, string defaultHotkey, IHotkeySettings InitializeComponent(); + // TODO: This is a temporary way to enforce changing only the open flow hotkey to Win, and will be removed by PR #3157 isOpenFlowHotkey = _hotkeySettings.RegisteredHotkeys .Any(x => x.DescriptionResourceKey == "flowlauncherHotkey" && x.Hotkey.ToString() == hotkey);