From e0b453fde4b3c0044b0fdeef8aac267b22e6a204 Mon Sep 17 00:00:00 2001 From: Ethan Blazkowicz Date: Sat, 25 Apr 2026 23:34:54 +0800 Subject: [PATCH] fix(preferences): open window over fullscreen apps instead of switching to desktop MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes the issue where opening the preferences window from the menu bar while in a fullscreen app would cause macOS to switch back to the desktop space. By changing the window's `collectionBehavior` to include `.fullScreenAuxiliary` and `.moveToActiveSpace`, and by removing the transition to a regular app (which showed the Dock icon), the application now correctly remains in "Accessory" mode and displays the preferences window directly over the current fullscreen app. Code written by Gemini. --- 修复了在全屏应用中通过菜单栏打开偏好设置时,macOS 会强制切换回桌面的问题。 通过修改窗口的 `collectionBehavior` 包含 `.fullScreenAuxiliary` 和 `.moveToActiveSpace`,同时移除了切换为常规应用(显示 Dock 图标)的逻辑,应用现在会正确保持在“辅助”模式,并直接在当前全屏应用上方显示偏好设置窗口。 代码由 Gemini 编写。 --- Mos/Managers/WindowManager.swift | 12 ++++++------ .../PreferencesWindowController.swift | 4 ++++ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/Mos/Managers/WindowManager.swift b/Mos/Managers/WindowManager.swift index 862860db..05745ba1 100644 --- a/Mos/Managers/WindowManager.swift +++ b/Mos/Managers/WindowManager.swift @@ -37,9 +37,12 @@ extension WindowManager { showWindow(withIdentifier: identifier, withTitle: title) return } - // 显示 + // 取消显示 Dock 图标并激活 App,保留 accessory 模式避免切换 space + // Utils.showDockIcon() + NSApp.activate(ignoringOtherApps: true) + + // 显示并前置窗口 windowController.showWindow(self) - // 前置并激活(已打开窗口也要置顶) if let window = windowController.window { if window.isMiniaturized { window.deminiaturize(self) @@ -47,14 +50,11 @@ extension WindowManager { window.makeKeyAndOrderFront(self) window.orderFrontRegardless() } - NSApp.activate(ignoringOtherApps: true) - // 显示 Dock 图标 - Utils.showDockIcon() } // 关闭对应 Identifier 的窗口 func hideWindow(withIdentifier identifier: String, destroy: Bool = false) { // 隐藏 Dock 图标 - Utils.hideDockIcon() + // Utils.hideDockIcon() // 销毁实例 if destroy { refs.removeValue(forKey: identifier) diff --git a/Mos/Windows/PreferencesWindow/PreferencesWindowController.swift b/Mos/Windows/PreferencesWindow/PreferencesWindowController.swift index 0374b5cf..5e167b77 100644 --- a/Mos/Windows/PreferencesWindow/PreferencesWindowController.swift +++ b/Mos/Windows/PreferencesWindow/PreferencesWindowController.swift @@ -14,6 +14,10 @@ class PreferencesWindowController: NSWindowController, NSWindowDelegate { override func windowDidLoad() { super.windowDidLoad() + + // Allow the window to appear on the current active space, including fullscreen apps + window?.collectionBehavior = [.moveToActiveSpace, .fullScreenAuxiliary] + // 插入分隔符 if #available(OSX 10.16, *) { window?.toolbar?.insertItem(withItemIdentifier: NSToolbarItem.Identifier.flexibleSpace, at: 4)