From bb537fe9969e490b74548738f16173d5b9d84c63 Mon Sep 17 00:00:00 2001 From: Amr Bashir Date: Sat, 4 Jan 2025 17:20:20 +0200 Subject: [PATCH] fix(windows): fix set_size doing nothing for undecorated window with shadows (#1039) closes tauri-apps/tauri#12168 --- .../windows-set-size-undecorated-window.md | 5 ++++ src/platform_impl/windows/window.rs | 24 ++++++++++++------- 2 files changed, 20 insertions(+), 9 deletions(-) create mode 100644 .changes/windows-set-size-undecorated-window.md diff --git a/.changes/windows-set-size-undecorated-window.md b/.changes/windows-set-size-undecorated-window.md new file mode 100644 index 000000000..d25a934ce --- /dev/null +++ b/.changes/windows-set-size-undecorated-window.md @@ -0,0 +1,5 @@ +--- +"tao": "patch" +--- + +On Windows, fix regression that caused `Window::set_size` to have no effect at all for undecorated window with shadows. \ No newline at end of file diff --git a/src/platform_impl/windows/window.rs b/src/platform_impl/windows/window.rs index 7e2dabd29..e53837387 100644 --- a/src/platform_impl/windows/window.rs +++ b/src/platform_impl/windows/window.rs @@ -287,7 +287,7 @@ impl Window { #[inline] pub fn set_inner_size(&self, size: Size) { let scale_factor = self.scale_factor(); - let (mut width, mut height) = size.to_physical::(scale_factor).into(); + let (mut desired_width, mut desired_height) = size.to_physical::(scale_factor).into(); let window_state = Arc::clone(&self.window_state); @@ -300,13 +300,19 @@ impl Window { if unsafe { ClientToScreen(self.hwnd(), &mut pt) }.as_bool() == true { let mut window_rc: RECT = unsafe { mem::zeroed() }; if unsafe { GetWindowRect(self.hwnd(), &mut window_rc) }.is_ok() { - let left_b = pt.x - window_rc.left; - let right_b = pt.x + width - window_rc.right; - let top_b = pt.y - window_rc.top; - let bottom_b = pt.y + height - window_rc.bottom; - - width = width + (left_b - right_b); - height = height + (top_b - bottom_b); + let mut client_rc: RECT = unsafe { mem::zeroed() }; + if unsafe { GetClientRect(self.hwnd(), &mut client_rc) }.is_ok() { + let curr_width = client_rc.right - client_rc.left; + let curr_height = client_rc.bottom - client_rc.top; + + let left_b = pt.x - window_rc.left; + let right_b: i32 = (pt.x + curr_width) - window_rc.right; + let top_b = pt.y - window_rc.top; + let bottom_b: i32 = (pt.y + curr_height) - window_rc.bottom; + + desired_width = desired_width + left_b + right_b.abs(); + desired_height = desired_height + top_b + bottom_b.abs(); + } } } } @@ -318,7 +324,7 @@ impl Window { }); }); - util::set_inner_size_physical(self.window.0, width, height, is_decorated); + util::set_inner_size_physical(self.window.0, desired_width, desired_height, is_decorated); } #[inline]