From baddd6b22ac853e5dde9561d909eb360b9f39560 Mon Sep 17 00:00:00 2001 From: nicm Date: Thu, 11 Mar 2021 06:31:05 +0000 Subject: [PATCH] Add split-window -Z to start the pane zoomed, GitHub issue 2591. --- usr.bin/tmux/cmd-join-pane.c | 4 ++-- usr.bin/tmux/cmd-rotate-window.c | 4 ++-- usr.bin/tmux/cmd-select-pane.c | 14 +++++++------- usr.bin/tmux/cmd-split-window.c | 11 +++++++---- usr.bin/tmux/cmd-swap-pane.c | 6 +++--- usr.bin/tmux/cmd-switch-client.c | 4 ++-- usr.bin/tmux/layout-custom.c | 4 ++-- usr.bin/tmux/layout-set.c | 10 +++++----- usr.bin/tmux/layout.c | 24 ++++++++++++++---------- usr.bin/tmux/options.c | 4 ++-- usr.bin/tmux/spawn.c | 7 +++++-- usr.bin/tmux/tmux.1 | 8 +++++--- usr.bin/tmux/tmux.h | 10 ++++++---- usr.bin/tmux/window.c | 8 ++++---- 14 files changed, 66 insertions(+), 52 deletions(-) diff --git a/usr.bin/tmux/cmd-join-pane.c b/usr.bin/tmux/cmd-join-pane.c index 50ecc6fc9cd..923497c482f 100644 --- a/usr.bin/tmux/cmd-join-pane.c +++ b/usr.bin/tmux/cmd-join-pane.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd-join-pane.c,v 1.47 2021/01/06 07:32:23 nicm Exp $ */ +/* $OpenBSD: cmd-join-pane.c,v 1.48 2021/03/11 06:31:05 nicm Exp $ */ /* * Copyright (c) 2011 George Nachman @@ -147,7 +147,7 @@ cmd_join_pane_exec(struct cmd *self, struct cmdq_item *item) TAILQ_INSERT_BEFORE(dst_wp, src_wp, entry); else TAILQ_INSERT_AFTER(&dst_w->panes, dst_wp, src_wp, entry); - layout_assign_pane(lc, src_wp); + layout_assign_pane(lc, src_wp, 0); recalculate_sizes(); diff --git a/usr.bin/tmux/cmd-rotate-window.c b/usr.bin/tmux/cmd-rotate-window.c index 7c96a3ded65..2b256b4a11e 100644 --- a/usr.bin/tmux/cmd-rotate-window.c +++ b/usr.bin/tmux/cmd-rotate-window.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd-rotate-window.c,v 1.31 2020/04/13 14:46:04 nicm Exp $ */ +/* $OpenBSD: cmd-rotate-window.c,v 1.32 2021/03/11 06:31:05 nicm Exp $ */ /* * Copyright (c) 2009 Nicholas Marriott @@ -52,7 +52,7 @@ cmd_rotate_window_exec(struct cmd *self, struct cmdq_item *item) struct layout_cell *lc; u_int sx, sy, xoff, yoff; - window_push_zoom(w, args_has(args, 'Z')); + window_push_zoom(w, 0, args_has(args, 'Z')); if (args_has(args, 'D')) { wp = TAILQ_LAST(&w->panes, window_panes); diff --git a/usr.bin/tmux/cmd-select-pane.c b/usr.bin/tmux/cmd-select-pane.c index 11dee6cf490..467331fe011 100644 --- a/usr.bin/tmux/cmd-select-pane.c +++ b/usr.bin/tmux/cmd-select-pane.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd-select-pane.c,v 1.65 2021/02/04 14:02:24 nicm Exp $ */ +/* $OpenBSD: cmd-select-pane.c,v 1.66 2021/03/11 06:31:05 nicm Exp $ */ /* * Copyright (c) 2009 Nicholas Marriott @@ -117,7 +117,7 @@ cmd_select_pane_exec(struct cmd *self, struct cmdq_item *item) server_redraw_window_borders(lastwp->window); server_status_window(lastwp->window); } else { - if (window_push_zoom(w, args_has(args, 'Z'))) + if (window_push_zoom(w, 0, args_has(args, 'Z'))) server_redraw_window(w); window_redraw_active_switch(w, lastwp); if (window_set_active_pane(w, lastwp, 1)) { @@ -171,19 +171,19 @@ cmd_select_pane_exec(struct cmd *self, struct cmdq_item *item) } if (args_has(args, 'L')) { - window_push_zoom(w, 1); + window_push_zoom(w, 0, 1); wp = window_pane_find_left(wp); window_pop_zoom(w); } else if (args_has(args, 'R')) { - window_push_zoom(w, 1); + window_push_zoom(w, 0, 1); wp = window_pane_find_right(wp); window_pop_zoom(w); } else if (args_has(args, 'U')) { - window_push_zoom(w, 1); + window_push_zoom(w, 0, 1); wp = window_pane_find_up(wp); window_pop_zoom(w); } else if (args_has(args, 'D')) { - window_push_zoom(w, 1); + window_push_zoom(w, 0, 1); wp = window_pane_find_down(wp); window_pop_zoom(w); } @@ -220,7 +220,7 @@ cmd_select_pane_exec(struct cmd *self, struct cmdq_item *item) activewp = w->active; if (wp == activewp) return (CMD_RETURN_NORMAL); - if (window_push_zoom(w, args_has(args, 'Z'))) + if (window_push_zoom(w, 0, args_has(args, 'Z'))) server_redraw_window(w); window_redraw_active_switch(w, wp); if (c != NULL && c->session != NULL && (c->flags & CLIENT_ACTIVEPANE)) diff --git a/usr.bin/tmux/cmd-split-window.c b/usr.bin/tmux/cmd-split-window.c index a0ed48dcae7..671fdfb1276 100644 --- a/usr.bin/tmux/cmd-split-window.c +++ b/usr.bin/tmux/cmd-split-window.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd-split-window.c,v 1.104 2020/05/16 16:20:59 nicm Exp $ */ +/* $OpenBSD: cmd-split-window.c,v 1.105 2021/03/11 06:31:05 nicm Exp $ */ /* * Copyright (c) 2009 Nicholas Marriott @@ -40,8 +40,8 @@ const struct cmd_entry cmd_split_window_entry = { .name = "split-window", .alias = "splitw", - .args = { "bc:de:fF:hIl:p:Pt:v", 0, -1 }, - .usage = "[-bdefhIPv] [-c start-directory] [-e environment] " + .args = { "bc:de:fF:hIl:p:Pt:vZ", 0, -1 }, + .usage = "[-bdefhIPvZ] [-c start-directory] [-e environment] " "[-F format] [-l size] " CMD_TARGET_PANE_USAGE " [command]", .target = { 't', CMD_FIND_PANE, 0 }, @@ -111,7 +111,7 @@ cmd_split_window_exec(struct cmd *self, struct cmdq_item *item) } else size = -1; - server_unzoom_window(wp->window); + window_push_zoom(wp->window, 1, args_has(args, 'Z')); input = (args_has(args, 'I') && args->argc == 0); flags = 0; @@ -153,6 +153,8 @@ cmd_split_window_exec(struct cmd *self, struct cmdq_item *item) sc.flags = flags; if (args_has(args, 'd')) sc.flags |= SPAWN_DETACHED; + if (args_has(args, 'Z')) + sc.flags |= SPAWN_ZOOM; if ((new_wp = spawn_pane(&sc, &cause)) == NULL) { cmdq_error(item, "create pane failed: %s", cause); @@ -169,6 +171,7 @@ cmd_split_window_exec(struct cmd *self, struct cmdq_item *item) } if (!args_has(args, 'd')) cmd_find_from_winlink_pane(current, wl, new_wp, 0); + window_pop_zoom(wp->window); server_redraw_window(wp->window); server_status_session(s); diff --git a/usr.bin/tmux/cmd-swap-pane.c b/usr.bin/tmux/cmd-swap-pane.c index 04fc89ac84a..511ae6fd815 100644 --- a/usr.bin/tmux/cmd-swap-pane.c +++ b/usr.bin/tmux/cmd-swap-pane.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd-swap-pane.c,v 1.38 2020/05/16 16:20:59 nicm Exp $ */ +/* $OpenBSD: cmd-swap-pane.c,v 1.39 2021/03/11 06:31:05 nicm Exp $ */ /* * Copyright (c) 2009 Nicholas Marriott @@ -58,7 +58,7 @@ cmd_swap_pane_exec(struct cmd *self, struct cmdq_item *item) src_w = source->wl->window; src_wp = source->wp; - if (window_push_zoom(dst_w, args_has(args, 'Z'))) + if (window_push_zoom(dst_w, 0, args_has(args, 'Z'))) server_redraw_window(dst_w); if (args_has(args, 'D')) { @@ -73,7 +73,7 @@ cmd_swap_pane_exec(struct cmd *self, struct cmdq_item *item) src_wp = TAILQ_LAST(&dst_w->panes, window_panes); } - if (src_w != dst_w && window_push_zoom(src_w, args_has(args, 'Z'))) + if (src_w != dst_w && window_push_zoom(src_w, 0, args_has(args, 'Z'))) server_redraw_window(src_w); if (src_wp == dst_wp) diff --git a/usr.bin/tmux/cmd-switch-client.c b/usr.bin/tmux/cmd-switch-client.c index eb027f37571..6502ee81643 100644 --- a/usr.bin/tmux/cmd-switch-client.c +++ b/usr.bin/tmux/cmd-switch-client.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd-switch-client.c,v 1.67 2020/06/05 11:20:51 nicm Exp $ */ +/* $OpenBSD: cmd-switch-client.c,v 1.68 2021/03/11 06:31:05 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -118,7 +118,7 @@ cmd_switch_client_exec(struct cmd *self, struct cmdq_item *item) return (CMD_RETURN_NORMAL); if (wl != NULL && wp != NULL && wp != wl->window->active) { w = wl->window; - if (window_push_zoom(w, args_has(args, 'Z'))) + if (window_push_zoom(w, 0, args_has(args, 'Z'))) server_redraw_window(w); window_redraw_active_switch(w, wp); window_set_active_pane(w, wp, 1); diff --git a/usr.bin/tmux/layout-custom.c b/usr.bin/tmux/layout-custom.c index 0949431059d..7b35bc11bc9 100644 --- a/usr.bin/tmux/layout-custom.c +++ b/usr.bin/tmux/layout-custom.c @@ -1,4 +1,4 @@ -/* $OpenBSD: layout-custom.c,v 1.19 2019/11/28 09:45:15 nicm Exp $ */ +/* $OpenBSD: layout-custom.c,v 1.20 2021/03/11 06:31:05 nicm Exp $ */ /* * Copyright (c) 2010 Nicholas Marriott @@ -233,7 +233,7 @@ layout_parse(struct window *w, const char *layout) /* Update pane offsets and sizes. */ layout_fix_offsets(w); - layout_fix_panes(w); + layout_fix_panes(w, NULL); recalculate_sizes(); layout_print_cell(lc, __func__, 0); diff --git a/usr.bin/tmux/layout-set.c b/usr.bin/tmux/layout-set.c index e551447ce79..e289b690d79 100644 --- a/usr.bin/tmux/layout-set.c +++ b/usr.bin/tmux/layout-set.c @@ -1,4 +1,4 @@ -/* $OpenBSD: layout-set.c,v 1.29 2020/04/22 06:57:13 nicm Exp $ */ +/* $OpenBSD: layout-set.c,v 1.30 2021/03/11 06:31:05 nicm Exp $ */ /* * Copyright (c) 2009 Nicholas Marriott @@ -160,7 +160,7 @@ layout_set_even(struct window *w, enum layout_type type) /* Fix cell offsets. */ layout_fix_offsets(w); - layout_fix_panes(w); + layout_fix_panes(w, NULL); layout_print_cell(w->layout_root, __func__, 1); @@ -270,7 +270,7 @@ layout_set_main_h(struct window *w) /* Fix cell offsets. */ layout_fix_offsets(w); - layout_fix_panes(w); + layout_fix_panes(w, NULL); layout_print_cell(w->layout_root, __func__, 1); @@ -368,7 +368,7 @@ layout_set_main_v(struct window *w) /* Fix cell offsets. */ layout_fix_offsets(w); - layout_fix_panes(w); + layout_fix_panes(w, NULL); layout_print_cell(w->layout_root, __func__, 1); @@ -477,7 +477,7 @@ layout_set_tiled(struct window *w) /* Fix cell offsets. */ layout_fix_offsets(w); - layout_fix_panes(w); + layout_fix_panes(w, NULL); layout_print_cell(w->layout_root, __func__, 1); diff --git a/usr.bin/tmux/layout.c b/usr.bin/tmux/layout.c index e14e7786d7a..33d680d37fa 100644 --- a/usr.bin/tmux/layout.c +++ b/usr.bin/tmux/layout.c @@ -1,4 +1,4 @@ -/* $OpenBSD: layout.c,v 1.47 2019/07/15 18:43:32 nicm Exp $ */ +/* $OpenBSD: layout.c,v 1.48 2021/03/11 06:31:05 nicm Exp $ */ /* * Copyright (c) 2009 Nicholas Marriott @@ -286,7 +286,7 @@ layout_add_border(struct window *w, struct layout_cell *lc, int status) /* Update pane offsets and sizes based on their cells. */ void -layout_fix_panes(struct window *w) +layout_fix_panes(struct window *w, struct window_pane *skip) { struct window_pane *wp; struct layout_cell *lc; @@ -294,7 +294,7 @@ layout_fix_panes(struct window *w) status = options_get_number(w->options, "pane-border-status"); TAILQ_FOREACH(wp, &w->panes, entry) { - if ((lc = wp->layout_cell) == NULL) + if ((lc = wp->layout_cell) == NULL || wp == skip) continue; wp->xoff = lc->xoff; @@ -482,7 +482,7 @@ layout_init(struct window *w, struct window_pane *wp) lc = w->layout_root = layout_create_cell(NULL); layout_set_size(lc, w->sx, w->sy, 0, 0); layout_make_leaf(lc, wp); - layout_fix_panes(w); + layout_fix_panes(w, NULL); } void @@ -540,7 +540,7 @@ layout_resize(struct window *w, u_int sx, u_int sy) /* Fix cell offsets. */ layout_fix_offsets(w); - layout_fix_panes(w); + layout_fix_panes(w, NULL); } /* Resize a pane to an absolute size. */ @@ -600,7 +600,7 @@ layout_resize_layout(struct window *w, struct layout_cell *lc, /* Fix cell offsets. */ layout_fix_offsets(w); - layout_fix_panes(w); + layout_fix_panes(w, NULL); notify_window("window-layout-changed", w); } @@ -704,10 +704,14 @@ layout_resize_pane_shrink(struct window *w, struct layout_cell *lc, /* Assign window pane to newly split cell. */ void -layout_assign_pane(struct layout_cell *lc, struct window_pane *wp) +layout_assign_pane(struct layout_cell *lc, struct window_pane *wp, + int do_not_resize) { layout_make_leaf(lc, wp); - layout_fix_panes(wp->window); + if (do_not_resize) + layout_fix_panes(wp->window, wp); + else + layout_fix_panes(wp->window, NULL); } /* Calculate the new pane size for resized parent. */ @@ -1040,7 +1044,7 @@ layout_close_pane(struct window_pane *wp) /* Fix pane offsets and sizes. */ if (w->layout_root != NULL) { layout_fix_offsets(w); - layout_fix_panes(w); + layout_fix_panes(w, NULL); } notify_window("window-layout-changed", w); } @@ -1109,7 +1113,7 @@ layout_spread_out(struct window_pane *wp) do { if (layout_spread_cell(w, parent)) { layout_fix_offsets(w); - layout_fix_panes(w); + layout_fix_panes(w, NULL); break; } } while ((parent = parent->parent) != NULL); diff --git a/usr.bin/tmux/options.c b/usr.bin/tmux/options.c index 7773ad55edf..87be58aa7b2 100644 --- a/usr.bin/tmux/options.c +++ b/usr.bin/tmux/options.c @@ -1,4 +1,4 @@ -/* $OpenBSD: options.c,v 1.61 2021/01/18 11:14:23 nicm Exp $ */ +/* $OpenBSD: options.c,v 1.62 2021/03/11 06:31:05 nicm Exp $ */ /* * Copyright (c) 2008 Nicholas Marriott @@ -1115,7 +1115,7 @@ options_push_changes(const char *name) } if (strcmp(name, "pane-border-status") == 0) { RB_FOREACH(w, windows, &windows) - layout_fix_panes(w); + layout_fix_panes(w, NULL); } RB_FOREACH(s, sessions, &sessions) status_update_cache(s); diff --git a/usr.bin/tmux/spawn.c b/usr.bin/tmux/spawn.c index d44420fa6e8..9317edf2938 100644 --- a/usr.bin/tmux/spawn.c +++ b/usr.bin/tmux/spawn.c @@ -1,4 +1,4 @@ -/* $OpenBSD: spawn.c,v 1.27 2021/03/02 11:00:38 nicm Exp $ */ +/* $OpenBSD: spawn.c,v 1.28 2021/03/11 06:31:05 nicm Exp $ */ /* * Copyright (c) 2019 Nicholas Marriott @@ -261,7 +261,10 @@ spawn_pane(struct spawn_context *sc, char **cause) layout_init(w, new_wp); } else { new_wp = window_add_pane(w, sc->wp0, hlimit, sc->flags); - layout_assign_pane(sc->lc, new_wp); + if (sc->flags & SPAWN_ZOOM) + layout_assign_pane(sc->lc, new_wp, 1); + else + layout_assign_pane(sc->lc, new_wp, 0); } /* diff --git a/usr.bin/tmux/tmux.1 b/usr.bin/tmux/tmux.1 index 76d3970ddef..f4b30ea383f 100644 --- a/usr.bin/tmux/tmux.1 +++ b/usr.bin/tmux/tmux.1 @@ -1,4 +1,4 @@ -.\" $OpenBSD: tmux.1,v 1.827 2021/03/02 10:56:45 nicm Exp $ +.\" $OpenBSD: tmux.1,v 1.828 2021/03/11 06:31:05 nicm Exp $ .\" .\" Copyright (c) 2007 Nicholas Marriott .\" @@ -14,7 +14,7 @@ .\" IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING .\" OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. .\" -.Dd $Mdocdate: March 2 2021 $ +.Dd $Mdocdate: March 11 2021 $ .Dt TMUX 1 .Os .Sh NAME @@ -2804,7 +2804,7 @@ is given and the selected window is already the current window, the command behaves like .Ic last-window . .It Xo Ic split-window -.Op Fl bdfhIvP +.Op Fl bdfhIvPZ .Op Fl c Ar start-directory .Op Fl e Ar environment .Op Fl l Ar size @@ -2840,6 +2840,8 @@ option creates a new pane spanning the full window height (with or full window width (with .Fl v ) , instead of splitting the active pane. +.Fl Z +zooms if the window is not zoomed, or keeps it zoomed if already zoomed. .Pp An empty .Ar shell-command diff --git a/usr.bin/tmux/tmux.h b/usr.bin/tmux/tmux.h index 2b4071e9fe8..c42b52f9e30 100644 --- a/usr.bin/tmux/tmux.h +++ b/usr.bin/tmux/tmux.h @@ -1,4 +1,4 @@ -/* $OpenBSD: tmux.h,v 1.1096 2021/03/02 10:56:45 nicm Exp $ */ +/* $OpenBSD: tmux.h,v 1.1097 2021/03/11 06:31:05 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -1862,6 +1862,7 @@ struct spawn_context { #define SPAWN_NONOTIFY 0x10 #define SPAWN_FULLSIZE 0x20 #define SPAWN_EMPTY 0x40 +#define SPAWN_ZOOM 0x80 }; /* Mode tree sort order. */ @@ -2752,7 +2753,7 @@ void window_resize(struct window *, u_int, u_int, int, int); void window_pane_send_resize(struct window_pane *, int); int window_zoom(struct window_pane *); int window_unzoom(struct window *); -int window_push_zoom(struct window *, int); +int window_push_zoom(struct window *, int, int); int window_pop_zoom(struct window *); void window_lost_pane(struct window *, struct window_pane *); void window_remove_pane(struct window *, struct window_pane *); @@ -2815,7 +2816,7 @@ void layout_set_size(struct layout_cell *, u_int, u_int, u_int, void layout_make_leaf(struct layout_cell *, struct window_pane *); void layout_make_node(struct layout_cell *, enum layout_type); void layout_fix_offsets(struct window *); -void layout_fix_panes(struct window *); +void layout_fix_panes(struct window *, struct window_pane *); void layout_resize_adjust(struct window *, struct layout_cell *, enum layout_type, int); void layout_init(struct window *, struct window_pane *); @@ -2825,7 +2826,8 @@ void layout_resize_pane(struct window_pane *, enum layout_type, int, int); void layout_resize_pane_to(struct window_pane *, enum layout_type, u_int); -void layout_assign_pane(struct layout_cell *, struct window_pane *); +void layout_assign_pane(struct layout_cell *, struct window_pane *, + int); struct layout_cell *layout_split_pane(struct window_pane *, enum layout_type, int, int); void layout_close_pane(struct window_pane *); diff --git a/usr.bin/tmux/window.c b/usr.bin/tmux/window.c index 0633425979c..fdede321808 100644 --- a/usr.bin/tmux/window.c +++ b/usr.bin/tmux/window.c @@ -1,4 +1,4 @@ -/* $OpenBSD: window.c,v 1.269 2021/02/22 07:09:06 nicm Exp $ */ +/* $OpenBSD: window.c,v 1.270 2021/03/11 06:31:05 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -622,18 +622,18 @@ window_unzoom(struct window *w) wp->layout_cell = wp->saved_layout_cell; wp->saved_layout_cell = NULL; } - layout_fix_panes(w); + layout_fix_panes(w, NULL); notify_window("window-layout-changed", w); return (0); } int -window_push_zoom(struct window *w, int flag) +window_push_zoom(struct window *w, int always, int flag) { log_debug("%s: @%u %d", __func__, w->id, flag && (w->flags & WINDOW_ZOOMED)); - if (flag && (w->flags & WINDOW_ZOOMED)) + if (flag && (always || (w->flags & WINDOW_ZOOMED))) w->flags |= WINDOW_WASZOOMED; else w->flags &= ~WINDOW_WASZOOMED; -- 2.20.1