We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 4255 - SDL_GetGlobalMouseState() returns incorrect Y on secondary display
Summary: SDL_GetGlobalMouseState() returns incorrect Y on secondary display
Status: RESOLVED FIXED
Alias: None
Product: SDL
Classification: Unclassified
Component: video (show other bugs)
Version: 2.0.8
Hardware: x86_64 macOS 10.13
: P2 normal
Assignee: Sam Lantinga
QA Contact: Sam Lantinga
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-09-09 09:49 UTC by Julian Raschke
Modified: 2019-01-05 06:09 UTC (History)
2 users (show)

See Also:


Attachments
Fix for the bug on OSX (895 bytes, patch)
2018-12-13 15:14 UTC, Giovanni Bajo
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Julian Raschke 2018-09-09 09:49:45 UTC
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
Comment 1 Giovanni Bajo 2018-12-13 15:14:13 UTC
Created attachment 3545 [details]
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.
Comment 2 Giovanni Bajo 2018-12-30 08:22:57 UTC
Ping! Can we get this applied?
Comment 3 Sam Lantinga 2019-01-05 06:09:57 UTC
Patch added, thanks!
https://hg.libsdl.org/SDL/rev/74e8ace1b2c3