From 9440c775c73e53e9f2820e69f6d61980b961f90e Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Sun, 20 Jul 2025 15:23:40 -0700 Subject: [PATCH] apprt/gtk-ng: set title --- src/apprt/gtk-ng/class/application.zig | 21 ++++++++++- src/apprt/gtk-ng/class/surface.zig | 48 ++++++++++++++++++++++++-- 2 files changed, 65 insertions(+), 4 deletions(-) diff --git a/src/apprt/gtk-ng/class/application.zig b/src/apprt/gtk-ng/class/application.zig index 083c00e5a..49e77052b 100644 --- a/src/apprt/gtk-ng/class/application.zig +++ b/src/apprt/gtk-ng/class/application.zig @@ -422,6 +422,8 @@ pub const Application = extern struct { .render => Action.render(self, target), + .set_title => Action.setTitle(target, value), + // Unimplemented .quit, .close_window, @@ -440,7 +442,6 @@ pub const Application = extern struct { .inspector, .show_gtk_inspector, .desktop_notification, - .set_title, .present_terminal, .initial_size, .size_limit, @@ -977,6 +978,24 @@ const Action = struct { .surface => |v| v.rt_surface.surface.redraw(), } } + + pub fn setTitle( + target: apprt.Target, + value: apprt.action.SetTitle, + ) void { + switch (target) { + .app => log.warn("set_title to app is unexpected", .{}), + .surface => |surface| { + var v = gobject.ext.Value.newFrom(value.title); + defer v.unset(); + gobject.Object.setProperty( + surface.rt_surface.gobj().as(gobject.Object), + "title", + &v, + ); + }, + } + } }; /// This sets various GTK-related environment variables as necessary diff --git a/src/apprt/gtk-ng/class/surface.zig b/src/apprt/gtk-ng/class/surface.zig index bbd47e7ae..353a1babb 100644 --- a/src/apprt/gtk-ng/class/surface.zig +++ b/src/apprt/gtk-ng/class/surface.zig @@ -117,6 +117,30 @@ pub const Surface = extern struct { }, ); }; + + pub const title = struct { + pub const name = "title"; + const impl = gobject.ext.defineProperty( + name, + Self, + ?[:0]const u8, + .{ + .nick = "Title", + .blurb = "The title of the surface.", + .default = null, + .accessor = gobject.ext.typedAccessor( + Self, + ?[:0]const u8, + .{ + .getter = getTitle, + .getter_transfer = .none, + .setter = setTitle, + .setter_transfer = .full, + }, + ), + }, + ); + }; }; pub const signals = struct { @@ -157,6 +181,9 @@ pub const Surface = extern struct { /// which triggers this property. pwd: ?[:0]const u8 = null, + /// The title of this surface, if any has been set. + title: ?[:0]const u8 = null, + /// The GLAarea that renders the actual surface. This is a binding /// to the template so it doesn't have to be unrefed manually. gl_area: *gtk.GLArea = undefined, @@ -849,9 +876,8 @@ pub const Surface = extern struct { priv.core_surface = null; } - if (priv.pwd != null) { - self.setPwd(null); - } + if (priv.pwd != null) self.setPwd(null); + if (priv.title != null) self.setTitle(null); gobject.Object.virtual_methods.finalize.call( Class.parent, @@ -882,6 +908,21 @@ pub const Surface = extern struct { priv.pwd = value; } + fn getTitle( + self: *Self, + ) ?[:0]const u8 { + return self.private().title; + } + + fn setTitle( + self: *Self, + value: ?[:0]const u8, + ) void { + const priv = self.private(); + if (priv.title) |v| glib.free(@constCast(@ptrCast(v.ptr))); + priv.title = value; + } + fn propMouseHidden( self: *Self, _: *gobject.ParamSpec, @@ -1565,6 +1606,7 @@ pub const Surface = extern struct { properties.@"mouse-shape".impl, properties.@"mouse-hidden".impl, properties.pwd.impl, + properties.title.impl, }); // Signals