From a8aad69ecbc03de684e2c931fa22065bfc43dfe0 Mon Sep 17 00:00:00 2001 From: LGUG2Z Date: Mon, 27 Nov 2023 12:04:41 -0800 Subject: [PATCH] feat(config): add animation options --- komorebi-core/src/lib.rs | 6 +++--- komorebi/src/animation.rs | 4 ++-- komorebi/src/main.rs | 6 +++--- komorebi/src/process_command.rs | 18 +++++++++--------- komorebi/src/static_config.rs | 29 +++++++++++++++++++++++++++++ komorebi/src/window.rs | 8 ++++---- komorebi/src/workspace.rs | 4 ++-- komorebic/src/main.rs | 6 +++--- 8 files changed, 55 insertions(+), 26 deletions(-) diff --git a/komorebi-core/src/lib.rs b/komorebi-core/src/lib.rs index 25b1afef..dd138dea 100644 --- a/komorebi-core/src/lib.rs +++ b/komorebi-core/src/lib.rs @@ -129,9 +129,9 @@ pub enum SocketMessage { WatchConfiguration(bool), CompleteConfiguration, AltFocusHack(bool), - Animate(bool), - AnimateDuration(u64), - AnimateEase(EaseEnum), + Animation(bool), + AnimationDuration(u64), + AnimationEase(EaseEnum), ActiveWindowBorder(bool), ActiveWindowBorderColour(WindowKind, u32, u32, u32), ActiveWindowBorderWidth(i32), diff --git a/komorebi/src/animation.rs b/komorebi/src/animation.rs index e2cdf0a6..3ecce95e 100644 --- a/komorebi/src/animation.rs +++ b/komorebi/src/animation.rs @@ -8,7 +8,7 @@ use std::f64::consts::PI; use std::time::Duration; use std::time::Instant; -use crate::ANIMATE_EASE; +use crate::ANIMATION_EASE; pub trait Ease { fn evaluate(t: f64) -> f64; @@ -363,7 +363,7 @@ impl Ease for EaseInOutBounce { } } fn apply_ease_func(t: f64) -> f64 { - let ease = *ANIMATE_EASE.lock(); + let ease = *ANIMATION_EASE.lock(); match ease { EaseEnum::Linear => Linear::evaluate(t), diff --git a/komorebi/src/main.rs b/komorebi/src/main.rs index 8b041f5e..7540e093 100644 --- a/komorebi/src/main.rs +++ b/komorebi/src/main.rs @@ -217,7 +217,7 @@ lazy_static! { static ref BORDER_OFFSET: Arc>> = Arc::new(Mutex::new(None)); - static ref ANIMATE_EASE: Arc> = Arc::new(Mutex::new(EaseEnum::EaseInOutExpo)); + static ref ANIMATION_EASE: Arc> = Arc::new(Mutex::new(EaseEnum::Linear)); // Use app-specific titlebar removal options where possible // eg. Windows Terminal, IntelliJ IDEA, Firefox @@ -242,8 +242,8 @@ pub static BORDER_WIDTH: AtomicI32 = AtomicI32::new(20); // 0 0 0 aka pure black, I doubt anyone will want this as a border colour pub const TRANSPARENCY_COLOUR: u32 = 0; pub static REMOVE_TITLEBARS: AtomicBool = AtomicBool::new(false); -pub static ANIMATE_ENABLED: AtomicBool = AtomicBool::new(true); -pub static ANIMATE_DURATION: AtomicU64 = AtomicU64::new(250); +pub static ANIMATION_ENABLED: AtomicBool = AtomicBool::new(false); +pub static ANIMATION_DURATION: AtomicU64 = AtomicU64::new(250); pub static HIDDEN_HWND: AtomicIsize = AtomicIsize::new(0); diff --git a/komorebi/src/process_command.rs b/komorebi/src/process_command.rs index ac28ae29..9ed5ce92 100644 --- a/komorebi/src/process_command.rs +++ b/komorebi/src/process_command.rs @@ -47,9 +47,9 @@ use crate::windows_api::WindowsApi; use crate::Notification; use crate::NotificationEvent; use crate::ALT_FOCUS_HACK; -use crate::ANIMATE_DURATION; -use crate::ANIMATE_EASE; -use crate::ANIMATE_ENABLED; +use crate::ANIMATION_DURATION; +use crate::ANIMATION_EASE; +use crate::ANIMATION_ENABLED; use crate::BORDER_COLOUR_CURRENT; use crate::BORDER_COLOUR_MONOCLE; use crate::BORDER_COLOUR_SINGLE; @@ -1143,14 +1143,14 @@ impl WindowManager { self.hide_border()?; } } - SocketMessage::Animate(enable) => { - ANIMATE_ENABLED.store(enable, Ordering::SeqCst); + SocketMessage::Animation(enable) => { + ANIMATION_ENABLED.store(enable, Ordering::SeqCst); } - SocketMessage::AnimateDuration(duration) => { - ANIMATE_DURATION.store(duration, Ordering::SeqCst); + SocketMessage::AnimationDuration(duration) => { + ANIMATION_DURATION.store(duration, Ordering::SeqCst); } - SocketMessage::AnimateEase(ease) => { - *ANIMATE_EASE.lock() = ease; + SocketMessage::AnimationEase(ease) => { + *ANIMATION_EASE.lock() = ease; } SocketMessage::ActiveWindowBorderColour(kind, r, g, b) => { match kind { diff --git a/komorebi/src/static_config.rs b/komorebi/src/static_config.rs index 1b3e6e8d..b29202ea 100644 --- a/komorebi/src/static_config.rs +++ b/komorebi/src/static_config.rs @@ -7,6 +7,9 @@ use crate::window_manager_event::WindowManagerEvent; use crate::windows_api::WindowsApi; use crate::workspace::Workspace; use crate::ALT_FOCUS_HACK; +use crate::ANIMATION_DURATION; +use crate::ANIMATION_EASE; +use crate::ANIMATION_ENABLED; use crate::BORDER_COLOUR_CURRENT; use crate::BORDER_COLOUR_MONOCLE; use crate::BORDER_COLOUR_SINGLE; @@ -39,6 +42,7 @@ use komorebi_core::config_generation::MatchingStrategy; use komorebi_core::resolve_home_path; use komorebi_core::ApplicationIdentifier; use komorebi_core::DefaultLayout; +use komorebi_core::EaseEnum; use komorebi_core::FocusFollowsMouseImplementation; use komorebi_core::HidingBehaviour; use komorebi_core::Layout; @@ -312,6 +316,15 @@ pub struct StaticConfig { /// Set monitor index preferences #[serde(skip_serializing_if = "Option::is_none")] pub monitor_index_preferences: Option>, + /// Enable or disable animations (default: false) + #[serde(skip_serializing_if = "Option::is_none")] + pub animation: Option, + /// Set the animation ease function (default: Linear) + #[serde(skip_serializing_if = "Option::is_none")] + pub animation_ease: Option, + /// Set the animation duration in ms (default: 250) + #[serde(skip_serializing_if = "Option::is_none")] + pub animation_duration: Option, } impl From<&WindowManager> for StaticConfig { @@ -432,6 +445,9 @@ impl From<&WindowManager> for StaticConfig { layered_applications: None, object_name_change_applications: None, monitor_index_preferences: Option::from(MONITOR_INDEX_PREFERENCES.lock().clone()), + animation: Option::from(ANIMATION_ENABLED.load(Ordering::SeqCst)), + animation_duration: Option::from(ANIMATION_DURATION.load(Ordering::SeqCst)), + animation_ease: Option::from(*ANIMATION_EASE.lock()), } } } @@ -449,6 +465,19 @@ impl StaticConfig { *window_hiding_behaviour = behaviour; } + if let Some(animation) = self.animation { + ANIMATION_ENABLED.store(animation, Ordering::SeqCst); + } + + if let Some(duration) = self.animation_duration { + ANIMATION_DURATION.store(duration, Ordering::SeqCst); + } + + if let Some(ease) = self.animation_ease { + let mut animation_ease = ANIMATION_EASE.lock(); + *animation_ease = ease; + } + if let Some(hack) = self.alt_focus_hack { ALT_FOCUS_HACK.store(hack, Ordering::SeqCst); } diff --git a/komorebi/src/window.rs b/komorebi/src/window.rs index ad173eae..5a1a63ab 100644 --- a/komorebi/src/window.rs +++ b/komorebi/src/window.rs @@ -1,7 +1,7 @@ use crate::com::SetCloak; use crate::winevent_listener::WINEVENT_CALLBACK_CHANNEL; -use crate::ANIMATE_DURATION; -use crate::ANIMATE_ENABLED; +use crate::ANIMATION_DURATION; +use crate::ANIMATION_ENABLED; use std::collections::HashMap; use std::convert::TryFrom; use std::fmt::Display; @@ -148,7 +148,7 @@ impl Window { WindowsApi::position_window(hwnd, layout, top) } else { let target_rect = *layout; - let duration = Duration::from_millis(ANIMATE_DURATION.load(Ordering::SeqCst)); + let duration = Duration::from_millis(ANIMATION_DURATION.load(Ordering::SeqCst)); let mut animation = self.animation; let self_copied = *self; @@ -209,7 +209,7 @@ impl Window { rect.bottom += invisible_borders.bottom; } - if ANIMATE_ENABLED.load(Ordering::SeqCst) { + if ANIMATION_ENABLED.load(Ordering::SeqCst) { // check if animation is in progress if self.animation.in_progress { // wait for cancel animation diff --git a/komorebi/src/workspace.rs b/komorebi/src/workspace.rs index 6deb5e0a..ddd0ed93 100644 --- a/komorebi/src/workspace.rs +++ b/komorebi/src/workspace.rs @@ -25,7 +25,7 @@ use crate::ring::Ring; use crate::static_config::WorkspaceConfig; use crate::window::Window; use crate::windows_api::WindowsApi; -use crate::ANIMATE_ENABLED; +use crate::ANIMATION_ENABLED; use crate::BORDER_HIDDEN; use crate::BORDER_HWND; use crate::DEFAULT_CONTAINER_PADDING; @@ -248,7 +248,7 @@ impl Workspace { } if *self.tile() { - if ANIMATE_ENABLED.load(Ordering::SeqCst) { + if ANIMATION_ENABLED.load(Ordering::SeqCst) { let border = Border::from(BORDER_HWND.load(Ordering::SeqCst)); border.hide()?; BORDER_HIDDEN.store(true, Ordering::SeqCst); diff --git a/komorebic/src/main.rs b/komorebic/src/main.rs index 3450ddf8..c3bd7da1 100644 --- a/komorebic/src/main.rs +++ b/komorebic/src/main.rs @@ -2016,13 +2016,13 @@ Stop-Process -Name:whkd -ErrorAction SilentlyContinue send_message(&SocketMessage::ActiveWindowBorderOffset(arg.offset).as_bytes()?)?; } SubCommand::Animate(arg) => { - send_message(&SocketMessage::Animate(arg.boolean_state.into()).as_bytes()?)?; + send_message(&SocketMessage::Animation(arg.boolean_state.into()).as_bytes()?)?; } SubCommand::AnimateDuration(arg) => { - send_message(&SocketMessage::AnimateDuration(arg.duration).as_bytes()?)?; + send_message(&SocketMessage::AnimationDuration(arg.duration).as_bytes()?)?; } SubCommand::AnimateEase(arg) => { - send_message(&SocketMessage::AnimateEase(arg.ease_func).as_bytes()?)?; + send_message(&SocketMessage::AnimationEase(arg.ease_func).as_bytes()?)?; } SubCommand::ResizeDelta(arg) => { send_message(&SocketMessage::ResizeDelta(arg.pixels).as_bytes()?)?;