Skip to content
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

SDL_GetGlobalMouseState() returns incorrect Y on secondary display #2975

Closed
SDLBugzilla opened this issue Feb 11, 2021 · 0 comments
Closed

Comments

@SDLBugzilla
Copy link
Collaborator

This bug report was migrated from our old Bugzilla tracker.

These attachments are available in the static archive:

Reported in version: 2.0.8
Reported for operating system, platform: macOS 10.13, x86_64

Comments on the original bug report:

On 2018-09-09 09:49:45 +0000, Julian Raschke wrote:

I use an open Mac laptop with an additional external monitor. The coordinate spaces from SDL_GetGlobalMouseState() and SDL_GetWindowPosition() match on the primary display, but not on the secondary display.

Cocoa window coordinates are vertically flipped in relation to the primary display:

https://github.com/spurious/SDL-mirror/blob/release-2.0.8/src/video/cocoa/SDL_cocoawindow.m#L219-L222

However, Cocoa_GetGlobalMouseState inverts the cursor Y coordinate per-display:

https://github.com/spurious/SDL-mirror/blob/release-2.0.8/src/video/cocoa/SDL_cocoamouse.m#L320-L323

Suggested fix: Replace the for-loop with this simpler calculation:

*x = (int) cocoaLocation.x;
*y = (int) (CGDisplayPixelsHigh(kCGDirectMainDisplay) - cocoaLocation.y);

Related ticket:

https://bugzilla.libsdl.org/show_bug.cgi?id=2655

On 2018-12-13 15:14:13 +0000, Giovanni Bajo wrote:

Created attachment 3545
Fix for the bug on OSX

I have the same problem: SDL_GetGlobalMouseState() is wrong on double monitor setups on OSX.

The fix suggested in this bug perfectly works. I'm attaching a patch that allows me to use SDL_GetGlobalMouseState() on double-monitor setups correctly. Please apply the fix.

On 2018-12-30 08:22:57 +0000, Giovanni Bajo wrote:

Ping! Can we get this applied?

On 2019-01-05 06:09:57 +0000, Sam Lantinga wrote:

Patch added, thanks!
https://hg.libsdl.org/SDL/rev/74e8ace1b2c3

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

No branches or pull requests

1 participant