summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNicholas Marriott <nicm@openbsd.org>2009-07-19 13:21:40 +0000
committerNicholas Marriott <nicm@openbsd.org>2009-07-19 13:21:40 +0000
commit6036bdd06cba9fa500098f1f17983d62955b24e5 (patch)
treef19dc96b0b6f65ca03222018df09defd585bed90
parentfc6a65c6207dbefcd8b5f187148978f8d4111b2b (diff)
Improved layout code.
Each window now has a tree of layout cells associated with it. In this tree, each node is either a horizontal or vertical cell containing a list of other cells running from left-to-right or top-to-bottom, or a leaf cell which is associated with a pane. The major functional changes are: - panes may now be split arbitrarily both horizontally (splitw -h, C-b %) and vertically (splitw -v, C-b "); - panes may be resized both horizontally and vertically (resizep -L/-R/-U/-D, bound to C-b left/right/up/down and C-b M-left/right/up/down); - layouts are now applied and then may be modified by resizing or splitting panes, rather than being fixed and reapplied when the window is resized or panes are added; - manual-vertical layout is no longer necessary, and active-only layout is gone (but may return in future); - the main-pane layouts now reduce the size of the main pane to fit all panes if possible. Thanks to all who tested.
-rw-r--r--Makefile2
-rw-r--r--cmd-break-pane.c4
-rw-r--r--cmd-choose-window.c4
-rw-r--r--cmd-down-pane.c1
-rw-r--r--cmd-kill-pane.c2
-rw-r--r--cmd-list-windows.c5
-rw-r--r--cmd-next-layout.c5
-rw-r--r--cmd-previous-layout.c7
-rw-r--r--cmd-resize-pane.c35
-rw-r--r--cmd-respawn-window.c2
-rw-r--r--cmd-rotate-window.c19
-rw-r--r--cmd-select-layout.c22
-rw-r--r--cmd-select-pane.c1
-rw-r--r--cmd-split-window.c97
-rw-r--r--cmd-swap-pane.c14
-rw-r--r--cmd-up-pane.c1
-rw-r--r--key-bindings.c13
-rw-r--r--layout-manual.c172
-rw-r--r--layout-set.c436
-rw-r--r--layout.c787
-rw-r--r--resize.c2
-rw-r--r--server.c6
-rw-r--r--tmux.181
-rw-r--r--tmux.h83
-rw-r--r--window.c53
25 files changed, 1258 insertions, 596 deletions
diff --git a/Makefile b/Makefile
index 6f6644a0..924ac4ec 100644
--- a/Makefile
+++ b/Makefile
@@ -27,7 +27,7 @@ SRCS= attributes.c buffer-poll.c buffer.c cfg.c client-fn.c \
cmd-switch-client.c cmd-unbind-key.c cmd-unlink-window.c \
cmd-up-pane.c cmd-display-message.c cmd.c \
colour.c grid-view.c grid.c input-keys.c \
- input.c key-bindings.c key-string.c layout-manual.c layout.c log.c \
+ input.c key-bindings.c key-string.c layout-set.c layout.c log.c \
mode-key.c names.c options-cmd.c options.c paste.c procname.c \
resize.c screen-redraw.c screen-write.c screen.c server-fn.c \
server-msg.c server.c session.c status.c tmux.c tty-keys.c tty-term.c \
diff --git a/cmd-break-pane.c b/cmd-break-pane.c
index 74e052d5..8eeb7f42 100644
--- a/cmd-break-pane.c
+++ b/cmd-break-pane.c
@@ -74,17 +74,17 @@ cmd_break_pane_exec(struct cmd *self, struct cmd_ctx *ctx)
if (wl->window->active == NULL)
wl->window->active = TAILQ_NEXT(wp, entry);
}
- layout_refresh(wl->window, 0);
+ layout_close_pane(wp);
w = wp->window = window_create1(s->sx, s->sy);
TAILQ_INSERT_HEAD(&w->panes, wp, entry);
w->active = wp;
w->name = default_window_name(w);
+ layout_init(w);
wl = session_attach(s, w, -1, &cause); /* can't fail */
if (!(data->chflags & CMD_CHFLAG('d')))
session_select(s, wl->idx);
- layout_refresh(w, 0);
server_redraw_session(s);
diff --git a/cmd-choose-window.c b/cmd-choose-window.c
index 33487e27..80a2518e 100644
--- a/cmd-choose-window.c
+++ b/cmd-choose-window.c
@@ -76,8 +76,8 @@ cmd_choose_window_exec(struct cmd *self, struct cmd_ctx *ctx)
idx++;
window_choose_add(wl->window->active,
- wm->idx, "%3d: %s [%ux%u %s] (%u panes)", wm->idx, w->name,
- w->sx, w->sy, layout_name(w), window_count_panes(w));
+ wm->idx, "%3d: %s [%ux%u] (%u panes)",
+ wm->idx, w->name, w->sx, w->sy, window_count_panes(w));
}
cdata = xmalloc(sizeof *cdata);
diff --git a/cmd-down-pane.c b/cmd-down-pane.c
index 73736946..640ad5bd 100644
--- a/cmd-down-pane.c
+++ b/cmd-down-pane.c
@@ -54,7 +54,6 @@ cmd_down_pane_exec(struct cmd *self, struct cmd_ctx *ctx)
w->active = TAILQ_NEXT(w->active, entry);
if (w->active == NULL)
w->active = TAILQ_FIRST(&w->panes);
- layout_refresh(w, 1);
} while (!window_pane_visible(w->active));
return (0);
diff --git a/cmd-kill-pane.c b/cmd-kill-pane.c
index b501e416..d219f399 100644
--- a/cmd-kill-pane.c
+++ b/cmd-kill-pane.c
@@ -66,8 +66,8 @@ cmd_kill_pane_exec(struct cmd *self, struct cmd_ctx *ctx)
return (0);
}
+ layout_close_pane(wp);
window_remove_pane(wl->window, wp);
server_redraw_window(wl->window);
- layout_refresh(wl->window, 0);
return (0);
}
diff --git a/cmd-list-windows.c b/cmd-list-windows.c
index 8b2162a5..197d683f 100644
--- a/cmd-list-windows.c
+++ b/cmd-list-windows.c
@@ -78,9 +78,8 @@ cmd_list_windows_exec(struct cmd *self, struct cmd_ctx *ctx)
else
name = "unknown";
ctx->print(ctx,
- " %s [%ux%u %s] [history %u/%u, %llu bytes]",
- name, wp->sx, wp->sy, layout_name(w), gd->hsize,
- gd->hlimit, size);
+ " %s [%ux%u] [history %u/%u, %llu bytes]",
+ name, wp->sx, wp->sy, gd->hsize, gd->hlimit, size);
}
}
diff --git a/cmd-next-layout.c b/cmd-next-layout.c
index b89dda3d..088046fa 100644
--- a/cmd-next-layout.c
+++ b/cmd-next-layout.c
@@ -44,12 +44,13 @@ cmd_next_layout_exec(struct cmd *self, struct cmd_ctx *ctx)
{
struct cmd_target_data *data = self->data;
struct winlink *wl;
+ u_int layout;
if ((wl = cmd_find_window(ctx, data->target, NULL)) == NULL)
return (-1);
- layout_next(wl->window);
- ctx->info(ctx, "layout now: %s", layout_name(wl->window));
+ layout = layout_set_next(wl->window);
+ ctx->info(ctx, "arranging in: %s", layout_set_name(layout));
return (0);
}
diff --git a/cmd-previous-layout.c b/cmd-previous-layout.c
index f4270f14..44071eb5 100644
--- a/cmd-previous-layout.c
+++ b/cmd-previous-layout.c
@@ -44,12 +44,13 @@ cmd_previous_layout_exec(struct cmd *self, struct cmd_ctx *ctx)
{
struct cmd_target_data *data = self->data;
struct winlink *wl;
-
+ u_int layout;
+
if ((wl = cmd_find_window(ctx, data->target, NULL)) == NULL)
return (-1);
- layout_previous(wl->window);
- ctx->info(ctx, "layout now: %s", layout_name(wl->window));
+ layout = layout_set_previous(wl->window);
+ ctx->info(ctx, "arranging in: %s", layout_set_name(layout));
return (0);
}
diff --git a/cmd-resize-pane.c b/cmd-resize-pane.c
index 64ac95b2..5e9f67e3 100644
--- a/cmd-resize-pane.c
+++ b/cmd-resize-pane.c
@@ -32,7 +32,8 @@ int cmd_resize_pane_exec(struct cmd *, struct cmd_ctx *);
const struct cmd_entry cmd_resize_pane_entry = {
"resize-pane", "resizep",
CMD_PANE_WINDOW_USAGE "[-DU] [adjustment]",
- CMD_ARG01, CMD_CHFLAG('D')|CMD_CHFLAG('U'),
+ CMD_ARG01,
+ CMD_CHFLAG('D')|CMD_CHFLAG('L')|CMD_CHFLAG('R')|CMD_CHFLAG('U'),
cmd_resize_pane_init,
cmd_pane_parse,
cmd_resize_pane_exec,
@@ -50,15 +51,31 @@ cmd_resize_pane_init(struct cmd *self, int key)
cmd_pane_init(self, key);
data = self->data;
+ if (key == KEYC_ADDCTL(KEYC_UP))
+ data->chflags |= CMD_CHFLAG('U');
if (key == KEYC_ADDCTL(KEYC_DOWN))
data->chflags |= CMD_CHFLAG('D');
+ if (key == KEYC_ADDCTL(KEYC_LEFT))
+ data->chflags |= CMD_CHFLAG('L');
+ if (key == KEYC_ADDCTL(KEYC_RIGHT))
+ data->chflags |= CMD_CHFLAG('R');
- if (key == KEYC_ADDESC(KEYC_UP))
+ if (key == KEYC_ADDESC(KEYC_UP)) {
+ data->chflags |= CMD_CHFLAG('U');
data->arg = xstrdup("5");
+ }
if (key == KEYC_ADDESC(KEYC_DOWN)) {
data->chflags |= CMD_CHFLAG('D');
data->arg = xstrdup("5");
}
+ if (key == KEYC_ADDESC(KEYC_LEFT)) {
+ data->chflags |= CMD_CHFLAG('L');
+ data->arg = xstrdup("5");
+ }
+ if (key == KEYC_ADDESC(KEYC_RIGHT)) {
+ data->chflags |= CMD_CHFLAG('R');
+ data->arg = xstrdup("5");
+ }
}
int
@@ -92,12 +109,14 @@ cmd_resize_pane_exec(struct cmd *self, struct cmd_ctx *ctx)
}
}
- if (!(data->chflags & CMD_CHFLAG('D')))
- adjust = -adjust;
- if (layout_resize(wp, adjust) != 0) {
- ctx->error(ctx, "layout %s "
- "does not support resizing", layout_name(wp->window));
- return (-1);
+ if (data->chflags & (CMD_CHFLAG('L')|CMD_CHFLAG('R'))) {
+ if (data->chflags & CMD_CHFLAG('L'))
+ adjust = -adjust;
+ layout_resize_pane(wp, LAYOUT_LEFTRIGHT, adjust);
+ } else {
+ if (data->chflags & CMD_CHFLAG('U'))
+ adjust = -adjust;
+ layout_resize_pane(wp, LAYOUT_TOPBOTTOM, adjust);
}
server_redraw_window(wl->window);
diff --git a/cmd-respawn-window.c b/cmd-respawn-window.c
index 5d70aa63..3a795461 100644
--- a/cmd-respawn-window.c
+++ b/cmd-respawn-window.c
@@ -70,6 +70,7 @@ cmd_respawn_window_exec(struct cmd *self, struct cmd_ctx *ctx)
wp = TAILQ_FIRST(&w->panes);
TAILQ_REMOVE(&w->panes, wp, entry);
+ layout_free(w);
window_destroy_panes(w);
TAILQ_INSERT_HEAD(&w->panes, wp, entry);
window_pane_resize(wp, w->sx, w->sy);
@@ -78,6 +79,7 @@ cmd_respawn_window_exec(struct cmd *self, struct cmd_ctx *ctx)
xfree(cause);
return (-1);
}
+ layout_init(w);
screen_reinit(&wp->base);
recalculate_sizes();
diff --git a/cmd-rotate-window.c b/cmd-rotate-window.c
index e730dc59..c69fa8d1 100644
--- a/cmd-rotate-window.c
+++ b/cmd-rotate-window.c
@@ -59,6 +59,7 @@ cmd_rotate_window_exec(struct cmd *self, struct cmd_ctx *ctx)
struct winlink *wl;
struct window *w;
struct window_pane *wp, *wp2;
+ struct layout_cell *lc;
u_int sx, sy, xoff, yoff;
if ((wl = cmd_find_window(ctx, data->target, NULL)) == NULL)
@@ -70,42 +71,56 @@ cmd_rotate_window_exec(struct cmd *self, struct cmd_ctx *ctx)
TAILQ_REMOVE(&w->panes, wp, entry);
TAILQ_INSERT_HEAD(&w->panes, wp, entry);
+ lc = wp->layout_cell;
xoff = wp->xoff; yoff = wp->yoff;
sx = wp->sx; sy = wp->sy;
TAILQ_FOREACH(wp, &w->panes, entry) {
if ((wp2 = TAILQ_NEXT(wp, entry)) == NULL)
break;
+ wp->layout_cell = wp2->layout_cell;
+ if (wp->layout_cell != NULL)
+ wp->layout_cell->wp = wp;
wp->xoff = wp2->xoff; wp->yoff = wp2->yoff;
window_pane_resize(wp, wp2->sx, wp2->sy);
}
+ wp->layout_cell = lc;
+ if (wp->layout_cell != NULL)
+ wp->layout_cell->wp = wp;
wp->xoff = xoff; wp->yoff = yoff;
window_pane_resize(wp, sx, sy);
if ((wp = TAILQ_PREV(w->active, window_panes, entry)) == NULL)
wp = TAILQ_LAST(&w->panes, window_panes);
window_set_active_pane(w, wp);
+ server_redraw_window(w);
} else {
wp = TAILQ_FIRST(&w->panes);
TAILQ_REMOVE(&w->panes, wp, entry);
TAILQ_INSERT_TAIL(&w->panes, wp, entry);
+ lc = wp->layout_cell;
xoff = wp->xoff; yoff = wp->yoff;
sx = wp->sx; sy = wp->sy;
TAILQ_FOREACH_REVERSE(wp, &w->panes, window_panes, entry) {
if ((wp2 = TAILQ_PREV(wp, window_panes, entry)) == NULL)
break;
+ wp->layout_cell = wp2->layout_cell;
+ if (wp->layout_cell != NULL)
+ wp->layout_cell->wp = wp;
wp->xoff = wp2->xoff; wp->yoff = wp2->yoff;
window_pane_resize(wp, wp2->sx, wp2->sy);
}
+ wp->layout_cell = lc;
+ if (wp->layout_cell != NULL)
+ wp->layout_cell->wp = wp;
wp->xoff = xoff; wp->yoff = yoff;
window_pane_resize(wp, sx, sy);
if ((wp = TAILQ_NEXT(w->active, entry)) == NULL)
wp = TAILQ_FIRST(&w->panes);
window_set_active_pane(w, wp);
+ server_redraw_window(w);
}
- layout_refresh(w, 0);
-
return (0);
}
diff --git a/cmd-select-layout.c b/cmd-select-layout.c
index 01d7ef6e..953cb69f 100644
--- a/cmd-select-layout.c
+++ b/cmd-select-layout.c
@@ -49,17 +49,17 @@ cmd_select_layout_init(struct cmd *self, int key)
data = self->data;
switch (key) {
- case KEYC_ADDESC('0'):
- data->arg = xstrdup("manual-vertical");
- break;
case KEYC_ADDESC('1'):
data->arg = xstrdup("even-horizontal");
break;
case KEYC_ADDESC('2'):
data->arg = xstrdup("even-vertical");
break;
- case KEYC_ADDESC('9'):
- data->arg = xstrdup("active-only");
+ case KEYC_ADDESC('3'):
+ data->arg = xstrdup("main-horizontal");
+ break;
+ case KEYC_ADDESC('4'):
+ data->arg = xstrdup("main-vertical");
break;
}
}
@@ -74,13 +74,13 @@ 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_lookup(data->arg)) == -1) {
- ctx->error(ctx, "unknown or ambiguous layout: %s", data->arg);
- return (-1);
- }
+ if ((layout = layout_set_lookup(data->arg)) == -1) {
+ ctx->error(ctx, "unknown or ambiguous layout: %s", data->arg);
+ return (-1);
+ }
- if (layout_select(wl->window, layout) == 0)
- ctx->info(ctx, "layout now: %s", layout_name(wl->window));
+ layout = layout_set_select(wl->window, layout);
+ ctx->info(ctx, "arranging in: %s", layout_set_name(layout));
return (0);
}
diff --git a/cmd-select-pane.c b/cmd-select-pane.c
index d112f919..6a9dec42 100644
--- a/cmd-select-pane.c
+++ b/cmd-select-pane.c
@@ -63,7 +63,6 @@ cmd_select_pane_exec(struct cmd *self, struct cmd_ctx *ctx)
return (-1);
}
window_set_active_pane(wl->window, wp);
- layout_refresh(wl->window, 1);
return (0);
}
diff --git a/cmd-split-window.c b/cmd-split-window.c
index 74d28313..f1b21d51 100644
--- a/cmd-split-window.c
+++ b/cmd-split-window.c
@@ -39,13 +39,14 @@ struct cmd_split_window_data {
char *target;
char *cmd;
int flag_detached;
+ int flag_horizontal;
int percentage;
- int lines;
+ int size;
};
const struct cmd_entry cmd_split_window_entry = {
"split-window", "splitw",
- "[-d] [-p percentage|-l lines] [-t target-window] [command]",
+ "[-dhv] [-p percentage|-l size] [-t target-window] [command]",
0, 0,
cmd_split_window_init,
cmd_split_window_parse,
@@ -57,7 +58,7 @@ const struct cmd_entry cmd_split_window_entry = {
};
void
-cmd_split_window_init(struct cmd *self, unused int arg)
+cmd_split_window_init(struct cmd *self, int key)
{
struct cmd_split_window_data *data;
@@ -65,50 +66,63 @@ cmd_split_window_init(struct cmd *self, unused int arg)
data->target = NULL;
data->cmd = NULL;
data->flag_detached = 0;
+ data->flag_horizontal = 0;
data->percentage = -1;
- data->lines = -1;
+ data->size = -1;
+
+ switch (key) {
+ case '%':
+ data->flag_horizontal = 1;
+ break;
+ case '"':
+ data->flag_horizontal = 0;
+ break;
+ }
}
int
cmd_split_window_parse(struct cmd *self, int argc, char **argv, char **cause)
{
struct cmd_split_window_data *data;
- int opt, n;
+ int opt;
const char *errstr;
self->entry->init(self, 0);
data = self->data;
- while ((opt = getopt(argc, argv, "dl:p:t:")) != -1) {
+ while ((opt = getopt(argc, argv, "dhl:p:t:v")) != -1) {
switch (opt) {
case 'd':
data->flag_detached = 1;
break;
+ case 'h':
+ data->flag_horizontal = 1;
+ break;
case 't':
if (data->target == NULL)
data->target = xstrdup(optarg);
break;
case 'l':
- if (data->percentage == -1 && data->lines == -1) {
- n = strtonum(optarg, 1, INT_MAX, &errstr);
- if (errstr != NULL) {
- xasprintf(cause, "lines %s", errstr);
- goto error;
- }
- data->lines = n;
+ if (data->percentage != -1 || data->size != -1)
+ break;
+ data->size = strtonum(optarg, 1, INT_MAX, &errstr);
+ if (errstr != NULL) {
+ xasprintf(cause, "size %s", errstr);
+ goto error;
}
break;
case 'p':
- if (data->lines == -1 && data->percentage == -1) {
- n = strtonum(optarg, 1, 100, &errstr);
- if (errstr != NULL) {
- xasprintf(
- cause, "percentage %s", errstr);
- goto error;
- }
- data->percentage = n;
+ if (data->size != -1 || data->percentage != -1)
+ break;
+ data->percentage = strtonum(optarg, 1, 100, &errstr);
+ if (errstr != NULL) {
+ xasprintf(cause, "percentage %s", errstr);
+ goto error;
}
break;
+ case 'v':
+ data->flag_horizontal = 0;
+ break;
default:
goto usage;
}
@@ -142,7 +156,8 @@ cmd_split_window_exec(struct cmd *self, struct cmd_ctx *ctx)
const char **env;
char *cmd, *cwd, *cause;
u_int hlimit;
- int lines;
+ int size;
+ enum layout_type type;
if ((wl = cmd_find_window(ctx, data->target, &s)) == NULL)
return (-1);
@@ -158,19 +173,27 @@ cmd_split_window_exec(struct cmd *self, struct cmd_ctx *ctx)
else
cwd = ctx->cmdclient->cwd;
- lines = -1;
- if (data->lines != -1)
- lines = data->lines;
+ size = -1;
+ if (data->size != -1)
+ size = data->size;
else if (data->percentage != -1)
- lines = (w->active->sy * data->percentage) / 100;
-
+ size = (w->active->sy * data->percentage) / 100;
hlimit = options_get_number(&s->options, "history-limit");
- wp = window_add_pane(w, lines, cmd, cwd, env, hlimit, &cause);
- if (wp == NULL) {
- ctx->error(ctx, "create pane failed: %s", cause);
- xfree(cause);
- return (-1);
+
+ type = LAYOUT_TOPBOTTOM;
+ if (data->flag_horizontal)
+ type = LAYOUT_LEFTRIGHT;
+
+ wp = window_add_pane(w, hlimit, &cause);
+ if (wp == NULL)
+ goto error;
+ if (window_pane_spawn(wp, cmd, cwd, env, &cause) != 0)
+ goto error;
+ if (layout_split_pane(w->active, type, size, wp) != 0) {
+ cause = xstrdup("pane too small");
+ goto error;
}
+
server_redraw_window(w);
if (!data->flag_detached) {
@@ -179,9 +202,15 @@ cmd_split_window_exec(struct cmd *self, struct cmd_ctx *ctx)
server_redraw_session(s);
} else
server_status_session(s);
- layout_refresh(w, 0);
return (0);
+
+error:
+ if (wp != NULL)
+ window_remove_pane(w, wp);
+ ctx->error(ctx, "create pane failed: %s", cause);
+ xfree(cause);
+ return (-1);
}
void
@@ -228,6 +257,8 @@ cmd_split_window_print(struct cmd *self, char *buf, size_t len)
return (off);
if (off < len && data->flag_detached)
off += xsnprintf(buf + off, len - off, " -d");
+ if (off < len && data->flag_horizontal)
+ off += xsnprintf(buf + off, len - off, " -h");
if (off < len && data->target != NULL)
off += cmd_prarg(buf + off, len - off, " -t ", data->target);
if (off < len && data->cmd != NULL)
diff --git a/cmd-swap-pane.c b/cmd-swap-pane.c
index 1c3cb508..0f0633d8 100644
--- a/cmd-swap-pane.c
+++ b/cmd-swap-pane.c
@@ -157,6 +157,7 @@ cmd_swap_pane_exec(struct cmd *self, struct cmd_ctx *ctx)
struct winlink *wl;
struct window *w;
struct window_pane *tmp_wp, *src_wp, *dst_wp;
+ struct layout_cell *lc;
u_int xx, yy;
if (data == NULL)
@@ -207,12 +208,15 @@ cmd_swap_pane_exec(struct cmd *self, struct cmd_ctx *ctx)
else
TAILQ_INSERT_AFTER(&w->panes, tmp_wp, src_wp, entry);
+ lc = src_wp->layout_cell;
xx = src_wp->xoff;
yy = src_wp->yoff;
- src_wp->xoff = dst_wp->xoff;
- src_wp->yoff = dst_wp->yoff;
- dst_wp->xoff = xx;
- dst_wp->yoff = yy;
+ src_wp->layout_cell = dst_wp->layout_cell;
+ if (src_wp->layout_cell != NULL)
+ src_wp->layout_cell->wp = src_wp;
+ dst_wp->layout_cell = lc;
+ if (dst_wp->layout_cell != NULL)
+ dst_wp->layout_cell->wp = dst_wp;
xx = src_wp->sx;
yy = src_wp->sy;
@@ -224,8 +228,8 @@ cmd_swap_pane_exec(struct cmd *self, struct cmd_ctx *ctx)
if (!window_pane_visible(tmp_wp))
tmp_wp = src_wp;
window_set_active_pane(w, tmp_wp);
- layout_refresh(w, 0);
}
+ server_redraw_window(w);
return (0);
}
diff --git a/cmd-up-pane.c b/cmd-up-pane.c
index 2f092ece..8b262c60 100644
--- a/cmd-up-pane.c
+++ b/cmd-up-pane.c
@@ -54,7 +54,6 @@ cmd_up_pane_exec(struct cmd *self, struct cmd_ctx *ctx)
w->active = TAILQ_PREV(w->active, window_panes, entry);
if (w->active == NULL)
w->active = TAILQ_LAST(&w->panes, window_panes);
- layout_refresh(w, 1);
} while (!window_pane_visible(w->active));
return (0);
diff --git a/key-bindings.c b/key-bindings.c
index c298c79d..66ed4927 100644
--- a/key-bindings.c
+++ b/key-bindings.c
@@ -93,7 +93,8 @@ key_bindings_init(void)
} table[] = {
{ ' ', 0, &cmd_next_layout_entry },
{ '!', 0, &cmd_break_pane_entry },
- { '"', 0, &cmd_split_window_entry },
+ { '"', 0, &cmd_split_window_entry },
+ { '%', 0, &cmd_split_window_entry },
{ '#', 0, &cmd_list_buffers_entry },
{ '&', 0, &cmd_confirm_before_entry },
{ ',', 0, &cmd_command_prompt_entry },
@@ -132,10 +133,10 @@ key_bindings_init(void)
{ '{', 0, &cmd_swap_pane_entry },
{ '}', 0, &cmd_swap_pane_entry },
{ '\002', 0, &cmd_send_prefix_entry },
- { KEYC_ADDESC('0'), 0, &cmd_select_layout_entry },
{ KEYC_ADDESC('1'), 0, &cmd_select_layout_entry },
{ KEYC_ADDESC('2'), 0, &cmd_select_layout_entry },
- { KEYC_ADDESC('9'), 0, &cmd_select_layout_entry },
+ { KEYC_ADDESC('3'), 0, &cmd_select_layout_entry },
+ { KEYC_ADDESC('4'), 0, &cmd_select_layout_entry },
{ KEYC_PPAGE, 0, &cmd_scroll_mode_entry },
{ KEYC_ADDESC('n'), 0, &cmd_next_window_entry },
{ KEYC_ADDESC('p'), 0, &cmd_previous_window_entry },
@@ -143,8 +144,12 @@ key_bindings_init(void)
{ KEYC_DOWN, 0, &cmd_down_pane_entry },
{ KEYC_ADDESC(KEYC_UP), 1, &cmd_resize_pane_entry },
{ KEYC_ADDESC(KEYC_DOWN), 1, &cmd_resize_pane_entry },
+ { KEYC_ADDESC(KEYC_LEFT), 1, &cmd_resize_pane_entry },
+ { KEYC_ADDESC(KEYC_RIGHT),1, &cmd_resize_pane_entry },
{ KEYC_ADDCTL(KEYC_UP), 1, &cmd_resize_pane_entry },
- { KEYC_ADDCTL(KEYC_DOWN), 1, &cmd_resize_pane_entry },
+ { KEYC_ADDCTL(KEYC_DOWN), 1, &cmd_resize_pane_entry },
+ { KEYC_ADDCTL(KEYC_LEFT), 1, &cmd_resize_pane_entry },
+ { KEYC_ADDCTL(KEYC_RIGHT),1, &cmd_resize_pane_entry },
{ KEYC_ADDESC('o'), 0, &cmd_rotate_window_entry },
{ '\017', 0, &cmd_rotate_window_entry },
};
diff --git a/layout-manual.c b/layout-manual.c
deleted file mode 100644
index 7edce667..00000000
--- a/layout-manual.c
+++ /dev/null
@@ -1,172 +0,0 @@
-/* $OpenBSD$ */
-
-/*
- * Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
- *
- * Permission to use, copy, modify, and distribute this software for any
- * purpose with or without fee is hereby granted, provided that the above
- * copyright notice and this permission notice appear in all copies.
- *
- * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
- * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
- * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
- * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
- * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
- * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- */
-
-#include <sys/types.h>
-
-#include "tmux.h"
-
-void layout_manual_v_update_offsets(struct window *);
-
-void
-layout_manual_v_refresh(struct window *w, unused int active_only)
-{
- struct window_pane *wp;
- u_int npanes, total, height;
- int left;
-
- if (active_only)
- return;
-
- if (TAILQ_EMPTY(&w->panes))
- return;
-
- /* Check the new size. */
- npanes = window_count_panes(w);
- if (w->sy <= PANE_MINIMUM * npanes) {
- /*
- * Make the first pane the smaller of the minimum and total (it
- * must fit to be visible) and the rest the minimum size.
- */
- height = PANE_MINIMUM;
- if (height > w->sy)
- height = w->sy + 1;
- TAILQ_FOREACH(wp, &w->panes, entry) {
- if (wp == TAILQ_FIRST(&w->panes))
- wp->sy = height - 1;
- else
- wp->sy = PANE_MINIMUM - 1;
- }
- /* And increase the first by the rest if possible. */
- if (w->sy >= PANE_MINIMUM)
- TAILQ_FIRST(&w->panes)->sy += 1 + w->sy % PANE_MINIMUM;
- } else {
- /* In theory they will all fit. Find the current total. */
- total = 0;
- TAILQ_FOREACH(wp, &w->panes, entry)
- total += wp->sy;
- total += npanes - 1;
-
- /* Growing or shrinking? */
- left = w->sy - total;
- if (left > 0) {
- /* Growing. Expand evenly. */
- while (left > 0) {
- TAILQ_FOREACH(wp, &w->panes, entry) {
- wp->sy++;
- if (--left == 0)
- break;
- }
- }
- } else {
- /* Shrinking. Reduce evenly down to minimum. */
- while (left < 0) {
- TAILQ_FOREACH(wp, &w->panes, entry) {
- if (wp->sy <= PANE_MINIMUM - 1)
- continue;
- wp->sy--;
- if (++left == 0)
- break;
- }
- }
- }
- }
-
- /* Now do the resize. */
- TAILQ_FOREACH(wp, &w->panes, entry) {
- wp->sy--;
- window_pane_resize(wp, w->sx, wp->sy + 1);
- }
-
- /* Fill in the offsets. */
- layout_manual_v_update_offsets(w);
-
- /* Switch the active window if necessary. */
- window_set_active_pane(w, w->active);
-}
-
-void
-layout_manual_v_resize(struct window_pane *wp, int adjust)
-{
- struct window *w = wp->window;
- struct window_pane *wq;
-
- if (adjust > 0) {
- /*
- * If this is not the last pane, keep trying to increase size
- * and remove it from the next panes. If it is the last, do
- * so on the previous pane.
- */
- if (TAILQ_NEXT(wp, entry) == NULL) {
- if (wp == TAILQ_FIRST(&w->panes)) {
- /* Only one pane. */
- return;
- }
- wp = TAILQ_PREV(wp, window_panes, entry);
- }
- while (adjust-- > 0) {
- wq = wp;
- while ((wq = TAILQ_NEXT(wq, entry)) != NULL) {
- if (wq->sy <= PANE_MINIMUM)
- continue;
- window_pane_resize(wq, wq->sx, wq->sy - 1);
- break;
- }
- if (wq == NULL)
- break;
- window_pane_resize(wp, wp->sx, wp->sy + 1);
- }
- } else {
- adjust = -adjust;
- /*
- * If this is not the last pane, keep trying to reduce size
- * and add to the following pane. If it is the last, do so on
- * the previous pane.
- */
- wq = TAILQ_NEXT(wp, entry);
- if (wq == NULL) {
- if (wp == TAILQ_FIRST(&w->panes)) {
- /* Only one pane. */
- return;
- }
- wq = wp;
- wp = TAILQ_PREV(wq, window_panes, entry);
- }
- while (adjust-- > 0) {
- if (wp->sy <= PANE_MINIMUM)
- break;
- window_pane_resize(wq, wq->sx, wq->sy + 1);
- window_pane_resize(wp, wp->sx, wp->sy - 1);
- }
- }
-
- layout_manual_v_update_offsets(w);
-}
-
-void
-layout_manual_v_update_offsets(struct window *w)
-{
- struct window_pane *wp;
- u_int yoff;
-
- yoff = 0;
- TAILQ_FOREACH(wp, &w->panes, entry) {
- wp->xoff = 0;
- wp->yoff = yoff;
- yoff += wp->sy + 1;
- }
-}
diff --git a/layout-set.c b/layout-set.c
new file mode 100644
index 00000000..ae99f6ff
--- /dev/null
+++ b/layout-set.c
@@ -0,0 +1,436 @@
+/* $OpenBSD$ */
+
+/*
+ * Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
+ * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
+ * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include <sys/types.h>
+
+#include <string.h>
+
+#include "tmux.h"
+
+/*
+ * Set window layouts - predefined methods to arrange windows. These are one-off
+ * and generate a layout tree.
+ */
+
+void layout_set_even_h(struct window *);
+void layout_set_even_v(struct window *);
+void layout_set_main_h(struct window *);
+void layout_set_main_v(struct window *);
+
+const struct {
+ const char *name;
+ void (*arrange)(struct window *);
+} layout_sets[] = {
+ { "even-horizontal", layout_set_even_h },
+ { "even-vertical", layout_set_even_v },
+ { "main-horizontal", layout_set_main_h },
+ { "main-vertical", layout_set_main_v },
+};
+
+const char *
+layout_set_name(u_int layout)
+{
+ return (layout_sets[layout].name);
+}
+
+int
+layout_set_lookup(const char *name)
+{
+ u_int i;
+ int matched = -1;
+
+ for (i = 0; i < nitems(layout_sets); i++) {
+ if (strncmp(layout_sets[i].name, name, strlen(name)) == 0) {
+ if (matched != -1) /* ambiguous */
+ return (-1);
+ matched = i;
+ }
+ }
+
+ return (matched);
+}