Something went wrong. Try again.
An auto tiler for macOS
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152public struct DriverWindowRole: Sendable, Equatable { public let windowID: UInt32 public let role: String public let subrole: String
public init(windowID: UInt32, role: String, subrole: String) { self.windowID = windowID self.role = role self.subrole = subrole }}
public enum DriverWindowIdentity: Sendable, Equatable { case identified(UInt32) case unsupported(String)}
public struct DriverWindowSelection: Sendable, Equatable { public let index: Int public let warnings: [String]
public static func standardWindowIDs(_ candidates: [DriverWindowRole]) throws -> [UInt32] { var seen: Set<UInt32> = [] for candidate in candidates { guard candidate.windowID > 0, seen.insert(candidate.windowID).inserted else { throw DriverError("Standard window identity must be positive and unique") } } return candidates.filter { $0.role == "AXWindow" && $0.subrole == "AXStandardWindow" } .map(\.windowID).sorted() }
public static func select(windowID: UInt32, candidates: [DriverWindowIdentity]) throws -> Self { guard windowID > 0 else { throw DriverError("CGWindowID must be positive") } var match: Int? var warnings: [String] = [] for (index, candidate) in candidates.enumerated() { switch candidate { case .identified(let id) where id == windowID: guard match == nil else { throw DriverError("Ambiguous AX identity for CGWindowID \(windowID)") } match = index case .identified: break case .unsupported(let reason): warnings.append("AX candidate \(index): \(reason)") } } guard let match else { throw DriverError("No AX window for CGWindowID \(windowID); unsupported candidates: \(warnings)") } return Self(index: match, warnings: warnings) }}