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