diff --git a/.changes/adjusted-rect.md b/.changes/adjusted-rect.md new file mode 100644 index 000000000..fa7757d90 --- /dev/null +++ b/.changes/adjusted-rect.md @@ -0,0 +1,5 @@ +--- +"tao": "patch" +--- + +On Windows, fix regression caused undecorated window with shadows to be slightly larger on creation. \ No newline at end of file diff --git a/src/platform_impl/windows/window.rs b/src/platform_impl/windows/window.rs index c571716cc..7e2dabd29 100644 --- a/src/platform_impl/windows/window.rs +++ b/src/platform_impl/windows/window.rs @@ -1213,8 +1213,23 @@ unsafe fn init( bottom: h, }; unsafe { - AdjustWindowRectEx(&mut rect, style, pl_attribs.menu.is_some(), ex_style)?; + AdjustWindowRectEx( + &mut rect, + window_flags.to_adjusted_window_styles().0, + pl_attribs.menu.is_some(), + ex_style, + )?; } + + // account for the 1px we add on each side in WM_NCCALCSIZE + // to add shadow for undecorated windows + if window_flags.contains(WindowFlags::MARKER_UNDECORATED_SHADOW) + && !window_flags.contains(WindowFlags::MARKER_DECORATIONS) + { + rect.right += 2; + rect.bottom += 2; + } + (rect.right - rect.left, rect.bottom - rect.top) }; diff --git a/src/platform_impl/windows/window_state.rs b/src/platform_impl/windows/window_state.rs index 00d558d1d..2e14348eb 100644 --- a/src/platform_impl/windows/window_state.rs +++ b/src/platform_impl/windows/window_state.rs @@ -295,6 +295,17 @@ impl WindowFlags { (style, style_ex) } + /// Returns the appropriate window styles for `AdjustWindowRectEx` + pub fn to_adjusted_window_styles(self) -> (WINDOW_STYLE, WINDOW_EX_STYLE) { + let (mut style, style_ex) = self.to_window_styles(); + + if !self.contains(WindowFlags::MARKER_DECORATIONS) { + style &= !(WS_CAPTION | WS_THICKFRAME) + } + + (style, style_ex) + } + /// Adjust the window client rectangle to the return value, if present. fn apply_diff(mut self, window: HWND, mut new: WindowFlags) { self = self.mask();