diff --git a/src/logic/Windows.swift b/src/logic/Windows.swift index f6c5a148..bcb73641 100644 --- a/src/logic/Windows.swift +++ b/src/logic/Windows.swift @@ -308,7 +308,7 @@ class Windows { if let cgWindowId = window.cgWindowId { let spaceIds = cgWindowId.spaces() window.spaceIds = spaceIds - window.spaceIndexes = spaceIds.map { spaceId in Spaces.idsAndIndexes.first { $0.0 == spaceId }!.1 } + window.spaceIndexes = spaceIds.compactMap { spaceId in Spaces.idsAndIndexes.first { $0.0 == spaceId }?.1 } window.isOnAllSpaces = spaceIds.count > 1 } } diff --git a/src/logic/events/ScreensEvents.swift b/src/logic/events/ScreensEvents.swift index 47559e2e..21ca7ab5 100644 --- a/src/logic/events/ScreensEvents.swift +++ b/src/logic/events/ScreensEvents.swift @@ -7,12 +7,13 @@ class ScreensEvents { @objc private static func handleEvent(_ notification: Notification) { Logger.debug(notification.name.rawValue) + Spaces.refresh() + // a screen added or removed, or screen resolution change can mess up layout; we reset components + App.app.resetPreferencesDependentComponents() // a screen added or removed can shuffle windows around Spaces; we refresh them App.app.refreshOpenUi(Windows.list, .refreshUiAfterExternalEvent) Logger.info("screens", NSScreen.screens.map { ($0.uuid() ?? "nil" as CFString, $0.frame) }) Logger.info("spaces", Spaces.screenSpacesMap) Logger.info("current space", Spaces.currentSpaceIndex, Spaces.currentSpaceId) - // a screen added or removed, or screen resolution change can mess up layout; we reset components - App.app.resetPreferencesDependentComponents() } }