diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/animation/mod.rs | 52 | ||||
| -rw-r--r-- | src/layout/monitor.rs | 6 | ||||
| -rw-r--r-- | src/layout/tile.rs | 20 | ||||
| -rw-r--r-- | src/layout/workspace.rs | 36 | ||||
| -rw-r--r-- | src/ui/config_error_notification.rs | 8 |
5 files changed, 28 insertions, 94 deletions
diff --git a/src/animation/mod.rs b/src/animation/mod.rs index 9831f666..e22ff1f1 100644 --- a/src/animation/mod.rs +++ b/src/animation/mod.rs @@ -46,52 +46,27 @@ pub enum Curve { } impl Animation { - pub fn new( - from: f64, - to: f64, - initial_velocity: f64, - config: niri_config::Animation, - default: niri_config::Animation, - ) -> Self { + pub fn new(from: f64, to: f64, initial_velocity: f64, config: niri_config::Animation) -> Self { let mut rv = Self::ease(from, to, initial_velocity, 0, Curve::EaseOutCubic); if config.off { return rv; } - rv.replace_config(config, default); + rv.replace_config(config); rv } - pub fn replace_config( - &mut self, - config: niri_config::Animation, - default: niri_config::Animation, - ) { + pub fn replace_config(&mut self, config: niri_config::Animation) { + if config.off { + self.duration = Duration::ZERO; + self.clamped_duration = Duration::ZERO; + return; + } + let start_time = self.start_time; let current_time = self.current_time; - // Resolve defaults. - let (kind, easing_defaults) = match (config.kind, default.kind) { - // Configured spring. - (configured @ niri_config::AnimationKind::Spring(_), _) => (configured, None), - // Configured nothing, defaults spring. - ( - niri_config::AnimationKind::Easing(easing), - defaults @ niri_config::AnimationKind::Spring(_), - ) if easing == niri_config::EasingParams::unfilled() => (defaults, None), - // Configured easing or nothing, defaults easing. - ( - configured @ niri_config::AnimationKind::Easing(_), - niri_config::AnimationKind::Easing(defaults), - ) => (configured, Some(defaults)), - // Configured easing, defaults spring. - ( - configured @ niri_config::AnimationKind::Easing(_), - niri_config::AnimationKind::Spring(_), - ) => (configured, None), - }; - - match kind { + match config.kind { niri_config::AnimationKind::Spring(p) => { let params = SpringParams::new(p.damping_ratio, f64::from(p.stiffness), p.epsilon); @@ -104,15 +79,12 @@ impl Animation { *self = Self::spring(spring); } niri_config::AnimationKind::Easing(p) => { - let defaults = easing_defaults.unwrap_or(niri_config::EasingParams::default()); - let duration_ms = p.duration_ms.or(defaults.duration_ms).unwrap(); - let curve = Curve::from(p.curve.or(defaults.curve).unwrap()); *self = Self::ease( self.from, self.to, self.initial_velocity, - u64::from(duration_ms), - curve, + u64::from(p.duration_ms), + Curve::from(p.curve), ); } } diff --git a/src/layout/monitor.rs b/src/layout/monitor.rs index 7a19673e..604dcab3 100644 --- a/src/layout/monitor.rs +++ b/src/layout/monitor.rs @@ -127,8 +127,7 @@ impl<W: LayoutElement> Monitor<W> { current_idx, idx as f64, 0., - self.options.animations.workspace_switch, - niri_config::Animation::default_workspace_switch(), + self.options.animations.workspace_switch.0, ))); } @@ -882,8 +881,7 @@ impl<W: LayoutElement> Monitor<W> { gesture.current_idx, new_idx as f64, velocity, - self.options.animations.workspace_switch, - niri_config::Animation::default_workspace_switch(), + self.options.animations.workspace_switch.0, ))); true diff --git a/src/layout/tile.rs b/src/layout/tile.rs index 87c168b0..16779c10 100644 --- a/src/layout/tile.rs +++ b/src/layout/tile.rs @@ -150,13 +150,7 @@ impl<W: LayoutElement> Tile<W> { let change = self.window.size().to_point() - size_from.to_point(); let change = max(change.x.abs(), change.y.abs()); if change > RESIZE_ANIMATION_THRESHOLD { - let anim = Animation::new( - 0., - 1., - 0., - self.options.animations.window_resize, - niri_config::Animation::default_window_resize(), - ); + let anim = Animation::new(0., 1., 0., self.options.animations.window_resize.0); self.resize_animation = Some(ResizeAnimation { anim, size_from, @@ -230,8 +224,7 @@ impl<W: LayoutElement> Tile<W> { 0., 1., 0., - self.options.animations.window_open, - niri_config::Animation::default_window_open(), + self.options.animations.window_open.0, )); } @@ -244,23 +237,18 @@ impl<W: LayoutElement> Tile<W> { } pub fn animate_move_from(&mut self, from: Point<i32, Logical>) { - self.animate_move_from_with_config( - from, - self.options.animations.window_movement, - niri_config::Animation::default_window_movement(), - ); + self.animate_move_from_with_config(from, self.options.animations.window_movement.0); } pub fn animate_move_from_with_config( &mut self, from: Point<i32, Logical>, config: niri_config::Animation, - default: niri_config::Animation, ) { let current_offset = self.render_offset(); self.move_animation = Some(MoveAnimation { - anim: Animation::new(1., 0., 0., config, default), + anim: Animation::new(1., 0., 0., config), from: from + current_offset, }); } diff --git a/src/layout/workspace.rs b/src/layout/workspace.rs index 271f6639..7474d650 100644 --- a/src/layout/workspace.rs +++ b/src/layout/workspace.rs @@ -525,8 +525,7 @@ impl<W: LayoutElement> Workspace<W> { self.view_offset as f64, new_view_offset as f64, 0., - self.options.animations.horizontal_view_movement, - niri_config::Animation::default_horizontal_view_movement(), + self.options.animations.horizontal_view_movement.0, ))); } @@ -857,8 +856,7 @@ impl<W: LayoutElement> Workspace<W> { for tile in &mut column.tiles[window_idx + 1..] { tile.animate_move_from_with_config( Point::from((0, offset_y)), - self.options.animations.window_resize, - niri_config::Animation::default_window_resize(), + self.options.animations.window_resize.0, ); } @@ -1034,16 +1032,14 @@ impl<W: LayoutElement> Workspace<W> { for col in &mut self.columns[col_idx + 1..] { col.animate_move_from_with_config( offset, - self.options.animations.window_resize, - niri_config::Animation::default_window_resize(), + self.options.animations.window_resize.0, ); } } else { for col in &mut self.columns[..=col_idx] { col.animate_move_from_with_config( -offset, - self.options.animations.window_resize, - niri_config::Animation::default_window_resize(), + self.options.animations.window_resize.0, ); } } @@ -1074,10 +1070,7 @@ impl<W: LayoutElement> Workspace<W> { // offset animation if the target was the same; maybe we shouldn't replace in this // case? if started_animation { - anim.replace_config( - self.options.animations.window_resize, - niri_config::Animation::default_window_resize(), - ); + anim.replace_config(self.options.animations.window_resize.0); } } } @@ -1149,13 +1142,7 @@ impl<W: LayoutElement> Workspace<W> { (1., 1.) }; - let anim = Animation::new( - 1., - 0., - 0., - self.options.animations.window_close, - niri_config::Animation::default_window_close(), - ); + let anim = Animation::new(1., 0., 0., self.options.animations.window_close.0); let res = ClosingWindow::new( renderer, @@ -2021,8 +2008,7 @@ impl<W: LayoutElement> Workspace<W> { current_view_offset + delta, target_view_offset as f64, velocity, - self.options.animations.horizontal_view_movement, - niri_config::Animation::default_horizontal_view_movement(), + self.options.animations.horizontal_view_movement.0, ))); // HACK: deal with things like snapping to the right edge of a larger-than-view window. @@ -2188,8 +2174,7 @@ impl<W: LayoutElement> Column<W> { pub fn animate_move_from(&mut self, from_x_offset: i32) { self.animate_move_from_with_config( from_x_offset, - self.options.animations.window_movement, - niri_config::Animation::default_window_movement(), + self.options.animations.window_movement.0, ); } @@ -2197,7 +2182,6 @@ impl<W: LayoutElement> Column<W> { &mut self, from_x_offset: i32, config: niri_config::Animation, - default: niri_config::Animation, ) { let current_offset = self.move_animation.as_ref().map_or(0., Animation::value); @@ -2206,7 +2190,6 @@ impl<W: LayoutElement> Column<W> { 0., 0., config, - default, )); } @@ -2257,8 +2240,7 @@ impl<W: LayoutElement> Column<W> { for tile in &mut self.tiles[tile_idx + 1..] { tile.animate_move_from_with_config( Point::from((0, offset)), - self.options.animations.window_resize, - niri_config::Animation::default_window_resize(), + self.options.animations.window_resize.0, ); } } diff --git a/src/ui/config_error_notification.rs b/src/ui/config_error_notification.rs index d49ab4f0..1331b912 100644 --- a/src/ui/config_error_notification.rs +++ b/src/ui/config_error_notification.rs @@ -59,13 +59,7 @@ impl ConfigErrorNotification { fn animation(&self, from: f64, to: f64) -> Animation { let c = self.config.borrow(); - Animation::new( - from, - to, - 0., - c.animations.config_notification_open_close, - niri_config::Animation::default_config_notification_open_close(), - ) + Animation::new(from, to, 0., c.animations.config_notification_open_close.0) } pub fn show_created(&mut self, created_path: Option<PathBuf>) { |
