mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-14 15:56:13 +03:00
apprt/embedded: store title directly instead of get_title cb
This commit is contained in:
@ -408,7 +408,6 @@ typedef void (*ghostty_runtime_wakeup_cb)(void*);
|
||||
typedef const ghostty_config_t (*ghostty_runtime_reload_config_cb)(void*);
|
||||
typedef void (*ghostty_runtime_open_config_cb)(void*);
|
||||
typedef void (*ghostty_runtime_set_title_cb)(void*, const char*);
|
||||
typedef const char* (*ghostty_runtime_get_title_cb)(void*);
|
||||
typedef void (*ghostty_runtime_set_mouse_shape_cb)(void*,
|
||||
ghostty_mouse_shape_e);
|
||||
typedef void (*ghostty_runtime_set_mouse_visibility_cb)(void*, bool);
|
||||
@ -463,7 +462,6 @@ typedef struct {
|
||||
ghostty_runtime_reload_config_cb reload_config_cb;
|
||||
ghostty_runtime_open_config_cb open_config_cb;
|
||||
ghostty_runtime_set_title_cb set_title_cb;
|
||||
ghostty_runtime_get_title_cb get_title_cb;
|
||||
ghostty_runtime_set_mouse_shape_cb set_mouse_shape_cb;
|
||||
ghostty_runtime_set_mouse_visibility_cb set_mouse_visibility_cb;
|
||||
ghostty_runtime_read_clipboard_cb read_clipboard_cb;
|
||||
|
@ -70,7 +70,6 @@ extension Ghostty {
|
||||
reload_config_cb: { userdata in App.reloadConfig(userdata) },
|
||||
open_config_cb: { userdata in App.openConfig(userdata) },
|
||||
set_title_cb: { userdata, title in App.setTitle(userdata, title: title) },
|
||||
get_title_cb: { userdata in App.title(userdata) },
|
||||
set_mouse_shape_cb: { userdata, shape in App.setMouseShape(userdata, shape: shape) },
|
||||
set_mouse_visibility_cb: { userdata, visible in App.setMouseVisibility(userdata, visible: visible) },
|
||||
read_clipboard_cb: { userdata, loc, state in App.readClipboard(userdata, location: loc, state: state) },
|
||||
|
@ -55,9 +55,6 @@ pub const App = struct {
|
||||
/// Called to set the title of the window.
|
||||
set_title: *const fn (SurfaceUD, [*]const u8) callconv(.C) void,
|
||||
|
||||
/// Called to get the title of the window.
|
||||
get_title: ?*const fn (SurfaceUD) callconv(.C) ?[*]const u8 = null,
|
||||
|
||||
/// Called to set the cursor shape.
|
||||
set_mouse_shape: *const fn (SurfaceUD, terminal.MouseShape) callconv(.C) void,
|
||||
|
||||
@ -309,6 +306,10 @@ pub const Surface = struct {
|
||||
keymap_state: input.Keymap.State,
|
||||
inspector: ?*Inspector = null,
|
||||
|
||||
/// The current title of the surface. The embedded apprt saves this so
|
||||
/// that getTitle works without the implementer needing to save it.
|
||||
title: ?[:0]const u8 = null,
|
||||
|
||||
/// Surface initialization options.
|
||||
pub const Options = extern struct {
|
||||
/// The platform that this surface is being initialized for and
|
||||
@ -432,6 +433,9 @@ pub const Surface = struct {
|
||||
// Shut down our inspector
|
||||
self.freeInspector();
|
||||
|
||||
// Free our title
|
||||
if (self.title) |v| self.app.core_app.alloc.free(v);
|
||||
|
||||
// Remove ourselves from the list of known surfaces in the app.
|
||||
self.app.core_app.deleteSurface(self);
|
||||
|
||||
@ -540,6 +544,12 @@ pub const Surface = struct {
|
||||
}
|
||||
|
||||
pub fn setTitle(self: *Surface, slice: [:0]const u8) !void {
|
||||
// Dupe the title so that we can store it. If we get an allocation
|
||||
// error we just ignore it, since this only breaks a few minor things.
|
||||
const alloc = self.app.core_app.alloc;
|
||||
if (self.title) |v| alloc.free(v);
|
||||
self.title = alloc.dupeZ(u8, slice) catch null;
|
||||
|
||||
self.app.opts.set_title(
|
||||
self.userdata,
|
||||
slice.ptr,
|
||||
@ -547,14 +557,7 @@ pub const Surface = struct {
|
||||
}
|
||||
|
||||
pub fn getTitle(self: *Surface) ?[:0]const u8 {
|
||||
const func = self.app.opts.get_title orelse {
|
||||
log.info("runtime embedder does not support get_title", .{});
|
||||
return null;
|
||||
};
|
||||
|
||||
const result = func(self.userdata);
|
||||
if (result == null) return null;
|
||||
return std.mem.sliceTo(@as([*:0]const u8, @ptrCast(result.?)), 0);
|
||||
return self.title;
|
||||
}
|
||||
|
||||
pub fn setMouseShape(self: *Surface, shape: terminal.MouseShape) !void {
|
||||
|
Reference in New Issue
Block a user