set title callback needs to use surface userdata

This commit is contained in:
Mitchell Hashimoto
2023-02-18 17:22:14 -08:00
parent c709467bee
commit 7b0ddc8b70
4 changed files with 13 additions and 7 deletions

View File

@@ -22,7 +22,6 @@ struct GhosttyApp: App {
case .ready:
TerminalView(app: ghostty.app!)
.modifier(WindowObservationModifier())
.navigationTitle(ghostty.title)
}
}
}
@@ -36,9 +35,6 @@ class GhosttyState: ObservableObject {
/// The readiness value of the state.
@Published var readiness: Readiness = .loading
/// The title of the window as requested by the underlying terminal.
@Published var title: String = "Ghostty";
/// The ghostty global configuration.
var config: ghostty_config_t? = nil
@@ -103,10 +99,10 @@ class GhosttyState: ObservableObject {
}
static func setTitle(_ userdata: UnsafeMutableRawPointer?, title: UnsafePointer<CChar>?) {
let state = Unmanaged<GhosttyState>.fromOpaque(userdata!).takeUnretainedValue()
let surfaceView = Unmanaged<TerminalSurfaceView_Real>.fromOpaque(userdata!).takeUnretainedValue()
guard let titleStr = String(cString: title!, encoding: .utf8) else { return }
DispatchQueue.main.async {
state.title = titleStr
surfaceView.title = titleStr
}
}