fix: handle windows assigned to all spaces (closes #266)

This commit is contained in:
Louis Pontoise authored and lwouis committed 2020-04-24 02:44:12 +09:00
1 parent 1acd918511
commit e35fe6b6c8
1 file changed
+8 -6
+8 -6
View File
@@ -23,16 +23,18 @@ class Applications {
} }
static func addInitialRunningApplicationsWindows() { static func addInitialRunningApplicationsWindows() {
let spaces = Spaces.otherSpaces() let otherSpaces = Spaces.otherSpaces()
if spaces.count == 0 { if otherSpaces.count == 0 {
Applications.observeNewWindows() Applications.observeNewWindows()
} else { } else {
let windows = Spaces.windowsInSpaces(spaces) let windowsOnCurrentSpace = Spaces.windowsInSpaces([Spaces.currentSpaceId])
if windows.count > 0 { 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 // 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
CGSAddWindowsToSpaces(cgsMainConnectionId, windows as NSArray, [Spaces.currentSpaceId]) CGSAddWindowsToSpaces(cgsMainConnectionId, windowsOnlyOnOtherSpaces as NSArray, [Spaces.currentSpaceId])
Applications.observeNewWindows() Applications.observeNewWindows()
CGSRemoveWindowsFromSpaces(cgsMainConnectionId, windows as NSArray, [Spaces.currentSpaceId]) CGSRemoveWindowsFromSpaces(cgsMainConnectionId, windowsOnlyOnOtherSpaces as NSArray, [Spaces.currentSpaceId])
} }
} }
} }