Skip to content

Commit

Permalink
fix: tab detection got broken in v6.41.0 (#1656)
Browse files Browse the repository at this point in the history
  • Loading branch information
lwouis committed Jun 5, 2022
1 parent 1243de8 commit 95f97d3
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/api-wrappers/PrivateApis.swift
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ func CGSCopyManagedDisplaySpaces(_ cid: CGSConnectionID) -> CFArray

struct CGSCopyWindowsOptions: OptionSet {
let rawValue: Int
static let minimized = CGSCopyWindowsOptions(rawValue: 1 << 0)
static let minimizedAndTabbed = CGSCopyWindowsOptions(rawValue: 1 << 0)
static let screenSaverLevel1000 = CGSCopyWindowsOptions(rawValue: 1 << 1)
static let minimized2 = CGSCopyWindowsOptions(rawValue: 1 << 2)
static let unknown1 = CGSCopyWindowsOptions(rawValue: 1 << 3)
Expand Down
4 changes: 2 additions & 2 deletions src/logic/Applications.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ class Applications {
static func addInitialRunningApplicationsWindows() {
let otherSpaces = Spaces.otherSpaces()
if otherSpaces.count > 0 {
let windowsOnCurrentSpace = Spaces.windowsInSpaces([Spaces.currentSpaceId])
let windowsOnOtherSpaces = Spaces.windowsInSpaces(otherSpaces)
let windowsOnCurrentSpace = Spaces.windowsInSpaces([Spaces.currentSpaceId], [.minimizedAndTabbed])
let windowsOnOtherSpaces = Spaces.windowsInSpaces(otherSpaces, [.minimizedAndTabbed])
let windowsOnlyOnOtherSpaces = Array(Set(windowsOnOtherSpaces).subtracting(windowsOnCurrentSpace))
if windowsOnlyOnOtherSpaces.count > 0 {
// on initial launch, we use private APIs to bring windows from other spaces into the current space, observe them, then remove them from the current space
Expand Down
5 changes: 2 additions & 3 deletions src/logic/Spaces.swift
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,10 @@ class Spaces {
return idsAndIndexes.filter { $0.0 != currentSpaceId }.map { $0.0 }
}

static func windowsInSpaces(_ spaceIds: [CGSSpaceID]) -> [CGWindowID] {
let options = ([.minimized] as CGSCopyWindowsOptions).rawValue
static func windowsInSpaces(_ spaceIds: [CGSSpaceID], _ options: CGSCopyWindowsOptions) -> [CGWindowID] {
var set_tags = ([] as CGSCopyWindowsTags).rawValue
var clear_tags = ([] as CGSCopyWindowsTags).rawValue
return CGSCopyWindowsWithOptionsAndTags(cgsMainConnectionId, 0, spaceIds as CFArray, options, &set_tags, &clear_tags) as! [CGWindowID]
return CGSCopyWindowsWithOptionsAndTags(cgsMainConnectionId, 0, spaceIds as CFArray, options.rawValue, &set_tags, &clear_tags) as! [CGWindowID]
}

static func isSingleSpace() -> Bool {
Expand Down
4 changes: 2 additions & 2 deletions src/logic/Windows.swift
Original file line number Diff line number Diff line change
Expand Up @@ -160,15 +160,15 @@ class Windows {
}

static func detectTabbedWindows() {
let cgsWindowIds = Spaces.windowsInSpaces(Spaces.idsAndIndexes.map { $0.0 })
let cgsWindowIds = Spaces.windowsInSpaces(Spaces.idsAndIndexes.map { $0.0 }, [])
list.forEach {
$0.isTabbed = !$0.isMinimized && !$0.isHidden && !cgsWindowIds.contains($0.cgWindowId)
}
}

static func sortByLevel() {
var windowLevelMap = [CGWindowID: Int]()
for (index, cgWindowId) in Spaces.windowsInSpaces([Spaces.currentSpaceId]).enumerated() {
for (index, cgWindowId) in Spaces.windowsInSpaces([Spaces.currentSpaceId], [.minimizedAndTabbed]).enumerated() {
windowLevelMap[cgWindowId] = index
}
var sortedTuples = Windows.list.map { (windowLevelMap[$0.cgWindowId], $0) }
Expand Down

0 comments on commit 95f97d3

Please sign in to comment.