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.
This commit is contained in:
Nicholas Marriott
2009-07-19 13:21:40 +00:00
parent fc6a65c620
commit 6036bdd06c
25 changed files with 1298 additions and 636 deletions

View File

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