From 281b3ed45bc61d83e531fb5e12943a3684347246 Mon Sep 17 00:00:00 2001 From: Louis Pontoise Date: Mon, 31 Oct 2022 21:37:49 +0100 Subject: [PATCH] fix: wrong focus after active app becomes windowless (closes #2065) --- src/logic/events/AccessibilityEvents.swift | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) 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)