fix: better filtering of "actual" windows (closes 102)

This commit is contained in:
louis.pontoise authored and lwouis committed 2020-01-03 19:44:26 +09:00
1 parent c69123b3d4
commit fcdce9cbac
2 files changed
+16 -7

No files matched your search

@@ -8,6 +8,7 @@ enum AXAttributeKey: String {
case windows = "AXWindows"
case minimized = "AXMinimized"
case focusedWindow = "AXFocusedWindow"
case subrole = "AXSubrole"
}
extension AXUIElement {
@@ -39,6 +40,11 @@ extension AXUIElement {
return attribute(.focusedWindow, AXUIElement.self)
}
func isActualWindow() -> Bool {
let subrole = self.attribute(.subrole, String.self)
return subrole != nil && subrole != "AXUnknown"
}
func windows() -> [AXUIElement]? {
return attribute(.windows, [AXUIElement].self)
}
+10 -7
View File
@@ -45,7 +45,7 @@ class TrackedWindows {
Spaces.windowsInSpaces(spaces.map { $0.0 }).enumerated().forEach {
windowSpaceMap[$0.element]!.2 = $0.offset
}
return windowSpaceMap as! [CGWindowID : (CGSSpaceID, SpaceIndex, WindowRank)]
return windowSpaceMap as! [CGWindowID: (CGSSpaceID, SpaceIndex, WindowRank)]
}
private static func sortList() {
@@ -69,15 +69,18 @@ class TrackedWindows {
continue
}
let (spaceId, spaceIndex, rank) = windowsMap[cgId] ?? (nil, nil, nil)
if let axWindow = cgId.AXUIElement(ownerPid) {
if let axWindow = cgId.AXUIElement(ownerPid), axWindow.isActualWindow() {
// window is in the current space
if spaceId != nil {
list.append(TrackedWindow(cgWindow, cgId, ownerPid, false, axWindow, spaceId, spaceIndex, rank))
} else if axWindow.isMinimized() {
list.append(TrackedWindow(cgWindow, cgId, ownerPid, true, axWindow, spaceId, spaceIndex, rank))
}
} else {
// window is on another space
guard spaceId != nil else { continue }
// window is minimized
else if axWindow.isMinimized() {
list.append(TrackedWindow(cgWindow, cgId, ownerPid, true, axWindow, nil, nil, rank))
}
}
// window is on another space
else if spaceId != nil && spaceId != Spaces.currentSpaceId {
list.append(TrackedWindow(cgWindow, cgId, ownerPid, false, nil, spaceId, spaceIndex, rank))
}
}