diff --git a/.changes/windows-inner-size-slightly-larger.md b/.changes/windows-inner-size-slightly-larger.md new file mode 100644 index 000000000..e052f0dcf --- /dev/null +++ b/.changes/windows-inner-size-slightly-larger.md @@ -0,0 +1,5 @@ +--- +"tao": "patch" +--- + +On Windows, fix `Window::inner_size` returns slightly larger than what's visible for undecorated windows but have shadows. \ No newline at end of file diff --git a/src/platform_impl/windows/event_loop.rs b/src/platform_impl/windows/event_loop.rs index 5b9d4db59..1a01825ed 100644 --- a/src/platform_impl/windows/event_loop.rs +++ b/src/platform_impl/windows/event_loop.rs @@ -2126,6 +2126,8 @@ unsafe fn public_window_callback_inner( let params = &mut *(lparam.0 as *mut NCCALCSIZE_PARAMS); params.rgrc[0].top += 1; params.rgrc[0].bottom += 1; + params.rgrc[0].left += 1; + params.rgrc[0].right += 1; } result = ProcResult::Value(LRESULT(0)); // return 0 here to make the window borderless } diff --git a/src/platform_impl/windows/window.rs b/src/platform_impl/windows/window.rs index 31ec275ea..8172cb538 100644 --- a/src/platform_impl/windows/window.rs +++ b/src/platform_impl/windows/window.rs @@ -244,10 +244,32 @@ impl Window { if unsafe { GetClientRect(self.window.0, &mut rect) }.is_err() { panic!("Unexpected GetClientRect failure") } - PhysicalSize::new( - (rect.right - rect.left) as u32, - (rect.bottom - rect.top) as u32, - ) + + let mut width = rect.right - rect.left; + let mut height = rect.bottom - rect.top; + + let window_state = self.window_state.lock(); + + if window_state + .window_flags + .contains(WindowFlags::MARKER_UNDECORATED_SHADOW) + { + 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; + } + } + } + + PhysicalSize::new(width as u32, height as u32) } #[inline] @@ -1287,6 +1309,8 @@ unsafe extern "system" fn window_proc( let params = &mut *(lparam.0 as *mut NCCALCSIZE_PARAMS); params.rgrc[0].top += 1; params.rgrc[0].bottom += 1; + params.rgrc[0].left += 1; + params.rgrc[0].right += 1; } return LRESULT(0); // return 0 here to make the window borderless }