diff options
| author | Ivan Molodetskikh <yalterz@gmail.com> | 2025-09-20 12:57:38 +0300 |
|---|---|---|
| committer | Ivan Molodetskikh <yalterz@gmail.com> | 2025-10-02 09:33:08 +0300 |
| commit | a2727ba2c9cfb22e4184235c6dfd8d8819328169 (patch) | |
| tree | dbde396598e3ac3483d8535ea62c2994ef2bbf70 /niri-config/src | |
| parent | 8df6231cc164396e19a892f11beb8c02e2e88efb (diff) | |
| download | niri-a2727ba2c9cfb22e4184235c6dfd8d8819328169.tar.gz niri-a2727ba2c9cfb22e4184235c6dfd8d8819328169.tar.bz2 niri-a2727ba2c9cfb22e4184235c6dfd8d8819328169.zip | |
config: Introduce MergeWith trait
Diffstat (limited to 'niri-config/src')
| -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 |
3 files changed, 32 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) + } +} |
