import ApplicationServices import CoreGraphics struct WindowParentObservation: Equatable { var hasParent: Bool? var windowID: CGWindowID? } enum WindowParentReader { static let ancestorLimit = 8 static func isWindowRole(_ role: String) -> Bool { [kAXWindowRole, kAXSheetRole, "AXDialog"].contains(role) } static func read( window: Node, parent: (Node) throws -> Node?, containingWindow: (Node) throws -> Node?, role: (Node) throws -> String?, same: (Node, Node) -> Bool, identify: (Node) throws -> CGWindowID? ) throws -> WindowParentObservation { var visited = [window] var current = window var reachedApplication = false var unknownRole = false for _ in 0..