Skip to content

Commit c63debe

Browse files
committed
Add foreground window check
1 parent 5be88dd commit c63debe

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

Flow.Launcher.Infrastructure/Win32Helper.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -386,8 +386,12 @@ public static unsafe void SwitchToEnglishKeyboardLayout(bool backupPrevious)
386386
// No installed English layout found
387387
if (enHKL == HKL.Null) return;
388388

389-
// Get the current window thread ID
390-
var threadId = PInvoke.GetWindowThreadProcessId(PInvoke.GetForegroundWindow());
389+
// Get the current foreground window
390+
var hwnd = PInvoke.GetForegroundWindow();
391+
if (hwnd == HWND.Null) return;
392+
393+
// Get the current foreground window thread ID
394+
var threadId = PInvoke.GetWindowThreadProcessId(hwnd);
391395
if (threadId == 0) throw new Win32Exception(Marshal.GetLastWin32Error());
392396

393397
// If the current layout has an IME mode, disable it without switching to another layout.

0 commit comments

Comments
 (0)