apprt/gtk-ng: set title

This commit is contained in:
Mitchell Hashimoto
2025-07-20 15:23:40 -07:00
parent 793e271989
commit 9440c775c7
2 changed files with 65 additions and 4 deletions

View File

@ -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

View File

@ -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