Skip to content

Commit f49db41

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 5cc9298 commit f49db41

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed
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

+4-1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ use core_foundation::{
2323
string::CFString,
2424
};
2525
use core_graphics::display::{CGDirectDisplayID, CGDisplay, CGDisplayBounds};
26+
use dpi::LogicalPosition;
2627

2728
#[derive(Clone)]
2829
pub struct VideoMode {
@@ -166,7 +167,9 @@ pub fn from_point(x: f64, y: f64) -> Option<MonitorHandle> {
166167
unsafe {
167168
for monitor in available_monitors() {
168169
let bound = CGDisplayBounds(monitor.0);
169-
if CGRectContainsPoint(bound, CGPoint::new(x, y)) > 0 {
170+
let position =
171+
LogicalPosition::from_physical::<_, f64>((x as f64, y as f64), monitor.scale_factor());
172+
if CGRectContainsPoint(bound, CGPoint::new(position.x, position.y)) > 0 {
170173
return Some(monitor);
171174
}
172175
}

0 commit comments

Comments
 (0)