Skip to content

Commit 45236e4

Browse files
committed
fix(macos): treat Monitor::from_point args as physical
The x and y values passed to from_point are now treated as physical and therefore converted to logical values on macOS. This makes the behavior consistent with the Windows implementation. Closes tauri-apps/tauri#12676.
1 parent aef8944 commit 45236e4

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"tao": patch
3+
---
4+
5+
The `x` and `y` values passed to `Monitor::from_point` are now treated as physical and therefore converted to logical values on macOS.
6+
This makes the behavior consistent with the implementation for Windows.

src/platform_impl/macos/monitor.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ use core_graphics::{
1818
display::{CGDirectDisplayID, CGDisplay, CGDisplayBounds},
1919
geometry::CGPoint,
2020
};
21+
use dpi::LogicalPosition;
2122
use objc2::{msg_send, rc::Retained};
2223
use objc2_app_kit::NSScreen;
2324
use objc2_foundation::{MainThreadMarker, NSString, NSUInteger};
@@ -164,7 +165,9 @@ pub fn from_point(x: f64, y: f64) -> Option<MonitorHandle> {
164165
unsafe {
165166
for monitor in available_monitors() {
166167
let bound = CGDisplayBounds(monitor.0);
167-
if CGRectContainsPoint(bound, CGPoint::new(x, y)) > 0 {
168+
let position =
169+
LogicalPosition::from_physical::<_, f64>((x as f64, y as f64), monitor.scale_factor());
170+
if CGRectContainsPoint(bound, CGPoint::new(position.x, position.y)) > 0 {
168171
return Some(monitor);
169172
}
170173
}

0 commit comments

Comments
 (0)