fix: center window ignores scale factors (#8942)

* fix: center window ignores scale factors

* chore: add .changes

* clippy
This commit is contained in:
Philipp Bokatius 2024-02-22 15:30:27 +01:00 committed by GitHub
parent fdcaf935fa
commit 6e3bd4b9f8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 12 additions and 6 deletions

View File

@ -0,0 +1,5 @@
---
"tauri-runtime-wry": patch:bug
---
Fix window centering not taking monitor scale into account

View File

@ -3354,16 +3354,17 @@ fn create_window<T: UserEvent, F: Fn(RawWindow) + Send + 'static>(
.window
.inner_size
.unwrap_or_else(|| TaoPhysicalSize::new(800, 600).into());
let scale_factor = monitor.scale_factor();
let window_size = window_builder
.inner
.window
.inner_size_constraints
.clamp(desired_size, monitor.scale_factor())
.to_logical::<i32>(monitor.scale_factor());
let screen_size = monitor.size();
let monitor_pos = monitor.position();
let x = (screen_size.width as i32 - window_size.width) / 2 + monitor_pos.x;
let y = (screen_size.height as i32 - window_size.height) / 2 + monitor_pos.y;
.clamp(desired_size, scale_factor)
.to_logical::<i32>(scale_factor);
let screen_size = monitor.size().to_logical::<i32>(scale_factor);
let monitor_pos = monitor.position().to_logical::<i32>(scale_factor);
let x = (screen_size.width - window_size.width) / 2 + monitor_pos.x;
let y = (screen_size.height - window_size.height) / 2 + monitor_pos.y;
window_builder = window_builder.position(x as f64, y as f64);
}