diff options
| -rw-r--r-- | niri-config/src/appearance.rs | 17 | ||||
| -rw-r--r-- | niri-config/src/utils.rs | 3 | ||||
| -rw-r--r-- | niri-config/src/utils/merge_with.rs | 18 | ||||
| -rw-r--r-- | src/layer/mod.rs | 1 | ||||
| -rw-r--r-- | src/window/mod.rs | 1 |
5 files changed, 34 insertions, 6 deletions
diff --git a/niri-config/src/appearance.rs b/niri-config/src/appearance.rs index e5efc4be..cc698ef6 100644 --- a/niri-config/src/appearance.rs +++ b/niri-config/src/appearance.rs @@ -5,6 +5,7 @@ use knuffel::errors::DecodeError; use miette::{miette, IntoDiagnostic as _}; use smithay::backend::renderer::Color32F; +use crate::utils::MergeWith; use crate::FloatOrInt; pub const DEFAULT_BACKGROUND_COLOR: Color = Color::from_array_unpremul([0.25, 0.25, 0.25, 1.]); @@ -563,8 +564,8 @@ pub struct TabIndicatorRule { pub urgent_gradient: Option<Gradient>, } -impl BorderRule { - pub fn merge_with(&mut self, other: &Self) { +impl MergeWith<Self> for BorderRule { + fn merge_with(&mut self, other: &Self) { if other.off { self.off = true; self.on = false; @@ -600,7 +601,9 @@ impl BorderRule { self.urgent_gradient = Some(x); } } +} +impl BorderRule { pub fn resolve_against(&self, mut config: Border) -> Border { config.off |= self.off; if self.on { @@ -636,8 +639,8 @@ impl BorderRule { } } -impl ShadowRule { - pub fn merge_with(&mut self, other: &Self) { +impl MergeWith<Self> for ShadowRule { + fn merge_with(&mut self, other: &Self) { if other.off { self.off = true; self.on = false; @@ -667,7 +670,9 @@ impl ShadowRule { self.inactive_color = Some(x); } } +} +impl ShadowRule { pub fn resolve_against(&self, mut config: Shadow) -> Shadow { config.on |= self.on; if self.off { @@ -697,8 +702,8 @@ impl ShadowRule { } } -impl TabIndicatorRule { - pub fn merge_with(&mut self, other: &Self) { +impl MergeWith<Self> for TabIndicatorRule { + fn merge_with(&mut self, other: &Self) { if let Some(x) = other.active_color { self.active_color = Some(x); self.active_gradient = None; diff --git a/niri-config/src/utils.rs b/niri-config/src/utils.rs index 77baac5e..e2a24901 100644 --- a/niri-config/src/utils.rs +++ b/niri-config/src/utils.rs @@ -4,6 +4,9 @@ use knuffel::errors::DecodeError; use miette::miette; use regex::Regex; +mod merge_with; +pub use merge_with::*; + #[derive(Debug, Clone, Copy, PartialEq)] pub struct Percent(pub f64); diff --git a/niri-config/src/utils/merge_with.rs b/niri-config/src/utils/merge_with.rs new file mode 100644 index 00000000..857e2146 --- /dev/null +++ b/niri-config/src/utils/merge_with.rs @@ -0,0 +1,18 @@ +pub trait MergeWith<T> { + fn merge_with(&mut self, part: &T); + + fn merged_with(mut self, part: &T) -> Self + where + Self: Sized, + { + self.merge_with(part); + self + } + + fn from_part(part: &T) -> Self + where + Self: Default + Sized, + { + Self::default().merged_with(part) + } +} diff --git a/src/layer/mod.rs b/src/layer/mod.rs index 2ff8b7ca..19a091c1 100644 --- a/src/layer/mod.rs +++ b/src/layer/mod.rs @@ -1,4 +1,5 @@ use niri_config::layer_rule::{LayerRule, Match}; +use niri_config::utils::MergeWith as _; use niri_config::{BlockOutFrom, CornerRadius, ShadowRule}; use smithay::desktop::LayerSurface; diff --git a/src/window/mod.rs b/src/window/mod.rs index b07b80d8..c65fa535 100644 --- a/src/window/mod.rs +++ b/src/window/mod.rs @@ -1,5 +1,6 @@ use std::cmp::{max, min}; +use niri_config::utils::MergeWith as _; use niri_config::window_rule::{Match, WindowRule}; use niri_config::{ BlockOutFrom, BorderRule, CornerRadius, FloatingPosition, PresetSize, ShadowRule, |
