mirror of
https://codeberg.org/dnkl/foot.git
synced 2026-02-05 04:06:08 -05:00
Add background alpha support
This commit is contained in:
parent
9e7106018e
commit
9fe6e8cc48
7 changed files with 35 additions and 2 deletions
25
config.c
25
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 = {
|
||||
|
|
|
|||
1
config.h
1
config.h
|
|
@ -18,6 +18,7 @@ struct config {
|
|||
uint32_t bg;
|
||||
uint32_t regular[8];
|
||||
uint32_t bright[8];
|
||||
double alpha;
|
||||
} colors;
|
||||
|
||||
struct {
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
1
footrc
1
footrc
|
|
@ -27,3 +27,4 @@
|
|||
# bright5=dc8cc3
|
||||
# bright6=93e0e3
|
||||
# bright7=ffffff
|
||||
# alpha=1.0
|
||||
1
main.c
1
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,
|
||||
|
|
|
|||
4
render.c
4
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);
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue