From 2aa1874f945dd480265d37ff93ce64729492951f Mon Sep 17 00:00:00 2001 From: Thorsten Ball Date: Fri, 12 Jan 2024 17:35:15 +0100 Subject: [PATCH 1/2] gtk: append new tabs at the end if config is set This adds a new config option: `window-append-new-tabs` (please: if you have a better name, let me know). If this is set to true, then new GTK tabs aren't added after the current tab, but after at the end. --- src/apprt/gtk/Tab.zig | 14 +++++++++++--- src/config/Config.zig | 4 ++++ 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/apprt/gtk/Tab.zig b/src/apprt/gtk/Tab.zig index d6ac452e2..d6a561322 100644 --- a/src/apprt/gtk/Tab.zig +++ b/src/apprt/gtk/Tab.zig @@ -107,13 +107,21 @@ pub fn init(self: *Tab, window: *Window, parent_: ?*CoreSurface) !void { const gl_area_widget = @as(*c.GtkWidget, @ptrCast(surface.gl_area)); c.gtk_box_append(self.box, gl_area_widget); - // Add the notebook page (create tab). We create the tab after our - // current selected tab if we have one. + // Add the notebook page (create tab). + const parent_page_idx = parent_page_idx: { + // If this option is enabled we append the new tab to the end of the notebook. + if (window.app.config.@"window-append-new-tabs") { + break :parent_page_idx c.gtk_notebook_get_n_pages(window.notebook); + } + // Otherwise we add it after the current tab. + break :parent_page_idx c.gtk_notebook_get_current_page(window.notebook) + 1; + }; + const page_idx = c.gtk_notebook_insert_page( window.notebook, box_widget, label_box_widget, - c.gtk_notebook_get_current_page(window.notebook) + 1, + parent_page_idx, ); if (page_idx < 0) { log.warn("failed to add page to notebook", .{}); diff --git a/src/config/Config.zig b/src/config/Config.zig index a852fcef7..41d4dc1f3 100644 --- a/src/config/Config.zig +++ b/src/config/Config.zig @@ -656,6 +656,10 @@ keybind: Keybinds = .{}, /// Currently only supported on macOS. @"window-step-resize": bool = false, +/// Append new tabs to the end of the tab list instead of right after the +/// current tab. +@"window-append-new-tabs": bool = false, + /// When enabled, the full GTK titlebar is displayed instead of your window /// manager's simple titlebar. The behavior of this option will vary with your /// window manager. From 81b9a6b623b25951b2a7f5f3d7cf4dee3197f6a7 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Fri, 12 Jan 2024 09:50:47 -0800 Subject: [PATCH 2/2] config: rename window-append-new-tab to window-new-tab-position --- src/apprt/gtk/Tab.zig | 10 +++------- src/config/Config.zig | 17 ++++++++++++++--- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/src/apprt/gtk/Tab.zig b/src/apprt/gtk/Tab.zig index d6a561322..875e80d58 100644 --- a/src/apprt/gtk/Tab.zig +++ b/src/apprt/gtk/Tab.zig @@ -108,13 +108,9 @@ pub fn init(self: *Tab, window: *Window, parent_: ?*CoreSurface) !void { c.gtk_box_append(self.box, gl_area_widget); // Add the notebook page (create tab). - const parent_page_idx = parent_page_idx: { - // If this option is enabled we append the new tab to the end of the notebook. - if (window.app.config.@"window-append-new-tabs") { - break :parent_page_idx c.gtk_notebook_get_n_pages(window.notebook); - } - // Otherwise we add it after the current tab. - break :parent_page_idx c.gtk_notebook_get_current_page(window.notebook) + 1; + const parent_page_idx = switch (window.app.config.@"window-new-tab-position") { + .current => c.gtk_notebook_get_current_page(window.notebook) + 1, + .end => c.gtk_notebook_get_n_pages(window.notebook), }; const page_idx = c.gtk_notebook_insert_page( diff --git a/src/config/Config.zig b/src/config/Config.zig index 41d4dc1f3..d5826f76a 100644 --- a/src/config/Config.zig +++ b/src/config/Config.zig @@ -656,9 +656,14 @@ keybind: Keybinds = .{}, /// Currently only supported on macOS. @"window-step-resize": bool = false, -/// Append new tabs to the end of the tab list instead of right after the -/// current tab. -@"window-append-new-tabs": bool = false, +/// The position where new tabs are created. Valid values: +/// +/// - "current" - Insert the new tab after the currently focused tab, +/// or at the end if there are no focused tabs. +/// - "end" - Insert the new tab at the end of the tab list. +/// +/// This configuration currently only works with GTK. +@"window-new-tab-position": WindowNewTabPosition = .current, /// When enabled, the full GTK titlebar is displayed instead of your window /// manager's simple titlebar. The behavior of this option will vary with your @@ -2899,6 +2904,12 @@ pub const WindowSaveState = enum { always, }; +/// See window-new-tab-position +pub const WindowNewTabPosition = enum { + current, + end, +}; + /// See grapheme-width-method pub const GraphemeWidthMethod = enum { wcswidth,