mirror of
https://github.com/lwouis/alt-tab-macos.git
synced 2026-05-24 11:20:36 +00:00
fix: selected thumbnail was sometimes wrong (closes #926)
This commit is contained in:
@@ -192,7 +192,6 @@ extension pid_t {
|
||||
// we compare a fresh call to get the windows (currentWindows) to the windows we have already (Windows.list)
|
||||
// any window not in currentWindows is considered tabbed
|
||||
private func updateTabs(_ currentWindows: [AXUIElement]?) -> [Window] {
|
||||
debugPrint(try? Windows.list.map { w in (w.cgWindowId, w.title, w.spaceId == Spaces.currentSpaceId, try currentWindows?.map { try $0.cgWindowId() }) })
|
||||
let windows = Windows.list.filter { w in
|
||||
if w.application.pid == self && self != ProcessInfo.processInfo.processIdentifier &&
|
||||
w.spaceId == Spaces.currentSpaceId {
|
||||
|
||||
@@ -53,7 +53,7 @@ class Applications {
|
||||
// comparing pid here can fail here, as it can be already nil; we use isEqual here to avoid the issue
|
||||
Applications.list.removeAll { $0.runningApplication.isEqual(runningApp) }
|
||||
Windows.list.enumerated().forEach { (index, window) in
|
||||
if window.application.runningApplication.isEqual(runningApp) && index < Windows.focusedWindowIndex {
|
||||
if window.application.runningApplication.isEqual(runningApp) && index < Windows.focusedWindowIndex && window.shouldShowTheUser {
|
||||
windowsOnTheLeftOfFocusedWindow += 1
|
||||
}
|
||||
}
|
||||
|
||||
+12
-4
@@ -100,11 +100,19 @@ class Windows {
|
||||
return targetIndex
|
||||
}
|
||||
|
||||
static func moveFocusedWindowIndexAfterWindowDestroyedInBackground(_ window: Window) {
|
||||
if focusedWindowIndex > window.lastFocusOrder {
|
||||
static func moveFocusedWindowIndexAfterWindowDestroyedInBackground(_ index: Int) {
|
||||
if index < focusedWindowIndex {
|
||||
cycleFocusedWindowIndex(-1)
|
||||
}
|
||||
}
|
||||
|
||||
static func updateFocusedWindowIndex() {
|
||||
if let focusedWindow = focusedWindow() {
|
||||
if !focusedWindow.shouldShowTheUser {
|
||||
cycleFocusedWindowIndex(windowIndexAfterCycling(1) > focusedWindowIndex ? 1 : -1)
|
||||
}
|
||||
} else {
|
||||
cycleFocusedWindowIndex(-1)
|
||||
} else if focusedWindowIndex == window.lastFocusOrder && !window.shouldShowTheUser {
|
||||
cycleFocusedWindowIndex(1)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -129,13 +129,14 @@ fileprivate func focusedWindowChanged(_ element: AXUIElement, _ pid: pid_t) thro
|
||||
fileprivate func windowDestroyed(_ element: AXUIElement, _ pid: pid_t) throws {
|
||||
let wid = try element.cgWindowId()
|
||||
DispatchQueue.main.async {
|
||||
if let window = (Windows.list.first { $0.isEqualRobust(element, wid) }) {
|
||||
if let index = (Windows.list.firstIndex { $0.isEqualRobust(element, wid) }) {
|
||||
let window = Windows.list[index]
|
||||
Windows.removeAndUpdateFocus(window)
|
||||
let windowlessApp = window.application.addWindowslessAppsIfNeeded()
|
||||
if Windows.list.count > 0 {
|
||||
// closing a tab may make another tab visible; we refresh tab status
|
||||
pid.retryToRefreshTabsUntilScreenIsNotAnimating { windows in
|
||||
Windows.moveFocusedWindowIndexAfterWindowDestroyedInBackground(window)
|
||||
Windows.moveFocusedWindowIndexAfterWindowDestroyedInBackground(index)
|
||||
if let windowlessApp = windowlessApp {
|
||||
App.app.refreshOpenUi(windows + windowlessApp)
|
||||
} else {
|
||||
|
||||
+7
-8
@@ -206,8 +206,13 @@ class App: AppCenterApplication, NSApplicationDelegate {
|
||||
// workaround: when Preferences > Mission Control > "Displays have separate Spaces" is unchecked,
|
||||
// switching between displays doesn't trigger .activeSpaceDidChangeNotification; we get the latest manually
|
||||
Spaces.refreshCurrentSpaceId()
|
||||
Windows.reorderList()
|
||||
Spaces.refreshAllIdsAndIndexes()
|
||||
guard appIsBeingUsed else { return }
|
||||
refreshSpecificWindows(windowsToUpdate, currentScreen)
|
||||
if (!Windows.list.contains { $0.shouldShowTheUser }) { hideUi(); return }
|
||||
guard appIsBeingUsed else { return }
|
||||
Windows.reorderList()
|
||||
Windows.updateFocusedWindowIndex()
|
||||
guard appIsBeingUsed else { return }
|
||||
thumbnailsPanel.thumbnailsView.updateItemsAndLayout(currentScreen)
|
||||
guard appIsBeingUsed else { return }
|
||||
@@ -222,13 +227,7 @@ class App: AppCenterApplication, NSApplicationDelegate {
|
||||
guard appIsBeingUsed else { return }
|
||||
window.refreshThumbnail()
|
||||
Windows.refreshIfWindowShouldBeShownToTheUser(window, currentScreen)
|
||||
if !window.shouldShowTheUser && window.cgWindowId == Windows.focusedWindow()!.cgWindowId {
|
||||
let stepWithClosestWindow = Windows.windowIndexAfterCycling(-1) > Windows.focusedWindowIndex ? 1 : -1
|
||||
Windows.cycleFocusedWindowIndex(stepWithClosestWindow)
|
||||
} else {
|
||||
Spaces.refreshAllIdsAndIndexes()
|
||||
window.updatesWindowSpace()
|
||||
}
|
||||
window.updatesWindowSpace()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user