Skip to content

Commit 4146f4d

Browse files
committed
Use focus events to trigger
1 parent c39079b commit 4146f4d

File tree

3 files changed

+18
-10
lines changed

3 files changed

+18
-10
lines changed

Flow.Launcher/MainWindow.xaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,8 @@
242242
InputMethod.PreferredImeState="{Binding StartWithEnglishMode, Converter={StaticResource BoolToIMEStateConverter}}"
243243
PreviewDragOver="QueryTextBox_OnPreviewDragOver"
244244
PreviewKeyUp="QueryTextBox_KeyUp"
245+
GotKeyboardFocus="QueryTextBox_OnGotKeyboardFocus"
246+
PreviewLostKeyboardFocus="QueryTextBox_OnPreviewLostKeyboardFocus"
245247
Style="{DynamicResource QueryBoxStyle}"
246248
Text="{Binding QueryText, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
247249
Visibility="Visible"

Flow.Launcher/MainWindow.xaml.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -989,6 +989,22 @@ private void QueryTextBox_OnPreviewDragOver(object sender, DragEventArgs e)
989989
e.Handled = true;
990990
}
991991

992+
private void QueryTextBox_OnGotKeyboardFocus(object sender, KeyboardFocusChangedEventArgs e)
993+
{
994+
if (_viewModel.StartWithEnglishMode)
995+
{
996+
Win32Helper.SwitchToEnglishKeyboardLayout(true);
997+
}
998+
}
999+
1000+
private void QueryTextBox_OnPreviewLostKeyboardFocus(object sender, KeyboardFocusChangedEventArgs e)
1001+
{
1002+
if (_viewModel.StartWithEnglishMode)
1003+
{
1004+
Win32Helper.RestorePreviousKeyboardLayout();
1005+
}
1006+
}
1007+
9921008
#endregion
9931009
}
9941010
}

Flow.Launcher/ViewModel/MainViewModel.cs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1373,11 +1373,6 @@ public void Show()
13731373
MainWindowOpacity = 1;
13741374
MainWindowVisibilityStatus = true;
13751375
VisibilityChanged?.Invoke(this, new VisibilityChangedEventArgs { IsVisible = true });
1376-
1377-
if (StartWithEnglishMode)
1378-
{
1379-
Win32Helper.SwitchToEnglishKeyboardLayout(true);
1380-
}
13811376
});
13821377
}
13831378

@@ -1447,11 +1442,6 @@ public async void Hide()
14471442
Win32Helper.DWMSetCloakForWindow(mainWindow, true);
14481443
}
14491444

1450-
if (StartWithEnglishMode)
1451-
{
1452-
Win32Helper.RestorePreviousKeyboardLayout();
1453-
}
1454-
14551445
await Task.Delay(50);
14561446

14571447
// Update WPF properties

0 commit comments

Comments
 (0)