Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(windows): fix set_size doing nothing for undecorated window with shadows #1039

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading