forge
Explore
Log in

Don't you dare go Hollow

config: Add merging for Animations

Browse files at this commit

31f9577df92d79ded3e60cea54cd56f61a9bd470Ivan MolodetskikhParent: 2eabc22
niri-config/src/animations.rsmodified+61 -16
@@ -1,34 +1,22 @@
1 use knuffel::errors::DecodeError;1 use knuffel::errors::DecodeError;
2 use knuffel::Decode as _;2 use knuffel::Decode as _;
3 3
4-use crate::utils::{expect_only_children, parse_arg_node};4+use crate::utils::{expect_only_children, parse_arg_node, MergeWith};
5 use crate::FloatOrInt;5 use crate::FloatOrInt;
6 6
7-#[derive(knuffel::Decode, Debug, Clone, PartialEq)]7+#[derive(Debug, Clone, PartialEq)]
8 pub struct Animations {8 pub struct Animations {
9- #[knuffel(child)]
10 pub off: bool,9 pub off: bool,
11- #[knuffel(child, unwrap(argument), default = FloatOrInt(1.))]10+ pub slowdown: f64,
12- pub slowdown: FloatOrInt<0, { i32::MAX }>,
13- #[knuffel(child, default)]
14 pub workspace_switch: WorkspaceSwitchAnim,11 pub workspace_switch: WorkspaceSwitchAnim,
15- #[knuffel(child, default)]
16 pub window_open: WindowOpenAnim,12 pub window_open: WindowOpenAnim,
17- #[knuffel(child, default)]
18 pub window_close: WindowCloseAnim,13 pub window_close: WindowCloseAnim,
19- #[knuffel(child, default)]
20 pub horizontal_view_movement: HorizontalViewMovementAnim,14 pub horizontal_view_movement: HorizontalViewMovementAnim,
21- #[knuffel(child, default)]
22 pub window_movement: WindowMovementAnim,15 pub window_movement: WindowMovementAnim,
23- #[knuffel(child, default)]
24 pub window_resize: WindowResizeAnim,16 pub window_resize: WindowResizeAnim,
25- #[knuffel(child, default)]
26 pub config_notification_open_close: ConfigNotificationOpenCloseAnim,17 pub config_notification_open_close: ConfigNotificationOpenCloseAnim,
27- #[knuffel(child, default)]
28 pub exit_confirmation_open_close: ExitConfirmationOpenCloseAnim,18 pub exit_confirmation_open_close: ExitConfirmationOpenCloseAnim,
29- #[knuffel(child, default)]
30 pub screenshot_ui_open: ScreenshotUiOpenAnim,19 pub screenshot_ui_open: ScreenshotUiOpenAnim,
31- #[knuffel(child, default)]
32 pub overview_open_close: OverviewOpenCloseAnim,20 pub overview_open_close: OverviewOpenCloseAnim,
33 }21 }
34 22
@@ -36,7 +24,7 @@ impl Default for Animations {
36 fn default() -> Self {24 fn default() -> Self {
37 Self {25 Self {
38 off: false,26 off: false,
39- slowdown: FloatOrInt(1.),27+ slowdown: 1.,
40 workspace_switch: Default::default(),28 workspace_switch: Default::default(),
41 horizontal_view_movement: Default::default(),29 horizontal_view_movement: Default::default(),
42 window_movement: Default::default(),30 window_movement: Default::default(),
@@ -51,6 +39,63 @@ impl Default for Animations {
51 }39 }
52 }40 }
53 41
42+#[derive(knuffel::Decode, Debug, Clone, PartialEq)]
43+pub struct AnimationsPart {
44+ #[knuffel(child)]
45+ pub off: bool,
46+ #[knuffel(child)]
47+ pub on: bool,
48+ #[knuffel(child, unwrap(argument))]
49+ pub slowdown: Option<FloatOrInt<0, { i32::MAX }>>,
50+ #[knuffel(child)]
51+ pub workspace_switch: Option<WorkspaceSwitchAnim>,
52+ #[knuffel(child)]
53+ pub window_open: Option<WindowOpenAnim>,
54+ #[knuffel(child)]
55+ pub window_close: Option<WindowCloseAnim>,
56+ #[knuffel(child)]
57+ pub horizontal_view_movement: Option<HorizontalViewMovementAnim>,
58+ #[knuffel(child)]
59+ pub window_movement: Option<WindowMovementAnim>,
60+ #[knuffel(child)]
61+ pub window_resize: Option<WindowResizeAnim>,
62+ #[knuffel(child)]
63+ pub config_notification_open_close: Option<ConfigNotificationOpenCloseAnim>,
64+ #[knuffel(child)]
65+ pub exit_confirmation_open_close: Option<ExitConfirmationOpenCloseAnim>,
66+ #[knuffel(child)]
67+ pub screenshot_ui_open: Option<ScreenshotUiOpenAnim>,
68+ #[knuffel(child)]
69+ pub overview_open_close: Option<OverviewOpenCloseAnim>,
70+}
71+
72+impl MergeWith<AnimationsPart> for Animations {
73+ fn merge_with(&mut self, part: &AnimationsPart) {
74+ self.off |= part.off;
75+ if part.on {
76+ self.off = false;
77+ }
78+
79+ merge!((self, part), slowdown);
80+
81+ // Animation properties are fairly tied together, except maybe `off`. So let's just save
82+ // ourselves the work and not merge within individual animations.
83+ merge_clone!(
84+ (self, part),
85+ workspace_switch,
86+ window_open,
87+ window_close,
88+ horizontal_view_movement,
89+ window_movement,
90+ window_resize,
91+ config_notification_open_close,
92+ exit_confirmation_open_close,
93+ screenshot_ui_open,
94+ overview_open_close,
95+ );
96+ }
97+}
98+
54 #[derive(Debug, Clone, Copy, PartialEq)]99 #[derive(Debug, Clone, Copy, PartialEq)]
55 pub struct Animation {100 pub struct Animation {
56 pub off: bool,101 pub off: bool,
niri-config/src/lib.rsmodified+2 -4
@@ -191,7 +191,7 @@ where
191 "clipboard" => m_merge!(clipboard),191 "clipboard" => m_merge!(clipboard),
192 "hotkey-overlay" => m_merge!(hotkey_overlay),192 "hotkey-overlay" => m_merge!(hotkey_overlay),
193 "config-notification" => m_merge!(config_notification),193 "config-notification" => m_merge!(config_notification),
194- "animations" => m_replace!(animations),194+ "animations" => m_merge!(animations),
195 "gestures" => m_merge!(gestures),195 "gestures" => m_merge!(gestures),
196 "overview" => m_merge!(overview),196 "overview" => m_merge!(overview),
197 "xwayland-satellite" => m_merge!(xwayland_satellite),197 "xwayland-satellite" => m_merge!(xwayland_satellite),
@@ -1303,9 +1303,7 @@ mod tests {
1303 },1303 },
1304 animations: Animations {1304 animations: Animations {
1305 off: false,1305 off: false,
1306- slowdown: FloatOrInt(1306+ slowdown: 2.0,
1307- 2.0,
1308- ),
1309 workspace_switch: WorkspaceSwitchAnim(1307 workspace_switch: WorkspaceSwitchAnim(
1310 Animation {1308 Animation {
1311 off: false,1309 off: false,
src/niri.rsmodified+2 -2
@@ -1381,7 +1381,7 @@ impl State {
1381 self.niri.layout.ensure_named_workspace(ws_config);1381 self.niri.layout.ensure_named_workspace(ws_config);
1382 }1382 }
1383 1383
1384- let rate = 1.0 / config.animations.slowdown.0.max(0.001);1384+ let rate = 1.0 / config.animations.slowdown.max(0.001);
1385 self.niri.clock.set_rate(rate);1385 self.niri.clock.set_rate(rate);
1386 self.niri1386 self.niri
1387 .clock1387 .clock
@@ -2320,7 +2320,7 @@ impl Niri {
2320 2320
2321 let mut animation_clock = Clock::default();2321 let mut animation_clock = Clock::default();
2322 2322
2323- let rate = 1.0 / config_.animations.slowdown.0.max(0.001);2323+ let rate = 1.0 / config_.animations.slowdown.max(0.001);
2324 animation_clock.set_rate(rate);2324 animation_clock.set_rate(rate);
2325 animation_clock.set_complete_instantly(config_.animations.off);2325 animation_clock.set_complete_instantly(config_.animations.off);
2326 2326