If select-layout is not given an argument, repply the last layout used in the

window, if any.
pull/1/head
Nicholas Marriott 2009-07-28 06:48:44 +00:00
parent 309b76fb32
commit 2da4864483
6 changed files with 42 additions and 24 deletions

View File

@ -29,8 +29,8 @@ int cmd_select_layout_exec(struct cmd *, struct cmd_ctx *);
const struct cmd_entry cmd_select_layout_entry = {
"select-layout", "selectl",
CMD_TARGET_WINDOW_USAGE " layout-name",
CMD_ARG1, 0,
CMD_TARGET_WINDOW_USAGE " [layout-name]",
CMD_ARG01, 0,
cmd_select_layout_init,
cmd_target_parse,
cmd_select_layout_exec,
@ -72,11 +72,15 @@ cmd_select_layout_exec(struct cmd *self, struct cmd_ctx *ctx)
if ((wl = cmd_find_window(ctx, data->target, NULL)) == NULL)
return (-1);
if ((layout = layout_set_lookup(data->arg)) == -1) {
ctx->error(ctx, "unknown or ambiguous layout: %s", data->arg);
return (-1);
}
if (data->arg == NULL) {
layout = wl->window->lastlayout;
if (layout == -1)
return (0);
} else if ((layout = layout_set_lookup(data->arg)) == -1) {
ctx->error(ctx, "unknown layout or ambiguous: %s", data->arg);
return (-1);
}
layout = layout_set_select(wl->window, layout);
ctx->info(ctx, "arranging in: %s", layout_set_name(layout));

View File

@ -112,9 +112,9 @@ cmd_server_info_exec(unused struct cmd *self, struct cmd_ctx *ctx)
RB_FOREACH(wl, winlinks, &s->windows) {
w = wl->window;
ctx->print(ctx, "%4u: %s [%ux%u] [flags=0x%x, "
"references=%u, layout=%u]", wl->idx, w->name,
"references=%u, last layout=%d]", wl->idx, w->name,
w->sx, w->sy, w->flags, w->references,
w->layout);
w->lastlayout);
j = 0;
TAILQ_FOREACH(wp, &w->panes, entry) {
lines = ulines = size = usize = 0;

View File

@ -74,36 +74,47 @@ layout_set_select(struct window *w, u_int layout)
if (layout_sets[layout].arrange != NULL)
layout_sets[layout].arrange(w);
w->layout = layout;
w->lastlayout = layout;
return (layout);
}
u_int
layout_set_next(struct window *w)
{
u_int layout = w->layout;
u_int layout;
if (w->lastlayout == -1)
layout = 0;
else {
layout = w->lastlayout + 1;
if (layout > nitems(layout_sets) - 1)
layout = 0;
}
if (layout_sets[layout].arrange != NULL)
layout_sets[layout].arrange(w);
w->layout++;
if (w->layout > nitems(layout_sets) - 1)
w->layout = 0;
w->lastlayout = layout;
return (layout);
}
u_int
layout_set_previous(struct window *w)
{
u_int layout = w->layout;
u_int layout;
if (w->lastlayout == -1)
layout = nitems(layout_sets) - 1;
else {
layout = w->lastlayout;
if (layout == 0)
layout = nitems(layout_sets) - 1;
else
layout--;
}
if (layout_sets[layout].arrange != NULL)
layout_sets[layout].arrange(w);
if (w->layout == 0)
w->layout = nitems(layout_sets) - 1;
else
w->layout--;
w->lastlayout = layout;
return (layout);
}

5
tmux.1
View File

@ -1064,10 +1064,13 @@ has the same meaning as in the
command.
.It Xo Ic select-layout
.Op Fl t Ar target-window
.Ar layout-name
.Op Ar layout-name
.Xc
.D1 (alias: selectl )
Choose a specific layout for a window.
If
.Ar layout-name
is not given, the last layout used (if any) is reapplied.
.It Xo Ic select-pane
.Op Fl p Ar pane-index
.Op Fl t Ar target-window

2
tmux.h
View File

@ -663,7 +663,7 @@ struct window {
struct window_pane *active;
struct window_panes panes;
u_int layout;
int lastlayout;
struct layout_cell *layout_root;
u_int sx;

View File

@ -231,7 +231,7 @@ window_create1(u_int sx, u_int sy)
TAILQ_INIT(&w->panes);
w->active = NULL;
w->layout = 0;
w->lastlayout = -1;
w->layout_root = NULL;
w->sx = sx;