mirror of
https://github.com/wez/wezterm.git
synced 2024-12-28 07:55:03 +03:00
background: refactor where we trigger background painting
moving it so that we have access to the full set of positioned panes in a subsequent commit.
This commit is contained in:
parent
27511c59ef
commit
08d2ec67dc
@ -1,3 +1,4 @@
|
||||
use crate::color::LinearRgba;
|
||||
use crate::termwindow::RenderState;
|
||||
use crate::Dimensions;
|
||||
use anyhow::Context;
|
||||
@ -9,7 +10,6 @@ use std::collections::HashMap;
|
||||
use std::sync::{Arc, Mutex};
|
||||
use std::time::SystemTime;
|
||||
use termwiz::image::{ImageData, ImageDataType};
|
||||
use wezterm_term::color::ColorPalette;
|
||||
|
||||
lazy_static::lazy_static! {
|
||||
static ref IMAGE_CACHE: Mutex<HashMap<String, CachedImage>> = Mutex::new(HashMap::new());
|
||||
@ -266,13 +266,10 @@ pub fn reload_background_image(
|
||||
}
|
||||
|
||||
impl crate::TermWindow {
|
||||
pub fn render_backgrounds(
|
||||
&self,
|
||||
gl_state: &RenderState,
|
||||
palette: &ColorPalette,
|
||||
) -> anyhow::Result<()> {
|
||||
pub fn render_backgrounds(&self, bg_color: LinearRgba) -> anyhow::Result<()> {
|
||||
let gl_state = self.render_state.as_ref().unwrap();
|
||||
for (idx, layer) in self.window_background.iter().enumerate() {
|
||||
self.render_background(gl_state, palette, layer, idx)?;
|
||||
self.render_background(gl_state, bg_color, layer, idx)?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
@ -280,7 +277,7 @@ impl crate::TermWindow {
|
||||
fn render_background(
|
||||
&self,
|
||||
gl_state: &RenderState,
|
||||
palette: &ColorPalette,
|
||||
bg_color: LinearRgba,
|
||||
layer: &LoadedBackgroundLayer,
|
||||
layer_index: usize,
|
||||
) -> anyhow::Result<()> {
|
||||
@ -289,7 +286,7 @@ impl crate::TermWindow {
|
||||
let mut vb_mut0 = vbs[0].current_vb_mut();
|
||||
let mut layer0 = vbs[0].map(&mut vb_mut0);
|
||||
|
||||
let color = palette.background.to_linear().mul_alpha(layer.def.opacity);
|
||||
let color = bg_color.mul_alpha(layer.def.opacity);
|
||||
|
||||
let (sprite, next_due) = gl_state
|
||||
.glyph_cache
|
||||
|
@ -1040,7 +1040,6 @@ impl super::TermWindow {
|
||||
};
|
||||
*/
|
||||
|
||||
let global_bg_color = self.palette().background;
|
||||
let global_cursor_fg = self.palette().cursor_fg;
|
||||
let global_cursor_bg = self.palette().cursor_bg;
|
||||
let config = &self.config;
|
||||
@ -1124,42 +1123,6 @@ impl super::TermWindow {
|
||||
config.text_background_opacity
|
||||
});
|
||||
|
||||
// Render the full window background
|
||||
if pos.index == 0 {
|
||||
match (self.window_background.is_empty(), self.allow_images) {
|
||||
(false, true) => {
|
||||
self.render_backgrounds(gl_state, &palette)?;
|
||||
}
|
||||
_ if window_is_transparent && num_panes > 1 => {
|
||||
// Avoid doubling up the background color: the panes
|
||||
// will render out through the padding so there
|
||||
// should be no gaps that need filling in
|
||||
}
|
||||
_ => {
|
||||
// Regular window background color
|
||||
let background = if num_panes == 1 {
|
||||
// If we're the only pane, use the pane's palette
|
||||
// to draw the padding background
|
||||
palette.background
|
||||
} else {
|
||||
global_bg_color
|
||||
}
|
||||
.to_linear()
|
||||
.mul_alpha(config.window_background_opacity);
|
||||
self.filled_rectangle(
|
||||
&mut layers[0],
|
||||
euclid::rect(
|
||||
0.,
|
||||
0.,
|
||||
self.dimensions.pixel_width as f32,
|
||||
self.dimensions.pixel_height as f32,
|
||||
),
|
||||
background,
|
||||
)?;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if num_panes > 1 && self.window_background.is_empty() {
|
||||
// Per-pane, palette-specified background
|
||||
let cell_width = self.render_metrics.cell_size.width as f32;
|
||||
@ -1643,6 +1606,50 @@ impl super::TermWindow {
|
||||
let panes = self.get_panes_to_render();
|
||||
let num_panes = panes.len();
|
||||
let focused = self.focused.is_some();
|
||||
let window_is_transparent =
|
||||
!self.window_background.is_empty() || self.config.window_background_opacity != 1.0;
|
||||
|
||||
// Render the full window background
|
||||
match (self.window_background.is_empty(), self.allow_images) {
|
||||
(false, true) => {
|
||||
let bg_color = self.palette().background.to_linear();
|
||||
self.render_backgrounds(bg_color)?;
|
||||
}
|
||||
_ if window_is_transparent && panes.len() > 1 => {
|
||||
// Avoid doubling up the background color: the panes
|
||||
// will render out through the padding so there
|
||||
// should be no gaps that need filling in
|
||||
}
|
||||
_ => {
|
||||
// Regular window background color
|
||||
let background = if panes.len() == 1 {
|
||||
// If we're the only pane, use the pane's palette
|
||||
// to draw the padding background
|
||||
panes[0].pane.palette().background
|
||||
} else {
|
||||
self.palette().background
|
||||
}
|
||||
.to_linear()
|
||||
.mul_alpha(self.config.window_background_opacity);
|
||||
|
||||
let gl_state = self.render_state.as_ref().unwrap();
|
||||
let render_layer = gl_state.layer_for_zindex(0)?;
|
||||
let vbs = render_layer.vb.borrow();
|
||||
let mut vb_mut0 = vbs[0].current_vb_mut();
|
||||
let mut layer0 = vbs[0].map(&mut vb_mut0);
|
||||
|
||||
self.filled_rectangle(
|
||||
&mut layer0,
|
||||
euclid::rect(
|
||||
0.,
|
||||
0.,
|
||||
self.dimensions.pixel_width as f32,
|
||||
self.dimensions.pixel_height as f32,
|
||||
),
|
||||
background,
|
||||
)?;
|
||||
}
|
||||
}
|
||||
|
||||
for pos in panes {
|
||||
if pos.is_active {
|
||||
|
Loading…
Reference in New Issue
Block a user