33using System . Linq ;
44using System . Windows ;
55using System . Windows . Input ;
6+ using ChefKeys ;
67using Flow . Launcher . Core . Resource ;
78using Flow . Launcher . Helper ;
89using Flow . Launcher . Infrastructure . Hotkey ;
@@ -33,6 +34,8 @@ public enum EResultType
3334 public string ResultValue { get ; private set ; } = string . Empty ;
3435 public static string EmptyHotkey => InternationalizationManager . Instance . GetTranslation ( "none" ) ;
3536
37+ private static bool isOpenFlowHotkey ;
38+
3639 public HotkeyControlDialog ( string hotkey , string defaultHotkey , IHotkeySettings hotkeySettings , string windowTitle = "" )
3740 {
3841 WindowTitle = windowTitle switch
@@ -46,6 +49,14 @@ public HotkeyControlDialog(string hotkey, string defaultHotkey, IHotkeySettings
4649 SetKeysToDisplay ( CurrentHotkey ) ;
4750
4851 InitializeComponent ( ) ;
52+
53+ // TODO: This is a temporary way to enforce changing only the open flow hotkey to Win, and will be removed by PR #3157
54+ isOpenFlowHotkey = _hotkeySettings . RegisteredHotkeys
55+ . Any ( x => x . DescriptionResourceKey == "flowlauncherHotkey"
56+ && x . Hotkey . ToString ( ) == hotkey ) ;
57+
58+ ChefKeysManager . StartMenuEnableBlocking = true ;
59+ ChefKeysManager . Start ( ) ;
4960 }
5061
5162 private void Reset ( object sender , RoutedEventArgs routedEventArgs )
@@ -61,12 +72,18 @@ private void Delete(object sender, RoutedEventArgs routedEventArgs)
6172
6273 private void Cancel ( object sender , RoutedEventArgs routedEventArgs )
6374 {
75+ ChefKeysManager . StartMenuEnableBlocking = false ;
76+ ChefKeysManager . Stop ( ) ;
77+
6478 ResultType = EResultType . Cancel ;
6579 Hide ( ) ;
6680 }
6781
6882 private void Save ( object sender , RoutedEventArgs routedEventArgs )
6983 {
84+ ChefKeysManager . StartMenuEnableBlocking = false ;
85+ ChefKeysManager . Stop ( ) ;
86+
7087 if ( KeysToDisplay . Count == 1 && KeysToDisplay [ 0 ] == EmptyHotkey )
7188 {
7289 ResultType = EResultType . Delete ;
@@ -85,6 +102,9 @@ private void OnPreviewKeyDown(object sender, KeyEventArgs e)
85102 //when alt is pressed, the real key should be e.SystemKey
86103 Key key = e . Key == Key . System ? e . SystemKey : e . Key ;
87104
105+ if ( ChefKeysManager . StartMenuBlocked && key . ToString ( ) == ChefKeysManager . StartMenuSimulatedKey )
106+ return ;
107+
88108 SpecialKeyState specialKeyState = GlobalHotkey . CheckModifiers ( ) ;
89109
90110 var hotkeyModel = new HotkeyModel (
@@ -168,8 +188,13 @@ private void SetKeysToDisplay(HotkeyModel? hotkey)
168188 }
169189 }
170190
171- private static bool CheckHotkeyAvailability ( HotkeyModel hotkey , bool validateKeyGesture ) =>
172- hotkey . Validate ( validateKeyGesture ) && HotKeyMapper . CheckAvailability ( hotkey ) ;
191+ private static bool CheckHotkeyAvailability ( HotkeyModel hotkey , bool validateKeyGesture )
192+ {
193+ if ( isOpenFlowHotkey && ( hotkey . ToString ( ) == "LWin" || hotkey . ToString ( ) == "RWin" ) )
194+ return true ;
195+
196+ return hotkey . Validate ( validateKeyGesture ) && HotKeyMapper . CheckAvailability ( hotkey ) ;
197+ }
173198
174199 private void Overwrite ( object sender , RoutedEventArgs e )
175200 {
0 commit comments