diff --git a/src/logic/Windows.swift b/src/logic/Windows.swift index 7e5368e9..cf9f07bc 100644 --- a/src/logic/Windows.swift +++ b/src/logic/Windows.swift @@ -94,10 +94,10 @@ class Windows { return targetIndex } - static func moveFocusedWindowIndexAfterWindowDestroyedInBackground(_ destroyedWindowIndex: Int) { - if focusedWindowIndex > destroyedWindowIndex { + static func moveFocusedWindowIndexAfterWindowDestroyedInBackground(_ window: Window) { + if focusedWindowIndex > window.lastFocusOrder { cycleFocusedWindowIndex(-1) - } else if focusedWindowIndex == destroyedWindowIndex && !focusedWindow()!.shouldShowTheUser { + } else if focusedWindowIndex == window.lastFocusOrder && !window.shouldShowTheUser { cycleFocusedWindowIndex(1) } } diff --git a/src/logic/events/AccessibilityEvents.swift b/src/logic/events/AccessibilityEvents.swift index d5d4a4aa..01fb90df 100644 --- a/src/logic/events/AccessibilityEvents.swift +++ b/src/logic/events/AccessibilityEvents.swift @@ -151,7 +151,7 @@ private func windowDestroyed(_ element: AXUIElement) throws { Windows.removeAndUpdateFocus(window) let windowlessApp = window.application.addWindowslessAppsIfNeeded() if Windows.list.count > 0 { - Windows.moveFocusedWindowIndexAfterWindowDestroyedInBackground(window.lastFocusOrder) + Windows.moveFocusedWindowIndexAfterWindowDestroyedInBackground(window) App.app.refreshOpenUi(windowlessApp) } else { App.app.hideUi()