summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSam Lantinga <slouken@libsdl.org>2019-01-04 22:09:38 -0800
committerSam Lantinga <slouken@libsdl.org>2019-01-04 22:09:38 -0800
commitd73f4de427e6e43b7482deb1a9c8eae39a66c48d (patch)
treed42858e8cc69149d2a3648e4aa8bbcb8ab50ae41
parenta7609d9e2ab6c547022a60a35a440ee6cb515ac9 (diff)
Fixed bug 4255 - SDL_GetGlobalMouseState() returns incorrect Y on secondary display
Julian Raschke 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);
-rw-r--r--src/video/cocoa/SDL_cocoamouse.m10
1 files changed, 2 insertions, 8 deletions
diff --git a/src/video/cocoa/SDL_cocoamouse.m b/src/video/cocoa/SDL_cocoamouse.m
index 9949c795a5..24a705bedb 100644
--- a/src/video/cocoa/SDL_cocoamouse.m
+++ b/src/video/cocoa/SDL_cocoamouse.m
@@ -315,14 +315,8 @@ Cocoa_GetGlobalMouseState(int *x, int *y)
const NSPoint cocoaLocation = [NSEvent mouseLocation];
Uint32 retval = 0;
- for (NSScreen *screen in [NSScreen screens]) {
- NSRect frame = [screen frame];
- if (NSMouseInRect(cocoaLocation, frame, NO)) {
- *x = (int) cocoaLocation.x;
- *y = (int) ((frame.origin.y + frame.size.height) - cocoaLocation.y);
- break;
- }
- }
+ *x = (int) cocoaLocation.x;
+ *y = (int) (CGDisplayPixelsHigh(kCGDirectMainDisplay) - cocoaLocation.y);
retval |= (cocoaButtons & (1 << 0)) ? SDL_BUTTON_LMASK : 0;
retval |= (cocoaButtons & (1 << 1)) ? SDL_BUTTON_RMASK : 0;