forge
Explore
Log in

Don't you dare go Hollow

Refactor animations to take explicit current time

Browse files at this commit

93cee2994ab9ccf59a09f61d5b8acf6cd937d654Ivan MolodetskikhParent: 9c7e8d0
niri-visual-tests/src/cases/gradient_angle.rsmodified+3 -3
@@ -7,9 +7,9 @@ use niri::render_helpers::border::BorderRenderElement;
7 use niri_config::{Color, CornerRadius, GradientInterpolation};7 use niri_config::{Color, CornerRadius, GradientInterpolation};
8 use smithay::backend::renderer::element::RenderElement;8 use smithay::backend::renderer::element::RenderElement;
9 use smithay::backend::renderer::gles::GlesRenderer;9 use smithay::backend::renderer::gles::GlesRenderer;
10-use smithay::utils::{Logical, Physical, Rectangle, Size};10+use smithay::utils::{Physical, Rectangle, Size};
11 11
12-use super::TestCase;12+use super::{Args, TestCase};
13 13
14 pub struct GradientAngle {14 pub struct GradientAngle {
15 angle: f32,15 angle: f32,
@@ -17,7 +17,7 @@ pub struct GradientAngle {
17 }17 }
18 18
19 impl GradientAngle {19 impl GradientAngle {
20- pub fn new(_size: Size<i32, Logical>) -> Self {20+ pub fn new(_args: Args) -> Self {
21 Self {21 Self {
22 angle: 0.,22 angle: 0.,
23 prev_time: Duration::ZERO,23 prev_time: Duration::ZERO,
niri-visual-tests/src/cases/gradient_area.rsmodified+3 -3
@@ -8,9 +8,9 @@ use niri::render_helpers::border::BorderRenderElement;
8 use niri_config::{Color, CornerRadius, FloatOrInt, GradientInterpolation};8 use niri_config::{Color, CornerRadius, FloatOrInt, GradientInterpolation};
9 use smithay::backend::renderer::element::RenderElement;9 use smithay::backend::renderer::element::RenderElement;
10 use smithay::backend::renderer::gles::GlesRenderer;10 use smithay::backend::renderer::gles::GlesRenderer;
11-use smithay::utils::{Logical, Physical, Point, Rectangle, Size};11+use smithay::utils::{Physical, Point, Rectangle, Size};
12 12
13-use super::TestCase;13+use super::{Args, TestCase};
14 14
15 pub struct GradientArea {15 pub struct GradientArea {
16 progress: f32,16 progress: f32,
@@ -19,7 +19,7 @@ pub struct GradientArea {
19 }19 }
20 20
21 impl GradientArea {21 impl GradientArea {
22- pub fn new(_size: Size<i32, Logical>) -> Self {22+ pub fn new(_args: Args) -> Self {
23 let border = FocusRing::new(niri_config::FocusRing {23 let border = FocusRing::new(niri_config::FocusRing {
24 off: false,24 off: false,
25 width: FloatOrInt(1.),25 width: FloatOrInt(1.),
niri-visual-tests/src/cases/gradient_oklab.rsmodified+3 -3
@@ -4,16 +4,16 @@ use niri_config::{
4 };4 };
5 use smithay::backend::renderer::element::RenderElement;5 use smithay::backend::renderer::element::RenderElement;
6 use smithay::backend::renderer::gles::GlesRenderer;6 use smithay::backend::renderer::gles::GlesRenderer;
7-use smithay::utils::{Logical, Physical, Rectangle, Size};7+use smithay::utils::{Physical, Rectangle, Size};
8 8
9-use super::TestCase;9+use super::{Args, TestCase};
10 10
11 pub struct GradientOklab {11 pub struct GradientOklab {
12 gradient_format: GradientInterpolation,12 gradient_format: GradientInterpolation,
13 }13 }
14 14
15 impl GradientOklab {15 impl GradientOklab {
16- pub fn new(_size: Size<i32, Logical>) -> Self {16+ pub fn new(_args: Args) -> Self {
17 Self {17 Self {
18 gradient_format: GradientInterpolation {18 gradient_format: GradientInterpolation {
19 color_space: GradientColorSpace::Oklab,19 color_space: GradientColorSpace::Oklab,
niri-visual-tests/src/cases/gradient_oklab_alpha.rsmodified+3 -3
@@ -2,16 +2,16 @@ use niri::render_helpers::border::BorderRenderElement;
2 use niri_config::{Color, CornerRadius, GradientColorSpace, GradientInterpolation};2 use niri_config::{Color, CornerRadius, GradientColorSpace, GradientInterpolation};
3 use smithay::backend::renderer::element::RenderElement;3 use smithay::backend::renderer::element::RenderElement;
4 use smithay::backend::renderer::gles::GlesRenderer;4 use smithay::backend::renderer::gles::GlesRenderer;
5-use smithay::utils::{Logical, Physical, Rectangle, Size};5+use smithay::utils::{Physical, Rectangle, Size};
6 6
7-use super::TestCase;7+use super::{Args, TestCase};
8 8
9 pub struct GradientOklabAlpha {9 pub struct GradientOklabAlpha {
10 gradient_format: GradientInterpolation,10 gradient_format: GradientInterpolation,
11 }11 }
12 12
13 impl GradientOklabAlpha {13 impl GradientOklabAlpha {
14- pub fn new(_size: Size<i32, Logical>) -> Self {14+ pub fn new(_args: Args) -> Self {
15 Self {15 Self {
16 gradient_format: GradientInterpolation {16 gradient_format: GradientInterpolation {
17 color_space: GradientColorSpace::Oklab,17 color_space: GradientColorSpace::Oklab,
niri-visual-tests/src/cases/gradient_oklch_alpha.rsmodified+3 -3
@@ -4,16 +4,16 @@ use niri_config::{
4 };4 };
5 use smithay::backend::renderer::element::RenderElement;5 use smithay::backend::renderer::element::RenderElement;
6 use smithay::backend::renderer::gles::GlesRenderer;6 use smithay::backend::renderer::gles::GlesRenderer;
7-use smithay::utils::{Logical, Physical, Rectangle, Size};7+use smithay::utils::{Physical, Rectangle, Size};
8 8
9-use super::TestCase;9+use super::{Args, TestCase};
10 10
11 pub struct GradientOklchAlpha {11 pub struct GradientOklchAlpha {
12 gradient_format: GradientInterpolation,12 gradient_format: GradientInterpolation,
13 }13 }
14 14
15 impl GradientOklchAlpha {15 impl GradientOklchAlpha {
16- pub fn new(_size: Size<i32, Logical>) -> Self {16+ pub fn new(_args: Args) -> Self {
17 Self {17 Self {
18 gradient_format: GradientInterpolation {18 gradient_format: GradientInterpolation {
19 color_space: GradientColorSpace::Oklch,19 color_space: GradientColorSpace::Oklch,
niri-visual-tests/src/cases/gradient_oklch_decreasing.rsmodified+3 -3
@@ -4,16 +4,16 @@ use niri_config::{
4 };4 };
5 use smithay::backend::renderer::element::RenderElement;5 use smithay::backend::renderer::element::RenderElement;
6 use smithay::backend::renderer::gles::GlesRenderer;6 use smithay::backend::renderer::gles::GlesRenderer;
7-use smithay::utils::{Logical, Physical, Rectangle, Size};7+use smithay::utils::{Physical, Rectangle, Size};
8 8
9-use super::TestCase;9+use super::{Args, TestCase};
10 10
11 pub struct GradientOklchDecreasing {11 pub struct GradientOklchDecreasing {
12 gradient_format: GradientInterpolation,12 gradient_format: GradientInterpolation,
13 }13 }
14 14
15 impl GradientOklchDecreasing {15 impl GradientOklchDecreasing {
16- pub fn new(_size: Size<i32, Logical>) -> Self {16+ pub fn new(_args: Args) -> Self {
17 Self {17 Self {
18 gradient_format: GradientInterpolation {18 gradient_format: GradientInterpolation {
19 color_space: GradientColorSpace::Oklch,19 color_space: GradientColorSpace::Oklch,
niri-visual-tests/src/cases/gradient_oklch_increasing.rsmodified+3 -3
@@ -4,16 +4,16 @@ use niri_config::{
4 };4 };
5 use smithay::backend::renderer::element::RenderElement;5 use smithay::backend::renderer::element::RenderElement;
6 use smithay::backend::renderer::gles::GlesRenderer;6 use smithay::backend::renderer::gles::GlesRenderer;
7-use smithay::utils::{Logical, Physical, Rectangle, Size};7+use smithay::utils::{Physical, Rectangle, Size};
8 8
9-use super::TestCase;9+use super::{Args, TestCase};
10 10
11 pub struct GradientOklchIncreasing {11 pub struct GradientOklchIncreasing {
12 gradient_format: GradientInterpolation,12 gradient_format: GradientInterpolation,
13 }13 }
14 14
15 impl GradientOklchIncreasing {15 impl GradientOklchIncreasing {
16- pub fn new(_size: Size<i32, Logical>) -> Self {16+ pub fn new(_args: Args) -> Self {
17 Self {17 Self {
18 gradient_format: GradientInterpolation {18 gradient_format: GradientInterpolation {
19 color_space: GradientColorSpace::Oklch,19 color_space: GradientColorSpace::Oklch,
niri-visual-tests/src/cases/gradient_oklch_longer.rsmodified+3 -3
@@ -4,16 +4,16 @@ use niri_config::{
4 };4 };
5 use smithay::backend::renderer::element::RenderElement;5 use smithay::backend::renderer::element::RenderElement;
6 use smithay::backend::renderer::gles::GlesRenderer;6 use smithay::backend::renderer::gles::GlesRenderer;
7-use smithay::utils::{Logical, Physical, Rectangle, Size};7+use smithay::utils::{Physical, Rectangle, Size};
8 8
9-use super::TestCase;9+use super::{Args, TestCase};
10 10
11 pub struct GradientOklchLonger {11 pub struct GradientOklchLonger {
12 gradient_format: GradientInterpolation,12 gradient_format: GradientInterpolation,
13 }13 }
14 14
15 impl GradientOklchLonger {15 impl GradientOklchLonger {
16- pub fn new(_size: Size<i32, Logical>) -> Self {16+ pub fn new(_args: Args) -> Self {
17 Self {17 Self {
18 gradient_format: GradientInterpolation {18 gradient_format: GradientInterpolation {
19 color_space: GradientColorSpace::Oklch,19 color_space: GradientColorSpace::Oklch,
niri-visual-tests/src/cases/gradient_oklch_shorter.rsmodified+3 -3
@@ -4,16 +4,16 @@ use niri_config::{
4 };4 };
5 use smithay::backend::renderer::element::RenderElement;5 use smithay::backend::renderer::element::RenderElement;
6 use smithay::backend::renderer::gles::GlesRenderer;6 use smithay::backend::renderer::gles::GlesRenderer;
7-use smithay::utils::{Logical, Physical, Rectangle, Size};7+use smithay::utils::{Physical, Rectangle, Size};
8 8
9-use super::TestCase;9+use super::{Args, TestCase};
10 10
11 pub struct GradientOklchShorter {11 pub struct GradientOklchShorter {
12 gradient_format: GradientInterpolation,12 gradient_format: GradientInterpolation,
13 }13 }
14 14
15 impl GradientOklchShorter {15 impl GradientOklchShorter {
16- pub fn new(_size: Size<i32, Logical>) -> Self {16+ pub fn new(_args: Args) -> Self {
17 Self {17 Self {
18 gradient_format: GradientInterpolation {18 gradient_format: GradientInterpolation {
19 color_space: GradientColorSpace::Oklch,19 color_space: GradientColorSpace::Oklch,
niri-visual-tests/src/cases/gradient_srgb.rsmodified+3 -3
@@ -4,16 +4,16 @@ use niri_config::{
4 };4 };
5 use smithay::backend::renderer::element::RenderElement;5 use smithay::backend::renderer::element::RenderElement;
6 use smithay::backend::renderer::gles::GlesRenderer;6 use smithay::backend::renderer::gles::GlesRenderer;
7-use smithay::utils::{Logical, Physical, Rectangle, Size};7+use smithay::utils::{Physical, Rectangle, Size};
8 8
9-use super::TestCase;9+use super::{Args, TestCase};
10 10
11 pub struct GradientSrgb {11 pub struct GradientSrgb {
12 gradient_format: GradientInterpolation,12 gradient_format: GradientInterpolation,
13 }13 }
14 14
15 impl GradientSrgb {15 impl GradientSrgb {
16- pub fn new(_size: Size<i32, Logical>) -> Self {16+ pub fn new(_args: Args) -> Self {
17 Self {17 Self {
18 gradient_format: GradientInterpolation {18 gradient_format: GradientInterpolation {
19 color_space: GradientColorSpace::Srgb,19 color_space: GradientColorSpace::Srgb,
niri-visual-tests/src/cases/gradient_srgb_alpha.rsmodified+3 -3
@@ -2,16 +2,16 @@ use niri::render_helpers::border::BorderRenderElement;
2 use niri_config::{Color, CornerRadius, GradientColorSpace, GradientInterpolation};2 use niri_config::{Color, CornerRadius, GradientColorSpace, GradientInterpolation};
3 use smithay::backend::renderer::element::RenderElement;3 use smithay::backend::renderer::element::RenderElement;
4 use smithay::backend::renderer::gles::GlesRenderer;4 use smithay::backend::renderer::gles::GlesRenderer;
5-use smithay::utils::{Logical, Physical, Rectangle, Size};5+use smithay::utils::{Physical, Rectangle, Size};
6 6
7-use super::TestCase;7+use super::{Args, TestCase};
8 8
9 pub struct GradientSrgbAlpha {9 pub struct GradientSrgbAlpha {
10 gradient_format: GradientInterpolation,10 gradient_format: GradientInterpolation,
11 }11 }
12 12
13 impl GradientSrgbAlpha {13 impl GradientSrgbAlpha {
14- pub fn new(_size: Size<i32, Logical>) -> Self {14+ pub fn new(_args: Args) -> Self {
15 Self {15 Self {
16 gradient_format: GradientInterpolation {16 gradient_format: GradientInterpolation {
17 color_space: GradientColorSpace::Srgb,17 color_space: GradientColorSpace::Srgb,
niri-visual-tests/src/cases/gradient_srgblinear.rsmodified+3 -3
@@ -4,16 +4,16 @@ use niri_config::{
4 };4 };
5 use smithay::backend::renderer::element::RenderElement;5 use smithay::backend::renderer::element::RenderElement;
6 use smithay::backend::renderer::gles::GlesRenderer;6 use smithay::backend::renderer::gles::GlesRenderer;
7-use smithay::utils::{Logical, Physical, Rectangle, Size};7+use smithay::utils::{Physical, Rectangle, Size};
8 8
9-use super::TestCase;9+use super::{Args, TestCase};
10 10
11 pub struct GradientSrgbLinear {11 pub struct GradientSrgbLinear {
12 gradient_format: GradientInterpolation,12 gradient_format: GradientInterpolation,
13 }13 }
14 14
15 impl GradientSrgbLinear {15 impl GradientSrgbLinear {
16- pub fn new(_size: Size<i32, Logical>) -> Self {16+ pub fn new(_args: Args) -> Self {
17 Self {17 Self {
18 gradient_format: GradientInterpolation {18 gradient_format: GradientInterpolation {
19 color_space: GradientColorSpace::SrgbLinear,19 color_space: GradientColorSpace::SrgbLinear,
niri-visual-tests/src/cases/gradient_srgblinear_alpha.rsmodified+3 -3
@@ -2,16 +2,16 @@ use niri::render_helpers::border::BorderRenderElement;
2 use niri_config::{Color, CornerRadius, GradientColorSpace, GradientInterpolation};2 use niri_config::{Color, CornerRadius, GradientColorSpace, GradientInterpolation};
3 use smithay::backend::renderer::element::RenderElement;3 use smithay::backend::renderer::element::RenderElement;
4 use smithay::backend::renderer::gles::GlesRenderer;4 use smithay::backend::renderer::gles::GlesRenderer;
5-use smithay::utils::{Logical, Physical, Rectangle, Size};5+use smithay::utils::{Physical, Rectangle, Size};
6 6
7-use super::TestCase;7+use super::{Args, TestCase};
8 8
9 pub struct GradientSrgbLinearAlpha {9 pub struct GradientSrgbLinearAlpha {
10 gradient_format: GradientInterpolation,10 gradient_format: GradientInterpolation,
11 }11 }
12 12
13 impl GradientSrgbLinearAlpha {13 impl GradientSrgbLinearAlpha {
14- pub fn new(_size: Size<i32, Logical>) -> Self {14+ pub fn new(_args: Args) -> Self {
15 Self {15 Self {
16 gradient_format: GradientInterpolation {16 gradient_format: GradientInterpolation {
17 color_space: GradientColorSpace::SrgbLinear,17 color_space: GradientColorSpace::SrgbLinear,
niri-visual-tests/src/cases/layout.rsmodified+30 -22
@@ -1,18 +1,18 @@
1 use std::collections::HashMap;1 use std::collections::HashMap;
2 use std::time::Duration;2 use std::time::Duration;
3 3
4+use niri::animation::Clock;
4 use niri::layout::workspace::ColumnWidth;5 use niri::layout::workspace::ColumnWidth;
5 use niri::layout::{LayoutElement as _, Options};6 use niri::layout::{LayoutElement as _, Options};
6 use niri::render_helpers::RenderTarget;7 use niri::render_helpers::RenderTarget;
7-use niri::utils::get_monotonic_time;
8 use niri_config::{Color, FloatOrInt, OutputName};8 use niri_config::{Color, FloatOrInt, OutputName};
9 use smithay::backend::renderer::element::RenderElement;9 use smithay::backend::renderer::element::RenderElement;
10 use smithay::backend::renderer::gles::GlesRenderer;10 use smithay::backend::renderer::gles::GlesRenderer;
11 use smithay::desktop::layer_map_for_output;11 use smithay::desktop::layer_map_for_output;
12 use smithay::output::{Mode, Output, PhysicalProperties, Subpixel};12 use smithay::output::{Mode, Output, PhysicalProperties, Subpixel};
13-use smithay::utils::{Logical, Physical, Size};13+use smithay::utils::{Physical, Size};
14 14
15-use super::TestCase;15+use super::{Args, TestCase};
16 use crate::test_window::TestWindow;16 use crate::test_window::TestWindow;
17 17
18 type DynStepFn = Box<dyn FnOnce(&mut Layout)>;18 type DynStepFn = Box<dyn FnOnce(&mut Layout)>;
@@ -20,13 +20,16 @@ type DynStepFn = Box<dyn FnOnce(&mut Layout)>;
20 pub struct Layout {20 pub struct Layout {
21 output: Output,21 output: Output,
22 windows: Vec<TestWindow>,22 windows: Vec<TestWindow>,
23+ clock: Clock,
23 layout: niri::layout::Layout<TestWindow>,24 layout: niri::layout::Layout<TestWindow>,
24 start_time: Duration,25 start_time: Duration,
25 steps: HashMap<Duration, DynStepFn>,26 steps: HashMap<Duration, DynStepFn>,
26 }27 }
27 28
28 impl Layout {29 impl Layout {
29- pub fn new(size: Size<i32, Logical>) -> Self {30+ pub fn new(args: Args) -> Self {
31+ let Args { size, clock } = args;
32+
30 let output = Output::new(33 let output = Output::new(
31 String::new(),34 String::new(),
32 PhysicalProperties {35 PhysicalProperties {
@@ -63,20 +66,23 @@ impl Layout {
63 },66 },
64 ..Default::default()67 ..Default::default()
65 };68 };
66- let mut layout = niri::layout::Layout::with_options(options);69+ let mut layout = niri::layout::Layout::with_options(clock.clone(), options);
67 layout.add_output(output.clone());70 layout.add_output(output.clone());
68 71
72+ let start_time = clock.now();
73+
69 Self {74 Self {
70 output,75 output,
71 windows: Vec::new(),76 windows: Vec::new(),
77+ clock,
72 layout,78 layout,
73- start_time: get_monotonic_time(),79+ start_time,
74 steps: HashMap::new(),80 steps: HashMap::new(),
75 }81 }
76 }82 }
77 83
78- pub fn open_in_between(size: Size<i32, Logical>) -> Self {84+ pub fn open_in_between(args: Args) -> Self {
79- let mut rv = Self::new(size);85+ let mut rv = Self::new(args);
80 86
81 rv.add_window(TestWindow::freeform(0), Some(ColumnWidth::Proportion(0.3)));87 rv.add_window(TestWindow::freeform(0), Some(ColumnWidth::Proportion(0.3)));
82 rv.add_window(TestWindow::freeform(1), Some(ColumnWidth::Proportion(0.3)));88 rv.add_window(TestWindow::freeform(1), Some(ColumnWidth::Proportion(0.3)));
@@ -91,8 +97,8 @@ impl Layout {
91 rv97 rv
92 }98 }
93 99
94- pub fn open_multiple_quickly(size: Size<i32, Logical>) -> Self {100+ pub fn open_multiple_quickly(args: Args) -> Self {
95- let mut rv = Self::new(size);101+ let mut rv = Self::new(args);
96 102
97 for delay in [100, 200, 300] {103 for delay in [100, 200, 300] {
98 rv.add_step(delay, move |l| {104 rv.add_step(delay, move |l| {
@@ -105,8 +111,8 @@ impl Layout {
105 rv111 rv
106 }112 }
107 113
108- pub fn open_multiple_quickly_big(size: Size<i32, Logical>) -> Self {114+ pub fn open_multiple_quickly_big(args: Args) -> Self {
109- let mut rv = Self::new(size);115+ let mut rv = Self::new(args);
110 116
111 for delay in [100, 200, 300] {117 for delay in [100, 200, 300] {
112 rv.add_step(delay, move |l| {118 rv.add_step(delay, move |l| {
@@ -119,8 +125,8 @@ impl Layout {
119 rv125 rv
120 }126 }
121 127
122- pub fn open_to_the_left(size: Size<i32, Logical>) -> Self {128+ pub fn open_to_the_left(args: Args) -> Self {
123- let mut rv = Self::new(size);129+ let mut rv = Self::new(args);
124 130
125 rv.add_window(TestWindow::freeform(0), Some(ColumnWidth::Proportion(0.3)));131 rv.add_window(TestWindow::freeform(0), Some(ColumnWidth::Proportion(0.3)));
126 rv.add_window(TestWindow::freeform(1), Some(ColumnWidth::Proportion(0.3)));132 rv.add_window(TestWindow::freeform(1), Some(ColumnWidth::Proportion(0.3)));
@@ -135,8 +141,8 @@ impl Layout {
135 rv141 rv
136 }142 }
137 143
138- pub fn open_to_the_left_big(size: Size<i32, Logical>) -> Self {144+ pub fn open_to_the_left_big(args: Args) -> Self {
139- let mut rv = Self::new(size);145+ let mut rv = Self::new(args);
140 146
141 rv.add_window(TestWindow::freeform(0), Some(ColumnWidth::Proportion(0.3)));147 rv.add_window(TestWindow::freeform(0), Some(ColumnWidth::Proportion(0.3)));
142 rv.add_window(TestWindow::freeform(1), Some(ColumnWidth::Proportion(0.8)));148 rv.add_window(TestWindow::freeform(1), Some(ColumnWidth::Proportion(0.8)));
@@ -201,21 +207,23 @@ impl TestCase for Layout {
201 self.layout.are_animations_ongoing(Some(&self.output)) || !self.steps.is_empty()207 self.layout.are_animations_ongoing(Some(&self.output)) || !self.steps.is_empty()
202 }208 }
203 209
204- fn advance_animations(&mut self, mut current_time: Duration) {210+ fn advance_animations(&mut self, current_time: Duration) {
205 let run = self211 let run = self
206 .steps212 .steps
207 .keys()213 .keys()
208 .copied()214 .copied()
209 .filter(|delay| self.start_time + *delay <= current_time)215 .filter(|delay| self.start_time + *delay <= current_time)
210 .collect::<Vec<_>>();216 .collect::<Vec<_>>();
211- for key in &run {217+ for delay in &run {
212- let f = self.steps.remove(key).unwrap();218+ let now = self.start_time + *delay;
219+ self.clock.set_time_override(Some(now));
220+ self.layout.advance_animations(now);
221+
222+ let f = self.steps.remove(delay).unwrap();
213 f(self);223 f(self);
214 }224 }
215- if !run.is_empty() {
216- current_time = get_monotonic_time();
217- }
218 225
226+ self.clock.set_time_override(None);
219 self.layout.advance_animations(current_time);227 self.layout.advance_animations(current_time);
220 }228 }
221 229
niri-visual-tests/src/cases/mod.rsmodified+7 -1
@@ -1,8 +1,9 @@
1 use std::time::Duration;1 use std::time::Duration;
2 2
3+use niri::animation::Clock;
3 use smithay::backend::renderer::element::RenderElement;4 use smithay::backend::renderer::element::RenderElement;
4 use smithay::backend::renderer::gles::GlesRenderer;5 use smithay::backend::renderer::gles::GlesRenderer;
5-use smithay::utils::{Physical, Size};6+use smithay::utils::{Logical, Physical, Size};
6 7
7 pub mod gradient_angle;8 pub mod gradient_angle;
8 pub mod gradient_area;9 pub mod gradient_area;
@@ -21,6 +22,11 @@ pub mod layout;
21 pub mod tile;22 pub mod tile;
22 pub mod window;23 pub mod window;
23 24
25+pub struct Args {
26+ pub size: Size<i32, Logical>,
27+ pub clock: Clock,
28+}
29+
24 pub trait TestCase {30 pub trait TestCase {
25 fn resize(&mut self, _width: i32, _height: i32) {}31 fn resize(&mut self, _width: i32, _height: i32) {}
26 fn are_animations_ongoing(&self) -> bool {32 fn are_animations_ongoing(&self) -> bool {
niri-visual-tests/src/cases/tile.rsmodified+22 -25
@@ -6,9 +6,9 @@ use niri::render_helpers::RenderTarget;
6 use niri_config::{Color, FloatOrInt};6 use niri_config::{Color, FloatOrInt};
7 use smithay::backend::renderer::element::RenderElement;7 use smithay::backend::renderer::element::RenderElement;
8 use smithay::backend::renderer::gles::GlesRenderer;8 use smithay::backend::renderer::gles::GlesRenderer;
9-use smithay::utils::{Logical, Physical, Point, Rectangle, Scale, Size};9+use smithay::utils::{Physical, Point, Rectangle, Scale, Size};
10 10
11-use super::TestCase;11+use super::{Args, TestCase};
12 use crate::test_window::TestWindow;12 use crate::test_window::TestWindow;
13 13
14 pub struct Tile {14 pub struct Tile {
@@ -17,53 +17,44 @@ pub struct Tile {
17 }17 }
18 18
19 impl Tile {19 impl Tile {
20- pub fn freeform(size: Size<i32, Logical>) -> Self {20+ pub fn freeform(args: Args) -> Self {
21 let window = TestWindow::freeform(0);21 let window = TestWindow::freeform(0);
22- let mut rv = Self::with_window(window);22+ Self::with_window(args, window)
23- rv.tile.request_tile_size(size.to_f64(), false, None);
24- rv.window.communicate();
25- rv
26 }23 }
27 24
28- pub fn fixed_size(size: Size<i32, Logical>) -> Self {25+ pub fn fixed_size(args: Args) -> Self {
29 let window = TestWindow::fixed_size(0);26 let window = TestWindow::fixed_size(0);
30- let mut rv = Self::with_window(window);27+ Self::with_window(args, window)
31- rv.tile.request_tile_size(size.to_f64(), false, None);
32- rv.window.communicate();
33- rv
34 }28 }
35 29
36- pub fn fixed_size_with_csd_shadow(size: Size<i32, Logical>) -> Self {30+ pub fn fixed_size_with_csd_shadow(args: Args) -> Self {
37 let window = TestWindow::fixed_size(0);31 let window = TestWindow::fixed_size(0);
38 window.set_csd_shadow_width(64);32 window.set_csd_shadow_width(64);
39- let mut rv = Self::with_window(window);33+ Self::with_window(args, window)
40- rv.tile.request_tile_size(size.to_f64(), false, None);
41- rv.window.communicate();
42- rv
43 }34 }
44 35
45- pub fn freeform_open(size: Size<i32, Logical>) -> Self {36+ pub fn freeform_open(args: Args) -> Self {
46- let mut rv = Self::freeform(size);37+ let mut rv = Self::freeform(args);
47 rv.window.set_color([0.1, 0.1, 0.1, 1.]);38 rv.window.set_color([0.1, 0.1, 0.1, 1.]);
48 rv.tile.start_open_animation();39 rv.tile.start_open_animation();
49 rv40 rv
50 }41 }
51 42
52- pub fn fixed_size_open(size: Size<i32, Logical>) -> Self {43+ pub fn fixed_size_open(args: Args) -> Self {
53- let mut rv = Self::fixed_size(size);44+ let mut rv = Self::fixed_size(args);
54 rv.window.set_color([0.1, 0.1, 0.1, 1.]);45 rv.window.set_color([0.1, 0.1, 0.1, 1.]);
55 rv.tile.start_open_animation();46 rv.tile.start_open_animation();
56 rv47 rv
57 }48 }
58 49
59- pub fn fixed_size_with_csd_shadow_open(size: Size<i32, Logical>) -> Self {50+ pub fn fixed_size_with_csd_shadow_open(args: Args) -> Self {
60- let mut rv = Self::fixed_size_with_csd_shadow(size);51+ let mut rv = Self::fixed_size_with_csd_shadow(args);
61 rv.window.set_color([0.1, 0.1, 0.1, 1.]);52 rv.window.set_color([0.1, 0.1, 0.1, 1.]);
62 rv.tile.start_open_animation();53 rv.tile.start_open_animation();
63 rv54 rv
64 }55 }
65 56
66- pub fn with_window(window: TestWindow) -> Self {57+ pub fn with_window(args: Args, window: TestWindow) -> Self {
67 let options = Options {58 let options = Options {
68 focus_ring: niri_config::FocusRing {59 focus_ring: niri_config::FocusRing {
69 off: true,60 off: true,
@@ -77,7 +68,13 @@ impl Tile {
77 },68 },
78 ..Default::default()69 ..Default::default()
79 };70 };
80- let tile = niri::layout::tile::Tile::new(window.clone(), 1., Rc::new(options));71+
72+ let mut tile =
73+ niri::layout::tile::Tile::new(window.clone(), 1., args.clock, Rc::new(options));
74+
75+ tile.request_tile_size(args.size.to_f64(), false, None);
76+ window.communicate();
77+
81 Self { window, tile }78 Self { window, tile }
82 }79 }
83 }80 }
niri-visual-tests/src/cases/window.rsmodified+8 -8
@@ -2,9 +2,9 @@ use niri::layout::LayoutElement;
2 use niri::render_helpers::RenderTarget;2 use niri::render_helpers::RenderTarget;
3 use smithay::backend::renderer::element::RenderElement;3 use smithay::backend::renderer::element::RenderElement;
4 use smithay::backend::renderer::gles::GlesRenderer;4 use smithay::backend::renderer::gles::GlesRenderer;
5-use smithay::utils::{Logical, Physical, Point, Scale, Size};5+use smithay::utils::{Physical, Point, Scale, Size};
6 6
7-use super::TestCase;7+use super::{Args, TestCase};
8 use crate::test_window::TestWindow;8 use crate::test_window::TestWindow;
9 9
10 pub struct Window {10 pub struct Window {
@@ -12,24 +12,24 @@ pub struct Window {
12 }12 }
13 13
14 impl Window {14 impl Window {
15- pub fn freeform(size: Size<i32, Logical>) -> Self {15+ pub fn freeform(args: Args) -> Self {
16 let mut window = TestWindow::freeform(0);16 let mut window = TestWindow::freeform(0);
17- window.request_size(size, false, None);17+ window.request_size(args.size, false, None);
18 window.communicate();18 window.communicate();
19 Self { window }19 Self { window }
20 }20 }
21 21
22- pub fn fixed_size(size: Size<i32, Logical>) -> Self {22+ pub fn fixed_size(args: Args) -> Self {
23 let mut window = TestWindow::fixed_size(0);23 let mut window = TestWindow::fixed_size(0);
24- window.request_size(size, false, None);24+ window.request_size(args.size, false, None);
25 window.communicate();25 window.communicate();
26 Self { window }26 Self { window }
27 }27 }
28 28
29- pub fn fixed_size_with_csd_shadow(size: Size<i32, Logical>) -> Self {29+ pub fn fixed_size_with_csd_shadow(args: Args) -> Self {
30 let mut window = TestWindow::fixed_size(0);30 let mut window = TestWindow::fixed_size(0);
31 window.set_csd_shadow_width(64);31 window.set_csd_shadow_width(64);
32- window.request_size(size, false, None);32+ window.request_size(args.size, false, None);
33 window.communicate();33 window.communicate();
34 Self { window }34 Self { window }
35 }35 }
niri-visual-tests/src/main.rsmodified+2 -6
@@ -5,12 +5,12 @@ use std::env;
5 use std::sync::atomic::Ordering;5 use std::sync::atomic::Ordering;
6 6
7 use adw::prelude::{AdwApplicationWindowExt, NavigationPageExt};7 use adw::prelude::{AdwApplicationWindowExt, NavigationPageExt};
8+use cases::Args;
8 use gtk::prelude::{9 use gtk::prelude::{
9 AdjustmentExt, ApplicationExt, ApplicationExtManual, BoxExt, GtkWindowExt, WidgetExt,10 AdjustmentExt, ApplicationExt, ApplicationExtManual, BoxExt, GtkWindowExt, WidgetExt,
10 };11 };
11 use gtk::{gdk, gio, glib};12 use gtk::{gdk, gio, glib};
12 use niri::animation::ANIMATION_SLOWDOWN;13 use niri::animation::ANIMATION_SLOWDOWN;
13-use smithay::utils::{Logical, Size};
14 use smithay_view::SmithayView;14 use smithay_view::SmithayView;
15 use tracing_subscriber::EnvFilter;15 use tracing_subscriber::EnvFilter;
16 16
@@ -72,11 +72,7 @@ fn build_ui(app: &adw::Application) {
72 }72 }
73 73
74 impl S {74 impl S {
75- fn add<T: TestCase + 'static>(75+ fn add<T: TestCase + 'static>(&self, make: impl Fn(Args) -> T + 'static, title: &str) {
76- &self,
77- make: impl Fn(Size<i32, Logical>) -> T + 'static,
78- title: &str,
79- ) {
80 let view = SmithayView::new(make);76 let view = SmithayView::new(make);
81 self.stack.add_titled(&view, None, title);77 self.stack.add_titled(&view, None, title);
82 }78 }
niri-visual-tests/src/smithay_view.rsmodified+12 -8
@@ -1,8 +1,8 @@
1 use gtk::glib;1 use gtk::glib;
2 use gtk::subclass::prelude::*;2 use gtk::subclass::prelude::*;
3-use smithay::utils::{Logical, Size};3+use smithay::utils::Size;
4 4
5-use crate::cases::TestCase;5+use crate::cases::{Args, TestCase};
6 6
7 mod imp {7 mod imp {
8 use std::cell::{Cell, OnceCell, RefCell};8 use std::cell::{Cell, OnceCell, RefCell};
@@ -11,6 +11,7 @@ mod imp {
11 use anyhow::{ensure, Context};11 use anyhow::{ensure, Context};
12 use gtk::gdk;12 use gtk::gdk;
13 use gtk::prelude::*;13 use gtk::prelude::*;
14+ use niri::animation::Clock;
14 use niri::render_helpers::{resources, shaders};15 use niri::render_helpers::{resources, shaders};
15 use niri::utils::get_monotonic_time;16 use niri::utils::get_monotonic_time;
16 use smithay::backend::egl::ffi::egl;17 use smithay::backend::egl::ffi::egl;
@@ -21,7 +22,7 @@ mod imp {
21 22
22 use super::*;23 use super::*;
23 24
24- type DynMakeTestCase = Box<dyn Fn(Size<i32, Logical>) -> Box<dyn TestCase>>;25+ type DynMakeTestCase = Box<dyn Fn(Args) -> Box<dyn TestCase>>;
25 26
26 #[derive(Default)]27 #[derive(Default)]
27 pub struct SmithayView {28 pub struct SmithayView {
@@ -30,6 +31,7 @@ mod imp {
30 renderer: RefCell<Option<Result<GlesRenderer, ()>>>,31 renderer: RefCell<Option<Result<GlesRenderer, ()>>>,
31 pub make_test_case: OnceCell<DynMakeTestCase>,32 pub make_test_case: OnceCell<DynMakeTestCase>,
32 test_case: RefCell<Option<Box<dyn TestCase>>>,33 test_case: RefCell<Option<Box<dyn TestCase>>>,
34+ clock: RefCell<Clock>,
33 }35 }
34 36
35 #[glib::object_subclass]37 #[glib::object_subclass]
@@ -129,7 +131,11 @@ mod imp {
129 let mut case = self.test_case.borrow_mut();131 let mut case = self.test_case.borrow_mut();
130 let case = case.get_or_insert_with(|| {132 let case = case.get_or_insert_with(|| {
131 let make = self.make_test_case.get().unwrap();133 let make = self.make_test_case.get().unwrap();
132- make(Size::from(size))134+ let args = Args {
135+ size: Size::from(size),
136+ clock: self.clock.borrow().clone(),
137+ };
138+ make(args)
133 });139 });
134 140
135 case.advance_animations(get_monotonic_time());141 case.advance_animations(get_monotonic_time());
@@ -232,12 +238,10 @@ glib::wrapper! {
232 }238 }
233 239
234 impl SmithayView {240 impl SmithayView {
235- pub fn new<T: TestCase + 'static>(241+ pub fn new<T: TestCase + 'static>(make_test_case: impl Fn(Args) -> T + 'static) -> Self {
236- make_test_case: impl Fn(Size<i32, Logical>) -> T + 'static,
237- ) -> Self {
238 let obj: Self = glib::Object::builder().build();242 let obj: Self = glib::Object::builder().build();
239 243
240- let make = move |size| Box::new(make_test_case(size)) as Box<dyn TestCase>;244+ let make = move |args| Box::new(make_test_case(args)) as Box<dyn TestCase>;
241 let make_test_case = Box::new(make) as _;245 let make_test_case = Box::new(make) as _;
242 let _ = obj.imp().make_test_case.set(make_test_case);246 let _ = obj.imp().make_test_case.set(make_test_case);
243 247
src/animation/clock.rsadded+41 -0
@@ -0,0 +1,41 @@
1+use std::cell::Cell;
2+use std::rc::Rc;
3+use std::time::Duration;
4+
5+use crate::utils::get_monotonic_time;
6+
7+/// Clock that can have its time value overridden.
8+///
9+/// Can be cloned to share the same clock.
10+#[derive(Debug, Default, Clone)]
11+pub struct Clock {
12+ time_override: Rc<Cell<Option<Duration>>>,
13+}
14+
15+impl Clock {
16+ /// Creates a new [`Clock`] with time override in place.
17+ pub fn with_override(time: Duration) -> Self {
18+ Self {
19+ time_override: Rc::new(Cell::new(Some(time))),
20+ }
21+ }
22+
23+ /// Sets the current time override.
24+ pub fn set_time_override(&mut self, time: Option<Duration>) {
25+ self.time_override.set(time);
26+ }
27+
28+ /// Gets the current time.
29+ #[inline]
30+ pub fn now(&self) -> Duration {
31+ self.time_override.get().unwrap_or_else(get_monotonic_time)
32+ }
33+}
34+
35+impl PartialEq for Clock {
36+ fn eq(&self, other: &Self) -> bool {
37+ Rc::ptr_eq(&self.time_override, &other.time_override)
38+ }
39+}
40+
41+impl Eq for Clock {}
src/animation/mod.rsmodified+52 -28
@@ -4,11 +4,12 @@ use keyframe::functions::{EaseOutCubic, EaseOutQuad};
4 use keyframe::EasingFunction;4 use keyframe::EasingFunction;
5 use portable_atomic::{AtomicF64, Ordering};5 use portable_atomic::{AtomicF64, Ordering};
6 6
7-use crate::utils::get_monotonic_time;
8-
9 mod spring;7 mod spring;
10 pub use spring::{Spring, SpringParams};8 pub use spring::{Spring, SpringParams};
11 9
10+mod clock;
11+pub use clock::Clock;
12+
12 pub static ANIMATION_SLOWDOWN: AtomicF64 = AtomicF64::new(1.);13 pub static ANIMATION_SLOWDOWN: AtomicF64 = AtomicF64::new(1.);
13 14
14 #[derive(Debug, Clone)]15 #[derive(Debug, Clone)]
@@ -48,11 +49,24 @@ pub enum Curve {
48 }49 }
49 50
50 impl Animation {51 impl Animation {
51- pub fn new(from: f64, to: f64, initial_velocity: f64, config: niri_config::Animation) -> Self {52+ pub fn new(
53+ current_time: Duration,
54+ from: f64,
55+ to: f64,
56+ initial_velocity: f64,
57+ config: niri_config::Animation,
58+ ) -> Self {
52 // Scale the velocity by slowdown to keep the touchpad gestures feeling right.59 // Scale the velocity by slowdown to keep the touchpad gestures feeling right.
53 let initial_velocity = initial_velocity * ANIMATION_SLOWDOWN.load(Ordering::Relaxed);60 let initial_velocity = initial_velocity * ANIMATION_SLOWDOWN.load(Ordering::Relaxed);
54 61
55- let mut rv = Self::ease(from, to, initial_velocity, 0, Curve::EaseOutCubic);62+ let mut rv = Self::ease(
63+ current_time,
64+ from,
65+ to,
66+ initial_velocity,
67+ 0,
68+ Curve::EaseOutCubic,
69+ );
56 if config.off {70 if config.off {
57 rv.is_off = true;71 rv.is_off = true;
58 return rv;72 return rv;
@@ -83,10 +97,11 @@ impl Animation {
83 initial_velocity: self.initial_velocity,97 initial_velocity: self.initial_velocity,
84 params,98 params,
85 };99 };
86- *self = Self::spring(spring);100+ *self = Self::spring(current_time, spring);
87 }101 }
88 niri_config::AnimationKind::Easing(p) => {102 niri_config::AnimationKind::Easing(p) => {
89 *self = Self::ease(103 *self = Self::ease(
104+ current_time,
90 self.from,105 self.from,
91 self.to,106 self.to,
92 self.initial_velocity,107 self.initial_velocity,
@@ -101,7 +116,13 @@ impl Animation {
101 }116 }
102 117
103 /// Restarts the animation using the previous config.118 /// Restarts the animation using the previous config.
104- pub fn restarted(&self, from: f64, to: f64, initial_velocity: f64) -> Self {119+ pub fn restarted(
120+ &self,
121+ current_time: Duration,
122+ from: f64,
123+ to: f64,
124+ initial_velocity: f64,
125+ ) -> Self {
105 if self.is_off {126 if self.is_off {
106 return self.clone();127 return self.clone();
107 }128 }
@@ -111,6 +132,7 @@ impl Animation {
111 132
112 match self.kind {133 match self.kind {
113 Kind::Easing { curve } => Self::ease(134 Kind::Easing { curve } => Self::ease(
135+ current_time,
114 from,136 from,
115 to,137 to,
116 initial_velocity,138 initial_velocity,
@@ -124,23 +146,32 @@ impl Animation {
124 initial_velocity: self.initial_velocity,146 initial_velocity: self.initial_velocity,
125 params: spring.params,147 params: spring.params,
126 };148 };
127- Self::spring(spring)149+ Self::spring(current_time, spring)
128 }150 }
129 Kind::Deceleration {151 Kind::Deceleration {
130 initial_velocity,152 initial_velocity,
131 deceleration_rate,153 deceleration_rate,
132 } => {154 } => {
133 let threshold = 0.001; // FIXME155 let threshold = 0.001; // FIXME
134- Self::decelerate(from, initial_velocity, deceleration_rate, threshold)156+ Self::decelerate(
157+ current_time,
158+ from,
159+ initial_velocity,
160+ deceleration_rate,
161+ threshold,
162+ )
135 }163 }
136 }164 }
137 }165 }
138 166
139- pub fn ease(from: f64, to: f64, initial_velocity: f64, duration_ms: u64, curve: Curve) -> Self {167+ pub fn ease(
140- // FIXME: ideally we shouldn't use current time here because animations started within the168+ current_time: Duration,
141- // same frame cycle should have the same start time to be synchronized.169+ from: f64,
142- let now = get_monotonic_time();170+ to: f64,
143-171+ initial_velocity: f64,
172+ duration_ms: u64,
173+ curve: Curve,
174+ ) -> Self {
144 let duration = Duration::from_millis(duration_ms);175 let duration = Duration::from_millis(duration_ms);
145 let kind = Kind::Easing { curve };176 let kind = Kind::Easing { curve };
146 177
@@ -152,19 +183,15 @@ impl Animation {
152 duration,183 duration,
153 // Our current curves never overshoot.184 // Our current curves never overshoot.
154 clamped_duration: duration,185 clamped_duration: duration,
155- start_time: now,186+ start_time: current_time,
156- current_time: now,187+ current_time,
157 kind,188 kind,
158 }189 }
159 }190 }
160 191
161- pub fn spring(spring: Spring) -> Self {192+ pub fn spring(current_time: Duration, spring: Spring) -> Self {
162 let _span = tracy_client::span!("Animation::spring");193 let _span = tracy_client::span!("Animation::spring");
163 194
164- // FIXME: ideally we shouldn't use current time here because animations started within the
165- // same frame cycle should have the same start time to be synchronized.
166- let now = get_monotonic_time();
167-
168 let duration = spring.duration();195 let duration = spring.duration();
169 let clamped_duration = spring.clamped_duration().unwrap_or(duration);196 let clamped_duration = spring.clamped_duration().unwrap_or(duration);
170 let kind = Kind::Spring(spring);197 let kind = Kind::Spring(spring);
@@ -176,22 +203,19 @@ impl Animation {
176 is_off: false,203 is_off: false,
177 duration,204 duration,
178 clamped_duration,205 clamped_duration,
179- start_time: now,206+ start_time: current_time,
180- current_time: now,207+ current_time,
181 kind,208 kind,
182 }209 }
183 }210 }
184 211
185 pub fn decelerate(212 pub fn decelerate(
213+ current_time: Duration,
186 from: f64,214 from: f64,
187 initial_velocity: f64,215 initial_velocity: f64,
188 deceleration_rate: f64,216 deceleration_rate: f64,
189 threshold: f64,217 threshold: f64,
190 ) -> Self {218 ) -> Self {
191- // FIXME: ideally we shouldn't use current time here because animations started within the
192- // same frame cycle should have the same start time to be synchronized.
193- let now = get_monotonic_time();
194-
195 let duration_s = if initial_velocity == 0. {219 let duration_s = if initial_velocity == 0. {
196 0.220 0.
197 } else {221 } else {
@@ -214,8 +238,8 @@ impl Animation {
214 is_off: false,238 is_off: false,
215 duration,239 duration,
216 clamped_duration: duration,240 clamped_duration: duration,
217- start_time: now,241+ start_time: current_time,
218- current_time: now,242+ current_time,
219 kind,243 kind,
220 }244 }
221 }245 }
src/input/mod.rsmodified+2 -1
@@ -3024,6 +3024,7 @@ pub fn mods_with_finger_scroll_binds(comp_mod: CompositorMod, binds: &Binds) ->
3024 #[cfg(test)]3024 #[cfg(test)]
3025 mod tests {3025 mod tests {
3026 use super::*;3026 use super::*;
3027+ use crate::animation::Clock;
3027 3028
3028 #[test]3029 #[test]
3029 fn bindings_suppress_keys() {3030 fn bindings_suppress_keys() {
@@ -3042,7 +3043,7 @@ mod tests {
3042 let comp_mod = CompositorMod::Super;3043 let comp_mod = CompositorMod::Super;
3043 let mut suppressed_keys = HashSet::new();3044 let mut suppressed_keys = HashSet::new();
3044 3045
3045- let screenshot_ui = ScreenshotUi::new(Default::default());3046+ let screenshot_ui = ScreenshotUi::new(Clock::default(), Default::default());
3046 let disable_power_key_handling = false;3047 let disable_power_key_handling = false;
3047 3048
3048 // The key_code we pick is arbitrary, the only thing3049 // The key_code we pick is arbitrary, the only thing
src/layout/closing_window.rsmodified+1 -2
@@ -142,8 +142,7 @@ impl ClosingWindow {
142 match &mut self.anim_state {142 match &mut self.anim_state {
143 AnimationState::Waiting { blocker, anim } => {143 AnimationState::Waiting { blocker, anim } => {
144 if blocker.state() != BlockerState::Pending {144 if blocker.state() != BlockerState::Pending {
145- let mut anim = anim.restarted(0., 1., 0.);145+ let anim = anim.restarted(current_time, 0., 1., 0.);
146- anim.set_current_time(current_time);
147 self.anim_state = AnimationState::Animating(anim);146 self.anim_state = AnimationState::Animating(anim);
148 }147 }
149 }148 }
src/layout/mod.rsmodified+104 -16
@@ -52,6 +52,7 @@ use workspace::WorkspaceId;
52 pub use self::monitor::MonitorRenderElement;52 pub use self::monitor::MonitorRenderElement;
53 use self::monitor::{Monitor, WorkspaceSwitch};53 use self::monitor::{Monitor, WorkspaceSwitch};
54 use self::workspace::{compute_working_area, Column, ColumnWidth, InsertHint, OutputId, Workspace};54 use self::workspace::{compute_working_area, Column, ColumnWidth, InsertHint, OutputId, Workspace};
55+use crate::animation::Clock;
55 use crate::layout::workspace::InsertPosition;56 use crate::layout::workspace::InsertPosition;
56 use crate::niri_render_elements;57 use crate::niri_render_elements;
57 use crate::render_helpers::renderer::NiriRenderer;58 use crate::render_helpers::renderer::NiriRenderer;
@@ -216,6 +217,8 @@ pub struct Layout<W: LayoutElement> {
216 last_active_workspace_id: HashMap<String, WorkspaceId>,217 last_active_workspace_id: HashMap<String, WorkspaceId>,
217 /// Ongoing interactive move.218 /// Ongoing interactive move.
218 interactive_move: Option<InteractiveMoveState<W>>,219 interactive_move: Option<InteractiveMoveState<W>>,
220+ /// Clock for driving animations.
221+ clock: Clock,
219 /// Configurable properties of the layout.222 /// Configurable properties of the layout.
220 options: Rc<Options>,223 options: Rc<Options>,
221 }224 }
@@ -433,27 +436,30 @@ impl Options {
433 }436 }
434 437
435 impl<W: LayoutElement> Layout<W> {438 impl<W: LayoutElement> Layout<W> {
436- pub fn new(config: &Config) -> Self {439+ pub fn new(clock: Clock, config: &Config) -> Self {
437- Self::with_options_and_workspaces(config, Options::from_config(config))440+ Self::with_options_and_workspaces(clock, config, Options::from_config(config))
438 }441 }
439 442
440- pub fn with_options(options: Options) -> Self {443+ pub fn with_options(clock: Clock, options: Options) -> Self {
441 Self {444 Self {
442 monitor_set: MonitorSet::NoOutputs { workspaces: vec![] },445 monitor_set: MonitorSet::NoOutputs { workspaces: vec![] },
443 is_active: true,446 is_active: true,
444 last_active_workspace_id: HashMap::new(),447 last_active_workspace_id: HashMap::new(),
445 interactive_move: None,448 interactive_move: None,
449+ clock,
446 options: Rc::new(options),450 options: Rc::new(options),
447 }451 }
448 }452 }
449 453
450- fn with_options_and_workspaces(config: &Config, options: Options) -> Self {454+ fn with_options_and_workspaces(clock: Clock, config: &Config, options: Options) -> Self {
451 let opts = Rc::new(options);455 let opts = Rc::new(options);
452 456
453 let workspaces = config457 let workspaces = config
454 .workspaces458 .workspaces
455 .iter()459 .iter()
456- .map(|ws| Workspace::new_with_config_no_outputs(Some(ws.clone()), opts.clone()))460+ .map(|ws| {
461+ Workspace::new_with_config_no_outputs(Some(ws.clone()), clock.clone(), opts.clone())
462+ })
457 .collect();463 .collect();
458 464
459 Self {465 Self {
@@ -461,6 +467,7 @@ impl<W: LayoutElement> Layout<W> {
461 is_active: true,467 is_active: true,
462 last_active_workspace_id: HashMap::new(),468 last_active_workspace_id: HashMap::new(),
463 interactive_move: None,469 interactive_move: None,
470+ clock,
464 options: opts,471 options: opts,
465 }472 }
466 }473 }
@@ -522,13 +529,18 @@ impl<W: LayoutElement> Layout<W> {
522 }529 }
523 530
524 // Make sure there's always an empty workspace.531 // Make sure there's always an empty workspace.
525- workspaces.push(Workspace::new(output.clone(), self.options.clone()));532+ workspaces.push(Workspace::new(
533+ output.clone(),
534+ self.clock.clone(),
535+ self.options.clone(),
536+ ));
526 537
527 for ws in &mut workspaces {538 for ws in &mut workspaces {
528 ws.set_output(Some(output.clone()));539 ws.set_output(Some(output.clone()));
529 }540 }
530 541
531- let mut monitor = Monitor::new(output, workspaces, self.options.clone());542+ let mut monitor =
543+ Monitor::new(output, workspaces, self.clock.clone(), self.options.clone());
532 monitor.active_workspace_idx = active_workspace_idx.unwrap_or(0);544 monitor.active_workspace_idx = active_workspace_idx.unwrap_or(0);
533 monitors.push(monitor);545 monitors.push(monitor);
534 546
@@ -540,7 +552,11 @@ impl<W: LayoutElement> Layout<W> {
540 }552 }
541 MonitorSet::NoOutputs { mut workspaces } => {553 MonitorSet::NoOutputs { mut workspaces } => {
542 // We know there are no empty workspaces there, so add one.554 // We know there are no empty workspaces there, so add one.
543- workspaces.push(Workspace::new(output.clone(), self.options.clone()));555+ workspaces.push(Workspace::new(
556+ output.clone(),
557+ self.clock.clone(),
558+ self.options.clone(),
559+ ));
544 560
545 let ws_id_to_activate = self.last_active_workspace_id.remove(&output.name());561 let ws_id_to_activate = self.last_active_workspace_id.remove(&output.name());
546 let mut active_workspace_idx = 0;562 let mut active_workspace_idx = 0;
@@ -553,7 +569,8 @@ impl<W: LayoutElement> Layout<W> {
553 }569 }
554 }570 }
555 571
556- let mut monitor = Monitor::new(output, workspaces, self.options.clone());572+ let mut monitor =
573+ Monitor::new(output, workspaces, self.clock.clone(), self.options.clone());
557 monitor.active_workspace_idx = active_workspace_idx;574 monitor.active_workspace_idx = active_workspace_idx;
558 575
559 MonitorSet::Normal {576 MonitorSet::Normal {
@@ -785,7 +802,10 @@ impl<W: LayoutElement> Layout<W> {
785 let ws = if let Some(ws) = workspaces.get_mut(0) {802 let ws = if let Some(ws) = workspaces.get_mut(0) {
786 ws803 ws
787 } else {804 } else {
788- workspaces.push(Workspace::new_no_outputs(self.options.clone()));805+ workspaces.push(Workspace::new_no_outputs(
806+ self.clock.clone(),
807+ self.options.clone(),
808+ ));
789 &mut workspaces[0]809 &mut workspaces[0]
790 };810 };
791 ws.add_window(None, window, true, width, is_full_width);811 ws.add_window(None, window, true, width, is_full_width);
@@ -1992,6 +2012,8 @@ impl<W: LayoutElement> Layout<W> {
1992 move_win_id = Some(window_id.clone());2012 move_win_id = Some(window_id.clone());
1993 }2013 }
1994 InteractiveMoveState::Moving(move_) => {2014 InteractiveMoveState::Moving(move_) => {
2015+ assert_eq!(self.clock, move_.tile.clock);
2016+
1995 let scale = move_.output.current_scale().fractional_scale();2017 let scale = move_.output.current_scale().fractional_scale();
1996 let options = Options::clone(&self.options).adjusted_for_scale(scale);2018 let options = Options::clone(&self.options).adjusted_for_scale(scale);
1997 assert_eq!(2019 assert_eq!(
@@ -2026,6 +2048,8 @@ impl<W: LayoutElement> Layout<W> {
2026 "with no outputs there cannot be empty unnamed workspaces"2048 "with no outputs there cannot be empty unnamed workspaces"
2027 );2049 );
2028 2050
2051+ assert_eq!(self.clock, workspace.clock);
2052+
2029 assert_eq!(2053 assert_eq!(
2030 workspace.base_options, self.options,2054 workspace.base_options, self.options,
2031 "workspace base options must be synchronized with layout"2055 "workspace base options must be synchronized with layout"
@@ -2070,6 +2094,7 @@ impl<W: LayoutElement> Layout<W> {
2070 );2094 );
2071 assert!(monitor.active_workspace_idx < monitor.workspaces.len());2095 assert!(monitor.active_workspace_idx < monitor.workspaces.len());
2072 2096
2097+ assert_eq!(self.clock, monitor.clock);
2073 assert_eq!(2098 assert_eq!(
2074 monitor.options, self.options,2099 monitor.options, self.options,
2075 "monitor options must be synchronized with layout"2100 "monitor options must be synchronized with layout"
@@ -2135,6 +2160,8 @@ impl<W: LayoutElement> Layout<W> {
2135 // exists.2160 // exists.
2136 2161
2137 for workspace in &monitor.workspaces {2162 for workspace in &monitor.workspaces {
2163+ assert_eq!(self.clock, workspace.clock);
2164+
2138 assert_eq!(2165 assert_eq!(
2139 workspace.base_options, self.options,2166 workspace.base_options, self.options,
2140 "workspace options must be synchronized with layout"2167 "workspace options must be synchronized with layout"
@@ -2326,6 +2353,7 @@ impl<W: LayoutElement> Layout<W> {
2326 return;2353 return;
2327 }2354 }
2328 2355
2356+ let clock = self.clock.clone();
2329 let options = self.options.clone();2357 let options = self.options.clone();
2330 2358
2331 match &mut self.monitor_set {2359 match &mut self.monitor_set {
@@ -2349,6 +2377,7 @@ impl<W: LayoutElement> Layout<W> {
2349 let ws = Workspace::new_with_config(2377 let ws = Workspace::new_with_config(
2350 mon.output.clone(),2378 mon.output.clone(),
2351 Some(ws_config.clone()),2379 Some(ws_config.clone()),
2380+ clock,
2352 options,2381 options,
2353 );2382 );
2354 mon.workspaces.insert(0, ws);2383 mon.workspaces.insert(0, ws);
@@ -2357,7 +2386,8 @@ impl<W: LayoutElement> Layout<W> {
2357 mon.clean_up_workspaces();2386 mon.clean_up_workspaces();
2358 }2387 }
2359 MonitorSet::NoOutputs { workspaces } => {2388 MonitorSet::NoOutputs { workspaces } => {
2360- let ws = Workspace::new_with_config_no_outputs(Some(ws_config.clone()), options);2389+ let ws =
2390+ Workspace::new_with_config_no_outputs(Some(ws_config.clone()), clock, options);
2361 workspaces.insert(0, ws);2391 workspaces.insert(0, ws);
2362 }2392 }
2363 }2393 }
@@ -3161,7 +3191,10 @@ impl<W: LayoutElement> Layout<W> {
3161 let ws = if let Some(ws) = workspaces.get_mut(0) {3191 let ws = if let Some(ws) = workspaces.get_mut(0) {
3162 ws3192 ws
3163 } else {3193 } else {
3164- workspaces.push(Workspace::new_no_outputs(self.options.clone()));3194+ workspaces.push(Workspace::new_no_outputs(
3195+ self.clock.clone(),
3196+ self.options.clone(),
3197+ ));
3165 &mut workspaces[0]3198 &mut workspaces[0]
3166 };3199 };
3167 3200
@@ -3620,7 +3653,7 @@ mod tests {
3620 3653
3621 impl<W: LayoutElement> Default for Layout<W> {3654 impl<W: LayoutElement> Default for Layout<W> {
3622 fn default() -> Self {3655 fn default() -> Self {
3623- Self::with_options(Default::default())3656+ Self::with_options(Clock::with_override(Duration::ZERO), Default::default())
3624 }3657 }
3625 }3658 }
3626 3659
@@ -3854,6 +3887,16 @@ mod tests {
3854 prop_oneof![Just(1.), Just(1.5), Just(2.),]3887 prop_oneof![Just(1.), Just(1.5), Just(2.),]
3855 }3888 }
3856 3889
3890+ fn arbitrary_msec_delta() -> impl Strategy<Value = i32> {
3891+ prop_oneof![
3892+ 1 => Just(-1000),
3893+ 2 => Just(-10),
3894+ 1 => Just(0),
3895+ 2 => Just(10),
3896+ 6 => Just(1000),
3897+ ]
3898+ }
3899+
3857 #[derive(Debug, Clone, Copy, Arbitrary)]3900 #[derive(Debug, Clone, Copy, Arbitrary)]
3858 enum Op {3901 enum Op {
3859 AddOutput(#[proptest(strategy = "1..=5usize")] usize),3902 AddOutput(#[proptest(strategy = "1..=5usize")] usize),
@@ -3997,6 +4040,10 @@ mod tests {
3997 Refresh {4040 Refresh {
3998 is_active: bool,4041 is_active: bool,
3999 },4042 },
4043+ AdvanceAnimations {
4044+ #[proptest(strategy = "arbitrary_msec_delta()")]
4045+ msec_delta: i32,
4046+ },
4000 MoveWorkspaceToOutput(#[proptest(strategy = "1..=5u8")] u8),4047 MoveWorkspaceToOutput(#[proptest(strategy = "1..=5u8")] u8),
4001 ViewOffsetGestureBegin {4048 ViewOffsetGestureBegin {
4002 #[proptest(strategy = "1..=5usize")]4049 #[proptest(strategy = "1..=5usize")]
@@ -4505,6 +4552,16 @@ mod tests {
4505 Op::Refresh { is_active } => {4552 Op::Refresh { is_active } => {
4506 layout.refresh(is_active);4553 layout.refresh(is_active);
4507 }4554 }
4555+ Op::AdvanceAnimations { msec_delta } => {
4556+ let mut now = layout.clock.now();
4557+ if msec_delta >= 0 {
4558+ now = now.saturating_add(Duration::from_millis(msec_delta as u64));
4559+ } else {
4560+ now = now.saturating_sub(Duration::from_millis(-msec_delta as u64));
4561+ }
4562+ layout.clock.set_time_override(Some(now));
4563+ layout.advance_animations(now);
4564+ }
4508 Op::MoveWorkspaceToOutput(id) => {4565 Op::MoveWorkspaceToOutput(id) => {
4509 let name = format!("output{id}");4566 let name = format!("output{id}");
4510 let Some(output) = layout.outputs().find(|o| o.name() == name).cloned() else {4567 let Some(output) = layout.outputs().find(|o| o.name() == name).cloned() else {
@@ -4617,7 +4674,7 @@ mod tests {
4617 4674
4618 #[track_caller]4675 #[track_caller]
4619 fn check_ops_with_options(options: Options, ops: &[Op]) {4676 fn check_ops_with_options(options: Options, ops: &[Op]) {
4620- let mut layout = Layout::with_options(options);4677+ let mut layout = Layout::with_options(Clock::with_override(Duration::ZERO), options);
4621 4678
4622 for op in ops {4679 for op in ops {
4623 op.apply(&mut layout);4680 op.apply(&mut layout);
@@ -5440,7 +5497,7 @@ mod tests {
5440 config.layout.border.off = false;5497 config.layout.border.off = false;
5441 config.layout.border.width = FloatOrInt(2.);5498 config.layout.border.width = FloatOrInt(2.);
5442 5499
5443- let mut layout = Layout::new(&config);5500+ let mut layout = Layout::new(Clock::default(), &config);
5444 5501
5445 Op::AddWindow {5502 Op::AddWindow {
5446 id: 1,5503 id: 1,
@@ -5460,7 +5517,7 @@ mod tests {
5460 let mut config = Config::default();5517 let mut config = Config::default();
5461 config.layout.preset_window_heights = vec![PresetSize::Fixed(1), PresetSize::Fixed(2)];5518 config.layout.preset_window_heights = vec![PresetSize::Fixed(1), PresetSize::Fixed(2)];
5462 5519
5463- let mut layout = Layout::new(&config);5520+ let mut layout = Layout::new(Clock::default(), &config);
5464 5521
5465 let ops = [5522 let ops = [
5466 Op::AddOutput(1),5523 Op::AddOutput(1),
@@ -5752,6 +5809,37 @@ mod tests {
5752 check_ops(&ops);5809 check_ops(&ops);
5753 }5810 }
5754 5811
5812+ #[test]
5813+ fn interactive_move_onto_last_workspace() {
5814+ let ops = [
5815+ Op::AddOutput(1),
5816+ Op::AddWindow {
5817+ id: 0,
5818+ bbox: Rectangle::from_loc_and_size((0, 0), (100, 200)),
5819+ min_max_size: Default::default(),
5820+ },
5821+ Op::InteractiveMoveBegin {
5822+ window: 0,
5823+ output_idx: 1,
5824+ px: 0.,
5825+ py: 0.,
5826+ },
5827+ Op::InteractiveMoveUpdate {
5828+ window: 0,
5829+ dx: 1000.,
5830+ dy: 0.,
5831+ output_idx: 1,
5832+ px: 0.,
5833+ py: 0.,
5834+ },
5835+ Op::FocusWorkspaceDown,
5836+ Op::AdvanceAnimations { msec_delta: 1000 },
5837+ Op::InteractiveMoveEnd { window: 0 },
5838+ ];
5839+
5840+ check_ops(&ops);
5841+ }
5842+
5755 #[test]5843 #[test]
5756 fn output_active_workspace_is_preserved() {5844 fn output_active_workspace_is_preserved() {
5757 let ops = [5845 let ops = [
src/layout/monitor.rsmodified+17 -3
@@ -15,7 +15,7 @@ use super::workspace::{
15 WorkspaceRenderElement,15 WorkspaceRenderElement,
16 };16 };
17 use super::{LayoutElement, Options};17 use super::{LayoutElement, Options};
18-use crate::animation::Animation;18+use crate::animation::{Animation, Clock};
19 use crate::input::swipe_tracker::SwipeTracker;19 use crate::input::swipe_tracker::SwipeTracker;
20 use crate::render_helpers::renderer::NiriRenderer;20 use crate::render_helpers::renderer::NiriRenderer;
21 use crate::render_helpers::RenderTarget;21 use crate::render_helpers::RenderTarget;
@@ -45,6 +45,8 @@ pub struct Monitor<W: LayoutElement> {
45 pub(super) previous_workspace_id: Option<WorkspaceId>,45 pub(super) previous_workspace_id: Option<WorkspaceId>,
46 /// In-progress switch between workspaces.46 /// In-progress switch between workspaces.
47 pub(super) workspace_switch: Option<WorkspaceSwitch>,47 pub(super) workspace_switch: Option<WorkspaceSwitch>,
48+ /// Clock for driving animations.
49+ pub(super) clock: Clock,
48 /// Configurable properties of the layout.50 /// Configurable properties of the layout.
49 pub(super) options: Rc<Options>,51 pub(super) options: Rc<Options>,
50 }52 }
@@ -94,7 +96,12 @@ impl WorkspaceSwitch {
94 }96 }
95 97
96 impl<W: LayoutElement> Monitor<W> {98 impl<W: LayoutElement> Monitor<W> {
97- pub fn new(output: Output, workspaces: Vec<Workspace<W>>, options: Rc<Options>) -> Self {99+ pub fn new(
100+ output: Output,
101+ workspaces: Vec<Workspace<W>>,
102+ clock: Clock,
103+ options: Rc<Options>,
104+ ) -> Self {
98 Self {105 Self {
99 output_name: output.name(),106 output_name: output.name(),
100 output,107 output,
@@ -102,6 +109,7 @@ impl<W: LayoutElement> Monitor<W> {
102 active_workspace_idx: 0,109 active_workspace_idx: 0,
103 previous_workspace_id: None,110 previous_workspace_id: None,
104 workspace_switch: None,111 workspace_switch: None,
112+ clock,
105 options,113 options,
106 }114 }
107 }115 }
@@ -151,7 +159,11 @@ impl<W: LayoutElement> Monitor<W> {
151 }159 }
152 160
153 pub fn add_workspace_bottom(&mut self) {161 pub fn add_workspace_bottom(&mut self) {
154- let ws = Workspace::new(self.output.clone(), self.options.clone());162+ let ws = Workspace::new(
163+ self.output.clone(),
164+ self.clock.clone(),
165+ self.options.clone(),
166+ );
155 self.workspaces.push(ws);167 self.workspaces.push(ws);
156 }168 }
157 169
@@ -172,6 +184,7 @@ impl<W: LayoutElement> Monitor<W> {
172 self.active_workspace_idx = idx;184 self.active_workspace_idx = idx;
173 185
174 self.workspace_switch = Some(WorkspaceSwitch::Animation(Animation::new(186 self.workspace_switch = Some(WorkspaceSwitch::Animation(Animation::new(
187+ self.clock.now(),
175 current_idx,188 current_idx,
176 idx as f64,189 idx as f64,
177 0.,190 0.,
@@ -1099,6 +1112,7 @@ impl<W: LayoutElement> Monitor<W> {
1099 1112
1100 self.active_workspace_idx = new_idx;1113 self.active_workspace_idx = new_idx;
1101 self.workspace_switch = Some(WorkspaceSwitch::Animation(Animation::new(1114 self.workspace_switch = Some(WorkspaceSwitch::Animation(Animation::new(
1115+ self.clock.now(),
1102 gesture.current_idx,1116 gesture.current_idx,
1103 new_idx as f64,1117 new_idx as f64,
1104 velocity,1118 velocity,
src/layout/tile.rsmodified+18 -7
@@ -13,7 +13,7 @@ use super::{
13 LayoutElement, LayoutElementRenderElement, LayoutElementRenderSnapshot, Options,13 LayoutElement, LayoutElementRenderElement, LayoutElementRenderSnapshot, Options,
14 RESIZE_ANIMATION_THRESHOLD,14 RESIZE_ANIMATION_THRESHOLD,
15 };15 };
16-use crate::animation::Animation;16+use crate::animation::{Animation, Clock};
17 use crate::niri_render_elements;17 use crate::niri_render_elements;
18 use crate::render_helpers::border::BorderRenderElement;18 use crate::render_helpers::border::BorderRenderElement;
19 use crate::render_helpers::clipped_surface::{ClippedSurfaceRenderElement, RoundedCornerDamage};19 use crate::render_helpers::clipped_surface::{ClippedSurfaceRenderElement, RoundedCornerDamage};
@@ -76,6 +76,9 @@ pub struct Tile<W: LayoutElement> {
76 /// Scale of the output the tile is on (and rounds its sizes to).76 /// Scale of the output the tile is on (and rounds its sizes to).
77 scale: f64,77 scale: f64,
78 78
79+ /// Clock for driving animations.
80+ pub(super) clock: Clock,
81+
79 /// Configurable properties of the layout.82 /// Configurable properties of the layout.
80 pub(super) options: Rc<Options>,83 pub(super) options: Rc<Options>,
81 }84 }
@@ -110,7 +113,7 @@ struct MoveAnimation {
110 }113 }
111 114
112 impl<W: LayoutElement> Tile<W> {115 impl<W: LayoutElement> Tile<W> {
113- pub fn new(window: W, scale: f64, options: Rc<Options>) -> Self {116+ pub fn new(window: W, scale: f64, clock: Clock, options: Rc<Options>) -> Self {
114 let rules = window.rules();117 let rules = window.rules();
115 let border_config = rules.border.resolve_against(options.border);118 let border_config = rules.border.resolve_against(options.border);
116 let focus_ring_config = rules.focus_ring.resolve_against(options.focus_ring.into());119 let focus_ring_config = rules.focus_ring.resolve_against(options.focus_ring.into());
@@ -130,6 +133,7 @@ impl<W: LayoutElement> Tile<W> {
130 unmap_snapshot: None,133 unmap_snapshot: None,
131 rounded_corner_damage: Default::default(),134 rounded_corner_damage: Default::default(),
132 scale,135 scale,
136+ clock,
133 options,137 options,
134 }138 }
135 }139 }
@@ -180,7 +184,13 @@ impl<W: LayoutElement> Tile<W> {
180 let change = self.window.size().to_f64().to_point() - size_from.to_point();184 let change = self.window.size().to_f64().to_point() - size_from.to_point();
181 let change = f64::max(change.x.abs(), change.y.abs());185 let change = f64::max(change.x.abs(), change.y.abs());
182 if change > RESIZE_ANIMATION_THRESHOLD {186 if change > RESIZE_ANIMATION_THRESHOLD {
183- let anim = Animation::new(0., 1., 0., self.options.animations.window_resize.anim);187+ let anim = Animation::new(
188+ self.clock.now(),
189+ 0.,
190+ 1.,
191+ 0.,
192+ self.options.animations.window_resize.anim,
193+ );
184 self.resize_animation = Some(ResizeAnimation {194 self.resize_animation = Some(ResizeAnimation {
185 anim,195 anim,
186 size_from,196 size_from,
@@ -316,6 +326,7 @@ impl<W: LayoutElement> Tile<W> {
316 326
317 pub fn start_open_animation(&mut self) {327 pub fn start_open_animation(&mut self) {
318 self.open_animation = Some(OpenAnimation::new(Animation::new(328 self.open_animation = Some(OpenAnimation::new(Animation::new(
329+ self.clock.now(),
319 0.,330 0.,
320 1.,331 1.,
321 0.,332 0.,
@@ -342,8 +353,8 @@ impl<W: LayoutElement> Tile<W> {
342 // Preserve the previous config if ongoing.353 // Preserve the previous config if ongoing.
343 let anim = self.move_x_animation.take().map(|move_| move_.anim);354 let anim = self.move_x_animation.take().map(|move_| move_.anim);
344 let anim = anim355 let anim = anim
345- .map(|anim| anim.restarted(1., 0., 0.))356+ .map(|anim| anim.restarted(self.clock.now(), 1., 0., 0.))
346- .unwrap_or_else(|| Animation::new(1., 0., 0., config));357+ .unwrap_or_else(|| Animation::new(self.clock.now(), 1., 0., 0., config));
347 358
348 self.move_x_animation = Some(MoveAnimation {359 self.move_x_animation = Some(MoveAnimation {
349 anim,360 anim,
@@ -361,8 +372,8 @@ impl<W: LayoutElement> Tile<W> {
361 // Preserve the previous config if ongoing.372 // Preserve the previous config if ongoing.
362 let anim = self.move_y_animation.take().map(|move_| move_.anim);373 let anim = self.move_y_animation.take().map(|move_| move_.anim);
363 let anim = anim374 let anim = anim
364- .map(|anim| anim.restarted(1., 0., 0.))375+ .map(|anim| anim.restarted(self.clock.now(), 1., 0., 0.))
365- .unwrap_or_else(|| Animation::new(1., 0., 0., config));376+ .unwrap_or_else(|| Animation::new(self.clock.now(), 1., 0., 0., config));
366 377
367 self.move_y_animation = Some(MoveAnimation {378 self.move_y_animation = Some(MoveAnimation {
368 anim,379 anim,
src/layout/workspace.rsmodified+35 -11
@@ -19,7 +19,7 @@ use super::closing_window::{ClosingWindow, ClosingWindowRenderElement};
19 use super::insert_hint_element::{InsertHintElement, InsertHintRenderElement};19 use super::insert_hint_element::{InsertHintElement, InsertHintRenderElement};
20 use super::tile::{Tile, TileRenderElement, TileRenderSnapshot};20 use super::tile::{Tile, TileRenderElement, TileRenderSnapshot};
21 use super::{ConfigureIntent, InteractiveResizeData, LayoutElement, Options, RemovedTile};21 use super::{ConfigureIntent, InteractiveResizeData, LayoutElement, Options, RemovedTile};
22-use crate::animation::Animation;22+use crate::animation::{Animation, Clock};
23 use crate::input::swipe_tracker::SwipeTracker;23 use crate::input::swipe_tracker::SwipeTracker;
24 use crate::niri_render_elements;24 use crate::niri_render_elements;
25 use crate::render_helpers::renderer::NiriRenderer;25 use crate::render_helpers::renderer::NiriRenderer;
@@ -113,6 +113,9 @@ pub struct Workspace<W: LayoutElement> {
113 /// Insert hint element for rendering.113 /// Insert hint element for rendering.
114 insert_hint_element: InsertHintElement,114 insert_hint_element: InsertHintElement,
115 115
116+ /// Clock for driving animations.
117+ pub(super) clock: Clock,
118+
116 /// Configurable properties of the layout as received from the parent monitor.119 /// Configurable properties of the layout as received from the parent monitor.
117 pub(super) base_options: Rc<Options>,120 pub(super) base_options: Rc<Options>,
118 121
@@ -293,6 +296,9 @@ pub struct Column<W: LayoutElement> {
293 /// Scale of the output the column is on (and rounds its sizes to).296 /// Scale of the output the column is on (and rounds its sizes to).
294 scale: f64,297 scale: f64,
295 298
299+ /// Clock for driving animations.
300+ clock: Clock,
301+
296 /// Configurable properties of the layout.302 /// Configurable properties of the layout.
297 options: Rc<Options>,303 options: Rc<Options>,
298 }304 }
@@ -403,13 +409,14 @@ impl TileData {
403 }409 }
404 410
405 impl<W: LayoutElement> Workspace<W> {411 impl<W: LayoutElement> Workspace<W> {
406- pub fn new(output: Output, options: Rc<Options>) -> Self {412+ pub fn new(output: Output, clock: Clock, options: Rc<Options>) -> Self {
407- Self::new_with_config(output, None, options)413+ Self::new_with_config(output, None, clock, options)
408 }414 }
409 415
410 pub fn new_with_config(416 pub fn new_with_config(
411 output: Output,417 output: Output,
412 config: Option<WorkspaceConfig>,418 config: Option<WorkspaceConfig>,
419+ clock: Clock,
413 base_options: Rc<Options>,420 base_options: Rc<Options>,
414 ) -> Self {421 ) -> Self {
415 let original_output = config422 let original_output = config
@@ -442,6 +449,7 @@ impl<W: LayoutElement> Workspace<W> {
442 closing_windows: vec![],449 closing_windows: vec![],
443 insert_hint: None,450 insert_hint: None,
444 insert_hint_element: InsertHintElement::new(options.insert_hint),451 insert_hint_element: InsertHintElement::new(options.insert_hint),
452+ clock,
445 base_options,453 base_options,
446 options,454 options,
447 name: config.map(|c| c.name.0),455 name: config.map(|c| c.name.0),
@@ -451,6 +459,7 @@ impl<W: LayoutElement> Workspace<W> {
451 459
452 pub fn new_with_config_no_outputs(460 pub fn new_with_config_no_outputs(
453 config: Option<WorkspaceConfig>,461 config: Option<WorkspaceConfig>,
462+ clock: Clock,
454 base_options: Rc<Options>,463 base_options: Rc<Options>,
455 ) -> Self {464 ) -> Self {
456 let original_output = OutputId(465 let original_output = OutputId(
@@ -482,6 +491,7 @@ impl<W: LayoutElement> Workspace<W> {
482 closing_windows: vec![],491 closing_windows: vec![],
483 insert_hint: None,492 insert_hint: None,
484 insert_hint_element: InsertHintElement::new(options.insert_hint),493 insert_hint_element: InsertHintElement::new(options.insert_hint),
494+ clock,
485 base_options,495 base_options,
486 options,496 options,
487 name: config.map(|c| c.name.0),497 name: config.map(|c| c.name.0),
@@ -489,8 +499,8 @@ impl<W: LayoutElement> Workspace<W> {
489 }499 }
490 }500 }
491 501
492- pub fn new_no_outputs(options: Rc<Options>) -> Self {502+ pub fn new_no_outputs(clock: Clock, options: Rc<Options>) -> Self {
493- Self::new_with_config_no_outputs(None, options)503+ Self::new_with_config_no_outputs(None, clock, options)
494 }504 }
495 505
496 pub fn id(&self) -> WorkspaceId {506 pub fn id(&self) -> WorkspaceId {
@@ -941,6 +951,7 @@ impl<W: LayoutElement> Workspace<W> {
941 951
942 // FIXME: also compute and use current velocity.952 // FIXME: also compute and use current velocity.
943 self.view_offset_adj = Some(ViewOffsetAdjustment::Animation(Animation::new(953 self.view_offset_adj = Some(ViewOffsetAdjustment::Animation(Animation::new(
954+ self.clock.now(),
944 self.view_offset,955 self.view_offset,
945 new_view_offset,956 new_view_offset,
946 0.,957 0.,
@@ -1100,7 +1111,12 @@ impl<W: LayoutElement> Workspace<W> {
1100 width: ColumnWidth,1111 width: ColumnWidth,
1101 is_full_width: bool,1112 is_full_width: bool,
1102 ) {1113 ) {
1103- let tile = Tile::new(window, self.scale.fractional_scale(), self.options.clone());1114+ let tile = Tile::new(
1115+ window,
1116+ self.scale.fractional_scale(),
1117+ self.clock.clone(),
1118+ self.options.clone(),
1119+ );
1104 self.add_tile(col_idx, tile, activate, width, is_full_width, None);1120 self.add_tile(col_idx, tile, activate, width, is_full_width, None);
1105 }1121 }
1106 1122
@@ -1118,7 +1134,6 @@ impl<W: LayoutElement> Workspace<W> {
1118 self.view_size,1134 self.view_size,
1119 self.working_area,1135 self.working_area,
1120 self.scale.fractional_scale(),1136 self.scale.fractional_scale(),
1121- self.options.clone(),
1122 width,1137 width,
1123 is_full_width,1138 is_full_width,
1124 true,1139 true,
@@ -1682,7 +1697,13 @@ impl<W: LayoutElement> Workspace<W> {
1682 ) {1697 ) {
1683 let output_scale = Scale::from(self.scale.fractional_scale());1698 let output_scale = Scale::from(self.scale.fractional_scale());
1684 1699
1685- let anim = Animation::new(0., 1., 0., self.options.animations.window_close.anim);1700+ let anim = Animation::new(
1701+ self.clock.now(),
1702+ 0.,
1703+ 1.,
1704+ 0.,
1705+ self.options.animations.window_close.anim,
1706+ );
1686 1707
1687 let blocker = if self.options.disable_transactions {1708 let blocker = if self.options.disable_transactions {
1688 TransactionBlocker::completed()1709 TransactionBlocker::completed()
@@ -1725,6 +1746,7 @@ impl<W: LayoutElement> Workspace<W> {
1725 1746
1726 for (column, data) in zip(&self.columns, &self.data) {1747 for (column, data) in zip(&self.columns, &self.data) {
1727 assert!(Rc::ptr_eq(&self.options, &column.options));1748 assert!(Rc::ptr_eq(&self.options, &column.options));
1749+ assert_eq!(self.clock, column.clock);
1728 assert_eq!(self.scale.fractional_scale(), column.scale);1750 assert_eq!(self.scale.fractional_scale(), column.scale);
1729 column.verify_invariants();1751 column.verify_invariants();
1730 1752
@@ -2619,7 +2641,6 @@ impl<W: LayoutElement> Workspace<W> {
2619 self.view_size,2641 self.view_size,
2620 self.working_area,2642 self.working_area,
2621 self.scale.fractional_scale(),2643 self.scale.fractional_scale(),
2622- self.options.clone(),
2623 removed.width,2644 removed.width,
2624 removed.is_full_width,2645 removed.is_full_width,
2625 false,2646 false,
@@ -2969,6 +2990,7 @@ impl<W: LayoutElement> Workspace<W> {
2969 let target_view_offset = target_snap.view_pos - new_col_x;2990 let target_view_offset = target_snap.view_pos - new_col_x;
2970 2991
2971 self.view_offset_adj = Some(ViewOffsetAdjustment::Animation(Animation::new(2992 self.view_offset_adj = Some(ViewOffsetAdjustment::Animation(Animation::new(
2993+ self.clock.now(),
2972 current_view_offset + delta,2994 current_view_offset + delta,
2973 target_view_offset,2995 target_view_offset,
2974 velocity,2996 velocity,
@@ -3174,7 +3196,6 @@ impl<W: LayoutElement> Column<W> {
3174 view_size: Size<f64, Logical>,3196 view_size: Size<f64, Logical>,
3175 working_area: Rectangle<f64, Logical>,3197 working_area: Rectangle<f64, Logical>,
3176 scale: f64,3198 scale: f64,
3177- options: Rc<Options>,
3178 width: ColumnWidth,3199 width: ColumnWidth,
3179 is_full_width: bool,3200 is_full_width: bool,
3180 animate_resize: bool,3201 animate_resize: bool,
@@ -3190,7 +3211,8 @@ impl<W: LayoutElement> Column<W> {
3190 view_size,3211 view_size,
3191 working_area,3212 working_area,
3192 scale,3213 scale,
3193- options,3214+ clock: tile.clock.clone(),
3215+ options: tile.options.clone(),
3194 };3216 };
3195 3217
3196 let is_pending_fullscreen = tile.window().is_pending_fullscreen();3218 let is_pending_fullscreen = tile.window().is_pending_fullscreen();
@@ -3313,6 +3335,7 @@ impl<W: LayoutElement> Column<W> {
3313 let current_offset = self.move_animation.as_ref().map_or(0., Animation::value);3335 let current_offset = self.move_animation.as_ref().map_or(0., Animation::value);
3314 3336
3315 self.move_animation = Some(Animation::new(3337 self.move_animation = Some(Animation::new(
3338+ self.clock.now(),
3316 from_x_offset + current_offset,3339 from_x_offset + current_offset,
3317 0.,3340 0.,
3318 0.,3341 0.,
@@ -3716,6 +3739,7 @@ impl<W: LayoutElement> Column<W> {
3716 let mut total_min_height = 0.;3739 let mut total_min_height = 0.;
3717 for (tile, data) in zip(&self.tiles, &self.data) {3740 for (tile, data) in zip(&self.tiles, &self.data) {
3718 assert!(Rc::ptr_eq(&self.options, &tile.options));3741 assert!(Rc::ptr_eq(&self.options, &tile.options));
3742+ assert_eq!(self.clock, tile.clock);
3719 assert_eq!(self.scale, tile.scale());3743 assert_eq!(self.scale, tile.scale());
3720 assert_eq!(self.is_fullscreen, tile.window().is_pending_fullscreen());3744 assert_eq!(self.is_fullscreen, tile.window().is_pending_fullscreen());
3721 3745
src/niri.rsmodified+12 -3
@@ -100,6 +100,7 @@ use smithay::wayland::virtual_keyboard::VirtualKeyboardManagerState;
100 use smithay::wayland::xdg_activation::XdgActivationState;100 use smithay::wayland::xdg_activation::XdgActivationState;
101 use smithay::wayland::xdg_foreign::XdgForeignState;101 use smithay::wayland::xdg_foreign::XdgForeignState;
102 102
103+use crate::animation::Clock;
103 use crate::backend::tty::SurfaceDmabufFeedback;104 use crate::backend::tty::SurfaceDmabufFeedback;
104 use crate::backend::{Backend, RenderResult, Tty, Winit};105 use crate::backend::{Backend, RenderResult, Tty, Winit};
105 use crate::cursor::{CursorManager, CursorTextureCache, RenderCursor, XCursor};106 use crate::cursor::{CursorManager, CursorTextureCache, RenderCursor, XCursor};
@@ -179,6 +180,9 @@ pub struct Niri {
179 /// Whether the at-startup=true window rules are active.180 /// Whether the at-startup=true window rules are active.
180 pub is_at_startup: bool,181 pub is_at_startup: bool,
181 182
183+ /// Clock for driving animations.
184+ pub clock: Clock,
185+
182 // Each workspace corresponds to a Space. Each workspace generally has one Output mapped to it,186 // Each workspace corresponds to a Space. Each workspace generally has one Output mapped to it,
183 // however it may have none (when there are no outputs connected) or multiple (when mirroring).187 // however it may have none (when there are no outputs connected) or multiple (when mirroring).
184 pub layout: Layout<Mapped>,188 pub layout: Layout<Mapped>,
@@ -1671,7 +1675,8 @@ impl Niri {
1671 let config_ = config.borrow();1675 let config_ = config.borrow();
1672 let config_file_output_config = config_.outputs.clone();1676 let config_file_output_config = config_.outputs.clone();
1673 1677
1674- let layout = Layout::new(&config_);1678+ let clock = Clock::default();
1679+ let layout = Layout::new(clock.clone(), &config_);
1675 1680
1676 let (blocker_cleared_tx, blocker_cleared_rx) = mpsc::channel();1681 let (blocker_cleared_tx, blocker_cleared_rx) = mpsc::channel();
1677 1682
@@ -1799,8 +1804,8 @@ impl Niri {
1799 let mods_with_finger_scroll_binds =1804 let mods_with_finger_scroll_binds =
1800 mods_with_finger_scroll_binds(backend.mod_key(), &config_.binds);1805 mods_with_finger_scroll_binds(backend.mod_key(), &config_.binds);
1801 1806
1802- let screenshot_ui = ScreenshotUi::new(config.clone());1807+ let screenshot_ui = ScreenshotUi::new(clock.clone(), config.clone());
1803- let config_error_notification = ConfigErrorNotification::new(config.clone());1808+ let config_error_notification = ConfigErrorNotification::new(clock.clone(), config.clone());
1804 1809
1805 let mut hotkey_overlay = HotkeyOverlay::new(config.clone(), backend.mod_key());1810 let mut hotkey_overlay = HotkeyOverlay::new(config.clone(), backend.mod_key());
1806 if !config_.hotkey_overlay.skip_at_startup {1811 if !config_.hotkey_overlay.skip_at_startup {
@@ -1895,6 +1900,7 @@ impl Niri {
1895 display_handle,1900 display_handle,
1896 start_time: Instant::now(),1901 start_time: Instant::now(),
1897 is_at_startup: true,1902 is_at_startup: true,
1903+ clock,
1898 1904
1899 layout,1905 layout,
1900 global_space: Space::default(),1906 global_space: Space::default(),
@@ -3044,6 +3050,7 @@ impl Niri {
3044 3050
3045 for state in self.output_state.values_mut() {3051 for state in self.output_state.values_mut() {
3046 if let Some(transition) = &mut state.screen_transition {3052 if let Some(transition) = &mut state.screen_transition {
3053+ // Screen transition uses real time so that it's not affected by animation slowdown.
3047 transition.advance_animations(target_time);3054 transition.advance_animations(target_time);
3048 if transition.is_done() {3055 if transition.is_done() {
3049 state.screen_transition = None;3056 state.screen_transition = None;
@@ -4819,6 +4826,8 @@ impl Niri {
4819 let delay = delay_ms.map_or(screen_transition::DELAY, |d| {4826 let delay = delay_ms.map_or(screen_transition::DELAY, |d| {
4820 Duration::from_millis(u64::from(d))4827 Duration::from_millis(u64::from(d))
4821 });4828 });
4829+
4830+ // Screen transition uses real time so that it's not affected by animation slowdown.
4822 let start_at = get_monotonic_time() + delay;4831 let start_at = get_monotonic_time() + delay;
4823 for (output, from_texture) in textures {4832 for (output, from_texture) in textures {
4824 let state = self.output_state.get_mut(&output).unwrap();4833 let state = self.output_state.get_mut(&output).unwrap();
src/ui/config_error_notification.rsmodified+11 -3
@@ -14,7 +14,7 @@ use smithay::output::Output;
14 use smithay::reexports::gbm::Format as Fourcc;14 use smithay::reexports::gbm::Format as Fourcc;
15 use smithay::utils::{Point, Transform};15 use smithay::utils::{Point, Transform};
16 16
17-use crate::animation::Animation;17+use crate::animation::{Animation, Clock};
18 use crate::render_helpers::primary_gpu_texture::PrimaryGpuTextureRenderElement;18 use crate::render_helpers::primary_gpu_texture::PrimaryGpuTextureRenderElement;
19 use crate::render_helpers::renderer::NiriRenderer;19 use crate::render_helpers::renderer::NiriRenderer;
20 use crate::render_helpers::texture::{TextureBuffer, TextureRenderElement};20 use crate::render_helpers::texture::{TextureBuffer, TextureRenderElement};
@@ -35,6 +35,7 @@ pub struct ConfigErrorNotification {
35 // notification.35 // notification.
36 created_path: Option<PathBuf>,36 created_path: Option<PathBuf>,
37 37
38+ clock: Clock,
38 config: Rc<RefCell<Config>>,39 config: Rc<RefCell<Config>>,
39 }40 }
40 41
@@ -46,18 +47,25 @@ enum State {
46 }47 }
47 48
48 impl ConfigErrorNotification {49 impl ConfigErrorNotification {
49- pub fn new(config: Rc<RefCell<Config>>) -> Self {50+ pub fn new(clock: Clock, config: Rc<RefCell<Config>>) -> Self {
50 Self {51 Self {
51 state: State::Hidden,52 state: State::Hidden,
52 buffers: RefCell::new(HashMap::new()),53 buffers: RefCell::new(HashMap::new()),
53 created_path: None,54 created_path: None,
55+ clock,
54 config,56 config,
55 }57 }
56 }58 }
57 59
58 fn animation(&self, from: f64, to: f64) -> Animation {60 fn animation(&self, from: f64, to: f64) -> Animation {
59 let c = self.config.borrow();61 let c = self.config.borrow();
60- Animation::new(from, to, 0., c.animations.config_notification_open_close.0)62+ Animation::new(
63+ self.clock.now(),
64+ from,
65+ to,
66+ 0.,
67+ c.animations.config_notification_open_close.0,
68+ )
61 }69 }
62 70
63 pub fn show_created(&mut self, created_path: PathBuf) {71 pub fn show_created(&mut self, created_path: PathBuf) {
src/ui/screenshot_ui.rsmodified+13 -4
@@ -20,7 +20,7 @@ use smithay::input::keyboard::{Keysym, ModifiersState};
20 use smithay::output::{Output, WeakOutput};20 use smithay::output::{Output, WeakOutput};
21 use smithay::utils::{Physical, Point, Rectangle, Scale, Size, Transform};21 use smithay::utils::{Physical, Point, Rectangle, Scale, Size, Transform};
22 22
23-use crate::animation::Animation;23+use crate::animation::{Animation, Clock};
24 use crate::niri_render_elements;24 use crate::niri_render_elements;
25 use crate::render_helpers::primary_gpu_texture::PrimaryGpuTextureRenderElement;25 use crate::render_helpers::primary_gpu_texture::PrimaryGpuTextureRenderElement;
26 use crate::render_helpers::solid_color::{SolidColorBuffer, SolidColorRenderElement};26 use crate::render_helpers::solid_color::{SolidColorBuffer, SolidColorRenderElement};
@@ -49,6 +49,7 @@ const TEXT_SHOW_P: &str =
49 pub enum ScreenshotUi {49 pub enum ScreenshotUi {
50 Closed {50 Closed {
51 last_selection: Option<(WeakOutput, Rectangle<i32, Physical>)>,51 last_selection: Option<(WeakOutput, Rectangle<i32, Physical>)>,
52+ clock: Clock,
52 config: Rc<RefCell<Config>>,53 config: Rc<RefCell<Config>>,
53 },54 },
54 Open {55 Open {
@@ -57,6 +58,7 @@ pub enum ScreenshotUi {
57 mouse_down: bool,58 mouse_down: bool,
58 show_pointer: bool,59 show_pointer: bool,
59 open_anim: Animation,60 open_anim: Animation,
61+ clock: Clock,
60 config: Rc<RefCell<Config>>,62 config: Rc<RefCell<Config>>,
61 },63 },
62 }64 }
@@ -86,9 +88,10 @@ niri_render_elements! {
86 }88 }
87 89
88 impl ScreenshotUi {90 impl ScreenshotUi {
89- pub fn new(config: Rc<RefCell<Config>>) -> Self {91+ pub fn new(clock: Clock, config: Rc<RefCell<Config>>) -> Self {
90 Self::Closed {92 Self::Closed {
91 last_selection: None,93 last_selection: None,
94+ clock,
92 config,95 config,
93 }96 }
94 }97 }
@@ -106,6 +109,7 @@ impl ScreenshotUi {
106 109
107 let Self::Closed {110 let Self::Closed {
108 last_selection,111 last_selection,
112+ clock,
109 config,113 config,
110 } = self114 } = self
111 else {115 else {
@@ -181,7 +185,7 @@ impl ScreenshotUi {
181 185
182 let open_anim = {186 let open_anim = {
183 let c = config.borrow();187 let c = config.borrow();
184- Animation::new(0., 1., 0., c.animations.screenshot_ui_open.0)188+ Animation::new(clock.now(), 0., 1., 0., c.animations.screenshot_ui_open.0)
185 };189 };
186 190
187 *self = Self::Open {191 *self = Self::Open {
@@ -190,6 +194,7 @@ impl ScreenshotUi {
190 mouse_down: false,194 mouse_down: false,
191 show_pointer: true,195 show_pointer: true,
192 open_anim,196 open_anim,
197+ clock: clock.clone(),
193 config: config.clone(),198 config: config.clone(),
194 };199 };
195 200
@@ -200,7 +205,10 @@ impl ScreenshotUi {
200 205
201 pub fn close(&mut self) -> bool {206 pub fn close(&mut self) -> bool {
202 let Self::Open {207 let Self::Open {
203- selection, config, ..208+ selection,
209+ clock,
210+ config,
211+ ..
204 } = self212 } = self
205 else {213 else {
206 return false;214 return false;
@@ -213,6 +221,7 @@ impl ScreenshotUi {
213 221
214 *self = Self::Closed {222 *self = Self::Closed {
215 last_selection,223 last_selection,
224+ clock: clock.clone(),
216 config: config.clone(),225 config: config.clone(),
217 };226 };
218 227