forge
Explore
Log in

Don't you dare go Hollow

Implement opacity window rule

Browse files at this commit

8b4a9d68e0ba8093e88d20f3a003f78ef27cac0eIvan MolodetskikhParent: a16a0f0
niri-config/src/lib.rsmodified+2 -0
@@ -697,6 +697,8 @@ pub struct WindowRule {
697 697
698 #[knuffel(child, unwrap(argument))]698 #[knuffel(child, unwrap(argument))]
699 pub draw_border_with_background: Option<bool>,699 pub draw_border_with_background: Option<bool>,
700+ #[knuffel(child, unwrap(argument))]
701+ pub opacity: Option<f32>,
700 }702 }
701 703
702 // Remember to update the PartialEq impl when adding fields!704 // Remember to update the PartialEq impl when adding fields!
niri-visual-tests/src/cases/window.rsmodified+1 -1
@@ -49,7 +49,7 @@ impl TestCase for Window {
49 let location = Point::from(((size.w - win_size.w) / 2, (size.h - win_size.h) / 2));49 let location = Point::from(((size.w - win_size.w) / 2, (size.h - win_size.h) / 2));
50 50
51 self.window51 self.window
52- .render(renderer, location, Scale::from(1.))52+ .render(renderer, location, Scale::from(1.), 1.)
53 .into_iter()53 .into_iter()
54 .map(|elem| Box::new(elem) as _)54 .map(|elem| Box::new(elem) as _)
55 .collect()55 .collect()
niri-visual-tests/src/test_window.rsmodified+3 -2
@@ -146,6 +146,7 @@ impl LayoutElement for TestWindow {
146 _renderer: &mut R,146 _renderer: &mut R,
147 location: Point<i32, Logical>,147 location: Point<i32, Logical>,
148 scale: Scale<f64>,148 scale: Scale<f64>,
149+ alpha: f32,
149 ) -> Vec<LayoutElementRenderElement<R>> {150 ) -> Vec<LayoutElementRenderElement<R>> {
150 let inner = self.inner.borrow();151 let inner = self.inner.borrow();
151 152
@@ -154,7 +155,7 @@ impl LayoutElement for TestWindow {
154 &inner.buffer,155 &inner.buffer,
155 location.to_physical_precise_round(scale),156 location.to_physical_precise_round(scale),
156 scale,157 scale,
157- 1.,158+ alpha,
158 Kind::Unspecified,159 Kind::Unspecified,
159 )160 )
160 .into(),161 .into(),
@@ -163,7 +164,7 @@ impl LayoutElement for TestWindow {
163 (location - Point::from((inner.csd_shadow_width, inner.csd_shadow_width)))164 (location - Point::from((inner.csd_shadow_width, inner.csd_shadow_width)))
164 .to_physical_precise_round(scale),165 .to_physical_precise_round(scale),
165 scale,166 scale,
166- 1.,167+ alpha,
167 Kind::Unspecified,168 Kind::Unspecified,
168 )169 )
169 .into(),170 .into(),
resources/default-config.kdlmodified+10 -0
@@ -414,6 +414,16 @@ animations {
414 // Set this to `false` to draw them as borders around the window even for414 // Set this to `false` to draw them as borders around the window even for
415 // windows which use client-side decorations.415 // windows which use client-side decorations.
416 draw-border-with-background false416 draw-border-with-background false
417+
418+ // Set the opacity of the window.
419+ // This is applied on top of the window's own opacity, so semitransparent
420+ // windows will become even more transparent.
421+ // Opacity is applied to every surface of the window individually, so
422+ // subsurfaces and pop-up menus will show window content behind them.
423+ // Also, focus ring and border with background will show through
424+ // semitransparent windows (see prefer-no-csd and
425+ // the draw-border-with-background property above).
426+ opacity 0.5
417 }427 }
418 428
419 // Here's a useful example. Work around WezTerm's initial configure bug429 // Here's a useful example. Work around WezTerm's initial configure bug
src/layout/mod.rsmodified+2 -0
@@ -95,6 +95,7 @@ pub trait LayoutElement {
95 renderer: &mut R,95 renderer: &mut R,
96 location: Point<i32, Logical>,96 location: Point<i32, Logical>,
97 scale: Scale<f64>,97 scale: Scale<f64>,
98+ alpha: f32,
98 ) -> Vec<LayoutElementRenderElement<R>>;99 ) -> Vec<LayoutElementRenderElement<R>>;
99 100
100 fn request_size(&self, size: Size<i32, Logical>);101 fn request_size(&self, size: Size<i32, Logical>);
@@ -1856,6 +1857,7 @@ mod tests {
1856 _renderer: &mut R,1857 _renderer: &mut R,
1857 _location: Point<i32, Logical>,1858 _location: Point<i32, Logical>,
1858 _scale: Scale<f64>,1859 _scale: Scale<f64>,
1860+ _alpha: f32,
1859 ) -> Vec<LayoutElementRenderElement<R>> {1861 ) -> Vec<LayoutElementRenderElement<R>> {
1860 vec![]1862 vec![]
1861 }1863 }
src/layout/tile.rsmodified+7 -1
@@ -325,9 +325,15 @@ impl<W: LayoutElement> Tile<W> {
325 view_size: Size<i32, Logical>,325 view_size: Size<i32, Logical>,
326 focus_ring: bool,326 focus_ring: bool,
327 ) -> impl Iterator<Item = TileRenderElement<R>> {327 ) -> impl Iterator<Item = TileRenderElement<R>> {
328+ let alpha = if self.is_fullscreen {
329+ 1.
330+ } else {
331+ self.window.rules().opacity.unwrap_or(1.).clamp(0., 1.)
332+ };
333+
328 let rv = self334 let rv = self
329 .window335 .window
330- .render(renderer, location + self.window_loc(), scale)336+ .render(renderer, location + self.window_loc(), scale, alpha)
331 .into_iter()337 .into_iter()
332 .map(Into::into);338 .map(Into::into);
333 339
src/window/mapped.rsmodified+2 -1
@@ -108,13 +108,14 @@ impl LayoutElement for Mapped {
108 renderer: &mut R,108 renderer: &mut R,
109 location: Point<i32, Logical>,109 location: Point<i32, Logical>,
110 scale: Scale<f64>,110 scale: Scale<f64>,
111+ alpha: f32,
111 ) -> Vec<LayoutElementRenderElement<R>> {112 ) -> Vec<LayoutElementRenderElement<R>> {
112 let buf_pos = location - self.window.geometry().loc;113 let buf_pos = location - self.window.geometry().loc;
113 self.window.render_elements(114 self.window.render_elements(
114 renderer,115 renderer,
115 buf_pos.to_physical_precise_round(scale),116 buf_pos.to_physical_precise_round(scale),
116 scale,117 scale,
117- 1.,118+ alpha,
118 )119 )
119 }120 }
120 121
src/window/mod.rsmodified+7 -0
@@ -52,6 +52,9 @@ pub struct ResolvedWindowRules {
52 ///52 ///
53 /// `None` means using the SSD heuristic.53 /// `None` means using the SSD heuristic.
54 pub draw_border_with_background: Option<bool>,54 pub draw_border_with_background: Option<bool>,
55+
56+ /// Extra opacity to draw this window with.
57+ pub opacity: Option<f32>,
55 }58 }
56 59
57 impl<'a> WindowRef<'a> {60 impl<'a> WindowRef<'a> {
@@ -82,6 +85,7 @@ impl ResolvedWindowRules {
82 max_width: None,85 max_width: None,
83 max_height: None,86 max_height: None,
84 draw_border_with_background: None,87 draw_border_with_background: None,
88+ opacity: None,
85 }89 }
86 }90 }
87 91
@@ -153,6 +157,9 @@ impl ResolvedWindowRules {
153 if let Some(x) = rule.draw_border_with_background {157 if let Some(x) = rule.draw_border_with_background {
154 resolved.draw_border_with_background = Some(x);158 resolved.draw_border_with_background = Some(x);
155 }159 }
160+ if let Some(x) = rule.opacity {
161+ resolved.opacity = Some(x);
162+ }
156 }163 }
157 164
158 resolved.open_on_output = open_on_output.map(|x| x.to_owned());165 resolved.open_on_output = open_on_output.map(|x| x.to_owned());