Add a wrapper (struct style) around styles rather than using the

grid_cell directly. There will be some non-cell members soon.
This commit is contained in:
nicm 2019-03-14 09:53:52 +00:00
parent 1e9f8a3523
commit 13f9a061ac
8 changed files with 194 additions and 153 deletions

View File

@ -90,6 +90,7 @@ cmd_select_pane_exec(struct cmd *self, struct cmdq_item *item)
struct window *w = wl->window; struct window *w = wl->window;
struct session *s = item->target.s; struct session *s = item->target.s;
struct window_pane *wp = item->target.wp, *lastwp, *markedwp; struct window_pane *wp = item->target.wp, *lastwp, *markedwp;
struct style *sy = &wp->style;
char *pane_title; char *pane_title;
const char *style; const char *style;
@ -142,19 +143,16 @@ cmd_select_pane_exec(struct cmd *self, struct cmdq_item *item)
} }
if (args_has(self->args, 'P') || args_has(self->args, 'g')) { if (args_has(self->args, 'P') || args_has(self->args, 'g')) {
if (args_has(args, 'P')) { if ((style = args_get(args, 'P')) != NULL) {
style = args_get(args, 'P'); style_set(sy, &grid_default_cell);
memcpy(&wp->colgc, &grid_default_cell, if (style_parse(sy, &grid_default_cell, style) == -1) {
sizeof wp->colgc);
if (style_parse(&grid_default_cell, &wp->colgc,
style) == -1) {
cmdq_error(item, "bad style: %s", style); cmdq_error(item, "bad style: %s", style);
return (CMD_RETURN_ERROR); return (CMD_RETURN_ERROR);
} }
wp->flags |= PANE_REDRAW; wp->flags |= PANE_REDRAW;
} }
if (args_has(self->args, 'g')) if (args_has(self->args, 'g'))
cmdq_print(item, "%s", style_tostring(&wp->colgc)); cmdq_print(item, "%s", style_tostring(sy));
return (CMD_RETURN_NORMAL); return (CMD_RETURN_NORMAL);
} }

View File

@ -2340,7 +2340,7 @@ input_osc_10(struct input_ctx *ictx, const char *p)
if (sscanf(p, "rgb:%2x/%2x/%2x", &r, &g, &b) != 3) if (sscanf(p, "rgb:%2x/%2x/%2x", &r, &g, &b) != 3)
goto bad; goto bad;
wp->colgc.fg = colour_join_rgb(r, g, b); wp->style.gc.fg = colour_join_rgb(r, g, b);
wp->flags |= PANE_REDRAW; wp->flags |= PANE_REDRAW;
return; return;
@ -2359,7 +2359,7 @@ input_osc_11(struct input_ctx *ictx, const char *p)
if (sscanf(p, "rgb:%2x/%2x/%2x", &r, &g, &b) != 3) if (sscanf(p, "rgb:%2x/%2x/%2x", &r, &g, &b) != 3)
goto bad; goto bad;
wp->colgc.bg = colour_join_rgb(r, g, b); wp->style.gc.bg = colour_join_rgb(r, g, b);
wp->flags |= PANE_REDRAW; wp->flags |= PANE_REDRAW;
return; return;

View File

