@@ -314,36 +314,64 @@ impl From<FocusRing> for Border {
314314
315315#[ derive( Debug , Clone , Copy , PartialEq ) ]
316316pub struct Blur {
317- pub on : bool ,
318- pub passes : u32 ,
319- pub radius : FloatOrInt < 0 , 1024 > ,
320- pub noise : FloatOrInt < 0 , 1024 > ,
317+ pub off : bool ,
318+ pub passes : u8 ,
319+ pub offset : f64 ,
320+ pub noise : f64 ,
321+ pub saturation : f64 ,
321322 pub ignore_alpha : FloatOrInt < 0 , 1 > ,
322323 pub blur_when_keyboard_focused : bool ,
323324}
324325
326+ #[ derive( knuffel:: Decode , Debug , Default , Clone , Copy , PartialEq ) ]
327+ pub struct BlurPart {
328+ #[ knuffel( child) ]
329+ pub off : bool ,
330+ #[ knuffel( child) ]
331+ pub on : bool ,
332+ #[ knuffel( child, unwrap( argument) ) ]
333+ pub passes : Option < u8 > ,
334+ #[ knuffel( child, unwrap( argument) ) ]
335+ pub offset : Option < FloatOrInt < 0 , 100 > > ,
336+ #[ knuffel( child, unwrap( argument) ) ]
337+ pub noise : Option < FloatOrInt < 0 , 1000 > > ,
338+ #[ knuffel( child, unwrap( argument) ) ]
339+ pub saturation : Option < FloatOrInt < 0 , 1000 > > ,
340+ #[ knuffel( child, unwrap( argument) ) ]
341+ pub ignore_alpha : Option < FloatOrInt < 0 , 1 > > ,
342+ #[ knuffel( child, unwrap( argument) ) ]
343+ pub blur_when_keyboard_focused : Option < bool > ,
344+ }
345+
325346impl Default for Blur {
326347 fn default ( ) -> Self {
327348 Self {
328- // off: false,
329- on : false ,
349+ off : false ,
330350 passes : 2 ,
331- radius : FloatOrInt ( 0.0 ) ,
332- noise : FloatOrInt ( 0.0 ) ,
351+ offset : 3. ,
352+ noise : 0.02 ,
333353 ignore_alpha : FloatOrInt ( 0. ) ,
334354 blur_when_keyboard_focused : false ,
355+ saturation : 1.5 ,
335356 }
336357 }
337358}
338359
339- impl MergeWith < BlurRule > for Blur {
340- fn merge_with ( & mut self , part : & BlurRule ) {
341- self . on |= part. on ;
342- if part. off {
343- self . on = false ;
360+ impl MergeWith < BlurPart > for Blur {
361+ fn merge_with ( & mut self , part : & BlurPart ) {
362+ self . off |= part. off ;
363+ if part. on {
364+ self . off = false ;
344365 }
345366
346- merge_clone ! ( ( self , part) , passes, radius, noise, ignore_alpha, blur_when_keyboard_focused) ;
367+ merge_clone ! (
368+ ( self , part) ,
369+ ignore_alpha,
370+ passes,
371+ blur_when_keyboard_focused
372+ ) ;
373+
374+ merge ! ( ( self , part) , offset, noise, saturation) ;
347375 }
348376}
349377
@@ -688,24 +716,6 @@ pub struct BorderRule {
688716 pub urgent_gradient : Option < Gradient > ,
689717}
690718
691- #[ derive( knuffel:: Decode , Debug , Default , Clone , Copy , PartialEq ) ]
692- pub struct BlurRule {
693- #[ knuffel( child) ]
694- pub off : bool ,
695- #[ knuffel( child) ]
696- pub on : bool ,
697- #[ knuffel( child, unwrap( argument) ) ]
698- pub passes : Option < u32 > ,
699- #[ knuffel( child, unwrap( argument) ) ]
700- pub radius : Option < FloatOrInt < 0 , 1024 > > ,
701- #[ knuffel( child, unwrap( argument) ) ]
702- pub noise : Option < FloatOrInt < 0 , 1024 > > ,
703- #[ knuffel( child, unwrap( argument) ) ]
704- pub ignore_alpha : Option < FloatOrInt < 0 , 1 > > ,
705- #[ knuffel( child, unwrap( argument) ) ]
706- pub blur_when_keyboard_focused : Option < bool > ,
707- }
708-
709719#[ derive( knuffel:: Decode , Debug , Default , Clone , Copy , PartialEq ) ]
710720pub struct ShadowRule {
711721 #[ knuffel( child) ]
@@ -759,10 +769,18 @@ impl MergeWith<Self> for BorderRule {
759769 }
760770}
761771
762- impl MergeWith < Self > for BlurRule {
772+ impl MergeWith < Self > for BlurPart {
763773 fn merge_with ( & mut self , part : & Self ) {
764774 merge_on_off ! ( ( self , part) ) ;
765- merge_clone_opt ! ( ( self , part) , passes, radius, noise, ignore_alpha, blur_when_keyboard_focused) ;
775+ merge_clone_opt ! (
776+ ( self , part) ,
777+ passes,
778+ offset,
779+ saturation,
780+ noise,
781+ ignore_alpha,
782+ blur_when_keyboard_focused
783+ ) ;
766784 }
767785}
768786
@@ -1078,6 +1096,72 @@ where
10781096 }
10791097}
10801098
1099+ #[ derive( knuffel:: Decode , Debug , Default , Clone , Copy , PartialEq ) ]
1100+ pub struct BlurRule {
1101+ #[ knuffel( child) ]
1102+ pub off : bool ,
1103+ #[ knuffel( child) ]
1104+ pub on : bool ,
1105+ }
1106+
1107+ #[ derive( knuffel:: Decode , Debug , Default , Clone , Copy , PartialEq ) ]
1108+ pub struct BackgroundEffectRule {
1109+ #[ knuffel( child, unwrap( argument) ) ]
1110+ pub xray : Option < bool > ,
1111+ #[ knuffel( child, default ) ]
1112+ pub blur : BlurRule ,
1113+ #[ knuffel( child, unwrap( argument) ) ]
1114+ pub noise : Option < FloatOrInt < 0 , 1000 > > ,
1115+ #[ knuffel( child, unwrap( argument) ) ]
1116+ pub saturation : Option < FloatOrInt < 0 , 1000 > > ,
1117+ }
1118+
1119+ impl MergeWith < Self > for BackgroundEffectRule {
1120+ fn merge_with ( & mut self , part : & Self ) {
1121+ merge_clone_opt ! ( ( self , part) , xray, noise, saturation) ;
1122+ merge_on_off ! ( ( self . blur, part. blur) ) ;
1123+ }
1124+ }
1125+
1126+ /// Resolved background effect rule.
1127+ #[ derive( Debug , Default , Clone , Copy , PartialEq ) ]
1128+ pub struct BackgroundEffect {
1129+ /// Whether to render with xray effect (see through).
1130+ pub xray : Option < bool > ,
1131+
1132+ /// Whether to blur the background.
1133+ ///
1134+ /// - `None`: blur when the window/layer requests it (e.g. through ext-background-effect
1135+ /// protocol)
1136+ /// - `Some(false)`: never blur
1137+ /// - `Some(true)`: always blur
1138+ pub blur : Option < bool > ,
1139+
1140+ pub noise : Option < f64 > ,
1141+ pub saturation : Option < f64 > ,
1142+ }
1143+
1144+ impl MergeWith < BackgroundEffectRule > for BackgroundEffect {
1145+ fn merge_with ( & mut self , part : & BackgroundEffectRule ) {
1146+ merge_clone_opt ! ( ( self , part) , xray) ;
1147+
1148+ if part. blur . on {
1149+ self . blur = Some ( true ) ;
1150+ }
1151+ if part. blur . off {
1152+ self . blur = Some ( false ) ;
1153+ }
1154+
1155+ if let Some ( x) = part. noise {
1156+ self . noise = Some ( x. 0 ) ;
1157+ }
1158+
1159+ if let Some ( x) = part. saturation {
1160+ self . saturation = Some ( x. 0 ) ;
1161+ }
1162+ }
1163+ }
1164+
10811165#[ cfg( test) ]
10821166mod tests {
10831167 use insta:: { assert_debug_snapshot, assert_snapshot} ;
0 commit comments