Skip to content

Commit

Permalink
feat(config): add animation options
Browse files Browse the repository at this point in the history
  • Loading branch information
LGUG2Z committed Dec 2, 2023
1 parent ed550ab commit 1f75520
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 26 deletions.
6 changes: 3 additions & 3 deletions komorebi-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
4 changes: 2 additions & 2 deletions komorebi/src/animation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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),
Expand Down
6 changes: 3 additions & 3 deletions komorebi/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ lazy_static! {
static ref BORDER_OFFSET: Arc<Mutex<Option<Rect>>> =
Arc::new(Mutex::new(None));

static ref ANIMATE_EASE: Arc<Mutex<EaseEnum>> = Arc::new(Mutex::new(EaseEnum::EaseInOutExpo));
static ref ANIMATION_EASE: Arc<Mutex<EaseEnum>> = Arc::new(Mutex::new(EaseEnum::Linear));

// Use app-specific titlebar removal options where possible
// eg. Windows Terminal, IntelliJ IDEA, Firefox
Expand All @@ -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);

Expand Down
18 changes: 9 additions & 9 deletions komorebi/src/process_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,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;
Expand Down Expand Up @@ -1142,14 +1142,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 {
Expand Down
29 changes: 29 additions & 0 deletions komorebi/src/static_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -312,6 +316,15 @@ pub struct StaticConfig {
/// Set monitor index preferences
#[serde(skip_serializing_if = "Option::is_none")]
pub monitor_index_preferences: Option<HashMap<usize, Rect>>,
/// Enable or disable animations (default: false)
#[serde(skip_serializing_if = "Option::is_none")]
pub animation: Option<bool>,
/// Set the animation ease function (default: Linear)
#[serde(skip_serializing_if = "Option::is_none")]
pub animation_ease: Option<EaseEnum>,
/// Set the animation duration in ms (default: 250)
#[serde(skip_serializing_if = "Option::is_none")]
pub animation_duration: Option<u64>,
}

impl From<&WindowManager> for StaticConfig {
Expand Down Expand Up @@ -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()),
}
}
}
Expand All @@ -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);
}
Expand Down
8 changes: 4 additions & 4 deletions komorebi/src/window.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions komorebi/src/workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions komorebic/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2013,13 +2013,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()?)?;
Expand Down

0 comments on commit 1f75520

Please sign in to comment.