Skip to content

Commit

Permalink
perf(wm): compare rects before position updates
Browse files Browse the repository at this point in the history
This commit ensures that both windows and borders will make a comparison
to the current values returned by WindowRect before attempting to make
update calls to SetWindowPos. This should greatly reduce visual
flickering in both the borders and sensitive apps like JetBrains IDEs.
  • Loading branch information
LGUG2Z committed May 13, 2024
1 parent 0d074db commit 54c58be
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
6 changes: 4 additions & 2 deletions komorebi/src/border_manager/border.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,10 @@ impl Border {
rects.insert(self.hwnd, rect);
}

// Update the position of the border
WindowsApi::set_border_pos(self.hwnd(), &rect, HWND((*Z_ORDER.lock()).into()))?;
// Update the position of the border if required
if !WindowsApi::window_rect(self.hwnd())?.eq(&rect) {
WindowsApi::set_border_pos(self.hwnd(), &rect, HWND((*Z_ORDER.lock()).into()))?;
}

// Invalidate the rect to trigger the callback to update colours etc.
self.invalidate();
Expand Down
4 changes: 4 additions & 0 deletions komorebi/src/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,10 @@ impl Window {
}

pub fn set_position(&self, layout: &Rect, top: bool) -> Result<()> {
if WindowsApi::window_rect(self.hwnd())?.eq(layout) {
return Ok(());
}

let rect = *layout;
WindowsApi::position_window(self.hwnd(), &rect, top)
}
Expand Down

0 comments on commit 54c58be

Please sign in to comment.