From d9ca743998c94839816442cf55ff071ea8b6971b Mon Sep 17 00:00:00 2001 From: Lucas Nogueira Date: Fri, 25 Apr 2025 20:05:42 -0300 Subject: [PATCH] fix: monitor work_area on macOS macOS uses a different coordinate system for visibleFrame, so to get accurate values we should only get the diff between frame() and visibleFrame() and apply that to the standard monitor position returned by CGDisplayBounds. Size isn't impacted by this, and properly returns the value (accounting for dock position). --- crates/tauri-runtime-wry/src/monitor/macos.rs | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/crates/tauri-runtime-wry/src/monitor/macos.rs b/crates/tauri-runtime-wry/src/monitor/macos.rs index 29f70e6cf629..82d810844fe4 100644 --- a/crates/tauri-runtime-wry/src/monitor/macos.rs +++ b/crates/tauri-runtime-wry/src/monitor/macos.rs @@ -2,7 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 // SPDX-License-Identifier: MIT -use tauri_runtime::dpi::{LogicalPosition, LogicalSize, PhysicalPosition, PhysicalRect}; +use tauri_runtime::dpi::{LogicalSize, PhysicalRect}; impl super::MonitorExt for tao::monitor::MonitorHandle { fn work_area(&self) -> PhysicalRect { @@ -10,11 +10,20 @@ impl super::MonitorExt for tao::monitor::MonitorHandle { use tao::platform::macos::MonitorHandleExtMacOS; if let Some(ns_screen) = self.ns_screen() { let ns_screen: &NSScreen = unsafe { &*ns_screen.cast() }; - let rect = ns_screen.visibleFrame(); + let screen_frame = ns_screen.frame(); + let visible_frame = ns_screen.visibleFrame(); + let scale_factor = self.scale_factor(); + + let mut position = self.position().to_logical::(scale_factor); + + position.x += visible_frame.origin.x - screen_frame.origin.x; + position.y -= visible_frame.origin.y - screen_frame.origin.y; + PhysicalRect { - size: LogicalSize::new(rect.size.width, rect.size.height).to_physical(scale_factor), - position: LogicalPosition::new(rect.origin.x, rect.origin.y).to_physical(scale_factor), + size: LogicalSize::new(visible_frame.size.width, visible_frame.size.height) + .to_physical(scale_factor), + position: position.to_physical(scale_factor), } } else { PhysicalRect {