fix: prevent flickering when switching to a previewed window

(closes #2432)
This commit is contained in:
Louis Pontoise
2023-06-23 23:30:56 +02:00
parent 8605b23135
commit b69f5f4b5f
2 changed files with 11 additions and 3 deletions
+4
View File
@@ -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()
}
}
}
}
+7 -3
View File
@@ -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)
}
}