Skip to content

Commit 4c0c760

Browse files
committed
fix size overflow when window is undecorated
1 parent 349acfa commit 4c0c760

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

src/platform_impl/windows/event_loop/runner.rs

+1
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,7 @@ impl<T> BufferedEvent<T> {
436436
(window_id.0).0,
437437
new_inner_size.width as _,
438438
new_inner_size.height as _,
439+
false,
439440
);
440441
}
441442
}

src/platform_impl/windows/util.rs

+10-2
Original file line numberDiff line numberDiff line change
@@ -88,14 +88,22 @@ pub fn adjust_size(hwnd: HWND, size: PhysicalSize<u32>) -> PhysicalSize<u32> {
8888
PhysicalSize::new((rect.right - rect.left) as _, (rect.bottom - rect.top) as _)
8989
}
9090

91-
pub(crate) fn set_inner_size_physical(window: HWND, x: u32, y: u32) {
91+
pub(crate) fn set_inner_size_physical(window: HWND, x: u32, y: u32, is_decorated: bool) {
9292
unsafe {
93+
let dpi = hwnd_dpi(window);
94+
let titlebar_height = if !is_decorated {
95+
winuser::GetSystemMetricsForDpi(winuser::SM_CYSIZE, dpi)
96+
+ winuser::GetSystemMetricsForDpi(winuser::SM_CXPADDEDBORDER, dpi) * 2
97+
+ winuser::GetSystemMetricsForDpi(winuser::SM_CYBORDER, dpi)
98+
} else {
99+
0
100+
};
93101
let rect = adjust_window_rect(
94102
window,
95103
RECT {
96104
top: 0,
97105
left: 0,
98-
bottom: y as LONG,
106+
bottom: (y - titlebar_height as u32) as LONG,
99107
right: x as LONG,
100108
},
101109
)

src/platform_impl/windows/window.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,10 @@ impl Window {
180180
pub fn set_inner_size(&self, size: Size) {
181181
let scale_factor = self.scale_factor();
182182
let (width, height) = size.to_physical::<u32>(scale_factor).into();
183+
let is_decorated = {
184+
let window_flags = Arc::clone(&self.window_state).lock().window_flags;
185+
window_flags.contains(WindowFlags::DECORATIONS)
186+
};
183187

184188
let window_state = Arc::clone(&self.window_state);
185189
let window = self.window.clone();
@@ -189,7 +193,7 @@ impl Window {
189193
});
190194
});
191195

192-
util::set_inner_size_physical(self.window.0, width, height);
196+
util::set_inner_size_physical(self.window.0, width, height, is_decorated);
193197
}
194198

195199
#[inline]

0 commit comments

Comments
 (0)