diff options
| author | LunarEclipse <luna@lunareclipse.zone> | 2025-03-09 18:55:17 +0100 |
|---|---|---|
| committer | Ivan Molodetskikh <yalterz@gmail.com> | 2025-03-31 14:13:20 +0300 |
| commit | 3b1bf34e21652b2ba6ce621226c05f74dccbefbb (patch) | |
| tree | e791a057c01fbfd76cfb1a8cea9b638e27263b1d | |
| parent | bd927b54e09d9f37356874d12b9e57dd28d2d837 (diff) | |
| download | niri-3b1bf34e21652b2ba6ce621226c05f74dccbefbb.tar.gz niri-3b1bf34e21652b2ba6ce621226c05f74dccbefbb.tar.bz2 niri-3b1bf34e21652b2ba6ce621226c05f74dccbefbb.zip | |
Allow negative shadow spread
| -rw-r--r-- | niri-config/src/lib.rs | 12 | ||||
| -rw-r--r-- | src/layout/shadow.rs | 10 | ||||
| -rw-r--r-- | wiki/Configuration:-Layout.md | 1 |
3 files changed, 19 insertions, 4 deletions
diff --git a/niri-config/src/lib.rs b/niri-config/src/lib.rs index 56bff592..d622bfcd 100644 --- a/niri-config/src/lib.rs +++ b/niri-config/src/lib.rs @@ -711,7 +711,7 @@ pub struct Shadow { #[knuffel(child, unwrap(argument), default = Self::default().softness)] pub softness: FloatOrInt<0, 1024>, #[knuffel(child, unwrap(argument), default = Self::default().spread)] - pub spread: FloatOrInt<0, 1024>, + pub spread: FloatOrInt<-1024, 1024>, #[knuffel(child, unwrap(argument), default = Self::default().draw_behind_window)] pub draw_behind_window: bool, #[knuffel(child, default = Self::default().color)] @@ -1379,7 +1379,7 @@ pub struct ShadowRule { #[knuffel(child, unwrap(argument))] pub softness: Option<FloatOrInt<0, 1024>>, #[knuffel(child, unwrap(argument))] - pub spread: Option<FloatOrInt<0, 1024>>, + pub spread: Option<FloatOrInt<-1024, 1024>>, #[knuffel(child, unwrap(argument))] pub draw_behind_window: Option<bool>, #[knuffel(child)] @@ -2346,6 +2346,7 @@ impl CornerRadius { } pub fn expanded_by(mut self, width: f32) -> Self { + // Radius = 0 is preserved, so that square corners remain square. if self.top_left > 0. { self.top_left += width; } @@ -2359,6 +2360,13 @@ impl CornerRadius { self.bottom_left += width; } + if width < 0. { + self.top_left = self.top_left.max(0.); + self.top_right = self.top_right.max(0.); + self.bottom_left = self.bottom_left.max(0.); + self.bottom_right = self.bottom_right.max(0.); + } + self } diff --git a/src/layout/shadow.rs b/src/layout/shadow.rs index d91986d1..df018b7b 100644 --- a/src/layout/shadow.rs +++ b/src/layout/shadow.rs @@ -57,12 +57,18 @@ impl Shadow { let offset = self.config.offset; let offset = Point::from((ceil(offset.x.0), ceil(offset.y.0))); - let spread = ceil(self.config.spread.0); + let spread = self.config.spread.0; + let spread = ceil(spread.abs()).copysign(spread); let offset = offset - Point::from((spread, spread)); let win_radius = radius.fit_to(win_size.w as f32, win_size.h as f32); - let box_size = win_size + Size::from((spread, spread)).upscale(2.); + let box_size = if spread >= 0. { + win_size + Size::from((spread, spread)).upscale(2.) + } else { + // This is a saturating sub. + win_size - Size::from((-spread, -spread)).upscale(2.) + }; let radius = win_radius.expanded_by(spread as f32); let shader_size = box_size + Size::from((width, width)).upscale(2.); diff --git a/wiki/Configuration:-Layout.md b/wiki/Configuration:-Layout.md index 08c3871a..a060d507 100644 --- a/wiki/Configuration:-Layout.md +++ b/wiki/Configuration:-Layout.md @@ -372,6 +372,7 @@ Set `on` to enable the shadow. Setting `softness 0` will give you hard shadows. `spread` is the distance to expand the window rectangle in logical pixels, same as [CSS box-shadow] spread. +<sup>Since: next release</sup> Spread can be negative. `offset` moves the shadow relative to the window in logical pixels, same as [CSS box-shadow] offset. For example, `offset x=2 y=2` will move the shadow 2 logical pixels downwards and to the right. |
