mirror of
https://github.com/LGUG2Z/komorebi.git
synced 2026-11-17 22:33:12 +01:00
fix(mac): register a window when its observer is attached, not when it is constructed
BEHAVIOUR (what is registered, and when; nothing reads the registry yet except the unused MacosBackend). Review findings 1 (cost) and 6 (wrong observer). Window::new created a fresh AXObserver and registered the window each time, so one event registered up to three constructions on the event thread under the window manager lock (the attach-check, the re-check and the managed one), each replacing the last, and the managed window's attached observer (the one window.observe put on the run loop) was replaced by the third throwaway's unattached one; window_by_title at start-up made n x n of them for an application with n windows. Registration now happens in Window::observe, after add_observer_to_run_loop succeeded: a Window made only to ask an app something is never observed and never registered, the registry holds the observer that is really attached, and a window is registered once (process_event.rs after should_manage, and macos_api.rs at start-up). The decision is documented in ax_registry.rs in the docs revision of this stack. Verified: macOS fake-CC type-check (tools/fast-check) PASS. Not verified: any run. Verified on the Mini: not yet. Hand checks: H3 (start-up with a many-window app: time to ready), H7 (native tabs).
This commit is contained in:
1 parent
a501c05809
commit
de630fc702
1 file changed
+9
-8
@@ -559,18 +559,13 @@ impl Window {
|
||||
Some(window_observer_callback),
|
||||
)?;
|
||||
|
||||
let window = Self {
|
||||
Ok(Self {
|
||||
id: AccessibilityApi::window_id(&element)?,
|
||||
element: AccessibilityUiElement(element),
|
||||
application,
|
||||
observer: AccessibilityObserver(Some(observer)),
|
||||
details: None,
|
||||
};
|
||||
|
||||
// so that the window can be found again from its id alone
|
||||
crate::ax_registry::register(&window);
|
||||
|
||||
Ok(window)
|
||||
})
|
||||
}
|
||||
|
||||
/// The handles that act on this window, as the registry keeps them
|
||||
@@ -627,7 +622,13 @@ impl Window {
|
||||
NOTIFICATIONS,
|
||||
run_loop,
|
||||
refcon,
|
||||
)
|
||||
)?;
|
||||
|
||||
// the registry holds the window whose observer is attached: a Window that was only made to
|
||||
// ask an app about a window is never observed, so it is never registered
|
||||
crate::ax_registry::register(self);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Hide the window in the corner of the display that it is on
|
||||
|
||||
Reference in new issue
Block a user