2009-05-04 19:58:27 +02:00
|
|
|
/* $Id: layout.c,v 1.6 2009-05-04 17:58:27 nicm Exp $ */
|
2009-04-01 20:21:42 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* 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"
|
|
|
|
|
2009-04-01 23:10:08 +02:00
|
|
|
/*
|
|
|
|
* Layout functions: second argument (int) is 1 if definitely the /only/ change
|
|
|
|
* has been the active pane has changed. If 0 then panes, active pane or both
|
|
|
|
* may have changed.
|
|
|
|
*/
|
|
|
|
void layout_manual(struct window *, int);
|
|
|
|
void layout_active_only(struct window *, int);
|
|
|
|
void layout_even_horizontal(struct window *, int);
|
|
|
|
void layout_even_vertical(struct window *, int);
|
|
|
|
void layout_left_vertical(struct window *, int);
|
2009-04-01 20:21:42 +02:00
|
|
|
|
|
|
|
const struct {
|
|
|
|
const char *name;
|
2009-04-01 23:10:08 +02:00
|
|
|
void (*fn)(struct window *, int);
|
2009-04-01 20:21:42 +02:00
|
|
|
} layouts[] = {
|
|
|
|
{ "manual", layout_manual },
|
|
|
|
{ "active-only", layout_active_only },
|
|
|
|
{ "even-horizontal", layout_even_horizontal },
|
|
|
|
{ "even-vertical", layout_even_vertical },
|
|
|
|
{ "left-vertical", layout_left_vertical },
|
2009-05-04 19:58:27 +02:00
|
|
|
};
|
2009-04-01 20:21:42 +02:00
|
|
|
|
2009-04-30 18:27:29 +02:00
|
|
|
const char *
|
|
|
|
layout_name(struct window *w)
|
|
|
|
{
|
|
|
|
return (layouts[w->layout].name);
|
|
|
|
}
|
|
|
|
|
2009-04-01 20:21:42 +02:00
|
|
|
void
|
|
|
|
layout_next(struct window *w)
|
|
|
|
{
|
|
|
|
w->layout++;
|
|
|
|
if (w->layout > nitems(layouts) - 1) {
|
|
|
|
w->layout = 0;
|
|
|
|
/* XXX Special-case manual. */
|
|
|
|
window_fit_panes(w);
|
|
|
|
window_update_panes(w);
|
|
|
|
}
|
2009-04-01 23:10:08 +02:00
|
|
|
layout_refresh(w, 0);
|
2009-04-01 20:21:42 +02:00
|
|
|
}
|
|
|
|
|
2009-04-30 23:17:06 +02:00
|
|
|
void
|
|
|
|
layout_previous(struct window *w)
|
|
|
|
{
|
|
|
|
if (w->layout == 0)
|
|
|
|
w->layout = nitems(layouts) - 1;
|
|
|
|
else
|
|
|
|
w->layout--;
|
|
|
|
if (w->layout == 0) {
|
|
|
|
/* XXX Special-case manual. */
|
|
|
|
window_fit_panes(w);
|
|
|
|
window_update_panes(w);
|
|
|
|
}
|
|
|
|
layout_refresh(w, 0);
|
|
|
|
}
|
|
|
|
|
2009-04-01 20:21:42 +02:00
|
|
|
void
|
2009-04-01 23:10:08 +02:00
|
|
|
layout_refresh(struct window *w, unused int active_changed)
|
2009-04-01 20:21:42 +02:00
|
|
|
{
|
2009-04-01 23:10:08 +02:00
|
|
|
layouts[w->layout].fn(w, active_changed);
|
2009-04-01 20:21:42 +02:00
|
|
|
server_redraw_window(w);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-04-01 23:10:08 +02:00
|
|
|
layout_manual(unused struct window *w, unused int active_changed)
|
2009-04-01 20:21:42 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-04-01 23:10:08 +02:00
|
|
|
layout_active_only(struct window *w, unused int active_changed)
|
2009-04-01 20:21:42 +02:00
|
|
|
{
|
|
|
|
struct window_pane *wp;
|
2009-05-04 19:58:27 +02:00
|
|
|
|
2009-04-01 20:21:42 +02:00
|
|
|
TAILQ_FOREACH(wp, &w->panes, entry) {
|
2009-05-04 19:58:27 +02:00
|
|
|
if (wp == w->active) {
|
2009-04-01 20:21:42 +02:00
|
|
|
wp->flags &= ~PANE_HIDDEN;
|
|
|
|
wp->xoff = wp->yoff = 0;
|
|
|
|
window_pane_resize(wp, w->sx, w->sy);
|
|
|
|
} else
|
|
|
|
wp->flags |= PANE_HIDDEN;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-04-01 23:10:08 +02:00
|
|
|
layout_even_horizontal(struct window *w, int active_changed)
|
2009-04-01 20:21:42 +02:00
|
|
|
{
|
|
|
|
struct window_pane *wp;
|
|
|
|
u_int i, n, width, xoff;
|
|
|
|
|
2009-04-01 23:10:08 +02:00
|
|
|
if (active_changed)
|
|
|
|
return;
|
|
|
|
|
2009-04-01 20:48:09 +02:00
|
|
|
/* Get number of panes. */
|
2009-04-01 20:21:42 +02:00
|
|
|
n = window_count_panes(w);
|
2009-04-01 20:48:09 +02:00
|
|
|
if (n == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* How many can we fit? */
|
2009-04-01 20:21:42 +02:00
|
|
|
if (w->sx / n < PANE_MINIMUM) {
|
|
|
|
width = PANE_MINIMUM;
|
|
|
|
n = w->sx / PANE_MINIMUM;
|
|
|
|
} else
|
|
|
|
width = w->sx / n;
|
2009-05-04 19:58:27 +02:00
|
|
|
|
2009-04-01 20:21:42 +02:00
|
|
|
/* Fit the panes. */
|
|
|
|
i = xoff = 0;
|
|
|
|
TAILQ_FOREACH(wp, &w->panes, entry) {
|
|
|
|
if (i > n) {
|
|
|
|
wp->flags |= PANE_HIDDEN;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
wp->flags &= ~PANE_HIDDEN;
|
|
|
|
|
|
|
|
wp->xoff = xoff;
|
|
|
|
wp->yoff = 0;
|
|
|
|
if (i != n - 1)
|
|
|
|
window_pane_resize(wp, width - 1, w->sy);
|
|
|
|
else
|
|
|
|
window_pane_resize(wp, width, w->sy);
|
|
|
|
|
|
|
|
i++;
|
|
|
|
xoff += width;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Any space left? */
|
|
|
|
while (xoff++ < w->sx) {
|
|
|
|
wp = TAILQ_LAST(&w->panes, window_panes);
|
|
|
|
window_pane_resize(wp, wp->sx + 1, wp->sy);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-04-01 23:10:08 +02:00
|
|
|
layout_even_vertical(struct window *w, int active_changed)
|
2009-04-01 20:21:42 +02:00
|
|
|
{
|
|
|
|
struct window_pane *wp;
|
|
|
|
u_int i, n, height, yoff;
|
|
|
|
|
2009-04-01 23:10:08 +02:00
|
|
|
if (active_changed)
|
|
|
|
return;
|
|
|
|
|
2009-04-01 20:48:09 +02:00
|
|
|
/* Get number of panes. */
|
2009-04-01 20:21:42 +02:00
|
|
|
n = window_count_panes(w);
|
2009-04-01 20:48:09 +02:00
|
|
|
if (n == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* How many can we fit? */
|
2009-04-01 20:21:42 +02:00
|
|
|
if (w->sy / n < PANE_MINIMUM) {
|
|
|
|
height = PANE_MINIMUM;
|
|
|
|
n = w->sy / PANE_MINIMUM;
|
|
|
|
} else
|
|
|
|
height = w->sy / n;
|
2009-05-04 19:58:27 +02:00
|
|
|
|
2009-04-01 20:21:42 +02:00
|
|
|
/* Fit the panes. */
|
|
|
|
i = yoff = 0;
|
|
|
|
TAILQ_FOREACH(wp, &w->panes, entry) {
|
|
|
|
if (i > n) {
|
|
|
|
wp->flags |= PANE_HIDDEN;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
wp->flags &= ~PANE_HIDDEN;
|
|
|
|
|
|
|
|
wp->xoff = 0;
|
|
|
|
wp->yoff = yoff;
|
|
|
|
if (i != n - 1)
|
|
|
|
window_pane_resize(wp, w->sx, height - 1);
|
|
|
|
else
|
|
|
|
window_pane_resize(wp, w->sx, height);
|
|
|
|
|
|
|
|
i++;
|
|
|
|
yoff += height;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Any space left? */
|
|
|
|
while (yoff++ < w->sy) {
|
|
|
|
wp = TAILQ_LAST(&w->panes, window_panes);
|
|
|
|
window_pane_resize(wp, wp->sx, wp->sy + 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-04-01 23:10:08 +02:00
|
|
|
layout_left_vertical(struct window *w, int active_changed)
|
2009-04-01 20:21:42 +02:00
|
|
|
{
|
|
|
|
struct window_pane *wp;
|
|
|
|
u_int i, n, height, yoff;
|
|
|
|
|
2009-04-01 23:10:08 +02:00
|
|
|
if (active_changed)
|
|
|
|
return;
|
|
|
|
|
2009-04-01 20:48:09 +02:00
|
|
|
/* Get number of panes. */
|
|
|
|
n = window_count_panes(w);
|
|
|
|
if (n == 0)
|
|
|
|
return;
|
|
|
|
|
2009-04-01 20:21:42 +02:00
|
|
|
/* Need >1 pane and minimum columns; if fewer, display active only. */
|
2009-04-01 20:48:09 +02:00
|
|
|
if (n == 1 || w->sx < 82 + PANE_MINIMUM) {
|
2009-04-01 23:10:08 +02:00
|
|
|
layout_active_only(w, active_changed);
|
2009-04-01 20:21:42 +02:00
|
|
|
return;
|
|
|
|
}
|
2009-04-01 20:48:09 +02:00
|
|
|
n--;
|
2009-04-01 20:21:42 +02:00
|
|
|
|
|
|
|
/* How many can we fit, not including first? */
|
|
|
|
if (w->sy / n < PANE_MINIMUM) {
|
|
|
|
height = PANE_MINIMUM;
|
|
|
|
n = w->sy / PANE_MINIMUM;
|
|
|
|
} else
|
|
|
|
height = w->sy / n;
|
2009-05-04 19:58:27 +02:00
|
|
|
|
2009-04-01 20:21:42 +02:00
|
|
|
/* Fit the panes. */
|
|
|
|
i = yoff = 0;
|
|
|
|
TAILQ_FOREACH(wp, &w->panes, entry) {
|
|
|
|
if (wp == TAILQ_FIRST(&w->panes)) {
|
|
|
|
wp->xoff = 0;
|
|
|
|
wp->yoff = 0;
|
|
|
|
window_pane_resize(wp, 81, w->sy);
|
|
|
|
wp->flags &= ~PANE_HIDDEN;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (i > n) {
|
|
|
|
wp->flags |= PANE_HIDDEN;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
wp->flags &= ~PANE_HIDDEN;
|
|
|
|
|
|
|
|
wp->xoff = 82;
|
|
|
|
wp->yoff = yoff;
|
|
|
|
if (i != n - 1)
|
|
|
|
window_pane_resize(wp, w->sx - 82, height - 1);
|
|
|
|
else
|
|
|
|
window_pane_resize(wp, w->sx - 82, height);
|
|
|
|
|
|
|
|
i++;
|
|
|
|
yoff += height;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Any space left? */
|
|
|
|
while (yoff++ < w->sy) {
|
|
|
|
wp = TAILQ_LAST(&w->panes, window_panes);
|
|
|
|
while (wp != NULL && wp == TAILQ_FIRST(&w->panes))
|
|
|
|
wp = TAILQ_PREV(wp, window_panes, entry);
|
|
|
|
if (wp == NULL)
|
|
|
|
break;
|
|
|
|
window_pane_resize(wp, wp->sx, wp->sy + 1);
|
|
|
|
}
|
|
|
|
}
|