Fixed bug 2346 - Mac: mousewheel events have flipped horizontal scroll values
authorSam Lantinga <slouken@libsdl.org>
Sat, 22 Feb 2014 14:57:12 -0800
changeset 82328976fb30952f
parent 8231 ad3edb1923f2
child 8233 ffece8ab18a6
Fixed bug 2346 - Mac: mousewheel events have flipped horizontal scroll values

Alex Szpakowski

On my Mac OS X system (10.9.1), the SDL_MOUSEWHEEL event reports negative X values when my trackpad scrolls to the right, and positive X values when my trackpad scrolls to the left. This is backwards from what I'd expect, and I don't think it matches the Windows wheel events.

The vertical scroll values are what I'd expect though, and are consistent what gets reported on Windows (positive Y for scrolling up, negative Y for scrolling down.)

This is with "scroll direction: natural" disabled in the OS X trackpad settings (i.e. my scroll direction in non-SDL OS X programs matches what happens in Windows and Linux.)

I also tested with the horizontal scroll on a real mouse (Logitech G500 without custom drivers), and the horizontal scroll values in SDL are still flipped.

I "solved" the issue for myself by changing this line in the Cocoa_HandleMouseWheel function:

float x = [event deltaX];

to this:

float x = -[event deltaX];

I believe it should work fine with that change - I found something similar in another codebase while looking online for my issue - but I haven't tested on anything below Mac OS 10.8.
include/SDL_events.h
src/video/cocoa/SDL_cocoamouse.m
     1.1 --- a/include/SDL_events.h	Sat Feb 22 10:40:12 2014 -0800
     1.2 +++ b/include/SDL_events.h	Sat Feb 22 14:57:12 2014 -0800
     1.3 @@ -257,8 +257,8 @@
     1.4      Uint32 timestamp;
     1.5      Uint32 windowID;    /**< The window with mouse focus, if any */
     1.6      Uint32 which;       /**< The mouse instance id, or SDL_TOUCH_MOUSEID */
     1.7 -    Sint32 x;           /**< The amount scrolled horizontally */
     1.8 -    Sint32 y;           /**< The amount scrolled vertically */
     1.9 +    Sint32 x;           /**< The amount scrolled horizontally, positive to the right and negative to the left */
    1.10 +    Sint32 y;           /**< The amount scrolled vertically, positive away from the user and negative toward the user */
    1.11  } SDL_MouseWheelEvent;
    1.12  
    1.13  /**
     2.1 --- a/src/video/cocoa/SDL_cocoamouse.m	Sat Feb 22 10:40:12 2014 -0800
     2.2 +++ b/src/video/cocoa/SDL_cocoamouse.m	Sat Feb 22 14:57:12 2014 -0800
     2.3 @@ -291,7 +291,7 @@
     2.4  {
     2.5      SDL_Mouse *mouse = SDL_GetMouse();
     2.6  
     2.7 -    float x = [event deltaX];
     2.8 +    float x = -[event deltaX];
     2.9      float y = [event deltaY];
    2.10  
    2.11      if (x > 0) {