Skip to content

Commit

Permalink
fix(windows): fix regression in setting/getting inner size (#1007)
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
amrbashir authored Nov 11, 2024
1 parent 0274b0f commit 9738223
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 12 deletions.
6 changes: 6 additions & 0 deletions .changes/regression-window-set-sinner-size.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"tao": "patch"
---

On Windows, fix `Window::set_inner_size` regression not handling borders correctly for undecorated window with shadows.

6 changes: 6 additions & 0 deletions .changes/regression-window-sinner-size.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"tao": "patch"
---

On Windows, fix `Window::inner_size` regression returning incorrect size for window with decorations.

6 changes: 3 additions & 3 deletions src/platform_impl/windows/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,15 +95,15 @@ pub fn adjust_size(hwnd: HWND, size: PhysicalSize<u32>, is_decorated: bool) -> P
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, is_decorated: bool) {
pub(crate) fn set_inner_size_physical(window: HWND, x: i32, y: i32, is_decorated: bool) {
unsafe {
let rect = adjust_window_rect(
window,
RECT {
top: 0,
left: 0,
bottom: y as i32,
right: x as i32,
bottom: y,
right: x,
},
is_decorated,
)
Expand Down
32 changes: 23 additions & 9 deletions src/platform_impl/windows/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,11 +248,10 @@ impl Window {
let mut width = rect.right - rect.left;
let mut height = rect.bottom - rect.top;

let window_state = self.window_state.lock();
let window_flags = self.window_state.lock().window_flags();

if window_state
.window_flags
.contains(WindowFlags::MARKER_UNDECORATED_SHADOW)
if window_flags.contains(WindowFlags::MARKER_UNDECORATED_SHADOW)
&& !window_flags.contains(WindowFlags::MARKER_DECORATIONS)
{
let mut pt: POINT = unsafe { mem::zeroed() };
if unsafe { ClientToScreen(self.hwnd(), &mut pt) }.as_bool() == true {
Expand Down Expand Up @@ -287,14 +286,29 @@ impl Window {
#[inline]
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 (mut width, mut height) = size.to_physical::<i32>(scale_factor).into();

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

let is_decorated = window_state
.lock()
.window_flags
.contains(WindowFlags::MARKER_DECORATIONS);
let window_flags = self.window_state.lock().window_flags();

let is_decorated = window_flags.contains(WindowFlags::MARKER_DECORATIONS);

if window_flags.contains(WindowFlags::MARKER_UNDECORATED_SHADOW) && !is_decorated {
let mut pt: POINT = unsafe { mem::zeroed() };
if unsafe { ClientToScreen(self.hwnd(), &mut pt) }.as_bool() == true {
let mut window_rc: RECT = unsafe { mem::zeroed() };
if unsafe { GetWindowRect(self.hwnd(), &mut window_rc) }.is_ok() {
let left_b = pt.x - window_rc.left;
let right_b = pt.x + width - window_rc.right;
let top_b = pt.y - window_rc.top;
let bottom_b = pt.y + height - window_rc.bottom;

width = width + (left_b - right_b);
height = height + (top_b - bottom_b);
}
}
}

let window = self.window.0 .0 as isize;
self.thread_executor.execute_in_thread(move || {
Expand Down

0 comments on commit 9738223

Please sign in to comment.