diff --git a/komorebi/src/lib.rs b/komorebi/src/lib.rs index 70d5601a..88d76054 100644 --- a/komorebi/src/lib.rs +++ b/komorebi/src/lib.rs @@ -228,6 +228,7 @@ pub static SESSION_ID: AtomicU32 = AtomicU32::new(0); pub static REMOVE_TITLEBARS: AtomicBool = AtomicBool::new(false); pub static ANIMATION_ENABLED: AtomicBool = AtomicBool::new(false); +pub static ANIMATION_TEMPORARY_DISABLED: AtomicBool = AtomicBool::new(false); pub static ANIMATION_DURATION: AtomicU64 = AtomicU64::new(250); #[must_use] diff --git a/komorebi/src/window.rs b/komorebi/src/window.rs index c8f56e35..703b4a7e 100644 --- a/komorebi/src/window.rs +++ b/komorebi/src/window.rs @@ -5,6 +5,7 @@ use crate::stackbar_manager; use crate::ANIMATIONS_IN_PROGRESS; use crate::ANIMATION_DURATION; use crate::ANIMATION_ENABLED; +use crate::ANIMATION_TEMPORARY_DISABLED; use std::collections::HashMap; use std::convert::TryFrom; use std::fmt::Display; @@ -223,7 +224,9 @@ impl Window { return Ok(()); } - if ANIMATION_ENABLED.load(Ordering::SeqCst) { + if ANIMATION_ENABLED.load(Ordering::SeqCst) + && !ANIMATION_TEMPORARY_DISABLED.load(Ordering::SeqCst) + { self.animate_position(layout, top) } else { WindowsApi::position_window(self.hwnd(), layout, top) diff --git a/komorebi/src/window_manager.rs b/komorebi/src/window_manager.rs index d2cf2203..0386db90 100644 --- a/komorebi/src/window_manager.rs +++ b/komorebi/src/window_manager.rs @@ -65,6 +65,7 @@ use crate::BorderColours; use crate::Colour; use crate::Rgb; use crate::WorkspaceRule; +use crate::ANIMATION_TEMPORARY_DISABLED; use crate::CUSTOM_FFM; use crate::DATA_DIR; use crate::DISPLAY_INDEX_PREFERENCES; @@ -1108,6 +1109,7 @@ impl WindowManager { follow: bool, ) -> Result<()> { self.handle_unmanaged_window_behaviour()?; + ANIMATION_TEMPORARY_DISABLED.store(true, Ordering::SeqCst); tracing::info!("moving container"); @@ -1177,12 +1179,17 @@ impl WindowManager { self.focus_monitor(monitor_idx)?; } - self.update_focused_workspace(self.mouse_follows_focus, true) + self.update_focused_workspace(self.mouse_follows_focus, true)?; + + ANIMATION_TEMPORARY_DISABLED.store(false, Ordering::SeqCst); + + Ok(()) } #[tracing::instrument(skip(self))] pub fn move_container_to_workspace(&mut self, idx: usize, follow: bool) -> Result<()> { self.handle_unmanaged_window_behaviour()?; + ANIMATION_TEMPORARY_DISABLED.store(true, Ordering::SeqCst); tracing::info!("moving container"); @@ -1194,7 +1201,11 @@ impl WindowManager { monitor.move_container_to_workspace(idx, follow)?; monitor.load_focused_workspace(mouse_follows_focus)?; - self.update_focused_workspace(mouse_follows_focus, true) + self.update_focused_workspace(mouse_follows_focus, true)?; + + ANIMATION_TEMPORARY_DISABLED.store(false, Ordering::SeqCst); + + Ok(()) } pub fn remove_focused_workspace(&mut self) -> Option { @@ -1297,6 +1308,13 @@ impl WindowManager { let origin_monitor_idx = self.focused_monitor_idx(); let target_container_idx = workspace.new_idx_for_direction(direction); + let animation_temporarily_disabled = if target_container_idx.is_none() { + ANIMATION_TEMPORARY_DISABLED.store(true, Ordering::SeqCst); + true + } else { + false + }; + match target_container_idx { // If there is nowhere to move on the current workspace, try to move it onto the monitor // in that direction if there is one @@ -1421,7 +1439,13 @@ impl WindowManager { } } - self.update_focused_workspace(self.mouse_follows_focus, true) + self.update_focused_workspace(self.mouse_follows_focus, true)?; + + if animation_temporarily_disabled { + ANIMATION_TEMPORARY_DISABLED.store(false, Ordering::SeqCst); + } + + Ok(()) } #[tracing::instrument(skip(self))]