Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/platform_impl/windows/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ use windows_sys::Win32::{
UI::{
Input::{
KeyboardAndMouse::{
EnableWindow, GetActiveWindow, MapVirtualKeyW, ReleaseCapture, SendInput,
ToUnicode, INPUT, INPUT_0, INPUT_KEYBOARD, KEYBDINPUT, KEYEVENTF_EXTENDEDKEY,
EnableWindow, GetActiveWindow, GetFocus, MapVirtualKeyW, ReleaseCapture,
SendInput, SetFocus, ToUnicode, INPUT, INPUT_0, INPUT_KEYBOARD, KEYBDINPUT, KEYEVENTF_EXTENDEDKEY,
KEYEVENTF_KEYUP, MAPVK_VK_TO_VSC, VIRTUAL_KEY, VK_LMENU, VK_MENU, VK_SPACE,
},
Touch::{RegisterTouchWindow, TWF_WANTPALM},
Expand Down Expand Up @@ -1004,6 +1004,12 @@ impl Window {

if is_visible && !is_minimized && !is_foreground {
unsafe { force_window_active(self.window) };
} else if is_visible && !is_minimized && unsafe { GetFocus() } != self.window {
// The window is in the foreground, but doesn't have keyboard focus. This happens when
// a focused child window, such as an embedded web view, is destroyed: Windows doesn't
// give focus back to the parent, and clicking the already active window doesn't
// either. Taking focus sends `WM_SETFOCUS`, which reports `WindowEvent::Focused`.
unsafe { SetFocus(self.window) };
}
}

Expand Down
Loading