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