@ -39,7 +39,7 @@ struct options_entry {
union { union {
char *string; char *string;
long long number; long long number;
struct grid_cell style; struct style style;
struct { struct {
const char **array; const char **array;
u_int arraysize; u_int arraysize;
@ -177,8 +177,8 @@ options_default(struct options *oo, const struct options_table_entry *oe)
else if (oe->type == OPTIONS_TABLE_STRING) else if (oe->type == OPTIONS_TABLE_STRING)
o->string = xstrdup(oe->default_str); o->string = xstrdup(oe->default_str);
else if (oe->type == OPTIONS_TABLE_STYLE) { else if (oe->type == OPTIONS_TABLE_STYLE) {
memcpy(&o->style, &grid_default_cell, sizeof o->style); style_set(&o->style, &grid_default_cell);
style_parse(&grid_default_cell, &o->style, oe->default_str); style_parse(&o->style, &grid_default_cell, oe->default_str);
} else } else
o->number = oe->default_num; o->number = oe->default_num;
return (o); return (o);
@ -504,7 +504,7 @@ options_get_number(struct options *oo, const char *name)
return (o->number); return (o->number);
} }
const struct grid_cell * struct style *
options_get_style(struct options *oo, const char *name) options_get_style(struct options *oo, const char *name)
{ {
struct options_entry *o; struct options_entry *o;
@ -576,17 +576,17 @@ options_set_style(struct options *oo, const char *name, int append,
const char *value) const char *value)
{ {
struct options_entry *o; struct options_entry *o;
struct grid_cell gc; struct style sy;
if (*name == '@') if (*name == '@')
fatalx("user option %s must be a string", name); fatalx("user option %s must be a string", name);
o = options_get_only(oo, name); o = options_get_only(oo, name);
if (o != NULL && append && OPTIONS_IS_STYLE(o)) if (o != NULL && append && OPTIONS_IS_STYLE(o))
memcpy(&gc, &o->style, sizeof gc); style_copy(&sy, &o->style);
else else
memcpy(&gc, &grid_default_cell, sizeof gc); style_set(&sy, &grid_default_cell);
if (style_parse(&grid_default_cell, &gc, value) == -1) if (style_parse(&sy, &grid_default_cell, value) == -1)
return (NULL); return (NULL);
if (o == NULL) { if (o == NULL) {
o = options_default(oo, options_parent_table_entry(oo, name)); o = options_default(oo, options_parent_table_entry(oo, name));
@ -596,7 +596,7 @@ options_set_style(struct options *oo, const char *name, int append,
if (!OPTIONS_IS_STYLE(o)) if (!OPTIONS_IS_STYLE(o))
fatalx("option %s is not a style", name); fatalx("option %s is not a style", name);
memcpy(&o->style, &gc, sizeof o->style); style_copy(&o->style, &sy);
return (o); return (o);
} }
@ -657,11 +657,11 @@ options_style_update_new(struct options *oo, struct options_entry *o)
new = options_set_style(oo, newname, 0, "default"); new = options_set_style(oo, newname, 0, "default");
if (strstr(o->name, "-bg") != NULL) if (strstr(o->name, "-bg") != NULL)
new->style.bg = o->number; new->style.gc.bg = o->number;
else if (strstr(o->name, "-fg") != NULL) else if (strstr(o->name, "-fg") != NULL)
new->style.fg = o->number; new->style.gc.fg = o->number;
else if (strstr(o->name, "-attr") != NULL) else if (strstr(o->name, "-attr") != NULL)
new->style.attr = o->number; new->style.gc.attr = o->number;
} }
void void
@ -674,13 +674,13 @@ options_style_update_old(struct options *oo, struct options_entry *o)
xsnprintf(newname, sizeof newname, "%.*s-bg", size, o->name); xsnprintf(newname, sizeof newname, "%.*s-bg", size, o->name);
if (options_get(oo, newname) != NULL) if (options_get(oo, newname) != NULL)
options_set_number(oo, newname, o->style.bg); options_set_number(oo, newname, o->style.gc.bg);
xsnprintf(newname, sizeof newname, "%.*s-fg", size, o->name); xsnprintf(newname, sizeof newname, "%.*s-fg", size, o->name);
if (options_get(oo, newname) != NULL) if (options_get(oo, newname) != NULL)
options_set_number(oo, newname, o->style.fg); options_set_number(oo, newname, o->style.gc.fg);
xsnprintf(newname, sizeof newname, "%.*s-attr", size, o->name); xsnprintf(newname, sizeof newname, "%.*s-attr", size, o->name);
if (options_get(oo, newname) != NULL) if (options_get(oo, newname) != NULL)
options_set_number(oo, newname, o->style.attr); options_set_number(oo, newname, o->style.gc.attr);
} }

View File

@ -327,15 +327,15 @@ void
screen_write_cnputs(struct screen_write_ctx *ctx, ssize_t maxlen, screen_write_cnputs(struct screen_write_ctx *ctx, ssize_t maxlen,
const struct grid_cell *gcp, const char *fmt, ...) const struct grid_cell *gcp, const char *fmt, ...)
{ {
struct grid_cell gc; struct style sy;
struct utf8_data *ud = &gc.data; struct utf8_data *ud = &sy.gc.data;
va_list ap; va_list ap;
char *msg; char *msg;
u_char *ptr, *last; u_char *ptr, *last;
size_t left, size = 0; size_t left, size = 0;
enum utf8_state more; enum utf8_state more;
memcpy(&gc, gcp, sizeof gc); style_set(&sy, gcp);
va_start(ap, fmt); va_start(ap, fmt);
xvasprintf(&msg, fmt, ap); xvasprintf(&msg, fmt, ap);
@ -352,7 +352,7 @@ screen_write_cnputs(struct screen_write_ctx *ctx, ssize_t maxlen,
} }
*last = '\0'; *last = '\0';
style_parse(gcp, &gc, ptr); style_parse(&sy, gcp, ptr);
ptr = last + 1; ptr = last + 1;
continue; continue;
} }
@ -370,22 +370,22 @@ screen_write_cnputs(struct screen_write_ctx *ctx, ssize_t maxlen,
continue; continue;
if (maxlen > 0 && size + ud->width > (size_t)maxlen) { if (maxlen > 0 && size + ud->width > (size_t)maxlen) {
while (size < (size_t)maxlen) { while (size < (size_t)maxlen) {
screen_write_putc(ctx, &gc, ' '); screen_write_putc(ctx, &sy.gc, ' ');
size++; size++;
} }
break; break;
} }
size += ud->width; size += ud->width;
screen_write_cell(ctx, &gc); screen_write_cell(ctx, &sy.gc);
} else { } else {
if (maxlen > 0 && size + 1 > (size_t)maxlen) if (maxlen > 0 && size + 1 > (size_t)maxlen)
break; break;
if (*ptr == '\001') if (*ptr == '\001')
gc.attr ^= GRID_ATTR_CHARSET; sy.gc.attr ^= GRID_ATTR_CHARSET;
else if (*ptr > 0x1f && *ptr < 0x7f) { else if (*ptr > 0x1f && *ptr < 0x7f) {
size++; size++;
screen_write_putc(ctx, &gc, *ptr); screen_write_putc(ctx, &sy.gc, *ptr);
} }
ptr++; ptr++;
} }

152
style.c
View File

@ -23,27 +23,40 @@
#include "tmux.h" #include "tmux.h"
/* Parse an embedded style of the form "fg=colour,bg=colour,bright,...". */ /* Mask for bits not included in style. */
#define STYLE_ATTR_MASK (~GRID_ATTR_CHARSET)
/* Default style. */
static struct style style_default = {
{ 0, 0, 8, 8, { { ' ' }, 0, 1, 1 } }
};
/*
* Parse an embedded style of the form "fg=colour,bg=colour,bright,...".
* Note that this adds onto the given style, so it must have been initialized
* alredy.
*/
int int
style_parse(const struct grid_cell *defgc, struct grid_cell *gc, style_parse(struct style *sy, const struct grid_cell *base, const char *in)
const char *in)
{ {
struct grid_cell savedgc; struct grid_cell *gc = &sy->gc;
const char delimiters[] = " ,"; struct grid_cell saved;
char tmp[32]; const char delimiters[] = " ,";
int val, fg, bg, attr, flags; char tmp[32];
size_t end; int value, fg, bg, attr, flags;
size_t end;
if (*in == '\0') if (*in == '\0')
return (0); return (0);
if (strchr(delimiters, in[strlen(in) - 1]) != NULL) if (strchr(delimiters, in[strlen(in) - 1]) != NULL)
return (-1); return (-1);
memcpy(&savedgc, gc, sizeof savedgc); memcpy(&saved, base, sizeof saved);
fg = gc->fg; fg = gc->fg;
bg = gc->bg; bg = gc->bg;
attr = gc->attr; attr = gc->attr;
flags = gc->flags; flags = gc->flags;
do { do {
end = strcspn(in, delimiters); end = strcspn(in, delimiters);
if (end > (sizeof tmp) - 1) if (end > (sizeof tmp) - 1)
@ -52,39 +65,40 @@ style_parse(const struct grid_cell *defgc, struct grid_cell *gc,
tmp[end] = '\0'; tmp[end] = '\0';
if (strcasecmp(tmp, "default") == 0) { if (strcasecmp(tmp, "default") == 0) {
fg = defgc->fg; fg = base->fg;
bg = defgc->bg; bg = base->bg;
attr = defgc->attr; attr = base->attr;
flags = defgc->flags; flags = base->flags;
} else if (end > 3 && strncasecmp(tmp + 1, "g=", 2) == 0) { } else if (end > 3 && strncasecmp(tmp + 1, "g=", 2) == 0) {
if ((val = colour_fromstring(tmp + 3)) == -1) if ((value = colour_fromstring(tmp + 3)) == -1)
goto error; goto error;
if (*in == 'f' || *in == 'F') { if (*in == 'f' || *in == 'F') {
if (val != 8) if (value != 8)
fg = val; fg = value;
else else
fg = defgc->fg; fg = base->fg;
} else if (*in == 'b' || *in == 'B') { } else if (*in == 'b' || *in == 'B') {
if (val != 8) if (value != 8)
bg = val; bg = value;
else else
bg = defgc->bg; bg = base->bg;
} else } else
goto error; goto error;
} else if (strcasecmp(tmp, "none") == 0) } else if (strcasecmp(tmp, "none") == 0)
attr = 0; attr = 0;
else if (end > 2 && strncasecmp(tmp, "no", 2) == 0) { else if (end > 2 && strncasecmp(tmp, "no", 2) == 0) {
if ((val = attributes_fromstring(tmp + 2)) == -1) if ((value = attributes_fromstring(tmp + 2)) == -1)
goto error; goto error;
attr &= ~val; attr &= ~value;
} else { } else {
if ((val = attributes_fromstring(tmp)) == -1) if ((value = attributes_fromstring(tmp)) == -1)
goto error; goto error;
attr |= val; attr |= value;
} }
in += end + strspn(in + end, delimiters); in += end + strspn(in + end, delimiters);
} while (*in != '\0'); } while (*in != '\0');
gc->fg = fg; gc->fg = fg;
gc->bg = bg; gc->bg = bg;
gc->attr = attr; gc->attr = attr;
@ -93,33 +107,35 @@ style_parse(const struct grid_cell *defgc, struct grid_cell *gc,
return (0); return (0);
error: error:
memcpy(gc, &savedgc, sizeof *gc); memcpy(gc, &saved, sizeof *gc);
return (-1); return (-1);
} }
/* Convert style to a string. */ /* Convert style to a string. */
const char * const char *
style_tostring(struct grid_cell *gc) style_tostring(struct style *sy)
{ {
int off = 0, comma = 0; struct grid_cell *gc = &sy->gc;
static char s[256]; int off = 0;
const char *comma = "";
static char s[256];
*s = '\0'; *s = '\0';
if (gc->fg != 8) { if (gc->fg != 8) {
off += xsnprintf(s, sizeof s, "fg=%s", colour_tostring(gc->fg)); off += xsnprintf(s + off, sizeof s - off, "%sfg=%s",
comma = 1; comma, colour_tostring(gc->fg));
comma = ",";
} }
if (gc->bg != 8) { if (gc->bg != 8) {
off += xsnprintf(s + off, sizeof s - off, "%sbg=%s", off += xsnprintf(s + off, sizeof s - off, "%sbg=%s",
comma ? "," : "", colour_tostring(gc->bg)); comma, colour_tostring(gc->bg));
comma = 1; comma = ",";
} }
if (gc->attr != 0 && gc->attr != GRID_ATTR_CHARSET) { if (gc->attr != 0 && gc->attr != GRID_ATTR_CHARSET) {
xsnprintf(s + off, sizeof s - off, "%s%s", xsnprintf(s + off, sizeof s - off, "%s%s",
comma ? "," : "", attributes_tostring(gc->attr)); comma, attributes_tostring(gc->attr));
comma = ",";
} }
if (*s == '\0') if (*s == '\0')
@ -131,38 +147,64 @@ style_tostring(struct grid_cell *gc)
void void
style_apply(struct grid_cell *gc, struct options *oo, const char *name) style_apply(struct grid_cell *gc, struct options *oo, const char *name)
{ {
const struct grid_cell *gcp; struct style *sy;
memcpy(gc, &grid_default_cell, sizeof *gc); memcpy(gc, &grid_default_cell, sizeof *gc);
gcp = options_get_style(oo, name); sy = options_get_style(oo, name);
gc->fg = gcp->fg; gc->fg = sy->gc.fg;
gc->bg = gcp->bg; gc->bg = sy->gc.bg;
gc->attr |= gcp->attr; gc->attr |= sy->gc.attr;
} }
/* Apply a style, updating if default. */ /* Apply a style, updating if default. */
void void
style_apply_update(struct grid_cell *gc, struct options *oo, const char *name) style_apply_update(struct grid_cell *gc, struct options *oo, const char *name)
{ {
const struct grid_cell *gcp; struct style *sy;
gcp = options_get_style(oo, name); sy = options_get_style(oo, name);
if (gcp->fg != 8) if (sy->gc.fg != 8)
gc->fg = gcp->fg; gc->fg = sy->gc.fg;
if (gcp->bg != 8) if (sy->gc.bg != 8)
gc->bg = gcp->bg; gc->bg = sy->gc.bg;
if (gcp->attr != 0) if (sy->gc.attr != 0)
gc->attr |= gcp->attr; gc->attr |= sy->gc.attr;
}
/* Initialize style from cell. */
void
style_set(struct style *sy, const struct grid_cell *gc)
{
memset(sy, 0, sizeof *sy);
memcpy(&sy->gc, gc, sizeof sy->gc);
}
/* Copy style. */
void
style_copy(struct style *dst, struct style *src)
{
memcpy(dst, src, sizeof *dst);
} }
/* Check if two styles are the same. */ /* Check if two styles are the same. */
int int
style_equal(const struct grid_cell *gc1, const struct grid_cell *gc2) style_equal(struct style *sy1, struct style *sy2)
{ {
return (gc1->fg == gc2->fg && struct grid_cell *gc1 = &sy1->gc;
gc1->bg == gc2->bg && struct grid_cell *gc2 = &sy2->gc;
(gc1->flags & ~GRID_FLAG_PADDING) ==
(gc2->flags & ~GRID_FLAG_PADDING) && if (gc1->fg != gc2->fg)
(gc1->attr & ~GRID_ATTR_CHARSET) == return (0);
(gc2->attr & ~GRID_ATTR_CHARSET)); if (gc1->bg != gc2->bg)
return (0);
if ((gc1->attr & STYLE_ATTR_MASK) != (gc2->attr & STYLE_ATTR_MASK))
return (0);
return (1);
}
/* Is this style default? */
int
style_is_default(struct style *sy)
{
return (style_equal(sy, &style_default));
} }

32
tmux.h
View File

@ -634,6 +634,11 @@ struct grid {
struct grid_line *linedata; struct grid_line *linedata;
}; };
/* Style option. */
struct style {
struct grid_cell gc;
};
/* Hook data structures. */ /* Hook data structures. */
struct hook { struct hook {
const char *name; const char *name;
@ -778,8 +783,7 @@ struct window_pane {
struct input_ctx *ictx; struct input_ctx *ictx;
struct grid_cell colgc; struct style style;
int *palette; int *palette;
int pipe_fd; int pipe_fd;
@ -847,8 +851,8 @@ struct window {
struct options *options; struct options *options;
struct grid_cell style; struct style style;
struct grid_cell active_style; struct style active_style;
u_int references; u_int references;
TAILQ_HEAD(, winlink) winlinks; TAILQ_HEAD(, winlink) winlinks;
@ -1649,7 +1653,7 @@ struct options_entry *options_match_get(struct options *, const char *, int *,
int, int *); int, int *);
const char *options_get_string(struct options *, const char *); const char *options_get_string(struct options *, const char *);
long long options_get_number(struct options *, const char *); long long options_get_number(struct options *, const char *);
const struct grid_cell *options_get_style(struct options *, const char *); struct style *options_get_style(struct options *, const char *);
struct options_entry * printflike(4, 5) options_set_string(struct options *, struct options_entry * printflike(4, 5) options_set_string(struct options *,
const char *, int, const char *, ...); const char *, int, const char *, ...);
struct options_entry *options_set_number(struct options *, const char *, struct options_entry *options_set_number(struct options *, const char *,
@ -1707,7 +1711,7 @@ void tty_update_window_offset(struct window *);
void tty_update_client_offset(struct client *); void tty_update_client_offset(struct client *);
void tty_raw(struct tty *, const char *); void tty_raw(struct tty *, const char *);
void tty_attributes(struct tty *, const struct grid_cell *, void tty_attributes(struct tty *, const struct grid_cell *,
const struct window_pane *); struct window_pane *);
void tty_reset(struct tty *); void tty_reset(struct tty *);
void tty_region_off(struct tty *); void tty_region_off(struct tty *);
void tty_margin_off(struct tty *); void tty_margin_off(struct tty *);
@ -1729,7 +1733,7 @@ void tty_start_tty(struct tty *);
void tty_stop_tty(struct tty *); void tty_stop_tty(struct tty *);
void tty_set_title(struct tty *, const char *); void tty_set_title(struct tty *, const char *);
void tty_update_mode(struct tty *, int, struct screen *); void tty_update_mode(struct tty *, int, struct screen *);
void tty_draw_line(struct tty *, const struct window_pane *, struct screen *, void tty_draw_line(struct tty *, struct window_pane *, struct screen *,
u_int, u_int, u_int, u_int, u_int); u_int, u_int, u_int, u_int, u_int);
int tty_open(struct tty *, char **); int tty_open(struct tty *, char **);
void tty_close(struct tty *); void tty_close(struct tty *);
@ -2207,7 +2211,7 @@ void window_pane_alternate_off(struct window_pane *,
void window_pane_set_palette(struct window_pane *, u_int, int); void window_pane_set_palette(struct window_pane *, u_int, int);
void window_pane_unset_palette(struct window_pane *, u_int); void window_pane_unset_palette(struct window_pane *, u_int);
void window_pane_reset_palette(struct window_pane *); void window_pane_reset_palette(struct window_pane *);
int window_pane_get_palette(const struct window_pane *, int); int window_pane_get_palette(struct window_pane *, int);
int window_pane_set_mode(struct window_pane *, int window_pane_set_mode(struct window_pane *,
const struct window_mode *, struct cmd_find_state *, const struct window_mode *, struct cmd_find_state *,
struct args *); struct args *);
@ -2420,14 +2424,16 @@ __dead void printflike(1, 2) fatal(const char *, ...);
__dead void printflike(1, 2) fatalx(const char *, ...); __dead void printflike(1, 2) fatalx(const char *, ...);
/* style.c */ /* style.c */
int style_parse(const struct grid_cell *, int style_parse(struct style *,const struct grid_cell *,
struct grid_cell *, const char *); const char *);
const char *style_tostring(struct grid_cell *); const char *style_tostring(struct style *);
void style_apply(struct grid_cell *, struct options *, void style_apply(struct grid_cell *, struct options *,
const char *); const char *);
void style_apply_update(struct grid_cell *, struct options *, void style_apply_update(struct grid_cell *, struct options *,
const char *); const char *);
int style_equal(const struct grid_cell *, int style_equal(struct style *, struct style *);
const struct grid_cell *); void style_set(struct style *, const struct grid_cell *);
void style_copy(struct style *, struct style *);
int style_is_default(struct style *);
#endif /* TMUX_H */ #endif /* TMUX_H */

79
tty.c
View File

@ -45,9 +45,9 @@ static void tty_cursor_pane_unless_wrap(struct tty *,
const struct tty_ctx *, u_int, u_int); const struct tty_ctx *, u_int, u_int);
static void tty_invalidate(struct tty *); static void tty_invalidate(struct tty *);
static void tty_colours(struct tty *, const struct grid_cell *); static void tty_colours(struct tty *, const struct grid_cell *);
static void tty_check_fg(struct tty *, const struct window_pane *, static void tty_check_fg(struct tty *, struct window_pane *,
struct grid_cell *); struct grid_cell *);
static void tty_check_bg(struct tty *, const struct window_pane *, static void tty_check_bg(struct tty *, struct window_pane *,
struct grid_cell *); struct grid_cell *);
static void tty_colours_fg(struct tty *, const struct grid_cell *); static void tty_colours_fg(struct tty *, const struct grid_cell *);
static void tty_colours_bg(struct tty *, const struct grid_cell *); static void tty_colours_bg(struct tty *, const struct grid_cell *);
@ -58,18 +58,16 @@ static void tty_region(struct tty *, u_int, u_int);
static void tty_margin_pane(struct tty *, const struct tty_ctx *); static void tty_margin_pane(struct tty *, const struct tty_ctx *);
static void tty_margin(struct tty *, u_int, u_int); static void tty_margin(struct tty *, u_int, u_int);
static int tty_large_region(struct tty *, const struct tty_ctx *); static int tty_large_region(struct tty *, const struct tty_ctx *);
static int tty_fake_bce(const struct tty *, const struct window_pane *, static int tty_fake_bce(const struct tty *, struct window_pane *, u_int);
u_int);
static void tty_redraw_region(struct tty *, const struct tty_ctx *); static void tty_redraw_region(struct tty *, const struct tty_ctx *);
static void tty_emulate_repeat(struct tty *, enum tty_code_code, static void tty_emulate_repeat(struct tty *, enum tty_code_code,
enum tty_code_code, u_int); enum tty_code_code, u_int);
static void tty_repeat_space(struct tty *, u_int); static void tty_repeat_space(struct tty *, u_int);
static void tty_draw_pane(struct tty *, const struct tty_ctx *, u_int); static void tty_draw_pane(struct tty *, const struct tty_ctx *, u_int);
static void tty_cell(struct tty *, const struct grid_cell *, static void tty_cell(struct tty *, const struct grid_cell *,
const struct window_pane *); struct window_pane *);
static void tty_default_colours(struct grid_cell *, static void tty_default_colours(struct grid_cell *, struct window_pane *);
const struct window_pane *); static void tty_default_attributes(struct tty *, struct window_pane *,
static void tty_default_attributes(struct tty *, const struct window_pane *,
u_int); u_int);
#define tty_use_margin(tty) \ #define tty_use_margin(tty) \
@ -847,7 +845,7 @@ tty_large_region(__unused struct tty *tty, const struct tty_ctx *ctx)
* emulated. * emulated.
*/ */
static int static int
tty_fake_bce(const struct tty *tty, const struct window_pane *wp, u_int bg) tty_fake_bce(const struct tty *tty, struct window_pane *wp, u_int bg)
{ {
struct grid_cell gc; struct grid_cell gc;
@ -956,8 +954,8 @@ tty_clamp_line(struct tty *tty, const struct tty_ctx *ctx, u_int px, u_int py,
/* Clear a line. */ /* Clear a line. */
static void static void
tty_clear_line(struct tty *tty, const struct window_pane *wp, u_int py, tty_clear_line(struct tty *tty, struct window_pane *wp, u_int py, u_int px,
u_int px, u_int nx, u_int bg) u_int nx, u_int bg)
{ {
struct client *c = tty->client; struct client *c = tty->client;
@ -1075,8 +1073,8 @@ tty_clamp_area(struct tty *tty, const struct tty_ctx *ctx, u_int px, u_int py,
/* Clear an area, adjusting to visible part of pane. */ /* Clear an area, adjusting to visible part of pane. */
static void static void
tty_clear_area(struct tty *tty, const struct window_pane *wp, u_int py, tty_clear_area(struct tty *tty, struct window_pane *wp, u_int py, u_int ny,
u_int ny, u_int px, u_int nx, u_int bg) u_int px, u_int nx, u_int bg)
{ {
struct client *c = tty->client; struct client *c = tty->client;
u_int yy; u_int yy;
@ -1198,8 +1196,8 @@ tty_check_codeset(struct tty *tty, const struct grid_cell *gc)
} }
void void
tty_draw_line(struct tty *tty, const struct window_pane *wp, tty_draw_line(struct tty *tty, struct window_pane *wp, struct screen *s,
struct screen *s, u_int px, u_int py, u_int nx, u_int atx, u_int aty) u_int px, u_int py, u_int nx, u_int atx, u_int aty)
{ {
struct grid *gd = s->grid; struct grid *gd = s->grid;
struct grid_cell gc, last; struct grid_cell gc, last;
@ -1802,8 +1800,7 @@ tty_cmd_rawstring(struct tty *tty, const struct tty_ctx *ctx)
} }
static void static void
tty_cell(struct tty *tty, const struct grid_cell *gc, tty_cell(struct tty *tty, const struct grid_cell *gc, struct window_pane *wp)
const struct window_pane *wp)
{ {
const struct grid_cell *gcp; const struct grid_cell *gcp;
@ -2117,7 +2114,7 @@ out:
void void
tty_attributes(struct tty *tty, const struct grid_cell *gc, tty_attributes(struct tty *tty, const struct grid_cell *gc,
const struct window_pane *wp) struct window_pane *wp)
{ {
struct grid_cell *tc = &tty->cell, gc2; struct grid_cell *tc = &tty->cell, gc2;
int changed; int changed;
@ -2265,8 +2262,7 @@ tty_colours(struct tty *tty, const struct grid_cell *gc)
} }
static void static void
tty_check_fg(struct tty *tty, const struct window_pane *wp, tty_check_fg(struct tty *tty, struct window_pane *wp, struct grid_cell *gc)
struct grid_cell *gc)
{ {
u_char r, g, b; u_char r, g, b;
u_int colours; u_int colours;
@ -2326,8 +2322,7 @@ tty_check_fg(struct tty *tty, const struct window_pane *wp,
} }
static void static void
tty_check_bg(struct tty *tty, const struct window_pane *wp, tty_check_bg(struct tty *tty, struct window_pane *wp, struct grid_cell *gc)
struct grid_cell *gc)
{ {
u_char r, g, b; u_char r, g, b;
u_int colours; u_int colours;
@ -2499,32 +2494,32 @@ fallback_256:
} }
static void static void
tty_default_colours(struct grid_cell *gc, const struct window_pane *wp) tty_default_colours(struct grid_cell *gc, struct window_pane *wp)
{ {
struct window *w = wp->window; struct window *w = wp->window;
struct options *oo = w->options; struct options *oo = w->options;
const struct grid_cell *agc, *pgc, *wgc; struct style *active, *pane, *window;
int c; int c;
if (w->flags & WINDOW_STYLECHANGED) { if (w->flags & WINDOW_STYLECHANGED) {
w->flags &= ~WINDOW_STYLECHANGED; w->flags &= ~WINDOW_STYLECHANGED;
agc = options_get_style(oo, "window-active-style"); active = options_get_style(oo, "window-active-style");
memcpy(&w->active_style, agc, sizeof w->active_style); style_copy(&w->active_style, active);
wgc = options_get_style(oo, "window-style"); window = options_get_style(oo, "window-style");
memcpy(&w->style, wgc, sizeof w->style); style_copy(&w->style, window);
} else { } else {
agc = &w->active_style; active = &w->active_style;
wgc = &w->style; window = &w->style;
} }
pgc = &wp->colgc; pane = &wp->style;
if (gc->fg == 8) { if (gc->fg == 8) {
if (pgc->fg != 8) if (pane->gc.fg != 8)
gc->fg = pgc->fg; gc->fg = pane->gc.fg;
else if (wp == w->active && agc->fg != 8) else if (wp == w->active && active->gc.fg != 8)
gc->fg = agc->fg; gc->fg = active->gc.fg;
else else
gc->fg = wgc->fg; gc->fg = window->gc.fg;
if (gc->fg != 8) { if (gc->fg != 8) {
c = window_pane_get_palette(wp, gc->fg); c = window_pane_get_palette(wp, gc->fg);
@ -2534,12 +2529,12 @@ tty_default_colours(struct grid_cell *gc, const struct window_pane *wp)
} }
if (gc->bg == 8) { if (gc->bg == 8) {
if (pgc->bg != 8) if (pane->gc.bg != 8)
gc->bg = pgc->bg; gc->bg = pane->gc.bg;
else if (wp == w->active && agc->bg != 8) else if (wp == w->active && active->gc.bg != 8)
gc->bg = agc->bg; gc->bg = active->gc.bg;
else else
gc->bg = wgc->bg; gc->bg = window->gc.bg;
if (gc->bg != 8) { if (gc->bg != 8) {
c = window_pane_get_palette(wp, gc->bg); c = window_pane_get_palette(wp, gc->bg);
@ -2550,7 +2545,7 @@ tty_default_colours(struct grid_cell *gc, const struct window_pane *wp)
} }
static void static void
tty_default_attributes(struct tty *tty, const struct window_pane *wp, u_int bg) tty_default_attributes(struct tty *tty, struct window_pane *wp, u_int bg)
{ {
static struct grid_cell gc; static struct grid_cell gc;

View File

@ -470,7 +470,7 @@ window_set_active_pane(struct window *w, struct window_pane *wp)
void void
window_redraw_active_switch(struct window *w, struct window_pane *wp) window_redraw_active_switch(struct window *w, struct window_pane *wp)
{ {
const struct grid_cell *gc; struct style *sy;
if (wp == w->active) if (wp == w->active)
return; return;
@ -479,21 +479,21 @@ window_redraw_active_switch(struct window *w, struct window_pane *wp)
* If window-style and window-active-style are the same, we don't need * If window-style and window-active-style are the same, we don't need
* to redraw panes when switching active panes. * to redraw panes when switching active panes.
*/ */
gc = options_get_style(w->options, "window-active-style"); sy = options_get_style(w->options, "window-active-style");
if (style_equal(gc, options_get_style(w->options, "window-style"))) if (style_equal(sy, options_get_style(w->options, "window-style")))
return; return;
/* /*
* If the now active or inactive pane do not have a custom style or if * If the now active or inactive pane do not have a custom style or if
* the palette is different, they need to be redrawn. * the palette is different, they need to be redrawn.
*/ */
if (window_pane_get_palette(w->active, w->active->colgc.fg) != -1 || if (window_pane_get_palette(w->active, w->active->style.gc.fg) != -1 ||
window_pane_get_palette(w->active, w->active->colgc.bg) != -1 || window_pane_get_palette(w->active, w->active->style.gc.bg) != -1 ||
style_equal(&grid_default_cell, &w->active->colgc)) style_is_default(&w->active->style))
w->active->flags |= PANE_REDRAW; w->active->flags |= PANE_REDRAW;
if (window_pane_get_palette(wp, wp->colgc.fg) != -1 || if (window_pane_get_palette(wp, wp->style.gc.fg) != -1 ||
window_pane_get_palette(wp, wp->colgc.bg) != -1 || window_pane_get_palette(wp, wp->style.gc.bg) != -1 ||
style_equal(&grid_default_cell, &wp->colgc)) style_is_default(&wp->style))
wp->flags |= PANE_REDRAW; wp->flags |= PANE_REDRAW;
} }
@ -826,7 +826,7 @@ window_pane_create(struct window *w, u_int sx, u_int sy, u_int hlimit)
wp->saved_grid = NULL; wp->saved_grid = NULL;
memcpy(&wp->colgc, &grid_default_cell, sizeof wp->colgc); style_set(&wp->style, &grid_default_cell);
screen_init(&wp->base, sx, sy, hlimit); screen_init(&wp->base, sx, sy, hlimit);
wp->screen = &wp->base; wp->screen = &wp->base;
@ -1179,7 +1179,7 @@ window_pane_reset_palette(struct window_pane *wp)
} }
int int
window_pane_get_palette(const struct window_pane *wp, int c) window_pane_get_palette(struct window_pane *wp, int c)
{ {
int new; int new;