diff --git a/.changes/regression-window-set-sinner-size.md b/.changes/regression-window-set-sinner-size.md new file mode 100644 index 000000000..fd688323b --- /dev/null +++ b/.changes/regression-window-set-sinner-size.md @@ -0,0 +1,6 @@ +--- +"tao": "patch" +--- + +On Windows, fix `Window::set_inner_size` regression not handling borders correctly for undecorated window with shadows. + diff --git a/.changes/regression-window-sinner-size.md b/.changes/regression-window-sinner-size.md new file mode 100644 index 000000000..39482265d --- /dev/null +++ b/.changes/regression-window-sinner-size.md @@ -0,0 +1,6 @@ +--- +"tao": "patch" +--- + +On Windows, fix `Window::inner_size` regression returning incorrect size for window with decorations. + diff --git a/src/platform_impl/windows/util.rs b/src/platform_impl/windows/util.rs index 96879c0c7..e24504b2d 100644 --- a/src/platform_impl/windows/util.rs +++ b/src/platform_impl/windows/util.rs @@ -95,15 +95,15 @@ pub fn adjust_size(hwnd: HWND, size: PhysicalSize, is_decorated: bool) -> P PhysicalSize::new((rect.right - rect.left) as _, (rect.bottom - rect.top) as _) } -pub(crate) fn set_inner_size_physical(window: HWND, x: u32, y: u32, is_decorated: bool) { +pub(crate) fn set_inner_size_physical(window: HWND, x: i32, y: i32, is_decorated: bool) { unsafe { let rect = adjust_window_rect( window, RECT { top: 0, left: 0, - bottom: y as i32, - right: x as i32, + bottom: y, + right: x, }, is_decorated, ) diff --git a/src/platform_impl/windows/window.rs b/src/platform_impl/windows/window.rs index 271989034..46c78e541 100644 --- a/src/platform_impl/windows/window.rs +++ b/src/platform_impl/windows/window.rs @@ -248,11 +248,10 @@ impl Window { let mut width = rect.right - rect.left; let mut height = rect.bottom - rect.top; - let window_state = self.window_state.lock(); + let window_flags = self.window_state.lock().window_flags(); - if window_state - .window_flags - .contains(WindowFlags::MARKER_UNDECORATED_SHADOW) + if window_flags.contains(WindowFlags::MARKER_UNDECORATED_SHADOW) + && !window_flags.contains(WindowFlags::MARKER_DECORATIONS) { let mut pt: POINT = unsafe { mem::zeroed() }; if unsafe { ClientToScreen(self.hwnd(), &mut pt) }.as_bool() == true { @@ -287,14 +286,29 @@ impl Window { #[inline] pub fn set_inner_size(&self, size: Size) { let scale_factor = self.scale_factor(); - let (width, height) = size.to_physical::(scale_factor).into(); + let (mut width, mut height) = size.to_physical::(scale_factor).into(); let window_state = Arc::clone(&self.window_state); - let is_decorated = window_state - .lock() - .window_flags - .contains(WindowFlags::MARKER_DECORATIONS); + let window_flags = self.window_state.lock().window_flags(); + + let is_decorated = window_flags.contains(WindowFlags::MARKER_DECORATIONS); + + if window_flags.contains(WindowFlags::MARKER_UNDECORATED_SHADOW) && !is_decorated { + let mut pt: POINT = unsafe { mem::zeroed() }; + 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 window = self.window.0 .0 as isize; self.thread_executor.execute_in_thread(move || {