Skip to content

Commit

Permalink
fix(core): account for monitor position when centering window (#4166)
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasfernog authored May 21, 2022
1 parent 52d1775 commit a7a9fde
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
6 changes: 6 additions & 0 deletions .changes/fix-center-window.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"tauri": patch
"tauri-runtime-wry": patch
---

Account the monitor position when centering a window.
6 changes: 5 additions & 1 deletion core/tauri-runtime-wry/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit a7a9fde

Please sign in to comment.