feat: improve support for scrcpy always-on-top windows

This commit is contained in:
Zachary Wander
2023-07-02 20:50:43 +02:00
committed by Louis Pontoise
parent f9f1c19b84
commit 06733812e6
2 changed files with 9 additions and 1 deletions
+8 -1
View File
@@ -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 && (
@@ -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)
}
+1
View File
@@ -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]