Skip to content

Commit 6ce10ab

Browse files
authored
fix: monitor work_area on macOS (#13309)
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).
1 parent 039f44b commit 6ce10ab

File tree

1 file changed

+13
-4
lines changed
  • crates/tauri-runtime-wry/src/monitor

1 file changed

+13
-4
lines changed

crates/tauri-runtime-wry/src/monitor/macos.rs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,28 @@
22
// SPDX-License-Identifier: Apache-2.0
33
// SPDX-License-Identifier: MIT
44

5-
use tauri_runtime::dpi::{LogicalPosition, LogicalSize, PhysicalPosition, PhysicalRect};
5+
use tauri_runtime::dpi::{LogicalSize, PhysicalRect};
66

77
impl super::MonitorExt for tao::monitor::MonitorHandle {
88
fn work_area(&self) -> PhysicalRect<i32, u32> {
99
use objc2_app_kit::NSScreen;
1010
use tao::platform::macos::MonitorHandleExtMacOS;
1111
if let Some(ns_screen) = self.ns_screen() {
1212
let ns_screen: &NSScreen = unsafe { &*ns_screen.cast() };
13-
let rect = ns_screen.visibleFrame();
13+
let screen_frame = ns_screen.frame();
14+
let visible_frame = ns_screen.visibleFrame();
15+
1416
let scale_factor = self.scale_factor();
17+
18+
let mut position = self.position().to_logical::<f64>(scale_factor);
19+
20+
position.x += visible_frame.origin.x - screen_frame.origin.x;
21+
position.y -= visible_frame.origin.y - screen_frame.origin.y;
22+
1523
PhysicalRect {
16-
size: LogicalSize::new(rect.size.width, rect.size.height).to_physical(scale_factor),
17-
position: LogicalPosition::new(rect.origin.x, rect.origin.y).to_physical(scale_factor),
24+
size: LogicalSize::new(visible_frame.size.width, visible_frame.size.height)
25+
.to_physical(scale_factor),
26+
position: position.to_physical(scale_factor),
1827
}
1928
} else {
2029
PhysicalRect {

0 commit comments

Comments
 (0)