Skip to content

Commit

Permalink
fix: prevent flickering when switching to a previewed window
Browse files Browse the repository at this point in the history
(closes #2432)
  • Loading branch information
lwouis committed Jun 23, 2023
1 parent 8605b23 commit b69f5f4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
4 changes: 4 additions & 0 deletions src/logic/Window.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
}
}
}
}
Expand Down
10 changes: 7 additions & 3 deletions src/ui/App.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}

Expand Down Expand Up @@ -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)
}
}

Expand Down

0 comments on commit b69f5f4

Please sign in to comment.