summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicholas Marriott <nicm@cvs.openbsd.org>2020-05-16 14:53:24 +0000
committerNicholas Marriott <nicm@cvs.openbsd.org>2020-05-16 14:53:24 +0000
commit15ce74dc20d25e97ca1265fcc7fd104f3b73ba9b (patch)
tree8a42c6b9c55a8bc1f77067309d31ce2347bfef28
parentcb11a38e6f545f0fd5bebea9b3d22f01dd95fbd9 (diff)
Use a grid cell not a style for the pane style.
-rw-r--r--usr.bin/tmux/format.c54
-rw-r--r--usr.bin/tmux/grid.c25
-rw-r--r--usr.bin/tmux/menu.c6
-rw-r--r--usr.bin/tmux/style.c31
-rw-r--r--usr.bin/tmux/tmux.h17
-rw-r--r--usr.bin/tmux/tty.c26
-rw-r--r--usr.bin/tmux/window.c20
7 files changed, 98 insertions, 81 deletions
diff --git a/usr.bin/tmux/format.c b/usr.bin/tmux/format.c
index 015d0638937..5ad22a7cb51 100644
--- a/usr.bin/tmux/format.c
+++ b/usr.bin/tmux/format.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: format.c,v 1.249 2020/05/16 14:30:17 nicm Exp $ */
+/* $OpenBSD: format.c,v 1.250 2020/05/16 14:53:23 nicm Exp $ */
/*
* Copyright (c) 2011 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -2479,25 +2479,59 @@ format_single(struct cmdq_item *item, const char *fmt, struct client *c,
struct format_tree *ft;
char *expanded;
- if (item != NULL)
- ft = format_create(cmdq_get_client(item), item, FORMAT_NONE, 0);
- else
- ft = format_create(NULL, item, FORMAT_NONE, 0);
- format_defaults(ft, c, s, wl, wp);
-
+ ft = format_create_defaults(item, c, s, wl, wp);
expanded = format_expand(ft, fmt);
format_free(ft);
return (expanded);
}
+/* Expand a single string using state. */
+char *
+format_single_from_state(struct cmdq_item *item, const char *fmt,
+ struct client *c, struct cmd_find_state *fs)
+{
+ return (format_single(item, fmt, c, fs->s, fs->wl, fs->wp));
+}
+
/* Expand a single string using target. */
char *
format_single_from_target(struct cmdq_item *item, const char *fmt)
{
- struct cmd_find_state *target = cmdq_get_target(item);
- struct client *tc = cmdq_get_target_client(item);
+ struct client *tc = cmdq_get_target_client(item);
+
+ return (format_single_from_state(item, fmt, tc, cmdq_get_target(item)));
+}
+
+/* Create and add defaults. */
+struct format_tree *
+format_create_defaults(struct cmdq_item *item, struct client *c,
+ struct session *s, struct winlink *wl, struct window_pane *wp)
+{
+ struct format_tree *ft;
+
+ if (item != NULL)
+ ft = format_create(cmdq_get_client(item), item, FORMAT_NONE, 0);
+ else
+ ft = format_create(NULL, item, FORMAT_NONE, 0);
+ format_defaults(ft, c, s, wl, wp);
+ return (ft);
+}
+
+/* Create and add defaults using state. */
+struct format_tree *
+format_create_from_state(struct cmdq_item *item, struct client *c,
+ struct cmd_find_state *fs)
+{
+ return (format_create_defaults(item, c, fs->s, fs->wl, fs->wp));
+}
+
+/* Create and add defaults using target. */
+struct format_tree *
+format_create_from_target(struct cmdq_item *item)
+{
+ struct client *tc = cmdq_get_target_client(item);
- return (format_single(item, fmt, tc, target->s, target->wl, target->wp));
+ return (format_create_from_state(item, tc, cmdq_get_target(item)));
}
/* Set defaults for any of arguments that are not NULL. */
diff --git a/usr.bin/tmux/grid.c b/usr.bin/tmux/grid.c
index 7ffd383a7df..1141e6c9220 100644
--- a/usr.bin/tmux/grid.c
+++ b/usr.bin/tmux/grid.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: grid.c,v 1.106 2020/04/15 12:59:20 nicm Exp $ */
+/* $OpenBSD: grid.c,v 1.107 2020/05/16 14:53:23 nicm Exp $ */
/*
* Copyright (c) 2008 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -211,19 +211,28 @@ grid_check_y(struct grid *gd, const char *from, u_int py)
return (0);
}
-/* Compare grid cells. Return 1 if equal, 0 if not. */
+/* Check if two styles are (visibly) the same. */
int
-grid_cells_equal(const struct grid_cell *gca, const struct grid_cell *gcb)
+grid_cells_look_equal(const struct grid_cell *gc1, const struct grid_cell *gc2)
{
- if (gca->fg != gcb->fg || gca->bg != gcb->bg)
+ if (gc1->fg != gc2->fg || gc1->bg != gc2->bg)
+ return (0);
+ if (gc1->attr != gc2->attr || gc1->flags != gc2->flags)
return (0);
- if (gca->attr != gcb->attr || gca->flags != gcb->flags)
+ return (1);
+}
+
+/* Compare grid cells. Return 1 if equal, 0 if not. */
+int
+grid_cells_equal(const struct grid_cell *gc1, const struct grid_cell *gc2)
+{
+ if (!grid_cells_look_equal(gc1, gc2))
return (0);
- if (gca->data.width != gcb->data.width)
+ if (gc1->data.width != gc2->data.width)
return (0);
- if (gca->data.size != gcb->data.size)
+ if (gc1->data.size != gc2->data.size)
return (0);
- return (memcmp(gca->data.data, gcb->data.data, gca->data.size) == 0);
+ return (memcmp(gc1->data.data, gc2->data.data, gc1->data.size) == 0);
}
/* Free one line. */
diff --git a/usr.bin/tmux/menu.c b/usr.bin/tmux/menu.c
index 1242550cd36..3922261b8d4 100644
--- a/usr.bin/tmux/menu.c
+++ b/usr.bin/tmux/menu.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: menu.c,v 1.23 2020/04/16 17:20:23 nicm Exp $ */
+/* $OpenBSD: menu.c,v 1.24 2020/05/16 14:53:23 nicm Exp $ */
/*
* Copyright (c) 2019 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -73,7 +73,7 @@ menu_add_item(struct menu *menu, const struct menu_item *item,
return;
if (fs != NULL)
- s = format_single(qitem, item->name, c, fs->s, fs->wl, fs->wp);
+ s = format_single_from_state(qitem, item->name, c, fs);
else
s = format_single(qitem, item->name, c, NULL, NULL, NULL);
if (*s == '\0') { /* no item if empty after format expanded */
@@ -91,7 +91,7 @@ menu_add_item(struct menu *menu, const struct menu_item *item,
cmd = item->command;
if (cmd != NULL) {
if (fs != NULL)
- s = format_single(qitem, cmd, c, fs->s, fs->wl, fs->wp);
+ s = format_single_from_state(qitem, cmd, c, fs);
else
s = format_single(qitem, cmd, c, NULL, NULL, NULL);
} else
diff --git a/usr.bin/tmux/style.c b/usr.bin/tmux/style.c
index 02da7c613b5..36cb44c48ff 100644
--- a/usr.bin/tmux/style.c
+++ b/usr.bin/tmux/style.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: style.c,v 1.25 2020/05/16 14:13:37 nicm Exp $ */
+/* $OpenBSD: style.c,v 1.26 2020/05/16 14:53:23 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -59,6 +59,7 @@ style_parse(struct style *sy, const struct grid_cell *base, const char *in)
return (0);
style_copy(&saved, sy);
+ log_debug("%s: %s", __func__, in);
do {
while (*in != '\0' && strchr(delimiters, *in) != NULL)
in++;
@@ -71,6 +72,7 @@ style_parse(struct style *sy, const struct grid_cell *base, const char *in)
memcpy(tmp, in, end);
tmp[end] = '\0';
+ log_debug("%s: %s", __func__, tmp);
if (strcasecmp(tmp, "default") == 0) {
sy->gc.fg = base->fg;
sy->gc.bg = base->bg;
@@ -285,30 +287,3 @@ style_copy(struct style *dst, struct style *src)
{
memcpy(dst, src, sizeof *dst);
}
-
-/* Check if two styles are (visibly) the same. */
-int
-style_equal(struct style *sy1, struct style *sy2)
-{
- struct grid_cell *gc1 = &sy1->gc;
- struct grid_cell *gc2 = &sy2->gc;
-
- if (gc1->fg != gc2->fg)
- return (0);
- if (gc1->bg != gc2->bg)
- return (0);
- if ((gc1->attr & STYLE_ATTR_MASK) != (gc2->attr & STYLE_ATTR_MASK))
- return (0);
- if (sy1->fill != sy2->fill)
- return (0);
- if (sy1->align != sy2->align)
- return (0);
- return (1);
-}
-
-/* Is this style default? */
-int
-style_is_default(struct style *sy)
-{
- return (style_equal(sy, &style_default));
-}
diff --git a/usr.bin/tmux/tmux.h b/usr.bin/tmux/tmux.h
index a78409b0058..7aaaf3c622b 100644
--- a/usr.bin/tmux/tmux.h
+++ b/usr.bin/tmux/tmux.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: tmux.h,v 1.1023 2020/05/16 14:49:50 nicm Exp $ */
+/* $OpenBSD: tmux.h,v 1.1024 2020/05/16 14:53:23 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -928,8 +928,8 @@ struct window_pane {
struct input_ctx *ictx;
- struct style cached_style;
- struct style cached_active_style;
+ struct grid_cell cached_gc;
+ struct grid_cell cached_active_gc;
int *palette;
int pipe_fd;
@@ -1825,7 +1825,14 @@ char *format_expand(struct format_tree *, const char *);
char *format_single(struct cmdq_item *, const char *,
struct client *, struct session *, struct winlink *,
struct window_pane *);
+char *format_single_from_state(struct cmdq_item *, const char *,
+ struct client *, struct cmd_find_state *);
char *format_single_from_target(struct cmdq_item *, const char *);
+struct format_tree *format_create_defaults(struct cmdq_item *, struct client *,
+ struct session *, struct winlink *, struct window_pane *);
+struct format_tree *format_create_from_state(struct cmdq_item *,
+ struct client *, struct cmd_find_state *);
+struct format_tree *format_create_from_target(struct cmdq_item *);
void format_defaults(struct format_tree *, struct client *,
struct session *, struct winlink *, struct window_pane *);
void format_defaults_window(struct format_tree *, struct window *);
@@ -2356,6 +2363,8 @@ int attributes_fromstring(const char *);
extern const struct grid_cell grid_default_cell;
void grid_empty_line(struct grid *, u_int, u_int);
int grid_cells_equal(const struct grid_cell *, const struct grid_cell *);
+int grid_cells_look_equal(const struct grid_cell *,
+ const struct grid_cell *);
struct grid *grid_create(u_int, u_int, u_int);
void grid_destroy(struct grid *);
int grid_compare(struct grid *, struct grid *);
@@ -2811,10 +2820,8 @@ int style_parse(struct style *,const struct grid_cell *,
const char *style_tostring(struct style *);
void style_apply(struct grid_cell *, struct options *,
const char *);
-int style_equal(struct style *, struct style *);
void style_set(struct style *, const struct grid_cell *);
void style_copy(struct style *, struct style *);
-int style_is_default(struct style *);
/* spawn.c */
struct winlink *spawn_window(struct spawn_context *, char **);
diff --git a/usr.bin/tmux/tty.c b/usr.bin/tmux/tty.c
index 6ae908f4fb6..6c3735fd86b 100644
--- a/usr.bin/tmux/tty.c
+++ b/usr.bin/tmux/tty.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: tty.c,v 1.369 2020/05/16 14:46:14 nicm Exp $ */
+/* $OpenBSD: tty.c,v 1.370 2020/05/16 14:53:23 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -2690,27 +2690,19 @@ static void
tty_default_colours(struct grid_cell *gc, struct window_pane *wp)
{
struct options *oo = wp->options;
- struct style *style, *active_style;
int c;
if (wp->flags & PANE_STYLECHANGED) {
wp->flags &= ~PANE_STYLECHANGED;
-
- active_style = options_get_style(oo, "window-active-style");
- style = options_get_style(oo, "window-style");
-
- style_copy(&wp->cached_active_style, active_style);
- style_copy(&wp->cached_style, style);
- } else {
- active_style = &wp->cached_active_style;
- style = &wp->cached_style;
+ style_apply(&wp->cached_active_gc, oo, "window-active-style");
+ style_apply(&wp->cached_gc, oo, "window-style");
}
if (gc->fg == 8) {
- if (wp == wp->window->active && active_style->gc.fg != 8)
- gc->fg = active_style->gc.fg;
+ if (wp == wp->window->active && wp->cached_active_gc.fg != 8)
+ gc->fg = wp->cached_active_gc.fg;
else
- gc->fg = style->gc.fg;
+ gc->fg = wp->cached_gc.fg;
if (gc->fg != 8) {
c = window_pane_get_palette(wp, gc->fg);
@@ -2720,10 +2712,10 @@ tty_default_colours(struct grid_cell *gc, struct window_pane *wp)
}
if (gc->bg == 8) {
- if (wp == wp->window->active && active_style->gc.bg != 8)
- gc->bg = active_style->gc.bg;
+ if (wp == wp->window->active && wp->cached_active_gc.bg != 8)
+ gc->bg = wp->cached_active_gc.bg;
else
- gc->bg = style->gc.bg;
+ gc->bg = wp->cached_gc.bg;
if (gc->bg != 8) {
c = window_pane_get_palette(wp, gc->bg);
diff --git a/usr.bin/tmux/window.c b/usr.bin/tmux/window.c
index 9e14d527569..2e4506ab8eb 100644
--- a/usr.bin/tmux/window.c
+++ b/usr.bin/tmux/window.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: window.c,v 1.257 2020/04/13 20:51:57 nicm Exp $ */
+/* $OpenBSD: window.c,v 1.258 2020/05/16 14:53:23 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -488,8 +488,8 @@ window_set_active_pane(struct window *w, struct window_pane *wp, int notify)
void
window_redraw_active_switch(struct window *w, struct window_pane *wp)
{
- struct style *sy1, *sy2;
- int c1, c2;
+ struct grid_cell *gc1, *gc2;
+ int c1, c2;
if (wp == w->active)
return;
@@ -499,18 +499,18 @@ window_redraw_active_switch(struct window *w, struct window_pane *wp)
* If the active and inactive styles or palettes are different,
* need to redraw the panes.
*/
- sy1 = &wp->cached_style;
- sy2 = &wp->cached_active_style;
- if (!style_equal(sy1, sy2))
+ gc1 = &wp->cached_gc;
+ gc2 = &wp->cached_active_gc;
+ if (!grid_cells_look_equal(gc1, gc2))
wp->flags |= PANE_REDRAW;
else {
- c1 = window_pane_get_palette(wp, sy1->gc.fg);
- c2 = window_pane_get_palette(wp, sy2->gc.fg);
+ c1 = window_pane_get_palette(wp, gc1->fg);
+ c2 = window_pane_get_palette(wp, gc2->fg);
if (c1 != c2)
wp->flags |= PANE_REDRAW;
else {
- c1 = window_pane_get_palette(wp, sy1->gc.bg);
- c2 = window_pane_get_palette(wp, sy2->gc.bg);
+ c1 = window_pane_get_palette(wp, gc1->bg);
+ c2 = window_pane_get_palette(wp, gc2->bg);
if (c1 != c2)
wp->flags |= PANE_REDRAW;
}