mirror of
https://github.com/lwouis/alt-tab-macos.git
synced 2026-05-24 11:20:36 +00:00
fix: highlight right thumbnail when no window is focused (closes #1044)
This commit is contained in:
@@ -14,6 +14,7 @@ class Application: NSObject {
|
||||
var dockLabel: String?
|
||||
var pid: pid_t { runningApplication.processIdentifier }
|
||||
var wasLaunchedBeforeAltTab = false
|
||||
var focusedWindow: Window? = nil
|
||||
|
||||
static func notifications(_ app: NSRunningApplication) -> [String] {
|
||||
let n = [
|
||||
|
||||
@@ -24,6 +24,29 @@ class Windows {
|
||||
}
|
||||
}
|
||||
|
||||
static func setInitialFocusedWindowIndex() {
|
||||
if let app = Applications.list.first { $0.pid == NSWorkspace.shared.frontmostApplication?.processIdentifier },
|
||||
app.focusedWindow == nil,
|
||||
let lastFocusedWindowIndex = getLastFocusedWindowIndex() {
|
||||
updateFocusedWindowIndex(lastFocusedWindowIndex)
|
||||
} else {
|
||||
updateFocusedWindowIndex(0)
|
||||
cycleFocusedWindowIndex(1)
|
||||
}
|
||||
}
|
||||
|
||||
static func getLastFocusedWindowIndex() -> Int? {
|
||||
var index: Int? = nil
|
||||
var lastFocusOrderMin = Int.max
|
||||
Windows.list.enumerated().forEach {
|
||||
if !$0.element.isWindowlessApp && $0.element.lastFocusOrder < lastFocusOrderMin {
|
||||
lastFocusOrderMin = $0.element.lastFocusOrder
|
||||
index = $0.offset
|
||||
}
|
||||
}
|
||||
return index
|
||||
}
|
||||
|
||||
static func appendAndUpdateFocus(_ window: Window) {
|
||||
list.forEach {
|
||||
$0.lastFocusOrder += 1
|
||||
|
||||
@@ -44,6 +44,7 @@ fileprivate func applicationActivated(_ element: AXUIElement, _ pid: pid_t) thro
|
||||
app.hasBeenActiveOnce = true
|
||||
}
|
||||
let window = (appFocusedWindow != nil && wid != nil) ? Windows.updateLastFocus(appFocusedWindow!, wid!)?.first : nil
|
||||
app.focusedWindow = window
|
||||
App.app.checkIfShortcutsShouldBeDisabled(window, app.runningApplication)
|
||||
App.app.refreshOpenUi(window != nil ? [window!] : nil)
|
||||
}
|
||||
@@ -123,6 +124,13 @@ fileprivate func focusedWindowChanged(_ element: AXUIElement, _ pid: pid_t) thro
|
||||
}
|
||||
}
|
||||
}
|
||||
DispatchQueue.main.async {
|
||||
Applications.list.first { $0.pid == pid }?.focusedWindow = Windows.list.first { $0.isEqualRobust(element, wid) }
|
||||
}
|
||||
} else {
|
||||
DispatchQueue.main.async {
|
||||
Applications.list.first { $0.pid == pid }?.focusedWindow = nil
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+1
-2
@@ -252,8 +252,7 @@ class App: AppCenterApplication, NSApplicationDelegate {
|
||||
Windows.refreshWhichWindowsToShowTheUser(screen)
|
||||
Windows.reorderList()
|
||||
if (!Windows.list.contains { $0.shouldShowTheUser }) { hideUi(); return }
|
||||
Windows.updateFocusedWindowIndex(0)
|
||||
Windows.cycleFocusedWindowIndex(1)
|
||||
Windows.setInitialFocusedWindowIndex()
|
||||
delayedDisplayScheduled += 1
|
||||
DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + Preferences.windowDisplayDelay) { () -> () in
|
||||
if self.delayedDisplayScheduled == 1 {
|
||||
|
||||
Reference in New Issue
Block a user