LAST_FOCUSED_BY_ROOT

Static LAST_FOCUSED_BY_ROOT 

Source
pub static LAST_FOCUSED_BY_ROOT: LazyLock<Mutex<HashMap<usize, usize>>>
Expand description

Per-top-level-window record of the last child HWND to receive intentional keyboard focus — written by the pane subclass when an allowed-through WM_SETFOCUS lands and by MainFocusReclaimTask after its SetFocus on the main render widget. Programmatic pane focus that the redirect intercepts is NOT recorded — only paths the user actually intends.

Keyed by GetAncestor(child, GA_ROOT). AgentMux runs multiple top-level windows in one process (primary "main" plus pool / sub-windows — see state::list_browsers); a single global slot would let WM_ACTIVATE on window A read window B’s child and SetFocus the wrong one. See spec §4.5 for the empirical evidence (docs/specs/SPEC_WINDOW_REACTIVATE_FOCUS_RESTORE_2026_05_23.md).

Mutex (not RwLock): writes are rare (per intentional focus event), reads rarer still (per top-level WM_ACTIVATE). Contention is negligible.

Stale entries (child HWND destroyed) self-heal: the activate handler re-validates via IsWindow before calling SetFocus.