From f74667074b252283609893d783af29e305f793d3 Mon Sep 17 00:00:00 2001 From: LGUG2Z Date: Sat, 31 Oct 2026 15:10:53 -0700 Subject: [PATCH] fix(mac): a clone of a Window being dropped does not deregister it BEHAVIOUR (registry only; the reaper notification that Window::drop already sends is the pre-existing behaviour and is untouched). Review finding 2. Window::drop runs for every clone, including the one State::from makes of each window on every command and event notification, and alive() is false for any failed Accessibility call (a busy or launching app, a modal animation). The registry forget that the registry revision put there therefore made a transient failure drop the entry of a live, managed window. It was redundant with the places that really know a window is gone (reap_window, and forget_pid when an application quits), so it is removed and a comment says why. Test (Mac): registering a window and dropping a clone of it leaves the entry. Verified: macOS fake-CC type-check (tools/fast-check) PASS. Not verified: any run. Verified on the Mini: not yet. Hand check: H7, and H3 (kill -STOP an app, focus around it: its windows must stay managed). --- komorebi-for-mac/komorebi/src/ax_registry.rs | 21 ++++++++++++++++++++ komorebi-for-mac/komorebi/src/window.rs | 11 +++++----- 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/komorebi-for-mac/komorebi/src/ax_registry.rs b/komorebi-for-mac/komorebi/src/ax_registry.rs index 0c9f1e4a..bd1a057e 100644 --- a/komorebi-for-mac/komorebi/src/ax_registry.rs +++ b/komorebi-for-mac/komorebi/src/ax_registry.rs @@ -153,3 +153,24 @@ mod tests { forget(0x5102); } } + +#[cfg(test)] +mod drop_tests { + use super::*; + + /// `State::from` clones every window on every command and event notification; whatever a + /// clone's drop finds out about the window (the stand-in element answers differently with and + /// without Accessibility permission), the entry of a window that was not reaped stays. + #[test] + fn dropping_a_clone_does_not_deregister_a_window() { + let mut window = Window::from(0x5201); + window.application.process_id = 6_200_001; + register(&window); + + drop(window.clone()); + + assert!(get(WindowId::from_u32(0x5201)).is_ok()); + + forget(0x5201); + } +} diff --git a/komorebi-for-mac/komorebi/src/window.rs b/komorebi-for-mac/komorebi/src/window.rs index c3788456..7d1dd991 100644 --- a/komorebi-for-mac/komorebi/src/window.rs +++ b/komorebi-for-mac/komorebi/src/window.rs @@ -475,8 +475,10 @@ impl Drop for Window { // for now - hopefully it doesn't break anything else reaper::send_notification(ReaperNotification::InvalidWindow(self.id)); - // and the id no longer names anything - crate::ax_registry::forget(self.id); + // the registry is not told here: `alive()` is false for any failed Accessibility call, and + // this runs for every clone (State::from makes one of each window on every command), so a + // window that answered badly once would lose its entry; the places that know a window + // is gone (the reaper, an application quitting) forget it // make sure the observer gets removed from any run loops AccessibilityApi::invalidate_observer(&self.observer); @@ -636,10 +638,7 @@ impl Window { /// Prefer [`Window::hide_on`] when the display is known, since a window that hangs over the /// edge of a display is not always on the display that the lookup by position finds. #[tracing::instrument(skip_all)] - pub fn hide( - &self, - hiding_position: WindowHidingPosition, - ) -> Result<(), AccessibilityError> { + pub fn hide(&self, hiding_position: WindowHidingPosition) -> Result<(), AccessibilityError> { self.hide_on(hiding_position, None) }