config: Fix inability to override border/focus-ring/tab-indicator gradient with color in window rules
Browse files at this commit19d21fc9b1d53fe226ff90242e54059e1b7c40daParent: a1dcced1 changed file +137 -1
- niri-config/src/appearance.rs +137 -1
niri-config/src/appearance.rsmodified+137 -1
| @@ -580,12 +580,15 @@ impl BorderRule { | |||
| 580 | } | 580 | } |
| 581 | if let Some(x) = other.active_color { | 581 | if let Some(x) = other.active_color { |
| 582 | self.active_color = Some(x); | 582 | self.active_color = Some(x); |
| 583 | + self.active_gradient = None; | ||
| 583 | } | 584 | } |
| 584 | if let Some(x) = other.inactive_color { | 585 | if let Some(x) = other.inactive_color { |
| 585 | self.inactive_color = Some(x); | 586 | self.inactive_color = Some(x); |
| 587 | + self.inactive_gradient = None; | ||
| 586 | } | 588 | } |
| 587 | if let Some(x) = other.urgent_color { | 589 | if let Some(x) = other.urgent_color { |
| 588 | self.urgent_color = Some(x); | 590 | self.urgent_color = Some(x); |
| 591 | + self.urgent_gradient = None; | ||
| 589 | } | 592 | } |
| 590 | if let Some(x) = other.active_gradient { | 593 | if let Some(x) = other.active_gradient { |
| 591 | self.active_gradient = Some(x); | 594 | self.active_gradient = Some(x); |
| @@ -698,12 +701,15 @@ impl TabIndicatorRule { | |||
| 698 | pub fn merge_with(&mut self, other: &Self) { | 701 | pub fn merge_with(&mut self, other: &Self) { |
| 699 | if let Some(x) = other.active_color { | 702 | if let Some(x) = other.active_color { |
| 700 | self.active_color = Some(x); | 703 | self.active_color = Some(x); |
| 704 | + self.active_gradient = None; | ||
| 701 | } | 705 | } |
| 702 | if let Some(x) = other.inactive_color { | 706 | if let Some(x) = other.inactive_color { |
| 703 | self.inactive_color = Some(x); | 707 | self.inactive_color = Some(x); |
| 708 | + self.inactive_gradient = None; | ||
| 704 | } | 709 | } |
| 705 | if let Some(x) = other.urgent_color { | 710 | if let Some(x) = other.urgent_color { |
| 706 | self.urgent_color = Some(x); | 711 | self.urgent_color = Some(x); |
| 712 | + self.urgent_gradient = None; | ||
| 707 | } | 713 | } |
| 708 | if let Some(x) = other.active_gradient { | 714 | if let Some(x) = other.active_gradient { |
| 709 | self.active_gradient = Some(x); | 715 | self.active_gradient = Some(x); |
| @@ -1003,9 +1009,10 @@ where | |||
| 1003 | 1009 | ||
| 1004 | #[cfg(test)] | 1010 | #[cfg(test)] |
| 1005 | mod tests { | 1011 | mod tests { |
| 1006 | - use insta::assert_snapshot; | 1012 | + use insta::{assert_debug_snapshot, assert_snapshot}; |
| 1007 | 1013 | ||
| 1008 | use super::*; | 1014 | use super::*; |
| 1015 | + use crate::Config; | ||
| 1009 | 1016 | ||
| 1010 | #[test] | 1017 | #[test] |
| 1011 | fn parse_gradient_interpolation() { | 1018 | fn parse_gradient_interpolation() { |
| @@ -1140,4 +1147,133 @@ mod tests { | |||
| 1140 | assert_snapshot!(is_on("on", &["on", "off"]), @"off"); | 1147 | assert_snapshot!(is_on("on", &["on", "off"]), @"off"); |
| 1141 | assert_snapshot!(is_on("on", &["on", "on"]), @"on"); | 1148 | assert_snapshot!(is_on("on", &["on", "on"]), @"on"); |
| 1142 | } | 1149 | } |
| 1150 | + | ||
| 1151 | + #[test] | ||
| 1152 | + fn rule_color_can_override_base_gradient() { | ||
| 1153 | + let config = Config::parse( | ||
| 1154 | + "test.kdl", | ||
| 1155 | + r##" | ||
| 1156 | + // Start with gradient set. | ||
| 1157 | + layout { | ||
| 1158 | + border { | ||
| 1159 | + active-gradient from="#101010" to="#202020" | ||
| 1160 | + inactive-gradient from="#111111" to="#212121" | ||
| 1161 | + urgent-gradient from="#121212" to="#222222" | ||
| 1162 | + } | ||
| 1163 | + } | ||
| 1164 | + | ||
| 1165 | + // Override with color. | ||
| 1166 | + window-rule { | ||
| 1167 | + border { | ||
| 1168 | + active-color "#abcdef" | ||
| 1169 | + inactive-color "#123456" | ||
| 1170 | + urgent-color "#fedcba" | ||
| 1171 | + } | ||
| 1172 | + } | ||
| 1173 | + "##, | ||
| 1174 | + ) | ||
| 1175 | + .unwrap(); | ||
| 1176 | + | ||
| 1177 | + let mut border_rule = BorderRule::default(); | ||
| 1178 | + for rule in &config.window_rules { | ||
| 1179 | + border_rule.merge_with(&rule.border); | ||
| 1180 | + } | ||
| 1181 | + | ||
| 1182 | + let border = border_rule.resolve_against(config.layout.border); | ||
| 1183 | + | ||
| 1184 | + // Gradient should be None because it's overwritten. | ||
| 1185 | + assert_debug_snapshot!( | ||
| 1186 | + ( | ||
| 1187 | + border.active_gradient.is_some(), | ||
| 1188 | + border.inactive_gradient.is_some(), | ||
| 1189 | + border.urgent_gradient.is_some(), | ||
| 1190 | + ), | ||
| 1191 | + @r" | ||
| 1192 | + ( | ||
| 1193 | + false, | ||
| 1194 | + false, | ||
| 1195 | + false, | ||
| 1196 | + ) | ||
| 1197 | + " | ||
| 1198 | + ); | ||
| 1199 | + } | ||
| 1200 | + | ||
| 1201 | + #[test] | ||
| 1202 | + fn rule_color_can_override_rule_gradient() { | ||
| 1203 | + let config = Config::parse( | ||
| 1204 | + "test.kdl", | ||
| 1205 | + r##" | ||
| 1206 | + // Start with gradient set. | ||
| 1207 | + layout { | ||
| 1208 | + border { | ||
| 1209 | + active-gradient from="#101010" to="#202020" | ||
| 1210 | + inactive-gradient from="#111111" to="#212121" | ||
| 1211 | + urgent-gradient from="#121212" to="#222222" | ||
| 1212 | + } | ||
| 1213 | + } | ||
| 1214 | + | ||
| 1215 | + // Window rule with gradients set. | ||
| 1216 | + window-rule { | ||
| 1217 | + border { | ||
| 1218 | + active-gradient from="#303030" to="#404040" | ||
| 1219 | + inactive-gradient from="#313131" to="#414141" | ||
| 1220 | + urgent-gradient from="#323232" to="#424242" | ||
| 1221 | + } | ||
| 1222 | + | ||
| 1223 | + tab-indicator { | ||
| 1224 | + active-gradient from="#505050" to="#606060" | ||
| 1225 | + inactive-gradient from="#515151" to="#616161" | ||
| 1226 | + urgent-gradient from="#525252" to="#626262" | ||
| 1227 | + } | ||
| 1228 | + } | ||
| 1229 | + | ||
| 1230 | + // Override with color. | ||
| 1231 | + window-rule { | ||
| 1232 | + border { | ||
| 1233 | + active-color "#abcdef" | ||
| 1234 | + inactive-color "#123456" | ||
| 1235 | + urgent-color "#fedcba" | ||
| 1236 | + } | ||
| 1237 | + | ||
| 1238 | + tab-indicator { | ||
| 1239 | + active-color "#abcdef" | ||
| 1240 | + inactive-color "#123456" | ||
| 1241 | + urgent-color "#fedcba" | ||
| 1242 | + } | ||
| 1243 | + } | ||
| 1244 | + "##, | ||
| 1245 | + ) | ||
| 1246 | + .unwrap(); | ||
| 1247 | + | ||
| 1248 | + let mut border_rule = BorderRule::default(); | ||
| 1249 | + let mut tab_indicator_rule = TabIndicatorRule::default(); | ||
| 1250 | + for rule in &config.window_rules { | ||
| 1251 | + border_rule.merge_with(&rule.border); | ||
| 1252 | + tab_indicator_rule.merge_with(&rule.tab_indicator); | ||
| 1253 | + } | ||
| 1254 | + | ||
| 1255 | + let border = border_rule.resolve_against(config.layout.border); | ||
| 1256 | + | ||
| 1257 | + // Gradient should be None because it's overwritten. | ||
| 1258 | + assert_debug_snapshot!( | ||
| 1259 | + ( | ||
| 1260 | + border.active_gradient.is_some(), | ||
| 1261 | + border.inactive_gradient.is_some(), | ||
| 1262 | + border.urgent_gradient.is_some(), | ||
| 1263 | + tab_indicator_rule.active_gradient.is_some(), | ||
| 1264 | + tab_indicator_rule.inactive_gradient.is_some(), | ||
| 1265 | + tab_indicator_rule.urgent_gradient.is_some(), | ||
| 1266 | + ), | ||
| 1267 | + @r" | ||
| 1268 | + ( | ||
| 1269 | + false, | ||
| 1270 | + false, | ||
| 1271 | + false, | ||
| 1272 | + false, | ||
| 1273 | + false, | ||
| 1274 | + false, | ||
| 1275 | + ) | ||
| 1276 | + " | ||
| 1277 | + ); | ||
| 1278 | + } | ||
| 1143 | } | 1279 | } |