Skip to content

Commit

Permalink
Fix: aerospace thinks that all windows are closed when you close MacB…
Browse files Browse the repository at this point in the history
…ook lid

The problem with the MacBook lid is not 100% reproducible, it's flaky

A follow up on #445

The change in MacApp.swift is insignificant, it just further reduces the
chance of detecting problematic ax events.
  • Loading branch information
nikitabobko committed Nov 1, 2024
1 parent 405dec8 commit 964e5b1
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
11 changes: 7 additions & 4 deletions Sources/AppBundle/layout/refresh.swift
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,13 @@ func gcWindows() {
// When lockscreen is active, all accessibility API becomes unobservable (all attributes become empty, window id
// becomes nil, etc.) which tricks AeroSpace into thinking that all windows were closed.
// The worst part is that windows don't becomes unobservable all together but window by window.
if NSWorkspace.shared.frontmostApplication?.bundleIdentifier == "com.apple.loginwindow" {
return
}
for window in MacWindow.allWindows where window.axWindow.containingWindowId() == nil {
if NSWorkspace.shared.frontmostApplication?.bundleIdentifier == lockScreenAppBundleId { return }
let allWindows = MacWindow.allWindows
let toKill: [MacWindow] = allWindows.filter { $0.axWindow.containingWindowId() == nil }
// If all windows are "unobservable", it's highly propable that loginwindow might be still active and we are still
// recovering from unlock
if toKill.count == allWindows.count { return }
for window in toKill {
window.garbageCollect()
}
}
Expand Down
5 changes: 5 additions & 0 deletions Sources/AppBundle/tree/MacApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ final class MacApp: AbstractApp {
static var allAppsMap: [pid_t: MacApp] = [:]

fileprivate static func get(_ nsApp: NSRunningApplication) -> MacApp? {
// Don't perceive any of the lock screen windows as real windows
// Otherwise, false positive ax notifications might trigger that lead to gcWindows
if nsApp.bundleIdentifier == lockScreenAppBundleId {
return nil
}
let pid = nsApp.processIdentifier
if let existing = allAppsMap[pid] {
return existing
Expand Down
1 change: 1 addition & 0 deletions Sources/AppBundle/util/appBundleUtil.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import AppKit
import Common
import Foundation

let lockScreenAppBundleId = "com.apple.loginwindow"
let AEROSPACE_WINDOW_ID = "AEROSPACE_WINDOW_ID" // env var
let AEROSPACE_WORKSPACE = "AEROSPACE_WORKSPACE" // env var

Expand Down

0 comments on commit 964e5b1

Please sign in to comment.