config: add alpha_mode option

This commit is contained in:
Fazzi 2023-10-09 18:47:09 +01:00 committed by Daniel Eklöf
parent 9a6227acb3
commit 5f83278afd
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F
5 changed files with 38 additions and 0 deletions

View file

@ -788,6 +788,9 @@
### Added
* `alpha-mode` option to `foot.ini`. Defaults to `default`. This
config changes how alpha is handled on background colours not set by
the terminal.(e.g. vim) ([#1510](1510))
* Support for building with _wayland-protocols_ as a subproject.
* Mouse wheel scrolls can now be used in `mouse-bindings`
([#1077][1077]).

View file

@ -1095,6 +1095,15 @@ parse_section_main(struct context *ctx)
return true;
}
else if (strcmp(key, "alpha-mode") == 0) {
_Static_assert(sizeof(conf->alpha_mode) == sizeof(int),
"enum is not 32-bit");
return value_to_enum(
ctx,
(const char *[]){"default", "matching", "all", NULL},
(int *)&conf->alpha_mode);
}
else {
LOG_CONTEXTUAL_ERR("not a valid option: %s", key);
return false;
@ -3338,6 +3347,7 @@ config_load(struct config *conf, const char *conf_path,
},
.multiplier = 3.,
},
.alpha_mode = ALPHA_MODE_DEFAULT,
.colors = {
.fg = default_foreground,
.bg = default_background,

View file

@ -167,6 +167,8 @@ struct config {
enum { STARTUP_WINDOWED, STARTUP_MAXIMIZED, STARTUP_FULLSCREEN } startup_mode;
enum { ALPHA_MODE_DEFAULT, ALPHA_MODE_MATCHING, ALPHA_MODE_ALL } alpha_mode;
bool dpi_aware;
enum {GAMMA_CORRECT_DISABLED,
GAMMA_CORRECT_ENABLED,

View file

@ -38,6 +38,8 @@
# utmp-helper=/usr/lib/utempter/utempter # When utmp backend is libutempter (Linux)
# utmp-helper=/usr/libexec/ulog-helper # When utmp backend is ulog (FreeBSD)
# alpha-mode=default # Can be `default`, `matching` or `all`
[environment]
# name=value

View file

@ -788,6 +788,27 @@ render_cell(struct terminal *term, pixman_image_t *pix,
alpha = term->colors.alpha;
}
}
if (!term->window->is_fullscreen) {
switch (term->conf->alpha_mode) {
case ALPHA_MODE_DEFAULT: {
if (cell->attrs.bg_src == COLOR_DEFAULT) {
alpha = term->colors.alpha;
}
break;
}
case ALPHA_MODE_MATCHING: {
if (cell->attrs.bg == term->colors.bg) {
alpha = term->colors.alpha;
}
break;
}
case ALPHA_MODE_ALL: {
alpha = term->colors.alpha;
break;
}
}
}
}
if (unlikely(is_selected && _fg == _bg)) {