diff --git a/src/apprt/gtk/class/surface.zig b/src/apprt/gtk/class/surface.zig index 12985c6b8..fd63d148a 100644 --- a/src/apprt/gtk/class/surface.zig +++ b/src/apprt/gtk/class/surface.zig @@ -28,8 +28,7 @@ const ResizeOverlay = @import("resize_overlay.zig").ResizeOverlay; const SearchOverlay = @import("search_overlay.zig").SearchOverlay; const ChildExited = @import("surface_child_exited.zig").SurfaceChildExited; const ClipboardConfirmationDialog = @import("clipboard_confirmation_dialog.zig").ClipboardConfirmationDialog; -const TitleDialog = @import("title_dialog.zig") - .TitleDialog; +const TitleDialog = @import("title_dialog.zig").TitleDialog; const Window = @import("window.zig").Window; const InspectorWindow = @import("inspector_window.zig").InspectorWindow; const i18n = @import("../../../os/i18n.zig"); diff --git a/src/apprt/gtk/class/tab.zig b/src/apprt/gtk/class/tab.zig index affd7d243..e343e0293 100644 --- a/src/apprt/gtk/class/tab.zig +++ b/src/apprt/gtk/class/tab.zig @@ -14,8 +14,7 @@ const Config = @import("config.zig").Config; const Application = @import("application.zig").Application; const SplitTree = @import("split_tree.zig").SplitTree; const Surface = @import("surface.zig").Surface; -const TitleDialog = @import("title_dialog.zig") - .TitleDialog; +const TitleDialog = @import("title_dialog.zig").TitleDialog; const log = std.log.scoped(.gtk_ghostty_window); diff --git a/src/apprt/gtk/class/window.zig b/src/apprt/gtk/class/window.zig index d71e6c768..fb491422f 100644 --- a/src/apprt/gtk/class/window.zig +++ b/src/apprt/gtk/class/window.zig @@ -252,6 +252,10 @@ pub const Window = extern struct { /// A weak reference to a command palette. command_palette: WeakRef(CommandPalette) = .empty, + /// Tab page that the context menu was opened for. + /// setup by `setup-menu`. + context_menu_page: ?*adw.TabPage = null, + // Template bindings tab_overview: *adw.TabOverview, tab_bar: *adw.TabBar, @@ -336,6 +340,7 @@ pub const Window = extern struct { .init("new-tab", actionNewTab, null), .init("new-window", actionNewWindow, null), .init("prompt-tab-title", actionPromptTabTitle, null), + .init("prompt-context-tab-title", actionPromptContextTabTitle, null), .init("ring-bell", actionRingBell, null), .init("split-right", actionSplitRight, null), .init("split-left", actionSplitLeft, null), @@ -1521,6 +1526,13 @@ pub const Window = extern struct { self.as(gtk.Window).close(); } } + fn setupTabMenu( + _: *adw.TabView, + page: ?*adw.TabPage, + self: *Self, + ) callconv(.c) void { + self.private().context_menu_page = page; + } fn surfaceClipboardWrite( _: *Surface, @@ -1764,6 +1776,18 @@ pub const Window = extern struct { self.performBindingAction(.new_tab); } + fn actionPromptContextTabTitle( + _: *gio.SimpleAction, + _: ?*glib.Variant, + self: *Self, + ) callconv(.c) void { + const priv = self.private(); + const page = priv.context_menu_page orelse return; + const child = page.getChild(); + const tab = gobject.ext.cast(Tab, child) orelse return; + tab.promptTabTitle(); + } + fn actionPromptTabTitle( _: *gio.SimpleAction, _: ?*glib.Variant, @@ -1997,6 +2021,7 @@ pub const Window = extern struct { class.bindTemplateCallback("close_page", &tabViewClosePage); class.bindTemplateCallback("page_attached", &tabViewPageAttached); class.bindTemplateCallback("page_detached", &tabViewPageDetached); + class.bindTemplateCallback("setup_tab_menu", &setupTabMenu); class.bindTemplateCallback("tab_create_window", &tabViewCreateWindow); class.bindTemplateCallback("notify_n_pages", &tabViewNPages); class.bindTemplateCallback("notify_selected_page", &tabViewSelectedPage); diff --git a/src/apprt/gtk/ui/1.5/window.blp b/src/apprt/gtk/ui/1.5/window.blp index 88e7d5324..305c7ef8c 100644 --- a/src/apprt/gtk/ui/1.5/window.blp +++ b/src/apprt/gtk/ui/1.5/window.blp @@ -162,6 +162,8 @@ template $GhosttyWindow: Adw.ApplicationWindow { page-attached => $page_attached(); page-detached => $page_detached(); create-window => $tab_create_window(); + setup-menu => $setup_tab_menu(); + menu-model: tab_context_menu; shortcuts: none; } } @@ -312,3 +314,10 @@ menu main_menu { } } } + +menu tab_context_menu { + item { + label: _("Change Title..."); + action: "win.prompt-context-tab-title"; + } +}