Fixed bug #750
authorSam Lantinga <slouken@libsdl.org>
Wed, 10 Jun 2009 14:00:21 +0000
changeset 319191b335df6fc8
parent 3190 c68d2ca5970f
child 3192 ec126b077b96
Fixed bug #750
Since many different event structures include windowID it should be placed near
the beginning of the structure (preferably right after type) so it's position
is the same between different events.

This is to avoid code like this:
if (event.type == SDL_WINDOWEVENT)
win = event.window.windowID;
else if ((SDL_EVENTMASK(event.type) & SDL_KEYEVENTMASK) != 0)
win = event.key.windowID;
else if (event.type == SDL_TEXTINPUT)
win = event.text.windowID;
else if (event.type == SDL_MOUSEMOTION)
win = event.motion.windowID;
else if ((SDL_EVENTMASK(event.type) & (SDL_MOUBUTTONDOWNMASK |
SDL_MOUBUTTONUPMASK)) != 0)
win = event.button.windowID;
else if (event.type == SDL_MOUSEWHEEL)
win = event.wheel.windowID;
...

in favor of:
win = event.window.windowID;
include/SDL_events.h
src/events/SDL_mouse.c
     1.1 --- a/include/SDL_events.h	Wed Jun 10 13:54:13 2009 +0000
     1.2 +++ b/include/SDL_events.h	Wed Jun 10 14:00:21 2009 +0000
     1.3 @@ -128,10 +128,10 @@
     1.4  typedef struct SDL_WindowEvent
     1.5  {
     1.6      Uint8 type;             /**< SDL_WINDOWEVENT */
     1.7 +    SDL_WindowID windowID;  /**< The associated window */
     1.8      Uint8 event;            /**< SDL_WindowEventID */
     1.9      int data1;              /**< event dependent data */
    1.10      int data2;              /**< event dependent data */
    1.11 -    SDL_WindowID windowID;  /**< The associated window */
    1.12  } SDL_WindowEvent;
    1.13  
    1.14  /**
    1.15 @@ -142,10 +142,10 @@
    1.16  typedef struct SDL_KeyboardEvent
    1.17  {
    1.18      Uint8 type;             /**< SDL_KEYDOWN or SDL_KEYUP */
    1.19 +    SDL_WindowID windowID;  /**< The window with keyboard focus, if any */
    1.20      Uint8 which;            /**< The keyboard device index */
    1.21      Uint8 state;            /**< SDL_PRESSED or SDL_RELEASED */
    1.22      SDL_keysym keysym;      /**< The key that was pressed or released */
    1.23 -    SDL_WindowID windowID;  /**< The window with keyboard focus, if any */
    1.24  } SDL_KeyboardEvent;
    1.25  
    1.26  /**
    1.27 @@ -157,9 +157,9 @@
    1.28  typedef struct SDL_TextInputEvent
    1.29  {
    1.30      Uint8 type;                               /**< SDL_TEXTINPUT */
    1.31 +    SDL_WindowID windowID;                    /**< The window with keyboard focus, if any */
    1.32      Uint8 which;                              /**< The keyboard device index */
    1.33      char text[SDL_TEXTINPUTEVENT_TEXT_SIZE];  /**< The input text */
    1.34 -    SDL_WindowID windowID;                    /**< The window with keyboard focus, if any */
    1.35  } SDL_TextInputEvent;
    1.36  
    1.37  /**
    1.38 @@ -170,6 +170,7 @@
    1.39  typedef struct SDL_MouseMotionEvent
    1.40  {
    1.41      Uint8 type;             /**< SDL_MOUSEMOTION */
    1.42 +    SDL_WindowID windowID;  /**< The window with mouse focus, if any */
    1.43      Uint8 which;            /**< The mouse device index */
    1.44      Uint8 state;            /**< The current button state */
    1.45      int x;                  /**< X coordinate, relative to window */
    1.46 @@ -183,7 +184,6 @@
    1.47      int cursor;             /**< The cursor being used in the event */
    1.48      int xrel;               /**< The relative motion in the X direction */
    1.49      int yrel;               /**< The relative motion in the Y direction */
    1.50 -    SDL_WindowID windowID;  /**< The window with mouse focus, if any */
    1.51  } SDL_MouseMotionEvent;
    1.52  
    1.53  /**
    1.54 @@ -194,12 +194,12 @@
    1.55  typedef struct SDL_MouseButtonEvent
    1.56  {
    1.57      Uint8 type;             /**< SDL_MOUSEBUTTONDOWN or SDL_MOUSEBUTTONUP */
    1.58 +    SDL_WindowID windowID;  /**< The window with mouse focus, if any */
    1.59      Uint8 which;            /**< The mouse device index */
    1.60      Uint8 button;           /**< The mouse button index */
    1.61      Uint8 state;            /**< SDL_PRESSED or SDL_RELEASED */
    1.62      int x;                  /**< X coordinate, relative to window */
    1.63      int y;                  /**< Y coordinate, relative to window */
    1.64 -    SDL_WindowID windowID;  /**< The window with mouse focus, if any */
    1.65  } SDL_MouseButtonEvent;
    1.66  
    1.67  /**
    1.68 @@ -210,10 +210,10 @@
    1.69  typedef struct SDL_MouseWheelEvent
    1.70  {
    1.71      Uint8 type;             /**< SDL_MOUSEWHEEL */
    1.72 +    SDL_WindowID windowID;  /**< The window with mouse focus, if any */
    1.73      Uint8 which;            /**< The mouse device index */
    1.74      int x;                  /**< The amount scrolled horizontally */
    1.75      int y;                  /**< The amount scrolled vertically */
    1.76 -    SDL_WindowID windowID;  /**< The window with mouse focus, if any */
    1.77  } SDL_MouseWheelEvent;
    1.78  
    1.79  /**
    1.80 @@ -292,10 +292,10 @@
    1.81  typedef struct SDL_UserEvent
    1.82  {
    1.83      Uint8 type;             /**< SDL_USEREVENT through SDL_NUMEVENTS-1 */
    1.84 +    SDL_WindowID windowID;  /**< The associated window if any*/
    1.85      int code;               /**< User defined event code */
    1.86      void *data1;            /**< User defined data pointer */
    1.87      void *data2;            /**< User defined data pointer */
    1.88 -    SDL_WindowID windowID;  /**< The associated window if any*/
    1.89  } SDL_UserEvent;
    1.90  
    1.91  /**
    1.92 @@ -316,6 +316,7 @@
    1.93  typedef struct SDL_ProximityEvent
    1.94  {
    1.95      Uint8 type;
    1.96 +    SDL_WindowID windowID;  /**< The associated window */
    1.97      Uint8 which;
    1.98      int cursor;
    1.99      int x;
     2.1 --- a/src/events/SDL_mouse.c	Wed Jun 10 13:54:13 2009 +0000
     2.2 +++ b/src/events/SDL_mouse.c	Wed Jun 10 14:00:21 2009 +0000
     2.3 @@ -369,6 +369,8 @@
     2.4          event.proximity.y = y;
     2.5          event.proximity.cursor = mouse->current_end;
     2.6          event.proximity.type = type;
     2.7 +        /* FIXME: is this right? */
     2.8 +        event.proximity.windowID = mouse->focus;
     2.9          posted = (SDL_PushEvent(&event) > 0);
    2.10          if (type == SDL_PROXIMITYIN) {
    2.11              mouse->proximity = SDL_TRUE;