summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornicm <nicm@openbsd.org>2019-08-14 09:58:31 +0000
committernicm <nicm@openbsd.org>2019-08-14 09:58:31 +0000
commit721430b8288e74bbeac1cb8345e4ce56de62f552 (patch)
tree67b171c39b7eabc763236a820fe12b1917d4b8d4
parentFix NAT traversal detection bug when "local" option is not explicitly (diff)
downloadwireguard-openbsd-721430b8288e74bbeac1cb8345e4ce56de62f552.tar.xz
wireguard-openbsd-721430b8288e74bbeac1cb8345e4ce56de62f552.zip
Add -Z flag to rotate-window, select-pane, swap-pane, switch-client to
preserve zoomed state. GitHub issue 1839.
-rw-r--r--usr.bin/tmux/cmd-rotate-window.c19
-rw-r--r--usr.bin/tmux/cmd-select-pane.c32
-rw-r--r--usr.bin/tmux/cmd-swap-pane.c28
-rw-r--r--usr.bin/tmux/cmd-switch-client.c21
-rw-r--r--usr.bin/tmux/tmux.129
-rw-r--r--usr.bin/tmux/tmux.h5
-rw-r--r--usr.bin/tmux/window-copy.c15
-rw-r--r--usr.bin/tmux/window.c24
8 files changed, 117 insertions, 56 deletions
diff --git a/usr.bin/tmux/cmd-rotate-window.c b/usr.bin/tmux/cmd-rotate-window.c
index 433605a1622..0625902d740 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.26 2019/04/17 14:37:48 nicm Exp $ */
+/* $OpenBSD: cmd-rotate-window.c,v 1.27 2019/08/14 09:58:31 nicm Exp $ */
/*
* Copyright (c) 2009 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -31,8 +31,8 @@ const struct cmd_entry cmd_rotate_window_entry = {
.name = "rotate-window",
.alias = "rotatew",
- .args = { "Dt:U", 0, 0 },
- .usage = "[-DU] " CMD_TARGET_WINDOW_USAGE,
+ .args = { "Dt:UZ", 0, 0 },
+ .usage = "[-DUZ] " CMD_TARGET_WINDOW_USAGE,
.target = { 't', CMD_FIND_WINDOW, 0 },
@@ -50,7 +50,7 @@ cmd_rotate_window_exec(struct cmd *self, struct cmdq_item *item)
struct layout_cell *lc;
u_int sx, sy, xoff, yoff;
- server_unzoom_window(w);
+ window_push_zoom(w, args_has(self->args, 'Z'));
if (args_has(self->args, 'D')) {
wp = TAILQ_LAST(&w->panes, window_panes);
@@ -77,9 +77,6 @@ cmd_rotate_window_exec(struct cmd *self, struct cmdq_item *item)
if ((wp = TAILQ_PREV(w->active, window_panes, entry)) == NULL)
wp = TAILQ_LAST(&w->panes, window_panes);
- window_set_active_pane(w, wp, 1);
- cmd_find_from_winlink_pane(current, wl, wp, 0);
- server_redraw_window(w);
} else {
wp = TAILQ_FIRST(&w->panes);
TAILQ_REMOVE(&w->panes, wp, entry);
@@ -105,10 +102,12 @@ cmd_rotate_window_exec(struct cmd *self, struct cmdq_item *item)
if ((wp = TAILQ_NEXT(w->active, entry)) == NULL)
wp = TAILQ_FIRST(&w->panes);
- window_set_active_pane(w, wp, 1);
- cmd_find_from_winlink_pane(current, wl, wp, 0);
- server_redraw_window(w);
}
+ window_set_active_pane(w, wp, 1);
+ cmd_find_from_winlink_pane(current, wl, wp, 0);
+ window_pop_zoom(w);
+ server_redraw_window(w);
+
return (CMD_RETURN_NORMAL);
}
diff --git a/usr.bin/tmux/cmd-select-pane.c b/usr.bin/tmux/cmd-select-pane.c
index c74b6715531..c643c934ff7 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.51 2019/06/20 11:59:59 nicm Exp $ */
+/* $OpenBSD: cmd-select-pane.c,v 1.52 2019/08/14 09:58:31 nicm Exp $ */
/*
* Copyright (c) 2009 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -33,8 +33,8 @@ const struct cmd_entry cmd_select_pane_entry = {
.name = "select-pane",
.alias = "selectp",
- .args = { "DdegLlMmP:RT:t:U", 0, 0 }, /* -P and -g deprecated */
- .usage = "[-DdeLlMmRU] [-T title] " CMD_TARGET_PANE_USAGE,
+ .args = { "DdegLlMmP:RT:t:UZ", 0, 0 }, /* -P and -g deprecated */
+ .usage = "[-DdeLlMmRUZ] [-T title] " CMD_TARGET_PANE_USAGE,
.target = { 't', CMD_FIND_PANE, 0 },
@@ -46,8 +46,8 @@ const struct cmd_entry cmd_last_pane_entry = {
.name = "last-pane",
.alias = "lastp",
- .args = { "det:", 0, 0 },
- .usage = "[-de] " CMD_TARGET_WINDOW_USAGE,
+ .args = { "det:Z", 0, 0 },
+ .usage = "[-deZ] " CMD_TARGET_WINDOW_USAGE,
.target = { 't', CMD_FIND_WINDOW, 0 },
@@ -111,12 +111,15 @@ cmd_select_pane_exec(struct cmd *self, struct cmdq_item *item)
else if (args_has(self->args, 'd'))
lastwp->flags |= PANE_INPUTOFF;
else {
- server_unzoom_window(w);
+ if (window_push_zoom(w, args_has(self->args, 'Z')))
+ server_redraw_window(w);
window_redraw_active_switch(w, lastwp);
if (window_set_active_pane(w, lastwp, 1)) {
cmd_find_from_winlink(current, wl, 0);
cmd_select_pane_redraw(w);
}
+ if (window_pop_zoom(w))
+ server_redraw_window(w);
}
return (CMD_RETURN_NORMAL);
}
@@ -161,17 +164,21 @@ cmd_select_pane_exec(struct cmd *self, struct cmdq_item *item)
}
if (args_has(self->args, 'L')) {
- server_unzoom_window(wp->window);
+ window_push_zoom(w, 1);
wp = window_pane_find_left(wp);
+ window_pop_zoom(w);
} else if (args_has(self->args, 'R')) {
- server_unzoom_window(wp->window);
+ window_push_zoom(w, 1);
wp = window_pane_find_right(wp);
+ window_pop_zoom(w);
} else if (args_has(self->args, 'U')) {
- server_unzoom_window(wp->window);
+ window_push_zoom(w, 1);
wp = window_pane_find_up(wp);
+ window_pop_zoom(w);
} else if (args_has(self->args, 'D')) {
- server_unzoom_window(wp->window);
+ window_push_zoom(w, 1);
wp = window_pane_find_down(wp);
+ window_pop_zoom(w);
}
if (wp == NULL)
return (CMD_RETURN_NORMAL);
@@ -196,13 +203,16 @@ cmd_select_pane_exec(struct cmd *self, struct cmdq_item *item)
if (wp == w->active)
return (CMD_RETURN_NORMAL);
- server_unzoom_window(wp->window);
+ if (window_push_zoom(w, args_has(self->args, 'Z')))
+ server_redraw_window(w);
window_redraw_active_switch(w, wp);
if (window_set_active_pane(w, wp, 1)) {
cmd_find_from_winlink_pane(current, wl, wp, 0);
cmdq_insert_hook(s, item, current, "after-select-pane");
cmd_select_pane_redraw(w);
}
+ if (window_pop_zoom(w))
+ server_redraw_window(w);
return (CMD_RETURN_NORMAL);
}
diff --git a/usr.bin/tmux/cmd-swap-pane.c b/usr.bin/tmux/cmd-swap-pane.c
index 6eafcf2b77d..87100b7c1e1 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.34 2019/06/20 11:59:59 nicm Exp $ */
+/* $OpenBSD: cmd-swap-pane.c,v 1.35 2019/08/14 09:58:31 nicm Exp $ */
/*
* Copyright (c) 2009 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -32,8 +32,8 @@ const struct cmd_entry cmd_swap_pane_entry = {
.name = "swap-pane",
.alias = "swapp",
- .args = { "dDs:t:U", 0, 0 },
- .usage = "[-dDU] " CMD_SRCDST_PANE_USAGE,
+ .args = { "dDs:t:UZ", 0, 0 },
+ .usage = "[-dDUZ] " CMD_SRCDST_PANE_USAGE,
.source = { 's', CMD_FIND_PANE, CMD_FIND_DEFAULT_MARKED },
.target = { 't', CMD_FIND_PANE, 0 },
@@ -45,6 +45,7 @@ const struct cmd_entry cmd_swap_pane_entry = {
static enum cmd_retval
cmd_swap_pane_exec(struct cmd *self, struct cmdq_item *item)
{
+ struct args *args = self->args;
struct window *src_w, *dst_w;
struct window_pane *tmp_wp, *src_wp, *dst_wp;
struct layout_cell *src_lc, *dst_lc;
@@ -54,23 +55,27 @@ cmd_swap_pane_exec(struct cmd *self, struct cmdq_item *item)
dst_wp = item->target.wp;
src_w = item->source.wl->window;
src_wp = item->source.wp;
- server_unzoom_window(dst_w);
- if (args_has(self->args, 'D')) {
+ if (window_push_zoom(dst_w, args_has(args, 'Z')))
+ server_redraw_window(dst_w);
+
+ if (args_has(args, 'D')) {
src_w = dst_w;
src_wp = TAILQ_NEXT(dst_wp, entry);
if (src_wp == NULL)
src_wp = TAILQ_FIRST(&dst_w->panes);
- } else if (args_has(self->args, 'U')) {
+ } else if (args_has(args, 'U')) {
src_w = dst_w;
src_wp = TAILQ_PREV(dst_wp, window_panes, entry);
if (src_wp == NULL)
src_wp = TAILQ_LAST(&dst_w->panes, window_panes);
}
- server_unzoom_window(src_w);
+
+ if (src_w != dst_w && window_push_zoom(src_w, args_has(args, 'Z')))
+ server_redraw_window(src_w);
if (src_wp == dst_wp)
- return (CMD_RETURN_NORMAL);
+ goto out;
tmp_wp = TAILQ_PREV(dst_wp, window_panes, entry);
TAILQ_REMOVE(&dst_w->panes, dst_wp, entry);
@@ -103,7 +108,7 @@ cmd_swap_pane_exec(struct cmd *self, struct cmdq_item *item)
dst_wp->xoff = xoff; dst_wp->yoff = yoff;
window_pane_resize(dst_wp, sx, sy);
- if (!args_has(self->args, 'd')) {
+ if (!args_has(args, 'd')) {
if (src_w != dst_w) {
window_set_active_pane(src_w, dst_wp, 1);
window_set_active_pane(dst_w, src_wp, 1);
@@ -126,5 +131,10 @@ cmd_swap_pane_exec(struct cmd *self, struct cmdq_item *item)
server_redraw_window(src_w);
server_redraw_window(dst_w);
+out:
+ if (window_pop_zoom(src_w))
+ server_redraw_window(src_w);
+ if (src_w != dst_w && window_pop_zoom(dst_w))
+ server_redraw_window(dst_w);
return (CMD_RETURN_NORMAL);
}
diff --git a/usr.bin/tmux/cmd-switch-client.c b/usr.bin/tmux/cmd-switch-client.c
index 0978129cc54..a2f2a1db5c2 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.57 2019/04/17 14:39:37 nicm Exp $ */
+/* $OpenBSD: cmd-switch-client.c,v 1.58 2019/08/14 09:58:31 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -34,8 +34,8 @@ const struct cmd_entry cmd_switch_client_entry = {
.name = "switch-client",
.alias = "switchc",
- .args = { "lc:Enpt:rT:", 0, 0 },
- .usage = "[-Elnpr] [-c target-client] [-t target-session] "
+ .args = { "lc:Enpt:rT:Z", 0, 0 },
+ .usage = "[-ElnprZ] [-c target-client] [-t target-session] "
"[-T key-table]",
/* -t is special */
@@ -54,6 +54,7 @@ cmd_switch_client_exec(struct cmd *self, struct cmdq_item *item)
struct client *c;
struct session *s;
struct winlink *wl;
+ struct window *w;
struct window_pane *wp;
const char *tablename;
struct key_table *table;
@@ -72,6 +73,7 @@ cmd_switch_client_exec(struct cmd *self, struct cmdq_item *item)
return (CMD_RETURN_ERROR);
s = item->target.s;
wl = item->target.wl;
+ w = wl->window;
wp = item->target.wp;
if (args_has(args, 'r'))
@@ -112,12 +114,15 @@ cmd_switch_client_exec(struct cmd *self, struct cmdq_item *item)
} else {
if (item->client == NULL)
return (CMD_RETURN_NORMAL);
+ if (wl != NULL && wp != NULL) {
+ if (window_push_zoom(w, args_has(self->args, 'Z')))
+ server_redraw_window(w);
+ window_redraw_active_switch(w, wp);
+ window_set_active_pane(w, wp, 1);
+ if (window_pop_zoom(w))
+ server_redraw_window(w);
+ }
if (wl != NULL) {
- server_unzoom_window(wl->window);
- if (wp != NULL) {
- window_redraw_active_switch(wp->window, wp);
- window_set_active_pane(wp->window, wp, 1);
- }
session_set_current(s, wl);
cmd_find_from_session(&item->shared->current, s, 0);
}
diff --git a/usr.bin/tmux/tmux.1 b/usr.bin/tmux/tmux.1
index 937667235dc..5f80438b906 100644
--- a/usr.bin/tmux/tmux.1
+++ b/usr.bin/tmux/tmux.1
@@ -1,4 +1,4 @@
-.\" $OpenBSD: tmux.1,v 1.680 2019/08/01 08:42:34 nicm Exp $
+.\" $OpenBSD: tmux.1,v 1.681 2019/08/14 09:58:31 nicm Exp $
.\"
.\" Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
.\"
@@ -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: August 1 2019 $
+.Dd $Mdocdate: August 14 2019 $
.Dt TMUX 1
.Os
.Sh NAME
@@ -1291,7 +1291,7 @@ Suspend a client by sending
.Dv SIGTSTP
(tty stop).
.It Xo Ic switch-client
-.Op Fl Elnpr
+.Op Fl ElnprZ
.Op Fl c Ar target-client
.Op Fl t Ar target-session
.Op Fl T Ar key-table
@@ -1308,7 +1308,10 @@ may refer to a pane (a target that contains
.Ql \&.
or
.Ql % ) ,
-in which case the session, window and pane are all changed.
+to change session, window and pane.
+In that case,
+.Fl Z
+keeps the window zoomed if it was zoomed.
If
.Fl l ,
.Fl n
@@ -1934,11 +1937,13 @@ The
option kills all but the window given with
.Fl t .
.It Xo Ic last-pane
-.Op Fl de
+.Op Fl deZ
.Op Fl t Ar target-window
.Xc
.D1 (alias: Ic lastp )
Select the last (previously selected) pane.
+.Fl Z
+keeps the window zoomed if it was zoomed.
.Fl e
enables or
.Fl d
@@ -2320,7 +2325,7 @@ option has the same meaning as for the
.Ic new-window
command.
.It Xo Ic rotate-window
-.Op Fl DU
+.Op Fl DUZ
.Op Fl t Ar target-window
.Xc
.D1 (alias: Ic rotatew )
@@ -2328,6 +2333,8 @@ Rotate the positions of the panes within a window, either upward (numerically
lower) with
.Fl U
or downward (numerically higher).
+.Fl Z
+keeps the window zoomed if it was zoomed.
.It Xo Ic select-layout
.Op Fl Enop
.Op Fl t Ar target-pane
@@ -2351,7 +2358,7 @@ applies the last set layout if possible (undoes the most recent layout change).
.Fl E
spreads the current pane and any panes next to it out evenly.
.It Xo Ic select-pane
-.Op Fl DdeLlMmRU
+.Op Fl DdeLlMmRUZ
.Op Fl T Ar title
.Op Fl t Ar target-pane
.Xc
@@ -2368,6 +2375,8 @@ or
.Fl U
is used, respectively the pane below, to the left, to the right, or above the
target pane is used.
+.Fl Z
+keeps the window zoomed if it was zoomed.
.Fl l
is the same as using the
.Ic last-pane
@@ -2473,7 +2482,7 @@ All other options have the same meaning as for the
.Ic new-window
command.
.It Xo Ic swap-pane
-.Op Fl dDU
+.Op Fl dDUZ
.Op Fl s Ar src-pane
.Op Fl t Ar dst-pane
.Xc
@@ -2490,7 +2499,9 @@ swaps with the next pane (after it numerically).
.Fl d
instructs
.Nm
-not to change the active pane.
+not to change the active pane and
+.Fl Z
+keeps the window zoomed if it was zoomed.
.Pp
If
.Fl s
diff --git a/usr.bin/tmux/tmux.h b/usr.bin/tmux/tmux.h
index fc5884e5298..2542e96f818 100644
--- a/usr.bin/tmux/tmux.h
+++ b/usr.bin/tmux/tmux.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: tmux.h,v 1.923 2019/08/05 06:42:02 nicm Exp $ */
+/* $OpenBSD: tmux.h,v 1.924 2019/08/14 09:58:31 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -922,6 +922,7 @@ struct window {
#define WINDOW_ACTIVITY 0x2
#define WINDOW_SILENCE 0x4
#define WINDOW_ZOOMED 0x8
+#define WINDOW_WASZOOMED 0x10
#define WINDOW_ALERTFLAGS (WINDOW_BELL|WINDOW_ACTIVITY|WINDOW_SILENCE)
int alerts_queued;
@@ -2381,6 +2382,8 @@ struct window_pane *window_add_pane(struct window *, struct window_pane *,
void window_resize(struct window *, u_int, u_int);
int window_zoom(struct window_pane *);
int window_unzoom(struct window *);
+int window_push_zoom(struct window *, 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 *);
struct window_pane *window_pane_at_index(struct window *, u_int);
diff --git a/usr.bin/tmux/window-copy.c b/usr.bin/tmux/window-copy.c
index 8ef403cfe3d..b4b7bb88c98 100644
--- a/usr.bin/tmux/window-copy.c
+++ b/usr.bin/tmux/window-copy.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: window-copy.c,v 1.230 2019/08/01 14:31:39 nicm Exp $ */
+/* $OpenBSD: window-copy.c,v 1.231 2019/08/14 09:58:31 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -1638,9 +1638,11 @@ window_copy_cmd_search_backward(struct window_copy_cmd_state *cs)
const char *argument = cs->args->argv[1];
if (*argument != '\0') {
- data->searchtype = WINDOW_COPY_SEARCHUP;
free(data->searchstr);
data->searchstr = xstrdup(argument);
+ }
+ if (data->searchstr != NULL) {
+ data->searchtype = WINDOW_COPY_SEARCHUP;
for (; np != 0; np--)
window_copy_search_up(wme);
}
@@ -1656,9 +1658,11 @@ window_copy_cmd_search_forward(struct window_copy_cmd_state *cs)
const char *argument = cs->args->argv[1];
if (*argument != '\0') {
- data->searchtype = WINDOW_COPY_SEARCHDOWN;
free(data->searchstr);
data->searchstr = xstrdup(argument);
+ }
+ if (data->searchstr != NULL) {
+ data->searchtype = WINDOW_COPY_SEARCHDOWN;
for (; np != 0; np--)
window_copy_search_down(wme);
}
@@ -2139,10 +2143,7 @@ window_copy_search_jump(struct window_mode_entry *wme, struct grid *gd,
return (0);
}
-/*
- * Search in for text searchstr. If direction is 0 then search up, otherwise
- * down.
- */
+/* Search in text. If direction is 0 then search up, otherwise down. */
static int
window_copy_search(struct window_mode_entry *wme, int direction)
{
diff --git a/usr.bin/tmux/window.c b/usr.bin/tmux/window.c
index 2a97b40c35a..d32f96489cd 100644
--- a/usr.bin/tmux/window.c
+++ b/usr.bin/tmux/window.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: window.c,v 1.240 2019/06/30 19:21:53 nicm Exp $ */
+/* $OpenBSD: window.c,v 1.241 2019/08/14 09:58:31 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -587,6 +587,28 @@ window_unzoom(struct window *w)
return (0);
}
+int
+window_push_zoom(struct window *w, int flag)
+{
+ log_debug("%s: @%u %d", __func__, w->id,
+ flag && (w->flags & WINDOW_ZOOMED));
+ if (flag && (w->flags & WINDOW_ZOOMED))
+ w->flags |= WINDOW_WASZOOMED;
+ else
+ w->flags &= ~WINDOW_WASZOOMED;
+ return (window_unzoom(w) == 0);
+}
+
+int
+window_pop_zoom(struct window *w)
+{
+ log_debug("%s: @%u %d", __func__, w->id,
+ !!(w->flags & WINDOW_WASZOOMED));
+ if (w->flags & WINDOW_WASZOOMED)
+ return (window_zoom(w->active) == 0);
+ return (0);
+}
+
struct window_pane *
window_add_pane(struct window *w, struct window_pane *other, u_int hlimit,
int flags)