From e35fe6b6c8eb0175bbc8856702123a3133c55dcd Mon Sep 17 00:00:00 2001 From: Louis Pontoise Date: Fri, 24 Apr 2020 02:21:12 +0900 Subject: [PATCH] fix: handle windows assigned to all spaces (closes #266) --- src/logic/Applications.swift | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/logic/Applications.swift b/src/logic/Applications.swift index e9455b2c..195612e3 100644 --- a/src/logic/Applications.swift +++ b/src/logic/Applications.swift @@ -23,16 +23,18 @@ class Applications { } static func addInitialRunningApplicationsWindows() { - let spaces = Spaces.otherSpaces() - if spaces.count == 0 { + let otherSpaces = Spaces.otherSpaces() + if otherSpaces.count == 0 { Applications.observeNewWindows() } else { - let windows = Spaces.windowsInSpaces(spaces) - if windows.count > 0 { + 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 - CGSAddWindowsToSpaces(cgsMainConnectionId, windows as NSArray, [Spaces.currentSpaceId]) + CGSAddWindowsToSpaces(cgsMainConnectionId, windowsOnlyOnOtherSpaces as NSArray, [Spaces.currentSpaceId]) Applications.observeNewWindows() - CGSRemoveWindowsFromSpaces(cgsMainConnectionId, windows as NSArray, [Spaces.currentSpaceId]) + CGSRemoveWindowsFromSpaces(cgsMainConnectionId, windowsOnlyOnOtherSpaces as NSArray, [Spaces.currentSpaceId]) } } }