mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-08-02 14:57:31 +03:00
macos: move title setting into a function to better encapsulate
This commit is contained in:
@ -947,20 +947,7 @@ 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 }
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
surfaceView.setTitle(title)
|
||||
|
||||
default:
|
||||
assertionFailure()
|
||||
@ -1095,7 +1082,10 @@ extension Ghostty {
|
||||
guard let surface = target.target.surface else { return }
|
||||
guard let surfaceView = self.surfaceView(from: surface) else { return }
|
||||
let backingSize = NSSize(width: Double(v.width), height: Double(v.height))
|
||||
surfaceView.cellSize = surfaceView.convertFromBacking(backingSize)
|
||||
DispatchQueue.main.async { [weak surfaceView] in
|
||||
guard let surfaceView else { return }
|
||||
surfaceView.cellSize = surfaceView.convertFromBacking(backingSize)
|
||||
}
|
||||
|
||||
default:
|
||||
assertionFailure()
|
||||
|
@ -12,11 +12,7 @@ extension Ghostty {
|
||||
// The current title of the surface as defined by the pty. This can be
|
||||
// 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?
|
||||
@Published private(set) var title: String = "👻"
|
||||
|
||||
// The current pwd of the surface as defined by the pty. This can be
|
||||
// changed with escape codes.
|
||||
@ -114,6 +110,9 @@ extension Ghostty {
|
||||
// This is set to non-null during keyDown to accumulate insertText contents
|
||||
private var keyTextAccumulator: [String]? = nil
|
||||
|
||||
// A small delay that is introduced before a title change to avoid flickers
|
||||
private var titleChangeTimer: Timer?
|
||||
|
||||
// We need to support being a first responder so that we can get input events
|
||||
override var acceptsFirstResponder: Bool { return true }
|
||||
|
||||
@ -343,6 +342,20 @@ extension Ghostty {
|
||||
NSCursor.setHiddenUntilMouseMoves(!visible)
|
||||
}
|
||||
|
||||
func setTitle(_ title: String) {
|
||||
// This fixes an issue where very quick changes to the title could
|
||||
// cause an unpleasant flickering. We set a timer so that we can
|
||||
// coalesce rapid changes. The timer is short enough that it still
|
||||
// feels "instant".
|
||||
titleChangeTimer?.invalidate()
|
||||
titleChangeTimer = Timer.scheduledTimer(
|
||||
withTimeInterval: 0.075,
|
||||
repeats: false
|
||||
) { [weak self] _ in
|
||||
self?.title = title
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Notifications
|
||||
|
||||
@objc private func onUpdateRendererHealth(notification: SwiftUI.Notification) {
|
||||
|
Reference in New Issue
Block a user