Skip to content

Commit

Permalink
fix size overflow when window is undecorated
Browse files Browse the repository at this point in the history
  • Loading branch information
amrbashir committed Mar 2, 2022
1 parent 349acfa commit 4c0c760
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/platform_impl/windows/event_loop/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,7 @@ impl<T> BufferedEvent<T> {
(window_id.0).0,
new_inner_size.width as _,
new_inner_size.height as _,
false,
);
}
}
Expand Down
12 changes: 10 additions & 2 deletions src/platform_impl/windows/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,22 @@ pub fn adjust_size(hwnd: HWND, size: PhysicalSize<u32>) -> PhysicalSize<u32> {
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) {
pub(crate) fn set_inner_size_physical(window: HWND, x: u32, y: u32, is_decorated: bool) {
unsafe {
let dpi = hwnd_dpi(window);
let titlebar_height = if !is_decorated {
winuser::GetSystemMetricsForDpi(winuser::SM_CYSIZE, dpi)
+ winuser::GetSystemMetricsForDpi(winuser::SM_CXPADDEDBORDER, dpi) * 2
+ winuser::GetSystemMetricsForDpi(winuser::SM_CYBORDER, dpi)
} else {
0
};
let rect = adjust_window_rect(
window,
RECT {
top: 0,
left: 0,
bottom: y as LONG,
bottom: (y - titlebar_height as u32) as LONG,
right: x as LONG,
},
)
Expand Down
6 changes: 5 additions & 1 deletion src/platform_impl/windows/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,10 @@ impl Window {
pub fn set_inner_size(&self, size: Size) {
let scale_factor = self.scale_factor();
let (width, height) = size.to_physical::<u32>(scale_factor).into();
let is_decorated = {
let window_flags = Arc::clone(&self.window_state).lock().window_flags;
window_flags.contains(WindowFlags::DECORATIONS)
};

let window_state = Arc::clone(&self.window_state);
let window = self.window.clone();
Expand All @@ -189,7 +193,7 @@ impl Window {
});
});

util::set_inner_size_physical(self.window.0, width, height);
util::set_inner_size_physical(self.window.0, width, height, is_decorated);
}

#[inline]
Expand Down

0 comments on commit 4c0c760

Please sign in to comment.