forge
Explore
Log in

Don't you dare go Hollow

Allow negative shadow spread

Browse files at this commit

3b1bf34e21652b2ba6ce621226c05f74dccbefbbLunarEclipseParent: bd927b5
niri-config/src/lib.rsmodified+10 -2
@@ -711,7 +711,7 @@ pub struct Shadow {
711 #[knuffel(child, unwrap(argument), default = Self::default().softness)]711 #[knuffel(child, unwrap(argument), default = Self::default().softness)]
712 pub softness: FloatOrInt<0, 1024>,712 pub softness: FloatOrInt<0, 1024>,
713 #[knuffel(child, unwrap(argument), default = Self::default().spread)]713 #[knuffel(child, unwrap(argument), default = Self::default().spread)]
714- pub spread: FloatOrInt<0, 1024>,714+ pub spread: FloatOrInt<-1024, 1024>,
715 #[knuffel(child, unwrap(argument), default = Self::default().draw_behind_window)]715 #[knuffel(child, unwrap(argument), default = Self::default().draw_behind_window)]
716 pub draw_behind_window: bool,716 pub draw_behind_window: bool,
717 #[knuffel(child, default = Self::default().color)]717 #[knuffel(child, default = Self::default().color)]
@@ -1379,7 +1379,7 @@ pub struct ShadowRule {
1379 #[knuffel(child, unwrap(argument))]1379 #[knuffel(child, unwrap(argument))]
1380 pub softness: Option<FloatOrInt<0, 1024>>,1380 pub softness: Option<FloatOrInt<0, 1024>>,
1381 #[knuffel(child, unwrap(argument))]1381 #[knuffel(child, unwrap(argument))]
1382- pub spread: Option<FloatOrInt<0, 1024>>,1382+ pub spread: Option<FloatOrInt<-1024, 1024>>,
1383 #[knuffel(child, unwrap(argument))]1383 #[knuffel(child, unwrap(argument))]
1384 pub draw_behind_window: Option<bool>,1384 pub draw_behind_window: Option<bool>,
1385 #[knuffel(child)]1385 #[knuffel(child)]
@@ -2346,6 +2346,7 @@ impl CornerRadius {
2346 }2346 }
2347 2347
2348 pub fn expanded_by(mut self, width: f32) -> Self {2348 pub fn expanded_by(mut self, width: f32) -> Self {
2349+ // Radius = 0 is preserved, so that square corners remain square.
2349 if self.top_left > 0. {2350 if self.top_left > 0. {
2350 self.top_left += width;2351 self.top_left += width;
2351 }2352 }
@@ -2359,6 +2360,13 @@ impl CornerRadius {
2359 self.bottom_left += width;2360 self.bottom_left += width;
2360 }2361 }
2361 2362
2363+ if width < 0. {
2364+ self.top_left = self.top_left.max(0.);
2365+ self.top_right = self.top_right.max(0.);
2366+ self.bottom_left = self.bottom_left.max(0.);
2367+ self.bottom_right = self.bottom_right.max(0.);
2368+ }
2369+
2362 self2370 self
2363 }2371 }
2364 2372
src/layout/shadow.rsmodified+8 -2
@@ -57,12 +57,18 @@ impl Shadow {
57 let offset = self.config.offset;57 let offset = self.config.offset;
58 let offset = Point::from((ceil(offset.x.0), ceil(offset.y.0)));58 let offset = Point::from((ceil(offset.x.0), ceil(offset.y.0)));
59 59
60- let spread = ceil(self.config.spread.0);60+ let spread = self.config.spread.0;
61+ let spread = ceil(spread.abs()).copysign(spread);
61 let offset = offset - Point::from((spread, spread));62 let offset = offset - Point::from((spread, spread));
62 63
63 let win_radius = radius.fit_to(win_size.w as f32, win_size.h as f32);64 let win_radius = radius.fit_to(win_size.w as f32, win_size.h as f32);
64 65
65- let box_size = win_size + Size::from((spread, spread)).upscale(2.);66+ let box_size = if spread >= 0. {
67+ win_size + Size::from((spread, spread)).upscale(2.)
68+ } else {
69+ // This is a saturating sub.
70+ win_size - Size::from((-spread, -spread)).upscale(2.)
71+ };
66 let radius = win_radius.expanded_by(spread as f32);72 let radius = win_radius.expanded_by(spread as f32);
67 73
68 let shader_size = box_size + Size::from((width, width)).upscale(2.);74 let shader_size = box_size + Size::from((width, width)).upscale(2.);
wiki/Configuration:-Layout.mdmodified+1 -0
@@ -372,6 +372,7 @@ Set `on` to enable the shadow.
372 Setting `softness 0` will give you hard shadows.372 Setting `softness 0` will give you hard shadows.
373 373
374 `spread` is the distance to expand the window rectangle in logical pixels, same as [CSS box-shadow] spread.374 `spread` is the distance to expand the window rectangle in logical pixels, same as [CSS box-shadow] spread.
375+<sup>Since: next release</sup> Spread can be negative.
375 376
376 `offset` moves the shadow relative to the window in logical pixels, same as [CSS box-shadow] offset.377 `offset` moves the shadow relative to the window in logical pixels, same as [CSS box-shadow] offset.
377 For example, `offset x=2 y=2` will move the shadow 2 logical pixels downwards and to the right.378 For example, `offset x=2 y=2` will move the shadow 2 logical pixels downwards and to the right.