Skip to content

Commit

Permalink
fix(core/windows): scale positions when hittesting for undecorated re…
Browse files Browse the repository at this point in the history
…sizing

closes #9464
  • Loading branch information
amrbashir committed Apr 25, 2024
1 parent 98101cb commit 4e73b91
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 5 deletions.
7 changes: 7 additions & 0 deletions .changes/undecorated-resizing-windows-non-100-scale.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"tauri": "patch:bug"
"tauri-runtime-wry": "patch"
---

Fixed undecorated window resizing on Windows when using display scale higher than 100%

31 changes: 26 additions & 5 deletions core/tauri-runtime-wry/src/undecorated_resizing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,10 @@ fn hit_test(
mod windows {
use super::{hit_test, HitTestResult};

use tao::window::{CursorIcon, ResizeDirection, Window};
use tao::{
dpi::LogicalPosition,
window::{CursorIcon, ResizeDirection, Window},
};
use windows::Win32::UI::WindowsAndMessaging::{
GetSystemMetrics, SM_CXFRAME, SM_CXPADDEDBORDER, SM_CYFRAME,
};
Expand Down Expand Up @@ -165,12 +168,21 @@ mod windows {
&& !window.is_window_fullscreen
{
let (x, y) = args.split_once(',').unwrap();
let (x, y) = (x.parse().unwrap(), y.parse().unwrap());
let (x, y): (i32, i32) = (x.parse().unwrap(), y.parse().unwrap());
let postion = LogicalPosition::new(x, y).to_physical::<i32>(w.scale_factor());
let size = w.inner_size();
let padded_border = unsafe { GetSystemMetrics(SM_CXPADDEDBORDER) };
let border_x = unsafe { GetSystemMetrics(SM_CXFRAME) + padded_border };
let border_y = unsafe { GetSystemMetrics(SM_CYFRAME) + padded_border };
hit_test(size.width, size.height, x, y, border_x, border_y).change_cursor(w);
hit_test(
size.width,
size.height,
postion.x,
postion.y,
border_x,
border_y,
)
.change_cursor(w);
}
}
}
Expand All @@ -186,12 +198,21 @@ mod windows {
&& !window.is_window_fullscreen
{
let (x, y) = args.split_once(',').unwrap();
let (x, y) = (x.parse().unwrap(), y.parse().unwrap());
let (x, y): (i32, i32) = (x.parse().unwrap(), y.parse().unwrap());
let postion = LogicalPosition::new(x, y).to_physical::<i32>(w.scale_factor());
let size = w.inner_size();
let padded_border = unsafe { GetSystemMetrics(SM_CXPADDEDBORDER) };
let border_x = unsafe { GetSystemMetrics(SM_CXFRAME) + padded_border };
let border_y = unsafe { GetSystemMetrics(SM_CYFRAME) + padded_border };
hit_test(size.width, size.height, x, y, border_x, border_y).drag_resize_window(w);
hit_test(
size.width,
size.height,
postion.x,
postion.y,
border_x,
border_y,
)
.drag_resize_window(w);
}
}
}
Expand Down

0 comments on commit 4e73b91

Please sign in to comment.