diff options
author | Nicholas Marriott <nicm@cvs.openbsd.org> | 2017-11-15 19:59:28 +0000 |
---|---|---|
committer | Nicholas Marriott <nicm@cvs.openbsd.org> | 2017-11-15 19:59:28 +0000 |
commit | a0f528479038c3624c7c979737bbdddcf192ab1f (patch) | |
tree | 1ad8451e448c46a20786b27b8da9401c8033390c /usr.bin/tmux/layout.c | |
parent | dd19a0f04db7657e686ec49283ddf67b1ca67ffb (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/tmux/layout.c')
-rw-r--r-- | usr.bin/tmux/layout.c | 60 |
1 files changed, 59 insertions, 1 deletions
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); +} |