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).
This commit is contained in:
LGUG2Z committed 2026-11-05 15:03:26 -08:00
1 parent de630fc702
commit f74667074b
2 files changed
+26 -6

No files matched your search

@@ -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);
}
}
+5 -6
View File
@@ -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)
}