install_top_level_focus_restore_hook

Function install_top_level_focus_restore_hook 

Source
pub(crate) unsafe fn install_top_level_focus_restore_hook(hwnd: *mut c_void)
Expand description

Subclass a top-level window’s WndProc to handle WM_ACTIVATE: when the window is being activated (wparam != WA_INACTIVE), look up the last intentionally-focused child for this root in LAST_FOCUSED_BY_ROOT and SetFocus it. Closes the alt-tab-back-and-input-drops bug.

Spec: docs/specs/SPEC_WINDOW_REACTIVATE_FOCUS_RESTORE_2026_05_23.md §5.1.3.

SAFE on the main CEF Views window: this hook ONLY observes WM_ACTIVATE and ALWAYS passes the message through to the original WndProc. No message is short-circuited. That is the crucial difference from install_frameless_resize_hook, which returns early for WM_NCCALCSIZE / WM_NCACTIVATE and so MUST NOT be installed on main.

Idempotent: re-calling on an already-hooked HWND is a no-op.