mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-08-02 14:57:31 +03:00
set title callback needs to use surface userdata
This commit is contained in:
@ -35,6 +35,7 @@ typedef struct {
|
|||||||
} ghostty_runtime_config_s;
|
} ghostty_runtime_config_s;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
void *userdata;
|
||||||
void *nsview;
|
void *nsview;
|
||||||
double scale_factor;
|
double scale_factor;
|
||||||
} ghostty_surface_config_s;
|
} ghostty_surface_config_s;
|
||||||
|
@ -22,7 +22,6 @@ struct GhosttyApp: App {
|
|||||||
case .ready:
|
case .ready:
|
||||||
TerminalView(app: ghostty.app!)
|
TerminalView(app: ghostty.app!)
|
||||||
.modifier(WindowObservationModifier())
|
.modifier(WindowObservationModifier())
|
||||||
.navigationTitle(ghostty.title)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -36,9 +35,6 @@ class GhosttyState: ObservableObject {
|
|||||||
/// The readiness value of the state.
|
/// The readiness value of the state.
|
||||||
@Published var readiness: Readiness = .loading
|
@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.
|
/// The ghostty global configuration.
|
||||||
var config: ghostty_config_t? = nil
|
var config: ghostty_config_t? = nil
|
||||||
|
|
||||||
@ -103,10 +99,10 @@ class GhosttyState: ObservableObject {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static func setTitle(_ userdata: UnsafeMutableRawPointer?, title: UnsafePointer<CChar>?) {
|
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 }
|
guard let titleStr = String(cString: title!, encoding: .utf8) else { return }
|
||||||
DispatchQueue.main.async {
|
DispatchQueue.main.async {
|
||||||
state.title = titleStr
|
surfaceView.title = titleStr
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -39,6 +39,9 @@ class TerminalSurfaceView_Real: NSView, NSTextInputClient, ObservableObject {
|
|||||||
// so we'll use that to tell ghostty to refresh.
|
// so we'll use that to tell ghostty to refresh.
|
||||||
override var wantsUpdateLayer: Bool { return true }
|
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 surface: ghostty_surface_t? = nil
|
||||||
private var error: Error? = nil
|
private var error: Error? = nil
|
||||||
private var markedText: NSMutableAttributedString;
|
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.
|
// Setup our surface. This will also initialize all the terminal IO.
|
||||||
var surface_cfg = ghostty_surface_config_s(
|
var surface_cfg = ghostty_surface_config_s(
|
||||||
|
userdata: Unmanaged.passUnretained(self).toOpaque(),
|
||||||
nsview: Unmanaged.passUnretained(self).toOpaque(),
|
nsview: Unmanaged.passUnretained(self).toOpaque(),
|
||||||
scale_factor: NSScreen.main!.backingScaleFactor)
|
scale_factor: NSScreen.main!.backingScaleFactor)
|
||||||
guard let surface = ghostty_surface_new(app, &surface_cfg) else {
|
guard let surface = ghostty_surface_new(app, &surface_cfg) else {
|
||||||
|
@ -58,8 +58,12 @@ pub const Window = struct {
|
|||||||
core_win: *CoreWindow,
|
core_win: *CoreWindow,
|
||||||
content_scale: apprt.ContentScale,
|
content_scale: apprt.ContentScale,
|
||||||
size: apprt.WindowSize,
|
size: apprt.WindowSize,
|
||||||
|
opts: Options,
|
||||||
|
|
||||||
pub const Options = extern struct {
|
pub const Options = extern struct {
|
||||||
|
/// Userdata passed to some of the callbacks.
|
||||||
|
userdata: ?*anyopaque = null,
|
||||||
|
|
||||||
/// The pointer to the backing NSView for the surface.
|
/// The pointer to the backing NSView for the surface.
|
||||||
nsview: *anyopaque = undefined,
|
nsview: *anyopaque = undefined,
|
||||||
|
|
||||||
@ -78,6 +82,7 @@ pub const Window = struct {
|
|||||||
.y = @floatCast(f32, opts.scale_factor),
|
.y = @floatCast(f32, opts.scale_factor),
|
||||||
},
|
},
|
||||||
.size = .{ .width = 800, .height = 600 },
|
.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 {
|
pub fn setTitle(self: *Window, slice: [:0]const u8) !void {
|
||||||
self.core_win.app.runtime.opts.set_title(
|
self.core_win.app.runtime.opts.set_title(
|
||||||
self.core_win.app.runtime.opts.userdata,
|
self.opts.userdata,
|
||||||
slice.ptr,
|
slice.ptr,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user