Skip to content

Commit

Permalink
fix(windows): remove WS_CAPTION and WS_THICKFRAME when calculatin…
Browse files Browse the repository at this point in the history
…g adjust window rect (#1017)

closes tauri-apps/tauri#11695
  • Loading branch information
amrbashir authored Nov 20, 2024
1 parent 720bd93 commit 5d6d7da
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changes/adjusted-rect.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"tao": "patch"
---

On Windows, fix regression caused undecorated window with shadows to be slightly larger on creation.
17 changes: 16 additions & 1 deletion src/platform_impl/windows/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1213,8 +1213,23 @@ unsafe fn init<T: 'static>(
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)
};

Expand Down
11 changes: 11 additions & 0 deletions src/platform_impl/windows/window_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 5d6d7da

Please sign in to comment.