Fixed bug 1856 - (Patch) More bits for SDL_MouseMotionEvent.state
authorSam Lantinga <slouken@libsdl.org>
Mon, 20 May 2013 23:57:10 -0700
changeset 7203c74f5dbcfd23
parent 7202 373d9e4e8ad9
child 7204 ad1ee23309ca
Fixed bug 1856 - (Patch) More bits for SDL_MouseMotionEvent.state

Gerry JJ

The state bitmask in SDL_MouseMotionEvent is stored in an Uint8. Unfortunately this doesn't actually have room for 8 buttons because SDL skips 4 button indices after the third mouse button (at least here on Linux x86-64, probably related to wheel handling?), so it's really just enough to track 4 buttons. For example, on a Logitech MX310 mouse I've got, even though the mouse has 6 buttons total, the left and right side buttons and extra middle button have indexes 8, 9 and 10, and the last two won't fit in the 8 bit button state.

The source of the button state (in SDL_Mouse) is already 32-bit, and the state field in SDL_MouseMotionEvent is 32-bit aligned and followed by three 8-bit padding fields. So simply changing the SDL_MouseMotionEvent state to an Uint32 and removing the padding fields fixes this, and I think it should be binary compatible, at least for little endian.
include/SDL_events.h
     1.1 --- a/include/SDL_events.h	Mon May 20 23:30:08 2013 -0700
     1.2 +++ b/include/SDL_events.h	Mon May 20 23:57:10 2013 -0700
     1.3 @@ -221,10 +221,7 @@
     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 -    Uint8 state;        /**< The current button state */
     1.8 -    Uint8 padding1;
     1.9 -    Uint8 padding2;
    1.10 -    Uint8 padding3;
    1.11 +    Uint32 state;       /**< The current button state */
    1.12      Sint32 x;           /**< X coordinate, relative to window */
    1.13      Sint32 y;           /**< Y coordinate, relative to window */
    1.14      Sint32 xrel;        /**< The relative motion in the X direction */