diff --git a/src/logic/Window.swift b/src/logic/Window.swift index 5a6668e5..f3a8683a 100644 --- a/src/logic/Window.swift +++ b/src/logic/Window.swift @@ -178,6 +178,7 @@ class Window { } else if let bundleID = application.runningApplication.bundleIdentifier, bundleID == App.id { App.shared.activate(ignoringOtherApps: true) App.app.window(withWindowNumber: Int(cgWindowId!))?.makeKeyAndOrderFront(nil) + Windows.previewFocusedWindowIfNeeded() } else { // macOS bug: when switching to a System Preferences window in another space, it switches to that space, // but quickly switches back to another window in that space @@ -189,6 +190,9 @@ class Window { _SLPSSetFrontProcessWithOptions(&psn, self.cgWindowId!, SLPSMode.userGenerated.rawValue) self.makeKeyWindow(psn) self.axUiElement.focusWindow() + DispatchQueue.main.asyncAfter(deadline: .now() + .milliseconds(50)) { + Windows.previewFocusedWindowIfNeeded() + } } } } diff --git a/src/ui/App.swift b/src/ui/App.swift index be5f3a1d..a6de7f33 100644 --- a/src/ui/App.swift +++ b/src/ui/App.swift @@ -109,13 +109,15 @@ class App: AppCenterApplication, NSApplicationDelegate { App.shared.terminate(self) } - func hideUi() { + func hideUi(_ keepPreview: Bool = false) { debugPrint("hideUi") appIsBeingUsed = false isFirstSummon = true MouseEvents.toggle(false) hideThumbnailPanelWithoutChangingKeyWindow() - previewPanel.orderOut(nil) + if !keepPreview { + previewPanel.orderOut(nil) + } hideAllTooltips() } @@ -205,12 +207,14 @@ class App: AppCenterApplication, NSApplicationDelegate { } func focusSelectedWindow(_ selectedWindow: Window?) { - hideUi() + hideUi(true) if let window = selectedWindow, !MissionControl.isActive() { window.focus() if Preferences.cursorFollowFocusEnabled { moveCursorToSelectedWindow(window) } + } else { + previewPanel.orderOut(nil) } }