Skip to content

Commit 9738223

Browse files
authored
fix(windows): fix regression in setting/getting inner size (#1007)
- Fix regression for decorated window, remove borders in `inner_size` only for undecorated window with shadows - Add borders when setting inner size for undecorated window with shadows
1 parent 0274b0f commit 9738223

File tree

4 files changed

+38
-12
lines changed

4 files changed

+38
-12
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"tao": "patch"
3+
---
4+
5+
On Windows, fix `Window::set_inner_size` regression not handling borders correctly for undecorated window with shadows.
6+
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"tao": "patch"
3+
---
4+
5+
On Windows, fix `Window::inner_size` regression returning incorrect size for window with decorations.
6+

src/platform_impl/windows/util.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,15 +95,15 @@ pub fn adjust_size(hwnd: HWND, size: PhysicalSize<u32>, is_decorated: bool) -> P
9595
PhysicalSize::new((rect.right - rect.left) as _, (rect.bottom - rect.top) as _)
9696
}
9797

98-
pub(crate) fn set_inner_size_physical(window: HWND, x: u32, y: u32, is_decorated: bool) {
98+
pub(crate) fn set_inner_size_physical(window: HWND, x: i32, y: i32, is_decorated: bool) {
9999
unsafe {
100100
let rect = adjust_window_rect(
101101
window,
102102
RECT {
103103
top: 0,
104104
left: 0,
105-
bottom: y as i32,
106-
right: x as i32,
105+
bottom: y,
106+
right: x,
107107
},
108108
is_decorated,
109109
)

src/platform_impl/windows/window.rs

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -248,11 +248,10 @@ impl Window {
248248
let mut width = rect.right - rect.left;
249249
let mut height = rect.bottom - rect.top;
250250

251-
let window_state = self.window_state.lock();
251+
let window_flags = self.window_state.lock().window_flags();
252252

253-
if window_state
254-
.window_flags
255-
.contains(WindowFlags::MARKER_UNDECORATED_SHADOW)
253+
if window_flags.contains(WindowFlags::MARKER_UNDECORATED_SHADOW)
254+
&& !window_flags.contains(WindowFlags::MARKER_DECORATIONS)
256255
{
257256
let mut pt: POINT = unsafe { mem::zeroed() };
258257
if unsafe { ClientToScreen(self.hwnd(), &mut pt) }.as_bool() == true {
@@ -287,14 +286,29 @@ impl Window {
287286
#[inline]
288287
pub fn set_inner_size(&self, size: Size) {
289288
let scale_factor = self.scale_factor();
290-
let (width, height) = size.to_physical::<u32>(scale_factor).into();
289+
let (mut width, mut height) = size.to_physical::<i32>(scale_factor).into();
291290

292291
let window_state = Arc::clone(&self.window_state);
293292

294-
let is_decorated = window_state
295-
.lock()
296-
.window_flags
297-
.contains(WindowFlags::MARKER_DECORATIONS);
293+
let window_flags = self.window_state.lock().window_flags();
294+
295+
let is_decorated = window_flags.contains(WindowFlags::MARKER_DECORATIONS);
296+
297+
if window_flags.contains(WindowFlags::MARKER_UNDECORATED_SHADOW) && !is_decorated {
298+
let mut pt: POINT = unsafe { mem::zeroed() };
299+
if unsafe { ClientToScreen(self.hwnd(), &mut pt) }.as_bool() == true {
300+
let mut window_rc: RECT = unsafe { mem::zeroed() };
301+
if unsafe { GetWindowRect(self.hwnd(), &mut window_rc) }.is_ok() {
302+
let left_b = pt.x - window_rc.left;
303+
let right_b = pt.x + width - window_rc.right;
304+
let top_b = pt.y - window_rc.top;
305+
let bottom_b = pt.y + height - window_rc.bottom;
306+
307+
width = width + (left_b - right_b);
308+
height = height + (top_b - bottom_b);
309+
}
310+
}
311+
}
298312

299313
let window = self.window.0 .0 as isize;
300314
self.thread_executor.execute_in_thread(move || {

0 commit comments

Comments
 (0)