mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-08-02 14:57:31 +03:00
Move title change timer to SurfaceView and call it from Ghostty.App instead of terminal controllers
This commit is contained in:
@ -53,10 +53,6 @@ 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
|
||||
@ -264,12 +260,9 @@ class BaseTerminalController: NSWindowController,
|
||||
func titleDidChange(to: String) {
|
||||
guard let window else { return }
|
||||
|
||||
titleChangeTimer?.invalidate()
|
||||
// Set the main window title
|
||||
window.title = to
|
||||
|
||||
// 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?) {
|
||||
|
@ -26,8 +26,6 @@ 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,
|
||||
@ -548,13 +546,7 @@ 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
|
||||
}
|
||||
toolbar.titleText = to
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -947,15 +947,21 @@ extension Ghostty {
|
||||
guard let surface = target.target.surface else { return }
|
||||
guard let surfaceView = self.surfaceView(from: surface) else { return }
|
||||
guard let title = String(cString: v.title!, encoding: .utf8) else { return }
|
||||
|
||||
// We must set this in a dispatchqueue to avoid a deadlock on startup on some
|
||||
// versions of macOS. I unfortunately didn't document the exact versions so
|
||||
// I don't know when its safe to remove this.
|
||||
DispatchQueue.main.async {
|
||||
surfaceView.title = title
|
||||
|
||||
surfaceView.titleChangeTimer?.invalidate()
|
||||
|
||||
surfaceView.titleChangeTimer = Timer.scheduledTimer(
|
||||
withTimeInterval: surfaceView.titleChangeDelay,
|
||||
repeats: false
|
||||
) { _ in
|
||||
// We must set this in a dispatchqueue to avoid a deadlock on startup on some
|
||||
// versions of macOS. I unfortunately didn't document the exact versions so
|
||||
// I don't know when its safe to remove this.
|
||||
DispatchQueue.main.async {
|
||||
surfaceView.title = title
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
default:
|
||||
assertionFailure()
|
||||
}
|
||||
|
@ -13,6 +13,10 @@ extension Ghostty {
|
||||
// changed with escape codes. This is public because the callbacks go
|
||||
// to the app level and it is set from there.
|
||||
@Published var title: String = "👻"
|
||||
|
||||
// A small delay that is introduced before a title change to avoid flickers
|
||||
var titleChangeDelay: TimeInterval = 0.075
|
||||
var titleChangeTimer: Timer?
|
||||
|
||||
// The current pwd of the surface as defined by the pty. This can be
|
||||
// changed with escape codes.
|
||||
|
Reference in New Issue
Block a user