diff --git a/include/ghostty.h b/include/ghostty.h index f630ab0d0..57eb2d716 100644 --- a/include/ghostty.h +++ b/include/ghostty.h @@ -35,6 +35,7 @@ typedef struct { } ghostty_runtime_config_s; typedef struct { + void *userdata; void *nsview; double scale_factor; } ghostty_surface_config_s; diff --git a/macos/Sources/GhosttyApp.swift b/macos/Sources/GhosttyApp.swift index 50baf2ea8..9226a722f 100644 --- a/macos/Sources/GhosttyApp.swift +++ b/macos/Sources/GhosttyApp.swift @@ -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?) { - let state = Unmanaged.fromOpaque(userdata!).takeUnretainedValue() + let surfaceView = Unmanaged.fromOpaque(userdata!).takeUnretainedValue() guard let titleStr = String(cString: title!, encoding: .utf8) else { return } DispatchQueue.main.async { - state.title = titleStr + surfaceView.title = titleStr } } diff --git a/macos/Sources/TerminalSurfaceView.swift b/macos/Sources/TerminalSurfaceView.swift index cd4659f6f..e16fbb02b 100644 --- a/macos/Sources/TerminalSurfaceView.swift +++ b/macos/Sources/TerminalSurfaceView.swift @@ -39,6 +39,9 @@ class TerminalSurfaceView_Real: NSView, NSTextInputClient, ObservableObject { // so we'll use that to tell ghostty to refresh. override var wantsUpdateLayer: Bool { return true } + // TODO: Figure out how to hook this up... + @Published var title: String = ""; + private var surface: ghostty_surface_t? = nil private var error: Error? = nil private var markedText: NSMutableAttributedString; @@ -170,6 +173,7 @@ class TerminalSurfaceView_Real: NSView, NSTextInputClient, ObservableObject { // Setup our surface. This will also initialize all the terminal IO. var surface_cfg = ghostty_surface_config_s( + userdata: Unmanaged.passUnretained(self).toOpaque(), nsview: Unmanaged.passUnretained(self).toOpaque(), scale_factor: NSScreen.main!.backingScaleFactor) guard let surface = ghostty_surface_new(app, &surface_cfg) else { diff --git a/src/apprt/embedded.zig b/src/apprt/embedded.zig index 8d1fa25e7..59b52878c 100644 --- a/src/apprt/embedded.zig +++ b/src/apprt/embedded.zig @@ -58,8 +58,12 @@ pub const Window = struct { core_win: *CoreWindow, content_scale: apprt.ContentScale, size: apprt.WindowSize, + opts: Options, pub const Options = extern struct { + /// Userdata passed to some of the callbacks. + userdata: ?*anyopaque = null, + /// The pointer to the backing NSView for the surface. nsview: *anyopaque = undefined, @@ -78,6 +82,7 @@ pub const Window = struct { .y = @floatCast(f32, opts.scale_factor), }, .size = .{ .width = 800, .height = 600 }, + .opts = opts, }; } @@ -101,7 +106,7 @@ pub const Window = struct { pub fn setTitle(self: *Window, slice: [:0]const u8) !void { self.core_win.app.runtime.opts.set_title( - self.core_win.app.runtime.opts.userdata, + self.opts.userdata, slice.ptr, ); }