Skip to content

Commit

Permalink
fix: switcher could select the wrong thumbnail (closes #1198)
Browse files Browse the repository at this point in the history
  • Loading branch information
lwouis committed May 7, 2022
1 parent 7acee37 commit 4c67778
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
12 changes: 12 additions & 0 deletions src/logic/Window.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class Window {
refreshThumbnail()
}
application.removeWindowslessAppWindow()
checkIfFocused(application, wid)
debugPrint("Adding window", cgWindowId, title ?? "nil", application.runningApplication.bundleIdentifier ?? "nil")
observeEvents()
}
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/logic/Windows.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 4c67778

Please sign in to comment.