mirror of
https://github.com/LGUG2Z/komorebi.git
synced 2026-07-08 05:55:09 +02:00
refactor(animation): move generation of animation key to RenderDispatcher
This commit is contained in:
@@ -56,11 +56,11 @@ impl Animation {
|
|||||||
|
|
||||||
#[allow(clippy::cast_precision_loss)]
|
#[allow(clippy::cast_precision_loss)]
|
||||||
pub fn animate(
|
pub fn animate(
|
||||||
animation_key: String,
|
|
||||||
duration: Duration,
|
|
||||||
render_dispatcher: (impl RenderDispatcher + Send + 'static),
|
render_dispatcher: (impl RenderDispatcher + Send + 'static),
|
||||||
|
duration: Duration,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
std::thread::spawn(move || {
|
std::thread::spawn(move || {
|
||||||
|
let animation_key = render_dispatcher.get_animation_key();
|
||||||
if ANIMATION_MANAGER.lock().in_progress(animation_key.as_str()) {
|
if ANIMATION_MANAGER.lock().in_progress(animation_key.as_str()) {
|
||||||
let should_animate = Self::cancel(animation_key.as_str());
|
let should_animate = Self::cancel(animation_key.as_str());
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
use color_eyre::Result;
|
use color_eyre::Result;
|
||||||
|
|
||||||
pub trait RenderDispatcher {
|
pub trait RenderDispatcher {
|
||||||
|
fn get_animation_key(&self) -> String;
|
||||||
fn pre_render(&self) -> Result<()>;
|
fn pre_render(&self) -> Result<()>;
|
||||||
fn render(&self, delta: f64) -> Result<()>;
|
fn render(&self, delta: f64) -> Result<()>;
|
||||||
fn post_render(&self) -> Result<()>;
|
fn post_render(&self) -> Result<()>;
|
||||||
|
|||||||
+12
-22
@@ -2,7 +2,6 @@ use crate::animation::lerp::Lerp;
|
|||||||
use crate::animation::prefix::new_animation_key;
|
use crate::animation::prefix::new_animation_key;
|
||||||
use crate::animation::prefix::AnimationPrefix;
|
use crate::animation::prefix::AnimationPrefix;
|
||||||
use crate::animation::RenderDispatcher;
|
use crate::animation::RenderDispatcher;
|
||||||
// use crate::animation::renderer::Renderer;
|
|
||||||
use crate::animation::ANIMATION_DURATION;
|
use crate::animation::ANIMATION_DURATION;
|
||||||
use crate::animation::ANIMATION_ENABLED;
|
use crate::animation::ANIMATION_ENABLED;
|
||||||
use crate::animation::ANIMATION_MANAGER;
|
use crate::animation::ANIMATION_MANAGER;
|
||||||
@@ -185,6 +184,10 @@ impl WindowMoveRenderDispatcher {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl RenderDispatcher for WindowMoveRenderDispatcher {
|
impl RenderDispatcher for WindowMoveRenderDispatcher {
|
||||||
|
fn get_animation_key(&self) -> String {
|
||||||
|
new_animation_key(self.prefix, self.hwnd.to_string())
|
||||||
|
}
|
||||||
|
|
||||||
fn pre_render(&self) -> Result<()> {
|
fn pre_render(&self) -> Result<()> {
|
||||||
border_manager::BORDER_TEMPORARILY_DISABLED.store(true, Ordering::SeqCst);
|
border_manager::BORDER_TEMPORARILY_DISABLED.store(true, Ordering::SeqCst);
|
||||||
border_manager::send_notification(Some(self.hwnd));
|
border_manager::send_notification(Some(self.hwnd));
|
||||||
@@ -232,14 +235,12 @@ struct WindowTransparencyRenderDispatcher {
|
|||||||
target_opacity: u8,
|
target_opacity: u8,
|
||||||
style: AnimationStyle,
|
style: AnimationStyle,
|
||||||
is_opaque: bool,
|
is_opaque: bool,
|
||||||
is_transparent: bool,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl WindowTransparencyRenderDispatcher {
|
impl WindowTransparencyRenderDispatcher {
|
||||||
pub fn new(
|
pub fn new(
|
||||||
hwnd: isize,
|
hwnd: isize,
|
||||||
is_opaque: bool,
|
is_opaque: bool,
|
||||||
is_transparent: bool,
|
|
||||||
start_opacity: u8,
|
start_opacity: u8,
|
||||||
target_opacity: u8,
|
target_opacity: u8,
|
||||||
style: AnimationStyle,
|
style: AnimationStyle,
|
||||||
@@ -251,15 +252,18 @@ impl WindowTransparencyRenderDispatcher {
|
|||||||
target_opacity,
|
target_opacity,
|
||||||
style,
|
style,
|
||||||
is_opaque,
|
is_opaque,
|
||||||
is_transparent,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl RenderDispatcher for WindowTransparencyRenderDispatcher {
|
impl RenderDispatcher for WindowTransparencyRenderDispatcher {
|
||||||
|
fn get_animation_key(&self) -> String {
|
||||||
|
new_animation_key(self.prefix, self.hwnd.to_string())
|
||||||
|
}
|
||||||
|
|
||||||
fn pre_render(&self) -> Result<()> {
|
fn pre_render(&self) -> Result<()> {
|
||||||
//transparent
|
//transparent
|
||||||
if self.is_transparent {
|
if !self.is_opaque {
|
||||||
let window = Window::from(self.hwnd);
|
let window = Window::from(self.hwnd);
|
||||||
let mut ex_style = window.ex_style()?;
|
let mut ex_style = window.ex_style()?;
|
||||||
ex_style.insert(ExtendedWindowStyle::LAYERED);
|
ex_style.insert(ExtendedWindowStyle::LAYERED);
|
||||||
@@ -349,11 +353,7 @@ impl Window {
|
|||||||
let render_dispatcher =
|
let render_dispatcher =
|
||||||
WindowMoveRenderDispatcher::new(self.hwnd, window_rect, *layout, top, style);
|
WindowMoveRenderDispatcher::new(self.hwnd, window_rect, *layout, top, style);
|
||||||
|
|
||||||
Animation::animate(
|
Animation::animate(render_dispatcher, duration)
|
||||||
new_animation_key(render_dispatcher.prefix, self.hwnd.to_string()),
|
|
||||||
duration,
|
|
||||||
render_dispatcher,
|
|
||||||
)
|
|
||||||
} else {
|
} else {
|
||||||
WindowsApi::position_window(self.hwnd, layout, top)
|
WindowsApi::position_window(self.hwnd, layout, top)
|
||||||
}
|
}
|
||||||
@@ -469,17 +469,12 @@ impl Window {
|
|||||||
let render_dispatcher = WindowTransparencyRenderDispatcher::new(
|
let render_dispatcher = WindowTransparencyRenderDispatcher::new(
|
||||||
self.hwnd,
|
self.hwnd,
|
||||||
false,
|
false,
|
||||||
true,
|
|
||||||
WindowsApi::get_transparent(self.hwnd).unwrap_or(255),
|
WindowsApi::get_transparent(self.hwnd).unwrap_or(255),
|
||||||
transparency_manager::TRANSPARENCY_ALPHA.load_consume(),
|
transparency_manager::TRANSPARENCY_ALPHA.load_consume(),
|
||||||
style,
|
style,
|
||||||
);
|
);
|
||||||
|
|
||||||
Animation::animate(
|
Animation::animate(render_dispatcher, duration)
|
||||||
new_animation_key(render_dispatcher.prefix, self.hwnd.to_string()),
|
|
||||||
duration,
|
|
||||||
render_dispatcher,
|
|
||||||
)
|
|
||||||
} else {
|
} else {
|
||||||
let mut ex_style = self.ex_style()?;
|
let mut ex_style = self.ex_style()?;
|
||||||
ex_style.insert(ExtendedWindowStyle::LAYERED);
|
ex_style.insert(ExtendedWindowStyle::LAYERED);
|
||||||
@@ -499,18 +494,13 @@ impl Window {
|
|||||||
let render_dispatcher = WindowTransparencyRenderDispatcher::new(
|
let render_dispatcher = WindowTransparencyRenderDispatcher::new(
|
||||||
self.hwnd,
|
self.hwnd,
|
||||||
true,
|
true,
|
||||||
false,
|
|
||||||
WindowsApi::get_transparent(self.hwnd)
|
WindowsApi::get_transparent(self.hwnd)
|
||||||
.unwrap_or(transparency_manager::TRANSPARENCY_ALPHA.load_consume()),
|
.unwrap_or(transparency_manager::TRANSPARENCY_ALPHA.load_consume()),
|
||||||
255,
|
255,
|
||||||
style,
|
style,
|
||||||
);
|
);
|
||||||
|
|
||||||
Animation::animate(
|
Animation::animate(render_dispatcher, duration)
|
||||||
new_animation_key(render_dispatcher.prefix, self.hwnd.to_string()),
|
|
||||||
duration,
|
|
||||||
render_dispatcher,
|
|
||||||
)
|
|
||||||
} else {
|
} else {
|
||||||
let mut ex_style = self.ex_style()?;
|
let mut ex_style = self.ex_style()?;
|
||||||
ex_style.remove(ExtendedWindowStyle::LAYERED);
|
ex_style.remove(ExtendedWindowStyle::LAYERED);
|
||||||
|
|||||||
Reference in New Issue
Block a user