Skip to content

Commit

Permalink
fix(animation): disable on cross-monitor ops
Browse files Browse the repository at this point in the history
There are quite a lot of janky animation bugs when moving window
containers across monitor and workspace boundaries.

This commit disables animation on all of the main cross-border window
container operations, meaning that animations should now only happen
within the context of a single workspace.

fix #912
  • Loading branch information
LGUG2Z committed Jul 12, 2024
1 parent 2c8f25e commit 50a2792
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 4 deletions.
1 change: 1 addition & 0 deletions komorebi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
5 changes: 4 additions & 1 deletion komorebi/src/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand Down
30 changes: 27 additions & 3 deletions komorebi/src/window_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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");

Expand Down Expand Up @@ -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");

Expand All @@ -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<Workspace> {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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))]
Expand Down

0 comments on commit 50a2792

Please sign in to comment.