1
1
mirror of https://github.com/wez/wezterm.git synced 2024-11-30 14:49:26 +03:00

pane select: allow bg to have alpha channel

Wraps up the changes from the following diff and allows for the modal
layer (and box model) to use alpha for poly quads.

Change the default background color for pane select to be slightly
transparent.
This commit is contained in:
Wez Furlong 2022-05-25 23:25:09 -07:00
parent 3058e245d0
commit 3be4dbc878
8 changed files with 103 additions and 52 deletions

View File

@ -41,6 +41,12 @@ impl From<RgbColor> for RgbaColor {
} }
} }
impl From<SrgbaTuple> for RgbaColor {
fn from(color: SrgbaTuple) -> Self {
Self { color }
}
}
impl std::ops::Deref for RgbaColor { impl std::ops::Deref for RgbaColor {
type Target = SrgbaTuple; type Target = SrgbaTuple;
fn deref(&self) -> &SrgbaTuple { fn deref(&self) -> &SrgbaTuple {

View File

@ -1,6 +1,8 @@
use crate::background::Gradient; use crate::background::Gradient;
use crate::bell::{AudibleBell, EasingFunction, VisualBell}; use crate::bell::{AudibleBell, EasingFunction, VisualBell};
use crate::color::{ColorSchemeFile, HsbTransform, Palette, TabBarStyle, WindowFrameConfig}; use crate::color::{
ColorSchemeFile, HsbTransform, Palette, SrgbaTuple, TabBarStyle, WindowFrameConfig,
};
use crate::daemon::DaemonOptions; use crate::daemon::DaemonOptions;
use crate::font::{ use crate::font::{
AllowSquareGlyphOverflow, FontLocatorSelection, FontRasterizerSelection, FontShaperSelection, AllowSquareGlyphOverflow, FontLocatorSelection, FontRasterizerSelection, FontShaperSelection,
@ -19,7 +21,7 @@ use crate::unix::UnixDomain;
use crate::wsl::WslDomain; use crate::wsl::WslDomain;
use crate::{ use crate::{
default_config_with_overrides_applied, default_one_point_oh, default_one_point_oh_f64, default_config_with_overrides_applied, default_one_point_oh, default_one_point_oh_f64,
default_true, KeyMapPreference, LoadedConfig, CONFIG_DIR, CONFIG_FILE_OVERRIDE, default_true, KeyMapPreference, LoadedConfig, RgbaColor, CONFIG_DIR, CONFIG_FILE_OVERRIDE,
CONFIG_OVERRIDES, CONFIG_SKIP, HOME_DIR, CONFIG_OVERRIDES, CONFIG_SKIP, HOME_DIR,
}; };
use anyhow::Context; use anyhow::Context;
@ -93,6 +95,12 @@ pub struct Config {
#[dynamic(default = "default_pane_select_font_size")] #[dynamic(default = "default_pane_select_font_size")]
pub pane_select_font_size: f64, pub pane_select_font_size: f64,
#[dynamic(default = "default_pane_select_fg_color")]
pub pane_select_fg_color: RgbaColor,
#[dynamic(default = "default_pane_select_bg_color")]
pub pane_select_bg_color: RgbaColor,
#[dynamic(default)] #[dynamic(default)]
pub tab_bar_style: TabBarStyle, pub tab_bar_style: TabBarStyle,
@ -1134,6 +1142,14 @@ impl Config {
} }
} }
fn default_pane_select_fg_color() -> RgbaColor {
SrgbaTuple(0.75, 0.75, 0.75, 1.0).into()
}
fn default_pane_select_bg_color() -> RgbaColor {
SrgbaTuple(0., 0., 0., 0.5).into()
}
fn default_pane_select_font_size() -> f64 { fn default_pane_select_font_size() -> f64 {
36.0 36.0
} }

View File

@ -3668,9 +3668,11 @@ impl<T: Texture2d> GlyphCache<T> {
style, style,
} in polys } in polys
{ {
let intensity = (intensity.to_scale() * 255.) as u8;
let mut paint = Paint::default(); let mut paint = Paint::default();
paint.set_color_rgba8(intensity, intensity, intensity, intensity); let intensity = intensity.to_scale();
paint.set_color(
tiny_skia::Color::from_rgba(intensity, intensity, intensity, intensity).unwrap(),
);
paint.anti_alias = match aa { paint.anti_alias = match aa {
PolyAA::AntiAlias => true, PolyAA::AntiAlias => true,
PolyAA::MoarPixels => false, PolyAA::MoarPixels => false,

View File

@ -93,6 +93,11 @@ void main() {
color = texture(atlas_nearest_sampler, o_tex); color = texture(atlas_nearest_sampler, o_tex);
// this is the alpha // this is the alpha
colorMask = color.aaaa; colorMask = color.aaaa;
} else if (o_has_color == 4.0) {
// Grayscale poly quad for non-aa text render layers
colorMask = texture(atlas_nearest_sampler, o_tex);
color = o_fg_color;
color.a *= colorMask.a;
} else if (o_has_color == 0.0) { } else if (o_has_color == 0.0) {
// the texture is the alpha channel/color mask // the texture is the alpha channel/color mask
colorMask = texture(atlas_nearest_sampler, o_tex); colorMask = texture(atlas_nearest_sampler, o_tex);

View File

@ -59,6 +59,14 @@ impl<'a> Quad<'a> {
} }
} }
/// Mark as a grayscale polyquad; color and alpha will be
/// multipled with those in the texture
pub fn set_grayscale(&mut self) {
for v in self.vert.iter_mut() {
v.has_color = 4.0;
}
}
/// Mark this quad as a background image. /// Mark this quad as a background image.
/// Mutually exclusive with set_has_color. /// Mutually exclusive with set_has_color.
pub fn set_is_background_image(&mut self) { pub fn set_is_background_image(&mut self) {

View File

@ -3,7 +3,8 @@ use crate::color::LinearRgba;
use crate::customglyph::{BlockKey, Poly}; use crate::customglyph::{BlockKey, Poly};
use crate::glyphcache::CachedGlyph; use crate::glyphcache::CachedGlyph;
use crate::termwindow::{ use crate::termwindow::{
MappedQuads, MouseCapture, RenderState, SrgbTexture2d, TermWindowNotif, UIItem, UIItemType, MappedQuads, MouseCapture, RenderLayer, RenderState, SrgbTexture2d, TermWindowNotif, UIItem,
UIItemType,
}; };
use crate::utilsprites::RenderMetrics; use crate::utilsprites::RenderMetrics;
use ::window::{RectF, WindowOps}; use ::window::{RectF, WindowOps};
@ -754,7 +755,26 @@ impl super::TermWindow {
pub fn render_element<'a>( pub fn render_element<'a>(
&self, &self,
element: &ComputedElement, element: &ComputedElement,
layer: &'a mut MappedQuads, layer: &RenderLayer,
inherited_colors: Option<&ElementColors>,
) -> anyhow::Result<()> {
let vb = [&layer.vb[0], &layer.vb[1], &layer.vb[2]];
let mut vb_mut0 = vb[0].current_vb_mut();
let mut vb_mut1 = vb[1].current_vb_mut();
let mut vb_mut2 = vb[2].current_vb_mut();
let mut layers = [
vb[0].map(&mut vb_mut0),
vb[1].map(&mut vb_mut1),
vb[2].map(&mut vb_mut2),
];
self.render_element_impl(element, &mut layers, inherited_colors)
}
fn render_element_impl<'a>(
&self,
element: &ComputedElement,
layers: &mut [MappedQuads; 3],
inherited_colors: Option<&ElementColors>, inherited_colors: Option<&ElementColors>,
) -> anyhow::Result<()> { ) -> anyhow::Result<()> {
let colors = match &element.hover_colors { let colors = match &element.hover_colors {
@ -780,7 +800,7 @@ impl super::TermWindow {
None => &element.colors, None => &element.colors,
}; };
self.render_element_background(element, colors, layer, inherited_colors)?; self.render_element_background(element, colors, layers, inherited_colors)?;
let left = self.dimensions.pixel_width as f32 / -2.0; let left = self.dimensions.pixel_width as f32 / -2.0;
let top = self.dimensions.pixel_height as f32 / -2.0; let top = self.dimensions.pixel_height as f32 / -2.0;
match &element.content { match &element.content {
@ -800,7 +820,7 @@ impl super::TermWindow {
break; break;
} }
let mut quad = layer.allocate()?; let mut quad = layers[2].allocate()?;
quad.set_position( quad.set_position(
pos_x + left, pos_x + left,
pos_y, pos_y,
@ -826,7 +846,7 @@ impl super::TermWindow {
break; break;
} }
let mut quad = layer.allocate()?; let mut quad = layers[1].allocate()?;
quad.set_position( quad.set_position(
pos_x + left, pos_x + left,
pos_y, pos_y,
@ -845,13 +865,13 @@ impl super::TermWindow {
} }
ComputedElementContent::Children(kids) => { ComputedElementContent::Children(kids) => {
for kid in kids { for kid in kids {
self.render_element(kid, layer, Some(colors))?; self.render_element_impl(kid, layers, Some(colors))?;
} }
} }
ComputedElementContent::Poly { poly, line_width } => { ComputedElementContent::Poly { poly, line_width } => {
if element.content_rect.width() >= poly.width { if element.content_rect.width() >= poly.width {
self.poly_quad( self.poly_quad(
layer, &mut layers[1],
element.content_rect.origin, element.content_rect.origin,
poly.poly, poly.poly,
*line_width, *line_width,
@ -869,7 +889,7 @@ impl super::TermWindow {
&self, &self,
element: &ComputedElement, element: &ComputedElement,
colors: &ElementColors, colors: &ElementColors,
layer: &'a mut MappedQuads, layers: &mut [MappedQuads; 3],
inherited_colors: Option<&ElementColors>, inherited_colors: Option<&ElementColors>,
) -> anyhow::Result<()> { ) -> anyhow::Result<()> {
let mut top_left_width = 0.; let mut top_left_width = 0.;
@ -895,17 +915,18 @@ impl super::TermWindow {
if top_left_width > 0. && top_left_height > 0. { if top_left_width > 0. && top_left_height > 0. {
self.poly_quad( self.poly_quad(
layer, &mut layers[0],
element.border_rect.origin, element.border_rect.origin,
c.top_left.poly, c.top_left.poly,
element.border.top as isize, element.border.top as isize,
euclid::size2(top_left_width, top_left_height), euclid::size2(top_left_width, top_left_height),
colors.border.top, colors.border.top,
)?; )?
.set_grayscale();
} }
if top_right_width > 0. && top_right_height > 0. { if top_right_width > 0. && top_right_height > 0. {
self.poly_quad( self.poly_quad(
layer, &mut layers[0],
euclid::point2( euclid::point2(
element.border_rect.max_x() - top_right_width, element.border_rect.max_x() - top_right_width,
element.border_rect.min_y(), element.border_rect.min_y(),
@ -914,11 +935,12 @@ impl super::TermWindow {
element.border.top as isize, element.border.top as isize,
euclid::size2(top_right_width, top_right_height), euclid::size2(top_right_width, top_right_height),
colors.border.top, colors.border.top,
)?; )?
.set_grayscale();
} }
if bottom_left_width > 0. && bottom_left_height > 0. { if bottom_left_width > 0. && bottom_left_height > 0. {
self.poly_quad( self.poly_quad(
layer, &mut layers[0],
euclid::point2( euclid::point2(
element.border_rect.min_x(), element.border_rect.min_x(),
element.border_rect.max_y() - bottom_left_height, element.border_rect.max_y() - bottom_left_height,
@ -927,11 +949,12 @@ impl super::TermWindow {
element.border.bottom as isize, element.border.bottom as isize,
euclid::size2(bottom_left_width, bottom_left_height), euclid::size2(bottom_left_width, bottom_left_height),
colors.border.bottom, colors.border.bottom,
)?; )?
.set_grayscale();
} }
if bottom_right_width > 0. && bottom_right_height > 0. { if bottom_right_width > 0. && bottom_right_height > 0. {
self.poly_quad( self.poly_quad(
layer, &mut layers[0],
euclid::point2( euclid::point2(
element.border_rect.max_x() - bottom_right_width, element.border_rect.max_x() - bottom_right_width,
element.border_rect.max_y() - bottom_right_height, element.border_rect.max_y() - bottom_right_height,
@ -940,7 +963,8 @@ impl super::TermWindow {
element.border.bottom as isize, element.border.bottom as isize,
euclid::size2(bottom_right_width, bottom_right_height), euclid::size2(bottom_right_width, bottom_right_height),
colors.border.bottom, colors.border.bottom,
)?; )?
.set_grayscale();
} }
// Filling the background is more complex because we can't // Filling the background is more complex because we can't
@ -957,7 +981,7 @@ impl super::TermWindow {
// The `T` piece // The `T` piece
self.filled_rectangle( self.filled_rectangle(
layer, &mut layers[0],
euclid::rect( euclid::rect(
element.border_rect.min_x() + top_left_width, element.border_rect.min_x() + top_left_width,
element.border_rect.min_y(), element.border_rect.min_y(),
@ -969,7 +993,7 @@ impl super::TermWindow {
// The `B` piece // The `B` piece
self.filled_rectangle( self.filled_rectangle(
layer, &mut layers[0],
euclid::rect( euclid::rect(
element.border_rect.min_x() + bottom_left_width, element.border_rect.min_x() + bottom_left_width,
element.border_rect.max_y() - bottom_left_height.max(bottom_right_height), element.border_rect.max_y() - bottom_left_height.max(bottom_right_height),
@ -981,7 +1005,7 @@ impl super::TermWindow {
// The `L` piece // The `L` piece
self.filled_rectangle( self.filled_rectangle(
layer, &mut layers[0],
euclid::rect( euclid::rect(
element.border_rect.min_x(), element.border_rect.min_x(),
element.border_rect.min_y() + top_left_height, element.border_rect.min_y() + top_left_height,
@ -993,7 +1017,7 @@ impl super::TermWindow {
// The `R` piece // The `R` piece
self.filled_rectangle( self.filled_rectangle(
layer, &mut layers[0],
euclid::rect( euclid::rect(
element.border_rect.max_x() - top_right_width, element.border_rect.max_x() - top_right_width,
element.border_rect.min_y() + top_right_height, element.border_rect.min_y() + top_right_height,
@ -1005,7 +1029,7 @@ impl super::TermWindow {
// The `C` piece // The `C` piece
self.filled_rectangle( self.filled_rectangle(
layer, &mut layers[0],
euclid::rect( euclid::rect(
element.border_rect.min_x() + top_left_width, element.border_rect.min_x() + top_left_width,
element.border_rect.min_y() + top_right_height.min(top_left_height), element.border_rect.min_y() + top_right_height.min(top_left_height),
@ -1017,7 +1041,11 @@ impl super::TermWindow {
colors.resolve_bg(inherited_colors), colors.resolve_bg(inherited_colors),
)?; )?;
} else if colors.bg != InheritableColor::Color(LinearRgba::TRANSPARENT) { } else if colors.bg != InheritableColor::Color(LinearRgba::TRANSPARENT) {
self.filled_rectangle(layer, element.padding, colors.resolve_bg(inherited_colors))?; self.filled_rectangle(
&mut layers[0],
element.padding,
colors.resolve_bg(inherited_colors),
)?;
} }
if element.border_rect == element.padding { if element.border_rect == element.padding {
@ -1027,7 +1055,7 @@ impl super::TermWindow {
if element.border.top > 0. && colors.border.top != LinearRgba::TRANSPARENT { if element.border.top > 0. && colors.border.top != LinearRgba::TRANSPARENT {
self.filled_rectangle( self.filled_rectangle(
layer, &mut layers[0],
euclid::rect( euclid::rect(
element.border_rect.min_x() + top_left_width as f32, element.border_rect.min_x() + top_left_width as f32,
element.border_rect.min_y(), element.border_rect.min_y(),
@ -1039,7 +1067,7 @@ impl super::TermWindow {
} }
if element.border.bottom > 0. && colors.border.bottom != LinearRgba::TRANSPARENT { if element.border.bottom > 0. && colors.border.bottom != LinearRgba::TRANSPARENT {
self.filled_rectangle( self.filled_rectangle(
layer, &mut layers[0],
euclid::rect( euclid::rect(
element.border_rect.min_x() + bottom_left_width as f32, element.border_rect.min_x() + bottom_left_width as f32,
element.border_rect.max_y() - element.border.bottom, element.border_rect.max_y() - element.border.bottom,
@ -1051,7 +1079,7 @@ impl super::TermWindow {
} }
if element.border.left > 0. && colors.border.left != LinearRgba::TRANSPARENT { if element.border.left > 0. && colors.border.left != LinearRgba::TRANSPARENT {
self.filled_rectangle( self.filled_rectangle(
layer, &mut layers[0],
euclid::rect( euclid::rect(
element.border_rect.min_x(), element.border_rect.min_x(),
element.border_rect.min_y() + top_left_height as f32, element.border_rect.min_y() + top_left_height as f32,
@ -1063,7 +1091,7 @@ impl super::TermWindow {
} }
if element.border.right > 0. && colors.border.right != LinearRgba::TRANSPARENT { if element.border.right > 0. && colors.border.right != LinearRgba::TRANSPARENT {
self.filled_rectangle( self.filled_rectangle(
layer, &mut layers[0],
euclid::rect( euclid::rect(
element.border_rect.max_x() - element.border.right, element.border_rect.max_x() - element.border.right,
element.border_rect.min_y() + top_right_height as f32, element.border_rect.min_y() + top_right_height as f32,

View File

@ -1,14 +1,14 @@
use crate::termwindow::box_model::*; use crate::termwindow::box_model::*;
use crate::termwindow::modal::Modal; use crate::termwindow::modal::Modal;
use crate::termwindow::render::{ use crate::termwindow::render::{
rgbcolor_to_window_color, BOTTOM_LEFT_ROUNDED_CORNER, BOTTOM_RIGHT_ROUNDED_CORNER, BOTTOM_LEFT_ROUNDED_CORNER, BOTTOM_RIGHT_ROUNDED_CORNER, TOP_LEFT_ROUNDED_CORNER,
TOP_LEFT_ROUNDED_CORNER, TOP_RIGHT_ROUNDED_CORNER, TOP_RIGHT_ROUNDED_CORNER,
}; };
use crate::termwindow::DimensionContext; use crate::termwindow::DimensionContext;
use crate::utilsprites::RenderMetrics; use crate::utilsprites::RenderMetrics;
use crate::TermWindow; use crate::TermWindow;
use config::keyassignment::{KeyAssignment, PaneSelectArguments, PaneSelectMode}; use config::keyassignment::{KeyAssignment, PaneSelectArguments, PaneSelectMode};
use config::{Dimension, TabBarColors}; use config::Dimension;
use mux::Mux; use mux::Mux;
use std::cell::{Ref, RefCell}; use std::cell::{Ref, RefCell};
use wezterm_term::{KeyCode, KeyModifiers, MouseEvent}; use wezterm_term::{KeyCode, KeyModifiers, MouseEvent};
@ -60,24 +60,16 @@ impl PaneSelector {
let labels = let labels =
crate::overlay::quickselect::compute_labels_for_alphabet(alphabet, panes.len()); crate::overlay::quickselect::compute_labels_for_alphabet(alphabet, panes.len());
let colors = term_window
.config
.colors
.as_ref()
.and_then(|c| c.tab_bar.as_ref())
.cloned()
.unwrap_or_else(TabBarColors::default);
let mut elements = vec![]; let mut elements = vec![];
for pos in panes { for pos in panes {
let caption = labels[pos.index].clone(); let caption = labels[pos.index].clone();
let element = Element::new(&font, ElementContent::Text(caption)) let element = Element::new(&font, ElementContent::Text(caption))
.colors(ElementColors { .colors(ElementColors {
border: BorderColor::new( border: BorderColor::new(
rgbcolor_to_window_color(colors.active_tab.bg_color).into(), term_window.config.pane_select_bg_color.to_linear().into(),
), ),
bg: rgbcolor_to_window_color(colors.active_tab.bg_color).into(), bg: term_window.config.pane_select_bg_color.to_linear().into(),
text: rgbcolor_to_window_color(colors.active_tab.fg_color).into(), text: term_window.config.pane_select_fg_color.to_linear().into(),
}) })
.padding(BoxDimension { .padding(BoxDimension {
left: Dimension::Cells(0.25), left: Dimension::Cells(0.25),

View File

@ -837,10 +837,7 @@ impl super::TermWindow {
let mut ui_items = computed.ui_items(); let mut ui_items = computed.ui_items();
let gl_state = self.render_state.as_ref().unwrap(); let gl_state = self.render_state.as_ref().unwrap();
let vb = &gl_state.modal_layer.vb[1]; self.render_element(&computed, &gl_state.modal_layer, None)?;
let mut vb_mut = vb.current_vb_mut();
let mut layer1 = vb.map(&mut vb_mut);
self.render_element(&computed, &mut layer1, None)?;
self.ui_items.append(&mut ui_items); self.ui_items.append(&mut ui_items);
} }
@ -857,10 +854,7 @@ impl super::TermWindow {
let ui_items = computed.ui_items(); let ui_items = computed.ui_items();
let gl_state = self.render_state.as_ref().unwrap(); let gl_state = self.render_state.as_ref().unwrap();
let vb = &gl_state.tab_layer.vb[1]; self.render_element(&computed, &gl_state.tab_layer, None)?;
let mut vb_mut = vb.current_vb_mut();
let mut layer1 = vb.map(&mut vb_mut);
self.render_element(&computed, &mut layer1, None)?;
Ok(ui_items) Ok(ui_items)
} }