apprt/gtk-ng: window-subtitle

This commit is contained in:
Mitchell Hashimoto
2025-08-12 15:11:23 -07:00
parent 502040c86a
commit 12bc0d7b10
3 changed files with 26 additions and 1 deletions

View File

@@ -1066,6 +1066,21 @@ pub const Window = extern struct {
});
}
fn closureSubtitle(
_: *Self,
config_: ?*Config,
pwd_: ?[*:0]const u8,
) callconv(.c) ?[*:0]const u8 {
const config = if (config_) |v| v.get() else return null;
return switch (config.@"window-subtitle") {
.false => null,
.@"working-directory" => pwd: {
const pwd = pwd_ orelse return null;
break :pwd glib.ext.dupeZ(u8, std.mem.span(pwd));
},
};
}
//---------------------------------------------------------------
// Virtual methods
@@ -1789,6 +1804,8 @@ pub const Window = extern struct {
fn init(class: *Class) callconv(.c) void {
gobject.ext.ensureType(DebugWarning);
gobject.ext.ensureType(Surface);
gobject.ext.ensureType(Tab);
gtk.Widget.Class.setTemplateFromResource(
class.as(gtk.Widget.Class),
comptime gresource.blueprint(.{
@@ -1838,6 +1855,7 @@ pub const Window = extern struct {
class.bindTemplateCallback("notify_quick_terminal", &propQuickTerminal);
class.bindTemplateCallback("notify_scale_factor", &propScaleFactor);
class.bindTemplateCallback("titlebar_style_is_tabs", &closureTitlebarStyleIsTab);
class.bindTemplateCallback("computed_subtitle", &closureSubtitle);
// Virtual methods
gobject.Object.virtual_methods.dispose.implement(class, &dispose);

View File

@@ -8,7 +8,7 @@ template $GhosttyTab: Box {
orientation: vertical;
hexpand: true;
vexpand: true;
tooltip: bind split_tree.active-surface as <$GhosttySurface>.pwd as <string>;
tooltip: bind split_tree.active-surface as <$GhosttySurface>.pwd;
$GhosttySplitTree split_tree {
notify::active-surface => $notify_active_surface();

View File

@@ -40,6 +40,13 @@ template $GhosttyWindow: Adw.ApplicationWindow {
title-widget: Adw.WindowTitle {
title: bind template.title;
// Blueprint auto-formatter won't let me split this into multiple
// lines. Let me explain myself. All parameters to a closure are used
// as notifications to recompute the value of the closure. All
// elements of a property chain are also subscribed to for changes.
// This one long, ugly line saves us from manually building up this
// massive notify chain in code.
subtitle: bind $computed_subtitle(template.config, tab_view.selected-page.child as <$GhosttyTab>.active-surface as <$GhosttySurface>.pwd) as <string>;
};
[start]