From aa660d5d062a158ea5671f607aa943f874fd7d1a Mon Sep 17 00:00:00 2001 From: Wez Furlong Date: Sun, 18 Oct 2020 21:39:03 -0700 Subject: [PATCH] wezterm: apply transparency tint to all background colors refs: https://github.com/wez/wezterm/issues/141#issuecomment-711442986 --- docs/config/appearance.markdown | 8 +++----- wezterm/src/gui/termwindow.rs | 26 ++++++++++++-------------- window/src/color.rs | 6 ++++++ 3 files changed, 21 insertions(+), 19 deletions(-) diff --git a/docs/config/appearance.markdown b/docs/config/appearance.markdown index 6b8e9f999..18aa98b3e 100644 --- a/docs/config/appearance.markdown +++ b/docs/config/appearance.markdown @@ -260,11 +260,9 @@ When using a background image or background opacity, the image content can have relatively low contrast with respect to the text you are trying to read in your terminal. -The `window_background_tint` setting specifies the alpha channel value -to use for cells that are rendered with the ANSI default background color -attribute. Cells that have reversed or other background colors, or that -are explicitly setting the color attributes to a color that happens to -be the same as the default background are not affected by this setting. +The `window_background_tint` setting specifies the alpha channel value to use +for the background color of cells when either `window_background_image` or +`window_background_opacity` are in use. The default for this setting is `0.0` such that the background image or desktop content shows through the window relatively unimpeded. diff --git a/wezterm/src/gui/termwindow.rs b/wezterm/src/gui/termwindow.rs index db6b2bb94..dd703a066 100644 --- a/wezterm/src/gui/termwindow.rs +++ b/wezterm/src/gui/termwindow.rs @@ -2914,7 +2914,6 @@ impl TermWindow { }; let style = self.fonts.match_style(params.config, attrs); - let bg_is_default = attrs.background == ColorAttribute::Default; let bg_color = params.palette.resolve_bg(attrs.background); let fg_color = match attrs.foreground { wezterm_term::color::ColorAttribute::Default => { @@ -2942,29 +2941,28 @@ impl TermWindow { _ => params.palette.resolve_fg(attrs.foreground), }; - let (fg_color, bg_color, bg_is_default) = { + let (fg_color, bg_color) = { let mut fg = fg_color; let mut bg = bg_color; - let mut bg_is_default = bg_is_default; if attrs.reverse() { std::mem::swap(&mut fg, &mut bg); - // reversed, so don't let it be transparent - bg_is_default = false; } - (fg, bg, bg_is_default) + (fg, bg) }; let glyph_color = rgbcolor_to_window_color(fg_color); - let bg_color = if bg_is_default { - rgbcolor_alpha_to_window_color( - bg_color, - (params.config.window_background_tint * 255.0) as u8, - ) - } else { - rgbcolor_to_window_color(bg_color) - }; + let bg_color = rgbcolor_alpha_to_window_color( + bg_color, + if self.window_background.is_none() + && params.config.window_background_opacity == 1.0 + { + 0xff + } else { + (params.config.window_background_tint * 255.0) as u8 + }, + ); // Shape the printable text from this cluster let glyph_info = { diff --git a/window/src/color.rs b/window/src/color.rs index 00517ba61..5ddbeafd9 100644 --- a/window/src/color.rs +++ b/window/src/color.rs @@ -276,6 +276,12 @@ impl Color { Color::rgba(red, green, blue, 0xff) } + #[inline] + pub fn with_alpha(self, alpha: u8) -> Self { + let (r, g, b, _) = self.as_rgba(); + Self::rgba(r, g, b, alpha) + } + #[inline] pub fn rgba(red: u8, green: u8, blue: u8, alpha: u8) -> Color { #[allow(clippy::cast_lossless)]