Skip to content

Commit a78b388

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 a78b388

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-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

+3-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,8 @@ 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 = LogicalPosition::from_physical::<_, f64>((x as f64, y as f64), monitor.scale_factor());
171+
if CGRectContainsPoint(bound, CGPoint::new(position.x, position.y)) > 0 {
170172
return Some(monitor);
171173
}
172174
}

0 commit comments

Comments
 (0)