Skip to content

Commit

Permalink
fix(animation): added pending cancel count to track is_cancelled state
Browse files Browse the repository at this point in the history
  • Loading branch information
thearturca committed Aug 1, 2024
1 parent 84ad947 commit 9350792
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 2 additions & 0 deletions komorebi/src/animation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,8 @@ impl Animation {

let latest_cancel_idx = ANIMATION_MANAGER.lock().latest_cancel_idx(self.hwnd);

ANIMATION_MANAGER.lock().end_cancel(self.hwnd);

latest_cancel_idx == cancel_idx
}

Expand Down
13 changes: 12 additions & 1 deletion komorebi/src/animation_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ pub static ANIMATIONS_IN_PROGRESS: AtomicUsize = AtomicUsize::new(0);
struct AnimationState {
pub in_progress: bool,
pub cancel_idx_counter: usize,
pub pending_cancel_count: usize,
}

#[derive(Debug)]
Expand All @@ -31,7 +32,7 @@ impl AnimationManager {

pub fn is_cancelled(&self, hwnd: isize) -> bool {
if let Some(animation_state) = self.animations.get(&hwnd) {
animation_state.cancel_idx_counter > 0
animation_state.pending_cancel_count > 0
} else {
false
}
Expand All @@ -47,7 +48,10 @@ impl AnimationManager {

pub fn init_cancel(&mut self, hwnd: isize) -> usize {
if let Some(animation_state) = self.animations.get_mut(&hwnd) {
animation_state.pending_cancel_count += 1;
animation_state.cancel_idx_counter += 1;

// return cancel idx
animation_state.cancel_idx_counter
} else {
0
Expand All @@ -62,6 +66,12 @@ impl AnimationManager {
}
}

pub fn end_cancel(&mut self, hwnd: isize) {
if let Some(animation_state) = self.animations.get_mut(&hwnd) {
animation_state.pending_cancel_count -= 1;
}
}

pub fn cancel(&mut self, hwnd: isize) {
if let Some(animation_state) = self.animations.get_mut(&hwnd) {
animation_state.in_progress = false;
Expand All @@ -73,6 +83,7 @@ impl AnimationManager {
e.insert(AnimationState {
in_progress: true,
cancel_idx_counter: 0,
pending_cancel_count: 0,
});

ANIMATIONS_IN_PROGRESS.store(self.animations.len(), Ordering::Release);
Expand Down

0 comments on commit 9350792

Please sign in to comment.