aboutsummaryrefslogtreecommitdiff
path: root/src/ui
diff options
context:
space:
mode:
authorIvan Molodetskikh <yalterz@gmail.com>2024-11-23 11:27:27 +0300
committerIvan Molodetskikh <yalterz@gmail.com>2024-11-25 04:07:59 -0800
commit93cee2994ab9ccf59a09f61d5b8acf6cd937d654 (patch)
treefb00cdb266e9e94891f226558cd93a09e0091d69 /src/ui
parent9c7e8d04d27d2f914ad3e9a54c64b64c34aea4d4 (diff)
downloadniri-93cee2994ab9ccf59a09f61d5b8acf6cd937d654.tar.gz
niri-93cee2994ab9ccf59a09f61d5b8acf6cd937d654.tar.bz2
niri-93cee2994ab9ccf59a09f61d5b8acf6cd937d654.zip
Refactor animations to take explicit current time
Diffstat (limited to 'src/ui')
-rw-r--r--src/ui/config_error_notification.rs14
-rw-r--r--src/ui/screenshot_ui.rs17
2 files changed, 24 insertions, 7 deletions
diff --git a/src/ui/config_error_notification.rs b/src/ui/config_error_notification.rs
index c4ca3b69..af4f67e3 100644
--- a/src/ui/config_error_notification.rs
+++ b/src/ui/config_error_notification.rs
@@ -14,7 +14,7 @@ use smithay::output::Output;
use smithay::reexports::gbm::Format as Fourcc;
use smithay::utils::{Point, Transform};
-use crate::animation::Animation;
+use crate::animation::{Animation, Clock};
use crate::render_helpers::primary_gpu_texture::PrimaryGpuTextureRenderElement;
use crate::render_helpers::renderer::NiriRenderer;
use crate::render_helpers::texture::{TextureBuffer, TextureRenderElement};
@@ -35,6 +35,7 @@ pub struct ConfigErrorNotification {
// notification.
created_path: Option<PathBuf>,
+ clock: Clock,
config: Rc<RefCell<Config>>,
}
@@ -46,18 +47,25 @@ enum State {
}
impl ConfigErrorNotification {
- pub fn new(config: Rc<RefCell<Config>>) -> Self {
+ pub fn new(clock: Clock, config: Rc<RefCell<Config>>) -> Self {
Self {
state: State::Hidden,
buffers: RefCell::new(HashMap::new()),
created_path: None,
+ clock,
config,
}
}
fn animation(&self, from: f64, to: f64) -> Animation {
let c = self.config.borrow();
- Animation::new(from, to, 0., c.animations.config_notification_open_close.0)
+ Animation::new(
+ self.clock.now(),
+ from,
+ to,
+ 0.,
+ c.animations.config_notification_open_close.0,
+ )
}
pub fn show_created(&mut self, created_path: PathBuf) {
diff --git a/src/ui/screenshot_ui.rs b/src/ui/screenshot_ui.rs
index 0e2006a1..cde9bdac 100644
--- a/src/ui/screenshot_ui.rs
+++ b/src/ui/screenshot_ui.rs
@@ -20,7 +20,7 @@ use smithay::input::keyboard::{Keysym, ModifiersState};
use smithay::output::{Output, WeakOutput};
use smithay::utils::{Physical, Point, Rectangle, Scale, Size, Transform};
-use crate::animation::Animation;
+use crate::animation::{Animation, Clock};
use crate::niri_render_elements;
use crate::render_helpers::primary_gpu_texture::PrimaryGpuTextureRenderElement;
use crate::render_helpers::solid_color::{SolidColorBuffer, SolidColorRenderElement};
@@ -49,6 +49,7 @@ const TEXT_SHOW_P: &str =
pub enum ScreenshotUi {
Closed {
last_selection: Option<(WeakOutput, Rectangle<i32, Physical>)>,
+ clock: Clock,
config: Rc<RefCell<Config>>,
},
Open {
@@ -57,6 +58,7 @@ pub enum ScreenshotUi {
mouse_down: bool,
show_pointer: bool,
open_anim: Animation,
+ clock: Clock,
config: Rc<RefCell<Config>>,
},
}
@@ -86,9 +88,10 @@ niri_render_elements! {
}
impl ScreenshotUi {
- pub fn new(config: Rc<RefCell<Config>>) -> Self {
+ pub fn new(clock: Clock, config: Rc<RefCell<Config>>) -> Self {
Self::Closed {
last_selection: None,
+ clock,
config,
}
}
@@ -106,6 +109,7 @@ impl ScreenshotUi {
let Self::Closed {
last_selection,
+ clock,
config,
} = self
else {
@@ -181,7 +185,7 @@ impl ScreenshotUi {
let open_anim = {
let c = config.borrow();
- Animation::new(0., 1., 0., c.animations.screenshot_ui_open.0)
+ Animation::new(clock.now(), 0., 1., 0., c.animations.screenshot_ui_open.0)
};
*self = Self::Open {
@@ -190,6 +194,7 @@ impl ScreenshotUi {
mouse_down: false,
show_pointer: true,
open_anim,
+ clock: clock.clone(),
config: config.clone(),
};
@@ -200,7 +205,10 @@ impl ScreenshotUi {
pub fn close(&mut self) -> bool {
let Self::Open {
- selection, config, ..
+ selection,
+ clock,
+ config,
+ ..
} = self
else {
return false;
@@ -213,6 +221,7 @@ impl ScreenshotUi {
*self = Self::Closed {
last_selection,
+ clock: clock.clone(),
config: config.clone(),
};