From 82cfb62804342db6fc3421d8986f6faeeea1380e Mon Sep 17 00:00:00 2001 From: Louis Pontoise Date: Tue, 15 Nov 2022 19:30:11 +0100 Subject: [PATCH] fix: windows assigned to all spaces were not shown (closes #2123) --- src/api-wrappers/PrivateApis.swift | 1 + src/logic/Applications.swift | 4 ++-- src/logic/Spaces.swift | 5 +++-- src/logic/Windows.swift | 4 ++-- 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/api-wrappers/PrivateApis.swift b/src/api-wrappers/PrivateApis.swift index d756fb21..c68ba092 100644 --- a/src/api-wrappers/PrivateApis.swift +++ b/src/api-wrappers/PrivateApis.swift @@ -113,6 +113,7 @@ func CGSCopyManagedDisplaySpaces(_ cid: CGSConnectionID) -> CFArray struct CGSCopyWindowsOptions: OptionSet { let rawValue: Int static let minimizedAndTabbed = CGSCopyWindowsOptions(rawValue: 1 << 0) + // retrieves windows when their app is assigned to All Spaces, and windows at ScreenSaver level 1000 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 7ec94f91..80130dab 100644 --- a/src/logic/Applications.swift +++ b/src/logic/Applications.swift @@ -31,8 +31,8 @@ class Applications { static func addInitialRunningApplicationsWindows() { let otherSpaces = Spaces.otherSpaces() if otherSpaces.count > 0 { - let windowsOnCurrentSpace = Spaces.windowsInSpaces([Spaces.currentSpaceId], [.minimizedAndTabbed]) - let windowsOnOtherSpaces = Spaces.windowsInSpaces(otherSpaces, [.minimizedAndTabbed]) + let windowsOnCurrentSpace = Spaces.windowsInSpaces([Spaces.currentSpaceId]) + let windowsOnOtherSpaces = Spaces.windowsInSpaces(otherSpaces) 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 7d2c4c16..22ad9c39 100644 --- a/src/logic/Spaces.swift +++ b/src/logic/Spaces.swift @@ -69,10 +69,11 @@ class Spaces { return idsAndIndexes.filter { $0.0 != currentSpaceId }.map { $0.0 } } - static func windowsInSpaces(_ spaceIds: [CGSSpaceID], _ options: CGSCopyWindowsOptions) -> [CGWindowID] { + static func windowsInSpaces(_ spaceIds: [CGSSpaceID]) -> [CGWindowID] { var set_tags = ([] as CGSCopyWindowsTags).rawValue var clear_tags = ([] as CGSCopyWindowsTags).rawValue - return CGSCopyWindowsWithOptionsAndTags(cgsMainConnectionId, 0, spaceIds as CFArray, options.rawValue, &set_tags, &clear_tags) as! [CGWindowID] + let options = ([.minimizedAndTabbed, .screenSaverLevel1000] as CGSCopyWindowsOptions).rawValue + return CGSCopyWindowsWithOptionsAndTags(cgsMainConnectionId, 0, spaceIds as CFArray, options, &set_tags, &clear_tags) as! [CGWindowID] } static func isSingleSpace() -> Bool { diff --git a/src/logic/Windows.swift b/src/logic/Windows.swift index a7902002..ea4c1774 100644 --- a/src/logic/Windows.swift +++ b/src/logic/Windows.swift @@ -161,7 +161,7 @@ class Windows { /// tabs detection is a flaky work-around the lack of public API to observe OS tabs /// see: https://github.com/lwouis/alt-tab-macos/issues/1540 static func detectTabbedWindows() { - let cgsWindowIds = Spaces.windowsInSpaces(Spaces.idsAndIndexes.map { $0.0 }, [.minimizedAndTabbed]) + let cgsWindowIds = Spaces.windowsInSpaces(Spaces.idsAndIndexes.map { $0.0 }) list.forEach { if let cgWindowId = $0.cgWindowId { $0.isTabbed = !cgsWindowIds.contains(cgWindowId) @@ -171,7 +171,7 @@ class Windows { static func sortByLevel() { var windowLevelMap = [CGWindowID: Int]() - for (index, cgWindowId) in Spaces.windowsInSpaces([Spaces.currentSpaceId], [.minimizedAndTabbed]).enumerated() { + for (index, cgWindowId) in Spaces.windowsInSpaces([Spaces.currentSpaceId]).enumerated() { windowLevelMap[cgWindowId] = index } var sortedTuples = Windows.list