summaryrefslogtreecommitdiff
path: root/usr.bin
diff options
context:
space:
mode:
authorNicholas Marriott <nicm@cvs.openbsd.org>2015-09-14 11:34:51 +0000
committerNicholas Marriott <nicm@cvs.openbsd.org>2015-09-14 11:34:51 +0000
commitef2c1ed4d53bc2ddf7c4eafc7eb751f9488a67ea (patch)
tree5136f39e3ed5aff62927aa68acb6688d4a81dd0e /usr.bin
parent9cebeab46d8f14874f8f2efc7e91165c232e2056 (diff)
When the active pane changes, redraw panes if the style has
changed. From Cam Hutchison.
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/tmux/cmd-select-pane.c30
-rw-r--r--usr.bin/tmux/style.c14
-rw-r--r--usr.bin/tmux/tmux.h6
-rw-r--r--usr.bin/tmux/window.c26
4 files changed, 61 insertions, 15 deletions
diff --git a/usr.bin/tmux/cmd-select-pane.c b/usr.bin/tmux/cmd-select-pane.c
index 248e5ace8e4..dcc7deba049 100644
--- a/usr.bin/tmux/cmd-select-pane.c
+++ b/usr.bin/tmux/cmd-select-pane.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cmd-select-pane.c,v 1.24 2015/06/04 11:43:51 nicm Exp $ */
+/* $OpenBSD: cmd-select-pane.c,v 1.25 2015/09/14 11:34:50 nicm Exp $ */
/*
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -47,6 +47,7 @@ cmd_select_pane_exec(struct cmd *self, struct cmd_q *cmdq)
{
struct args *args = self->args;
struct winlink *wl;
+ struct window *w;
struct session *s;
struct window_pane *wp, *lastwp, *markedwp;
const char *style;
@@ -55,21 +56,24 @@ cmd_select_pane_exec(struct cmd *self, struct cmd_q *cmdq)
wl = cmd_find_window(cmdq, args_get(args, 't'), NULL);
if (wl == NULL)
return (CMD_RETURN_ERROR);
+ w = wl->window;
- if (wl->window->last == NULL) {
+ if (w->last == NULL) {
cmdq_error(cmdq, "no last pane");
return (CMD_RETURN_ERROR);
}
if (args_has(self->args, 'e'))
- wl->window->last->flags &= ~PANE_INPUTOFF;
+ w->last->flags &= ~PANE_INPUTOFF;
else if (args_has(self->args, 'd'))
- wl->window->last->flags |= PANE_INPUTOFF;
+ w->last->flags |= PANE_INPUTOFF;
else {
- server_unzoom_window(wl->window);
- window_set_active_pane(wl->window, wl->window->last);
- server_status_window(wl->window);
- server_redraw_window_borders(wl->window);
+ server_unzoom_window(w);
+ window_redraw_active_switch(w, w->last);
+ if (window_set_active_pane(w, w->last)) {
+ server_status_window(w);
+ server_redraw_window_borders(w);
+ }
}
return (CMD_RETURN_NORMAL);
@@ -77,6 +81,7 @@ cmd_select_pane_exec(struct cmd *self, struct cmd_q *cmdq)
if ((wl = cmd_find_pane(cmdq, args_get(args, 't'), &s, &wp)) == NULL)
return (CMD_RETURN_ERROR);
+ w = wl->window;
if (args_has(args, 'm') || args_has(args, 'M')) {
if (args_has(args, 'm') && !window_pane_visible(wp))
@@ -135,16 +140,17 @@ cmd_select_pane_exec(struct cmd *self, struct cmd_q *cmdq)
return (CMD_RETURN_NORMAL);
}
- if (wp == wl->window->active)
+ if (wp == w->active)
return (CMD_RETURN_NORMAL);
server_unzoom_window(wp->window);
if (!window_pane_visible(wp)) {
cmdq_error(cmdq, "pane not visible");
return (CMD_RETURN_ERROR);
}
- if (window_set_active_pane(wl->window, wp)) {
- server_status_window(wl->window);
- server_redraw_window_borders(wl->window);
+ window_redraw_active_switch(w, wp);
+ if (window_set_active_pane(w, wp)) {
+ server_status_window(w);
+ server_redraw_window_borders(w);
}
return (CMD_RETURN_NORMAL);
diff --git a/usr.bin/tmux/style.c b/usr.bin/tmux/style.c
index bf7ca6be253..7828a8179af 100644
--- a/usr.bin/tmux/style.c
+++ b/usr.bin/tmux/style.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: style.c,v 1.7 2015/05/07 11:42:56 nicm Exp $ */
+/* $OpenBSD: style.c,v 1.8 2015/09/14 11:34:50 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -252,3 +252,15 @@ style_apply_update(struct grid_cell *gc, struct options *oo, const char *name)
if (gcp->attr != 0)
gc->attr |= gcp->attr;
}
+
+/* Check if two styles are the same. */
+int
+style_equal(const struct grid_cell *gc1, const struct grid_cell *gc2)
+{
+ return gc1->fg == gc2->fg &&
+ gc1->bg == gc2->bg &&
+ (gc1->flags & ~GRID_FLAG_PADDING) ==
+ (gc2->flags & ~GRID_FLAG_PADDING) &&
+ (gc1->attr & ~GRID_ATTR_CHARSET) ==
+ (gc2->attr & ~GRID_ATTR_CHARSET);
+}
diff --git a/usr.bin/tmux/tmux.h b/usr.bin/tmux/tmux.h
index b14b3113542..d9efaa19422 100644
--- a/usr.bin/tmux/tmux.h
+++ b/usr.bin/tmux/tmux.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: tmux.h,v 1.558 2015/09/14 10:25:52 nicm Exp $ */
+/* $OpenBSD: tmux.h,v 1.559 2015/09/14 11:34:50 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -1983,6 +1983,8 @@ struct window_pane *window_get_active_at(struct window *, u_int, u_int);
struct window_pane *window_find_string(struct window *, const char *);
int window_has_pane(struct window *, struct window_pane *);
int window_set_active_pane(struct window *, struct window_pane *);
+void window_redraw_active_switch(struct window *,
+ struct window_pane *);
struct window_pane *window_add_pane(struct window *, u_int);
void window_resize(struct window *, u_int, u_int);
int window_zoom(struct window_pane *);
@@ -2210,5 +2212,7 @@ void style_apply(struct grid_cell *, struct options *,
const char *);
void style_apply_update(struct grid_cell *, struct options *,
const char *);
+int style_equal(const struct grid_cell *,
+ const struct grid_cell *);
#endif /* TMUX_H */
diff --git a/usr.bin/tmux/window.c b/usr.bin/tmux/window.c
index fa791d93276..242d3ec61cf 100644
--- a/usr.bin/tmux/window.c
+++ b/usr.bin/tmux/window.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: window.c,v 1.144 2015/08/29 23:55:55 nicm Exp $ */
+/* $OpenBSD: window.c,v 1.145 2015/09/14 11:34:50 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -423,6 +423,30 @@ window_set_active_pane(struct window *w, struct window_pane *wp)
return (1);
}
+void
+window_redraw_active_switch(struct window *w, struct window_pane *wp)
+{
+ const struct grid_cell *agc, *wgc;
+
+ if (wp == w->active)
+ return;
+
+ /*
+ * If window-style and window-active-style are the same, we don't need
+ * to redraw panes when switching active panes. Otherwise, if the
+ * active or inactive pane do not have a custom style, they will need
+ * to be redrawn.
+ */
+ agc = options_get_style(&w->options, "window-active-style");
+ wgc = options_get_style(&w->options, "window-style");
+ if (style_equal(agc, wgc))
+ return;
+ if (style_equal(&grid_default_cell, &w->active->colgc))
+ w->active->flags |= PANE_REDRAW;
+ if (style_equal(&grid_default_cell, &wp->colgc))
+ wp->flags |= PANE_REDRAW;
+}
+
struct window_pane *
window_get_active_at(struct window *w, u_int x, u_int y)
{