Skip to content

Commit

Permalink
fix(windows): fix set_size doing nothing for undecorated window with …
Browse files Browse the repository at this point in the history
…shadows (#1039)

closes tauri-apps/tauri#12168
  • Loading branch information
amrbashir authored Jan 4, 2025
1 parent 83e35e9 commit bb537fe
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
5 changes: 5 additions & 0 deletions .changes/windows-set-size-undecorated-window.md
Original file line number Diff line number Diff line change
@@ -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.
24 changes: 15 additions & 9 deletions src/platform_impl/windows/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<i32>(scale_factor).into();
let (mut desired_width, mut desired_height) = size.to_physical::<i32>(scale_factor).into();

let window_state = Arc::clone(&self.window_state);

Expand All @@ -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();
}
}
}
}
Expand All @@ -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]
Expand Down

0 comments on commit bb537fe

Please sign in to comment.