diff options
| author | Ivan Molodetskikh <yalterz@gmail.com> | 2024-02-07 17:05:15 +0400 |
|---|---|---|
| committer | Ivan Molodetskikh <yalterz@gmail.com> | 2024-02-07 17:14:24 +0400 |
| commit | 6424a2738db6349de62dab150d5d6f1d431ca6c4 (patch) | |
| tree | 39adaf858ec3ee8661a40be6b4792df215ab4368 /src | |
| parent | 753a90430abbdf166a86b95c5c69aa1e68b3c412 (diff) | |
| download | niri-6424a2738db6349de62dab150d5d6f1d431ca6c4.tar.gz niri-6424a2738db6349de62dab150d5d6f1d431ca6c4.tar.bz2 niri-6424a2738db6349de62dab150d5d6f1d431ca6c4.zip | |
Make all animations configurable
Diffstat (limited to 'src')
| -rw-r--r-- | src/animation.rs | 33 | ||||
| -rw-r--r-- | src/config_error_notification.rs | 29 | ||||
| -rw-r--r-- | src/layout/mod.rs | 6 | ||||
| -rw-r--r-- | src/layout/monitor.rs | 3 | ||||
| -rw-r--r-- | src/layout/tile.rs | 9 | ||||
| -rw-r--r-- | src/layout/workspace.rs | 3 | ||||
| -rw-r--r-- | src/main.rs | 8 | ||||
| -rw-r--r-- | src/niri.rs | 10 |
8 files changed, 75 insertions, 26 deletions
diff --git a/src/animation.rs b/src/animation.rs index 404c3d85..bb22b75c 100644 --- a/src/animation.rs +++ b/src/animation.rs @@ -25,28 +25,36 @@ pub enum Curve { } impl Animation { - pub fn new(from: f64, to: f64, over_ms: u32) -> Self { + pub fn new( + from: f64, + to: f64, + config: niri_config::Animation, + default: niri_config::Animation, + ) -> Self { // FIXME: ideally we shouldn't use current time here because animations started within the // same frame cycle should have the same start time to be synchronized. let now = get_monotonic_time(); - let duration = Duration::from_millis(u64::from(over_ms)) + let duration_ms = if config.off { + 0 + } else { + config.duration_ms.unwrap_or(default.duration_ms.unwrap()) + }; + let duration = Duration::from_millis(u64::from(duration_ms)) .mul_f64(ANIMATION_SLOWDOWN.load(Ordering::Relaxed)); + + let curve = Curve::from(config.curve.unwrap_or(default.curve.unwrap())); + Self { from, to, duration, start_time: now, current_time: now, - curve: Curve::EaseOutCubic, + curve, } } - pub fn with_curve(mut self, curve: Curve) -> Self { - self.curve = curve; - self - } - pub fn set_current_time(&mut self, time: Duration) { self.current_time = time; } @@ -80,3 +88,12 @@ impl Curve { } } } + +impl From<niri_config::AnimationCurve> for Curve { + fn from(value: niri_config::AnimationCurve) -> Self { + match value { + niri_config::AnimationCurve::EaseOutCubic => Curve::EaseOutCubic, + niri_config::AnimationCurve::EaseOutExpo => Curve::EaseOutExpo, + } + } +} 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"); diff --git a/src/layout/mod.rs b/src/layout/mod.rs index 7c381358..c4bcc61f 100644 --- a/src/layout/mod.rs +++ b/src/layout/mod.rs @@ -158,6 +158,7 @@ pub struct Options { pub preset_widths: Vec<ColumnWidth>, /// Initial width for new columns. pub default_width: Option<ColumnWidth>, + pub animations: niri_config::Animations, } impl Default for Options { @@ -174,6 +175,7 @@ impl Default for Options { ColumnWidth::Proportion(2. / 3.), ], default_width: None, + animations: Default::default(), } } } @@ -209,6 +211,7 @@ impl Options { center_focused_column: layout.center_focused_column, preset_widths, default_width, + animations: config.animations, } } } @@ -1577,7 +1580,8 @@ impl<W: LayoutElement> Layout<W> { monitor.workspace_switch = Some(WorkspaceSwitch::Animation(Animation::new( current_idx, idx as f64, - 250, + self.options.animations.workspace_switch, + niri_config::Animation::default_workspace_switch(), ))); return Some(monitor.output.clone()); diff --git a/src/layout/monitor.rs b/src/layout/monitor.rs index accce645..e67f5bf2 100644 --- a/src/layout/monitor.rs +++ b/src/layout/monitor.rs @@ -96,7 +96,8 @@ impl<W: LayoutElement> Monitor<W> { self.workspace_switch = Some(WorkspaceSwitch::Animation(Animation::new( current_idx, idx as f64, - 250, + self.options.animations.workspace_switch, + niri_config::Animation::default_workspace_switch(), ))); } diff --git a/src/layout/tile.rs b/src/layout/tile.rs index be96f6e6..62f79a77 100644 --- a/src/layout/tile.rs +++ b/src/layout/tile.rs @@ -11,7 +11,7 @@ use smithay::utils::{Logical, Point, Rectangle, Scale, Size}; use super::focus_ring::FocusRing; use super::{LayoutElement, LayoutElementRenderElement, Options}; -use crate::animation::{Animation, Curve}; +use crate::animation::Animation; use crate::niri_render_elements; use crate::render_helpers::offscreen::OffscreenRenderElement; use crate::render_helpers::renderer::NiriRenderer; @@ -114,7 +114,12 @@ impl<W: LayoutElement> Tile<W> { } pub fn start_open_animation(&mut self) { - self.open_animation = Some(Animation::new(0., 1., 150).with_curve(Curve::EaseOutExpo)); + self.open_animation = Some(Animation::new( + 0., + 1., + self.options.animations.window_open, + niri_config::Animation::default_window_open(), + )); } pub fn window(&self) -> &W { diff --git a/src/layout/workspace.rs b/src/layout/workspace.rs index 9165d7e0..0e576b7a 100644 --- a/src/layout/workspace.rs +++ b/src/layout/workspace.rs @@ -401,7 +401,8 @@ impl<W: LayoutElement> Workspace<W> { self.view_offset_anim = Some(Animation::new( self.view_offset as f64, new_view_offset as f64, - 250, + self.options.animations.horizontal_view_movement, + niri_config::Animation::default_horizontal_view_movement(), )); } diff --git a/src/main.rs b/src/main.rs index 3e38b6d0..3dfacfa1 100644 --- a/src/main.rs +++ b/src/main.rs @@ -177,7 +177,13 @@ fn main() -> Result<(), Box<dyn std::error::Error>> { }) .unwrap_or_default(); - animation::ANIMATION_SLOWDOWN.store(config.debug.animation_slowdown, Ordering::Relaxed); + let slowdown = if config.animations.off { + 0. + } else { + config.animations.slowdown + }; + animation::ANIMATION_SLOWDOWN.store(slowdown, Ordering::Relaxed); + let spawn_at_startup = mem::take(&mut config.spawn_at_startup); // Create the compositor. diff --git a/src/niri.rs b/src/niri.rs index 3cb01091..aa1df4d9 100644 --- a/src/niri.rs +++ b/src/niri.rs @@ -581,7 +581,13 @@ impl State { self.niri.config_error_notification.hide(); self.niri.layout.update_config(&config); - animation::ANIMATION_SLOWDOWN.store(config.debug.animation_slowdown, Ordering::Relaxed); + + let slowdown = if config.animations.off { + 0. + } else { + config.animations.slowdown + }; + animation::ANIMATION_SLOWDOWN.store(slowdown, Ordering::Relaxed); let mut reload_xkb = None; let mut libinput_config_changed = false; @@ -902,7 +908,7 @@ impl Niri { }); let screenshot_ui = ScreenshotUi::new(); - let config_error_notification = ConfigErrorNotification::new(); + let config_error_notification = ConfigErrorNotification::new(config.clone()); let mut hotkey_overlay = HotkeyOverlay::new(config.clone(), backend.mod_key()); if !config_.hotkey_overlay.skip_at_startup { |
