mirror of
https://github.com/tmux/tmux.git
synced 2025-04-05 23:58:58 +00:00
Add resize-pane -Z to temporary zoom the active pane to occupy the full
window or unzoom (restored to the normal layout) if it already zoomed, bound to C-b z by default. The pane is unzoomed on pretty much any excuse whatsoever. We considered making this a new layout but the requirements are quite different from layouts so decided it is better as a special case. Each current layout cell is saved, a temporary one-cell layout generated and all except the active pane set to NULL. Prompted by suggestions and scripts from several. Thanks to Aaron Jensen and Thiago Padilha for testing an earlier version.
This commit is contained in:
parent
a05b8c4143
commit
c71844de63
@ -63,6 +63,8 @@ cmd_break_pane_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
}
|
||||
|
||||
w = wl->window;
|
||||
server_unzoom_window(w);
|
||||
|
||||
TAILQ_REMOVE(&w->panes, wp, entry);
|
||||
if (wp == w->active) {
|
||||
w->active = w->last;
|
||||
@ -82,7 +84,7 @@ cmd_break_pane_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
name = default_window_name(w);
|
||||
window_set_name(w, name);
|
||||
free(name);
|
||||
layout_init(w);
|
||||
layout_init(w, wp);
|
||||
|
||||
base_idx = options_get_number(&s->options, "base-index");
|
||||
wl = session_attach(s, w, -1 - base_idx, &cause); /* can't fail */
|
||||
|
@ -92,11 +92,13 @@ join_pane(struct cmd *self, struct cmd_q *cmdq, int not_same_window)
|
||||
return (CMD_RETURN_ERROR);
|
||||
dst_w = dst_wl->window;
|
||||
dst_idx = dst_wl->idx;
|
||||
server_unzoom_window(dst_w);
|
||||
|
||||
src_wl = cmd_find_pane(cmdq, args_get(args, 's'), NULL, &src_wp);
|
||||
if (src_wl == NULL)
|
||||
return (CMD_RETURN_ERROR);
|
||||
src_w = src_wl->window;
|
||||
server_unzoom_window(src_w);
|
||||
|
||||
if (not_same_window && src_w == dst_w) {
|
||||
cmdq_error(cmdq, "can't join a pane to its own window");
|
||||
|
@ -47,6 +47,7 @@ cmd_kill_pane_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
|
||||
if ((wl = cmd_find_pane(cmdq, args_get(args, 't'), NULL, &wp)) == NULL)
|
||||
return (CMD_RETURN_ERROR);
|
||||
server_unzoom_window(wl->window);
|
||||
|
||||
if (window_count_panes(wl->window) == 1) {
|
||||
/* Only one pane, kill the window. */
|
||||
|
@ -31,8 +31,8 @@ enum cmd_retval cmd_resize_pane_exec(struct cmd *, struct cmd_q *);
|
||||
|
||||
const struct cmd_entry cmd_resize_pane_entry = {
|
||||
"resize-pane", "resizep",
|
||||
"DLRt:Ux:y:", 0, 1,
|
||||
"[-DLRU] [-x width] [-y height] " CMD_TARGET_PANE_USAGE " [adjustment]",
|
||||
"DLRt:Ux:y:Z", 0, 1,
|
||||
"[-DLRUZ] [-x width] [-y height] " CMD_TARGET_PANE_USAGE " [adjustment]",
|
||||
0,
|
||||
cmd_resize_pane_key_binding,
|
||||
NULL,
|
||||
@ -75,6 +75,10 @@ cmd_resize_pane_key_binding(struct cmd *self, int key)
|
||||
self->args = args_create(1, "5");
|
||||
args_set(self->args, 'R', NULL);
|
||||
break;
|
||||
case 'z':
|
||||
self->args = args_create(0);
|
||||
args_set(self->args, 'Z', NULL);
|
||||
break;
|
||||
default:
|
||||
self->args = args_create(0);
|
||||
break;
|
||||
@ -86,6 +90,7 @@ cmd_resize_pane_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
{
|
||||
struct args *args = self->args;
|
||||
struct winlink *wl;
|
||||
struct window *w;
|
||||
const char *errstr;
|
||||
char *cause;
|
||||
struct window_pane *wp;
|
||||
@ -94,6 +99,18 @@ cmd_resize_pane_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
|
||||
if ((wl = cmd_find_pane(cmdq, args_get(args, 't'), NULL, &wp)) == NULL)
|
||||
return (CMD_RETURN_ERROR);
|
||||
w = wl->window;
|
||||
|
||||
if (args_has(args, 'Z')) {
|
||||
if (w->flags & WINDOW_ZOOMED)
|
||||
window_unzoom(w);
|
||||
else
|
||||
window_zoom(wp);
|
||||
server_redraw_window(w);
|
||||
server_status_window(w);
|
||||
return (CMD_RETURN_NORMAL);
|
||||
}
|
||||
server_unzoom_window(w);
|
||||
|
||||
if (args->argc == 0)
|
||||
adjust = 1;
|
||||
|
@ -87,7 +87,7 @@ cmd_respawn_window_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
server_destroy_pane(wp);
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
layout_init(w);
|
||||
layout_init(w, wp);
|
||||
window_pane_reset_mode(wp);
|
||||
screen_reinit(&wp->base);
|
||||
input_init(wp);
|
||||
|
@ -92,6 +92,7 @@ cmd_select_layout_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
|
||||
if ((wl = cmd_find_window(cmdq, args_get(args, 't'), NULL)) == NULL)
|
||||
return (CMD_RETURN_ERROR);
|
||||
server_unzoom_window(wl->window);
|
||||
|
||||
next = self->entry == &cmd_next_layout_entry;
|
||||
if (args_has(self->args, 'n'))
|
||||
|
@ -80,6 +80,7 @@ cmd_select_pane_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
return (CMD_RETURN_ERROR);
|
||||
}
|
||||
|
||||
server_unzoom_window(wl->window);
|
||||
window_set_active_pane(wl->window, wl->window->last);
|
||||
server_status_window(wl->window);
|
||||
server_redraw_window_borders(wl->window);
|
||||
@ -90,6 +91,7 @@ cmd_select_pane_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
if ((wl = cmd_find_pane(cmdq, args_get(args, 't'), NULL, &wp)) == NULL)
|
||||
return (CMD_RETURN_ERROR);
|
||||
|
||||
server_unzoom_window(wp->window);
|
||||
if (!window_pane_visible(wp)) {
|
||||
cmdq_error(cmdq, "pane not visible");
|
||||
return (CMD_RETURN_ERROR);
|
||||
|
@ -73,6 +73,7 @@ cmd_split_window_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
if ((wl = cmd_find_pane(cmdq, args_get(args, 't'), &s, &wp)) == NULL)
|
||||
return (CMD_RETURN_ERROR);
|
||||
w = wl->window;
|
||||
server_unzoom_window(w);
|
||||
|
||||
environ_init(&env);
|
||||
environ_copy(&global_environ, &env);
|
||||
|
@ -63,6 +63,7 @@ cmd_swap_pane_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
if (dst_wl == NULL)
|
||||
return (CMD_RETURN_ERROR);
|
||||
dst_w = dst_wl->window;
|
||||
server_unzoom_window(dst_w);
|
||||
|
||||
if (!args_has(args, 's')) {
|
||||
src_w = dst_w;
|
||||
@ -82,6 +83,7 @@ cmd_swap_pane_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
return (CMD_RETURN_ERROR);
|
||||
src_w = src_wl->window;
|
||||
}
|
||||
server_unzoom_window(src_w);
|
||||
|
||||
if (src_wp == dst_wp)
|
||||
return (CMD_RETURN_NORMAL);
|
||||
|
@ -219,7 +219,8 @@ input_mouse(struct window_pane *wp, struct session *s, struct mouse_event *m)
|
||||
*/
|
||||
if (m->sgr && (wp->screen->mode & MODE_MOUSE_SGR)) {
|
||||
len = xsnprintf(buf, sizeof buf, "\033[<%d;%d;%d%c",
|
||||
m->sgr_xb, m->x + 1, m->y + 1, m->sgr_rel ? 'm' : 'M');
|
||||
m->sgr_xb, m->x + 1, m->y + 1,
|
||||
m->sgr_rel ? 'm' : 'M');
|
||||
} else if (wp->screen->mode & MODE_MOUSE_UTF8) {
|
||||
len = xsnprintf(buf, sizeof buf, "\033[M");
|
||||
len += utf8_split2(m->xb + 32, &buf[len]);
|
||||
|
@ -150,6 +150,7 @@ key_bindings_init(void)
|
||||
{ 't', 0, &cmd_clock_mode_entry },
|
||||
{ 'w', 0, &cmd_choose_window_entry },
|
||||
{ 'x', 0, &cmd_confirm_before_entry },
|
||||
{ 'z', 0, &cmd_resize_pane_entry },
|
||||
{ '{', 0, &cmd_swap_pane_entry },
|
||||
{ '}', 0, &cmd_swap_pane_entry },
|
||||
{ '~', 0, &cmd_show_messages_entry },
|
||||
|
4
layout.c
4
layout.c
@ -374,13 +374,13 @@ layout_destroy_cell(struct layout_cell *lc, struct layout_cell **lcroot)
|
||||
}
|
||||
|
||||
void
|
||||
layout_init(struct window *w)
|
||||
layout_init(struct window *w, struct window_pane *wp)
|
||||
{
|
||||
struct layout_cell *lc;
|
||||
|
||||
lc = w->layout_root = layout_create_cell(NULL);
|
||||
layout_set_size(lc, w->sx, w->sy, 0, 0);
|
||||
layout_make_leaf(lc, TAILQ_FIRST(&w->panes));
|
||||
layout_make_leaf(lc, wp);
|
||||
|
||||
layout_fix_panes(w, w->sx, w->sy);
|
||||
}
|
||||
|
8
resize.c
8
resize.c
@ -50,7 +50,7 @@ recalculate_sizes(void)
|
||||
struct window *w;
|
||||
struct window_pane *wp;
|
||||
u_int i, j, ssx, ssy, has, limit;
|
||||
int flag, has_status;
|
||||
int flag, has_status, is_zoomed;
|
||||
|
||||
RB_FOREACH(s, sessions, &sessions) {
|
||||
has_status = options_get_number(&s->options, "status");
|
||||
@ -123,12 +123,16 @@ recalculate_sizes(void)
|
||||
|
||||
if (w->sx == ssx && w->sy == ssy)
|
||||
continue;
|
||||
|
||||
log_debug("window size %u,%u (was %u,%u)", ssx, ssy, w->sx,
|
||||
w->sy);
|
||||
|
||||
is_zoomed = w->flags & WINDOW_ZOOMED;
|
||||
if (is_zoomed)
|
||||
window_unzoom(w);
|
||||
layout_resize(w, ssx, ssy);
|
||||
window_resize(w, ssx, ssy);
|
||||
if (is_zoomed && window_pane_visible(w->active))
|
||||
window_zoom(w->active);
|
||||
|
||||
/*
|
||||
* If the current pane is now not visible, move to the next
|
||||
|
@ -384,6 +384,7 @@ server_client_handle_key(struct client *c, int key)
|
||||
if (c->flags & CLIENT_IDENTIFY && key >= '0' && key <= '9') {
|
||||
if (c->flags & CLIENT_READONLY)
|
||||
return;
|
||||
window_unzoom(w);
|
||||
wp = window_pane_at_index(w, key - '0');
|
||||
if (wp != NULL && window_pane_visible(wp))
|
||||
window_set_active_pane(w, wp);
|
||||
|
@ -377,6 +377,7 @@ server_destroy_pane(struct window_pane *wp)
|
||||
return;
|
||||
}
|
||||
|
||||
server_unzoom_window(w);
|
||||
layout_close_pane(wp);
|
||||
window_remove_pane(w, wp);
|
||||
|
||||
@ -588,3 +589,11 @@ server_set_stdin_callback(struct client *c, void (*cb)(struct client *, int,
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
void
|
||||
server_unzoom_window(struct window *w)
|
||||
{
|
||||
window_unzoom(w);
|
||||
server_redraw_window(w);
|
||||
server_status_window(w);
|
||||
}
|
||||
|
56
window.c
56
window.c
@ -319,7 +319,7 @@ window_create(const char *name, const char *cmd, const char *shell,
|
||||
|
||||
w = window_create1(sx, sy);
|
||||
wp = window_add_pane(w, hlimit);
|
||||
layout_init(w);
|
||||
layout_init(w, wp);
|
||||
|
||||
if (*cmd != '\0') {
|
||||
prefix = options_get_string(&w->options, "command-prefix");
|
||||
@ -348,6 +348,8 @@ window_destroy(struct window *w)
|
||||
{
|
||||
u_int i;
|
||||
|
||||
window_unzoom(w);
|
||||
|
||||
if (window_index(w, &i) != 0)
|
||||
fatalx("index not found");
|
||||
ARRAY_SET(&windows, i, NULL);
|
||||
@ -470,6 +472,54 @@ window_find_string(struct window *w, const char *s)
|
||||
return (window_get_active_at(w, x, y));
|
||||
}
|
||||
|
||||
int
|
||||
window_zoom(struct window_pane *wp)
|
||||
{
|
||||
struct window *w = wp->window;
|
||||
struct window_pane *wp1;
|
||||
|
||||
if (w->flags & WINDOW_ZOOMED)
|
||||
return (-1);
|
||||
|
||||
if (!window_pane_visible(wp))
|
||||
return (-1);
|
||||
if (w->active != wp)
|
||||
window_set_active_pane(w, wp);
|
||||
|
||||
TAILQ_FOREACH(wp1, &w->panes, entry) {
|
||||
wp1->saved_layout_cell = wp1->layout_cell;
|
||||
wp1->layout_cell = NULL;
|
||||
}
|
||||
|
||||
w->saved_layout_root = w->layout_root;
|
||||
layout_init(w, wp);
|
||||
w->flags |= WINDOW_ZOOMED;
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
int
|
||||
window_unzoom(struct window *w)
|
||||
{
|
||||
struct window_pane *wp, *wp1;
|
||||
|
||||
if (!(w->flags & WINDOW_ZOOMED))
|
||||
return (-1);
|
||||
wp = w->active;
|
||||
|
||||
w->flags &= ~WINDOW_ZOOMED;
|
||||
layout_free(w);
|
||||
w->layout_root = w->saved_layout_root;
|
||||
|
||||
TAILQ_FOREACH(wp1, &w->panes, entry) {
|
||||
wp1->layout_cell = wp1->saved_layout_cell;
|
||||
wp1->saved_layout_cell = NULL;
|
||||
}
|
||||
layout_fix_panes(w, w->sx, w->sy);
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
struct window_pane *
|
||||
window_add_pane(struct window *w, u_int hlimit)
|
||||
{
|
||||
@ -600,6 +650,8 @@ window_printable_flags(struct session *s, struct winlink *wl)
|
||||
flags[pos++] = '*';
|
||||
if (wl == TAILQ_FIRST(&s->lastw))
|
||||
flags[pos++] = '-';
|
||||
if (wl->window->flags & WINDOW_ZOOMED)
|
||||
flags[pos++] = 'Z';
|
||||
if (pos == 0)
|
||||
flags[pos++] = ' ';
|
||||
flags[pos] = '\0';
|
||||
@ -1027,6 +1079,8 @@ window_pane_visible(struct window_pane *wp)
|
||||
{
|
||||
struct window *w = wp->window;
|
||||
|
||||
if (wp->layout_cell == NULL)
|
||||
return (0);
|
||||
if (wp->xoff >= w->sx || wp->yoff >= w->sy)
|
||||
return (0);
|
||||
if (wp->xoff + wp->sx > w->sx || wp->yoff + wp->sy > w->sy)
|
||||
|
Loading…
Reference in New Issue
Block a user