From 6424a2738db6349de62dab150d5d6f1d431ca6c4 Mon Sep 17 00:00:00 2001 From: Ivan Molodetskikh Date: Wed, 7 Feb 2024 17:05:15 +0400 Subject: Make all animations configurable --- src/config_error_notification.rs | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) (limited to 'src/config_error_notification.rs') diff --git a/src/config_error_notification.rs b/src/config_error_notification.rs index b80e8d27..12d92b85 100644 --- a/src/config_error_notification.rs +++ b/src/config_error_notification.rs @@ -1,8 +1,10 @@ use std::cell::RefCell; use std::collections::HashMap; use std::path::{Path, PathBuf}; +use std::rc::Rc; use std::time::Duration; +use niri_config::Config; use pangocairo::cairo::{self, ImageSurface}; use pangocairo::pango::FontDescription; use smithay::backend::renderer::element::memory::{ @@ -31,6 +33,8 @@ pub struct ConfigErrorNotification { // If set, this is a "Created config at {path}" notification. If unset, this is a config error // notification. created_path: Option, + + config: Rc>, } enum State { @@ -44,21 +48,32 @@ pub type ConfigErrorNotificationRenderElement = RelocateRenderElement>; impl ConfigErrorNotification { - pub fn new() -> Self { + pub fn new(config: Rc>) -> Self { Self { state: State::Hidden, buffers: RefCell::new(HashMap::new()), created_path: None, + config, } } + fn animation(&self, from: f64, to: f64) -> Animation { + let c = self.config.borrow(); + Animation::new( + from, + to, + c.animations.config_notification_open_close, + niri_config::Animation::default_config_notification_open_close(), + ) + } + pub fn show_created(&mut self, created_path: Option) { if self.created_path != created_path { self.created_path = created_path; self.buffers.borrow_mut().clear(); } - self.state = State::Showing(Animation::new(0., 1., 250)); + self.state = State::Showing(self.animation(0., 1.)); } pub fn show(&mut self) { @@ -68,7 +83,7 @@ impl ConfigErrorNotification { } // Show from scratch even if already showing to bring attention. - self.state = State::Showing(Animation::new(0., 1., 250)); + self.state = State::Showing(self.animation(0., 1.)); } pub fn hide(&mut self) { @@ -76,7 +91,7 @@ impl ConfigErrorNotification { return; } - self.state = State::Hiding(Animation::new(1., 0., 250)); + self.state = State::Hiding(self.animation(1., 0.)); } pub fn advance_animations(&mut self, target_presentation_time: Duration) { @@ -167,12 +182,6 @@ impl ConfigErrorNotification { } } -impl Default for ConfigErrorNotification { - fn default() -> Self { - Self::new() - } -} - fn render(scale: i32, created_path: Option<&Path>) -> anyhow::Result { let _span = tracy_client::span!("config_error_notification::render"); -- cgit