diff options
author | Nicholas Marriott <nicm@cvs.openbsd.org> | 2009-07-19 13:21:41 +0000 |
---|---|---|
committer | Nicholas Marriott <nicm@cvs.openbsd.org> | 2009-07-19 13:21:41 +0000 |
commit | 0a2a020bb1719511145e8cf18794a0b585188946 (patch) | |
tree | 6dc87cd44a35c71c97e69f7dc981810a92a68fc1 /usr.bin/tmux/window.c | |
parent | 46b6a514f4de53a5ae1a61be419d3e14534f3ab4 (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.
Diffstat (limited to 'usr.bin/tmux/window.c')
-rw-r--r-- | usr.bin/tmux/window.c | 55 |
1 files changed, 20 insertions, 35 deletions
diff --git a/usr.bin/tmux/window.c b/usr.bin/tmux/window.c index f4f60fc6f57..c632b1eeba4 100644 --- a/usr.bin/tmux/window.c +++ b/usr.bin/tmux/window.c @@ -1,4 +1,4 @@ -/* $OpenBSD: window.c,v 1.13 2009/07/17 18:45:08 nicm Exp $ */ +/* $OpenBSD: window.c,v 1.14 2009/07/19 13:21:40 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> @@ -35,7 +35,7 @@ #include "tmux.h" /* - * Each window is attached to one or two panes, each of which is a pty. This + * Each window is attached to a number of panes, each of which is a pty. This * file contains code to handle them. * * A pane has two buffers attached, these are filled and emptied by the main @@ -230,8 +230,10 @@ window_create1(u_int sx, u_int sy) TAILQ_INIT(&w->panes); w->active = NULL; - w->layout = 0; + w->layout = 0; + w->layout_root = NULL; + w->sx = sx; w->sy = sy; @@ -254,15 +256,20 @@ struct window * window_create(const char *name, const char *cmd, const char *cwd, const char **envp, u_int sx, u_int sy, u_int hlimit, char **cause) { - struct window *w; + struct window *w; + struct window_pane *wp; w = window_create1(sx, sy); - if (window_add_pane(w, -1, cmd, cwd, envp, hlimit, cause) == NULL) { + if ((wp = window_add_pane(w, hlimit, cause)) == NULL) { + window_destroy(w); + return (NULL); + } + layout_init(w); + if (window_pane_spawn(wp, cmd, cwd, envp, cause) != 0) { window_destroy(w); return (NULL); } w->active = TAILQ_FIRST(&w->panes); - if (name != NULL) { w->name = xstrdup(name); options_set_number(&w->options, "automatic-rename", 0); @@ -282,6 +289,9 @@ window_destroy(struct window *w) while (!ARRAY_EMPTY(&windows) && ARRAY_LAST(&windows) == NULL) ARRAY_TRUNC(&windows, 1); + if (w->layout_root != NULL) + layout_free(w); + options_free(&w->options); window_destroy_panes(w); @@ -304,7 +314,6 @@ void window_set_active_pane(struct window *w, struct window_pane *wp) { w->active = wp; - while (!window_pane_visible(w->active)) { w->active = TAILQ_PREV(w->active, window_panes, entry); if (w->active == NULL) @@ -315,41 +324,15 @@ window_set_active_pane(struct window *w, struct window_pane *wp) } struct window_pane * -window_add_pane(struct window *w, int wanty, const char *cmd, - const char *cwd, const char **envp, u_int hlimit, char **cause) +window_add_pane(struct window *w, u_int hlimit, unused char **cause) { struct window_pane *wp; - u_int sizey; - if (TAILQ_EMPTY(&w->panes)) - wanty = w->sy; - else { - sizey = w->active->sy - 1; /* for separator */ - if (sizey < PANE_MINIMUM * 2) { - *cause = xstrdup("pane too small"); - return (NULL); - } - - if (wanty == -1) - wanty = sizey / 2; - - if (wanty < PANE_MINIMUM) - wanty = PANE_MINIMUM; - if ((u_int) wanty > sizey - PANE_MINIMUM) - wanty = sizey - PANE_MINIMUM; - - window_pane_resize(w->active, w->sx, sizey - wanty); - } - - wp = window_pane_create(w, w->sx, wanty, hlimit); + wp = window_pane_create(w, w->sx, w->sy, hlimit); if (TAILQ_EMPTY(&w->panes)) TAILQ_INSERT_HEAD(&w->panes, wp, entry); else TAILQ_INSERT_AFTER(&w->panes, w->active, wp, entry); - if (window_pane_spawn(wp, cmd, cwd, envp, cause) != 0) { - window_remove_pane(w, wp); - return (NULL); - } return (wp); } @@ -435,6 +418,8 @@ window_pane_create(struct window *w, u_int sx, u_int sy, u_int hlimit) wp->mode = NULL; + wp->layout_cell = NULL; + wp->xoff = 0; wp->yoff = 0; |