From 7e4f8b45b64b0cbe889c5846806038c4c45c36e8 Mon Sep 17 00:00:00 2001 From: Nicholas Marriott Date: Sun, 3 Jan 2010 12:51:05 +0000 Subject: [PATCH] Options to set the colour of the pane borders, with different colours for the active pane. --- cmd-down-pane.c | 1 + cmd-select-pane.c | 1 + cmd-set-option.c | 4 ++ cmd-up-pane.c | 1 + screen-redraw.c | 97 +++++++++++++++++++++++++++++++---------------- server-client.c | 11 ++++-- server-fn.c | 15 ++++++++ tmux.1 | 6 +++ tmux.c | 4 ++ tmux.h | 4 +- 10 files changed, 106 insertions(+), 38 deletions(-) diff --git a/cmd-down-pane.c b/cmd-down-pane.c index a0f771eb..a065a6e9 100644 --- a/cmd-down-pane.c +++ b/cmd-down-pane.c @@ -54,6 +54,7 @@ cmd_down_pane_exec(struct cmd *self, struct cmd_ctx *ctx) w->active = TAILQ_FIRST(&w->panes); } while (!window_pane_visible(w->active)); server_status_window(wl->window); + server_redraw_window_borders(wl->window); return (0); } diff --git a/cmd-select-pane.c b/cmd-select-pane.c index 890cebc6..956ed912 100644 --- a/cmd-select-pane.c +++ b/cmd-select-pane.c @@ -53,6 +53,7 @@ cmd_select_pane_exec(struct cmd *self, struct cmd_ctx *ctx) } window_set_active_pane(wl->window, wp); server_status_window(wl->window); + server_redraw_window_borders(wl->window); return (0); } diff --git a/cmd-set-option.c b/cmd-set-option.c index b445e537..06535e0d 100644 --- a/cmd-set-option.c +++ b/cmd-set-option.c @@ -99,6 +99,10 @@ const struct set_option_entry set_session_option_table[] = { { "message-fg", SET_OPTION_COLOUR, 0, 0, NULL }, { "message-limit", SET_OPTION_NUMBER, 0, INT_MAX, NULL }, { "mouse-select-pane", SET_OPTION_FLAG, 0, 0, NULL }, + { "pane-active-border-bg", SET_OPTION_COLOUR, 0, 0, NULL }, + { "pane-active-border-fg", SET_OPTION_COLOUR, 0, 0, NULL }, + { "pane-border-bg", SET_OPTION_COLOUR, 0, 0, NULL }, + { "pane-border-fg", SET_OPTION_COLOUR, 0, 0, NULL }, { "prefix", SET_OPTION_KEYS, 0, 0, NULL }, { "repeat-time", SET_OPTION_NUMBER, 0, SHRT_MAX, NULL }, { "set-remain-on-exit", SET_OPTION_FLAG, 0, 0, NULL }, diff --git a/cmd-up-pane.c b/cmd-up-pane.c index 49ab49a7..62fe76be 100644 --- a/cmd-up-pane.c +++ b/cmd-up-pane.c @@ -54,6 +54,7 @@ cmd_up_pane_exec(struct cmd *self, struct cmd_ctx *ctx) w->active = TAILQ_LAST(&w->panes, window_panes); } while (!window_pane_visible(w->active)); server_status_window(wl->window); + server_redraw_window_borders(wl->window); return (0); } diff --git a/screen-redraw.c b/screen-redraw.c index 03dd52db..83eafa62 100644 --- a/screen-redraw.c +++ b/screen-redraw.c @@ -22,6 +22,7 @@ #include "tmux.h" +int screen_redraw_cell_border1(struct window_pane *, u_int, u_int); int screen_redraw_cell_border(struct client *, u_int, u_int); int screen_redraw_check_cell(struct client *, u_int, u_int); void screen_redraw_draw_number(struct client *, struct window_pane *); @@ -40,40 +41,49 @@ void screen_redraw_draw_number(struct client *, struct window_pane *); #define CELL_JOIN 11 #define CELL_OUTSIDE 12 +/* Check if cell is on the border of a particular pane. */ +int +screen_redraw_cell_border1(struct window_pane *wp, u_int px, u_int py) +{ + /* Inside pane. */ + if (px >= wp->xoff && px < wp->xoff + wp->sx && + py >= wp->yoff && py < wp->yoff + wp->sy) + return (0); + + /* Left/right borders. */ + if ((wp->yoff == 0 || py >= wp->yoff - 1) && py <= wp->yoff + wp->sy) { + if (wp->xoff != 0 && px == wp->xoff - 1) + return (1); + if (px == wp->xoff + wp->sx) + return (1); + } + + /* Top/bottom borders. */ + if ((wp->xoff == 0 || px >= wp->xoff - 1) && px <= wp->xoff + wp->sx) { + if (wp->yoff != 0 && py == wp->yoff - 1) + return (1); + if (py == wp->yoff + wp->sy) + return (1); + } + + /* Outside pane. */ + return (-1); +} + /* Check if a cell is on the pane border. */ int screen_redraw_cell_border(struct client *c, u_int px, u_int py) { struct window *w = c->session->curw->window; struct window_pane *wp; + int retval; /* Check all the panes. */ TAILQ_FOREACH(wp, &w->panes, entry) { if (!window_pane_visible(wp)) continue; - - /* Inside pane. */ - if (px >= wp->xoff && px < wp->xoff + wp->sx && - py >= wp->yoff && py < wp->yoff + wp->sy) - return (0); - - /* Left/right borders. */ - if ((wp->yoff == 0 || py >= wp->yoff - 1) && - py <= wp->yoff + wp->sy) { - if (wp->xoff != 0 && px == wp->xoff - 1) - return (1); - if (px == wp->xoff + wp->sx) - return (1); - } - - /* Top/bottom borders. */ - if ((wp->xoff == 0 || px >= wp->xoff - 1) && - px <= wp->xoff + wp->sx) { - if (wp->yoff != 0 && py == wp->yoff - 1) - return (1); - if (py == wp->yoff + wp->sy) - return (1); - } + if ((retval = screen_redraw_cell_border1(wp, px, py)) != -1) + return (retval); } return (0); @@ -155,13 +165,14 @@ screen_redraw_check_cell(struct client *c, u_int px, u_int py) /* Redraw entire screen. */ void -screen_redraw_screen(struct client *c, int status_only) +screen_redraw_screen(struct client *c, int status_only, int borders_only) { struct window *w = c->session->curw->window; struct tty *tty = &c->tty; struct window_pane *wp; + struct grid_cell active_gc, other_gc; u_int i, j, type; - int status; + int status, fg, bg; const u_char *base, *ptr; u_char ch, border[20]; @@ -178,8 +189,20 @@ screen_redraw_screen(struct client *c, int status_only) return; } + /* Set up pane border attributes. */ + memcpy(&other_gc, &grid_default_cell, sizeof other_gc); + memcpy(&active_gc, &grid_default_cell, sizeof active_gc); + active_gc.data = other_gc.data = 'x'; /* not space */ + fg = options_get_number(&c->session->options, "pane-border-fg"); + colour_set_fg(&other_gc, fg); + bg = options_get_number(&c->session->options, "pane-border-bg"); + colour_set_bg(&other_gc, bg); + fg = options_get_number(&c->session->options, "pane-active-border-fg"); + colour_set_fg(&active_gc, fg); + bg = options_get_number(&c->session->options, "pane-active-border-bg"); + colour_set_bg(&active_gc, bg); + /* Draw background and borders. */ - tty_reset(tty); strlcpy(border, " |-....--||+.", sizeof border); if (tty_term_has(tty->term, TTYC_ACSC)) { base = " xqlkmjwvtun~"; @@ -187,22 +210,30 @@ screen_redraw_screen(struct client *c, int status_only) if ((ch = tty_get_acs(tty, *ptr)) != '\0') border[ptr - base] = ch; } - tty_putcode(tty, TTYC_SMACS); + other_gc.attr |= GRID_ATTR_CHARSET; + active_gc.attr |= GRID_ATTR_CHARSET; } for (j = 0; j < tty->sy - status; j++) { if (status_only && j != tty->sy - 1) continue; for (i = 0; i < tty->sx; i++) { type = screen_redraw_check_cell(c, i, j); - if (type != CELL_INSIDE) { - tty_cursor(tty, i, j); - tty_putc(tty, border[type]); - } + if (type == CELL_INSIDE) + continue; + if (screen_redraw_cell_border1(w->active, i, j) == 1) + tty_attributes(tty, &active_gc); + else + tty_attributes(tty, &other_gc); + tty_cursor(tty, i, j); + tty_putc(tty, border[type]); } } - tty_putcode(tty, TTYC_RMACS); - /* Draw the panes. */ + /* If only drawing borders, that's it. */ + if (borders_only) + return; + + /* Draw the panes, if necessary. */ TAILQ_FOREACH(wp, &w->panes, entry) { if (!window_pane_visible(wp)) continue; diff --git a/server-client.c b/server-client.c index 02edabc6..c321a4c2 100644 --- a/server-client.c +++ b/server-client.c @@ -463,8 +463,8 @@ server_client_check_redraw(struct client *c) } if (c->flags & CLIENT_REDRAW) { - screen_redraw_screen(c, 0); - c->flags &= ~CLIENT_STATUS; + screen_redraw_screen(c, 0, 0); + c->flags &= ~(CLIENT_STATUS|CLIENT_BORDERS); } else { TAILQ_FOREACH(wp, &c->session->curw->window->panes, entry) { if (wp->flags & PANE_REDRAW) @@ -472,12 +472,15 @@ server_client_check_redraw(struct client *c) } } + if (c->flags & CLIENT_BORDERS) + screen_redraw_screen(c, 0, 1); + if (c->flags & CLIENT_STATUS) - screen_redraw_screen(c, 1); + screen_redraw_screen(c, 1, 0); c->tty.flags |= flags; - c->flags &= ~(CLIENT_REDRAW|CLIENT_STATUS); + c->flags &= ~(CLIENT_REDRAW|CLIENT_STATUS|CLIENT_BORDERS); } /* Set client title. */ diff --git a/server-fn.c b/server-fn.c index df6aa134..ce5e518d 100644 --- a/server-fn.c +++ b/server-fn.c @@ -164,6 +164,21 @@ server_redraw_window(struct window *w) w->flags |= WINDOW_REDRAW; } +void +server_redraw_window_borders(struct window *w) +{ + struct client *c; + u_int i; + + for (i = 0; i < ARRAY_LENGTH(&clients); i++) { + c = ARRAY_ITEM(&clients, i); + if (c == NULL || c->session == NULL) + continue; + if (c->session->curw->window == w) + c->flags |= CLIENT_BORDERS; + } +} + void server_status_window(struct window *w) { diff --git a/tmux.1 b/tmux.1 index 79e65af6..41b28d46 100644 --- a/tmux.1 +++ b/tmux.1 @@ -1457,6 +1457,12 @@ If on, captures the mouse and when a window is split into multiple panes the mouse may be used to select the current pane. The mouse click is also passed through to the application as normal. +.It Ic pane-border-fg Ar colour +.It Ic pane-border-bg Ar colour +Set the pane border colour for panes aside from the active pane. +.It Ic pane-active-border-fg Ar colour +.It Ic pane-active-border-bg Ar colour +Set the pane border colour for the currently active pane. .It Ic prefix Ar keys Set the keys accepted as a prefix key. .Ar keys diff --git a/tmux.c b/tmux.c index 0e080306..24aa24f6 100644 --- a/tmux.c +++ b/tmux.c @@ -339,6 +339,10 @@ main(int argc, char **argv) options_set_number(so, "message-fg", 0); options_set_number(so, "message-limit", 20); options_set_number(so, "mouse-select-pane", 0); + options_set_number(so, "pane-active-border-bg", 2); + options_set_number(so, "pane-active-border-fg", 8); + options_set_number(so, "pane-border-bg", 8); + options_set_number(so, "pane-border-fg", 8); options_set_number(so, "repeat-time", 500); options_set_number(so, "set-remain-on-exit", 0); options_set_number(so, "set-titles", 0); diff --git a/tmux.h b/tmux.h index 8ffdf06a..56ef4aac 100644 --- a/tmux.h +++ b/tmux.h @@ -1083,6 +1083,7 @@ struct client { #define CLIENT_BAD 0x80 #define CLIENT_IDENTIFY 0x100 #define CLIENT_DEAD 0x200 +#define CLIENT_BORDERS 0x400 int flags; struct event identify_timer; @@ -1589,6 +1590,7 @@ void server_redraw_session_group(struct session *); void server_status_session(struct session *); void server_status_session_group(struct session *); void server_redraw_window(struct window *); +void server_redraw_window_borders(struct window *); void server_status_window(struct window *); void server_lock(void); void server_lock_session(struct session *); @@ -1749,7 +1751,7 @@ void screen_write_cell(struct screen_write_ctx *, const struct grid_cell *, const struct utf8_data *); /* screen-redraw.c */ -void screen_redraw_screen(struct client *, int); +void screen_redraw_screen(struct client *, int, int); void screen_redraw_pane(struct client *, struct window_pane *); /* screen.c */