diff --git a/config/src/color.rs b/config/src/color.rs index 90d31176c..1abadebda 100644 --- a/config/src/color.rs +++ b/config/src/color.rs @@ -3,6 +3,16 @@ use luahelper::impl_lua_conversion; use termwiz::cell::CellAttributes; use termwiz::color::{ColorSpec, RgbColor}; +#[derive(Debug, Default, Copy, Deserialize, Serialize, Clone)] +pub struct HsbTransform { + #[serde(default = "default_one_point_oh")] + pub hue: f32, + #[serde(default = "default_one_point_oh")] + pub saturation: f32, + #[serde(default = "default_one_point_oh")] + pub brightness: f32, +} + #[derive(Debug, Deserialize, Serialize, Clone)] pub struct Palette { /// The text color to use when the attributes are reset to default diff --git a/config/src/lib.rs b/config/src/lib.rs index 5d089274c..a26f0c847 100644 --- a/config/src/lib.rs +++ b/config/src/lib.rs @@ -700,6 +700,8 @@ pub struct Config { /// The image will be scaled to fit the window. #[serde(default)] pub window_background_image: Option, + #[serde(default)] + pub window_background_image_hsb: Option, /// Specifies the alpha value to use when rendering the background /// of the window. The background is taken either from the @@ -743,28 +745,11 @@ pub struct Config { /// A subtle dimming effect can be achieved by setting: /// inactive_pane_saturation = 0.9 /// inactive_pane_brightness = 0.8 - #[serde(default = "default_one_point_oh")] - pub inactive_pane_hue: f32, - #[serde(default = "default_one_point_oh")] - pub inactive_pane_saturation: f32, - #[serde(default = "default_one_point_oh")] - pub inactive_pane_brightness: f32, + #[serde(default)] + pub inactive_pane_hsb: Option, - /// Specifies the alpha value to use when applying the default - /// background color in a cell. This is useful to apply a kind - /// of "tint" to the background image if either window_background_image - /// or window_background_opacity are in used. - /// - /// It can be a number between 0.0 and 1.0. - /// The default is 0.0 - /// - /// Larger numbers increase the amount of the color scheme's - /// background color that is applied over the background image. - /// - /// This can be useful to increase effective contrast for text - /// that is rendered over the top. - #[serde(default = "default_zero_point_oh")] - pub window_background_tint: f32, + #[serde(default = "default_one_point_oh")] + pub text_background_opacity: f32, /// Specifies how often a blinking cursor transitions between visible /// and invisible, expressed in milliseconds. @@ -832,10 +817,6 @@ pub struct Config { pub enable_csi_u_key_encoding: bool, } -fn default_zero_point_oh() -> f32 { - 0.0 -} - fn default_one_point_oh() -> f32 { 1.0 } diff --git a/docs/config/appearance.markdown b/docs/config/appearance.markdown index 99cb7c2b4..ecae9a9eb 100644 --- a/docs/config/appearance.markdown +++ b/docs/config/appearance.markdown @@ -229,7 +229,30 @@ PNG, JPEG, GIF, BMP, ICO, TIFF, PNM, DDS, TGA and farbfeld files can be loaded. The image will be scaled to fit the window contents. Very large -images may decrease render performance. +images may decrease render performance and take up VRAM from the +GPU, so you may wish to resize the image file before using it. + +You can optionally transform the background image by specifying +a hue, saturation, brightness multiplier: + +```lua + +return { + window_background_image = "/path/to/wallpaper.jpg", + + window_background_image_hsb = { + -- Darken the background image by reducing it to 1/3rd + brightness = 0.3, + + -- You can adjust the hue by scaling its value. + -- a multiplier of 1.0 leaves the value unchanged. + hue = 1.0, + + -- You can adjust the saturation also. + saturation = 1.0, + }, +} +``` ## Window Background Opacity @@ -257,7 +280,7 @@ return { } ``` -## Window Backing Tint +## Text Background Opacity *since: nightly builds only* @@ -265,24 +288,18 @@ 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 the background color of cells when either `window_background_image` or -`window_background_opacity` are in use. +The `text_background_opacity` setting specifies the alpha channel value to use +for the background color of cells other than the default background color. -The default for this setting is `0.0` such that the background image or -desktop content shows through the window relatively unimpeded. - -Increasing `window_background_tint` causes whatever your color scheme's -background color to be mixed into the background. If you have a dark -color this effectively will darken the content behind and increase the -contrast for your text, making it a bit more readable. +The default for this setting is `1.0`, which means that the background +color is fully opaque. The range of values permitted are `0.0` (completely translucent) through to `1.0` (completely opaque). ```lua return { - window_background_tint = 0.0, + text_background_opacity = 0.3, } ``` diff --git a/wezterm/src/gui/fragment.glsl b/wezterm/src/gui/fragment.glsl index cf020e3ea..4044663d4 100644 --- a/wezterm/src/gui/fragment.glsl +++ b/wezterm/src/gui/fragment.glsl @@ -64,17 +64,20 @@ void main() { if (o_has_color == 2.0) { // We're the window background image. color = texture(glyph_tex, o_tex); - // Apply window_background_opacity to the background image + // Apply window_background_image_opacity to the background image color.a = o_bg_color.a; - } else if (!has_background_image) { - // If there is no background image then take the cell background - color = o_bg_color; } else { // Nothing else should render on the background layer // color = vec4(0,0,0,0); discard; } } else if (bg_and_line_layer) { + if (o_has_color == 2.0) { + // Don't render the background image on anything other than + // the window_bg_layer. + discard; + return; + } // Note that o_bg_color is set to transparent if the background // color is "default" and there is a window background attachment color = o_bg_color; @@ -102,7 +105,6 @@ void main() { if (o_has_color == 2.0) { // Don't render the background image on anything other than // the window_bg_layer. - // color = vec4(0,0,0,0); discard; } else { color = texture(glyph_tex, o_tex); diff --git a/wezterm/src/gui/quad.rs b/wezterm/src/gui/quad.rs index dc69c93f7..44465b70d 100644 --- a/wezterm/src/gui/quad.rs +++ b/wezterm/src/gui/quad.rs @@ -192,8 +192,10 @@ impl<'a> Quad<'a> { } } - pub fn set_hsv(&mut self, hsv: Option<(f32, f32, f32)>) { - let s = hsv.unwrap_or((1., 1., 1.)); + pub fn set_hsv(&mut self, hsv: Option) { + let s = hsv + .map(|t| (t.hue, t.saturation, t.brightness)) + .unwrap_or((1., 1., 1.)); for v in self.vert.iter_mut() { v.hsv = s; } diff --git a/wezterm/src/gui/termwindow.rs b/wezterm/src/gui/termwindow.rs index c3188fc5c..670363597 100644 --- a/wezterm/src/gui/termwindow.rs +++ b/wezterm/src/gui/termwindow.rs @@ -2263,10 +2263,10 @@ impl TermWindow { let foreground = rgbcolor_to_window_color(palette.split); let background = rgbcolor_alpha_to_window_color( palette.background, - if self.window_background.is_none() && config.window_background_opacity == 1.0 { - 0xff + if self.window_background.is_some() || config.window_background_opacity != 1.0 { + 0x00 } else { - (config.window_background_tint * 255.0) as u8 + (config.text_background_opacity * 255.0) as u8 }, ); @@ -2386,9 +2386,6 @@ impl TermWindow { let palette = pos.pane.palette(); let background_color = palette.resolve_bg(wezterm_term::color::ColorAttribute::Default); - let background_alpha = (config.window_background_opacity * 255.0) as u8; - let background = rgbcolor_alpha_to_window_color(palette.background, background_alpha); - let first_line_offset = if self.show_tab_bar { 1 } else { 0 }; let mut term = pos.pane.renderer(); @@ -2498,7 +2495,8 @@ impl TermWindow { quad.set_cursor(white_space); quad.set_has_color(false); - let color = Color::rgba(0, 0, 0, background_alpha); + let background_image_alpha = (config.window_background_opacity * 255.0) as u8; + let color = Color::rgba(0, 0, 0, background_image_alpha); quad.set_texture_adjust(0., 0., 0., 0.); quad.set_texture(white_space); @@ -2507,10 +2505,10 @@ impl TermWindow { quad.set_texture(sprite.texture_coords()); quad.set_is_background_image(); } - quad.set_hsv(None); + quad.set_hsv(config.window_background_image_hsb); quad.set_cursor_color(color); quad.set_fg_color(color); - quad.set_bg_color(background); + quad.set_bg_color(color); quad.set_cursor_color(color); } @@ -2672,13 +2670,12 @@ impl TermWindow { let hsv = if params.is_active { None } else { - Some(( - params.config.inactive_pane_hue, - params.config.inactive_pane_saturation, - params.config.inactive_pane_brightness, - )) + params.config.inactive_pane_hsb }; + let window_is_transparent = + self.window_background.is_some() || params.config.window_background_opacity != 1.0; + // Break the line into clusters of cells with the same attributes let cell_clusters = params.line.cluster(); let mut last_cell_idx = 0; @@ -2690,6 +2687,7 @@ 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 => { @@ -2717,26 +2715,27 @@ impl TermWindow { _ => params.palette.resolve_fg(attrs.foreground), }; - let (fg_color, bg_color) = { + let (fg_color, bg_color, bg_is_default) = { let mut fg = fg_color; let mut bg = bg_color; + let mut bg_default = bg_is_default; if attrs.reverse() { std::mem::swap(&mut fg, &mut bg); + bg_default = false; } - (fg, bg) + (fg, bg, bg_default) }; let glyph_color = rgbcolor_to_window_color(fg_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 + if window_is_transparent && bg_is_default { + 0x00 } else { - (params.config.window_background_tint * 255.0) as u8 + (params.config.text_background_opacity * 255.0) as u8 }, ); @@ -2945,7 +2944,11 @@ impl TermWindow { fg_color: params.foreground, bg_color: rgbcolor_alpha_to_window_color( params.palette.resolve_bg(ColorAttribute::Default), - (params.config.window_background_tint * 255.0) as u8, + if window_is_transparent { + 0x00 + } else { + (params.config.text_background_opacity * 255.0) as u8 + }, ), palette: params.palette, is_active_pane: params.pos.is_active, diff --git a/wezterm/src/gui/vertex.glsl b/wezterm/src/gui/vertex.glsl index 6a448fd15..ad683fefe 100644 --- a/wezterm/src/gui/vertex.glsl +++ b/wezterm/src/gui/vertex.glsl @@ -46,11 +46,6 @@ void main() { if (o_has_color == 2.0) { // Background image takes up its full coordinates gl_Position = projection * vec4(position, 0.0, 1.0); - } else if (!has_background_image) { - // If there is no background attachment, then we're - // rendering the cell background color and need to - // fill the cell with that color - gl_Position = projection * vec4(position, 0.0, 1.0); } else { // Nothing else should render on the background layer gl_Position = off_screen();