Add delay before a title change to avoid flicker on macOS

This commit is contained in:
Pranav Mangal
2024-12-11 23:10:03 +05:30
parent 9f75d93a55
commit 146b1f2a1b
2 changed files with 18 additions and 3 deletions

View File

@ -54,6 +54,10 @@ class BaseTerminalController: NSWindowController,
/// Fullscreen state management.
private(set) var fullscreenStyle: FullscreenStyle?
var titleChangeDelay: TimeInterval = 0.075
private var titleChangeTimer: Timer?
/// Event monitor (see individual events for why)
private var eventMonitor: Any? = nil
@ -260,9 +264,12 @@ class BaseTerminalController: NSWindowController,
func titleDidChange(to: String) {
guard let window else { return }
// Set the main window title
window.title = to
titleChangeTimer?.invalidate()
// Set the main window title after a small delay to prevent flicker
titleChangeTimer = Timer.scheduledTimer(withTimeInterval: titleChangeDelay, repeats: false) { _ in
window.title = to
}
}
func pwdDidChange(to: URL?) {

View File

@ -27,6 +27,8 @@ class TerminalController: BaseTerminalController {
/// The notification cancellable for focused surface property changes.
private var surfaceAppearanceCancellables: Set<AnyCancellable> = []
private var toolbarTitleChangeTimer: Timer?
init(_ ghostty: Ghostty.App,
withBaseConfig base: Ghostty.SurfaceConfiguration? = nil,
withSurfaceTree tree: Ghostty.SplitNode? = nil
@ -546,9 +548,15 @@ class TerminalController: BaseTerminalController {
// a custom view instead, we need to re-hide it.
window.titleVisibility = .hidden
}
toolbarTitleChangeTimer?.invalidate()
// Set the toolbar title after a small delay to prevent flicker
toolbarTitleChangeTimer = Timer.scheduledTimer(withTimeInterval: titleChangeDelay, repeats: false) { _ in
toolbar.titleText = to
}
}
}
override func surfaceTreeDidChange() {
// Whenever our surface tree changes in any way (new split, close split, etc.)