2009-06-01 22:58:49 +00:00
|
|
|
/* $OpenBSD$ */
|
|
|
|
|
|
|
|
/*
|
2016-01-19 15:59:12 +00:00
|
|
|
* Copyright (c) 2009 Nicholas Marriott <nicholas.marriott@gmail.com>
|
2016-09-04 17:37:06 +00:00
|
|
|
* Copyright (c) 2016 Stephen Kent <smkent@smkent.net>
|
2009-06-01 22:58:49 +00:00
|
|
|
*
|
|
|
|
* 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>
|
|
|
|
|
2009-07-19 13:21:40 +00:00
|
|
|
#include <stdlib.h>
|
2009-06-01 22:58:49 +00:00
|
|
|
|
|
|
|
#include "tmux.h"
|
|
|
|
|
|
|
|
/*
|
2009-07-19 13:21:40 +00:00
|
|
|
* The window layout is a tree of cells each of which can be one of: a
|
|
|
|
* left-right container for a list of cells, a top-bottom container for a list
|
|
|
|
* of cells, or a container for a window pane.
|
2009-06-01 22:58:49 +00:00
|
|
|
*
|
2009-07-19 13:21:40 +00:00
|
|
|
* Each window has a pointer to the root of its layout tree (containing its
|
|
|
|
* panes), every pane has a pointer back to the cell containing it, and each
|
|
|
|
* cell a pointer to its parent cell.
|
2009-06-01 22:58:49 +00:00
|
|
|
*/
|
|
|
|
|
2016-08-03 09:07:02 +00:00
|
|
|
static u_int layout_resize_check(struct window *, struct layout_cell *,
|
|
|
|
enum layout_type);
|
|
|
|
static int layout_resize_pane_grow(struct window *, struct layout_cell *,
|
2016-10-10 17:28:30 +00:00
|
|
|
enum layout_type, int, int);
|
2016-08-03 09:07:02 +00:00
|
|
|
static int layout_resize_pane_shrink(struct window *, struct layout_cell *,
|
2016-04-29 15:00:48 +00:00
|
|
|
enum layout_type, int);
|
|
|
|
static int layout_need_status(struct layout_cell *, int);
|
2016-09-04 17:37:06 +00:00
|
|
|
static u_int layout_new_pane_size(struct window *, u_int,
|
|
|
|
struct layout_cell *, enum layout_type, u_int, u_int,
|
|
|
|
u_int);
|
|
|
|
static int layout_set_size_check(struct window *, struct layout_cell *,
|
|
|
|
enum layout_type, int);
|
|
|
|
static void layout_resize_child_cells(struct window *,
|
|
|
|
struct layout_cell *);
|
2009-07-19 13:21:40 +00:00
|
|
|
|
|
|
|
struct layout_cell *
|
|
|
|
layout_create_cell(struct layout_cell *lcparent)
|
2009-06-01 22:58:49 +00:00
|
|
|
{
|
2009-07-19 13:21:40 +00:00
|
|
|
struct layout_cell *lc;
|
|
|
|
|
|
|
|
lc = xmalloc(sizeof *lc);
|
|
|
|
lc->type = LAYOUT_WINDOWPANE;
|
|
|
|
lc->parent = lcparent;
|
|
|
|
|
|
|
|
TAILQ_INIT(&lc->cells);
|
2009-12-03 22:50:09 +00:00
|
|
|
|
2009-07-19 13:21:40 +00:00
|
|
|
lc->sx = UINT_MAX;
|
|
|
|
lc->sy = UINT_MAX;
|
2009-12-03 22:50:09 +00:00
|
|
|
|
2009-07-19 13:21:40 +00:00
|
|
|
lc->xoff = UINT_MAX;
|
|
|
|
lc->yoff = UINT_MAX;
|
2009-12-03 22:50:09 +00:00
|
|
|
|
2009-07-19 13:21:40 +00:00
|
|
|
lc->wp = NULL;
|
|
|
|
|
|
|
|
return (lc);
|
2009-06-01 22:58:49 +00:00
|
|
|
}
|
|
|
|
|
2009-07-19 13:21:40 +00:00
|
|
|
void
|
|
|
|
layout_free_cell(struct layout_cell *lc)
|
2009-06-01 22:58:49 +00:00
|
|
|
{
|
2009-07-19 13:21:40 +00:00
|
|
|
struct layout_cell *lcchild;
|
|
|
|
|
|
|
|
switch (lc->type) {
|
|
|
|
case LAYOUT_LEFTRIGHT:
|
|
|
|
case LAYOUT_TOPBOTTOM:
|
|
|
|
while (!TAILQ_EMPTY(&lc->cells)) {
|
|
|
|
lcchild = TAILQ_FIRST(&lc->cells);
|
|
|
|
TAILQ_REMOVE(&lc->cells, lcchild, entry);
|
|
|
|
layout_free_cell(lcchild);
|
2009-06-01 22:58:49 +00:00
|
|
|
}
|
2009-07-19 13:21:40 +00:00
|
|
|
break;
|
|
|
|
case LAYOUT_WINDOWPANE:
|
|
|
|
if (lc->wp != NULL)
|
|
|
|
lc->wp->layout_cell = NULL;
|
|
|
|
break;
|
2009-06-01 22:58:49 +00:00
|
|
|
}
|
|
|
|
|
2012-07-10 11:53:01 +00:00
|
|
|
free(lc);
|
2009-06-01 22:58:49 +00:00
|
|
|
}
|
|
|
|
|
2009-07-19 13:21:40 +00:00
|
|
|
void
|
|
|
|
layout_print_cell(struct layout_cell *lc, const char *hdr, u_int n)
|
2009-06-01 22:58:49 +00:00
|
|
|
{
|
2009-07-19 13:21:40 +00:00
|
|
|
struct layout_cell *lcchild;
|
2018-01-12 10:16:03 +00:00
|
|
|
const char *type;
|
2009-07-19 13:21:40 +00:00
|
|
|
|
2018-01-12 10:16:03 +00:00
|
|
|
switch (lc->type) {
|
|
|
|
case LAYOUT_LEFTRIGHT:
|
|
|
|
type = "LEFTRIGHT";
|
|
|
|
break;
|
|
|
|
case LAYOUT_TOPBOTTOM:
|
|
|
|
type = "TOPBOTTOM";
|
|
|
|
break;
|
|
|
|
case LAYOUT_WINDOWPANE:
|
|
|
|
type = "WINDOWPANE";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
type = "UNKNOWN";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
log_debug("%s:%*s%p type %s [parent %p] wp=%p [%u,%u %ux%u]", hdr, n,
|
|
|
|
" ", lc, type, lc->parent, lc->wp, lc->xoff, lc->yoff, lc->sx,
|
2015-12-11 16:37:21 +00:00
|
|
|
lc->sy);
|
2009-07-19 13:21:40 +00:00
|
|
|
switch (lc->type) {
|
|
|
|
case LAYOUT_LEFTRIGHT:
|
|
|
|
case LAYOUT_TOPBOTTOM:
|
|
|
|
TAILQ_FOREACH(lcchild, &lc->cells, entry)
|
|
|
|
layout_print_cell(lcchild, hdr, n + 1);
|
|
|
|
break;
|
|
|
|
case LAYOUT_WINDOWPANE:
|
|
|
|
break;
|
|
|
|
}
|
2009-06-01 22:58:49 +00:00
|
|
|
}
|
|
|
|
|
2018-06-08 20:54:22 +00:00
|
|
|
struct layout_cell *
|
|
|
|
layout_search_by_border(struct layout_cell *lc, u_int x, u_int y)
|
|
|
|
{
|
|
|
|
struct layout_cell *lcchild, *last = NULL;
|
|
|
|
|
|
|
|
TAILQ_FOREACH(lcchild, &lc->cells, entry) {
|
|
|
|
if (x >= lcchild->xoff && x < lcchild->xoff + lcchild->sx &&
|
|
|
|
y >= lcchild->yoff && y < lcchild->yoff + lcchild->sy) {
|
|
|
|
/* Inside the cell - recurse. */
|
|
|
|
return (layout_search_by_border(lcchild, x, y));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (last == NULL) {
|
|
|
|
last = lcchild;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (lc->type) {
|
|
|
|
case LAYOUT_LEFTRIGHT:
|
|
|
|
if (x < lcchild->xoff && x >= last->xoff + last->sx)
|
|
|
|
return (last);
|
|
|
|
break;
|
|
|
|
case LAYOUT_TOPBOTTOM:
|
|
|
|
if (y < lcchild->yoff && y >= last->yoff + last->sy)
|
|
|
|
return (last);
|
|
|
|
break;
|
|
|
|
case LAYOUT_WINDOWPANE:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
last = lcchild;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
|
2009-06-01 22:58:49 +00:00
|
|
|
void
|
2015-12-11 16:37:21 +00:00
|
|
|
layout_set_size(struct layout_cell *lc, u_int sx, u_int sy, u_int xoff,
|
|
|
|
u_int yoff)
|
2009-06-01 22:58:49 +00:00
|
|
|
{
|
2009-07-19 13:21:40 +00:00
|
|
|
lc->sx = sx;
|
|
|
|
lc->sy = sy;
|
|
|
|
|
|
|
|
lc->xoff = xoff;
|
|
|
|
lc->yoff = yoff;
|
2009-06-01 22:58:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-07-19 13:21:40 +00:00
|
|
|
layout_make_leaf(struct layout_cell *lc, struct window_pane *wp)
|
2009-06-01 22:58:49 +00:00
|
|
|
{
|
2009-07-19 13:21:40 +00:00
|
|
|
lc->type = LAYOUT_WINDOWPANE;
|
|
|
|
|
|
|
|
TAILQ_INIT(&lc->cells);
|
|
|
|
|
|
|
|
wp->layout_cell = lc;
|
|
|
|
lc->wp = wp;
|
2009-06-01 22:58:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-07-19 13:21:40 +00:00
|
|
|
layout_make_node(struct layout_cell *lc, enum layout_type type)
|
2009-06-01 22:58:49 +00:00
|
|
|
{
|
2009-07-19 13:21:40 +00:00
|
|
|
if (type == LAYOUT_WINDOWPANE)
|
|
|
|
fatalx("bad layout type");
|
|
|
|
lc->type = type;
|
2009-06-01 22:58:49 +00:00
|
|
|
|
2009-07-19 13:21:40 +00:00
|
|
|
TAILQ_INIT(&lc->cells);
|
2009-06-01 22:58:49 +00:00
|
|
|
|
2009-07-19 13:21:40 +00:00
|
|
|
if (lc->wp != NULL)
|
|
|
|
lc->wp->layout_cell = NULL;
|
|
|
|
lc->wp = NULL;
|
2009-06-01 22:58:49 +00:00
|
|
|
}
|
|
|
|
|
2009-07-19 13:21:40 +00:00
|
|
|
/* Fix cell offsets based on their sizes. */
|
2009-06-01 22:58:49 +00:00
|
|
|
void
|
2009-07-19 13:21:40 +00:00
|
|
|
layout_fix_offsets(struct layout_cell *lc)
|
2009-06-01 22:58:49 +00:00
|
|
|
{
|
2009-07-19 13:21:40 +00:00
|
|
|
struct layout_cell *lcchild;
|
|
|
|
u_int xoff, yoff;
|
|
|
|
|
|
|
|
if (lc->type == LAYOUT_LEFTRIGHT) {
|
|
|
|
xoff = lc->xoff;
|
|
|
|
TAILQ_FOREACH(lcchild, &lc->cells, entry) {
|
|
|
|
lcchild->xoff = xoff;
|
|
|
|
lcchild->yoff = lc->yoff;
|
|
|
|
if (lcchild->type != LAYOUT_WINDOWPANE)
|
|
|
|
layout_fix_offsets(lcchild);
|
|
|
|
xoff += lcchild->sx + 1;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
yoff = lc->yoff;
|
|
|
|
TAILQ_FOREACH(lcchild, &lc->cells, entry) {
|
|
|
|
lcchild->xoff = lc->xoff;
|
|
|
|
lcchild->yoff = yoff;
|
|
|
|
if (lcchild->type != LAYOUT_WINDOWPANE)
|
|
|
|
layout_fix_offsets(lcchild);
|
|
|
|
yoff += lcchild->sy + 1;
|
2009-07-14 07:23:36 +00:00
|
|
|
}
|
2009-06-01 22:58:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-29 15:00:48 +00:00
|
|
|
/*
|
|
|
|
* Returns 1 if we need to reserve space for the pane status line. This is the
|
|
|
|
* case for the most upper panes only.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
layout_need_status(struct layout_cell *lc, int at_top)
|
|
|
|
{
|
|
|
|
struct layout_cell *first_lc;
|
|
|
|
|
2018-09-24 15:29:56 +00:00
|
|
|
if (lc->parent != NULL) {
|
2016-04-29 15:00:48 +00:00
|
|
|
if (lc->parent->type == LAYOUT_LEFTRIGHT)
|
|
|
|
return (layout_need_status(lc->parent, at_top));
|
|
|
|
|
|
|
|
if (at_top)
|
|
|
|
first_lc = TAILQ_FIRST(&lc->parent->cells);
|
|
|
|
else
|
|
|
|
first_lc = TAILQ_LAST(&lc->parent->cells,layout_cells);
|
|
|
|
if (lc == first_lc)
|
|
|
|
return (layout_need_status(lc->parent, at_top));
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
|
2009-07-19 13:21:40 +00:00
|
|
|
/* Update pane offsets and sizes based on their cells. */
|
2009-06-01 22:58:49 +00:00
|
|
|
void
|
Support for windows larger than visible on the attached client. This has
been a limitation for a long time.
There are two new options, window-size and default-size, and a new
command, resize-window. The force-width and force-height options and the
session_width and session_height formats have been removed.
The new window-size option tells tmux how to work out the size of
windows: largest means it picks the size of the largest session,
smallest the smallest session (similar to the old behaviour) and manual
means that it does not automatically resize windows. The default is
currently largest but this may change. aggressive-resize modifies the
choice of session for largest and smallest as it did before.
If a window is in a session attached to a client that is too small, only
part of the window is shown. tmux attempts to keep the cursor visible,
so the part of the window displayed is changed as the cursor moves (with
a small delay, to try and avoid excess redrawing when applications
redraw status lines or similar that are not currently visible). The
offset of the visible portion of the window is shown in status-right.
Drawing windows which are larger than the client is not as efficient as
those which fit, particularly when the cursor moves, so it is
recommended to avoid using this on slow machines or networks (set
window-size to smallest or manual).
The resize-window command can be used to resize a window manually. If it
is used, the window-size option is automatically set to manual for the
window (undo this with "setw -u window-size"). resize-window works in a
similar way to resize-pane (-U -D -L -R -x -y flags) but also has -a and
-A flags. -a sets the window to the size of the smallest client (what it
would be if window-size was smallest) and -A the largest.
For the same behaviour as force-width or force-height, use resize-window
-x or -y, and "setw -u window-size" to revert to automatic sizing..
If the global window-size option is set to manual, the default-size
option is used for new windows. If -x or -y is used with new-session,
that sets the default-size option for the new session.
The maximum size of a window is 10000x10000. But expect applications to
complain and much higher memory use if making a window excessively
big. The minimum size is the size required for the current layout
including borders.
The refresh-client command can be used to pan around a window, -U -D -L
-R moves up, down, left or right and -c returns to automatic cursor
tracking. The position is reset when the current window is changed.
2018-10-18 08:38:01 +00:00
|
|
|
layout_fix_panes(struct window *w)
|
2009-06-01 22:58:49 +00:00
|
|
|
{
|
|
|
|
struct window_pane *wp;
|
2009-07-19 13:21:40 +00:00
|
|
|
struct layout_cell *lc;
|
Support for windows larger than visible on the attached client. This has
been a limitation for a long time.
There are two new options, window-size and default-size, and a new
command, resize-window. The force-width and force-height options and the
session_width and session_height formats have been removed.
The new window-size option tells tmux how to work out the size of
windows: largest means it picks the size of the largest session,
smallest the smallest session (similar to the old behaviour) and manual
means that it does not automatically resize windows. The default is
currently largest but this may change. aggressive-resize modifies the
choice of session for largest and smallest as it did before.
If a window is in a session attached to a client that is too small, only
part of the window is shown. tmux attempts to keep the cursor visible,
so the part of the window displayed is changed as the cursor moves (with
a small delay, to try and avoid excess redrawing when applications
redraw status lines or similar that are not currently visible). The
offset of the visible portion of the window is shown in status-right.
Drawing windows which are larger than the client is not as efficient as
those which fit, particularly when the cursor moves, so it is
recommended to avoid using this on slow machines or networks (set
window-size to smallest or manual).
The resize-window command can be used to resize a window manually. If it
is used, the window-size option is automatically set to manual for the
window (undo this with "setw -u window-size"). resize-window works in a
similar way to resize-pane (-U -D -L -R -x -y flags) but also has -a and
-A flags. -a sets the window to the size of the smallest client (what it
would be if window-size was smallest) and -A the largest.
For the same behaviour as force-width or force-height, use resize-window
-x or -y, and "setw -u window-size" to revert to automatic sizing..
If the global window-size option is set to manual, the default-size
option is used for new windows. If -x or -y is used with new-session,
that sets the default-size option for the new session.
The maximum size of a window is 10000x10000. But expect applications to
complain and much higher memory use if making a window excessively
big. The minimum size is the size required for the current layout
including borders.
The refresh-client command can be used to pan around a window, -U -D -L
-R moves up, down, left or right and -c returns to automatic cursor
tracking. The position is reset when the current window is changed.
2018-10-18 08:38:01 +00:00
|
|
|
int shift, status;
|
2009-06-01 22:58:49 +00:00
|
|
|
|
2016-04-29 15:00:48 +00:00
|
|
|
status = options_get_number(w->options, "pane-border-status");
|
2009-07-19 13:21:40 +00:00
|
|
|
TAILQ_FOREACH(wp, &w->panes, entry) {
|
|
|
|
if ((lc = wp->layout_cell) == NULL)
|
|
|
|
continue;
|
2016-04-29 15:00:48 +00:00
|
|
|
|
|
|
|
if (status != 0)
|
Support for windows larger than visible on the attached client. This has
been a limitation for a long time.
There are two new options, window-size and default-size, and a new
command, resize-window. The force-width and force-height options and the
session_width and session_height formats have been removed.
The new window-size option tells tmux how to work out the size of
windows: largest means it picks the size of the largest session,
smallest the smallest session (similar to the old behaviour) and manual
means that it does not automatically resize windows. The default is
currently largest but this may change. aggressive-resize modifies the
choice of session for largest and smallest as it did before.
If a window is in a session attached to a client that is too small, only
part of the window is shown. tmux attempts to keep the cursor visible,
so the part of the window displayed is changed as the cursor moves (with
a small delay, to try and avoid excess redrawing when applications
redraw status lines or similar that are not currently visible). The
offset of the visible portion of the window is shown in status-right.
Drawing windows which are larger than the client is not as efficient as
those which fit, particularly when the cursor moves, so it is
recommended to avoid using this on slow machines or networks (set
window-size to smallest or manual).
The resize-window command can be used to resize a window manually. If it
is used, the window-size option is automatically set to manual for the
window (undo this with "setw -u window-size"). resize-window works in a
similar way to resize-pane (-U -D -L -R -x -y flags) but also has -a and
-A flags. -a sets the window to the size of the smallest client (what it
would be if window-size was smallest) and -A the largest.
For the same behaviour as force-width or force-height, use resize-window
-x or -y, and "setw -u window-size" to revert to automatic sizing..
If the global window-size option is set to manual, the default-size
option is used for new windows. If -x or -y is used with new-session,
that sets the default-size option for the new session.
The maximum size of a window is 10000x10000. But expect applications to
complain and much higher memory use if making a window excessively
big. The minimum size is the size required for the current layout
including borders.
The refresh-client command can be used to pan around a window, -U -D -L
-R moves up, down, left or right and -c returns to automatic cursor
tracking. The position is reset when the current window is changed.
2018-10-18 08:38:01 +00:00
|
|
|
shift = layout_need_status(lc, status == 1);
|
2016-04-29 15:00:48 +00:00
|
|
|
else
|
|
|
|
shift = 0;
|
|
|
|
|
2009-07-19 13:21:40 +00:00
|
|
|
wp->xoff = lc->xoff;
|
|
|
|
wp->yoff = lc->yoff;
|
|
|
|
|
Support for windows larger than visible on the attached client. This has
been a limitation for a long time.
There are two new options, window-size and default-size, and a new
command, resize-window. The force-width and force-height options and the
session_width and session_height formats have been removed.
The new window-size option tells tmux how to work out the size of
windows: largest means it picks the size of the largest session,
smallest the smallest session (similar to the old behaviour) and manual
means that it does not automatically resize windows. The default is
currently largest but this may change. aggressive-resize modifies the
choice of session for largest and smallest as it did before.
If a window is in a session attached to a client that is too small, only
part of the window is shown. tmux attempts to keep the cursor visible,
so the part of the window displayed is changed as the cursor moves (with
a small delay, to try and avoid excess redrawing when applications
redraw status lines or similar that are not currently visible). The
offset of the visible portion of the window is shown in status-right.
Drawing windows which are larger than the client is not as efficient as
those which fit, particularly when the cursor moves, so it is
recommended to avoid using this on slow machines or networks (set
window-size to smallest or manual).
The resize-window command can be used to resize a window manually. If it
is used, the window-size option is automatically set to manual for the
window (undo this with "setw -u window-size"). resize-window works in a
similar way to resize-pane (-U -D -L -R -x -y flags) but also has -a and
-A flags. -a sets the window to the size of the smallest client (what it
would be if window-size was smallest) and -A the largest.
For the same behaviour as force-width or force-height, use resize-window
-x or -y, and "setw -u window-size" to revert to automatic sizing..
If the global window-size option is set to manual, the default-size
option is used for new windows. If -x or -y is used with new-session,
that sets the default-size option for the new session.
The maximum size of a window is 10000x10000. But expect applications to
complain and much higher memory use if making a window excessively
big. The minimum size is the size required for the current layout
including borders.
The refresh-client command can be used to pan around a window, -U -D -L
-R moves up, down, left or right and -c returns to automatic cursor
tracking. The position is reset when the current window is changed.
2018-10-18 08:38:01 +00:00
|
|
|
if (shift && status == 1)
|
2016-04-29 15:00:48 +00:00
|
|
|
wp->yoff += 1;
|
|
|
|
|
Support for windows larger than visible on the attached client. This has
been a limitation for a long time.
There are two new options, window-size and default-size, and a new
command, resize-window. The force-width and force-height options and the
session_width and session_height formats have been removed.
The new window-size option tells tmux how to work out the size of
windows: largest means it picks the size of the largest session,
smallest the smallest session (similar to the old behaviour) and manual
means that it does not automatically resize windows. The default is
currently largest but this may change. aggressive-resize modifies the
choice of session for largest and smallest as it did before.
If a window is in a session attached to a client that is too small, only
part of the window is shown. tmux attempts to keep the cursor visible,
so the part of the window displayed is changed as the cursor moves (with
a small delay, to try and avoid excess redrawing when applications
redraw status lines or similar that are not currently visible). The
offset of the visible portion of the window is shown in status-right.
Drawing windows which are larger than the client is not as efficient as
those which fit, particularly when the cursor moves, so it is
recommended to avoid using this on slow machines or networks (set
window-size to smallest or manual).
The resize-window command can be used to resize a window manually. If it
is used, the window-size option is automatically set to manual for the
window (undo this with "setw -u window-size"). resize-window works in a
similar way to resize-pane (-U -D -L -R -x -y flags) but also has -a and
-A flags. -a sets the window to the size of the smallest client (what it
would be if window-size was smallest) and -A the largest.
For the same behaviour as force-width or force-height, use resize-window
-x or -y, and "setw -u window-size" to revert to automatic sizing..
If the global window-size option is set to manual, the default-size
option is used for new windows. If -x or -y is used with new-session,
that sets the default-size option for the new session.
The maximum size of a window is 10000x10000. But expect applications to
complain and much higher memory use if making a window excessively
big. The minimum size is the size required for the current layout
including borders.
The refresh-client command can be used to pan around a window, -U -D -L
-R moves up, down, left or right and -c returns to automatic cursor
tracking. The position is reset when the current window is changed.
2018-10-18 08:38:01 +00:00
|
|
|
window_pane_resize(wp, lc->sx, lc->sy - shift);
|
2009-07-14 07:23:36 +00:00
|
|
|
}
|
2009-07-19 13:21:40 +00:00
|
|
|
}
|
2009-07-14 07:23:36 +00:00
|
|
|
|
2010-06-29 03:30:13 +00:00
|
|
|
/* Count the number of available cells in a layout. */
|
|
|
|
u_int
|
|
|
|
layout_count_cells(struct layout_cell *lc)
|
|
|
|
{
|
|
|
|
struct layout_cell *lcchild;
|
2016-09-04 17:37:06 +00:00
|
|
|
u_int count;
|
2010-06-29 03:30:13 +00:00
|
|
|
|
|
|
|
switch (lc->type) {
|
|
|
|
case LAYOUT_WINDOWPANE:
|
|
|
|
return (1);
|
|
|
|
case LAYOUT_LEFTRIGHT:
|
|
|
|
case LAYOUT_TOPBOTTOM:
|
2016-09-04 17:37:06 +00:00
|
|
|
count = 0;
|
2010-06-29 03:30:13 +00:00
|
|
|
TAILQ_FOREACH(lcchild, &lc->cells, entry)
|
2016-09-04 17:37:06 +00:00
|
|
|
count += layout_count_cells(lcchild);
|
|
|
|
return (count);
|
2010-06-29 03:30:13 +00:00
|
|
|
default:
|
|
|
|
fatalx("bad layout type");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-07-19 13:21:40 +00:00
|
|
|
/* Calculate how much size is available to be removed from a cell. */
|
2016-08-03 09:07:02 +00:00
|
|
|
static u_int
|
|
|
|
layout_resize_check(struct window *w, struct layout_cell *lc,
|
|
|
|
enum layout_type type)
|
2009-07-19 13:21:40 +00:00
|
|
|
{
|
|
|
|
struct layout_cell *lcchild;
|
|
|
|
u_int available, minimum;
|
2018-09-24 15:29:56 +00:00
|
|
|
int status;
|
2009-06-01 22:58:49 +00:00
|
|
|
|
2018-09-24 15:29:56 +00:00
|
|
|
status = options_get_number(w->options, "pane-border-status");
|
2009-07-19 13:21:40 +00:00
|
|
|
if (lc->type == LAYOUT_WINDOWPANE) {
|
|
|
|
/* Space available in this cell only. */
|
2016-08-03 09:07:02 +00:00
|
|
|
minimum = PANE_MINIMUM;
|
2009-07-19 13:21:40 +00:00
|
|
|
if (type == LAYOUT_LEFTRIGHT)
|
|
|
|
available = lc->sx;
|
2016-08-03 09:07:02 +00:00
|
|
|
else {
|
2009-07-19 13:21:40 +00:00
|
|
|
available = lc->sy;
|
2018-09-24 15:29:56 +00:00
|
|
|
if (status != 0)
|
|
|
|
minimum += layout_need_status(lc, status == 1);
|
2016-08-03 09:07:02 +00:00
|
|
|
}
|
|
|
|
if (available > minimum)
|
|
|
|
available -= minimum;
|
2009-07-19 13:21:40 +00:00
|
|
|
else
|
|
|
|
available = 0;
|
|
|
|
} else if (lc->type == type) {
|
|
|
|
/* Same type: total of available space in all child cells. */
|
|
|
|
available = 0;
|
|
|
|
TAILQ_FOREACH(lcchild, &lc->cells, entry)
|
2016-08-03 09:07:02 +00:00
|
|
|
available += layout_resize_check(w, lcchild, type);
|
2009-07-19 13:21:40 +00:00
|
|
|
} else {
|
|
|
|
/* Different type: minimum of available space in child cells. */
|
|
|
|
minimum = UINT_MAX;
|
|
|
|
TAILQ_FOREACH(lcchild, &lc->cells, entry) {
|
2016-08-03 09:07:02 +00:00
|
|
|
available = layout_resize_check(w, lcchild, type);
|
2009-07-19 13:21:40 +00:00
|
|
|
if (available < minimum)
|
|
|
|
minimum = available;
|
|
|
|
}
|
|
|
|
available = minimum;
|
2009-06-01 22:58:49 +00:00
|
|
|
}
|
|
|
|
|
2009-07-19 13:21:40 +00:00
|
|
|
return (available);
|
2009-06-01 22:58:49 +00:00
|
|
|
}
|
|
|
|
|
2009-07-19 13:21:40 +00:00
|
|
|
/*
|
|
|
|
* Adjust cell size evenly, including altering its children. This function
|
|
|
|
* expects the change to have already been bounded to the space available.
|
|
|
|
*/
|
2009-06-01 22:58:49 +00:00
|
|
|
void
|
2016-08-03 09:07:02 +00:00
|
|
|
layout_resize_adjust(struct window *w, struct layout_cell *lc,
|
|
|
|
enum layout_type type, int change)
|
2009-06-01 22:58:49 +00:00
|
|
|
{
|
2009-07-19 13:21:40 +00:00
|
|
|
struct layout_cell *lcchild;
|
2009-06-01 22:58:49 +00:00
|
|
|
|
2009-07-19 13:21:40 +00:00
|
|
|
/* Adjust the cell size. */
|
|
|
|
if (type == LAYOUT_LEFTRIGHT)
|
|
|
|
lc->sx += change;
|
|
|
|
else
|
|
|
|
lc->sy += change;
|
2009-12-03 22:50:09 +00:00
|
|
|
|
2009-07-19 13:21:40 +00:00
|
|
|
/* If this is a leaf cell, that is all that is necessary. */
|
|
|
|
if (type == LAYOUT_WINDOWPANE)
|
2009-06-01 22:58:49 +00:00
|
|
|
return;
|
|
|
|
|
2009-07-19 13:21:40 +00:00
|
|
|
/* Child cell runs in a different direction. */
|
|
|
|
if (lc->type != type) {
|
|
|
|
TAILQ_FOREACH(lcchild, &lc->cells, entry)
|
2016-08-03 09:07:02 +00:00
|
|
|
layout_resize_adjust(w, lcchild, type, change);
|
2009-07-14 07:23:36 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-12-03 22:50:09 +00:00
|
|
|
/*
|
|
|
|
* Child cell runs in the same direction. Adjust each child equally
|
2009-07-19 13:21:40 +00:00
|
|
|
* until no further change is possible.
|
|
|
|
*/
|
|
|
|
while (change != 0) {
|
|
|
|
TAILQ_FOREACH(lcchild, &lc->cells, entry) {
|
|
|
|
if (change == 0)
|
|
|
|
break;
|
|
|
|
if (change > 0) {
|
2016-08-03 09:07:02 +00:00
|
|
|
layout_resize_adjust(w, lcchild, type, 1);
|
2009-07-19 13:21:40 +00:00
|
|
|
change--;
|
|
|
|
continue;
|
|
|
|
}
|
2016-08-03 09:07:02 +00:00
|
|
|
if (layout_resize_check(w, lcchild, type) > 0) {
|
|
|
|
layout_resize_adjust(w, lcchild, type, -1);
|
2009-07-19 13:21:40 +00:00
|
|
|
change++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-06-01 22:58:49 +00:00
|
|
|
|
2010-06-29 03:30:13 +00:00
|
|
|
/* Destroy a cell and redistribute the space. */
|
|
|
|
void
|
2016-08-03 09:07:02 +00:00
|
|
|
layout_destroy_cell(struct window *w, struct layout_cell *lc,
|
|
|
|
struct layout_cell **lcroot)
|
2010-06-29 03:30:13 +00:00
|
|
|
{
|
|
|
|
struct layout_cell *lcother, *lcparent;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If no parent, this is the last pane so window close is imminent and
|
|
|
|
* there is no need to resize anything.
|
|
|
|
*/
|
|
|
|
lcparent = lc->parent;
|
|
|
|
if (lcparent == NULL) {
|
|
|
|
layout_free_cell(lc);
|
|
|
|
*lcroot = NULL;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Merge the space into the previous or next cell. */
|
|
|
|
if (lc == TAILQ_FIRST(&lcparent->cells))
|
|
|
|
lcother = TAILQ_NEXT(lc, entry);
|
|
|
|
else
|
|
|
|
lcother = TAILQ_PREV(lc, layout_cells, entry);
|
2019-04-23 09:15:24 +00:00
|
|
|
if (lcother != NULL && lcparent->type == LAYOUT_LEFTRIGHT)
|
2016-08-03 09:07:02 +00:00
|
|
|
layout_resize_adjust(w, lcother, lcparent->type, lc->sx + 1);
|
2019-04-23 09:15:24 +00:00
|
|
|
else if (lcother != NULL)
|
2016-08-03 09:07:02 +00:00
|
|
|
layout_resize_adjust(w, lcother, lcparent->type, lc->sy + 1);
|
2010-06-29 03:30:13 +00:00
|
|
|
|
|
|
|
/* Remove this from the parent's list. */
|
|
|
|
TAILQ_REMOVE(&lcparent->cells, lc, entry);
|
|
|
|
layout_free_cell(lc);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If the parent now has one cell, remove the parent from the tree and
|
|
|
|
* replace it by that cell.
|
|
|
|
*/
|
|
|
|
lc = TAILQ_FIRST(&lcparent->cells);
|
|
|
|
if (TAILQ_NEXT(lc, entry) == NULL) {
|
|
|
|
TAILQ_REMOVE(&lcparent->cells, lc, entry);
|
|
|
|
|
|
|
|
lc->parent = lcparent->parent;
|
|
|
|
if (lc->parent == NULL) {
|
|
|
|
lc->xoff = 0; lc->yoff = 0;
|
|
|
|
*lcroot = lc;
|
|
|
|
} else
|
|
|
|
TAILQ_REPLACE(&lc->parent->cells, lcparent, lc, entry);
|
|
|
|
|
|
|
|
layout_free_cell(lcparent);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-07-19 13:21:40 +00:00
|
|
|
void
|
2013-03-24 09:57:59 +00:00
|
|
|
layout_init(struct window *w, struct window_pane *wp)
|
2009-07-19 13:21:40 +00:00
|
|
|
{
|
|
|
|
struct layout_cell *lc;
|
2009-06-01 22:58:49 +00:00
|
|
|
|
2009-07-19 13:21:40 +00:00
|
|
|
lc = w->layout_root = layout_create_cell(NULL);
|
|
|
|
layout_set_size(lc, w->sx, w->sy, 0, 0);
|
2013-03-24 09:57:59 +00:00
|
|
|
layout_make_leaf(lc, wp);
|
Support for windows larger than visible on the attached client. This has
been a limitation for a long time.
There are two new options, window-size and default-size, and a new
command, resize-window. The force-width and force-height options and the
session_width and session_height formats have been removed.
The new window-size option tells tmux how to work out the size of
windows: largest means it picks the size of the largest session,
smallest the smallest session (similar to the old behaviour) and manual
means that it does not automatically resize windows. The default is
currently largest but this may change. aggressive-resize modifies the
choice of session for largest and smallest as it did before.
If a window is in a session attached to a client that is too small, only
part of the window is shown. tmux attempts to keep the cursor visible,
so the part of the window displayed is changed as the cursor moves (with
a small delay, to try and avoid excess redrawing when applications
redraw status lines or similar that are not currently visible). The
offset of the visible portion of the window is shown in status-right.
Drawing windows which are larger than the client is not as efficient as
those which fit, particularly when the cursor moves, so it is
recommended to avoid using this on slow machines or networks (set
window-size to smallest or manual).
The resize-window command can be used to resize a window manually. If it
is used, the window-size option is automatically set to manual for the
window (undo this with "setw -u window-size"). resize-window works in a
similar way to resize-pane (-U -D -L -R -x -y flags) but also has -a and
-A flags. -a sets the window to the size of the smallest client (what it
would be if window-size was smallest) and -A the largest.
For the same behaviour as force-width or force-height, use resize-window
-x or -y, and "setw -u window-size" to revert to automatic sizing..
If the global window-size option is set to manual, the default-size
option is used for new windows. If -x or -y is used with new-session,
that sets the default-size option for the new session.
The maximum size of a window is 10000x10000. But expect applications to
complain and much higher memory use if making a window excessively
big. The minimum size is the size required for the current layout
including borders.
The refresh-client command can be used to pan around a window, -U -D -L
-R moves up, down, left or right and -c returns to automatic cursor
tracking. The position is reset when the current window is changed.
2018-10-18 08:38:01 +00:00
|
|
|
layout_fix_panes(w);
|
2009-07-19 13:21:40 +00:00
|
|
|
}
|
2009-06-01 22:58:49 +00:00
|
|
|
|
2009-07-19 13:21:40 +00:00
|
|
|
void
|
|
|
|
layout_free(struct window *w)
|
|
|
|
{
|
|
|
|
layout_free_cell(w->layout_root);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Resize the entire layout after window resize. */
|
|
|
|
void
|
|
|
|
layout_resize(struct window *w, u_int sx, u_int sy)
|
|
|
|
{
|
|
|
|
struct layout_cell *lc = w->layout_root;
|
|
|
|
int xlimit, ylimit, xchange, ychange;
|
|
|
|
|
2009-12-03 22:50:09 +00:00
|
|
|
/*
|
2009-07-19 13:21:40 +00:00
|
|
|
* Adjust horizontally. Do not attempt to reduce the layout lower than
|
|
|
|
* the minimum (more than the amount returned by layout_resize_check).
|
2009-12-03 22:50:09 +00:00
|
|
|
*
|
2009-07-19 13:21:40 +00:00
|
|
|
* This can mean that the window size is smaller than the total layout
|
|
|
|
* size: redrawing this is handled at a higher level, but it does leave
|
|
|
|
* a problem with growing the window size here: if the current size is
|
|
|
|
* < the minimum, growing proportionately by adding to each pane is
|
|
|
|
* wrong as it would keep the layout size larger than the window size.
|
|
|
|
* Instead, spread the difference between the minimum and the new size
|
|
|
|
* out proportionately - this should leave the layout fitting the new
|
|
|
|
* window size.
|
|
|
|
*/
|
2019-04-17 14:43:49 +00:00
|
|
|
xchange = sx - lc->sx;
|
2016-08-03 09:07:02 +00:00
|
|
|
xlimit = layout_resize_check(w, lc, LAYOUT_LEFTRIGHT);
|
2009-07-19 13:21:40 +00:00
|
|
|
if (xchange < 0 && xchange < -xlimit)
|
|
|
|
xchange = -xlimit;
|
|
|
|
if (xlimit == 0) {
|
|
|
|
if (sx <= lc->sx) /* lc->sx is minimum possible */
|
|
|
|
xchange = 0;
|
|
|
|
else
|
|
|
|
xchange = sx - lc->sx;
|
2009-06-01 22:58:49 +00:00
|
|
|
}
|
2009-07-19 13:21:40 +00:00
|
|
|
if (xchange != 0)
|
2016-08-03 09:07:02 +00:00
|
|
|
layout_resize_adjust(w, lc, LAYOUT_LEFTRIGHT, xchange);
|
2009-07-19 13:21:40 +00:00
|
|
|
|
|
|
|
/* Adjust vertically in a similar fashion. */
|
2019-04-17 14:43:49 +00:00
|
|
|
ychange = sy - lc->sy;
|
2016-08-03 09:07:02 +00:00
|
|
|
ylimit = layout_resize_check(w, lc, LAYOUT_TOPBOTTOM);
|
2009-07-19 13:21:40 +00:00
|
|
|
if (ychange < 0 && ychange < -ylimit)
|
|
|
|
ychange = -ylimit;
|
|
|
|
if (ylimit == 0) {
|
|
|
|
if (sy <= lc->sy) /* lc->sy is minimum possible */
|
|
|
|
ychange = 0;
|
|
|
|
else
|
|
|
|
ychange = sy - lc->sy;
|
|
|
|
}
|
|
|
|
if (ychange != 0)
|
2016-08-03 09:07:02 +00:00
|
|
|
layout_resize_adjust(w, lc, LAYOUT_TOPBOTTOM, ychange);
|
2009-12-03 22:50:09 +00:00
|
|
|
|
2009-07-19 13:21:40 +00:00
|
|
|
/* Fix cell offsets. */
|
|
|
|
layout_fix_offsets(lc);
|
Support for windows larger than visible on the attached client. This has
been a limitation for a long time.
There are two new options, window-size and default-size, and a new
command, resize-window. The force-width and force-height options and the
session_width and session_height formats have been removed.
The new window-size option tells tmux how to work out the size of
windows: largest means it picks the size of the largest session,
smallest the smallest session (similar to the old behaviour) and manual
means that it does not automatically resize windows. The default is
currently largest but this may change. aggressive-resize modifies the
choice of session for largest and smallest as it did before.
If a window is in a session attached to a client that is too small, only
part of the window is shown. tmux attempts to keep the cursor visible,
so the part of the window displayed is changed as the cursor moves (with
a small delay, to try and avoid excess redrawing when applications
redraw status lines or similar that are not currently visible). The
offset of the visible portion of the window is shown in status-right.
Drawing windows which are larger than the client is not as efficient as
those which fit, particularly when the cursor moves, so it is
recommended to avoid using this on slow machines or networks (set
window-size to smallest or manual).
The resize-window command can be used to resize a window manually. If it
is used, the window-size option is automatically set to manual for the
window (undo this with "setw -u window-size"). resize-window works in a
similar way to resize-pane (-U -D -L -R -x -y flags) but also has -a and
-A flags. -a sets the window to the size of the smallest client (what it
would be if window-size was smallest) and -A the largest.
For the same behaviour as force-width or force-height, use resize-window
-x or -y, and "setw -u window-size" to revert to automatic sizing..
If the global window-size option is set to manual, the default-size
option is used for new windows. If -x or -y is used with new-session,
that sets the default-size option for the new session.
The maximum size of a window is 10000x10000. But expect applications to
complain and much higher memory use if making a window excessively
big. The minimum size is the size required for the current layout
including borders.
The refresh-client command can be used to pan around a window, -U -D -L
-R moves up, down, left or right and -c returns to automatic cursor
tracking. The position is reset when the current window is changed.
2018-10-18 08:38:01 +00:00
|
|
|
layout_fix_panes(w);
|
2009-06-01 22:58:49 +00:00
|
|
|
}
|
|
|
|
|
2013-03-22 10:37:39 +00:00
|
|
|
/* Resize a pane to an absolute size. */
|
|
|
|
void
|
|
|
|
layout_resize_pane_to(struct window_pane *wp, enum layout_type type,
|
|
|
|
u_int new_size)
|
|
|
|
{
|
|
|
|
struct layout_cell *lc, *lcparent;
|
|
|
|
int change, size;
|
|
|
|
|
|
|
|
lc = wp->layout_cell;
|
|
|
|
|
|
|
|
/* Find next parent of the same type. */
|
|
|
|
lcparent = lc->parent;
|
|
|
|
while (lcparent != NULL && lcparent->type != type) {
|
|
|
|
lc = lcparent;
|
|
|
|
lcparent = lc->parent;
|
|
|
|
}
|
|
|
|
if (lcparent == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* Work out the size adjustment. */
|
|
|
|
if (type == LAYOUT_LEFTRIGHT)
|
|
|
|
size = lc->sx;
|
|
|
|
else
|
|
|
|
size = lc->sy;
|
|
|
|
if (lc == TAILQ_LAST(&lcparent->cells, layout_cells))
|
|
|
|
change = size - new_size;
|
|
|
|
else
|
|
|
|
change = new_size - size;
|
|
|
|
|
|
|
|
/* Resize the pane. */
|
2016-10-10 17:28:30 +00:00
|
|
|
layout_resize_pane(wp, type, change, 1);
|
2013-03-22 10:37:39 +00:00
|
|
|
}
|
|
|
|
|
2018-06-08 20:54:22 +00:00
|
|
|
void
|
|
|
|
layout_resize_layout(struct window *w, struct layout_cell *lc,
|
|
|
|
enum layout_type type, int change, int opposite)
|
|
|
|
{
|
|
|
|
int needed, size;
|
|
|
|
|
|
|
|
/* Grow or shrink the cell. */
|
|
|
|
needed = change;
|
|
|
|
while (needed != 0) {
|
|
|
|
if (change > 0) {
|
|
|
|
size = layout_resize_pane_grow(w, lc, type, needed,
|
|
|
|
opposite);
|
|
|
|
needed -= size;
|
|
|
|
} else {
|
|
|
|
size = layout_resize_pane_shrink(w, lc, type, needed);
|
|
|
|
needed += size;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (size == 0) /* no more change possible */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Fix cell offsets. */
|
|
|
|
layout_fix_offsets(w->layout_root);
|
Support for windows larger than visible on the attached client. This has
been a limitation for a long time.
There are two new options, window-size and default-size, and a new
command, resize-window. The force-width and force-height options and the
session_width and session_height formats have been removed.
The new window-size option tells tmux how to work out the size of
windows: largest means it picks the size of the largest session,
smallest the smallest session (similar to the old behaviour) and manual
means that it does not automatically resize windows. The default is
currently largest but this may change. aggressive-resize modifies the
choice of session for largest and smallest as it did before.
If a window is in a session attached to a client that is too small, only
part of the window is shown. tmux attempts to keep the cursor visible,
so the part of the window displayed is changed as the cursor moves (with
a small delay, to try and avoid excess redrawing when applications
redraw status lines or similar that are not currently visible). The
offset of the visible portion of the window is shown in status-right.
Drawing windows which are larger than the client is not as efficient as
those which fit, particularly when the cursor moves, so it is
recommended to avoid using this on slow machines or networks (set
window-size to smallest or manual).
The resize-window command can be used to resize a window manually. If it
is used, the window-size option is automatically set to manual for the
window (undo this with "setw -u window-size"). resize-window works in a
similar way to resize-pane (-U -D -L -R -x -y flags) but also has -a and
-A flags. -a sets the window to the size of the smallest client (what it
would be if window-size was smallest) and -A the largest.
For the same behaviour as force-width or force-height, use resize-window
-x or -y, and "setw -u window-size" to revert to automatic sizing..
If the global window-size option is set to manual, the default-size
option is used for new windows. If -x or -y is used with new-session,
that sets the default-size option for the new session.
The maximum size of a window is 10000x10000. But expect applications to
complain and much higher memory use if making a window excessively
big. The minimum size is the size required for the current layout
including borders.
The refresh-client command can be used to pan around a window, -U -D -L
-R moves up, down, left or right and -c returns to automatic cursor
tracking. The position is reset when the current window is changed.
2018-10-18 08:38:01 +00:00
|
|
|
layout_fix_panes(w);
|
2018-06-08 20:54:22 +00:00
|
|
|
notify_window("window-layout-changed", w);
|
|
|
|
}
|
|
|
|
|
2009-07-19 13:21:40 +00:00
|
|
|
/* Resize a single pane within the layout. */
|
2009-06-01 22:58:49 +00:00
|
|
|
void
|
2016-10-10 17:28:30 +00:00
|
|
|
layout_resize_pane(struct window_pane *wp, enum layout_type type, int change,
|
|
|
|
int opposite)
|
2009-06-01 22:58:49 +00:00
|
|
|
{
|
2016-08-03 09:07:02 +00:00
|
|
|
struct layout_cell *lc, *lcparent;
|
2009-06-01 22:58:49 +00:00
|
|
|
|
2009-07-19 13:21:40 +00:00
|
|
|
lc = wp->layout_cell;
|
2009-06-01 22:58:49 +00:00
|
|
|
|
2009-07-19 13:21:40 +00:00
|
|
|
/* Find next parent of the same type. */
|
|
|
|
lcparent = lc->parent;
|
|
|
|
while (lcparent != NULL && lcparent->type != type) {
|
|
|
|
lc = lcparent;
|
|
|
|
lcparent = lc->parent;
|
|
|
|
}
|
|
|
|
if (lcparent == NULL)
|
2009-06-01 22:58:49 +00:00
|
|
|
return;
|
|
|
|
|
2009-07-19 13:21:40 +00:00
|
|
|
/* If this is the last cell, move back one. */
|
|
|
|
if (lc == TAILQ_LAST(&lcparent->cells, layout_cells))
|
|
|
|
lc = TAILQ_PREV(lc, layout_cells, entry);
|
|
|
|
|
2018-06-08 20:54:22 +00:00
|
|
|
layout_resize_layout(wp->window, lc, type, change, opposite);
|
2009-07-19 13:21:40 +00:00
|
|
|
}
|
2009-06-01 22:58:49 +00:00
|
|
|
|
2013-03-22 10:37:39 +00:00
|
|
|
/* Helper function to grow pane. */
|
2016-04-29 15:00:48 +00:00
|
|
|
static int
|
2016-08-03 09:07:02 +00:00
|
|
|
layout_resize_pane_grow(struct window *w, struct layout_cell *lc,
|
2016-10-10 17:28:30 +00:00
|
|
|
enum layout_type type, int needed, int opposite)
|
2009-07-19 13:21:40 +00:00
|
|
|
{
|
|
|
|
struct layout_cell *lcadd, *lcremove;
|
2016-10-10 17:28:30 +00:00
|
|
|
u_int size = 0;
|
2009-07-19 13:21:40 +00:00
|
|
|
|
|
|
|
/* Growing. Always add to the current cell. */
|
|
|
|
lcadd = lc;
|
2009-12-03 22:50:09 +00:00
|
|
|
|
2009-07-19 13:21:40 +00:00
|
|
|
/* Look towards the tail for a suitable cell for reduction. */
|
|
|
|
lcremove = TAILQ_NEXT(lc, entry);
|
|
|
|
while (lcremove != NULL) {
|
2016-08-03 09:07:02 +00:00
|
|
|
size = layout_resize_check(w, lcremove, type);
|
2009-07-19 13:21:40 +00:00
|
|
|
if (size > 0)
|
|
|
|
break;
|
2009-12-03 22:50:09 +00:00
|
|
|
lcremove = TAILQ_NEXT(lcremove, entry);
|
2009-07-19 13:21:40 +00:00
|
|
|
}
|
2009-06-01 22:58:49 +00:00
|
|
|
|
2009-07-19 13:21:40 +00:00
|
|
|
/* If none found, look towards the head. */
|
2016-10-10 17:28:30 +00:00
|
|
|
if (opposite && lcremove == NULL) {
|
2009-07-19 13:21:40 +00:00
|
|
|
lcremove = TAILQ_PREV(lc, layout_cells, entry);
|
|
|
|
while (lcremove != NULL) {
|
2016-08-03 09:07:02 +00:00
|
|
|
size = layout_resize_check(w, lcremove, type);
|
2009-07-19 13:21:40 +00:00
|
|
|
if (size > 0)
|
|
|
|
break;
|
|
|
|
lcremove = TAILQ_PREV(lcremove, layout_cells, entry);
|
2009-06-01 22:58:49 +00:00
|
|
|
}
|
|
|
|
}
|
2016-10-10 17:28:30 +00:00
|
|
|
if (lcremove == NULL)
|
|
|
|
return (0);
|
2009-06-01 22:58:49 +00:00
|
|
|
|
2009-07-19 13:21:40 +00:00
|
|
|
/* Change the cells. */
|
|
|
|
if (size > (u_int) needed)
|
|
|
|
size = needed;
|
2016-08-03 09:07:02 +00:00
|
|
|
layout_resize_adjust(w, lcadd, type, size);
|
|
|
|
layout_resize_adjust(w, lcremove, type, -size);
|
2009-07-19 13:21:40 +00:00
|
|
|
return (size);
|
2009-06-01 22:58:49 +00:00
|
|
|
}
|
|
|
|
|
2013-03-22 10:37:39 +00:00
|
|
|
/* Helper function to shrink pane. */
|
2016-04-29 15:00:48 +00:00
|
|
|
static int
|
2016-08-03 09:07:02 +00:00
|
|
|
layout_resize_pane_shrink(struct window *w, struct layout_cell *lc,
|
|
|
|
enum layout_type type, int needed)
|
2009-06-01 22:58:49 +00:00
|
|
|
{
|
2009-07-19 13:21:40 +00:00
|
|
|
struct layout_cell *lcadd, *lcremove;
|
|
|
|
u_int size;
|
|
|
|
|
|
|
|
/* Shrinking. Find cell to remove from by walking towards head. */
|
|
|
|
lcremove = lc;
|
|
|
|
do {
|
2016-08-03 09:07:02 +00:00
|
|
|
size = layout_resize_check(w, lcremove, type);
|
2009-07-19 13:21:40 +00:00
|
|
|
if (size != 0)
|
|
|
|
break;
|
|
|
|
lcremove = TAILQ_PREV(lcremove, layout_cells, entry);
|
|
|
|
} while (lcremove != NULL);
|
|
|
|
if (lcremove == NULL)
|
|
|
|
return (0);
|
|
|
|
|
|
|
|
/* And add onto the next cell (from the original cell). */
|
|
|
|
lcadd = TAILQ_NEXT(lc, entry);
|
|
|
|
if (lcadd == NULL)
|
|
|
|
return (0);
|
|
|
|
|
|
|
|
/* Change the cells. */
|
|
|
|
if (size > (u_int) -needed)
|
|
|
|
size = -needed;
|
2016-08-03 09:07:02 +00:00
|
|
|
layout_resize_adjust(w, lcadd, type, size);
|
|
|
|
layout_resize_adjust(w, lcremove, type, -size);
|
2009-07-19 13:21:40 +00:00
|
|
|
return (size);
|
|
|
|
}
|
2009-06-01 22:58:49 +00:00
|
|
|
|
2010-01-07 20:52:18 +00:00
|
|
|
/* Assign window pane to newly split cell. */
|
|
|
|
void
|
|
|
|
layout_assign_pane(struct layout_cell *lc, struct window_pane *wp)
|
|
|
|
{
|
|
|
|
layout_make_leaf(lc, wp);
|
Support for windows larger than visible on the attached client. This has
been a limitation for a long time.
There are two new options, window-size and default-size, and a new
command, resize-window. The force-width and force-height options and the
session_width and session_height formats have been removed.
The new window-size option tells tmux how to work out the size of
windows: largest means it picks the size of the largest session,
smallest the smallest session (similar to the old behaviour) and manual
means that it does not automatically resize windows. The default is
currently largest but this may change. aggressive-resize modifies the
choice of session for largest and smallest as it did before.
If a window is in a session attached to a client that is too small, only
part of the window is shown. tmux attempts to keep the cursor visible,
so the part of the window displayed is changed as the cursor moves (with
a small delay, to try and avoid excess redrawing when applications
redraw status lines or similar that are not currently visible). The
offset of the visible portion of the window is shown in status-right.
Drawing windows which are larger than the client is not as efficient as
those which fit, particularly when the cursor moves, so it is
recommended to avoid using this on slow machines or networks (set
window-size to smallest or manual).
The resize-window command can be used to resize a window manually. If it
is used, the window-size option is automatically set to manual for the
window (undo this with "setw -u window-size"). resize-window works in a
similar way to resize-pane (-U -D -L -R -x -y flags) but also has -a and
-A flags. -a sets the window to the size of the smallest client (what it
would be if window-size was smallest) and -A the largest.
For the same behaviour as force-width or force-height, use resize-window
-x or -y, and "setw -u window-size" to revert to automatic sizing..
If the global window-size option is set to manual, the default-size
option is used for new windows. If -x or -y is used with new-session,
that sets the default-size option for the new session.
The maximum size of a window is 10000x10000. But expect applications to
complain and much higher memory use if making a window excessively
big. The minimum size is the size required for the current layout
including borders.
The refresh-client command can be used to pan around a window, -U -D -L
-R moves up, down, left or right and -c returns to automatic cursor
tracking. The position is reset when the current window is changed.
2018-10-18 08:38:01 +00:00
|
|
|
layout_fix_panes(wp->window);
|
2010-01-07 20:52:18 +00:00
|
|
|
}
|
|
|
|
|
2016-09-04 17:37:06 +00:00
|
|
|
/* Calculate the new pane size for resized parent. */
|
|
|
|
static u_int
|
|
|
|
layout_new_pane_size(struct window *w, u_int previous, struct layout_cell *lc,
|
|
|
|
enum layout_type type, u_int size, u_int count_left, u_int size_left)
|
|
|
|
{
|
|
|
|
u_int new_size, min, max, available;
|
|
|
|
|
|
|
|
/* If this is the last cell, it can take all of the remaining size. */
|
|
|
|
if (count_left == 1)
|
|
|
|
return (size_left);
|
|
|
|
|
|
|
|
/* How much is available in this parent? */
|
|
|
|
available = layout_resize_check(w, lc, type);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Work out the minimum size of this cell and the new size
|
|
|
|
* proportionate to the previous size.
|
|
|
|
*/
|
|
|
|
min = (PANE_MINIMUM + 1) * (count_left - 1);
|
|
|
|
if (type == LAYOUT_LEFTRIGHT) {
|
|
|
|
if (lc->sx - available > min)
|
|
|
|
min = lc->sx - available;
|
|
|
|
new_size = (lc->sx * size) / previous;
|
|
|
|
} else {
|
|
|
|
if (lc->sy - available > min)
|
|
|
|
min = lc->sy - available;
|
|
|
|
new_size = (lc->sy * size) / previous;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check against the maximum and minimum size. */
|
|
|
|
max = size_left - min;
|
|
|
|
if (new_size > max)
|
|
|
|
new_size = max;
|
|
|
|
if (new_size < PANE_MINIMUM)
|
|
|
|
new_size = PANE_MINIMUM;
|
|
|
|
return (new_size);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check if the cell and all its children can be resized to a specific size. */
|
|
|
|
static int
|
|
|
|
layout_set_size_check(struct window *w, struct layout_cell *lc,
|
|
|
|
enum layout_type type, int size)
|
|
|
|
{
|
|
|
|
struct layout_cell *lcchild;
|
2019-04-04 10:25:35 +00:00
|
|
|
u_int new_size, available, previous, count, idx;
|
2016-09-04 17:37:06 +00:00
|
|
|
|
|
|
|
/* Cells with no children must just be bigger than minimum. */
|
|
|
|
if (lc->type == LAYOUT_WINDOWPANE)
|
|
|
|
return (size >= PANE_MINIMUM);
|
|
|
|
available = size;
|
|
|
|
|
|
|
|
/* Count number of children. */
|
|
|
|
count = 0;
|
|
|
|
TAILQ_FOREACH(lcchild, &lc->cells, entry)
|
|
|
|
count++;
|
|
|
|
|
|
|
|
/* Check new size will work for each child. */
|
|
|
|
if (lc->type == type) {
|
2019-04-04 10:25:35 +00:00
|
|
|
if (available < (count * 2) - 1)
|
|
|
|
return (0);
|
|
|
|
|
2016-09-04 17:37:06 +00:00
|
|
|
if (type == LAYOUT_LEFTRIGHT)
|
|
|
|
previous = lc->sx;
|
|
|
|
else
|
|
|
|
previous = lc->sy;
|
|
|
|
|
|
|
|
idx = 0;
|
|
|
|
TAILQ_FOREACH(lcchild, &lc->cells, entry) {
|
|
|
|
new_size = layout_new_pane_size(w, previous, lcchild,
|
|
|
|
type, size, count - idx, available);
|
2019-04-04 10:25:35 +00:00
|
|
|
if (idx == count - 1) {
|
|
|
|
if (new_size > available)
|
|
|
|
return (0);
|
|
|
|
available -= new_size;
|
|
|
|
} else {
|
|
|
|
if (new_size + 1 > available)
|
|
|
|
return (0);
|
|
|
|
available -= new_size + 1;
|
|
|
|
}
|
2016-09-04 17:37:06 +00:00
|
|
|
if (!layout_set_size_check(w, lcchild, type, new_size))
|
|
|
|
return (0);
|
|
|
|
idx++;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
TAILQ_FOREACH(lcchild, &lc->cells, entry) {
|
|
|
|
if (lcchild->type == LAYOUT_WINDOWPANE)
|
|
|
|
continue;
|
|
|
|
if (!layout_set_size_check(w, lcchild, type, size))
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Resize all child cells to fit within the current cell. */
|
|
|
|
static void
|
|
|
|
layout_resize_child_cells(struct window *w, struct layout_cell *lc)
|
|
|
|
{
|
|
|
|
struct layout_cell *lcchild;
|
|
|
|
u_int previous, available, count, idx;
|
|
|
|
|
|
|
|
if (lc->type == LAYOUT_WINDOWPANE)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* What is the current size used? */
|
|
|
|
count = 0;
|
|
|
|
previous = 0;
|
|
|
|
TAILQ_FOREACH(lcchild, &lc->cells, entry) {
|
|
|
|
count++;
|
|
|
|
if (lc->type == LAYOUT_LEFTRIGHT)
|
|
|
|
previous += lcchild->sx;
|
|
|
|
else if (lc->type == LAYOUT_TOPBOTTOM)
|
|
|
|
previous += lcchild->sy;
|
|
|
|
}
|
|
|
|
previous += (count - 1);
|
|
|
|
|
|
|
|
/* And how much is available? */
|
|
|
|
available = 0;
|
|
|
|
if (lc->type == LAYOUT_LEFTRIGHT)
|
|
|
|
available = lc->sx;
|
|
|
|
else if (lc->type == LAYOUT_TOPBOTTOM)
|
|
|
|
available = lc->sy;
|
|
|
|
|
|
|
|
/* Resize children into the new size. */
|
|
|
|
idx = 0;
|
|
|
|
TAILQ_FOREACH(lcchild, &lc->cells, entry) {
|
|
|
|
if (lc->type == LAYOUT_TOPBOTTOM) {
|
|
|
|
lcchild->sx = lc->sx;
|
|
|
|
lcchild->xoff = lc->xoff;
|
|
|
|
} else {
|
|
|
|
lcchild->sx = layout_new_pane_size(w, previous, lcchild,
|
|
|
|
lc->type, lc->sx, count - idx, available);
|
|
|
|
available -= (lcchild->sx + 1);
|
|
|
|
}
|
|
|
|
if (lc->type == LAYOUT_LEFTRIGHT)
|
|
|
|
lcchild->sy = lc->sy;
|
|
|
|
else {
|
|
|
|
lcchild->sy = layout_new_pane_size(w, previous, lcchild,
|
|
|
|
lc->type, lc->sy, count - idx, available);
|
|
|
|
available -= (lcchild->sy + 1);
|
|
|
|
}
|
|
|
|
layout_resize_child_cells(w, lcchild);
|
|
|
|
idx++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-01-07 20:52:18 +00:00
|
|
|
/*
|
|
|
|
* 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!
|
2016-09-04 17:37:06 +00:00
|
|
|
*/
|
2010-01-07 20:52:18 +00:00
|
|
|
struct layout_cell *
|
2015-12-11 16:37:21 +00:00
|
|
|
layout_split_pane(struct window_pane *wp, enum layout_type type, int size,
|
2019-04-17 14:37:48 +00:00
|
|
|
int flags)
|
2009-07-19 13:21:40 +00:00
|
|
|
{
|
2012-03-03 08:31:18 +00:00
|
|
|
struct layout_cell *lc, *lcparent, *lcnew, *lc1, *lc2;
|
2019-04-17 14:44:33 +00:00
|
|
|
u_int sx, sy, xoff, yoff, size1, size2, minimum;
|
2016-09-04 17:37:06 +00:00
|
|
|
u_int new_size, saved_size, resize_first = 0;
|
2019-04-17 14:44:33 +00:00
|
|
|
int full_size = (flags & SPAWN_FULLSIZE), status;
|
2009-07-19 13:21:40 +00:00
|
|
|
|
2016-09-04 17:37:06 +00:00
|
|
|
/*
|
|
|
|
* If full_size is specified, add a new cell at the top of the window
|
|
|
|
* layout. Otherwise, split the cell for the current pane.
|
|
|
|
*/
|
|
|
|
if (full_size)
|
|
|
|
lc = wp->window->layout_root;
|
|
|
|
else
|
|
|
|
lc = wp->layout_cell;
|
2019-04-17 14:44:33 +00:00
|
|
|
status = options_get_number(wp->window->options, "pane-border-status");
|
2009-07-19 13:21:40 +00:00
|
|
|
|
|
|
|
/* Copy the old cell size. */
|
|
|
|
sx = lc->sx;
|
|
|
|
sy = lc->sy;
|
|
|
|
xoff = lc->xoff;
|
|
|
|
yoff = lc->yoff;
|
|
|
|
|
|
|
|
/* Check there is enough space for the two new panes. */
|
|
|
|
switch (type) {
|
|
|
|
case LAYOUT_LEFTRIGHT:
|
|
|
|
if (sx < PANE_MINIMUM * 2 + 1)
|
2010-01-07 20:52:18 +00:00
|
|
|
return (NULL);
|
2009-07-19 13:21:40 +00:00
|
|
|
break;
|
|
|
|
case LAYOUT_TOPBOTTOM:
|
2019-04-17 14:44:33 +00:00
|
|
|
minimum = PANE_MINIMUM * 2 + 1;
|
|
|
|
if (status != 0)
|
|
|
|
minimum += layout_need_status(lc, status == 1);
|
|
|
|
if (sy < minimum)
|
2010-01-07 20:52:18 +00:00
|
|
|
return (NULL);
|
2009-07-19 13:21:40 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
fatalx("bad layout type");
|
|
|
|
}
|
2009-12-03 22:50:09 +00:00
|
|
|
|
2016-09-04 17:37:06 +00:00
|
|
|
/*
|
|
|
|
* 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;
|
2019-04-17 14:37:48 +00:00
|
|
|
else if (flags & SPAWN_BEFORE)
|
2016-09-04 17:37:06 +00:00
|
|
|
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;
|
|
|
|
|
|
|
|
/* Which size are we using? */
|
2019-04-17 14:37:48 +00:00
|
|
|
if (flags & SPAWN_BEFORE)
|
2016-09-04 17:37:06 +00:00
|
|
|
new_size = size2;
|
|
|
|
else
|
|
|
|
new_size = size1;
|
|
|
|
|
|
|
|
/* Confirm there is enough space for full size pane. */
|
|
|
|
if (full_size && !layout_set_size_check(wp->window, lc, type, new_size))
|
|
|
|
return (NULL);
|
|
|
|
|
2009-07-19 13:21:40 +00:00
|
|
|
if (lc->parent != NULL && lc->parent->type == type) {
|
|
|
|
/*
|
|
|
|
* If the parent exists and is of the same type as the split,
|
|
|
|
* create a new cell and insert it after this one.
|
|
|
|
*/
|
2012-03-03 08:31:18 +00:00
|
|
|
lcparent = lc->parent;
|
|
|
|
lcnew = layout_create_cell(lcparent);
|
2019-04-17 14:37:48 +00:00
|
|
|
if (flags & SPAWN_BEFORE)
|
2012-03-03 08:31:18 +00:00
|
|
|
TAILQ_INSERT_BEFORE(lc, lcnew, entry);
|
|
|
|
else
|
|
|
|
TAILQ_INSERT_AFTER(&lcparent->cells, lc, lcnew, entry);
|
2016-09-04 17:37:06 +00:00
|
|
|
} else if (full_size && lc->parent == NULL && lc->type == type) {
|
|
|
|
/*
|
|
|
|
* If the new full size pane is the same type as the root
|
|
|
|
* split, insert the new pane under the existing root cell
|
|
|
|
* instead of creating a new root cell. The existing layout
|
|
|
|
* must be resized before inserting the new cell.
|
|
|
|
*/
|
|
|
|
if (lc->type == LAYOUT_LEFTRIGHT) {
|
|
|
|
lc->sx = new_size;
|
|
|
|
layout_resize_child_cells(wp->window, lc);
|
|
|
|
lc->sx = saved_size;
|
|
|
|
} else if (lc->type == LAYOUT_TOPBOTTOM) {
|
|
|
|
lc->sy = new_size;
|
|
|
|
layout_resize_child_cells(wp->window, lc);
|
|
|
|
lc->sy = saved_size;
|
|
|
|
}
|
|
|
|
resize_first = 1;
|
|
|
|
|
|
|
|
/* Create the new cell. */
|
|
|
|
lcnew = layout_create_cell(lc);
|
2017-03-11 15:16:35 +00:00
|
|
|
size = saved_size - 1 - new_size;
|
2016-09-04 17:37:06 +00:00
|
|
|
if (lc->type == LAYOUT_LEFTRIGHT)
|
2017-03-11 15:16:35 +00:00
|
|
|
layout_set_size(lcnew, size, sy, 0, 0);
|
2016-09-04 17:37:06 +00:00
|
|
|
else if (lc->type == LAYOUT_TOPBOTTOM)
|
2017-03-11 15:16:35 +00:00
|
|
|
layout_set_size(lcnew, sx, size, 0, 0);
|
2019-04-17 14:37:48 +00:00
|
|
|
if (flags & SPAWN_BEFORE)
|
2016-09-04 17:37:06 +00:00
|
|
|
TAILQ_INSERT_HEAD(&lc->cells, lcnew, entry);
|
|
|
|
else
|
|
|
|
TAILQ_INSERT_TAIL(&lc->cells, lcnew, entry);
|
2009-07-19 13:21:40 +00:00
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* Otherwise create a new parent and insert it.
|
|
|
|
*/
|
2009-12-03 22:50:09 +00:00
|
|
|
|
2009-07-19 13:21:40 +00:00
|
|
|
/* Create and insert the replacement parent. */
|
|
|
|
lcparent = layout_create_cell(lc->parent);
|
|
|
|
layout_make_node(lcparent, type);
|
|
|
|
layout_set_size(lcparent, sx, sy, xoff, yoff);
|
|
|
|
if (lc->parent == NULL)
|
|
|
|
wp->window->layout_root = lcparent;
|
|
|
|
else
|
|
|
|
TAILQ_REPLACE(&lc->parent->cells, lc, lcparent, entry);
|
2009-12-03 22:50:09 +00:00
|
|
|
|
2009-07-19 13:21:40 +00:00
|
|
|
/* Insert the old cell. */
|
|
|
|
lc->parent = lcparent;
|
|
|
|
TAILQ_INSERT_HEAD(&lcparent->cells, lc, entry);
|
2009-12-03 22:50:09 +00:00
|
|
|
|
2009-07-19 13:21:40 +00:00
|
|
|
/* Create the new child cell. */
|
|
|
|
lcnew = layout_create_cell(lcparent);
|
2019-04-17 14:37:48 +00:00
|
|
|
if (flags & SPAWN_BEFORE)
|
2012-03-03 08:31:18 +00:00
|
|
|
TAILQ_INSERT_HEAD(&lcparent->cells, lcnew, entry);
|
|
|
|
else
|
|
|
|
TAILQ_INSERT_TAIL(&lcparent->cells, lcnew, entry);
|
|
|
|
}
|
2019-04-17 14:37:48 +00:00
|
|
|
if (flags & SPAWN_BEFORE) {
|
2012-03-03 08:31:18 +00:00
|
|
|
lc1 = lcnew;
|
|
|
|
lc2 = lc;
|
|
|
|
} else {
|
|
|
|
lc1 = lc;
|
|
|
|
lc2 = lcnew;
|
2009-07-19 13:21:40 +00:00
|
|
|
}
|
2009-06-01 22:58:49 +00:00
|
|
|
|
2016-09-04 17:37:06 +00:00
|
|
|
/*
|
|
|
|
* Set new cell sizes. size1 is the size of the top/left and size2 the
|
|
|
|
* bottom/right.
|
2009-07-19 13:21:40 +00:00
|
|
|
*/
|
2016-09-04 17:37:06 +00:00
|
|
|
if (!resize_first && type == LAYOUT_LEFTRIGHT) {
|
2012-03-03 08:31:18 +00:00
|
|
|
layout_set_size(lc1, size1, sy, xoff, yoff);
|
|
|
|
layout_set_size(lc2, size2, sy, xoff + lc1->sx + 1, yoff);
|
2016-09-04 17:37:06 +00:00
|
|
|
} else if (!resize_first && type == LAYOUT_TOPBOTTOM) {
|
2012-03-03 08:31:18 +00:00
|
|
|
layout_set_size(lc1, sx, size1, xoff, yoff);
|
|
|
|
layout_set_size(lc2, sx, size2, xoff, yoff + lc1->sy + 1);
|
2009-06-01 22:58:49 +00:00
|
|
|
}
|
2016-09-04 17:37:06 +00:00
|
|
|
if (full_size) {
|
|
|
|
if (!resize_first)
|
|
|
|
layout_resize_child_cells(wp->window, lc);
|
|
|
|
layout_fix_offsets(wp->window->layout_root);
|
|
|
|
} else
|
|
|
|
layout_make_leaf(lc, wp);
|
2009-06-01 22:58:49 +00:00
|
|
|
|
2010-01-07 20:52:18 +00:00
|
|
|
return (lcnew);
|
2009-07-19 13:21:40 +00:00
|
|
|
}
|
2009-06-01 22:58:49 +00:00
|
|
|
|
2010-06-29 03:30:13 +00:00
|
|
|
/* Destroy the cell associated with a pane. */
|
2009-07-19 13:21:40 +00:00
|
|
|
void
|
|
|
|
layout_close_pane(struct window_pane *wp)
|
|
|
|
{
|
2016-08-03 09:07:02 +00:00
|
|
|
struct window *w = wp->window;
|
|
|
|
|
2010-06-29 03:30:13 +00:00
|
|
|
/* Remove the cell. */
|
2016-08-03 09:07:02 +00:00
|
|
|
layout_destroy_cell(w, wp->layout_cell, &w->layout_root);
|
2009-07-19 13:21:40 +00:00
|
|
|
|
|
|
|
/* Fix pane offsets and sizes. */
|
2016-08-03 09:07:02 +00:00
|
|
|
if (w->layout_root != NULL) {
|
|
|
|
layout_fix_offsets(w->layout_root);
|
Support for windows larger than visible on the attached client. This has
been a limitation for a long time.
There are two new options, window-size and default-size, and a new
command, resize-window. The force-width and force-height options and the
session_width and session_height formats have been removed.
The new window-size option tells tmux how to work out the size of
windows: largest means it picks the size of the largest session,
smallest the smallest session (similar to the old behaviour) and manual
means that it does not automatically resize windows. The default is
currently largest but this may change. aggressive-resize modifies the
choice of session for largest and smallest as it did before.
If a window is in a session attached to a client that is too small, only
part of the window is shown. tmux attempts to keep the cursor visible,
so the part of the window displayed is changed as the cursor moves (with
a small delay, to try and avoid excess redrawing when applications
redraw status lines or similar that are not currently visible). The
offset of the visible portion of the window is shown in status-right.
Drawing windows which are larger than the client is not as efficient as
those which fit, particularly when the cursor moves, so it is
recommended to avoid using this on slow machines or networks (set
window-size to smallest or manual).
The resize-window command can be used to resize a window manually. If it
is used, the window-size option is automatically set to manual for the
window (undo this with "setw -u window-size"). resize-window works in a
similar way to resize-pane (-U -D -L -R -x -y flags) but also has -a and
-A flags. -a sets the window to the size of the smallest client (what it
would be if window-size was smallest) and -A the largest.
For the same behaviour as force-width or force-height, use resize-window
-x or -y, and "setw -u window-size" to revert to automatic sizing..
If the global window-size option is set to manual, the default-size
option is used for new windows. If -x or -y is used with new-session,
that sets the default-size option for the new session.
The maximum size of a window is 10000x10000. But expect applications to
complain and much higher memory use if making a window excessively
big. The minimum size is the size required for the current layout
including borders.
The refresh-client command can be used to pan around a window, -U -D -L
-R moves up, down, left or right and -c returns to automatic cursor
tracking. The position is reset when the current window is changed.
2018-10-18 08:38:01 +00:00
|
|
|
layout_fix_panes(w);
|
2010-06-29 03:30:13 +00:00
|
|
|
}
|
2016-10-16 22:06:40 +00:00
|
|
|
notify_window("window-layout-changed", w);
|
2009-06-01 22:58:49 +00:00
|
|
|
}
|
2017-11-15 19:59:27 +00:00
|
|
|
|
|
|
|
int
|
|
|
|
layout_spread_cell(struct window *w, struct layout_cell *parent)
|
|
|
|
{
|
|
|
|
struct layout_cell *lc;
|
2019-04-17 14:44:33 +00:00
|
|
|
u_int number, each, size, this;
|
|
|
|
int change, changed, status;
|
2017-11-15 19:59:27 +00:00
|
|
|
|
|
|
|
number = 0;
|
|
|
|
TAILQ_FOREACH (lc, &parent->cells, entry)
|
|
|
|
number++;
|
|
|
|
if (number <= 1)
|
|
|
|
return (0);
|
2019-04-17 14:44:33 +00:00
|
|
|
status = options_get_number(w->options, "pane-border-status");
|
2017-11-15 19:59:27 +00:00
|
|
|
|
|
|
|
if (parent->type == LAYOUT_LEFTRIGHT)
|
|
|
|
size = parent->sx;
|
2019-04-17 14:44:33 +00:00
|
|
|
else if (parent->type == LAYOUT_TOPBOTTOM) {
|
2017-11-15 19:59:27 +00:00
|
|
|
size = parent->sy;
|
2019-04-17 14:44:33 +00:00
|
|
|
if (status != 0)
|
|
|
|
size -= layout_need_status(parent, status == 1);
|
|
|
|
} else
|
|
|
|
return (0);
|
|
|
|
if (size < number - 1)
|
2017-11-15 19:59:27 +00:00
|
|
|
return (0);
|
|
|
|
each = (size - (number - 1)) / number;
|
2019-04-17 14:44:33 +00:00
|
|
|
if (each == 0)
|
|
|
|
return (0);
|
2017-11-15 19:59:27 +00:00
|
|
|
|
|
|
|
changed = 0;
|
|
|
|
TAILQ_FOREACH (lc, &parent->cells, entry) {
|
|
|
|
if (TAILQ_NEXT(lc, entry) == NULL)
|
2018-03-23 07:44:44 +00:00
|
|
|
each = size - ((each + 1) * (number - 1));
|
2017-11-15 19:59:27 +00:00
|
|
|
change = 0;
|
|
|
|
if (parent->type == LAYOUT_LEFTRIGHT) {
|
|
|
|
change = each - (int)lc->sx;
|
|
|
|
layout_resize_adjust(w, lc, LAYOUT_LEFTRIGHT, change);
|
|
|
|
} else if (parent->type == LAYOUT_TOPBOTTOM) {
|
2019-04-17 14:44:33 +00:00
|
|
|
this = each;
|
|
|
|
if (status != 0)
|
|
|
|
this += layout_need_status(lc, status == 1);
|
|
|
|
change = this - (int)lc->sy;
|
2017-11-15 19:59:27 +00:00
|
|
|
layout_resize_adjust(w, lc, LAYOUT_TOPBOTTOM, change);
|
|
|
|
}
|
|
|
|
if (change != 0)
|
|
|
|
changed = 1;
|
|
|
|
}
|
|
|
|
return (changed);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
layout_spread_out(struct window_pane *wp)
|
|
|
|
{
|
|
|
|
struct layout_cell *parent;
|
|
|
|
struct window *w = wp->window;
|
|
|
|
|
|
|
|
parent = wp->layout_cell->parent;
|
|
|
|
if (parent == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
do {
|
|
|
|
if (layout_spread_cell(w, parent)) {
|
|
|
|
layout_fix_offsets(parent);
|
Support for windows larger than visible on the attached client. This has
been a limitation for a long time.
There are two new options, window-size and default-size, and a new
command, resize-window. The force-width and force-height options and the
session_width and session_height formats have been removed.
The new window-size option tells tmux how to work out the size of
windows: largest means it picks the size of the largest session,
smallest the smallest session (similar to the old behaviour) and manual
means that it does not automatically resize windows. The default is
currently largest but this may change. aggressive-resize modifies the
choice of session for largest and smallest as it did before.
If a window is in a session attached to a client that is too small, only
part of the window is shown. tmux attempts to keep the cursor visible,
so the part of the window displayed is changed as the cursor moves (with
a small delay, to try and avoid excess redrawing when applications
redraw status lines or similar that are not currently visible). The
offset of the visible portion of the window is shown in status-right.
Drawing windows which are larger than the client is not as efficient as
those which fit, particularly when the cursor moves, so it is
recommended to avoid using this on slow machines or networks (set
window-size to smallest or manual).
The resize-window command can be used to resize a window manually. If it
is used, the window-size option is automatically set to manual for the
window (undo this with "setw -u window-size"). resize-window works in a
similar way to resize-pane (-U -D -L -R -x -y flags) but also has -a and
-A flags. -a sets the window to the size of the smallest client (what it
would be if window-size was smallest) and -A the largest.
For the same behaviour as force-width or force-height, use resize-window
-x or -y, and "setw -u window-size" to revert to automatic sizing..
If the global window-size option is set to manual, the default-size
option is used for new windows. If -x or -y is used with new-session,
that sets the default-size option for the new session.
The maximum size of a window is 10000x10000. But expect applications to
complain and much higher memory use if making a window excessively
big. The minimum size is the size required for the current layout
including borders.
The refresh-client command can be used to pan around a window, -U -D -L
-R moves up, down, left or right and -c returns to automatic cursor
tracking. The position is reset when the current window is changed.
2018-10-18 08:38:01 +00:00
|
|
|
layout_fix_panes(w);
|
2017-11-15 19:59:27 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
} while ((parent = parent->parent) != NULL);
|
|
|
|
}
|