summaryrefslogtreecommitdiffstats
path: root/layout.c
diff options
context:
space:
mode:
authornicm <nicm>2016-04-29 15:00:48 +0000
committernicm <nicm>2016-04-29 15:00:48 +0000
commit0509be07404a4f4626bbdab56d858f657dc68604 (patch)
treeae0d8196081ac903121f0d2e4ac754a763a3689d /layout.c
parent0d84fdd95303a6ed4dcd761425e35f3731b86725 (diff)
Add option to include status text in the pane borders. If
pane-border-status is set to "top" or "bottom" (rather than "off"), every pane has a permanent top or bottom border containing the text from pane-border-format. Based on a diff sent long ago by Jonathan Slenders, mostly rewritten and simplified by me.
Diffstat (limited to 'layout.c')
-rw-r--r--layout.c50
1 files changed, 46 insertions, 4 deletions
diff --git a/layout.c b/layout.c
index 31dce95c..a73ba527 100644
--- a/layout.c
+++ b/layout.c
@@ -32,8 +32,11 @@
* cell a pointer to its parent cell.
*/
-int layout_resize_pane_grow(struct layout_cell *, enum layout_type, int);
-int layout_resize_pane_shrink(struct layout_cell *, enum layout_type, int);
+static int layout_resize_pane_grow(struct layout_cell *, enum layout_type,
+ int);
+static int layout_resize_pane_shrink(struct layout_cell *,
+ enum layout_type, int);
+static int layout_need_status(struct layout_cell *, int);
struct layout_cell *
layout_create_cell(struct layout_cell *lcparent)
@@ -163,6 +166,30 @@ layout_fix_offsets(struct layout_cell *lc)
}
}
+/*
+ * 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;
+
+ if (lc->parent) {
+ 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);
+}
+
/* Update pane offsets and sizes based on their cells. */
void
layout_fix_panes(struct window *w, u_int wsx, u_int wsy)
@@ -170,13 +197,25 @@ layout_fix_panes(struct window *w, u_int wsx, u_int wsy)
struct window_pane *wp;
struct layout_cell *lc;
u_int sx, sy;
+ int shift, status, at_top;
+ status = options_get_number(w->options, "pane-border-status");
+ at_top = (status == 1);
TAILQ_FOREACH(wp, &w->panes, entry) {
if ((lc = wp->layout_cell) == NULL)
continue;
+
+ if (status != 0)
+ shift = layout_need_status(lc, at_top);
+ else
+ shift = 0;
+
wp->xoff = lc->xoff;
wp->yoff = lc->yoff;
+ if (shift && at_top)
+ wp->yoff += 1;
+
/*
* Layout cells are limited by the smallest size of other cells
* within the same row or column; if this isn't the case
@@ -214,6 +253,9 @@ layout_fix_panes(struct window *w, u_int wsx, u_int wsy)
sy = lc->sy;
}
+ if (shift)
+ sy -= 1;
+
window_pane_resize(wp, sx, sy);
}
}
@@ -520,7 +562,7 @@ layout_resize_pane(struct window_pane *wp, enum layout_type type, int change)
}
/* Helper function to grow pane. */
-int
+static int
layout_resize_pane_grow(struct layout_cell *lc, enum layout_type type,
int needed)
{
@@ -561,7 +603,7 @@ layout_resize_pane_grow(struct layout_cell *lc, enum layout_type type,
}
/* Helper function to shrink pane. */
-int
+static int
layout_resize_pane_shrink(struct layout_cell *lc, enum layout_type type,
int needed)
{