diff options
| author | Daniel Eklöf <daniel@ekloef.se> | 2019-08-15 16:15:43 +0000 |
|---|---|---|
| committer | Daniel Eklöf <daniel@ekloef.se> | 2019-08-15 16:15:43 +0000 |
| commit | 9fe6e8cc4850ea9dd14245ae9563ceaf12f810c6 (patch) | |
| tree | 80ff5885b52edf624d110bde30e6cc98df3b4a2f | |
| parent | font: don't bother creating a cairo surface for zero-width glyphs (diff) | |
Add background alpha support
| -rw-r--r-- | config.c | 25 | ||||
| -rw-r--r-- | config.h | 1 | ||||
| -rw-r--r-- | doc/foot.5.scd | 4 | ||||
| -rw-r--r-- | footrc | 1 | ||||
| -rw-r--r-- | main.c | 1 | ||||
| -rw-r--r-- | render.c | 4 | ||||
| -rw-r--r-- | terminal.h | 1 |
7 files changed, 35 insertions, 2 deletions
@@ -120,6 +120,19 @@ str_to_ulong(const char *s, int base, unsigned long *res) } static bool +str_to_double(const char *s, double *res) +{ + if (s == NULL) + return false; + + errno = 0; + char *end = NULL; + + *res = strtod(s, &end); + return errno == 0 && *end == '\0'; +} + +static bool str_to_color(const char *s, uint32_t *color, const char *path, int lineno) { unsigned long value; @@ -203,6 +216,17 @@ parse_section_colors(const char *key, const char *value, struct config *conf, else if (strcmp(key, "bright5") == 0) color = &conf->colors.bright[5]; else if (strcmp(key, "bright6") == 0) color = &conf->colors.bright[6]; else if (strcmp(key, "bright7") == 0) color = &conf->colors.bright[7]; + else if (strcmp(key, "alpha") == 0) { + double alpha; + if (!str_to_double(value, &alpha) || alpha < 0. || alpha > 1.) { + LOG_ERR("%s: %d: alpha: expected a value in the range 0.0-1.0", + path, lineno); + return false; + } + + conf->colors.alpha = alpha; + return true; + } else { LOG_ERR("%s:%d: invalid key: %s", path, lineno, key); @@ -442,6 +466,7 @@ config_load(struct config *conf) default_bright[6], default_bright[7], }, + .alpha = 1., }, .cursor = { @@ -18,6 +18,7 @@ struct config { uint32_t bg; uint32_t regular[8]; uint32_t bright[8]; + double alpha; } colors; struct { diff --git a/doc/foot.5.scd b/doc/foot.5.scd index ee1fb88e..51d8888f 100644 --- a/doc/foot.5.scd +++ b/doc/foot.5.scd @@ -71,6 +71,10 @@ in this order: _bfebbf_, _f0dfaf_, _8cd0d3_, _dc8cc3_, _93e0e3_ and _ffffff_ (a variant of the _zenburn_ theme). +*alpha* + Background translucency. A value in the range 0.0-1.0, where 0.0 + means completely transparent, and 1.0 is opaque. Default: _1.0_. + # FONT FORMAT The font is specified in FontConfig syntax. That is, a colon-separated @@ -27,3 +27,4 @@ # bright5=dc8cc3 # bright6=93e0e3 # bright7=ffffff +# alpha=1.0
\ No newline at end of file @@ -462,6 +462,7 @@ main(int argc, char *const *argv) conf.colors.bright[6], conf.colors.bright[7], }, + .alpha = conf.colors.alpha, }, .default_cursor_style = conf.cursor.style, .cursor_style = conf.cursor.style, @@ -189,7 +189,7 @@ render_cell(struct terminal *term, cairo_t *cr, /* Background */ cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); - cairo_set_source_rgb(cr, bg.r, bg.g, bg.b); + cairo_set_source_rgba(cr, bg.r, bg.g, bg.b, block_cursor ? 1.0 : term->colors.alpha); cairo_rectangle(cr, x, y, cell_cols * width, height); cairo_fill(cr); @@ -432,7 +432,7 @@ grid_render(struct terminal *term) uint32_t _bg = !term->reverse ? term->colors.bg : term->colors.fg; struct rgb bg = color_hex_to_rgb(_bg); - cairo_set_source_rgb(buf->cairo[0], bg.r, bg.g, bg.b); + cairo_set_source_rgba(buf->cairo[0], bg.r, bg.g, bg.b, term->colors.alpha); cairo_rectangle(buf->cairo[0], rmargin, 0, rmargin_width, term->height); cairo_rectangle(buf->cairo[0], 0, bmargin, term->width, bmargin_height); @@ -283,6 +283,7 @@ struct terminal { uint32_t bg; uint32_t regular[8]; uint32_t bright[8]; + double alpha; uint32_t default_fg; uint32_t default_bg; |
