Skip to content

native/macos: don't shift the mouse y by one pixel - #707

Open
nivaldomcj wants to merge 1 commit into
not-fl3:masterfrom
nivaldomcj:macos-mouse-y
Open

nivaldomcj wants to merge 1 commit into
not-fl3:masterfrom
nivaldomcj:macos-mouse-y

Conversation

@nivaldomcj

@nivaldomcj nivaldomcj commented Nov 23, 2026 •

Copy link
Copy Markdown

transform_mouse_point turns Cocoa's bottom-left mouse position into a top-left one with screen_height - y * dpi_scale - 1. locationInWindow is a continuous position (100.25, say), not a row index, so the flip is screen_height - y * dpi_scale, and the extra - 1 makes every mouse position read one physical pixel too high. On a 1x display that's a whole point. X11 and Windows pass the event position through unchanged.

I checked it by sending the view a synthetic mouse-moved event at content position (50.5, 100.25) in points and printing what mouse_motion_event received:

Display high_dpi Expected Before After
1x (2560×1080) false 100.25 99.25 100.25
1x true 100.25 99.25 100.25
Retina false 100.25 99.25 100.25
Retina true 200.5 199.5 200.5

Tested on macOS 27.2.1 (26B131), Apple M3 Max (arm64), Rust 1.100.0.

x is unchanged. cargo build --all-targets passes for aarch64-apple-darwin and x86_64-apple-darwin, and cargo check --all-targets for aarch64-apple-ios and x86_64-apple-ios.

The - 1 predates f46c5dd ("Redesign globals"), and I couldn't find a reason for it in the history. If it's there on purpose, I'm happy to close this.

locationInWindow is continuous with the origin at the bottom-left, so
flipping it to a top-left origin is height - y. The extra - 1 made every
mouse position read one backing pixel too high. X11 and Windows report
the position unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant