From bbaef6cf8ec6605c4fe6067c8db68391d4ac6730 Mon Sep 17 00:00:00 2001 From: lwouis Date: Fri, 15 Mar 2024 14:26:33 +0100 Subject: [PATCH] feat: support autocad non-native windows (#3219) --- src/api-wrappers/AXUIElement.swift | 8 +++++++- src/api-wrappers/PrivateApis.swift | 3 +++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/api-wrappers/AXUIElement.swift b/src/api-wrappers/AXUIElement.swift index 3a177cc5..5da0ce46 100644 --- a/src/api-wrappers/AXUIElement.swift +++ b/src/api-wrappers/AXUIElement.swift @@ -106,7 +106,8 @@ extension AXUIElement { sanGuoShaAirWD(runningApp) || dvdFab(runningApp) || drBetotte(runningApp) || - androidEmulator(runningApp, title) + androidEmulator(runningApp, title) || + autocad(runningApp, subrole) ) && ( mustHaveIfJetbrainApp(runningApp, title, subrole, size!) && mustHaveIfSteam(runningApp, title, role) && @@ -225,6 +226,11 @@ extension AXUIElement { return runningApp.localizedName == "scrcpy" && level == CGWindow.floatingWindow && role == kAXWindowRole && subrole == kAXStandardWindowSubrole } + private static func autocad(_ runningApp: NSRunningApplication, _ subrole: String?) -> Bool { + // AutoCAD uses the undocumented "AXDocumentWindow" subrole + return (runningApp.bundleIdentifier?.hasPrefix("com.autodesk.AutoCAD") ?? false) && subrole == kAXDocumentWindowSubrole + } + func position() throws -> CGPoint? { return try value(kAXPositionAttribute, CGPoint.zero, .cgPoint) } diff --git a/src/api-wrappers/PrivateApis.swift b/src/api-wrappers/PrivateApis.swift index f822a6d1..4b73aabb 100644 --- a/src/api-wrappers/PrivateApis.swift +++ b/src/api-wrappers/PrivateApis.swift @@ -204,6 +204,9 @@ func SLSRequestScreenCaptureAccess() -> UInt8 let kAXFullscreenAttribute = "AXFullScreen" let kAXStatusLabelAttribute = "AXStatusLabel" +// for some reason, these attributes are missing from AXRoleConstants +let kAXDocumentWindowSubrole = "AXDocumentWindow" + enum CGSSymbolicHotKey: Int, CaseIterable { case commandTab = 1 case commandShiftTab = 2