From 8b4a9d68e0ba8093e88d20f3a003f78ef27cac0e Mon Sep 17 00:00:00 2001 From: Ivan Molodetskikh Date: Sun, 24 Mar 2024 08:30:26 +0400 Subject: Implement opacity window rule --- src/layout/mod.rs | 2 ++ src/layout/tile.rs | 8 +++++++- src/window/mapped.rs | 3 ++- src/window/mod.rs | 7 +++++++ 4 files changed, 18 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/layout/mod.rs b/src/layout/mod.rs index bc5c8dcf..bbca41c9 100644 --- a/src/layout/mod.rs +++ b/src/layout/mod.rs @@ -95,6 +95,7 @@ pub trait LayoutElement { renderer: &mut R, location: Point, scale: Scale, + alpha: f32, ) -> Vec>; fn request_size(&self, size: Size); @@ -1856,6 +1857,7 @@ mod tests { _renderer: &mut R, _location: Point, _scale: Scale, + _alpha: f32, ) -> Vec> { vec![] } diff --git a/src/layout/tile.rs b/src/layout/tile.rs index 0609583e..faa17840 100644 --- a/src/layout/tile.rs +++ b/src/layout/tile.rs @@ -325,9 +325,15 @@ impl Tile { view_size: Size, focus_ring: bool, ) -> impl Iterator> { + let alpha = if self.is_fullscreen { + 1. + } else { + self.window.rules().opacity.unwrap_or(1.).clamp(0., 1.) + }; + let rv = self .window - .render(renderer, location + self.window_loc(), scale) + .render(renderer, location + self.window_loc(), scale, alpha) .into_iter() .map(Into::into); diff --git a/src/window/mapped.rs b/src/window/mapped.rs index a48ca636..52b9ac92 100644 --- a/src/window/mapped.rs +++ b/src/window/mapped.rs @@ -108,13 +108,14 @@ impl LayoutElement for Mapped { renderer: &mut R, location: Point, scale: Scale, + alpha: f32, ) -> Vec> { let buf_pos = location - self.window.geometry().loc; self.window.render_elements( renderer, buf_pos.to_physical_precise_round(scale), scale, - 1., + alpha, ) } diff --git a/src/window/mod.rs b/src/window/mod.rs index 63cdbe3f..ddf712b0 100644 --- a/src/window/mod.rs +++ b/src/window/mod.rs @@ -52,6 +52,9 @@ pub struct ResolvedWindowRules { /// /// `None` means using the SSD heuristic. pub draw_border_with_background: Option, + + /// Extra opacity to draw this window with. + pub opacity: Option, } impl<'a> WindowRef<'a> { @@ -82,6 +85,7 @@ impl ResolvedWindowRules { max_width: None, max_height: None, draw_border_with_background: None, + opacity: None, } } @@ -153,6 +157,9 @@ impl ResolvedWindowRules { if let Some(x) = rule.draw_border_with_background { resolved.draw_border_with_background = Some(x); } + if let Some(x) = rule.opacity { + resolved.opacity = Some(x); + } } resolved.open_on_output = open_on_output.map(|x| x.to_owned()); -- cgit