Skip to content

Commit

Permalink
fix(windows): Use SetForegroundWindow before focus hack (#719)
Browse files Browse the repository at this point in the history
  • Loading branch information
FabianLars authored Apr 3, 2023
1 parent 226756f commit 62db431
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changes/fix-windows-focus.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'tao': 'patch'
---

Fix set_focus not working on Windows in some situations like interactive notifications.
9 changes: 6 additions & 3 deletions src/platform_impl/windows/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1266,10 +1266,13 @@ unsafe fn taskbar_mark_fullscreen(handle: HWND, fullscreen: bool) {
}

unsafe fn force_window_active(handle: HWND) {
// In some situation, calling SetForegroundWindow could not bring up the window,
// This is a little hack which can "steal" the foreground window permission
// Try to focus the window without the hack first.
SetForegroundWindow(handle);

// In some situations, calling SetForegroundWindow could not bring up the window,
// This is a little hack which can "steal" the foreground window permission.
// We only call this function in the window creation, so it should be fine.
// See : https://stackoverflow.com/questions/10740346/setforegroundwindow-only-working-while-visual-studio-is-open
// See: https://stackoverflow.com/questions/10740346/setforegroundwindow-only-working-while-visual-studio-is-open
let alt_sc = MapVirtualKeyW(u32::from(VK_MENU.0), MAPVK_VK_TO_VSC);

let mut inputs: [INPUT; 2] = mem::zeroed();
Expand Down

0 comments on commit 62db431

Please sign in to comment.