From ae81edfcbfc3a33a8b3d5b147c5557e1325395d4 Mon Sep 17 00:00:00 2001 From: Ismael Arias Date: Thu, 9 Jan 2025 12:50:49 +0100 Subject: [PATCH 1/2] feat(gtk): show menu in context menu if titlebar is disabled --- src/apprt/gtk/App.zig | 41 ++++++++++++++++++++++++++++------------ src/apprt/gtk/Window.zig | 2 +- 2 files changed, 30 insertions(+), 13 deletions(-) diff --git a/src/apprt/gtk/App.zig b/src/apprt/gtk/App.zig index eb5fa7292f..e8c85907de 100644 --- a/src/apprt/gtk/App.zig +++ b/src/apprt/gtk/App.zig @@ -831,12 +831,12 @@ fn setSizeLimit( switch (target) { .app => {}, .surface => |v| try v.rt_surface.setSizeLimits(.{ - .width = value.min_width, - .height = value.min_height, - }, if (value.max_width > 0) .{ - .width = value.max_width, - .height = value.max_height, - } else null), + .width = value.min_width, + .height = value.min_height, + }, if (value.max_width > 0) .{ + .width = value.max_width, + .height = value.max_height, + } else null), } } @@ -1766,12 +1766,10 @@ fn initActions(self: *App) void { } } -/// This sets the self.menu property to the application menu that can be -/// shared by all application windows. -fn initMenu(self: *App) void { - const menu = c.g_menu_new(); - errdefer c.g_object_unref(menu); - +/// Initializes and populates the provided GMenu with sections and actions. +/// This function is used to set up the application's menu structure, either for +/// the main menu button or as a context menu when window decorations are disabled. +fn initMenuContent(menu: *c.GMenu) void { { const section = c.g_menu_new(); defer c.g_object_unref(section); @@ -1793,7 +1791,14 @@ fn initMenu(self: *App) void { c.g_menu_append(section, "Reload Configuration", "app.reload-config"); c.g_menu_append(section, "About Ghostty", "win.about"); } +} +/// This sets the self.menu property to the application menu that can be +/// shared by all application windows. +fn initMenu(self: *App) void { + const menu = c.g_menu_new(); + errdefer c.g_object_unref(menu); + initMenuContent(@ptrCast(menu)); self.menu = menu; } @@ -1825,6 +1830,18 @@ fn initContextMenu(self: *App) void { c.g_menu_append(section, "Terminal Inspector", "win.toggle_inspector"); } + if (!self.config.@"window-decoration") { + const section = c.g_menu_new(); + defer c.g_object_unref(section); + const submenu = c.g_menu_new(); + defer c.g_object_unref(submenu); + initMenuContent(@ptrCast(submenu)); + + // Just append the submenu to the menu structure + c.g_menu_append_submenu(section, "Menu", @ptrCast(@alignCast(submenu))); + c.g_menu_append_section(menu, null, @ptrCast(@alignCast(section))); + } + self.context_menu = menu; } diff --git a/src/apprt/gtk/Window.zig b/src/apprt/gtk/Window.zig index 9058ca9dac..0f44cee7b4 100644 --- a/src/apprt/gtk/Window.zig +++ b/src/apprt/gtk/Window.zig @@ -270,7 +270,7 @@ pub fn init(self: *Window, app: *App) !void { } self.context_menu = c.gtk_popover_menu_new_from_model(@ptrCast(@alignCast(self.app.context_menu))); - c.gtk_widget_set_parent(self.context_menu, window); + c.gtk_widget_set_parent(self.context_menu, box); c.gtk_popover_set_has_arrow(@ptrCast(@alignCast(self.context_menu)), 0); c.gtk_widget_set_halign(self.context_menu, c.GTK_ALIGN_START); From b25c59330923557d592dc835cf074287006992ea Mon Sep 17 00:00:00 2001 From: Ismael Arias Date: Thu, 9 Jan 2025 12:52:35 +0100 Subject: [PATCH 2/2] feat(GTK): remove comment --- src/apprt/gtk/App.zig | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/apprt/gtk/App.zig b/src/apprt/gtk/App.zig index e8c85907de..fa5eb7b9f1 100644 --- a/src/apprt/gtk/App.zig +++ b/src/apprt/gtk/App.zig @@ -1835,9 +1835,8 @@ fn initContextMenu(self: *App) void { defer c.g_object_unref(section); const submenu = c.g_menu_new(); defer c.g_object_unref(submenu); - initMenuContent(@ptrCast(submenu)); - // Just append the submenu to the menu structure + initMenuContent(@ptrCast(submenu)); c.g_menu_append_submenu(section, "Menu", @ptrCast(@alignCast(submenu))); c.g_menu_append_section(menu, null, @ptrCast(@alignCast(section))); }