mirror of
https://github.com/niri-wm/niri.git
synced 2026-06-21 02:01:55 +07:00
Allow negative shadow spread
This commit is contained in:
committed by
Ivan Molodetskikh
parent
bd927b54e0
commit
3b1bf34e21
+10
-2
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -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.);
|
||||
|
||||
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user