From b53cf702629bb5a0c9b24ad03b2dba9733cd2159 Mon Sep 17 00:00:00 2001 From: nicm Date: Sun, 7 Sep 2025 14:03:18 +0000 Subject: [PATCH] Introduce a new window option: tiled-layout-max-columns. It configures the maximum number of columns in the tiled layout. The default value is 0 which means no limit and makes the change backward-compatible. From vkadlcik at redhat dot com. --- layout-set.c | 9 +++++++-- options-table.c | 10 ++++++++++ tmux.1 | 8 ++++++++ 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/layout-set.c b/layout-set.c index 642dbffb..bd68f663 100644 --- a/layout-set.c +++ b/layout-set.c @@ -584,10 +584,11 @@ layout_set_main_v_mirrored(struct window *w) void layout_set_tiled(struct window *w) { + struct options *oo = w->options; struct window_pane *wp; struct layout_cell *lc, *lcrow, *lcchild; u_int n, width, height, used, sx, sy; - u_int i, j, columns, rows; + u_int i, j, columns, rows, max_columns; layout_print_cell(w->layout_root, __func__, 1); @@ -596,11 +597,15 @@ layout_set_tiled(struct window *w) if (n <= 1) return; + /* Get maximum columns from window option. */ + max_columns = options_get_number(oo, "tiled-layout-max-columns"); + /* How many rows and columns are wanted? */ rows = columns = 1; while (rows * columns < n) { rows++; - if (rows * columns < n) + if (rows * columns < n && + (max_columns == 0 || columns < max_columns)) columns++; } diff --git a/options-table.c b/options-table.c index 45e3ae52..e31178fa 100644 --- a/options-table.c +++ b/options-table.c @@ -1395,6 +1395,16 @@ const struct options_table_entry options_table[] = { .text = "Whether typing should be sent to all panes simultaneously." }, + { .name = "tiled-layout-max-columns", + .type = OPTIONS_TABLE_NUMBER, + .scope = OPTIONS_TABLE_WINDOW, + .minimum = 0, + .maximum = USHRT_MAX, + .default_num = 0, + .text = "Maximum number of columns in the 'tiled' layout. " + "A value of 0 means no limit." + }, + { .name = "window-active-style", .type = OPTIONS_TABLE_STRING, .scope = OPTIONS_TABLE_WINDOW|OPTIONS_TABLE_PANE, diff --git a/tmux.1 b/tmux.1 index 73c4ad9d..62e6ca96 100644 --- a/tmux.1 +++ b/tmux.1 @@ -5220,6 +5220,14 @@ see the .Sx STYLES section. .Pp +.It Ic tiled-layout-max-columns Ar number +Set the maximum number of columns in the +.Ic tiled +layout. +A value of 0 (the default) means no limit. +When a limit is set, panes are arranged to not exceed this number of columns, +with additional panes stacked in extra rows. +.Pp .It Ic window-status-activity-style Ar style Set status line style for windows with an activity alert. For how to specify