Skip to content

Commit

Permalink
feat: improve support for crossover windows
Browse files Browse the repository at this point in the history
  • Loading branch information
zacharee authored and lwouis committed Jul 2, 2023
1 parent 01b3a42 commit f9f1c19
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
29 changes: 21 additions & 8 deletions src/api-wrappers/AXUIElement.swift
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,17 @@ extension AXUIElement {
// debugPrint(runningApp.bundleIdentifier, title, level, CGWindow.normalLevel, subrole, role, size)

// Some non-windows have cgWindowId == 0 (e.g. windows of apps starting at login with the checkbox "Hidden" checked)
return wid != 0 && size != nil &&
(books(runningApp) || keynote(runningApp) || iina(runningApp) || openFlStudio(runningApp, title) || (
return wid != 0 && size != nil && (
(
books(runningApp) ||
keynote(runningApp) ||
iina(runningApp) ||
openFlStudio(runningApp, title) ||
crossoverWindow(runningApp, role, subrole, level)
) || (
// CGWindowLevel == .normalWindow helps filter out iStats Pro and other top-level pop-overs, and floating windows
level == CGWindow.normalLevel &&
([kAXStandardWindowSubrole, kAXDialogSubrole].contains(subrole) ||
level == CGWindow.normalLevel && (
[kAXStandardWindowSubrole, kAXDialogSubrole].contains(subrole) ||
openBoard(runningApp) ||
adobeAudition(runningApp, subrole) ||
adobeAfterEffects(runningApp, subrole) ||
Expand All @@ -100,11 +106,13 @@ extension AXUIElement {
dvdFab(runningApp) ||
drBetotte(runningApp) ||
androidEmulator(runningApp, title)
) &&
) && (
mustHaveIfJetbrainApp(runningApp, title, subrole, size!) &&
mustHaveIfSteam(runningApp, title, role) &&
mustHaveIfColorSlurp(runningApp, title, subrole)
))
mustHaveIfSteam(runningApp, title, role) &&
mustHaveIfColorSlurp(runningApp, title, subrole)
)
)
)
}

private static func mustHaveIfJetbrainApp(_ runningApp: NSRunningApplication, _ title: String?, _ subrole: String?, _ size: NSSize) -> Bool {
Expand Down Expand Up @@ -205,6 +213,11 @@ extension AXUIElement {
return title != "" && Applications.isAndroidEmulator(runningApp)
}

private static func crossoverWindow(_ runningApp: NSRunningApplication, _ role: String?, _ subrole: String?, _ level: CGWindowLevel) -> Bool {
return runningApp.bundleIdentifier == nil && role == kAXWindowRole && subrole == kAXUnknownSubrole && level == CGWindow.baseLevel
&& (runningApp.localizedName == "wine64-preloader" || runningApp.executableURL?.absoluteString.contains("/winetemp-") ?? false)
}

func position() throws -> CGPoint? {
return try value(kAXPositionAttribute, CGPoint.zero, .cgPoint)
}
Expand Down
1 change: 1 addition & 0 deletions src/api-wrappers/CGWindow.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ typealias CGWindow = [CFString: Any]

extension CGWindow {
static let normalLevel = CGWindowLevelForKey(.normalWindow)
static let baseLevel = CGWindowLevelForKey(.baseWindow)

static func windows(_ option: CGWindowListOption) -> [CGWindow] {
return CGWindowListCopyWindowInfo([.excludeDesktopElements, option], kCGNullWindowID) as! [CGWindow]
Expand Down

0 comments on commit f9f1c19

Please sign in to comment.