From e67407d35479945272f9bc800e2ae7d04d7b4e3f Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Wed, 10 Jun 2009 14:00:21 +0000 Subject: [PATCH] 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 | 15 ++++++++------- src/events/SDL_mouse.c | 2 ++ 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/include/SDL_events.h b/include/SDL_events.h index f613bb27b..e9e8d07d6 100644 --- a/include/SDL_events.h +++ b/include/SDL_events.h @@ -128,10 +128,10 @@ typedef enum typedef struct SDL_WindowEvent { Uint8 type; /**< SDL_WINDOWEVENT */ + SDL_WindowID windowID; /**< The associated window */ Uint8 event; /**< SDL_WindowEventID */ int data1; /**< event dependent data */ int data2; /**< event dependent data */ - SDL_WindowID windowID; /**< The associated window */ } SDL_WindowEvent; /** @@ -142,10 +142,10 @@ typedef struct SDL_WindowEvent typedef struct SDL_KeyboardEvent { Uint8 type; /**< SDL_KEYDOWN or SDL_KEYUP */ + SDL_WindowID windowID; /**< The window with keyboard focus, if any */ Uint8 which; /**< The keyboard device index */ Uint8 state; /**< SDL_PRESSED or SDL_RELEASED */ SDL_keysym keysym; /**< The key that was pressed or released */ - SDL_WindowID windowID; /**< The window with keyboard focus, if any */ } SDL_KeyboardEvent; /** @@ -157,9 +157,9 @@ typedef struct SDL_KeyboardEvent typedef struct SDL_TextInputEvent { Uint8 type; /**< SDL_TEXTINPUT */ + SDL_WindowID windowID; /**< The window with keyboard focus, if any */ Uint8 which; /**< The keyboard device index */ char text[SDL_TEXTINPUTEVENT_TEXT_SIZE]; /**< The input text */ - SDL_WindowID windowID; /**< The window with keyboard focus, if any */ } SDL_TextInputEvent; /** @@ -170,6 +170,7 @@ typedef struct SDL_TextInputEvent typedef struct SDL_MouseMotionEvent { Uint8 type; /**< SDL_MOUSEMOTION */ + SDL_WindowID windowID; /**< The window with mouse focus, if any */ Uint8 which; /**< The mouse device index */ Uint8 state; /**< The current button state */ int x; /**< X coordinate, relative to window */ @@ -183,7 +184,6 @@ typedef struct SDL_MouseMotionEvent int cursor; /**< The cursor being used in the event */ int xrel; /**< The relative motion in the X direction */ int yrel; /**< The relative motion in the Y direction */ - SDL_WindowID windowID; /**< The window with mouse focus, if any */ } SDL_MouseMotionEvent; /** @@ -194,12 +194,12 @@ typedef struct SDL_MouseMotionEvent typedef struct SDL_MouseButtonEvent { Uint8 type; /**< SDL_MOUSEBUTTONDOWN or SDL_MOUSEBUTTONUP */ + SDL_WindowID windowID; /**< The window with mouse focus, if any */ Uint8 which; /**< The mouse device index */ Uint8 button; /**< The mouse button index */ Uint8 state; /**< SDL_PRESSED or SDL_RELEASED */ int x; /**< X coordinate, relative to window */ int y; /**< Y coordinate, relative to window */ - SDL_WindowID windowID; /**< The window with mouse focus, if any */ } SDL_MouseButtonEvent; /** @@ -210,10 +210,10 @@ typedef struct SDL_MouseButtonEvent typedef struct SDL_MouseWheelEvent { Uint8 type; /**< SDL_MOUSEWHEEL */ + SDL_WindowID windowID; /**< The window with mouse focus, if any */ Uint8 which; /**< The mouse device index */ int x; /**< The amount scrolled horizontally */ int y; /**< The amount scrolled vertically */ - SDL_WindowID windowID; /**< The window with mouse focus, if any */ } SDL_MouseWheelEvent; /** @@ -292,10 +292,10 @@ typedef struct SDL_QuitEvent typedef struct SDL_UserEvent { Uint8 type; /**< SDL_USEREVENT through SDL_NUMEVENTS-1 */ + SDL_WindowID windowID; /**< The associated window if any*/ int code; /**< User defined event code */ void *data1; /**< User defined data pointer */ void *data2; /**< User defined data pointer */ - SDL_WindowID windowID; /**< The associated window if any*/ } SDL_UserEvent; /** @@ -316,6 +316,7 @@ typedef struct SDL_SysWMEvent typedef struct SDL_ProximityEvent { Uint8 type; + SDL_WindowID windowID; /**< The associated window */ Uint8 which; int cursor; int x; diff --git a/src/events/SDL_mouse.c b/src/events/SDL_mouse.c index 478cee307..05fa358b2 100644 --- a/src/events/SDL_mouse.c +++ b/src/events/SDL_mouse.c @@ -369,6 +369,8 @@ SDL_SendProximity(int id, int x, int y, int type) event.proximity.y = y; event.proximity.cursor = mouse->current_end; event.proximity.type = type; + /* FIXME: is this right? */ + event.proximity.windowID = mouse->focus; posted = (SDL_PushEvent(&event) > 0); if (type == SDL_PROXIMITYIN) { mouse->proximity = SDL_TRUE;