From 9c26d54eda285f1df639454af7c1078d613d29f7 Mon Sep 17 00:00:00 2001 From: Louis Pontoise Date: Fri, 14 Oct 2022 21:14:51 +0200 Subject: [PATCH] fix: discover windows when switching spaces (#1324) --- src/logic/Applications.swift | 6 +++++- src/logic/Spaces.swift | 2 ++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/logic/Applications.swift b/src/logic/Applications.swift index ec059c4c5..7ec94f913 100644 --- a/src/logic/Applications.swift +++ b/src/logic/Applications.swift @@ -6,12 +6,16 @@ class Applications { static func manuallyUpdateWindowsFor2s() { let group = DispatchGroup() + manuallyUpdateWindows(group) + _ = group.wait(wallTimeout: .now() + .seconds(2)) + } + + static func manuallyUpdateWindows(_ group: DispatchGroup? = nil) { for app in list { if app.runningApplication.isFinishedLaunching && app.runningApplication.activationPolicy != .prohibited { app.manuallyUpdateWindows(group) } } - _ = group.wait(wallTimeout: .now() + .seconds(2)) } static func initialDiscovery() { diff --git a/src/logic/Spaces.swift b/src/logic/Spaces.swift index c7533eead..bbaa0d0f9 100644 --- a/src/logic/Spaces.swift +++ b/src/logic/Spaces.swift @@ -14,6 +14,8 @@ class Spaces { updateCurrentSpace() // if UI was kept open during Space transition, the Spaces may be obsolete; we refresh them Windows.list.forEachAsync { $0.updatesWindowSpace() } + // from macos 12.2 beta onwards, we can't get other-space windows; grabbing windows when switching spaces mitigates the issue + Applications.manuallyUpdateWindows() }) NSWorkspace.shared.notificationCenter.addObserver(forName: NSApplication.didChangeScreenParametersNotification, object: nil, queue: nil, using: { _ in debugPrint("OS event", "didChangeScreenParametersNotification")