diff options
| author | Daniel Eklöf <daniel@ekloef.se> | 2021-11-03 13:25:38 +0000 |
|---|---|---|
| committer | Daniel Eklöf <daniel@ekloef.se> | 2021-11-13 16:39:08 +0000 |
| commit | c01904a2c75e962e5159dd42a640cce3d7370b13 (patch) | |
| tree | fc6a5d6c1284bd7a7f035ae66998fa16f2c27a15 /render.c | |
| parent | doc: foot.ini: try to clear up the meaning of (AA)RRGGBB (diff) | |
config: add [colors].dim0-7
This allows you to configure custom colors to be used when colors are
being dimmed (`\E[2m`).
It is implemented by color matching (just like
bold-text-in-bright=palette-based); the color-to-be-dimmed is matched
against the current color palette.
If it matches one of the regular colors (colors 0-7), the
corresponding “dim” color will be used.
If it matches one of the bright colors (colors 8-15), the
corresponding “regular” color will be used (but *only* if the “dim”
color has been set).
Otherwise, the color is dimmed by reducing its luminance.
The default behavior, i.e. when dim0-7 hasn’t been configured, is to
dim by reducing luminance for *all* colors. I.e. we don’t do any color
matching at all. In particular, this means that dimming a bright color
will *not* result in the corresponding “regular” color.
Closes #776
Diffstat (limited to 'render.c')
| -rw-r--r-- | render.c | 41 |
1 files changed, 34 insertions, 7 deletions
@@ -244,7 +244,7 @@ color_hex_to_pixman(uint32_t color) } static inline uint32_t -color_dim(uint32_t color) +color_decrease_luminance(uint32_t color) { uint32_t alpha = color & 0xff000000; int hue, sat, lum; @@ -253,6 +253,33 @@ color_dim(uint32_t color) } static inline uint32_t +color_dim(const struct terminal *term, uint32_t color) +{ + const struct config *conf = term->conf; + const uint8_t custom_dim = conf->colors.use_custom.dim; + + if (likely(custom_dim == 0)) + return color_decrease_luminance(color); + + for (size_t i = 0; i < 8; i++) { + if (((custom_dim >> i) & 1) == 0) + continue; + + if (term->colors.table[0 + i] == color) { + /* “Regular” color, return the corresponding “dim” */ + return conf->colors.dim[i]; + } + + else if (term->colors.table[8 + i] == color) { + /* “Bright” color, return the corresponding “regular” */ + return term->colors.table[i]; + } + } + + return color_decrease_luminance(color); +} + +static inline uint32_t color_brighten(const struct terminal *term, uint32_t color) { /* @@ -485,12 +512,12 @@ render_cell(struct terminal *term, pixman_image_t *pix, } if (cell->attrs.dim) - _fg = color_dim(_fg); + _fg = color_dim(term, _fg); if (term->conf->bold_in_bright.enabled && cell->attrs.bold) _fg = color_brighten(term, _fg); if (cell->attrs.blink && term->blink.state == BLINK_OFF) - _fg = color_dim(_fg); + _fg = color_decrease_luminance(_fg); pixman_color_t fg = color_hex_to_pixman(_fg); pixman_color_t bg = color_hex_to_pixman_with_alpha(_bg, alpha); @@ -779,7 +806,7 @@ render_urgency(struct terminal *term, struct buffer *buf) { uint32_t red = term->colors.table[1]; if (term->is_searching) - red = color_dim(red); + red = color_decrease_luminance(red); pixman_color_t bg = color_hex_to_pixman(red); @@ -1685,8 +1712,8 @@ render_csd_title(struct terminal *term, const struct csd_data *info, : term->conf->colors.bg; if (!term->visual_focus) { - bg = color_dim(bg); - fg = color_dim(fg); + bg = color_dim(term, bg); + fg = color_dim(term, fg); } const wchar_t *title_text = L""; @@ -2001,7 +2028,7 @@ render_csd_button(struct terminal *term, enum csd_surface surf_idx, } if (!term->visual_focus) - _color = color_dim(_color); + _color = color_dim(term, _color); pixman_color_t color = color_hex_to_pixman_with_alpha(_color, alpha); render_csd_part(term, surf, buf, info->width, info->height, &color); |
