mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-09-23 11:38:34 +00:00
macos: hook up change title events
This commit is contained in:
@@ -22,6 +22,7 @@ struct GhosttyApp: App {
|
||||
case .ready:
|
||||
TerminalView(app: ghostty.app!)
|
||||
.modifier(WindowObservationModifier())
|
||||
.navigationTitle(ghostty.title)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -35,6 +36,9 @@ 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
|
||||
|
||||
@@ -69,7 +73,8 @@ class GhosttyState: ObservableObject {
|
||||
// uses to interface with the application runtime environment.
|
||||
var runtime_cfg = ghostty_runtime_config_s(
|
||||
userdata: Unmanaged.passUnretained(self).toOpaque(),
|
||||
wakeup_cb: { userdata in GhosttyState.wakeup(userdata) })
|
||||
wakeup_cb: { userdata in GhosttyState.wakeup(userdata) },
|
||||
set_title_cb: { userdata, title in GhosttyState.setTitle(userdata, title: title) })
|
||||
|
||||
// Create the ghostty app.
|
||||
guard let app = ghostty_app_new(&runtime_cfg, cfg) else {
|
||||
@@ -97,6 +102,14 @@ class GhosttyState: ObservableObject {
|
||||
DispatchQueue.main.async { state.appTick() }
|
||||
}
|
||||
|
||||
static func setTitle(_ userdata: UnsafeMutableRawPointer?, title: UnsafePointer<CChar>?) {
|
||||
let state = Unmanaged<GhosttyState>.fromOpaque(userdata!).takeUnretainedValue()
|
||||
guard let titleStr = String(cString: title!, encoding: .utf8) else { return }
|
||||
DispatchQueue.main.async {
|
||||
state.title = titleStr
|
||||
}
|
||||
}
|
||||
|
||||
deinit {
|
||||
ghostty_app_free(app)
|
||||
ghostty_config_free(config)
|
||||
|
Reference in New Issue
Block a user