diff --git a/src/logic/events/AccessibilityEvents.swift b/src/logic/events/AccessibilityEvents.swift index 0e796a3de..a3d4f1037 100644 --- a/src/logic/events/AccessibilityEvents.swift +++ b/src/logic/events/AccessibilityEvents.swift @@ -97,6 +97,8 @@ fileprivate func focusedWindowChanged(_ element: AXUIElement, _ pid: pid_t) thro let level = try wid.level() let position = try element.position() let size = try element.size() + let parent = try element.parent() + let parentWid = try parent?.cgWindowId() DispatchQueue.main.async { if let windows = Windows.updateLastFocus(element, wid) { App.app.refreshOpenUi(windows) @@ -106,6 +108,11 @@ fileprivate func focusedWindowChanged(_ element: AXUIElement, _ pid: pid_t) thro Windows.appendAndUpdateFocus(window) App.app.refreshOpenUi([window]) } + // if the window is shown by alt-tab, we mark her as focused for this app + // this avoids issues with dialogs, quicklook, etc (see scenarios from #1044 and #2003) + if let w = (Windows.list.first { $0.isEqualRobust(element, wid) }) { + Applications.find(pid)?.focusedWindow = w + } } } DispatchQueue.main.async { @@ -118,9 +125,6 @@ fileprivate func focusedWindowChanged(_ element: AXUIElement, _ pid: pid_t) thro } } } - DispatchQueue.main.async { - Applications.find(pid)?.focusedWindow = Windows.list.first { $0.isEqualRobust(element, wid) } - } } else { DispatchQueue.main.async { Applications.find(pid)?.focusedWindow = nil