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/HotkeyControl.xaml.cs b/Flow.Launcher/HotkeyControl.xaml.cs index a42bde7c9cd..e1dfc1108ef 100644 --- a/Flow.Launcher/HotkeyControl.xaml.cs +++ b/Flow.Launcher/HotkeyControl.xaml.cs @@ -154,7 +154,16 @@ private void SetHotkey(HotkeyModel keyModel, bool triggerValidate = true) { if (triggerValidate) { - bool hotkeyAvailable = CheckHotkeyAvailability(keyModel, ValidateKeyGesture); + 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; + } + else + { + hotkeyAvailable = CheckHotkeyAvailability(keyModel, ValidateKeyGesture); + } if (!hotkeyAvailable) { diff --git a/Flow.Launcher/HotkeyControlDialog.xaml.cs b/Flow.Launcher/HotkeyControlDialog.xaml.cs index a7b99f6704b..a4d21a7827b 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; @@ -33,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 @@ -46,6 +49,14 @@ public HotkeyControlDialog(string hotkey, string defaultHotkey, IHotkeySettings SetKeysToDisplay(CurrentHotkey); 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); + + ChefKeysManager.StartMenuEnableBlocking = true; + ChefKeysManager.Start(); } private void Reset(object sender, RoutedEventArgs routedEventArgs) @@ -61,12 +72,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 +102,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( @@ -168,8 +188,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) {