From fc6d63603a02b1d1ff5a28f3d6cb6dcce7dc8913 Mon Sep 17 00:00:00 2001 From: lwouis Date: Thu, 2 Jan 2025 18:00:59 +0100 Subject: [PATCH] feat: improve performance and order accuracy at launch --- src/api-wrappers/CGWindowID.swift | 4 ---- src/logic/Applications.swift | 6 ++++-- src/ui/App.swift | 7 +++++-- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/api-wrappers/CGWindowID.swift b/src/api-wrappers/CGWindowID.swift index 58e75da8..6aa7f3c0 100644 --- a/src/api-wrappers/CGWindowID.swift +++ b/src/api-wrappers/CGWindowID.swift @@ -40,7 +40,3 @@ extension CGWindowID { return value as? T } } - -//class Testt { -// static var sampleCgImage: CGImage? = nil -//} diff --git a/src/logic/Applications.swift b/src/logic/Applications.swift index 205890af..484adb7f 100644 --- a/src/logic/Applications.swift +++ b/src/logic/Applications.swift @@ -30,7 +30,9 @@ class Applications { static func addInitialRunningApplicationsWindows() { let otherSpaces = Spaces.otherSpaces() - if otherSpaces.count > 0 { + // the CGSAddWindowsToSpaces trick stopped working starting with macOS 12.2 + // see https://github.com/lwouis/alt-tab-macos/issues/1324 + if otherSpaces.count > 0, #unavailable(macOS 12.2) { let windowsOnCurrentSpace = Spaces.windowsInSpaces([Spaces.currentSpaceId]) let windowsOnOtherSpaces = Spaces.windowsInSpaces(otherSpaces) let windowsOnlyOnOtherSpaces = Array(Set(windowsOnOtherSpaces).subtracting(windowsOnCurrentSpace)) @@ -41,7 +43,7 @@ class Applications { CGSRemoveWindowsFromSpaces(cgsMainConnectionId, windowsOnlyOnOtherSpaces as NSArray, [Spaces.currentSpaceId]) } } else { - Applications.manuallyUpdateWindowsFor2s() + Applications.manuallyUpdateWindows() } } diff --git a/src/ui/App.swift b/src/ui/App.swift index 8ffee2f2..79095d2a 100644 --- a/src/ui/App.swift +++ b/src/ui/App.swift @@ -24,6 +24,7 @@ class App: AppCenterApplication, NSApplicationDelegate { var feedbackWindow: FeedbackWindow! var permissionsWindow: PermissionsWindow! var isFirstSummon = true + var isVeryFirstSummon = true var appIsBeingUsed = false var globalShortcutsAreDisabled = false var shortcutIndex = 0 @@ -75,8 +76,6 @@ class App: AppCenterApplication, NSApplicationDelegate { KeyboardEvents.addEventHandlers() MouseEvents.observe() TrackpadEvents.observe() - // TODO: undeterministic; events in the queue may still be processing; good enough for now - DispatchQueue.main.async { () -> () in Windows.sortByLevel() } self.preloadWindows() #if DEBUG // self.showPreferencesWindow() @@ -281,6 +280,10 @@ class App: AppCenterApplication, NSApplicationDelegate { Logger.debug(shortcutIndex, self.shortcutIndex, isFirstSummon) App.app.appIsBeingUsed = true if isFirstSummon || shortcutIndex != self.shortcutIndex { + if isVeryFirstSummon { + DispatchQueue.main.async { () -> () in Windows.sortByLevel() } + isVeryFirstSummon = false + } isFirstSummon = false self.shortcutIndex = shortcutIndex let screen = NSScreen.preferred()