From 1d1ec156c595d16d699752c329311ad2da7daf77 Mon Sep 17 00:00:00 2001 From: LGUG2Z Date: Sat, 31 Oct 2026 15:11:11 -0700 Subject: [PATCH] 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. --- komorebi-for-mac/komorebi/src/ax_registry.rs | 22 +++++++++++++++++++ .../komorebi/src/process_event.rs | 14 +++++++++++- 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/komorebi-for-mac/komorebi/src/ax_registry.rs b/komorebi-for-mac/komorebi/src/ax_registry.rs index bd1a057e..2d554ea7 100644 --- a/komorebi-for-mac/komorebi/src/ax_registry.rs +++ b/komorebi-for-mac/komorebi/src/ax_registry.rs @@ -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); + } +} diff --git a/komorebi-for-mac/komorebi/src/process_event.rs b/komorebi-for-mac/komorebi/src/process_event.rs index ba9b57fa..d4844df1 100644 --- a/komorebi-for-mac/komorebi/src/process_event.rs +++ b/komorebi-for-mac/komorebi/src/process_event.rs @@ -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