aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/animation/mod.rs40
-rw-r--r--src/layout/workspace.rs17
-rw-r--r--wiki/Configuration:-Animations.md1
3 files changed, 50 insertions, 8 deletions
diff --git a/src/animation/mod.rs b/src/animation/mod.rs
index 0a972ab8..9831f666 100644
--- a/src/animation/mod.rs
+++ b/src/animation/mod.rs
@@ -15,6 +15,7 @@ pub static ANIMATION_SLOWDOWN: AtomicF64 = AtomicF64::new(1.);
pub struct Animation {
from: f64,
to: f64,
+ initial_velocity: f64,
duration: Duration,
/// Time until the animation first reaches `to`.
///
@@ -52,10 +53,23 @@ impl Animation {
config: niri_config::Animation,
default: niri_config::Animation,
) -> Self {
+ let mut rv = Self::ease(from, to, initial_velocity, 0, Curve::EaseOutCubic);
if config.off {
- return Self::ease(from, to, 0, Curve::EaseOutCubic);
+ return rv;
}
+ rv.replace_config(config, default);
+ rv
+ }
+
+ pub fn replace_config(
+ &mut self,
+ config: niri_config::Animation,
+ default: niri_config::Animation,
+ ) {
+ 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.
@@ -82,23 +96,32 @@ impl Animation {
let params = SpringParams::new(p.damping_ratio, f64::from(p.stiffness), p.epsilon);
let spring = Spring {
- from,
- to,
- initial_velocity,
+ from: self.from,
+ to: self.to,
+ initial_velocity: self.initial_velocity,
params,
};
- Self::spring(spring)
+ *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::ease(from, to, u64::from(duration_ms), curve)
+ *self = Self::ease(
+ self.from,
+ self.to,
+ self.initial_velocity,
+ u64::from(duration_ms),
+ curve,
+ );
}
}
+
+ self.start_time = start_time;
+ self.current_time = current_time;
}
- pub fn ease(from: f64, to: f64, duration_ms: u64, curve: Curve) -> Self {
+ pub fn ease(from: f64, to: f64, initial_velocity: f64, duration_ms: u64, curve: Curve) -> Self {
// FIXME: ideally we shouldn't use current time here because animations started within the
// same frame cycle should have the same start time to be synchronized.
let now = get_monotonic_time();
@@ -109,6 +132,7 @@ impl Animation {
Self {
from,
to,
+ initial_velocity,
duration,
// Our current curves never overshoot.
clamped_duration: duration,
@@ -132,6 +156,7 @@ impl Animation {
Self {
from: spring.from,
to: spring.to,
+ initial_velocity: spring.initial_velocity,
duration,
clamped_duration,
start_time: now,
@@ -168,6 +193,7 @@ impl Animation {
Self {
from,
to,
+ initial_velocity,
duration,
clamped_duration: duration,
start_time: now,
diff --git a/src/layout/workspace.rs b/src/layout/workspace.rs
index ef8548ae..07dae721 100644
--- a/src/layout/workspace.rs
+++ b/src/layout/workspace.rs
@@ -903,7 +903,8 @@ impl<W: LayoutElement> Workspace<W> {
column.update_tile_sizes(false);
// Move other columns in tandem with resizing.
- if column.tiles[tile_idx].resize_animation().is_some() && offset != 0 {
+ let started_animation = column.tiles[tile_idx].resize_animation().is_some() && offset != 0;
+ if started_animation {
if self.active_column_idx <= col_idx {
for col in &mut self.columns[col_idx + 1..] {
col.animate_move_from_with_config(
@@ -932,6 +933,20 @@ impl<W: LayoutElement> Workspace<W> {
// FIXME: we will want to skip the animation in some cases here to make continuously
// resizing windows not look janky.
self.animate_view_offset_to_column(current_x, col_idx, None);
+
+ // If this animated resize caused a view animation, make sure that it uses the same
+ // config. This is important for always-centered view.
+ if let Some(ViewOffsetAdjustment::Animation(anim)) = &mut self.view_offset_adj {
+ // FIXME: animate_view_offset_to_column() will keep the previous running view
+ // 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(),
+ );
+ }
+ }
}
}
diff --git a/wiki/Configuration:-Animations.md b/wiki/Configuration:-Animations.md
index 0aec81be..7646926b 100644
--- a/wiki/Configuration:-Animations.md
+++ b/wiki/Configuration:-Animations.md
@@ -139,6 +139,7 @@ All horizontal camera view movement animations, such as:
- When a window off-screen is focused and the camera scrolls to it.
- When a new window appears off-screen and the camera scrolls to it.
- When a window resizes bigger and the camera scrolls to show it in full.
+ - Since 0.1.5, animated window resizes will use the `window-resize` animation parameters for the view animation to make them synchronized.
- After a horizontal touchpad gesture (a spring is recommended).
```