From 12bc0d7b107ba35708d343c427b0826462ee2d9a Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Tue, 12 Aug 2025 15:11:23 -0700 Subject: [PATCH] apprt/gtk-ng: window-subtitle --- src/apprt/gtk-ng/class/window.zig | 18 ++++++++++++++++++ src/apprt/gtk-ng/ui/1.5/tab.blp | 2 +- src/apprt/gtk-ng/ui/1.5/window.blp | 7 +++++++ 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/apprt/gtk-ng/class/window.zig b/src/apprt/gtk-ng/class/window.zig index 3c818068b..fbee07801 100644 --- a/src/apprt/gtk-ng/class/window.zig +++ b/src/apprt/gtk-ng/class/window.zig @@ -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); diff --git a/src/apprt/gtk-ng/ui/1.5/tab.blp b/src/apprt/gtk-ng/ui/1.5/tab.blp index 32938c7c2..5c07209e8 100644 --- a/src/apprt/gtk-ng/ui/1.5/tab.blp +++ b/src/apprt/gtk-ng/ui/1.5/tab.blp @@ -8,7 +8,7 @@ template $GhosttyTab: Box { orientation: vertical; hexpand: true; vexpand: true; - tooltip: bind split_tree.active-surface as <$GhosttySurface>.pwd as ; + tooltip: bind split_tree.active-surface as <$GhosttySurface>.pwd; $GhosttySplitTree split_tree { notify::active-surface => $notify_active_surface(); diff --git a/src/apprt/gtk-ng/ui/1.5/window.blp b/src/apprt/gtk-ng/ui/1.5/window.blp index 4ca90dfb5..b09c0d9b3 100644 --- a/src/apprt/gtk-ng/ui/1.5/window.blp +++ b/src/apprt/gtk-ng/ui/1.5/window.blp @@ -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 ; }; [start]