mirror of
https://github.com/wez/wezterm.git
synced 2024-09-20 11:17:15 +03:00
gui: fixup window transparency
This commit is contained in:
parent
406782fb31
commit
0158e8e49a
@ -270,7 +270,10 @@ impl ImageDataType {
|
||||
Self::EncodedFile(data) => {
|
||||
let format = match image::guess_format(&data) {
|
||||
Ok(format) => format,
|
||||
_ => return Self::EncodedFile(data),
|
||||
Err(err) => {
|
||||
log::warn!("Unable to decode raw image data: {:#}", err);
|
||||
return Self::EncodedFile(data);
|
||||
}
|
||||
};
|
||||
match format {
|
||||
ImageFormat::Gif => image::gif::GifDecoder::new(&*data)
|
||||
@ -297,7 +300,7 @@ impl ImageDataType {
|
||||
Self::decode_single(data)
|
||||
}
|
||||
}
|
||||
_ => Self::EncodedFile(data),
|
||||
_ => Self::decode_single(data),
|
||||
}
|
||||
}
|
||||
data => data,
|
||||
@ -370,7 +373,7 @@ impl PartialEq for ImageData {
|
||||
impl ImageData {
|
||||
/// Create a new ImageData struct with the provided raw data.
|
||||
pub fn with_raw_data(data: Vec<u8>) -> Self {
|
||||
Self::with_data(ImageDataType::EncodedFile(data))
|
||||
Self::with_data(ImageDataType::EncodedFile(data).decode())
|
||||
}
|
||||
|
||||
pub fn with_data(data: ImageDataType) -> Self {
|
||||
|
@ -14,11 +14,13 @@ use ::window::{Point, Rect};
|
||||
use anyhow::Context;
|
||||
use config::{AllowSquareGlyphOverflow, TextStyle};
|
||||
use euclid::num::Zero;
|
||||
use ordered_float::NotNan;
|
||||
use std::collections::HashMap;
|
||||
use std::convert::TryInto;
|
||||
use std::rc::Rc;
|
||||
use std::sync::{Arc, MutexGuard};
|
||||
use std::time::Instant;
|
||||
use termwiz::color::RgbColor;
|
||||
use termwiz::image::{ImageData, ImageDataType};
|
||||
use termwiz::surface::CursorShape;
|
||||
use wezterm_font::units::*;
|
||||
@ -217,6 +219,7 @@ pub struct GlyphCache<T: Texture2d> {
|
||||
line_glyphs: HashMap<LineKey, Sprite<T>>,
|
||||
pub block_glyphs: HashMap<BlockKey, Sprite<T>>,
|
||||
pub cursor_glyphs: HashMap<Option<CursorShape>, Sprite<T>>,
|
||||
pub color: HashMap<(RgbColor, NotNan<f32>), Sprite<T>>,
|
||||
pub metrics: RenderMetrics,
|
||||
}
|
||||
|
||||
@ -244,6 +247,7 @@ impl GlyphCache<ImageTexture> {
|
||||
line_glyphs: HashMap::new(),
|
||||
block_glyphs: HashMap::new(),
|
||||
cursor_glyphs: HashMap::new(),
|
||||
color: HashMap::new(),
|
||||
})
|
||||
}
|
||||
}
|
||||
@ -296,6 +300,7 @@ impl GlyphCache<SrgbTexture2d> {
|
||||
line_glyphs: HashMap::new(),
|
||||
block_glyphs: HashMap::new(),
|
||||
cursor_glyphs: HashMap::new(),
|
||||
color: HashMap::new(),
|
||||
})
|
||||
}
|
||||
}
|
||||
@ -627,6 +632,27 @@ impl<T: Texture2d> GlyphCache<T> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn cached_color(&mut self, color: RgbColor, alpha: f32) -> anyhow::Result<Sprite<T>> {
|
||||
let key = (color, NotNan::new(alpha).unwrap());
|
||||
|
||||
if let Some(s) = self.color.get(&key) {
|
||||
return Ok(s.clone());
|
||||
}
|
||||
|
||||
let (red, green, blue) = color.to_tuple_rgb8();
|
||||
let alpha = (alpha * 255.0) as u8;
|
||||
|
||||
let data = vec![
|
||||
red, green, blue, alpha, red, green, blue, alpha, red, green, blue, alpha, red, green,
|
||||
blue, alpha,
|
||||
];
|
||||
let image = Image::from_raw(2, 2, data);
|
||||
|
||||
let sprite = self.atlas.allocate(&image)?;
|
||||
self.color.insert(key, sprite.clone());
|
||||
Ok(sprite)
|
||||
}
|
||||
|
||||
pub fn cached_block(&mut self, block: BlockKey) -> anyhow::Result<Sprite<T>> {
|
||||
if let Some(s) = self.block_glyphs.get(&block) {
|
||||
return Ok(s.clone());
|
||||
|
@ -343,7 +343,8 @@ fn load_background_image(config: &ConfigHandle) -> Option<Arc<ImageData>> {
|
||||
Some(p) => match std::fs::read(p) {
|
||||
Ok(data) => {
|
||||
log::info!("loaded {}", p.display());
|
||||
Some(Arc::new(ImageData::with_raw_data(data)))
|
||||
let data = ImageDataType::EncodedFile(data).decode();
|
||||
Some(Arc::new(ImageData::with_data(data)))
|
||||
}
|
||||
Err(err) => {
|
||||
log::error!(
|
||||
|
@ -282,6 +282,7 @@ impl super::TermWindow {
|
||||
self.dimensions.pixel_height as f32 / 2.,
|
||||
);
|
||||
quad.set_texture_adjust(0., 0., 0., 0.);
|
||||
quad.set_is_background_image();
|
||||
|
||||
match (self.window_background.as_ref(), self.allow_images) {
|
||||
(Some(im), true) => {
|
||||
@ -295,7 +296,6 @@ impl super::TermWindow {
|
||||
gl_state.glyph_cache.borrow_mut().cached_image(im, None)?;
|
||||
self.update_next_frame_time(next_due);
|
||||
quad.set_texture(sprite.texture_coords());
|
||||
quad.set_is_background_image();
|
||||
quad.set_hsv(config.window_background_image_hsb);
|
||||
quad.set_fg_color(color);
|
||||
}
|
||||
@ -303,12 +303,16 @@ impl super::TermWindow {
|
||||
// Regular window background color
|
||||
let background = rgbcolor_alpha_to_window_color(
|
||||
global_bg_color,
|
||||
self.config.window_background_opacity,
|
||||
config.window_background_opacity,
|
||||
);
|
||||
quad.set_texture(
|
||||
gl_state
|
||||
.glyph_cache
|
||||
.borrow_mut()
|
||||
.cached_color(global_bg_color, config.window_background_opacity)?
|
||||
.texture_coords(),
|
||||
);
|
||||
quad.set_texture(filled_box);
|
||||
quad.set_fg_color(background);
|
||||
quad.set_bg_color(background);
|
||||
quad.set_has_color(false);
|
||||
quad.set_hsv(None);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user