From 95f97d33af9a5751837ee8a7b5d74a8c4a7b505b Mon Sep 17 00:00:00 2001 From: Louis Pontoise Date: Sun, 5 Jun 2022 11:55:53 +0900 Subject: [PATCH] fix: tab detection got broken in v6.41.0 (#1656) --- src/api-wrappers/PrivateApis.swift | 2 +- src/logic/Applications.swift | 4 ++-- src/logic/Spaces.swift | 5 ++--- src/logic/Windows.swift | 4 ++-- 4 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/api-wrappers/PrivateApis.swift b/src/api-wrappers/PrivateApis.swift index 0dd509c34..a6e907016 100644 --- a/src/api-wrappers/PrivateApis.swift +++ b/src/api-wrappers/PrivateApis.swift @@ -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) diff --git a/src/logic/Applications.swift b/src/logic/Applications.swift index f5b70a1bb..fa951b8aa 100644 --- a/src/logic/Applications.swift +++ b/src/logic/Applications.swift @@ -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 diff --git a/src/logic/Spaces.swift b/src/logic/Spaces.swift index bb1c8aae3..4ec580fb0 100644 --- a/src/logic/Spaces.swift +++ b/src/logic/Spaces.swift @@ -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 { diff --git a/src/logic/Windows.swift b/src/logic/Windows.swift index 19a47153b..63c60a179 100644 --- a/src/logic/Windows.swift +++ b/src/logic/Windows.swift @@ -160,7 +160,7 @@ 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) } @@ -168,7 +168,7 @@ class Windows { 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) }