mirror of
https://github.com/Flow-Launcher/Flow.Launcher.git
synced 2026-03-11 08:54:32 +00:00
Add doc comments and additional error handling in keyboard layout switch logic
This commit is contained in:
parent
48aff32f1b
commit
4df42a0f63
1 changed files with 16 additions and 1 deletions
|
|
@ -350,7 +350,11 @@ namespace Flow.Launcher.Infrastructure
|
|||
var handles = new HKL[count];
|
||||
fixed (HKL* h = handles)
|
||||
{
|
||||
_ = PInvoke.GetKeyboardLayoutList(count, h);
|
||||
var result = PInvoke.GetKeyboardLayoutList(count, h);
|
||||
if (result != 0)
|
||||
{
|
||||
throw new Win32Exception(Marshal.GetLastWin32Error());
|
||||
}
|
||||
}
|
||||
|
||||
// Look for any English keyboard layout
|
||||
|
|
@ -369,6 +373,11 @@ namespace Flow.Launcher.Infrastructure
|
|||
return HKL.Null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Switches the keyboard layout to English if available.
|
||||
/// </summary>
|
||||
/// <param name="backupPrevious">If true, the current keyboard layout will be stored for later restoration.</param>
|
||||
/// <exception cref="Win32Exception">Thrown when there's an error getting the window thread process ID.</exception>
|
||||
public static unsafe void SwitchToEnglishKeyboardLayout(bool backupPrevious)
|
||||
{
|
||||
// Find an installed English layout
|
||||
|
|
@ -401,11 +410,17 @@ namespace Flow.Launcher.Infrastructure
|
|||
PInvoke.ActivateKeyboardLayout(enHKL, 0);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Restores the previously backed-up keyboard layout.
|
||||
/// If it wasn't backed up or has already been restored, this method does nothing.
|
||||
/// </summary>
|
||||
public static void RestorePreviousKeyboardLayout()
|
||||
{
|
||||
if (_previousLayout == HKL.Null) return;
|
||||
|
||||
var hwnd = PInvoke.GetForegroundWindow();
|
||||
if (hwnd == HWND.Null) return;
|
||||
|
||||
PInvoke.PostMessage(
|
||||
hwnd,
|
||||
PInvoke.WM_INPUTLANGCHANGEREQUEST,
|
||||
|
|
|
|||
Loading…
Reference in a new issue