aboutsummaryrefslogtreecommitdiff
path: root/src/config_error_notification.rs
diff options
context:
space:
mode:
authorIvan Molodetskikh <yalterz@gmail.com>2024-02-07 17:05:15 +0400
committerIvan Molodetskikh <yalterz@gmail.com>2024-02-07 17:14:24 +0400
commit6424a2738db6349de62dab150d5d6f1d431ca6c4 (patch)
tree39adaf858ec3ee8661a40be6b4792df215ab4368 /src/config_error_notification.rs
parent753a90430abbdf166a86b95c5c69aa1e68b3c412 (diff)
downloadniri-6424a2738db6349de62dab150d5d6f1d431ca6c4.tar.gz
niri-6424a2738db6349de62dab150d5d6f1d431ca6c4.tar.bz2
niri-6424a2738db6349de62dab150d5d6f1d431ca6c4.zip
Make all animations configurable
Diffstat (limited to 'src/config_error_notification.rs')
-rw-r--r--src/config_error_notification.rs29
1 files changed, 19 insertions, 10 deletions
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<PathBuf>,
+
+ config: Rc<RefCell<Config>>,
}
enum State {
@@ -44,21 +48,32 @@ pub type ConfigErrorNotificationRenderElement<R> =
RelocateRenderElement<MemoryRenderBufferRenderElement<R>>;
impl ConfigErrorNotification {
- pub fn new() -> Self {
+ pub fn new(config: Rc<RefCell<Config>>) -> 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<PathBuf>) {
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<MemoryRenderBuffer> {
let _span = tracy_client::span!("config_error_notification::render");