2009-07-19 13:21:40 +00:00
|
|
|
/* $OpenBSD$ */
|
|
|
|
|
|
|
|
/*
|
2016-01-19 15:59:12 +00:00
|
|
|
* Copyright (c) 2009 Nicholas Marriott <nicholas.marriott@gmail.com>
|
2009-07-19 13:21:40 +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>
|
|
|
|
|
2020-04-22 06:57:13 +00:00
|
|
|
#include <stdlib.h>
|
2009-07-19 13:21:40 +00:00
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "tmux.h"
|
|
|
|
|
|
|
|
/*
|
2014-04-17 14:45:49 +00:00
|
|
|
* Set window layouts - predefined methods to arrange windows. These are
|
|
|
|
* one-off and generate a layout tree.
|
2009-07-19 13:21:40 +00:00
|
|
|
*/
|
|
|
|
|
2016-10-10 21:29:23 +00:00
|
|
|
static void layout_set_even_h(struct window *);
|
|
|
|
static void layout_set_even_v(struct window *);
|
|
|
|
static void layout_set_main_h(struct window *);
|
|
|
|
static void layout_set_main_v(struct window *);
|
|
|
|
static void layout_set_tiled(struct window *);
|
2009-07-19 13:21:40 +00:00
|
|
|
|
2016-10-11 13:45:47 +00:00
|
|
|
static const struct {
|
2009-07-19 13:21:40 +00:00
|
|
|
const char *name;
|
|
|
|
void (*arrange)(struct window *);
|
|
|
|
} layout_sets[] = {
|
|
|
|
{ "even-horizontal", layout_set_even_h },
|
|
|
|
{ "even-vertical", layout_set_even_v },
|
|
|
|
{ "main-horizontal", layout_set_main_h },
|
|
|
|
{ "main-vertical", layout_set_main_v },
|
2010-04-25 20:28:13 +00:00
|
|
|
{ "tiled", layout_set_tiled },
|
2009-07-19 13:21:40 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
int
|
|
|
|
layout_set_lookup(const char *name)
|
|
|
|
{
|
|
|
|
u_int i;
|
|
|
|
int matched = -1;
|
|
|
|
|
|
|
|
for (i = 0; i < nitems(layout_sets); i++) {
|
|
|
|
if (strncmp(layout_sets[i].name, name, strlen(name)) == 0) {
|
|
|
|
if (matched != -1) /* ambiguous */
|
|
|
|
return (-1);
|
|
|
|
matched = i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return (matched);
|
|
|
|
}
|
|
|
|
|
|
|
|
u_int
|
|
|
|
layout_set_select(struct window *w, u_int layout)
|
|
|
|
{
|
|
|
|
if (layout > nitems(layout_sets) - 1)
|
|
|
|
layout = nitems(layout_sets) - 1;
|
|
|
|
|
|
|
|
if (layout_sets[layout].arrange != NULL)
|
|
|
|
layout_sets[layout].arrange(w);
|
|
|
|
|
2009-07-28 06:48:44 +00:00
|
|
|
w->lastlayout = layout;
|
2009-07-19 13:21:40 +00:00
|
|
|
return (layout);
|
|
|
|
}
|
|
|
|
|
|
|
|
u_int
|
|
|
|
layout_set_next(struct window *w)
|
|
|
|
{
|
2009-07-28 06:48:44 +00:00
|
|
|
u_int layout;
|
|
|
|
|
|
|
|
if (w->lastlayout == -1)
|
|
|
|
layout = 0;
|
|
|
|
else {
|
|
|
|
layout = w->lastlayout + 1;
|
|
|
|
if (layout > nitems(layout_sets) - 1)
|
|
|
|
layout = 0;
|
|
|
|
}
|
2009-07-19 13:21:40 +00:00
|
|
|
|
|
|
|
if (layout_sets[layout].arrange != NULL)
|
|
|
|
layout_sets[layout].arrange(w);
|
2009-07-28 06:48:44 +00:00
|
|
|
w->lastlayout = layout;
|
2009-07-19 13:21:40 +00:00
|
|
|
return (layout);
|
|
|
|
}
|
|
|
|
|
|
|
|
u_int
|
|
|
|
layout_set_previous(struct window *w)
|
|
|
|
{
|
2009-07-28 06:48:44 +00:00
|
|
|
u_int layout;
|
|
|
|
|
|
|
|
if (w->lastlayout == -1)
|
|
|
|
layout = nitems(layout_sets) - 1;
|
|
|
|
else {
|
|
|
|
layout = w->lastlayout;
|
|
|
|
if (layout == 0)
|
|
|
|
layout = nitems(layout_sets) - 1;
|
|
|
|
else
|
|
|
|
layout--;
|
|
|
|
}
|
2009-07-19 13:21:40 +00:00
|
|
|
|
|
|
|
if (layout_sets[layout].arrange != NULL)
|
|
|
|
layout_sets[layout].arrange(w);
|
2009-07-28 06:48:44 +00:00
|
|
|
w->lastlayout = layout;
|
2009-07-19 13:21:40 +00:00
|
|
|
return (layout);
|
|
|
|
}
|
|
|
|
|
2016-10-10 21:29:23 +00:00
|
|
|
static void
|
2017-11-15 19:59:27 +00:00
|
|
|
layout_set_even(struct window *w, enum layout_type type)
|
2009-07-19 13:21:40 +00:00
|
|
|
{
|
|
|
|
struct window_pane *wp;
|
|
|
|
struct layout_cell *lc, *lcnew;
|
2019-04-17 14:43:49 +00:00
|
|
|
u_int n, sx, sy;
|
2009-07-19 13:21:40 +00:00
|
|
|
|
|
|
|
layout_print_cell(w->layout_root, __func__, 1);
|
|
|
|
|
|
|
|
/* Get number of panes. */
|
|
|
|
n = window_count_panes(w);
|
|
|
|
if (n <= 1)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* Free the old root and construct a new. */
|
|
|
|
layout_free(w);
|
|
|
|
lc = w->layout_root = layout_create_cell(NULL);
|
2019-04-17 14:43:49 +00:00
|
|
|
if (type == LAYOUT_LEFTRIGHT) {
|
|
|
|
sx = (n * (PANE_MINIMUM + 1)) - 1;
|
|
|
|
if (sx < w->sx)
|
|
|
|
sx = w->sx;
|
|
|
|
sy = w->sy;
|
|
|
|
} else {
|
|
|
|
sy = (n * (PANE_MINIMUM + 1)) - 1;
|
|
|
|
if (sy < w->sy)
|
|
|
|
sy = w->sy;
|
|
|
|
sx = w->sx;
|
|
|
|
}
|
|
|
|
layout_set_size(lc, sx, sy, 0, 0);
|
2017-11-15 19:59:27 +00:00
|
|
|
layout_make_node(lc, type);
|
2009-07-19 13:21:40 +00:00
|
|
|
|
|
|
|
/* Build new leaf cells. */
|
|
|
|
TAILQ_FOREACH(wp, &w->panes, entry) {
|
|
|
|
lcnew = layout_create_cell(lc);
|
|
|
|
layout_make_leaf(lcnew, wp);
|
2017-12-31 20:00:44 +00:00
|
|
|
lcnew->sx = w->sx;
|
|
|
|
lcnew->sy = w->sy;
|
2009-07-19 13:21:40 +00:00
|
|
|
TAILQ_INSERT_TAIL(&lc->cells, lcnew, entry);
|
|
|
|
}
|
|
|
|
|
2017-11-15 19:59:27 +00:00
|
|
|
/* Spread out cells. */
|
|
|
|
layout_spread_cell(w, lc);
|
2009-07-19 13:21:40 +00:00
|
|
|
|
|
|
|
/* Fix cell offsets. */
|
2019-07-15 18:25:07 +00:00
|
|
|
layout_fix_offsets(w);
|
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
|
|
|
|
|
|
|
layout_print_cell(w->layout_root, __func__, 1);
|
|
|
|
|
2019-11-28 09:45:15 +00:00
|
|
|
window_resize(w, lc->sx, lc->sy, -1, -1);
|
2017-05-15 14:57:29 +00:00
|
|
|
notify_window("window-layout-changed", w);
|
2009-07-19 13:21:40 +00:00
|
|
|
server_redraw_window(w);
|
|
|
|
}
|
|
|
|
|
2016-10-10 21:29:23 +00:00
|
|
|
static void
|
2017-11-15 19:59:27 +00:00
|
|
|
layout_set_even_h(struct window *w)
|
2009-07-19 13:21:40 +00:00
|
|
|
{
|
2017-11-15 19:59:27 +00:00
|
|
|
layout_set_even(w, LAYOUT_LEFTRIGHT);
|
|
|
|
}
|
2009-07-19 13:21:40 +00:00
|
|
|
|
2017-11-15 19:59:27 +00:00
|
|
|
static void
|
|
|
|
layout_set_even_v(struct window *w)
|
|
|
|
{
|
|
|
|
layout_set_even(w, LAYOUT_TOPBOTTOM);
|
2009-07-19 13:21:40 +00:00
|
|
|
}
|
|
|
|
|
2016-10-10 21:29:23 +00:00
|
|
|
static void
|
2009-07-19 13:21:40 +00:00
|
|
|
layout_set_main_h(struct window *w)
|
|
|
|
{
|
|
|
|
struct window_pane *wp;
|
2019-04-17 14:44:14 +00:00
|
|
|
struct layout_cell *lc, *lcmain, *lcother, *lcchild;
|
2019-05-14 07:37:50 +00:00
|
|
|
u_int n, mainh, otherh, sx, sy;
|
2020-04-22 06:57:13 +00:00
|
|
|
char *cause;
|
|
|
|
const char *s;
|
2009-07-19 13:21:40 +00:00
|
|
|
|
|
|
|
layout_print_cell(w->layout_root, __func__, 1);
|
|
|
|
|
|
|
|
/* Get number of panes. */
|
|
|
|
n = window_count_panes(w);
|
|
|
|
if (n <= 1)
|
|
|
|
return;
|
|
|
|
n--; /* take off main pane */
|
|
|
|
|
2019-05-14 07:37:50 +00:00
|
|
|
/* Find available height - take off one line for the border. */
|
|
|
|
sy = w->sy - 1;
|
|
|
|
|
2020-04-22 06:57:13 +00:00
|
|
|
/* Get the main pane height. */
|
|
|
|
s = options_get_string(w->options, "main-pane-height");
|
|
|
|
mainh = args_string_percentage(s, 0, sy, sy, &cause);
|
|
|
|
if (cause != NULL) {
|
|
|
|
mainh = 24;
|
|
|
|
free(cause);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Work out the other pane height. */
|
2019-05-14 07:37:50 +00:00
|
|
|
if (mainh + PANE_MINIMUM >= sy) {
|
|
|
|
if (sy <= PANE_MINIMUM + PANE_MINIMUM)
|
2019-04-17 14:44:14 +00:00
|
|
|
mainh = PANE_MINIMUM;
|
2009-07-19 13:21:40 +00:00
|
|
|
else
|
2019-05-14 07:37:50 +00:00
|
|
|
mainh = sy - PANE_MINIMUM;
|
2019-04-17 14:44:14 +00:00
|
|
|
otherh = PANE_MINIMUM;
|
|
|
|
} else {
|
2020-04-22 06:57:13 +00:00
|
|
|
s = options_get_string(w->options, "other-pane-height");
|
|
|
|
otherh = args_string_percentage(s, 0, sy, sy, &cause);
|
|
|
|
if (cause != NULL || otherh == 0) {
|
2019-05-14 07:37:50 +00:00
|
|
|
otherh = sy - mainh;
|
2020-04-22 06:57:13 +00:00
|
|
|
free(cause);
|
|
|
|
} else if (otherh > sy || sy - otherh < mainh)
|
2019-05-14 07:37:50 +00:00
|
|
|
otherh = sy - mainh;
|
2019-04-17 14:44:14 +00:00
|
|
|
else
|
2019-05-14 07:37:50 +00:00
|
|
|
mainh = sy - otherh;
|
2019-04-17 14:44:14 +00:00
|
|
|
}
|
|
|
|
|
2019-04-26 10:15:40 +00:00
|
|
|
/* Work out what width is needed. */
|
2019-04-17 14:44:14 +00:00
|
|
|
sx = (n * (PANE_MINIMUM + 1)) - 1;
|
|
|
|
if (sx < w->sx)
|
|
|
|
sx = w->sx;
|
2009-07-19 13:21:40 +00:00
|
|
|
|
|
|
|
/* Free old tree and create a new root. */
|
|
|
|
layout_free(w);
|
|
|
|
lc = w->layout_root = layout_create_cell(NULL);
|
2019-05-14 07:37:50 +00:00
|
|
|
layout_set_size(lc, sx, mainh + otherh + 1, 0, 0);
|
2009-07-19 13:21:40 +00:00
|
|
|
layout_make_node(lc, LAYOUT_TOPBOTTOM);
|
|
|
|
|
|
|
|
/* Create the main pane. */
|
|
|
|
lcmain = layout_create_cell(lc);
|
2019-04-17 14:44:14 +00:00
|
|
|
layout_set_size(lcmain, sx, mainh, 0, 0);
|
2009-07-19 13:21:40 +00:00
|
|
|
layout_make_leaf(lcmain, TAILQ_FIRST(&w->panes));
|
|
|
|
TAILQ_INSERT_TAIL(&lc->cells, lcmain, entry);
|
|
|
|
|
2019-04-17 14:44:14 +00:00
|
|
|
/* Create the other pane. */
|
|
|
|
lcother = layout_create_cell(lc);
|
|
|
|
layout_set_size(lcother, sx, otherh, 0, 0);
|
2019-04-26 10:15:40 +00:00
|
|
|
if (n == 1) {
|
|
|
|
wp = TAILQ_NEXT(TAILQ_FIRST(&w->panes), entry);
|
|
|
|
layout_make_leaf(lcother, wp);
|
|
|
|
TAILQ_INSERT_TAIL(&lc->cells, lcother, entry);
|
|
|
|
} else {
|
|
|
|
layout_make_node(lcother, LAYOUT_LEFTRIGHT);
|
|
|
|
TAILQ_INSERT_TAIL(&lc->cells, lcother, entry);
|
|
|
|
|
|
|
|
/* Add the remaining panes as children. */
|
|
|
|
TAILQ_FOREACH(wp, &w->panes, entry) {
|
|
|
|
if (wp == TAILQ_FIRST(&w->panes))
|
|
|
|
continue;
|
|
|
|
lcchild = layout_create_cell(lcother);
|
|
|
|
layout_set_size(lcchild, PANE_MINIMUM, otherh, 0, 0);
|
|
|
|
layout_make_leaf(lcchild, wp);
|
|
|
|
TAILQ_INSERT_TAIL(&lcother->cells, lcchild, entry);
|
|
|
|
}
|
|
|
|
layout_spread_cell(w, lcother);
|
2009-07-19 13:21:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Fix cell offsets. */
|
2019-07-15 18:25:07 +00:00
|
|
|
layout_fix_offsets(w);
|
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
|
|
|
|
|
|
|
layout_print_cell(w->layout_root, __func__, 1);
|
|
|
|
|
2019-11-28 09:45:15 +00:00
|
|
|
window_resize(w, lc->sx, lc->sy, -1, -1);
|
2017-05-15 14:57:29 +00:00
|
|
|
notify_window("window-layout-changed", w);
|
2009-07-19 13:21:40 +00:00
|
|
|
server_redraw_window(w);
|
|
|
|
}
|
|
|
|
|
2016-10-10 21:29:23 +00:00
|
|
|
static void
|
2009-07-19 13:21:40 +00:00
|
|
|
layout_set_main_v(struct window *w)
|
|
|
|
{
|
|
|
|
struct window_pane *wp;
|
2019-04-17 14:44:14 +00:00
|
|
|
struct layout_cell *lc, *lcmain, *lcother, *lcchild;
|
2019-05-14 07:37:50 +00:00
|
|
|
u_int n, mainw, otherw, sx, sy;
|
2020-04-22 06:57:13 +00:00
|
|
|
char *cause;
|
|
|
|
const char *s;
|
2009-07-19 13:21:40 +00:00
|
|
|
|
|
|
|
layout_print_cell(w->layout_root, __func__, 1);
|
|
|
|
|
|
|
|
/* Get number of panes. */
|
|
|
|
n = window_count_panes(w);
|
|
|
|
if (n <= 1)
|
|
|
|
return;
|
|
|
|
n--; /* take off main pane */
|
|
|
|
|
2019-05-14 07:37:50 +00:00
|
|
|
/* Find available width - take off one line for the border. */
|
|
|
|
sx = w->sx - 1;
|
|
|
|
|
2020-04-22 06:57:13 +00:00
|
|
|
/* Get the main pane width. */
|
|
|
|
s = options_get_string(w->options, "main-pane-width");
|
|
|
|
mainw = args_string_percentage(s, 0, sx, sx, &cause);
|
|
|
|
if (cause != NULL) {
|
|
|
|
mainw = 80;
|
|
|
|
free(cause);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Work out the other pane width. */
|
2019-05-14 07:37:50 +00:00
|
|
|
if (mainw + PANE_MINIMUM >= sx) {
|
|
|
|
if (sx <= PANE_MINIMUM + PANE_MINIMUM)
|
2019-04-17 14:44:14 +00:00
|
|
|
mainw = PANE_MINIMUM;
|
2009-07-19 13:21:40 +00:00
|
|
|
else
|
2019-05-14 07:37:50 +00:00
|
|
|
mainw = sx - PANE_MINIMUM;
|
2019-04-17 14:44:14 +00:00
|
|
|
otherw = PANE_MINIMUM;
|
|
|
|
} else {
|
2020-04-22 06:57:13 +00:00
|
|
|
s = options_get_string(w->options, "other-pane-width");
|
|
|
|
otherw = args_string_percentage(s, 0, sx, sx, &cause);
|
|
|
|
if (cause != NULL || otherw == 0) {
|
2019-05-14 07:37:50 +00:00
|
|
|
otherw = sx - mainw;
|
2020-04-22 06:57:13 +00:00
|
|
|
free(cause);
|
|
|
|
} else if (otherw > sx || sx - otherw < mainw)
|
2019-05-14 07:37:50 +00:00
|
|
|
otherw = sx - mainw;
|
2019-04-17 14:44:14 +00:00
|
|
|
else
|
2019-05-14 07:37:50 +00:00
|
|
|
mainw = sx - otherw;
|
2019-04-17 14:44:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Work out what height is needed. */
|
|
|
|
sy = (n * (PANE_MINIMUM + 1)) - 1;
|
|
|
|
if (sy < w->sy)
|
|
|
|
sy = w->sy;
|
2009-07-19 13:21:40 +00:00
|
|
|
|
|
|
|
/* Free old tree and create a new root. */
|
|
|
|
layout_free(w);
|
|
|
|
lc = w->layout_root = layout_create_cell(NULL);
|
2019-05-14 07:37:50 +00:00
|
|
|
layout_set_size(lc, mainw + otherw + 1, sy, 0, 0);
|
2009-07-19 13:21:40 +00:00
|
|
|
layout_make_node(lc, LAYOUT_LEFTRIGHT);
|
|
|
|
|
|
|
|
/* Create the main pane. */
|
|
|
|
lcmain = layout_create_cell(lc);
|
2019-04-17 14:44:14 +00:00
|
|
|
layout_set_size(lcmain, mainw, sy, 0, 0);
|
2009-07-19 13:21:40 +00:00
|
|
|
layout_make_leaf(lcmain, TAILQ_FIRST(&w->panes));
|
|
|
|
TAILQ_INSERT_TAIL(&lc->cells, lcmain, entry);
|
|
|
|
|
2019-04-17 14:44:14 +00:00
|
|
|
/* Create the other pane. */
|
|
|
|
lcother = layout_create_cell(lc);
|
|
|
|
layout_set_size(lcother, otherw, sy, 0, 0);
|
2019-04-26 10:15:40 +00:00
|
|
|
if (n == 1) {
|
|
|
|
wp = TAILQ_NEXT(TAILQ_FIRST(&w->panes), entry);
|
|
|
|
layout_make_leaf(lcother, wp);
|
|
|
|
TAILQ_INSERT_TAIL(&lc->cells, lcother, entry);
|
|
|
|
} else {
|
|
|
|
layout_make_node(lcother, LAYOUT_TOPBOTTOM);
|
|
|
|
TAILQ_INSERT_TAIL(&lc->cells, lcother, entry);
|
|
|
|
|
|
|
|
/* Add the remaining panes as children. */
|
|
|
|
TAILQ_FOREACH(wp, &w->panes, entry) {
|
|
|
|
if (wp == TAILQ_FIRST(&w->panes))
|
|
|
|
continue;
|
|
|
|
lcchild = layout_create_cell(lcother);
|
|
|
|
layout_set_size(lcchild, otherw, PANE_MINIMUM, 0, 0);
|
|
|
|
layout_make_leaf(lcchild, wp);
|
|
|
|
TAILQ_INSERT_TAIL(&lcother->cells, lcchild, entry);
|
|
|
|
}
|
|
|
|
layout_spread_cell(w, lcother);
|
2009-07-19 13:21:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Fix cell offsets. */
|
2019-07-15 18:25:07 +00:00
|
|
|
layout_fix_offsets(w);
|
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
|
|
|
|
|
|
|
layout_print_cell(w->layout_root, __func__, 1);
|
|
|
|
|
2019-11-28 09:45:15 +00:00
|
|
|
window_resize(w, lc->sx, lc->sy, -1, -1);
|
2017-05-15 14:57:29 +00:00
|
|
|
notify_window("window-layout-changed", w);
|
2009-07-19 13:21:40 +00:00
|
|
|
server_redraw_window(w);
|
|
|
|
}
|
2010-04-25 20:28:13 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
layout_set_tiled(struct window *w)
|
|
|
|
{
|
|
|
|
struct window_pane *wp;
|
|
|
|
struct layout_cell *lc, *lcrow, *lcchild;
|
2019-04-17 14:43:49 +00:00
|
|
|
u_int n, width, height, used, sx, sy;
|
2010-04-25 20:28:13 +00:00
|
|
|
u_int i, j, columns, rows;
|
|
|
|
|
|
|
|
layout_print_cell(w->layout_root, __func__, 1);
|
|
|
|
|
|
|
|
/* Get number of panes. */
|
|
|
|
n = window_count_panes(w);
|
|
|
|
if (n <= 1)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* How many rows and columns are wanted? */
|
|
|
|
rows = columns = 1;
|
|
|
|
while (rows * columns < n) {
|
|
|
|
rows++;
|
|
|
|
if (rows * columns < n)
|
|
|
|
columns++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* What width and height should they be? */
|
2010-12-08 19:57:03 +00:00
|
|
|
width = (w->sx - (columns - 1)) / columns;
|
|
|
|
if (width < PANE_MINIMUM)
|
|
|
|
width = PANE_MINIMUM;
|
|
|
|
height = (w->sy - (rows - 1)) / rows;
|
|
|
|
if (height < PANE_MINIMUM)
|
|
|
|
height = PANE_MINIMUM;
|
2010-04-25 20:28:13 +00:00
|
|
|
|
|
|
|
/* Free old tree and create a new root. */
|
|
|
|
layout_free(w);
|
|
|
|
lc = w->layout_root = layout_create_cell(NULL);
|
2019-04-17 14:43:49 +00:00
|
|
|
sx = ((width + 1) * columns) - 1;
|
|
|
|
if (sx < w->sx)
|
|
|
|
sx = w->sx;
|
|
|
|
sy = ((height + 1) * rows) - 1;
|
|
|
|
if (sy < w->sy)
|
|
|
|
sy = w->sy;
|
|
|
|
layout_set_size(lc, sx, sy, 0, 0);
|
2010-04-25 20:28:13 +00:00
|
|
|
layout_make_node(lc, LAYOUT_TOPBOTTOM);
|
|
|
|
|
|
|
|
/* Create a grid of the cells. */
|
|
|
|
wp = TAILQ_FIRST(&w->panes);
|
|
|
|
for (j = 0; j < rows; j++) {
|
|
|
|
/* If this is the last cell, all done. */
|
|
|
|
if (wp == NULL)
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* Create the new row. */
|
|
|
|
lcrow = layout_create_cell(lc);
|
2010-12-08 19:57:03 +00:00
|
|
|
layout_set_size(lcrow, w->sx, height, 0, 0);
|
2010-04-25 20:28:13 +00:00
|
|
|
TAILQ_INSERT_TAIL(&lc->cells, lcrow, entry);
|
|
|
|
|
|
|
|
/* If only one column, just use the row directly. */
|
2011-03-07 23:55:16 +00:00
|
|
|
if (n - (j * columns) == 1 || columns == 1) {
|
2010-04-25 20:28:13 +00:00
|
|
|
layout_make_leaf(lcrow, wp);
|
|
|
|
wp = TAILQ_NEXT(wp, entry);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Add in the columns. */
|
|
|
|
layout_make_node(lcrow, LAYOUT_LEFTRIGHT);
|
|
|
|
for (i = 0; i < columns; i++) {
|
|
|
|
/* Create and add a pane cell. */
|
|
|
|
lcchild = layout_create_cell(lcrow);
|
2010-12-08 19:57:03 +00:00
|
|
|
layout_set_size(lcchild, width, height, 0, 0);
|
2010-04-25 20:28:13 +00:00
|
|
|
layout_make_leaf(lcchild, wp);
|
|
|
|
TAILQ_INSERT_TAIL(&lcrow->cells, lcchild, entry);
|
|
|
|
|
|
|
|
/* Move to the next cell. */
|
|
|
|
if ((wp = TAILQ_NEXT(wp, entry)) == NULL)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Adjust the row and columns to fit the full width if
|
|
|
|
* necessary.
|
|
|
|
*/
|
|
|
|
if (i == columns)
|
|
|
|
i--;
|
2010-12-08 19:57:03 +00:00
|
|
|
used = ((i + 1) * (width + 1)) - 1;
|
2010-04-25 20:28:13 +00:00
|
|
|
if (w->sx <= used)
|
|
|
|
continue;
|
|
|
|
lcchild = TAILQ_LAST(&lcrow->cells, layout_cells);
|
2016-08-03 09:07:02 +00:00
|
|
|
layout_resize_adjust(w, lcchild, LAYOUT_LEFTRIGHT,
|
|
|
|
w->sx - used);
|
2010-04-25 20:28:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Adjust the last row height to fit if necessary. */
|
2010-12-08 19:57:03 +00:00
|
|
|
used = (rows * height) + rows - 1;
|
2010-04-25 20:28:13 +00:00
|
|
|
if (w->sy > used) {
|
|
|
|
lcrow = TAILQ_LAST(&lc->cells, layout_cells);
|
2016-08-03 09:07:02 +00:00
|
|
|
layout_resize_adjust(w, lcrow, LAYOUT_TOPBOTTOM,
|
|
|
|
w->sy - used);
|
2010-04-25 20:28:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Fix cell offsets. */
|
2019-07-15 18:25:07 +00:00
|
|
|
layout_fix_offsets(w);
|
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-04-25 20:28:13 +00:00
|
|
|
|
|
|
|
layout_print_cell(w->layout_root, __func__, 1);
|
|
|
|
|
2019-11-28 09:45:15 +00:00
|
|
|
window_resize(w, lc->sx, lc->sy, -1, -1);
|
2017-05-15 14:57:29 +00:00
|
|
|
notify_window("window-layout-changed", w);
|
2010-04-25 20:28:13 +00:00
|
|
|
server_redraw_window(w);
|
|
|
|
}
|