summaryrefslogtreecommitdiff
path: root/usr.bin
diff options
context:
space:
mode:
authorNicholas Marriott <nicm@cvs.openbsd.org>2017-11-15 19:59:28 +0000
committerNicholas Marriott <nicm@cvs.openbsd.org>2017-11-15 19:59:28 +0000
commita0f528479038c3624c7c979737bbdddcf192ab1f (patch)
tree1ad8451e448c46a20786b27b8da9401c8033390c /usr.bin
parentdd19a0f04db7657e686ec49283ddf67b1ca67ffb (diff)
Add a common function for spreading out cells and use it for the two
even layouts and to add a -E flag to select-layout to spread out cells evenly without changing parent cells.
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/tmux/cmd-select-layout.c29
-rw-r--r--usr.bin/tmux/key-bindings.c3
-rw-r--r--usr.bin/tmux/layout-set.c84
-rw-r--r--usr.bin/tmux/layout.c60
-rw-r--r--usr.bin/tmux/tmux.110
-rw-r--r--usr.bin/tmux/tmux.h4
6 files changed, 100 insertions, 90 deletions
diff --git a/usr.bin/tmux/cmd-select-layout.c b/usr.bin/tmux/cmd-select-layout.c
index b2d572e442c..e024f7bd977 100644
--- a/usr.bin/tmux/cmd-select-layout.c
+++ b/usr.bin/tmux/cmd-select-layout.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cmd-select-layout.c,v 1.33 2017/04/22 10:22:39 nicm Exp $ */
+/* $OpenBSD: cmd-select-layout.c,v 1.34 2017/11/15 19:59:27 nicm Exp $ */
/*
* Copyright (c) 2009 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -33,10 +33,10 @@ const struct cmd_entry cmd_select_layout_entry = {
.name = "select-layout",
.alias = "selectl",
- .args = { "nopt:", 0, 1 },
- .usage = "[-nop] " CMD_TARGET_WINDOW_USAGE " [layout-name]",
+ .args = { "Enopt:", 0, 1 },
+ .usage = "[-Enop] " CMD_TARGET_PANE_USAGE " [layout-name]",
- .target = { 't', CMD_FIND_WINDOW, 0 },
+ .target = { 't', CMD_FIND_PANE, 0 },
.flags = CMD_AFTERHOOK,
.exec = cmd_select_layout_exec
@@ -71,14 +71,14 @@ const struct cmd_entry cmd_previous_layout_entry = {
static enum cmd_retval
cmd_select_layout_exec(struct cmd *self, struct cmdq_item *item)
{
- struct args *args = self->args;
- struct winlink *wl = item->target.wl;
- struct window *w;
- const char *layoutname;
- char *oldlayout;
- int next, previous, layout;
-
- w = wl->window;
+ struct args *args = self->args;
+ struct winlink *wl = item->target.wl;
+ struct window *w = wl->window;
+ struct window_pane *wp = item->target.wp;
+ const char *layoutname;
+ char *oldlayout;
+ int next, previous, layout;
+
server_unzoom_window(w);
next = self->entry == &cmd_next_layout_entry;
@@ -99,6 +99,11 @@ cmd_select_layout_exec(struct cmd *self, struct cmdq_item *item)
goto changed;
}
+ if (args_has(args, 'E')) {
+ layout_spread_out(wp);
+ goto changed;
+ }
+
if (!args_has(args, 'o')) {
if (args->argc == 0)
layout = w->lastlayout;
diff --git a/usr.bin/tmux/key-bindings.c b/usr.bin/tmux/key-bindings.c
index 26d68620b16..4bb01f36c66 100644
--- a/usr.bin/tmux/key-bindings.c
+++ b/usr.bin/tmux/key-bindings.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: key-bindings.c,v 1.83 2017/10/05 13:43:34 nicm Exp $ */
+/* $OpenBSD: key-bindings.c,v 1.84 2017/11/15 19:59:27 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -186,6 +186,7 @@ key_bindings_init(void)
"bind = choose-buffer",
"bind ? list-keys",
"bind D choose-client",
+ "bind E select-layout -E",
"bind L switch-client -l",
"bind M select-pane -M",
"bind [ copy-mode",
diff --git a/usr.bin/tmux/layout-set.c b/usr.bin/tmux/layout-set.c
index dae3d5a3ddc..4c6d15a07df 100644
--- a/usr.bin/tmux/layout-set.c
+++ b/usr.bin/tmux/layout-set.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: layout-set.c,v 1.18 2017/05/15 14:57:29 nicm Exp $ */
+/* $OpenBSD: layout-set.c,v 1.19 2017/11/15 19:59:27 nicm Exp $ */
/*
* Copyright (c) 2009 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -115,11 +115,11 @@ layout_set_previous(struct window *w)
}
static void
-layout_set_even_h(struct window *w)
+layout_set_even(struct window *w, enum layout_type type)
{
struct window_pane *wp;
struct layout_cell *lc, *lcnew;
- u_int i, n, width, xoff;
+ u_int n;
layout_print_cell(w->layout_root, __func__, 1);
@@ -128,36 +128,21 @@ layout_set_even_h(struct window *w)
if (n <= 1)
return;
- /* How many can we fit? */
- width = (w->sx - (n - 1)) / n;
- if (width < PANE_MINIMUM)
- width = PANE_MINIMUM;
-
/* Free the old root and construct a new. */
layout_free(w);
lc = w->layout_root = layout_create_cell(NULL);
layout_set_size(lc, w->sx, w->sy, 0, 0);
- layout_make_node(lc, LAYOUT_LEFTRIGHT);
+ layout_make_node(lc, type);
/* Build new leaf cells. */
- i = xoff = 0;
TAILQ_FOREACH(wp, &w->panes, entry) {
- /* Create child cell. */
lcnew = layout_create_cell(lc);
- layout_set_size(lcnew, width, w->sy, xoff, 0);
layout_make_leaf(lcnew, wp);
TAILQ_INSERT_TAIL(&lc->cells, lcnew, entry);
-
- i++;
- xoff += width + 1;
}
- /* Allocate any remaining space. */
- if (w->sx > xoff - 1) {
- lc = TAILQ_LAST(&lc->cells, layout_cells);
- layout_resize_adjust(w, lc, LAYOUT_LEFTRIGHT,
- w->sx - (xoff - 1));
- }
+ /* Spread out cells. */
+ layout_spread_cell(w, lc);
/* Fix cell offsets. */
layout_fix_offsets(lc);
@@ -170,58 +155,15 @@ layout_set_even_h(struct window *w)
}
static void
-layout_set_even_v(struct window *w)
+layout_set_even_h(struct window *w)
{
- struct window_pane *wp;
- struct layout_cell *lc, *lcnew;
- u_int i, n, height, yoff;
-
- layout_print_cell(w->layout_root, __func__, 1);
-
- /* Get number of panes. */
- n = window_count_panes(w);
- if (n <= 1)
- return;
-
- /* How many can we fit? */
- height = (w->sy - (n - 1)) / n;
- if (height < PANE_MINIMUM)
- height = PANE_MINIMUM;
-
- /* Free the old root and construct a new. */
- layout_free(w);
- lc = w->layout_root = layout_create_cell(NULL);
- layout_set_size(lc, w->sx, w->sy, 0, 0);
- layout_make_node(lc, LAYOUT_TOPBOTTOM);
-
- /* Build new leaf cells. */
- i = yoff = 0;
- TAILQ_FOREACH(wp, &w->panes, entry) {
- /* Create child cell. */
- lcnew = layout_create_cell(lc);
- layout_set_size(lcnew, w->sx, height, 0, yoff);
- layout_make_leaf(lcnew, wp);
- TAILQ_INSERT_TAIL(&lc->cells, lcnew, entry);
-
- i++;
- yoff += height + 1;
- }
-
- /* Allocate any remaining space. */
- if (w->sy > yoff - 1) {
- lc = TAILQ_LAST(&lc->cells, layout_cells);
- layout_resize_adjust(w, lc, LAYOUT_TOPBOTTOM,
- w->sy - (yoff - 1));
- }
-
- /* Fix cell offsets. */
- layout_fix_offsets(lc);
- layout_fix_panes(w, w->sx, w->sy);
-
- layout_print_cell(w->layout_root, __func__, 1);
+ layout_set_even(w, LAYOUT_LEFTRIGHT);
+}
- notify_window("window-layout-changed", w);
- server_redraw_window(w);
+static void
+layout_set_even_v(struct window *w)
+{
+ layout_set_even(w, LAYOUT_TOPBOTTOM);
}
static void
diff --git a/usr.bin/tmux/layout.c b/usr.bin/tmux/layout.c
index f5e4c4c6cf9..7f83af70ccc 100644
--- a/usr.bin/tmux/layout.c
+++ b/usr.bin/tmux/layout.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: layout.c,v 1.32 2017/03/11 15:16:35 nicm Exp $ */
+/* $OpenBSD: layout.c,v 1.33 2017/11/15 19:59:27 nicm Exp $ */
/*
* Copyright (c) 2009 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -983,3 +983,61 @@ layout_close_pane(struct window_pane *wp)
}
notify_window("window-layout-changed", w);
}
+
+int
+layout_spread_cell(struct window *w, struct layout_cell *parent)
+{
+ struct layout_cell *lc;
+ u_int number, each, size;
+ int change, changed;
+
+ number = 0;
+ TAILQ_FOREACH (lc, &parent->cells, entry)
+ number++;
+ if (number <= 1)
+ return (0);
+
+ if (parent->type == LAYOUT_LEFTRIGHT)
+ size = parent->sx;
+ else if (parent->type == LAYOUT_TOPBOTTOM)
+ size = parent->sy;
+ else
+ return (0);
+ each = (size - (number - 1)) / number;
+
+ changed = 0;
+ TAILQ_FOREACH (lc, &parent->cells, entry) {
+ if (TAILQ_NEXT(lc, entry) == NULL)
+ each = size - (each * (number - 1));
+ 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) {
+ change = each - (int)lc->sy;
+ 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);
+ layout_fix_panes(w, w->sx, w->sy);
+ break;
+ }
+ } while ((parent = parent->parent) != NULL);
+}
diff --git a/usr.bin/tmux/tmux.1 b/usr.bin/tmux/tmux.1
index 9eeef827c8e..78b7458441c 100644
--- a/usr.bin/tmux/tmux.1
+++ b/usr.bin/tmux/tmux.1
@@ -1,4 +1,4 @@
-.\" $OpenBSD: tmux.1,v 1.587 2017/11/02 18:52:05 nicm Exp $
+.\" $OpenBSD: tmux.1,v 1.588 2017/11/15 19:59:27 nicm Exp $
.\"
.\" Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
.\"
@@ -14,7 +14,7 @@
.\" IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
.\" OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
.\"
-.Dd $Mdocdate: November 2 2017 $
+.Dd $Mdocdate: November 15 2017 $
.Dt TMUX 1
.Os
.Sh NAME
@@ -1923,8 +1923,8 @@ lower) with
.Fl U
or downward (numerically higher).
.It Xo Ic select-layout
-.Op Fl nop
-.Op Fl t Ar target-window
+.Op Fl Enop
+.Op Fl t Ar target-pane
.Op Ar layout-name
.Xc
.D1 (alias: Ic selectl )
@@ -1942,6 +1942,8 @@ and
commands.
.Fl o
applies the last set layout if possible (undoes the most recent layout change).
+.Fl E
+spreads the current pane and any panes next to it out evenly.
.It Xo Ic select-pane
.Op Fl DdegLlMmRU
.Op Fl P Ar style
diff --git a/usr.bin/tmux/tmux.h b/usr.bin/tmux/tmux.h
index cb120955757..81fd52f2d27 100644
--- a/usr.bin/tmux/tmux.h
+++ b/usr.bin/tmux/tmux.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: tmux.h,v 1.813 2017/11/15 19:21:24 nicm Exp $ */
+/* $OpenBSD: tmux.h,v 1.814 2017/11/15 19:59:27 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -2213,6 +2213,8 @@ void layout_assign_pane(struct layout_cell *, struct window_pane *);
struct layout_cell *layout_split_pane(struct window_pane *, enum layout_type,
int, int, int);
void layout_close_pane(struct window_pane *);
+int layout_spread_cell(struct window *, struct layout_cell *);
+void layout_spread_out(struct window_pane *);
/* layout-custom.c */
char *layout_dump(struct layout_cell *);