Skip to content

fix(macos): treat Monitor::from_point args as physical #1057

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changes/macos-monitor-from-point-physical-coordinates.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"tao": patch
---

The `x` and `y` values passed to `Monitor::from_point` are now treated as physical and therefore converted to logical values on macOS.
This makes the behavior consistent with the implementation for Windows.
5 changes: 4 additions & 1 deletion src/platform_impl/macos/monitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use core_graphics::{
display::{CGDirectDisplayID, CGDisplay, CGDisplayBounds},
geometry::CGPoint,
};
use dpi::LogicalPosition;
use objc2::{msg_send, rc::Retained};
use objc2_app_kit::NSScreen;
use objc2_foundation::{MainThreadMarker, NSString, NSUInteger};
Expand Down Expand Up @@ -164,7 +165,9 @@ pub fn from_point(x: f64, y: f64) -> Option<MonitorHandle> {
unsafe {
for monitor in available_monitors() {
let bound = CGDisplayBounds(monitor.0);
if CGRectContainsPoint(bound, CGPoint::new(x, y)) > 0 {
let position =
LogicalPosition::from_physical::<_, f64>((x as f64, y as f64), monitor.scale_factor());
if CGRectContainsPoint(bound, CGPoint::new(position.x, position.y)) > 0 {
return Some(monitor);
}
}
Expand Down
Loading