diff --git a/src/logic/events/AccessibilityEvents.swift b/src/logic/events/AccessibilityEvents.swift index 928ece2f..14d44c99 100644 --- a/src/logic/events/AccessibilityEvents.swift +++ b/src/logic/events/AccessibilityEvents.swift @@ -19,7 +19,7 @@ fileprivate func handleEvent(_ type: String, _ element: AXUIElement) throws { case kAXWindowCreatedNotification: try windowCreated(element, pid) case kAXMainWindowChangedNotification, kAXFocusedWindowChangedNotification: try focusedWindowChanged(element, pid) - case kAXUIElementDestroyedNotification: try windowDestroyed(element) + case kAXUIElementDestroyedNotification: try windowDestroyed(element, pid) case kAXWindowMiniaturizedNotification, kAXWindowDeminiaturizedNotification: try windowMiniaturizedOrDeminiaturized(element, type) case kAXTitleChangedNotification: try windowTitleChanged(element, pid) @@ -130,13 +130,16 @@ fileprivate func focusedWindowChanged(_ element: AXUIElement, _ pid: pid_t) thro } } -fileprivate func windowDestroyed(_ element: AXUIElement) throws { +fileprivate func windowDestroyed(_ element: AXUIElement, _ pid: pid_t) throws { let wid = try element.cgWindowId() DispatchQueue.main.async { if let index = (Windows.list.firstIndex { $0.isEqualRobust(element, wid) }) { let window = Windows.list[index] Windows.removeAndUpdateFocus(window) let windowlessApp = window.application.addWindowslessAppsIfNeeded() + if windowlessApp != nil { + Applications.find(pid)?.focusedWindow = nil + } if Windows.list.count > 0 { Windows.moveFocusedWindowIndexAfterWindowDestroyedInBackground(index) App.app.refreshOpenUi(windowlessApp)