mirror of
https://github.com/tmux/tmux.git
synced 2026-06-21 09:45:41 +00:00
Updating tile-pane and float-pane to use new layout mechanics.
This commit is contained in:
339
layout.c
339
layout.c
@@ -66,6 +66,12 @@ layout_create_cell(struct layout_cell *lcparent)
|
||||
lc->xoff = INT_MAX;
|
||||
lc->yoff = INT_MAX;
|
||||
|
||||
lc->saved_sx = UINT_MAX;
|
||||
lc->saved_sy = UINT_MAX;
|
||||
|
||||
lc->saved_xoff = INT_MAX;
|
||||
lc->saved_yoff = INT_MAX;
|
||||
|
||||
lc->wp = NULL;
|
||||
|
||||
return (lc);
|
||||
@@ -190,6 +196,16 @@ layout_set_size(struct layout_cell *lc, u_int sx, u_int sy, int xoff, int yoff)
|
||||
lc->yoff = yoff;
|
||||
}
|
||||
|
||||
void
|
||||
layout_save_size(struct layout_cell *lc)
|
||||
{
|
||||
lc->saved_sx = lc->sx;
|
||||
lc->saved_sy = lc->sy;
|
||||
|
||||
lc->saved_xoff = lc->xoff;
|
||||
lc->saved_yoff = lc->yoff;
|
||||
}
|
||||
|
||||
/* Make a cell a leaf cell. */
|
||||
void
|
||||
layout_make_leaf(struct layout_cell *lc, struct window_pane *wp)
|
||||
@@ -290,13 +306,33 @@ layout_fix_offsets(struct window *w)
|
||||
|
||||
/*
|
||||
* Not all cells are drawn within the tiled grid of a layout. This predicate
|
||||
* isolates that logic.
|
||||
* isolates that logic. Nodes are considered tiled.
|
||||
*/
|
||||
int
|
||||
layout_cell_is_tiled(struct layout_cell *lc)
|
||||
{
|
||||
return ((~lc->flags & LAYOUT_CELL_HIDDEN) &&
|
||||
(~lc->flags & LAYOUT_CELL_FLOATING));
|
||||
int is_node, is_floating, is_hidden;
|
||||
|
||||
is_node = lc->type != LAYOUT_WINDOWPANE;
|
||||
is_floating = lc->flags & LAYOUT_CELL_FLOATING;
|
||||
is_hidden = lc->flags & LAYOUT_CELL_HIDDEN;
|
||||
|
||||
return is_node || (!is_floating && !is_hidden);
|
||||
}
|
||||
|
||||
static int
|
||||
layout_cell_has_tiled_child(struct layout_cell *lc)
|
||||
{
|
||||
struct layout_cell *lcchild;
|
||||
|
||||
if (lc == NULL || lc->type == LAYOUT_WINDOWPANE)
|
||||
return (0);
|
||||
|
||||
TAILQ_FOREACH(lcchild, &lc->cells, entry) {
|
||||
if (layout_cell_is_tiled(lcchild))
|
||||
return (1);
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
static int
|
||||
@@ -532,6 +568,12 @@ layout_resize_adjust(struct window *w, struct layout_cell *lc,
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* If a container doesn't have any tiled cells, there is nothing to do.
|
||||
*/
|
||||
if (!layout_cell_has_tiled_child(lc))
|
||||
return;
|
||||
|
||||
/*
|
||||
* Child cell runs in the same direction. Adjust each child equally
|
||||
* until no further change is possible.
|
||||
@@ -555,6 +597,20 @@ layout_resize_adjust(struct window *w, struct layout_cell *lc,
|
||||
}
|
||||
}
|
||||
|
||||
/* Resizes a cell to a specified size */
|
||||
void
|
||||
layout_resize_set(struct window *w, struct layout_cell *lc,
|
||||
enum layout_type type, u_int size)
|
||||
{
|
||||
int change;
|
||||
|
||||
if (type == LAYOUT_LEFTRIGHT)
|
||||
change = size - lc->sx;
|
||||
else
|
||||
change = size - lc->sy;
|
||||
layout_resize_adjust(w, lc, type, change);
|
||||
}
|
||||
|
||||
/*
|
||||
* Redistribute space equally among all visible (non-hidden WINDOWPANE)
|
||||
* children of lcparent in the given direction. Hidden WINDOWPANE leaves
|
||||
@@ -1238,6 +1294,73 @@ layout_resize_child_cells(struct window *w, struct layout_cell *lc)
|
||||
}
|
||||
}
|
||||
|
||||
/* Checks if there is enough space for two new panes. */
|
||||
int
|
||||
layout_split_check_space(struct window_pane *wp, struct layout_cell *lc,
|
||||
enum layout_type type)
|
||||
{
|
||||
struct style *sb_style = &wp->scrollbar_style;
|
||||
u_int minimum, sx = lc->sx, sy = lc->sy;
|
||||
int scrollbars, status;
|
||||
|
||||
status = options_get_number(wp->window->options, "pane-border-status");
|
||||
scrollbars = options_get_number(wp->window->options, "pane-scrollbars");
|
||||
|
||||
switch (type) {
|
||||
case LAYOUT_LEFTRIGHT:
|
||||
if (scrollbars) {
|
||||
minimum = PANE_MINIMUM * 2 + sb_style->width +
|
||||
sb_style->pad;
|
||||
} else
|
||||
minimum = PANE_MINIMUM * 2 + 1;
|
||||
if (sx < minimum)
|
||||
return (0);
|
||||
break;
|
||||
case LAYOUT_TOPBOTTOM:
|
||||
if (layout_add_horizontal_border(wp->window, lc, status))
|
||||
minimum = PANE_MINIMUM * 2 + 2;
|
||||
else
|
||||
minimum = PANE_MINIMUM * 2 + 1;
|
||||
if (sy < minimum)
|
||||
return (0);
|
||||
break;
|
||||
default:
|
||||
fatalx("bad layout type");
|
||||
}
|
||||
|
||||
return (1);
|
||||
}
|
||||
|
||||
/* Calculates the new cell sizes when splitting a pane. */
|
||||
void
|
||||
layout_split_sizes(struct layout_cell *lc, int size, int flags,
|
||||
enum layout_type type, u_int *size1, u_int *size2, u_int *saved_size)
|
||||
{
|
||||
u_int s1, s2, ss;
|
||||
u_int sx = lc->sx, sy = lc->sy;
|
||||
|
||||
if (type == LAYOUT_LEFTRIGHT)
|
||||
ss = sx;
|
||||
else
|
||||
ss = sy;
|
||||
if (size < 0)
|
||||
s2 = ((ss + 1) / 2) - 1;
|
||||
else if (flags & SPAWN_BEFORE)
|
||||
s2 = ss - size - 1;
|
||||
else
|
||||
s2 = size;
|
||||
if (s2 < PANE_MINIMUM)
|
||||
s2 = PANE_MINIMUM;
|
||||
else if (s2 > sx - 2)
|
||||
s2 = ss - 2;
|
||||
s1 = ss - 1 - s2;
|
||||
|
||||
*size1 = s1;
|
||||
*size2 = s2;
|
||||
*saved_size = ss;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Split a pane into two. size is a hint, or -1 for default half/half
|
||||
* split. This must be followed by layout_assign_pane before much else happens!
|
||||
@@ -1247,11 +1370,9 @@ layout_split_pane(struct window_pane *wp, enum layout_type type, int size,
|
||||
int flags)
|
||||
{
|
||||
struct layout_cell *lc, *lcparent, *lcnew, *lc1, *lc2;
|
||||
struct style *sb_style = &wp->scrollbar_style;
|
||||
u_int sx, sy, xoff, yoff, size1, size2, minimum;
|
||||
u_int sx, sy, xoff, yoff, size1, size2;
|
||||
u_int new_size, saved_size, resize_first = 0;
|
||||
int full_size = (flags & SPAWN_FULLSIZE), status;
|
||||
int scrollbars;
|
||||
int full_size = (flags & SPAWN_FULLSIZE);
|
||||
|
||||
/*
|
||||
* If full_size is specified, add a new cell at the top of the window
|
||||
@@ -1261,8 +1382,6 @@ layout_split_pane(struct window_pane *wp, enum layout_type type, int size,
|
||||
lc = wp->window->layout_root;
|
||||
else
|
||||
lc = wp->layout_cell;
|
||||
status = window_get_pane_status(wp->window);
|
||||
scrollbars = options_get_number(wp->window->options, "pane-scrollbars");
|
||||
|
||||
/* Copy the old cell size. */
|
||||
sx = lc->sx;
|
||||
@@ -1271,47 +1390,14 @@ layout_split_pane(struct window_pane *wp, enum layout_type type, int size,
|
||||
yoff = lc->yoff;
|
||||
|
||||
/* Check there is enough space for the two new panes. */
|
||||
switch (type) {
|
||||
case LAYOUT_LEFTRIGHT:
|
||||
if (scrollbars) {
|
||||
minimum = PANE_MINIMUM * 2 + sb_style->width +
|
||||
sb_style->pad;
|
||||
} else
|
||||
minimum = PANE_MINIMUM * 2 + 1;
|
||||
if (sx < minimum)
|
||||
return (NULL);
|
||||
break;
|
||||
case LAYOUT_TOPBOTTOM:
|
||||
if (layout_add_horizontal_border(wp->window, lc, status))
|
||||
minimum = PANE_MINIMUM * 2 + 2;
|
||||
else
|
||||
minimum = PANE_MINIMUM * 2 + 1;
|
||||
if (sy < minimum)
|
||||
return (NULL);
|
||||
break;
|
||||
default:
|
||||
fatalx("bad layout type");
|
||||
}
|
||||
if (!layout_split_check_space(wp, lc, type))
|
||||
return (NULL);
|
||||
|
||||
/*
|
||||
* Calculate new cell sizes. size is the target size or -1 for middle
|
||||
* split, size1 is the size of the top/left and size2 the bottom/right.
|
||||
*/
|
||||
if (type == LAYOUT_LEFTRIGHT)
|
||||
saved_size = sx;
|
||||
else
|
||||
saved_size = sy;
|
||||
if (size < 0)
|
||||
size2 = ((saved_size + 1) / 2) - 1;
|
||||
else if (flags & SPAWN_BEFORE)
|
||||
size2 = saved_size - size - 1;
|
||||
else
|
||||
size2 = size;
|
||||
if (size2 < PANE_MINIMUM)
|
||||
size2 = PANE_MINIMUM;
|
||||
else if (size2 > saved_size - 2)
|
||||
size2 = saved_size - 2;
|
||||
size1 = saved_size - 1 - size2;
|
||||
layout_split_sizes(lc, size, flags, type, &size1, &size2, &saved_size);
|
||||
|
||||
/* Which size are we using? */
|
||||
if (flags & SPAWN_BEFORE)
|
||||
@@ -1619,51 +1705,41 @@ layout_get_tiled_cell(struct cmdq_item *item, struct args *args,
|
||||
return (lc);
|
||||
}
|
||||
|
||||
/* Get a new floating cell. */
|
||||
struct layout_cell *
|
||||
layout_get_floating_cell(struct cmdq_item *item, struct args *args,
|
||||
struct window *w, struct window_pane *wp, char **cause)
|
||||
void
|
||||
layout_cell_floating_args(struct cmdq_item *item, struct args *args,
|
||||
struct window *w, u_int *sxp, u_int *syp, int *oxp, int *oyp, char **cause)
|
||||
{
|
||||
struct layout_cell *lcnew;
|
||||
u_int sx = w->sx / 2, sy = w->sy / 4;
|
||||
int ox = INT_MAX, oy = INT_MAX;
|
||||
char *error;
|
||||
int sx, sy, ox, oy;
|
||||
|
||||
sx = *sxp == UINT_MAX ? w->sx / 2 : *sxp;
|
||||
sy = *syp == UINT_MAX ? w->sy / 4 : *syp;
|
||||
ox = *oxp == INT_MAX ? INT_MAX : *oxp;
|
||||
oy = *oyp == INT_MAX ? INT_MAX : *oyp;
|
||||
|
||||
if (args_has(args, 'x')) {
|
||||
sx = args_percentage_and_expand(args, 'x', 0, w->sx - 1, w->sx,
|
||||
item, &error);
|
||||
if (error != NULL) {
|
||||
xasprintf(cause, "position %s", error);
|
||||
free(error);
|
||||
return (NULL);
|
||||
}
|
||||
item, cause);
|
||||
if (*cause != NULL)
|
||||
return;
|
||||
}
|
||||
if (args_has(args, 'y')) {
|
||||
sy = args_percentage_and_expand(args, 'y', 0, w->sy - 1, w->sy,
|
||||
item, &error);
|
||||
if (error != NULL) {
|
||||
xasprintf(cause, "position %s", error);
|
||||
free(error);
|
||||
return (NULL);
|
||||
}
|
||||
item, cause);
|
||||
if (*cause != NULL)
|
||||
return;
|
||||
}
|
||||
if (args_has(args, 'X')) {
|
||||
ox = args_percentage_and_expand(args, 'X', -sx, w->sx,
|
||||
w->sx, item, &error);
|
||||
if (error != NULL) {
|
||||
xasprintf(cause, "size %s", error);
|
||||
free(error);
|
||||
return (NULL);
|
||||
}
|
||||
ox = args_percentage_and_expand(args, 'X', -(int)w->sx, w->sx,
|
||||
w->sx, item, cause);
|
||||
if (*cause != NULL)
|
||||
return;
|
||||
}
|
||||
if (args_has(args, 'Y')) {
|
||||
oy = args_percentage_and_expand(args, 'Y', -sy, w->sy,
|
||||
w->sy, item, &error);
|
||||
if (error != NULL) {
|
||||
xasprintf(cause, "size %s", error);
|
||||
free(error);
|
||||
return (NULL);
|
||||
}
|
||||
oy = args_percentage_and_expand(args, 'Y', -(int)w->sy, w->sy,
|
||||
w->sy, item, cause);
|
||||
if (*cause != NULL)
|
||||
return;
|
||||
>>>>>>> 5d81c9e4 (Updating tile-pane and float-pane to use new layout mechanics.)
|
||||
}
|
||||
|
||||
if (ox == INT_MAX) {
|
||||
@@ -1686,6 +1762,25 @@ layout_get_floating_cell(struct cmdq_item *item, struct args *args,
|
||||
}
|
||||
w->last_new_pane_y = oy;
|
||||
}
|
||||
*sxp = sx;
|
||||
*syp = sy;
|
||||
*oxp = ox;
|
||||
*oyp = oy;
|
||||
}
|
||||
|
||||
/* Get a new floating cell. */
|
||||
struct layout_cell *
|
||||
layout_get_floating_cell(struct cmdq_item *item, struct args *args,
|
||||
struct window *w, struct window_pane *wp, char **cause)
|
||||
{
|
||||
struct layout_cell *lcnew;
|
||||
u_int sx, sy;
|
||||
int ox, oy;
|
||||
|
||||
layout_cell_floating_args(item, args, w, &sx, &sy, &ox, &oy, cause);
|
||||
if (cause != NULL) {
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
if (sx < PANE_MINIMUM || sx > PANE_MAXIMUM) {
|
||||
*cause = xstrdup("invalid width");
|
||||
@@ -1699,3 +1794,89 @@ layout_get_floating_cell(struct cmdq_item *item, struct args *args,
|
||||
lcnew = layout_floating_pane(w, wp, sx, sy, ox, oy);
|
||||
return (lcnew);
|
||||
}
|
||||
|
||||
int
|
||||
layout_cell_remove_tile(struct window *w, struct layout_cell *lc)
|
||||
{
|
||||
struct layout_cell *lcother, *lcparent;
|
||||
enum layout_type type;
|
||||
int change;
|
||||
|
||||
if (lc->flags & LAYOUT_CELL_FLOATING)
|
||||
return (0);
|
||||
|
||||
lcother = layout_cell_get_neighbour(lc);
|
||||
if (lcother == NULL) {
|
||||
layout_cell_remove_tile(w, lc->parent);
|
||||
} else if ((lcparent = lcother->parent) != NULL) {
|
||||
type = lcparent->type;
|
||||
if (type == LAYOUT_TOPBOTTOM)
|
||||
change = lcother->sy + 1;
|
||||
else
|
||||
change = lcother->sx + 1;
|
||||
layout_resize_adjust(w, lcother, type, change);
|
||||
}
|
||||
|
||||
layout_set_size(lc, 0, 0, 0, 0);
|
||||
return (1);
|
||||
}
|
||||
|
||||
int
|
||||
layout_cell_insert_tile(struct window *w, struct layout_cell *lc)
|
||||
{
|
||||
struct window_pane *wp;
|
||||
struct layout_cell *lcother, *lcparent = lc->parent;
|
||||
enum layout_type type;
|
||||
u_int size1, size2, saved_size;
|
||||
int flags = 0;
|
||||
|
||||
if (lc == NULL)
|
||||
return (0);
|
||||
|
||||
if (lcparent == NULL) {
|
||||
layout_set_size(lc, w->sx, w->sy, 0, 0);
|
||||
return (1);
|
||||
}
|
||||
|
||||
type = lcparent->type;
|
||||
lcother = layout_cell_get_neighbour(lc);
|
||||
if (lcother == NULL) {
|
||||
/*
|
||||
* This is now the only revealed cell in the parent. Reveal the
|
||||
* parent, then set the child's 'type' dimension.
|
||||
*/
|
||||
layout_cell_insert_tile(w, lcparent);
|
||||
if (type == LAYOUT_LEFTRIGHT)
|
||||
size1 = lcparent->sx;
|
||||
else
|
||||
size1 = lcparent->sy;
|
||||
layout_resize_set(w, lc, type, size1);
|
||||
} else {
|
||||
if (lcother->wp == NULL) /* neighbour is a container */
|
||||
wp = TAILQ_FIRST(&lcother->cells)->wp;
|
||||
else
|
||||
wp = lcother->wp;
|
||||
/*
|
||||
* Failure point requires clearing concealed flag in many spots
|
||||
*/
|
||||
if (!layout_split_check_space(wp, lcother, type))
|
||||
return (0);
|
||||
layout_split_sizes(lcother, -1, flags, type, &size1, &size2,
|
||||
&saved_size);
|
||||
layout_resize_set(w, lc, type, size1);
|
||||
layout_resize_set(w, lcother, type, size2);
|
||||
}
|
||||
|
||||
/* Setting the opposite of 'type' dimension. */
|
||||
if (lcparent != NULL) {
|
||||
if (lcparent->type == LAYOUT_LEFTRIGHT) {
|
||||
size1 = lcparent->sy;
|
||||
type = LAYOUT_TOPBOTTOM;
|
||||
} else {
|
||||
size1 = lcparent->sx;
|
||||
type = LAYOUT_LEFTRIGHT;
|
||||
}
|
||||
layout_resize_set(w, lc, type, size1);
|
||||
}
|
||||
return (1);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user