From 57484ae5d7a4b4fb24e276d5f54109badb0c52b2 Mon Sep 17 00:00:00 2001 From: Policarpo Date: Wed, 15 Apr 2026 12:57:02 -0300 Subject: [PATCH 1/4] fix(macOS): fix incorrect window position on multi-monitor setups --- crates/tauri-runtime-wry/src/lib.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/crates/tauri-runtime-wry/src/lib.rs b/crates/tauri-runtime-wry/src/lib.rs index 6c537de6cf43..c51779eeeaef 100644 --- a/crates/tauri-runtime-wry/src/lib.rs +++ b/crates/tauri-runtime-wry/src/lib.rs @@ -4567,12 +4567,20 @@ fn create_window( } }; + #[cfg(target_os = "macos")] + let initial_outer_position = window_builder.inner.window.position; + let window = window_builder .inner .build(event_loop) .inspect_err(|e| log::error!("Error creating window: {e:?}")) .map_err(|_| Error::CreateWindow)?; + #[cfg(target_os = "macos")] + if let Some(position) = initial_outer_position { + window.set_outer_position(position); + } + #[cfg(feature = "tracing")] { drop(window_create_span); From 09bfd7182bc962bc9f6aa3d45ede037344eaba35 Mon Sep 17 00:00:00 2001 From: Policarpo Date: Fri, 17 Apr 2026 08:44:29 -0300 Subject: [PATCH 2/4] avoid 'flash' on current monitor when targeting another display for fullscreen --- crates/tauri-runtime-wry/src/lib.rs | 63 +++++++++++++++++++++-------- 1 file changed, 47 insertions(+), 16 deletions(-) diff --git a/crates/tauri-runtime-wry/src/lib.rs b/crates/tauri-runtime-wry/src/lib.rs index c51779eeeaef..0ca2db941b07 100644 --- a/crates/tauri-runtime-wry/src/lib.rs +++ b/crates/tauri-runtime-wry/src/lib.rs @@ -692,6 +692,25 @@ impl From for PositionWrapper { } } +#[cfg(desktop)] +fn find_monitor_for_position( + monitors: impl Iterator, + window_position: TaoPosition, +) -> Option { + monitors.into_iter().find(|m| { + let monitor_pos = m.position(); + let monitor_size = m.size(); + + // type annotations required for 32bit targets. + let window_position = window_position.to_physical::(m.scale_factor()); + + monitor_pos.x <= window_position.x + && window_position.x < monitor_pos.x + monitor_size.width as i32 + && monitor_pos.y <= window_position.y + && window_position.y < monitor_pos.y + monitor_size.height as i32 + }) +} + #[derive(Debug, Clone)] pub struct UserAttentionTypeWrapper(pub TaoUserAttentionType); @@ -4489,18 +4508,7 @@ fn create_window( #[cfg(desktop)] if window_builder.prevent_overflow.is_some() || window_builder.center { let monitor = if let Some(window_position) = &window_builder.inner.window.position { - event_loop.available_monitors().find(|m| { - let monitor_pos = m.position(); - let monitor_size = m.size(); - - // type annotations required for 32bit targets. - let window_position = window_position.to_physical::(m.scale_factor()); - - monitor_pos.x <= window_position.x - && window_position.x < monitor_pos.x + monitor_size.width as i32 - && monitor_pos.y <= window_position.y - && window_position.y < monitor_pos.y + monitor_size.height as i32 - }) + find_monitor_for_position(event_loop.available_monitors(), *window_position) } else { event_loop.primary_monitor() }; @@ -4567,8 +4575,27 @@ fn create_window( } }; - #[cfg(target_os = "macos")] - let initial_outer_position = window_builder.inner.window.position; + #[cfg(any(target_os = "macos", target_os = "linux"))] + let (initial_position, is_fullscreen) = ( + window_builder.inner.window.position, + window_builder.inner.window.fullscreen.is_some(), + ); + + // When fullscreen is requested with a position targeting a second display, + // resolve the target monitor so the window is created fullscreen there directly, + // avoiding a visible 'flash' on the primary monitor. + #[cfg(any(target_os = "macos", target_os = "linux"))] + match (is_fullscreen, initial_position) { + (true, Some(position)) => { + if let Some(target_monitor) = + find_monitor_for_position(event_loop.available_monitors(), position) + { + window_builder.inner.window.fullscreen = + Some(Fullscreen::Borderless(Some(target_monitor))); + } + } + _ => {} + } let window = window_builder .inner @@ -4576,9 +4603,13 @@ fn create_window( .inspect_err(|e| log::error!("Error creating window: {e:?}")) .map_err(|_| Error::CreateWindow)?; + // on macOS, `with_position` sets the content's inner position and the title bar + // is placed above it. `set_outer_position` is needed for precise placement. #[cfg(target_os = "macos")] - if let Some(position) = initial_outer_position { - window.set_outer_position(position); + if !is_fullscreen { + if let Some(position) = initial_position { + window.set_outer_position(position); + } } #[cfg(feature = "tracing")] From a48ea786d9d5c2a1bbce19f5ce4c9c4fb4d98a5b Mon Sep 17 00:00:00 2001 From: Policarpo Date: Mon, 27 Apr 2026 17:12:20 -0300 Subject: [PATCH 3/4] simplify fullscreen monitor selection --- crates/tauri-runtime-wry/src/lib.rs | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/crates/tauri-runtime-wry/src/lib.rs b/crates/tauri-runtime-wry/src/lib.rs index 0ca2db941b07..a7c53914a3ce 100644 --- a/crates/tauri-runtime-wry/src/lib.rs +++ b/crates/tauri-runtime-wry/src/lib.rs @@ -4581,20 +4581,15 @@ fn create_window( window_builder.inner.window.fullscreen.is_some(), ); - // When fullscreen is requested with a position targeting a second display, - // resolve the target monitor so the window is created fullscreen there directly, - // avoiding a visible 'flash' on the primary monitor. + // If fullscreen is requested with an explicit position, resolve the target + // monitor up front so the window is created fullscreen on that display. #[cfg(any(target_os = "macos", target_os = "linux"))] - match (is_fullscreen, initial_position) { - (true, Some(position)) => { - if let Some(target_monitor) = - find_monitor_for_position(event_loop.available_monitors(), position) - { - window_builder.inner.window.fullscreen = - Some(Fullscreen::Borderless(Some(target_monitor))); - } + if let (true, Some(position)) = (is_fullscreen, initial_position) { + if let Some(target_monitor) = + find_monitor_for_position(event_loop.available_monitors(), position) + { + window_builder.inner.window.fullscreen = Some(Fullscreen::Borderless(Some(target_monitor))); } - _ => {} } let window = window_builder @@ -4603,8 +4598,8 @@ fn create_window( .inspect_err(|e| log::error!("Error creating window: {e:?}")) .map_err(|_| Error::CreateWindow)?; - // on macOS, `with_position` sets the content's inner position and the title bar - // is placed above it. `set_outer_position` is needed for precise placement. + // On macOS, `with_position` uses the content origin; the title bar is added + // above it. `set_outer_position` is needed for precise window placement. #[cfg(target_os = "macos")] if !is_fullscreen { if let Some(position) = initial_position { From 94963f661c02b4095a636a2bef8b675db8e8397d Mon Sep 17 00:00:00 2001 From: Lucas Nogueira Date: Thu, 30 Apr 2026 10:19:06 -0300 Subject: [PATCH 4/4] change file --- .changes/fix-macos-initial-window-position.md | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 .changes/fix-macos-initial-window-position.md diff --git a/.changes/fix-macos-initial-window-position.md b/.changes/fix-macos-initial-window-position.md new file mode 100644 index 000000000000..3a6ab039929d --- /dev/null +++ b/.changes/fix-macos-initial-window-position.md @@ -0,0 +1,6 @@ +--- +"tauri-runtime-wry": patch:bug +"tauri": patch:bug +--- + +Fix initial window position when positioning it to another monitor.