aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIvan Molodetskikh <yalterz@gmail.com>2025-09-18 10:43:31 +0300
committerIvan Molodetskikh <yalterz@gmail.com>2025-09-20 15:08:15 +0300
commit19d21fc9b1d53fe226ff90242e54059e1b7c40da (patch)
tree4ad8599e0a0fd4c9795f152b58e494013ee9aa58
parenta1dccedbb72da372d2a8a84022f37ccaa4d4a6e6 (diff)
downloadniri-19d21fc9b1d53fe226ff90242e54059e1b7c40da.tar.gz
niri-19d21fc9b1d53fe226ff90242e54059e1b7c40da.tar.bz2
niri-19d21fc9b1d53fe226ff90242e54059e1b7c40da.zip
config: Fix inability to override border/focus-ring/tab-indicator gradient with color in window rules
-rw-r--r--niri-config/src/appearance.rs138
1 files changed, 137 insertions, 1 deletions
diff --git a/niri-config/src/appearance.rs b/niri-config/src/appearance.rs
index a50e6a55..815da78b 100644
--- a/niri-config/src/appearance.rs
+++ b/niri-config/src/appearance.rs
@@ -580,12 +580,15 @@ impl BorderRule {
}
if let Some(x) = other.active_color {
self.active_color = Some(x);
+ self.active_gradient = None;
}
if let Some(x) = other.inactive_color {
self.inactive_color = Some(x);
+ self.inactive_gradient = None;
}
if let Some(x) = other.urgent_color {
self.urgent_color = Some(x);
+ self.urgent_gradient = None;
}
if let Some(x) = other.active_gradient {
self.active_gradient = Some(x);
@@ -698,12 +701,15 @@ impl TabIndicatorRule {
pub fn merge_with(&mut self, other: &Self) {
if let Some(x) = other.active_color {
self.active_color = Some(x);
+ self.active_gradient = None;
}
if let Some(x) = other.inactive_color {
self.inactive_color = Some(x);
+ self.inactive_gradient = None;
}
if let Some(x) = other.urgent_color {
self.urgent_color = Some(x);
+ self.urgent_gradient = None;
}
if let Some(x) = other.active_gradient {
self.active_gradient = Some(x);
@@ -1003,9 +1009,10 @@ where
#[cfg(test)]
mod tests {
- use insta::assert_snapshot;
+ use insta::{assert_debug_snapshot, assert_snapshot};
use super::*;
+ use crate::Config;
#[test]
fn parse_gradient_interpolation() {
@@ -1140,4 +1147,133 @@ mod tests {
assert_snapshot!(is_on("on", &["on", "off"]), @"off");
assert_snapshot!(is_on("on", &["on", "on"]), @"on");
}
+
+ #[test]
+ fn rule_color_can_override_base_gradient() {
+ let config = Config::parse(
+ "test.kdl",
+ r##"
+ // Start with gradient set.
+ layout {
+ border {
+ active-gradient from="#101010" to="#202020"
+ inactive-gradient from="#111111" to="#212121"
+ urgent-gradient from="#121212" to="#222222"
+ }
+ }
+
+ // Override with color.
+ window-rule {
+ border {
+ active-color "#abcdef"
+ inactive-color "#123456"
+ urgent-color "#fedcba"
+ }
+ }
+ "##,
+ )
+ .unwrap();
+
+ let mut border_rule = BorderRule::default();
+ for rule in &config.window_rules {
+ border_rule.merge_with(&rule.border);
+ }
+
+ let border = border_rule.resolve_against(config.layout.border);
+
+ // Gradient should be None because it's overwritten.
+ assert_debug_snapshot!(
+ (
+ border.active_gradient.is_some(),
+ border.inactive_gradient.is_some(),
+ border.urgent_gradient.is_some(),
+ ),
+ @r"
+ (
+ false,
+ false,
+ false,
+ )
+ "
+ );
+ }
+
+ #[test]
+ fn rule_color_can_override_rule_gradient() {
+ let config = Config::parse(
+ "test.kdl",
+ r##"
+ // Start with gradient set.
+ layout {
+ border {
+ active-gradient from="#101010" to="#202020"
+ inactive-gradient from="#111111" to="#212121"
+ urgent-gradient from="#121212" to="#222222"
+ }
+ }
+
+ // Window rule with gradients set.
+ window-rule {
+ border {
+ active-gradient from="#303030" to="#404040"
+ inactive-gradient from="#313131" to="#414141"
+ urgent-gradient from="#323232" to="#424242"
+ }
+
+ tab-indicator {
+ active-gradient from="#505050" to="#606060"
+ inactive-gradient from="#515151" to="#616161"
+ urgent-gradient from="#525252" to="#626262"
+ }
+ }
+
+ // Override with color.
+ window-rule {
+ border {
+ active-color "#abcdef"
+ inactive-color "#123456"
+ urgent-color "#fedcba"
+ }
+
+ tab-indicator {
+ active-color "#abcdef"
+ inactive-color "#123456"
+ urgent-color "#fedcba"
+ }
+ }
+ "##,
+ )
+ .unwrap();
+
+ let mut border_rule = BorderRule::default();
+ let mut tab_indicator_rule = TabIndicatorRule::default();
+ for rule in &config.window_rules {
+ border_rule.merge_with(&rule.border);
+ tab_indicator_rule.merge_with(&rule.tab_indicator);
+ }
+
+ let border = border_rule.resolve_against(config.layout.border);
+
+ // Gradient should be None because it's overwritten.
+ assert_debug_snapshot!(
+ (
+ border.active_gradient.is_some(),
+ border.inactive_gradient.is_some(),
+ border.urgent_gradient.is_some(),
+ tab_indicator_rule.active_gradient.is_some(),
+ tab_indicator_rule.inactive_gradient.is_some(),
+ tab_indicator_rule.urgent_gradient.is_some(),
+ ),
+ @r"
+ (
+ false,
+ false,
+ false,
+ false,
+ false,
+ false,
+ )
+ "
+ );
+ }
}