Skip to content

Commit ba65486

Browse files
fix(windows): initial position sets to 0 (#1107)
1 parent 4a08505 commit ba65486

File tree

4 files changed

+27
-5
lines changed

4 files changed

+27
-5
lines changed

.changes/nagative-initial-position.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
tao: patch
3+
---
4+
5+
Fix initial position gets reset to 0 on Windows if it's accounted for the shadow

src/platform_impl/windows/monitor.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,11 @@ impl MonitorHandle {
217217

218218
#[inline]
219219
pub fn scale_factor(&self) -> f64 {
220-
dpi_to_scale_factor(get_monitor_dpi(self.hmonitor()).unwrap_or(USER_DEFAULT_SCREEN_DPI))
220+
dpi_to_scale_factor(self.dpi())
221+
}
222+
223+
pub fn dpi(&self) -> u32 {
224+
get_monitor_dpi(self.hmonitor()).unwrap_or(USER_DEFAULT_SCREEN_DPI)
221225
}
222226

223227
#[inline]

src/platform_impl/windows/window.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ use crate::{
5757
};
5858

5959
use super::{
60-
dpi::get_monitor_dpi,
6160
event_loop::CHANGE_THEME_MSG_ID,
6261
keyboard::{KeyEventBuilder, KEY_EVENT_BUILDERS},
6362
util::calculate_insets_for_dpi,
@@ -1165,11 +1164,20 @@ unsafe fn init<T: 'static>(
11651164
monitor::available_monitors()
11661165
.into_iter()
11671166
.find_map(|monitor| {
1168-
let position = p.to_physical::<i32>(monitor.scale_factor());
1167+
let dpi = monitor.dpi();
1168+
let scale_factor = dpi_to_scale_factor(dpi);
1169+
let position = p.to_physical::<i32>(scale_factor);
11691170
let (x, y): (i32, i32) = monitor.position().into();
11701171
let (width, height): (i32, i32) = monitor.size().into();
11711172

1172-
if x <= position.x
1173+
let frame_thickness = if window_flags.contains_shadow() {
1174+
util::get_frame_thickness(dpi)
1175+
} else {
1176+
0
1177+
};
1178+
1179+
// Only the starting position x needs to be accounted
1180+
if x <= position.x + frame_thickness
11731181
&& position.x <= x + width
11741182
&& y <= position.y
11751183
&& position.y <= y + height
@@ -1215,7 +1223,7 @@ unsafe fn init<T: 'static>(
12151223
w = rect.right - rect.left;
12161224
h = rect.bottom - rect.top;
12171225
} else if window_flags.undecorated_with_shadows() {
1218-
let dpi = get_monitor_dpi(target_monitor.hmonitor()).unwrap_or(USER_DEFAULT_SCREEN_DPI);
1226+
let dpi = target_monitor.dpi();
12191227
let insets = calculate_insets_for_dpi(dpi);
12201228
w += insets.left + insets.right;
12211229
h += insets.top + insets.bottom;

src/platform_impl/windows/window_state.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,11 @@ impl WindowFlags {
462462
self.contains(WindowFlags::MARKER_UNDECORATED_SHADOW)
463463
&& !self.contains(WindowFlags::MARKER_DECORATIONS)
464464
}
465+
466+
pub fn contains_shadow(&self) -> bool {
467+
self.contains(WindowFlags::MARKER_UNDECORATED_SHADOW)
468+
|| self.contains(WindowFlags::MARKER_DECORATIONS)
469+
}
465470
}
466471

467472
impl CursorFlags {

0 commit comments

Comments
 (0)