mirror of
https://github.com/LGUG2Z/komorebi.git
synced 2026-05-05 02:14:22 +02:00
refactor(animation): reduce mutex call on ANIMATION_STYLE
This commit is contained in:
@@ -13,6 +13,7 @@ use super::style::apply_ease_func;
|
||||
use super::ANIMATION_DURATION;
|
||||
use super::ANIMATION_FPS;
|
||||
use super::ANIMATION_MANAGER;
|
||||
use crate::AnimationStyle;
|
||||
|
||||
#[derive(Debug, Default, Clone, Copy, Serialize, Deserialize, JsonSchema, PartialEq)]
|
||||
pub struct Animation {
|
||||
@@ -53,19 +54,19 @@ impl Animation {
|
||||
}
|
||||
|
||||
#[allow(clippy::cast_possible_truncation)]
|
||||
pub fn lerp(start: i32, end: i32, t: f64) -> i32 {
|
||||
let time = apply_ease_func(t);
|
||||
pub fn lerp(start: i32, end: i32, t: f64, style: AnimationStyle) -> i32 {
|
||||
let time = apply_ease_func(t, style);
|
||||
f64::from(end - start)
|
||||
.mul_add(time, f64::from(start))
|
||||
.round() as i32
|
||||
}
|
||||
|
||||
pub fn lerp_rect(start_rect: &Rect, end_rect: &Rect, t: f64) -> Rect {
|
||||
pub fn lerp_rect(start_rect: &Rect, end_rect: &Rect, t: f64, style: AnimationStyle) -> Rect {
|
||||
Rect {
|
||||
left: Self::lerp(start_rect.left, end_rect.left, t),
|
||||
top: Self::lerp(start_rect.top, end_rect.top, t),
|
||||
right: Self::lerp(start_rect.right, end_rect.right, t),
|
||||
bottom: Self::lerp(start_rect.bottom, end_rect.bottom, t),
|
||||
left: Self::lerp(start_rect.left, end_rect.left, t, style),
|
||||
top: Self::lerp(start_rect.top, end_rect.top, t, style),
|
||||
right: Self::lerp(start_rect.right, end_rect.right, t, style),
|
||||
bottom: Self::lerp(start_rect.bottom, end_rect.bottom, t, style),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
use super::ANIMATION_STYLE;
|
||||
use crate::core::AnimationStyle;
|
||||
|
||||
use std::f64::consts::PI;
|
||||
@@ -356,9 +355,7 @@ impl Ease for EaseInOutBounce {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn apply_ease_func(t: f64) -> f64 {
|
||||
let style = *ANIMATION_STYLE.lock();
|
||||
|
||||
pub fn apply_ease_func(t: f64, style: AnimationStyle) -> f64 {
|
||||
match style {
|
||||
AnimationStyle::Linear => Linear::evaluate(t),
|
||||
AnimationStyle::EaseInSine => EaseInSine::evaluate(t),
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
use crate::animation::ANIMATIONS_IN_PROGRESS;
|
||||
use crate::animation::ANIMATION_DURATION;
|
||||
use crate::animation::ANIMATION_ENABLED;
|
||||
use crate::animation::ANIMATION_STYLE;
|
||||
use crate::border_manager;
|
||||
use crate::com::SetCloak;
|
||||
use crate::focus_manager;
|
||||
@@ -203,8 +204,9 @@ impl Window {
|
||||
pub fn animate_position(&self, start_rect: &Rect, target_rect: &Rect, top: bool) -> Result<()> {
|
||||
let start_rect = *start_rect;
|
||||
let target_rect = *target_rect;
|
||||
let duration = Duration::from_millis(ANIMATION_DURATION.load(Ordering::SeqCst));
|
||||
let mut animation = self.animation;
|
||||
let duration = Duration::from_millis(ANIMATION_DURATION.load(Ordering::SeqCst));
|
||||
let style = *ANIMATION_STYLE.lock();
|
||||
|
||||
border_manager::BORDER_TEMPORARILY_DISABLED.store(true, Ordering::SeqCst);
|
||||
border_manager::send_notification(Some(self.hwnd));
|
||||
@@ -216,7 +218,7 @@ impl Window {
|
||||
|
||||
std::thread::spawn(move || {
|
||||
animation.animate(duration, |progress: f64| {
|
||||
let new_rect = Animation::lerp_rect(&start_rect, &target_rect, progress);
|
||||
let new_rect = Animation::lerp_rect(&start_rect, &target_rect, progress, style);
|
||||
|
||||
if progress == 1.0 {
|
||||
WindowsApi::position_window(hwnd, &new_rect, top)?;
|
||||
|
||||
Reference in New Issue
Block a user