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 Window::inner_size returns slightly larger than what's visible #993

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
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-inner-size-slightly-larger.md
Original file line number Diff line number Diff line change
@@ -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.
2 changes: 2 additions & 0 deletions src/platform_impl/windows/event_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2126,6 +2126,8 @@ unsafe fn public_window_callback_inner<T: 'static>(
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
}
Expand Down
32 changes: 28 additions & 4 deletions src/platform_impl/windows/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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
}
Expand Down
Loading