mirror of
https://github.com/niri-wm/niri.git
synced 2026-06-23 02:05:33 +07:00
config: Add merging for Animations
This commit is contained in:
@@ -1,34 +1,22 @@
|
|||||||
use knuffel::errors::DecodeError;
|
use knuffel::errors::DecodeError;
|
||||||
use knuffel::Decode as _;
|
use knuffel::Decode as _;
|
||||||
|
|
||||||
use crate::utils::{expect_only_children, parse_arg_node};
|
use crate::utils::{expect_only_children, parse_arg_node, MergeWith};
|
||||||
use crate::FloatOrInt;
|
use crate::FloatOrInt;
|
||||||
|
|
||||||
#[derive(knuffel::Decode, Debug, Clone, PartialEq)]
|
#[derive(Debug, Clone, PartialEq)]
|
||||||
pub struct Animations {
|
pub struct Animations {
|
||||||
#[knuffel(child)]
|
|
||||||
pub off: bool,
|
pub off: bool,
|
||||||
#[knuffel(child, unwrap(argument), default = FloatOrInt(1.))]
|
pub slowdown: f64,
|
||||||
pub slowdown: FloatOrInt<0, { i32::MAX }>,
|
|
||||||
#[knuffel(child, default)]
|
|
||||||
pub workspace_switch: WorkspaceSwitchAnim,
|
pub workspace_switch: WorkspaceSwitchAnim,
|
||||||
#[knuffel(child, default)]
|
|
||||||
pub window_open: WindowOpenAnim,
|
pub window_open: WindowOpenAnim,
|
||||||
#[knuffel(child, default)]
|
|
||||||
pub window_close: WindowCloseAnim,
|
pub window_close: WindowCloseAnim,
|
||||||
#[knuffel(child, default)]
|
|
||||||
pub horizontal_view_movement: HorizontalViewMovementAnim,
|
pub horizontal_view_movement: HorizontalViewMovementAnim,
|
||||||
#[knuffel(child, default)]
|
|
||||||
pub window_movement: WindowMovementAnim,
|
pub window_movement: WindowMovementAnim,
|
||||||
#[knuffel(child, default)]
|
|
||||||
pub window_resize: WindowResizeAnim,
|
pub window_resize: WindowResizeAnim,
|
||||||
#[knuffel(child, default)]
|
|
||||||
pub config_notification_open_close: ConfigNotificationOpenCloseAnim,
|
pub config_notification_open_close: ConfigNotificationOpenCloseAnim,
|
||||||
#[knuffel(child, default)]
|
|
||||||
pub exit_confirmation_open_close: ExitConfirmationOpenCloseAnim,
|
pub exit_confirmation_open_close: ExitConfirmationOpenCloseAnim,
|
||||||
#[knuffel(child, default)]
|
|
||||||
pub screenshot_ui_open: ScreenshotUiOpenAnim,
|
pub screenshot_ui_open: ScreenshotUiOpenAnim,
|
||||||
#[knuffel(child, default)]
|
|
||||||
pub overview_open_close: OverviewOpenCloseAnim,
|
pub overview_open_close: OverviewOpenCloseAnim,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -36,7 +24,7 @@ impl Default for Animations {
|
|||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self {
|
Self {
|
||||||
off: false,
|
off: false,
|
||||||
slowdown: FloatOrInt(1.),
|
slowdown: 1.,
|
||||||
workspace_switch: Default::default(),
|
workspace_switch: Default::default(),
|
||||||
horizontal_view_movement: Default::default(),
|
horizontal_view_movement: Default::default(),
|
||||||
window_movement: Default::default(),
|
window_movement: Default::default(),
|
||||||
@@ -51,6 +39,63 @@ impl Default for Animations {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(knuffel::Decode, Debug, Clone, PartialEq)]
|
||||||
|
pub struct AnimationsPart {
|
||||||
|
#[knuffel(child)]
|
||||||
|
pub off: bool,
|
||||||
|
#[knuffel(child)]
|
||||||
|
pub on: bool,
|
||||||
|
#[knuffel(child, unwrap(argument))]
|
||||||
|
pub slowdown: Option<FloatOrInt<0, { i32::MAX }>>,
|
||||||
|
#[knuffel(child)]
|
||||||
|
pub workspace_switch: Option<WorkspaceSwitchAnim>,
|
||||||
|
#[knuffel(child)]
|
||||||
|
pub window_open: Option<WindowOpenAnim>,
|
||||||
|
#[knuffel(child)]
|
||||||
|
pub window_close: Option<WindowCloseAnim>,
|
||||||
|
#[knuffel(child)]
|
||||||
|
pub horizontal_view_movement: Option<HorizontalViewMovementAnim>,
|
||||||
|
#[knuffel(child)]
|
||||||
|
pub window_movement: Option<WindowMovementAnim>,
|
||||||
|
#[knuffel(child)]
|
||||||
|
pub window_resize: Option<WindowResizeAnim>,
|
||||||
|
#[knuffel(child)]
|
||||||
|
pub config_notification_open_close: Option<ConfigNotificationOpenCloseAnim>,
|
||||||
|
#[knuffel(child)]
|
||||||
|
pub exit_confirmation_open_close: Option<ExitConfirmationOpenCloseAnim>,
|
||||||
|
#[knuffel(child)]
|
||||||
|
pub screenshot_ui_open: Option<ScreenshotUiOpenAnim>,
|
||||||
|
#[knuffel(child)]
|
||||||
|
pub overview_open_close: Option<OverviewOpenCloseAnim>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl MergeWith<AnimationsPart> for Animations {
|
||||||
|
fn merge_with(&mut self, part: &AnimationsPart) {
|
||||||
|
self.off |= part.off;
|
||||||
|
if part.on {
|
||||||
|
self.off = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
merge!((self, part), slowdown);
|
||||||
|
|
||||||
|
// Animation properties are fairly tied together, except maybe `off`. So let's just save
|
||||||
|
// ourselves the work and not merge within individual animations.
|
||||||
|
merge_clone!(
|
||||||
|
(self, part),
|
||||||
|
workspace_switch,
|
||||||
|
window_open,
|
||||||
|
window_close,
|
||||||
|
horizontal_view_movement,
|
||||||
|
window_movement,
|
||||||
|
window_resize,
|
||||||
|
config_notification_open_close,
|
||||||
|
exit_confirmation_open_close,
|
||||||
|
screenshot_ui_open,
|
||||||
|
overview_open_close,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq)]
|
#[derive(Debug, Clone, Copy, PartialEq)]
|
||||||
pub struct Animation {
|
pub struct Animation {
|
||||||
pub off: bool,
|
pub off: bool,
|
||||||
|
|||||||
@@ -191,7 +191,7 @@ where
|
|||||||
"clipboard" => m_merge!(clipboard),
|
"clipboard" => m_merge!(clipboard),
|
||||||
"hotkey-overlay" => m_merge!(hotkey_overlay),
|
"hotkey-overlay" => m_merge!(hotkey_overlay),
|
||||||
"config-notification" => m_merge!(config_notification),
|
"config-notification" => m_merge!(config_notification),
|
||||||
"animations" => m_replace!(animations),
|
"animations" => m_merge!(animations),
|
||||||
"gestures" => m_merge!(gestures),
|
"gestures" => m_merge!(gestures),
|
||||||
"overview" => m_merge!(overview),
|
"overview" => m_merge!(overview),
|
||||||
"xwayland-satellite" => m_merge!(xwayland_satellite),
|
"xwayland-satellite" => m_merge!(xwayland_satellite),
|
||||||
@@ -1303,9 +1303,7 @@ mod tests {
|
|||||||
},
|
},
|
||||||
animations: Animations {
|
animations: Animations {
|
||||||
off: false,
|
off: false,
|
||||||
slowdown: FloatOrInt(
|
slowdown: 2.0,
|
||||||
2.0,
|
|
||||||
),
|
|
||||||
workspace_switch: WorkspaceSwitchAnim(
|
workspace_switch: WorkspaceSwitchAnim(
|
||||||
Animation {
|
Animation {
|
||||||
off: false,
|
off: false,
|
||||||
|
|||||||
+2
-2
@@ -1381,7 +1381,7 @@ impl State {
|
|||||||
self.niri.layout.ensure_named_workspace(ws_config);
|
self.niri.layout.ensure_named_workspace(ws_config);
|
||||||
}
|
}
|
||||||
|
|
||||||
let rate = 1.0 / config.animations.slowdown.0.max(0.001);
|
let rate = 1.0 / config.animations.slowdown.max(0.001);
|
||||||
self.niri.clock.set_rate(rate);
|
self.niri.clock.set_rate(rate);
|
||||||
self.niri
|
self.niri
|
||||||
.clock
|
.clock
|
||||||
@@ -2320,7 +2320,7 @@ impl Niri {
|
|||||||
|
|
||||||
let mut animation_clock = Clock::default();
|
let mut animation_clock = Clock::default();
|
||||||
|
|
||||||
let rate = 1.0 / config_.animations.slowdown.0.max(0.001);
|
let rate = 1.0 / config_.animations.slowdown.max(0.001);
|
||||||
animation_clock.set_rate(rate);
|
animation_clock.set_rate(rate);
|
||||||
animation_clock.set_complete_instantly(config_.animations.off);
|
animation_clock.set_complete_instantly(config_.animations.off);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user