diff options
author | Nicholas Marriott <nicm@cvs.openbsd.org> | 2020-02-14 13:57:59 +0000 |
---|---|---|
committer | Nicholas Marriott <nicm@cvs.openbsd.org> | 2020-02-14 13:57:59 +0000 |
commit | 579439cd720092209bd8cc615534911bdf05a6d8 (patch) | |
tree | 77ec97a4383d9cc42fb3f6a7fc0c7d29a6270e79 | |
parent | 22be2c7b740d329faa36e19d79eff2debd2c5760 (diff) |
Fix top/bottom pane calculation with pane border status enabled,
reported by Stanislav Spassov.
-rw-r--r-- | usr.bin/tmux/format.c | 44 | ||||
-rw-r--r-- | usr.bin/tmux/window.c | 23 |
2 files changed, 56 insertions, 11 deletions
diff --git a/usr.bin/tmux/format.c b/usr.bin/tmux/format.c index 2b7fb1d7706..2325b210c7a 100644 --- a/usr.bin/tmux/format.c +++ b/usr.bin/tmux/format.c @@ -1,4 +1,4 @@ -/* $OpenBSD: format.c,v 1.224 2020/01/28 10:44:30 nicm Exp $ */ +/* $OpenBSD: format.c,v 1.225 2020/02/14 13:57:58 nicm Exp $ */ /* * Copyright (c) 2011 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -880,6 +880,44 @@ format_cb_pane_in_mode(struct format_tree *ft, struct format_entry *fe) xasprintf(&fe->value, "%u", n); } +/* Callback for pane_at_top. */ +static void +format_cb_pane_at_top(struct format_tree *ft, struct format_entry *fe) +{ + struct window_pane *wp = ft->wp; + struct window *w = wp->window; + int status, flag; + + if (wp == NULL) + return; + + status = options_get_number(w->options, "pane-border-status"); + if (status == PANE_STATUS_TOP) + flag = (wp->yoff == 1); + else + flag = (wp->yoff == 0); + xasprintf(&fe->value, "%d", flag); +} + +/* Callback for pane_at_bottom. */ +static void +format_cb_pane_at_bottom(struct format_tree *ft, struct format_entry *fe) +{ + struct window_pane *wp = ft->wp; + struct window *w = wp->window; + int status, flag; + + if (wp == NULL) + return; + + status = options_get_number(w->options, "pane-border-status"); + if (status == PANE_STATUS_BOTTOM) + flag = (wp->yoff + wp->sy == w->sy - 1); + else + flag = (wp->yoff + wp->sy == w->sy); + xasprintf(&fe->value, "%d", flag); +} + /* Callback for cursor_character. */ static void format_cb_cursor_character(struct format_tree *ft, struct format_entry *fe) @@ -2531,9 +2569,9 @@ format_defaults_pane(struct format_tree *ft, struct window_pane *wp) format_add(ft, "pane_right", "%u", wp->xoff + wp->sx - 1); format_add(ft, "pane_bottom", "%u", wp->yoff + wp->sy - 1); format_add(ft, "pane_at_left", "%d", wp->xoff == 0); - format_add(ft, "pane_at_top", "%d", wp->yoff == 0); + format_add_cb(ft, "pane_at_top", format_cb_pane_at_top); format_add(ft, "pane_at_right", "%d", wp->xoff + wp->sx == w->sx); - format_add(ft, "pane_at_bottom", "%d", wp->yoff + wp->sy == w->sy); + format_add_cb(ft, "pane_at_bottom", format_cb_pane_at_bottom); wme = TAILQ_FIRST(&wp->modes); if (wme != NULL) { diff --git a/usr.bin/tmux/window.c b/usr.bin/tmux/window.c index 03464301eec..7744bd0dd5b 100644 --- a/usr.bin/tmux/window.c +++ b/usr.bin/tmux/window.c @@ -1,4 +1,4 @@ -/* $OpenBSD: window.c,v 1.247 2020/01/13 07:51:55 nicm Exp $ */ +/* $OpenBSD: window.c,v 1.248 2020/02/14 13:57:58 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -541,31 +541,38 @@ window_get_active_at(struct window *w, u_int x, u_int y) struct window_pane * window_find_string(struct window *w, const char *s) { - u_int x, y; + u_int x, y, top = 0, bottom = w->sy - 1; + int status; x = w->sx / 2; y = w->sy / 2; + status = options_get_number(w->options, "pane-border-status"); + if (status == PANE_STATUS_TOP) + top++; + else if (status == PANE_STATUS_BOTTOM) + bottom--; + if (strcasecmp(s, "top") == 0) - y = 0; + y = top; else if (strcasecmp(s, "bottom") == 0) - y = w->sy - 1; + y = bottom; else if (strcasecmp(s, "left") == 0) x = 0; else if (strcasecmp(s, "right") == 0) x = w->sx - 1; else if (strcasecmp(s, "top-left") == 0) { x = 0; - y = 0; + y = top; } else if (strcasecmp(s, "top-right") == 0) { x = w->sx - 1; - y = 0; + y = top; } else if (strcasecmp(s, "bottom-left") == 0) { x = 0; - y = w->sy - 1; + y = bottom; } else if (strcasecmp(s, "bottom-right") == 0) { x = w->sx - 1; - y = w->sy - 1; + y = bottom; } else return (NULL); |