Skip to content

Commit

Permalink
feat: improve support for scrcpy always-on-top 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 f9f1c19 commit 0673381
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/api-wrappers/AXUIElement.swift
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ extension AXUIElement {
keynote(runningApp) ||
iina(runningApp) ||
openFlStudio(runningApp, title) ||
crossoverWindow(runningApp, role, subrole, level)
crossoverWindow(runningApp, role, subrole, level) ||
isAlwaysOnTopScrcpy(runningApp, level, role, subrole)
) || (
// CGWindowLevel == .normalWindow helps filter out iStats Pro and other top-level pop-overs, and floating windows
level == CGWindow.normalLevel && (
Expand Down Expand Up @@ -218,6 +219,12 @@ extension AXUIElement {
&& (runningApp.localizedName == "wine64-preloader" || runningApp.executableURL?.absoluteString.contains("/winetemp-") ?? false)
}

private static func isAlwaysOnTopScrcpy(_ runningApp: NSRunningApplication, _ level: CGWindowLevel, _ role: String?, _ subrole: String?) -> Bool {
// scrcpy presents as a floating window when "Always on top" is enabled, so it doesn't get picked up normally.
// It also doesn't have a bundle ID, so we need to match using the localized name, which should always be the same.
return runningApp.localizedName == "scrcpy" && level == CGWindow.floatingWindow && role == kAXWindowRole && subrole == kAXStandardWindowSubrole
}

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 @@ -5,6 +5,7 @@ typealias CGWindow = [CFString: Any]
extension CGWindow {
static let normalLevel = CGWindowLevelForKey(.normalWindow)
static let baseLevel = CGWindowLevelForKey(.baseWindow)
static let floatingWindow = CGWindowLevelForKey(.floatingWindow)

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

0 comments on commit 0673381

Please sign in to comment.