diff --git a/.changes/fix-windows-focus.md b/.changes/fix-windows-focus.md new file mode 100644 index 000000000..4ed71b3ff --- /dev/null +++ b/.changes/fix-windows-focus.md @@ -0,0 +1,5 @@ +--- +'tao': 'patch' +--- + +Fix set_focus not working on Windows in some situations like interactive notifications. diff --git a/src/platform_impl/windows/window.rs b/src/platform_impl/windows/window.rs index f18ce43b8..7cc6b3c52 100644 --- a/src/platform_impl/windows/window.rs +++ b/src/platform_impl/windows/window.rs @@ -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();