diff options
| author | Ivan Molodetskikh <yalterz@gmail.com> | 2025-02-08 13:33:28 +0300 |
|---|---|---|
| committer | Ivan Molodetskikh <yalterz@gmail.com> | 2025-02-10 07:29:33 -0800 |
| commit | 4f05a74aa84bca74b650cffdc7ad889413f621cf (patch) | |
| tree | 9bf496dde8954c60fb5ba232a2f2b10babcd9de5 | |
| parent | c30f522ef28ed01744f5c90150af8a9c4da558f1 (diff) | |
| download | niri-4f05a74aa84bca74b650cffdc7ad889413f621cf.tar.gz niri-4f05a74aa84bca74b650cffdc7ad889413f621cf.tar.bz2 niri-4f05a74aa84bca74b650cffdc7ad889413f621cf.zip | |
Add alpha parameter to shaders
Lets us add extra opacity.
22 files changed, 50 insertions, 4 deletions
diff --git a/niri-visual-tests/src/cases/gradient_angle.rs b/niri-visual-tests/src/cases/gradient_angle.rs index 807e7aa6..6cf666c1 100644 --- a/niri-visual-tests/src/cases/gradient_angle.rs +++ b/niri-visual-tests/src/cases/gradient_angle.rs @@ -63,6 +63,7 @@ impl TestCase for GradientAngle { 0., CornerRadius::default(), 1., + 1., ) .with_location(area.loc)] .into_iter() diff --git a/niri-visual-tests/src/cases/gradient_area.rs b/niri-visual-tests/src/cases/gradient_area.rs index 73b71ce9..290e0a82 100644 --- a/niri-visual-tests/src/cases/gradient_area.rs +++ b/niri-visual-tests/src/cases/gradient_area.rs @@ -84,6 +84,7 @@ impl TestCase for GradientArea { Rectangle::default(), CornerRadius::default(), 1., + 1., ); rv.extend( self.border @@ -103,6 +104,7 @@ impl TestCase for GradientArea { 0., CornerRadius::default(), 1., + 1., ) .with_location(area.loc)] .into_iter() diff --git a/niri-visual-tests/src/cases/gradient_oklab.rs b/niri-visual-tests/src/cases/gradient_oklab.rs index 8230be99..c933d278 100644 --- a/niri-visual-tests/src/cases/gradient_oklab.rs +++ b/niri-visual-tests/src/cases/gradient_oklab.rs @@ -44,6 +44,7 @@ impl TestCase for GradientOklab { 0., CornerRadius::default(), 1., + 1., ) .with_location(area.loc)] .into_iter() diff --git a/niri-visual-tests/src/cases/gradient_oklab_alpha.rs b/niri-visual-tests/src/cases/gradient_oklab_alpha.rs index 372bfb47..a0d65f92 100644 --- a/niri-visual-tests/src/cases/gradient_oklab_alpha.rs +++ b/niri-visual-tests/src/cases/gradient_oklab_alpha.rs @@ -42,6 +42,7 @@ impl TestCase for GradientOklabAlpha { 0., CornerRadius::default(), 1., + 1., ) .with_location(area.loc)] .into_iter() diff --git a/niri-visual-tests/src/cases/gradient_oklch_alpha.rs b/niri-visual-tests/src/cases/gradient_oklch_alpha.rs index 0c649b0d..ebcfb09a 100644 --- a/niri-visual-tests/src/cases/gradient_oklch_alpha.rs +++ b/niri-visual-tests/src/cases/gradient_oklch_alpha.rs @@ -44,6 +44,7 @@ impl TestCase for GradientOklchAlpha { 0., CornerRadius::default(), 1., + 1., ) .with_location(area.loc)] .into_iter() diff --git a/niri-visual-tests/src/cases/gradient_oklch_decreasing.rs b/niri-visual-tests/src/cases/gradient_oklch_decreasing.rs index b693e032..fb604fae 100644 --- a/niri-visual-tests/src/cases/gradient_oklch_decreasing.rs +++ b/niri-visual-tests/src/cases/gradient_oklch_decreasing.rs @@ -44,6 +44,7 @@ impl TestCase for GradientOklchDecreasing { 0., CornerRadius::default(), 1., + 1., ) .with_location(area.loc)] .into_iter() diff --git a/niri-visual-tests/src/cases/gradient_oklch_increasing.rs b/niri-visual-tests/src/cases/gradient_oklch_increasing.rs index e562f170..776b0d51 100644 --- a/niri-visual-tests/src/cases/gradient_oklch_increasing.rs +++ b/niri-visual-tests/src/cases/gradient_oklch_increasing.rs @@ -44,6 +44,7 @@ impl TestCase for GradientOklchIncreasing { 0., CornerRadius::default(), 1., + 1., ) .with_location(area.loc)] .into_iter() diff --git a/niri-visual-tests/src/cases/gradient_oklch_longer.rs b/niri-visual-tests/src/cases/gradient_oklch_longer.rs index bb3c5de0..870b1175 100644 --- a/niri-visual-tests/src/cases/gradient_oklch_longer.rs +++ b/niri-visual-tests/src/cases/gradient_oklch_longer.rs @@ -44,6 +44,7 @@ impl TestCase for GradientOklchLonger { 0., CornerRadius::default(), 1., + 1., ) .with_location(area.loc)] .into_iter() diff --git a/niri-visual-tests/src/cases/gradient_oklch_shorter.rs b/niri-visual-tests/src/cases/gradient_oklch_shorter.rs index d0103f30..5622ac35 100644 --- a/niri-visual-tests/src/cases/gradient_oklch_shorter.rs +++ b/niri-visual-tests/src/cases/gradient_oklch_shorter.rs @@ -44,6 +44,7 @@ impl TestCase for GradientOklchShorter { 0., CornerRadius::default(), 1., + 1., ) .with_location(area.loc)] .into_iter() diff --git a/niri-visual-tests/src/cases/gradient_srgb.rs b/niri-visual-tests/src/cases/gradient_srgb.rs index 6e704e29..4afc69b6 100644 --- a/niri-visual-tests/src/cases/gradient_srgb.rs +++ b/niri-visual-tests/src/cases/gradient_srgb.rs @@ -44,6 +44,7 @@ impl TestCase for GradientSrgb { 0., CornerRadius::default(), 1., + 1., ) .with_location(area.loc)] .into_iter() diff --git a/niri-visual-tests/src/cases/gradient_srgb_alpha.rs b/niri-visual-tests/src/cases/gradient_srgb_alpha.rs index 237bfad4..1cb602fa 100644 --- a/niri-visual-tests/src/cases/gradient_srgb_alpha.rs +++ b/niri-visual-tests/src/cases/gradient_srgb_alpha.rs @@ -42,6 +42,7 @@ impl TestCase for GradientSrgbAlpha { 0., CornerRadius::default(), 1., + 1., ) .with_location(area.loc)] .into_iter() diff --git a/niri-visual-tests/src/cases/gradient_srgblinear.rs b/niri-visual-tests/src/cases/gradient_srgblinear.rs index a154971c..5c24275f 100644 --- a/niri-visual-tests/src/cases/gradient_srgblinear.rs +++ b/niri-visual-tests/src/cases/gradient_srgblinear.rs @@ -44,6 +44,7 @@ impl TestCase for GradientSrgbLinear { 0., CornerRadius::default(), 1., + 1., ) .with_location(area.loc)] .into_iter() diff --git a/niri-visual-tests/src/cases/gradient_srgblinear_alpha.rs b/niri-visual-tests/src/cases/gradient_srgblinear_alpha.rs index 847b3a6b..59b8fbce 100644 --- a/niri-visual-tests/src/cases/gradient_srgblinear_alpha.rs +++ b/niri-visual-tests/src/cases/gradient_srgblinear_alpha.rs @@ -42,6 +42,7 @@ impl TestCase for GradientSrgbLinearAlpha { 0., CornerRadius::default(), 1., + 1., ) .with_location(area.loc)] .into_iter() diff --git a/src/layer/mapped.rs b/src/layer/mapped.rs index 493bbc58..5e62d033 100644 --- a/src/layer/mapped.rs +++ b/src/layer/mapped.rs @@ -74,7 +74,7 @@ impl MappedLayer { let radius = self.rules.geometry_corner_radius.unwrap_or_default(); // FIXME: is_active based on keyboard focus? self.shadow - .update_render_elements(size, true, radius, scale.x); + .update_render_elements(size, true, radius, scale.x, 1.); } pub fn surface(&self) -> &LayerSurface { diff --git a/src/layout/focus_ring.rs b/src/layout/focus_ring.rs index 3d97cb02..411a73a5 100644 --- a/src/layout/focus_ring.rs +++ b/src/layout/focus_ring.rs @@ -2,7 +2,7 @@ use std::iter::zip; use arrayvec::ArrayVec; use niri_config::{CornerRadius, Gradient, GradientRelativeTo}; -use smithay::backend::renderer::element::Kind; +use smithay::backend::renderer::element::{Element as _, Kind}; use smithay::utils::{Logical, Point, Rectangle, Size}; use crate::niri_render_elements; @@ -53,6 +53,7 @@ impl FocusRing { } } + #[allow(clippy::too_many_arguments)] pub fn update_render_elements( &mut self, win_size: Size<f64, Logical>, @@ -61,6 +62,7 @@ impl FocusRing { view_rect: Rectangle<f64, Logical>, radius: CornerRadius, scale: f64, + alpha: f32, ) { let width = self.config.width.0; self.full_size = win_size + Size::from((width, width)).upscale(2.); @@ -181,6 +183,7 @@ impl FocusRing { rounded_corner_border_width, radius, scale as f32, + alpha, ); } } else { @@ -199,6 +202,7 @@ impl FocusRing { rounded_corner_border_width, radius, scale as f32, + alpha, ); } @@ -229,7 +233,9 @@ impl FocusRing { let elem = if self.use_border_shader && has_border_shader { border.clone().with_location(location).into() } else { - SolidColorRenderElement::from_buffer(buffer, location, 1., Kind::Unspecified).into() + let alpha = border.alpha(); + SolidColorRenderElement::from_buffer(buffer, location, alpha, Kind::Unspecified) + .into() }; rv.push(elem); }; diff --git a/src/layout/insert_hint_element.rs b/src/layout/insert_hint_element.rs index 5f70295c..89dfcd14 100644 --- a/src/layout/insert_hint_element.rs +++ b/src/layout/insert_hint_element.rs @@ -48,7 +48,7 @@ impl InsertHintElement { scale: f64, ) { self.inner - .update_render_elements(size, true, false, view_rect, radius, scale); + .update_render_elements(size, true, false, view_rect, radius, scale, 1.); } pub fn render( diff --git a/src/layout/shadow.rs b/src/layout/shadow.rs index 3e0605c4..d91986d1 100644 --- a/src/layout/shadow.rs +++ b/src/layout/shadow.rs @@ -38,6 +38,7 @@ impl Shadow { is_active: bool, radius: CornerRadius, scale: f64, + alpha: f32, ) { let ceil = |logical: f64| (logical * scale).ceil() / scale; @@ -129,6 +130,7 @@ impl Shadow { scale as f32, Rectangle::new(window_geo.loc - offset - rect.loc, window_geo.size), win_radius, + alpha, ); rect.loc += offset; @@ -147,6 +149,7 @@ impl Shadow { scale as f32, Rectangle::zero(), Default::default(), + alpha, ); self.shader_rects[0].loc += offset; diff --git a/src/layout/tile.rs b/src/layout/tile.rs index b8d049b0..ad3f7ff9 100644 --- a/src/layout/tile.rs +++ b/src/layout/tile.rs @@ -336,6 +336,7 @@ impl<W: LayoutElement> Tile<W> { ), radius, self.scale, + 1., ); let radius = if self.is_fullscreen { @@ -350,6 +351,7 @@ impl<W: LayoutElement> Tile<W> { is_active, radius, self.scale, + 1., ); let draw_focus_ring_with_background = if self.effective_border_width().is_some() { @@ -365,6 +367,7 @@ impl<W: LayoutElement> Tile<W> { view_rect, radius, self.scale, + 1., ); } @@ -880,6 +883,7 @@ impl<W: LayoutElement> Tile<W> { 0., radius, scale.x as f32, + 1., ) .with_location(geo.loc) .into(); diff --git a/src/render_helpers/border.rs b/src/render_helpers/border.rs index c0ab6663..588e53b1 100644 --- a/src/render_helpers/border.rs +++ b/src/render_helpers/border.rs @@ -39,6 +39,7 @@ struct Parameters { corner_radius: CornerRadius, // Should only be used for visual improvements, i.e. corner radius anti-aliasing. scale: f32, + alpha: f32, } impl BorderRenderElement { @@ -54,6 +55,7 @@ impl BorderRenderElement { border_width: f32, corner_radius: CornerRadius, scale: f32, + alpha: f32, ) -> Self { let inner = ShaderRenderElement::empty(ProgramType::Border, Kind::Unspecified); let mut rv = Self { @@ -69,6 +71,7 @@ impl BorderRenderElement { border_width, corner_radius, scale, + alpha, }, }; rv.update_inner(); @@ -90,6 +93,7 @@ impl BorderRenderElement { border_width: 0., corner_radius: Default::default(), scale: 1., + alpha: 1., }, } } @@ -111,6 +115,7 @@ impl BorderRenderElement { border_width: f32, corner_radius: CornerRadius, scale: f32, + alpha: f32, ) { let params = Parameters { size, @@ -123,6 +128,7 @@ impl BorderRenderElement { border_width, corner_radius, scale, + alpha, }; if self.params == params { return; @@ -144,6 +150,7 @@ impl BorderRenderElement { border_width, corner_radius, scale, + alpha, } = self.params; let grad_offset = geometry.loc - gradient_area.loc; @@ -189,6 +196,7 @@ impl BorderRenderElement { size, None, scale, + alpha, vec