From 70ef90b3044ba4535e6ed503a57caccf426385ef Mon Sep 17 00:00:00 2001 From: LGUG2Z Date: Mon, 13 May 2024 08:44:27 -0700 Subject: [PATCH] perf(wm): compare rects before position updates 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. --- komorebi/src/border_manager/border.rs | 6 ++++-- komorebi/src/window.rs | 4 ++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/komorebi/src/border_manager/border.rs b/komorebi/src/border_manager/border.rs index 46c7c5e9..882a44be 100644 --- a/komorebi/src/border_manager/border.rs +++ b/komorebi/src/border_manager/border.rs @@ -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(); diff --git a/komorebi/src/window.rs b/komorebi/src/window.rs index 6e8787ff..14273550 100644 --- a/komorebi/src/window.rs +++ b/komorebi/src/window.rs @@ -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) }