Skip to content

Commit

Permalink
fix: wrong focus after active app becomes windowless (closes #2065)
Browse files Browse the repository at this point in the history
  • Loading branch information
lwouis committed Nov 2, 2022
1 parent 8b2d659 commit 281b3ed
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/logic/events/AccessibilityEvents.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ fileprivate func handleEvent(_ type: String, _ element: AXUIElement) throws {
case kAXWindowCreatedNotification: try windowCreated(element, pid)
case kAXMainWindowChangedNotification,
kAXFocusedWindowChangedNotification: try focusedWindowChanged(element, pid)
case kAXUIElementDestroyedNotification: try windowDestroyed(element)
case kAXUIElementDestroyedNotification: try windowDestroyed(element, pid)
case kAXWindowMiniaturizedNotification,
kAXWindowDeminiaturizedNotification: try windowMiniaturizedOrDeminiaturized(element, type)
case kAXTitleChangedNotification: try windowTitleChanged(element, pid)
Expand Down Expand Up @@ -130,13 +130,16 @@ fileprivate func focusedWindowChanged(_ element: AXUIElement, _ pid: pid_t) thro
}
}

fileprivate func windowDestroyed(_ element: AXUIElement) throws {
fileprivate func windowDestroyed(_ element: AXUIElement, _ pid: pid_t) throws {
let wid = try element.cgWindowId()
DispatchQueue.main.async {
if let index = (Windows.list.firstIndex { $0.isEqualRobust(element, wid) }) {
let window = Windows.list[index]
Windows.removeAndUpdateFocus(window)
let windowlessApp = window.application.addWindowslessAppsIfNeeded()
if windowlessApp != nil {
Applications.find(pid)?.focusedWindow = nil
}
if Windows.list.count > 0 {
Windows.moveFocusedWindowIndexAfterWindowDestroyedInBackground(index)
App.app.refreshOpenUi(windowlessApp)
Expand Down

0 comments on commit 281b3ed

Please sign in to comment.