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) }