Use a grid cell not a style for the pane style.

pull/2195/head
Nicholas Marriott 2020-04-27 15:15:12 +01:00
parent c30e765c7b
commit 79b4d83952
5 changed files with 39 additions and 63 deletions

23
grid.c
View File

@ -211,19 +211,28 @@ grid_check_y(struct grid *gd, const char *from, u_int py)
return (0);
}
/* Check if two styles are (visibly) the same. */
int
grid_cells_look_equal(const struct grid_cell *gc1, const struct grid_cell *gc2)
{
if (gc1->fg != gc2->fg || gc1->bg != gc2->bg)
return (0);
if (gc1->attr != gc2->attr || gc1->flags != gc2->flags)
return (0);
return (1);
}
/* Compare grid cells. Return 1 if equal, 0 if not. */
int
grid_cells_equal(const struct grid_cell *gca, const struct grid_cell *gcb)
grid_cells_equal(const struct grid_cell *gc1, const struct grid_cell *gc2)
{
if (gca->fg != gcb->fg || gca->bg != gcb->bg)
if (!grid_cells_look_equal(gc1, gc2))
return (0);
if (gca->attr != gcb->attr || gca->flags != gcb->flags)
if (gc1->data.width != gc2->data.width)
return (0);
if (gca->data.width != gcb->data.width)
if (gc1->data.size != gc2->data.size)
return (0);
if (gca->data.size != gcb->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. */

29
style.c
View File

@ -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));
}

8
tmux.h
View File

@ -930,8 +930,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;
@ -2365,6 +2365,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 *);
@ -2821,10 +2823,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 **);

24
tty.c
View File

@ -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);

View File

@ -495,8 +495,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;
@ -506,18 +506,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;
}