Skip to content

Commit a7a9fde

Browse files
authored
fix(core): account for monitor position when centering window (#4166)
1 parent 52d1775 commit a7a9fde

2 files changed

Lines changed: 11 additions & 1 deletion

File tree

.changes/fix-center-window.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"tauri": patch
3+
"tauri-runtime-wry": patch
4+
---
5+
6+
Account the monitor position when centering a window.

core/tauri-runtime-wry/src/lib.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2854,9 +2854,13 @@ fn on_window_close(
28542854
fn center_window(window: &Window, window_size: WryPhysicalSize<u32>) -> Result<()> {
28552855
if let Some(monitor) = window.current_monitor() {
28562856
let screen_size = monitor.size();
2857+
let monitor_pos = monitor.position();
28572858
let x = (screen_size.width as i32 - window_size.width as i32) / 2;
28582859
let y = (screen_size.height as i32 - window_size.height as i32) / 2;
2859-
window.set_outer_position(WryPhysicalPosition::new(x, y));
2860+
window.set_outer_position(WryPhysicalPosition::new(
2861+
monitor_pos.x + x,
2862+
monitor_pos.y + y,
2863+
));
28602864
Ok(())
28612865
} else {
28622866
Err(Error::FailedToGetMonitor)

0 commit comments

Comments
 (0)