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:
Nicholas Marriott 2013-02-24 00:25:03 +00:00
parent be13479f09
commit c5239c5984
18 changed files with 121 additions and 12 deletions

View File

@ -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 */

View File

@ -91,11 +91,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");

View File

@ -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. */

View File

@ -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;

View File

@ -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);

View File

@ -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'))

View File

@ -90,6 +90,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);

View File

@ -72,6 +72,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);

View File

@ -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);

View File

@ -218,7 +218,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]);

View File

@ -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 },

View File

@ -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);
}

View File

@ -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

View File

@ -383,6 +383,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);

View File

@ -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);
}

7
tmux.1
View File

@ -1572,7 +1572,7 @@ Rename the current window, or the window at
if specified, to
.Ar new-name .
.It Xo Ic resize-pane
.Op Fl DLRU
.Op Fl DLRUZ
.Op Fl t Ar target-pane
.Op Fl x Ar width
.Op Fl y Ar height
@ -1596,6 +1596,11 @@ or
The
.Ar adjustment
is given in lines or cells (the default is 1).
.Pp
With
.Fl Z ,
the active pane is toggled between occupying the whole of the window and it's
normal position in the layout.
.It Xo Ic respawn-pane
.Op Fl k
.Op Fl t Ar target-pane

9
tmux.h
View File

@ -925,7 +925,9 @@ struct window_pane {
u_int id;
struct window *window;
struct layout_cell *layout_cell;
struct layout_cell *saved_layout_cell;
u_int sx;
u_int sy;
@ -990,6 +992,7 @@ struct window {
int lastlayout;
struct layout_cell *layout_root;
struct layout_cell *saved_layout_root;
u_int sx;
u_int sy;
@ -999,6 +1002,7 @@ struct window {
#define WINDOW_ACTIVITY 0x2
#define WINDOW_REDRAW 0x4
#define WINDOW_SILENCE 0x8
#define WINDOW_ZOOMED 0x10
struct options options;
@ -1925,6 +1929,7 @@ void server_push_stdout(struct client *);
void server_push_stderr(struct client *);
int server_set_stdin_callback(struct client *, void (*)(struct client *,
int, void *), void *, char **);
void server_unzoom_window(struct window *);
/* status.c */
int status_out_cmp(struct status_out *, struct status_out *);
@ -2128,6 +2133,8 @@ struct window_pane *window_find_string(struct window *, const char *);
void window_set_active_pane(struct window *, struct window_pane *);
struct window_pane *window_add_pane(struct window *, u_int);
void window_resize(struct window *, u_int, u_int);
int window_zoom(struct window_pane *);
int window_unzoom(struct window *);
void window_remove_pane(struct window *, struct window_pane *);
struct window_pane *window_pane_at_index(struct window *, u_int);
struct window_pane *window_pane_next_by_number(struct window *,
@ -2184,7 +2191,7 @@ void layout_fix_panes(struct window *, u_int, u_int);
u_int layout_resize_check(struct layout_cell *, enum layout_type);
void layout_resize_adjust(
struct layout_cell *, enum layout_type, int);
void layout_init(struct window *);
void layout_init(struct window *, struct window_pane *);
void layout_free(struct window *);
void layout_resize(struct window *, u_int, u_int);
void layout_resize_pane(struct window_pane *, enum layout_type,

View File

@ -316,7 +316,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");
@ -345,6 +345,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);
@ -467,6 +469,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)
{
@ -597,6 +647,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';
@ -1030,6 +1082,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)