ReadonlyonFires when an individual window's focus state changes. The event payload identifies which window changed and whether it gained or lost focus.
A window losing focus to another application window will fire separately
for each window involved: one event with hasFocus: false for the window
that lost focus, and one with hasFocus: true for the window that gained it.
Protected ReadonlyonProtected ReadonlytoProtected ReadonlywindowPer-window tracking state.
Whether any registered window currently has focus.
ProtectedcancelDispose this object.
ProtectedhandleProtectedinitRegister a window for focus tracking. The returned Disposable removes the window from tracking when disposed.
The main window is registered automatically. Call this for secondary windows when they are created.
ProtectedscheduleSchedule a deferred blur check for this specific window.
If no focus event arrives on this same window before the timeout fires,
we treat it as a real focus loss for that window.
ProtectedupdateRe-evaluate a single window's focus and fire if it changed (latching).
Protectedwindow
Tracks focus state for each registered application window independently.
The main window is registered automatically. Secondary windows should be registered via registerWindow — typically by the service responsible for creating them.
Uses two complementary signals per window for robust detection:
windowfocus/blurevents (OS-level window focus changes)documentvisibilitychangeevents (browser tab switches)Blur events are debounced per window with
setTimeout(0)so that focus moving between elements within the same window does not produce a false blur: the subsequentfocusevent cancels the pending blur before it fires.Each per-window event is latched — it only fires when that window's focus state actually changes.