diff --git a/config.c b/config.c index 2b9bf1c4..2bb04a65 100644 --- a/config.c +++ b/config.c @@ -119,6 +119,19 @@ str_to_ulong(const char *s, int base, unsigned long *res) return errno == 0 && *end == '\0'; } +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) { @@ -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 = { diff --git a/config.h b/config.h index 2a6075cc..cc17c8e2 100644 --- a/config.h +++ b/config.h @@ -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 diff --git a/footrc b/footrc index 2c4961ff..7cacbf1b 100644 --- a/footrc +++ b/footrc @@ -27,3 +27,4 @@ # bright5=dc8cc3 # bright6=93e0e3 # bright7=ffffff +# alpha=1.0 \ No newline at end of file diff --git a/main.c b/main.c index 3a28a960..943a3d32 100644 --- a/main.c +++ b/main.c @@ -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, diff --git a/render.c b/render.c index b2fa4117..5ed69d6e 100644 --- a/render.c +++ b/render.c @@ -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); diff --git a/terminal.h b/terminal.h index 217daec8..c88c433f 100644 --- a/terminal.h +++ b/terminal.h @@ -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;