Bladeren bron

fix(core): account for monitor position when centering window (#4166)

Lucas Fernandes Nogueira 3 jaren geleden
bovenliggende
commit
a7a9fde16f
2 gewijzigde bestanden met toevoegingen van 11 en 1 verwijderingen
  1. 6 0
      .changes/fix-center-window.md
  2. 5 1
      core/tauri-runtime-wry/src/lib.rs

+ 6 - 0
.changes/fix-center-window.md

@@ -0,0 +1,6 @@
+---
+"tauri": patch
+"tauri-runtime-wry": patch
+---
+
+Account the monitor position when centering a window.

+ 5 - 1
core/tauri-runtime-wry/src/lib.rs

@@ -2854,9 +2854,13 @@ fn on_window_close(
 fn center_window(window: &Window, window_size: WryPhysicalSize<u32>) -> Result<()> {
   if let Some(monitor) = window.current_monitor() {
     let screen_size = monitor.size();
+    let monitor_pos = monitor.position();
     let x = (screen_size.width as i32 - window_size.width as i32) / 2;
     let y = (screen_size.height as i32 - window_size.height as i32) / 2;
-    window.set_outer_position(WryPhysicalPosition::new(x, y));
+    window.set_outer_position(WryPhysicalPosition::new(
+      monitor_pos.x + x,
+      monitor_pos.y + y,
+    ));
     Ok(())
   } else {
     Err(Error::FailedToGetMonitor)