Skip to content

Commit

Permalink
fix: better filtering of "actual" windows (closes 102)
Browse files Browse the repository at this point in the history
  • Loading branch information
louis.pontoise authored and lwouis committed Jan 3, 2020
1 parent c69123b commit fcdce9c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
6 changes: 6 additions & 0 deletions alt-tab-macos/api-wrappers/AXUIElement.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ enum AXAttributeKey: String {
case windows = "AXWindows"
case minimized = "AXMinimized"
case focusedWindow = "AXFocusedWindow"
case subrole = "AXSubrole"
}

extension AXUIElement {
Expand Down Expand Up @@ -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)
}
Expand Down
17 changes: 10 additions & 7 deletions alt-tab-macos/logic/TrackedWindows.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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))
}
}
Expand Down

0 comments on commit fcdce9c

Please sign in to comment.