diff --git a/CHANGELOG.md b/CHANGELOG.md index 175403dc..0dce3dd0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -263,6 +263,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]). diff --git a/config.c b/config.c index d63934b3..b0d1eb54 100644 --- a/config.c +++ b/config.c @@ -1055,6 +1055,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; @@ -3083,6 +3092,7 @@ config_load(struct config *conf, const char *conf_path, }, .multiplier = 3., }, + .alpha_mode = ALPHA_MODE_DEFAULT, .colors = { .fg = default_foreground, .bg = default_background, diff --git a/config.h b/config.h index df3d45f9..c94d2058 100644 --- a/config.h +++ b/config.h @@ -151,6 +151,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; struct config_font_list fonts[4]; struct font_size_adjustment font_size_adjustment; diff --git a/foot.ini b/foot.ini index a2c85e97..76ffcced 100644 --- a/foot.ini +++ b/foot.ini @@ -37,6 +37,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 diff --git a/render.c b/render.c index 804ccdc3..baa8604f 100644 --- a/render.c +++ b/render.c @@ -576,6 +576,27 @@ render_cell(struct terminal *term, pixman_image_t *pix, pixman_region32_t *damag 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)) {