Skip to content

Commit

Permalink
feat(animation): bring in changes from #597
Browse files Browse the repository at this point in the history
This commit contains all the changes of #597 to make it easier to rebase
with the latest changes on master post-v0.1.21.
  • Loading branch information
LGUG2Z authored and raggi committed Feb 27, 2024
1 parent b6dde25 commit 2b32c12
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 1 deletion.
10 changes: 10 additions & 0 deletions komorebi-core/src/rect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,14 @@ impl Rect {
bottom: (self.bottom * rect_dpi) / system_dpi,
}
}

#[must_use]
pub const fn rect(&self) -> RECT {
RECT {
left: self.left,
top: self.top,
right: self.left + self.right,
bottom: self.top + self.bottom,
}
}
}
2 changes: 1 addition & 1 deletion komorebi/src/process_event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,7 @@ impl WindowManager {
}

if *self.focused_workspace()?.tile() && BORDER_ENABLED.load(Ordering::SeqCst) {
match event {
match &event {
WindowManagerEvent::MoveResizeStart(_, _) => {
let border = Border::from(BORDER_HWND.load(Ordering::SeqCst));
border.hide()?;
Expand Down
2 changes: 2 additions & 0 deletions komorebi/src/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ impl Window {
true,
)
}

pub fn animate_position(&mut self, layout: &Rect, top: bool) -> Result<()> {
let hwnd = self.hwnd();
let curr_rect = WindowsApi::window_rect(hwnd).unwrap();
Expand All @@ -175,6 +176,7 @@ impl Window {
// using MoveWindow because it runs faster than SetWindowPos
// so animation have more fps and feel smoother
WindowsApi::move_window(hwnd, &new_rect, true)?;
WindowsApi::invalidate_rect(hwnd, None, false);
} else {
WindowsApi::position_window(hwnd, &new_rect, top)?;

Expand Down
8 changes: 8 additions & 0 deletions komorebi/src/windows_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use windows::Win32::Foundation::HMODULE;
use windows::Win32::Foundation::HWND;
use windows::Win32::Foundation::LPARAM;
use windows::Win32::Foundation::POINT;
use windows::Win32::Foundation::RECT;
use windows::Win32::Foundation::WPARAM;
use windows::Win32::Graphics::Dwm::DwmGetWindowAttribute;
use windows::Win32::Graphics::Dwm::DwmSetWindowAttribute;
Expand Down Expand Up @@ -966,6 +967,13 @@ impl WindowsApi {
.process()
}

pub fn invalidate_rect(hwnd: HWND, rect: Option<&Rect>, erase: bool) -> bool {
let rect = rect.map(|rect|
&rect.rect() as *const RECT
);
unsafe { InvalidateRect(hwnd, rect, erase) }.as_bool()
}

pub fn invalidate_border_rect() -> Result<()> {
unsafe { InvalidateRect(HWND(BORDER_HWND.load(Ordering::SeqCst)), None, false) }
.ok()
Expand Down

0 comments on commit 2b32c12

Please sign in to comment.