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:
@ -54,10 +54,6 @@ class BaseTerminalController: NSWindowController,
|
|||||||
/// Fullscreen state management.
|
/// Fullscreen state management.
|
||||||
private(set) var fullscreenStyle: FullscreenStyle?
|
private(set) var fullscreenStyle: FullscreenStyle?
|
||||||
|
|
||||||
var titleChangeDelay: TimeInterval = 0.075
|
|
||||||
|
|
||||||
private var titleChangeTimer: Timer?
|
|
||||||
|
|
||||||
/// Event monitor (see individual events for why)
|
/// Event monitor (see individual events for why)
|
||||||
private var eventMonitor: Any? = nil
|
private var eventMonitor: Any? = nil
|
||||||
|
|
||||||
@ -264,12 +260,9 @@ class BaseTerminalController: NSWindowController,
|
|||||||
func titleDidChange(to: String) {
|
func titleDidChange(to: String) {
|
||||||
guard let window else { return }
|
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?) {
|
func pwdDidChange(to: URL?) {
|
||||||
|
@ -27,8 +27,6 @@ class TerminalController: BaseTerminalController {
|
|||||||
/// The notification cancellable for focused surface property changes.
|
/// The notification cancellable for focused surface property changes.
|
||||||
private var surfaceAppearanceCancellables: Set<AnyCancellable> = []
|
private var surfaceAppearanceCancellables: Set<AnyCancellable> = []
|
||||||
|
|
||||||
private var toolbarTitleChangeTimer: Timer?
|
|
||||||
|
|
||||||
init(_ ghostty: Ghostty.App,
|
init(_ ghostty: Ghostty.App,
|
||||||
withBaseConfig base: Ghostty.SurfaceConfiguration? = nil,
|
withBaseConfig base: Ghostty.SurfaceConfiguration? = nil,
|
||||||
withSurfaceTree tree: Ghostty.SplitNode? = nil
|
withSurfaceTree tree: Ghostty.SplitNode? = nil
|
||||||
@ -548,13 +546,7 @@ class TerminalController: BaseTerminalController {
|
|||||||
// a custom view instead, we need to re-hide it.
|
// a custom view instead, we need to re-hide it.
|
||||||
window.titleVisibility = .hidden
|
window.titleVisibility = .hidden
|
||||||
}
|
}
|
||||||
|
toolbar.titleText = to
|
||||||
toolbarTitleChangeTimer?.invalidate()
|
|
||||||
|
|
||||||
// Set the toolbar title after a small delay to prevent flicker
|
|
||||||
toolbarTitleChangeTimer = Timer.scheduledTimer(withTimeInterval: titleChangeDelay, repeats: false) { _ in
|
|
||||||
toolbar.titleText = to
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -948,13 +948,19 @@ extension Ghostty {
|
|||||||
guard let surfaceView = self.surfaceView(from: surface) else { return }
|
guard let surfaceView = self.surfaceView(from: surface) else { return }
|
||||||
guard let title = String(cString: v.title!, encoding: .utf8) 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
|
surfaceView.titleChangeTimer?.invalidate()
|
||||||
// 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 = 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:
|
default:
|
||||||
assertionFailure()
|
assertionFailure()
|
||||||
|
@ -14,6 +14,10 @@ extension Ghostty {
|
|||||||
// to the app level and it is set from there.
|
// to the app level and it is set from there.
|
||||||
@Published var title: String = "👻"
|
@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
|
// The current pwd of the surface as defined by the pty. This can be
|
||||||
// changed with escape codes.
|
// changed with escape codes.
|
||||||
@Published var pwd: String? = nil
|
@Published var pwd: String? = nil
|
||||||
|
Reference in New Issue
Block a user