Expand description
Win32 HWND-level helpers for browser panes: the WM_SETFOCUS redirect
subclass and the focus-bypass flag.
Moved out of client.rs during Phase 2 of the pane modularization split
(see docs/specs/SPEC_BROWSER_PANE_MODULARIZATION.md §6). client.rs
still uses ALLOW_BROWSER_PANE_FOCUS_ONCE at a distance (nothing there imports
the function directly), but install_browser_pane_focus_redirect is the home
for pane-focused Win32 subclass logic and future phases can wire it up
to pane on_after_created / on_load_end without touching client.rs.
Everything in this file is Windows-only by gating.
Structs§
- Browser
Pane 🔒Context - Per-pane context, keyed by the pane’s outer HWND. Populated by
install_browser_pane_focus_redirect. The WndProc hook uses it to emit thebrowser-pane-clickedevent onWM_LBUTTONDOWNwithout needing to round-trip through CEF callbacks — only the outer HWND is keyed here; descendants walk up viaGetParentto find their context.
Statics§
- ALLOW_
BROWSER_ PANE_ FOCUS_ ONCE - When
true, the nextWM_SETFOCUSdelivered to a subclassed pane HWND is allowed through instead of being redirected back to the parent. - BROWSER_
PANE_ 🔒HWND_ CONTEXT - BROWSER_
PANE_ 🔒REDIRECT_ LAST_ AT - Last-redirect timestamp per root HWND, used by
should_redirect_pane_focus_to_rootto rate-limit programmatic focus storms (setInterval-drivenwindow.focus(), OAuth redirector pages, DOM mutation observers re-focusing on every change). Keyed by the root HWND cast tousize. Entries are overwritten on each pass and never explicitly removed — the map is bounded by the count of distinct top-level AgentMux windows seen in a session, which is small. - BROWSER_
PANE_ 🔒WNDPROCS - Map of pane HWND -> original WndProc, so the subclass hook can delegate to the real handler after running its interception logic. The mutex is held only while mutating the map — hooks that read on the UI thread copy out the pointer quickly.
- LAST_
FOCUSED_ BY_ ROOT - 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_SETFOCUSlands and byMainFocusReclaimTaskafter itsSetFocuson the main render widget. Programmatic pane focus that the redirect intercepts is NOT recorded — only paths the user actually intends.
Functions§
- install_
browser_ ⚠pane_ focus_ redirect - Subclass a browser pane’s outer HWND (and every descendant HWND Chromium
has already created) so
WM_SETFOCUSis redirected back to the parent top-level window unless the focus change is user-initiated (seeALLOW_BROWSER_PANE_FOCUS_ONCE). - record_
intentional_ ⚠focus - Single write helper called from both intentional-focus sites (the
pane subclass in this module and
MainFocusReclaimTaskinui_tasks.rs). Resolveschild’s top-level ancestor viaGetAncestor(GA_ROOT)and stores the pair intoLAST_FOCUSED_BY_ROOT. - remove_
contexts_ for_ block - Remove every
BROWSER_PANE_HWND_CONTEXTentry whose context refers to the givenblock_id. Called fromon_before_close_browser_paneso the map doesn’t grow unbounded as panes are opened and closed over the session. Keyed by block_id (not HWND) because the close path has the label/block_id immediately but not the HWND — by the time CEF fires on_before_close, the browser’s HWND may already be invalid. - should_
redirect_ 🔒 ⚠pane_ focus_ to_ root - Returns
trueiff the pane WM_SETFOCUS subclass should redirect torootviaSetFocus(root). Two guards, both motivated by the 2026-05-02 multi-window freeze investigation (docs/specs/SPEC_WINDOW_FLEET_REDUCER_2026-05-02.md):