fix(mac): an application that quit leaves the registry even while paused or on another space

BEHAVIOUR (registry only). Review finding 3.

process_event returned at 'if self.is_paused' and at the space-id mismatch before
reaching the Destroy arm where forget_pid was, so NSWorkspaceDidTerminateApplication
seen while paused (a locked screen pauses, so does toggle-pause) or on another space
was discarded and the entries of that pid stayed for a process that reuses it.
The forget_pid call is now the first thing process_event does for that
notification, with a comment, and the Destroy arm keeps the rest as it was (the
enhanced-UI forget there is pre-existing and not moved). forget_pid takes only
the registry's own lock: it does not take the window manager lock or dispatch to
the main queue.

Test (Mac): forget_pid removes the windows of that pid and no others.

Verified: macOS fake-CC type-check (tools/fast-check) PASS. Not verified: any
run; a WindowManager-level test of the paused case needs the process_command.rs
harness and is left to the Mini. Verified on the Mini: not yet. Hand check: H6.
This commit is contained in:
LGUG2Z committed 2026-11-05 15:03:26 -08:00
1 parent f74667074b
commit 1d1ec156c5
2 files changed
+35 -1

No files matched your search

@@ -174,3 +174,25 @@ mod drop_tests {
forget(0x5201);
}
}
#[cfg(test)]
mod pid_tests {
use super::*;
#[test]
fn an_application_quitting_takes_its_windows_and_no_other() {
let mut quitter = Window::from(0x5301);
quitter.application.process_id = 6_300_001;
let mut stayer = Window::from(0x5302);
stayer.application.process_id = 6_300_002;
register(&quitter);
register(&stayer);
forget_pid(6_300_001);
assert!(get(WindowId::from_u32(0x5301)).is_err());
assert!(get(WindowId::from_u32(0x5302)).is_ok());
forget(0x5302);
}
}
+13 -1
View File
@@ -98,6 +98,19 @@ impl WindowManager {
window_manager_event_listener::resize_step_taken();
}
// an application that quit takes its windows out of the registry whatever else is going on:
// this is ahead of the pause and the other-space returns below, which would otherwise discard
// the notification and leave the entries to be inherited by a process that reuses the pid
if let WindowManagerEvent::Destroy(
SystemNotification::AppKitWorkspace(
AppKitWorkspaceNotification::NSWorkspaceDidTerminateApplicationNotification,
),
process_id,
) = &event
{
crate::ax_registry::forget_pid(*process_id);
}
if matches!(event, WindowManagerEvent::ScreenLock(_, _)) {
let application = self.application(event.process_id())?;
if application.name().unwrap_or_default() == "loginwindow" {
@@ -749,7 +762,6 @@ impl WindowManager {
)
) {
enhanced_ui::forget(process_id);
crate::ax_registry::forget_pid(process_id);
}
// some apps like Discord in all of their relentless Electron slop stupidity