From 87aaff5fae2ef9d07dac8532650ad728662640b4 Mon Sep 17 00:00:00 2001 From: nicm Date: Sat, 4 Apr 2026 16:40:27 +0000 Subject: [PATCH 1/3] Bring some new formats from the floating panes work: pane_zoomed_flag, pane_flags, pane_floating_flag. By Michael Grant. --- cmd-select-layout.c | 2 +- format.c | 52 ++++++++++++++++++++++++++++++++++++++++++--- layout-custom.c | 2 +- tmux.1 | 3 +++ tmux.h | 5 +++-- window.c | 22 +++++++++++++++++-- 6 files changed, 77 insertions(+), 9 deletions(-) diff --git a/cmd-select-layout.c b/cmd-select-layout.c index 6dfe2b6a..41779747 100644 --- a/cmd-select-layout.c +++ b/cmd-select-layout.c @@ -90,7 +90,7 @@ cmd_select_layout_exec(struct cmd *self, struct cmdq_item *item) previous = 1; oldlayout = w->old_layout; - w->old_layout = layout_dump(w->layout_root); + w->old_layout = layout_dump(w, w->layout_root); if (next || previous) { if (next) diff --git a/format.c b/format.c index a9310ff4..2ebfe588 100644 --- a/format.c +++ b/format.c @@ -811,8 +811,8 @@ format_cb_window_layout(struct format_tree *ft) return (NULL); if (w->saved_layout_root != NULL) - return (layout_dump(w->saved_layout_root)); - return (layout_dump(w->layout_root)); + return (layout_dump(w, w->saved_layout_root)); + return (layout_dump(w, w->layout_root)); } /* Callback for window_visible_layout. */ @@ -824,7 +824,7 @@ format_cb_window_visible_layout(struct format_tree *ft) if (w == NULL) return (NULL); - return (layout_dump(w->layout_root)); + return (layout_dump(w, w->layout_root)); } /* Callback for pane_start_command. */ @@ -990,6 +990,29 @@ format_cb_pane_fg(struct format_tree *ft) return (xstrdup(colour_tostring(gc.fg))); } +/* Callback for pane_flags. */ +static void * +format_cb_pane_flags(struct format_tree *ft) +{ + if (ft->wp != NULL) + return (xstrdup(window_pane_printable_flags(ft->wp))); + return (NULL); +} + +/* Callback for pane_floating_flag. */ +static void * +format_cb_pane_floating_flag(struct format_tree *ft) +{ + struct window_pane *wp = ft->wp; + + if (wp != NULL) { + if (wp->flags & PANE_FLOATING) + return (xstrdup("1")); + return (xstrdup("0")); + } + return (NULL); +} + /* Callback for pane_bg. */ static void * format_cb_pane_bg(struct format_tree *ft) @@ -2351,6 +2374,20 @@ format_cb_pane_width(struct format_tree *ft) return (NULL); } +/* Callback for pane_zoomed_flag. */ +static void * +format_cb_pane_zoomed_flag(struct format_tree *ft) +{ + struct window_pane *wp = ft->wp; + + if (wp != NULL) { + if (wp->flags & PANE_ZOOMED) + return (xstrdup("1")); + return (xstrdup("0")); + } + return (NULL); +} + /* Callback for scroll_region_lower. */ static void * format_cb_scroll_region_lower(struct format_tree *ft) @@ -3326,6 +3363,12 @@ static const struct format_table_entry format_table[] = { { "pane_fg", FORMAT_TABLE_STRING, format_cb_pane_fg }, + { "pane_flags", FORMAT_TABLE_STRING, + format_cb_pane_flags + }, + { "pane_floating_flag", FORMAT_TABLE_STRING, + format_cb_pane_floating_flag + }, { "pane_format", FORMAT_TABLE_STRING, format_cb_pane_format }, @@ -3413,6 +3456,9 @@ static const struct format_table_entry format_table[] = { { "pane_width", FORMAT_TABLE_STRING, format_cb_pane_width }, + { "pane_zoomed_flag", FORMAT_TABLE_STRING, + format_cb_pane_zoomed_flag + }, { "pid", FORMAT_TABLE_STRING, format_cb_pid }, diff --git a/layout-custom.c b/layout-custom.c index 2bfb6d89..22de0bdd 100644 --- a/layout-custom.c +++ b/layout-custom.c @@ -58,7 +58,7 @@ layout_checksum(const char *layout) /* Dump layout as a string. */ char * -layout_dump(struct layout_cell *root) +layout_dump(__unused struct window *w, struct layout_cell *root) { char layout[8192], *out; diff --git a/tmux.1 b/tmux.1 index dd0f7c4a..9c2932ad 100644 --- a/tmux.1 +++ b/tmux.1 @@ -6369,6 +6369,8 @@ The following variables are available, where appropriate: .It Li "pane_dead_status" Ta "" Ta "Exit status of process in dead pane" .It Li "pane_dead_time" Ta "" Ta "Exit time of process in dead pane" .It Li "pane_fg" Ta "" Ta "Pane foreground colour" +.It Li "pane_flags" Ta "" Ta "Pane flags" +.It Li "pane_floating_flag" Ta "" Ta "1 if pane is floating" .It Li "pane_format" Ta "" Ta "1 if format is for a pane" .It Li "pane_height" Ta "" Ta "Height of pane" .It Li "pane_id" Ta "#D" Ta "Unique pane ID" @@ -6398,6 +6400,7 @@ The following variables are available, where appropriate: .It Li "pane_tty" Ta "" Ta "Pseudo terminal of pane" .It Li "pane_unseen_changes" Ta "" Ta "1 if there were changes in pane while in mode" .It Li "pane_width" Ta "" Ta "Width of pane" +.It Li "pane_floating_flag" Ta "" Ta "1 if pane is floating" .It Li "pid" Ta "" Ta "Server PID" .It Li "prev_window_active" Ta "" Ta "1 if previous window in W: loop is active" .It Li "prev_window_index" Ta "" Ta "Index of previous window in W: loop" diff --git a/tmux.h b/tmux.h index 3f55c30f..27f016de 100644 --- a/tmux.h +++ b/tmux.h @@ -1218,7 +1218,7 @@ struct window_pane { #define PANE_FOCUSED 0x4 #define PANE_VISITED 0x8 #define PANE_ZOOMED 0x10 -/* 0x20 unused */ +#define PANE_FLOATING 0x20 #define PANE_INPUTOFF 0x40 #define PANE_CHANGED 0x80 #define PANE_EXITED 0x100 @@ -3372,6 +3372,7 @@ int window_pane_exited(struct window_pane *); u_int window_pane_search(struct window_pane *, const char *, int, int); const char *window_printable_flags(struct winlink *, int); +const char *window_pane_printable_flags(struct window_pane *); struct window_pane *window_pane_find_up(struct window_pane *); struct window_pane *window_pane_find_down(struct window_pane *); struct window_pane *window_pane_find_left(struct window_pane *); @@ -3439,7 +3440,7 @@ int layout_spread_cell(struct window *, struct layout_cell *); void layout_spread_out(struct window_pane *); /* layout-custom.c */ -char *layout_dump(struct layout_cell *); +char *layout_dump(struct window *, struct layout_cell *); int layout_parse(struct window *, const char *, char **); /* layout-set.c */ diff --git a/window.c b/window.c index 7a70205e..c97a3875 100644 --- a/window.c +++ b/window.c @@ -882,9 +882,8 @@ window_printable_flags(struct winlink *wl, int escape) { struct session *s = wl->session; static char flags[32]; - int pos; + u_int pos = 0; - pos = 0; if (wl->flags & WINLINK_ACTIVITY) { flags[pos++] = '#'; if (escape) @@ -906,6 +905,25 @@ window_printable_flags(struct winlink *wl, int escape) return (flags); } +const char * +window_pane_printable_flags(struct window_pane *wp) +{ + struct window *w = wp->window; + static char flags[32]; + u_int pos = 0; + + if (wp == w->active) + flags[pos++] = '*'; + if (wp == TAILQ_FIRST(&w->last_panes)) + flags[pos++] = '-'; + if (wp->flags & PANE_ZOOMED) + flags[pos++] = 'Z'; + if (wp->flags & PANE_FLOATING) + flags[pos++] = 'F'; + flags[pos] = '\0'; + return (flags); +} + struct window_pane * window_pane_find_by_id_str(const char *s) { From 7f2ac9c8718355a88d3c21ef127fd0292e7d3013 Mon Sep 17 00:00:00 2001 From: nicm Date: Sat, 4 Apr 2026 17:00:33 +0000 Subject: [PATCH 2/3] Add remain-on-exit key to keep pane around until a key is pressed, from Michael Grant. --- options-table.c | 7 ++++--- server-client.c | 9 +++++++++ server-fn.c | 1 + tmux.1 | 5 ++++- 4 files changed, 18 insertions(+), 4 deletions(-) diff --git a/options-table.c b/options-table.c index 8101a92c..55abe679 100644 --- a/options-table.c +++ b/options-table.c @@ -92,7 +92,7 @@ static const char *options_table_window_size_list[] = { "largest", "smallest", "manual", "latest", NULL }; static const char *options_table_remain_on_exit_list[] = { - "off", "on", "failed", NULL + "off", "on", "failed", "key", NULL }; static const char *options_table_destroy_unattached_list[] = { "off", "on", "keep-last", "keep-group", NULL @@ -1408,8 +1408,9 @@ const struct options_table_entry options_table[] = { .scope = OPTIONS_TABLE_WINDOW|OPTIONS_TABLE_PANE, .choices = options_table_remain_on_exit_list, .default_num = 0, - .text = "Whether panes should remain ('on') or be automatically " - "killed ('off' or 'failed') when the program inside exits." + .text = "Whether panes should remain ('on'), remain until a key is " + "pressed ('key') or be automatically killed ('off' or " + "'failed') when the program inside exits." }, { .name = "remain-on-exit-format", diff --git a/server-client.c b/server-client.c index ca57d397..88de60d0 100644 --- a/server-client.c +++ b/server-client.c @@ -1359,6 +1359,15 @@ try_again: } forward_key: + if (wp != NULL && + (wp->flags & PANE_EXITED) && + !KEYC_IS_MOUSE(key) && + !KEYC_IS_PASTE(key) && + options_get_number(wp->options, "remain-on-exit") == 3) { + options_set_number(wp->options, "remain-on-exit", 0); + server_destroy_pane(wp, 0); + goto out; + } if (c->flags & CLIENT_READONLY) goto out; if (wp != NULL) diff --git a/server-fn.c b/server-fn.c index c36dc74f..6c4c9c61 100644 --- a/server-fn.c +++ b/server-fn.c @@ -341,6 +341,7 @@ server_destroy_pane(struct window_pane *wp, int notify) break; /* FALLTHROUGH */ case 1: + case 3: if (wp->flags & PANE_STATUSDRAWN) return; wp->flags |= PANE_STATUSDRAWN; diff --git a/tmux.1 b/tmux.1 index 9c2932ad..5a457420 100644 --- a/tmux.1 +++ b/tmux.1 @@ -5569,13 +5569,16 @@ uses when the colour with that index is requested. The index may be from zero to 255. .Pp .It Xo Ic remain\-on\-exit -.Op Ic on | off | failed +.Op Ic on | off | failed | key .Xc A pane with this flag set is not destroyed when the program running in it exits. If set to .Ic failed , then only when the program exit status is not zero. +If set to +.Ic key , +the pane stays open and closes when a key is pressed. The pane may be reactivated with the .Ic respawn\-pane command. From cad282ebb77b5c037e3bc5281eab95f077ba31af Mon Sep 17 00:00:00 2001 From: nicm Date: Sat, 4 Apr 2026 17:13:07 +0000 Subject: [PATCH 3/3] Cache user from getpwuid because it can be very expensive on some platforms. From Ben Maurer in GitHub issue 4973. --- format.c | 15 +++++++++++---- server-client.c | 1 + tmux.h | 1 + 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/format.c b/format.c index 2ebfe588..1dba66a6 100644 --- a/format.c +++ b/format.c @@ -1616,9 +1616,13 @@ format_cb_client_user(struct format_tree *ft) struct passwd *pw; if (ft->c != NULL) { + if (ft->c->user != NULL) + return (xstrdup(ft->c->user)); uid = proc_get_peer_uid(ft->c->peer); - if (uid != (uid_t)-1 && (pw = getpwuid(uid)) != NULL) - return (xstrdup(pw->pw_name)); + if (uid != (uid_t)-1 && (pw = getpwuid(uid)) != NULL) { + ft->c->user = xstrdup(pw->pw_name); + return (xstrdup(ft->c->user)); + } } return (NULL); } @@ -3076,10 +3080,13 @@ format_cb_uid(__unused struct format_tree *ft) static void * format_cb_user(__unused struct format_tree *ft) { + static char *cached; struct passwd *pw; - if ((pw = getpwuid(getuid())) != NULL) - return (xstrdup(pw->pw_name)); + if (cached == NULL && (pw = getpwuid(getuid())) != NULL) + cached = xstrdup(pw->pw_name); + if (cached != NULL) + return (xstrdup(cached)); return (NULL); } diff --git a/server-client.c b/server-client.c index 88de60d0..d6a6159e 100644 --- a/server-client.c +++ b/server-client.c @@ -537,6 +537,7 @@ server_client_free(__unused int fd, __unused short events, void *arg) if (c->references == 0) { free((void *)c->name); + free((void *)c->user); free(c); } } diff --git a/tmux.h b/tmux.h index 27f016de..87bcac78 100644 --- a/tmux.h +++ b/tmux.h @@ -1958,6 +1958,7 @@ typedef void (*overlay_resize_cb)(struct client *, void *); struct client { const char *name; struct tmuxpeer *peer; + const char *user; struct cmdq_list *queue; struct client_windows windows;