diff --git a/src/logic/Window.swift b/src/logic/Window.swift index b87441264..2f99abe6c 100644 --- a/src/logic/Window.swift +++ b/src/logic/Window.swift @@ -49,6 +49,7 @@ class Window { refreshThumbnail() } application.removeWindowslessAppWindow() + checkIfFocused(application, wid) debugPrint("Adding window", cgWindowId, title ?? "nil", application.runningApplication.bundleIdentifier ?? "nil") observeEvents() } @@ -64,6 +65,17 @@ class Window { debugPrint("Deinit window", title ?? "nil", application.runningApplication.bundleIdentifier ?? "nil") } + /// some apps will not trigger AXApplicationActivated, where we usually update application.focusedWindow + /// workaround: we check and possibly do it here + func checkIfFocused(_ application: Application, _ wid: CGWindowID) { + retryAxCallUntilTimeout { + let focusedWid = try application.axUiElement?.focusedWindow()?.cgWindowId() + if wid == focusedWid { + application.focusedWindow = self + } + } + } + func isEqualRobust(_ otherWindowAxUiElement: AXUIElement, _ otherWindowWid: CGWindowID?) -> Bool { // the window can be deallocated by the OS, in which case its `CGWindowID` will be `-1` // we check for equality both on the AXUIElement, and the CGWindowID, in order to catch all scenarios diff --git a/src/logic/Windows.swift b/src/logic/Windows.swift index f3c3ab6d5..038c4635b 100644 --- a/src/logic/Windows.swift +++ b/src/logic/Windows.swift @@ -180,8 +180,8 @@ class Windows { static func refreshFirstFewThumbnailsSync() { if Preferences.hideThumbnails { return } list.filter { $0.shouldShowTheUser } - .prefix(criticalFirstThumbnails) - .forEachAsync { window in window.refreshThumbnail() } + .prefix(criticalFirstThumbnails) + .forEachAsync { window in window.refreshThumbnail() } } static func refreshThumbnailsAsync(_ screen: NSScreen, _ currentIndex: Int = criticalFirstThumbnails) {