Fixed the joystick id usage in the joystick and game controller events.
authorSam Lantinga <slouken@libsdl.org>
Sat, 02 Mar 2013 17:51:32 -0800
changeset 6949 4de584a3a027
parent 6948 84a71440360d
child 6950 1ddb72193079
Fixed the joystick id usage in the joystick and game controller events.
include/SDL_events.h
include/SDL_joystick.h
src/events/SDL_events.c
src/joystick/SDL_sysjoystick.h
--- a/include/SDL_events.h	Fri Mar 01 11:27:01 2013 -0800
+++ b/include/SDL_events.h	Sat Mar 02 17:51:32 2013 -0800
@@ -131,6 +131,15 @@
 } SDL_EventType;
 
 /**
+ *  \brief Fields shared by every event
+ */
+typedef struct SDL_GenericEvent
+{
+    Uint32 type;
+    Uint32 timestamp;
+} SDL_GenericEvent;
+    
+/**
  *  \brief Window state change event data (event.window.*)
  */
 typedef struct SDL_WindowEvent
@@ -241,11 +250,13 @@
 {
     Uint32 type;        /**< ::SDL_JOYAXISMOTION */
     Uint32 timestamp;
-    Uint8 which;        /**< The joystick instance id */
+    Uint32 which;       /**< The joystick instance id */
     Uint8 axis;         /**< The joystick axis index */
     Uint8 padding1;
     Uint8 padding2;
-    int value;          /**< The axis value (range: -32768 to 32767) */
+    Uint8 padding3;
+    Sint16 value;       /**< The axis value (range: -32768 to 32767) */
+    Uint16 padding4;
 } SDL_JoyAxisEvent;
 
 /**
@@ -255,12 +266,13 @@
 {
     Uint32 type;        /**< ::SDL_JOYBALLMOTION */
     Uint32 timestamp;
-    Uint8 which;        /**< The joystick instance id */
+    Uint32 which;       /**< The joystick instance id */
     Uint8 ball;         /**< The joystick trackball index */
     Uint8 padding1;
     Uint8 padding2;
-    int xrel;           /**< The relative motion in the X direction */
-    int yrel;           /**< The relative motion in the Y direction */
+    Uint8 padding3;
+    Sint16 xrel;        /**< The relative motion in the X direction */
+    Sint16 yrel;        /**< The relative motion in the Y direction */
 } SDL_JoyBallEvent;
 
 /**
@@ -270,7 +282,7 @@
 {
     Uint32 type;        /**< ::SDL_JOYHATMOTION */
     Uint32 timestamp;
-    Uint8 which;        /**< The joystick instance id */
+    Uint32 which;       /**< The joystick instance id */
     Uint8 hat;          /**< The joystick hat index */
     Uint8 value;        /**< The hat position value.
                          *   \sa ::SDL_HAT_LEFTUP ::SDL_HAT_UP ::SDL_HAT_RIGHTUP
@@ -280,6 +292,7 @@
                          *   Note that zero means the POV is centered.
                          */
     Uint8 padding1;
+    Uint8 padding2;
 } SDL_JoyHatEvent;
 
 /**
@@ -289,10 +302,11 @@
 {
     Uint32 type;        /**< ::SDL_JOYBUTTONDOWN or ::SDL_JOYBUTTONUP */
     Uint32 timestamp;
-    Uint8 which;        /**< The joystick instance id */
+    Uint32 which;       /**< The joystick instance id */
     Uint8 button;       /**< The joystick button index */
     Uint8 state;        /**< ::SDL_PRESSED or ::SDL_RELEASED */
     Uint8 padding1;
+    Uint8 padding2;
 } SDL_JoyButtonEvent;
 
 /**
@@ -302,7 +316,7 @@
 {
 	Uint32 type;        /**< ::SDL_JOYDEVICEADDED or ::SDL_JOYDEVICEREMOVED */
 	Uint32 timestamp;
-	Uint32 which;        /**< The joystick device index for ADD, instance_id for REMOVE*/
+	Uint32 which;       /**< The joystick device index for the ADDED event, instance id for the REMOVED event */
 } SDL_JoyDeviceEvent;
 
 
@@ -313,9 +327,13 @@
 {
     Uint32 type;        /**< ::SDL_CONTROLLERAXISMOTION */
     Uint32 timestamp;
-    Uint8 which;        /**< The joystick instance id */
-    SDL_GameControllerAxis axis;         /**< The joystick axis index */
-    int value;          /**< The axis value (range: -32768 to 32767) */
+    Uint32 which;       /**< The joystick instance id */
+    Uint8 axis;         /**< The controller axis (SDL_GameControllerAxis) */
+    Uint8 padding1;
+    Uint8 padding2;
+    Uint8 padding3;
+    Sint16 value;       /**< The axis value (range: -32768 to 32767) */
+    Uint16 padding4;
 } SDL_ControllerAxisEvent;
 
 
@@ -326,9 +344,11 @@
 {
     Uint32 type;        /**< ::SDL_CONTROLLERBUTTONDOWN or ::SDL_CONTROLLERBUTTONUP */
     Uint32 timestamp;
-    Uint8 which;        /**< The joystick instance id */
-    SDL_GameControllerButton button;       /**< The joystick button index */
+    Uint32 which;       /**< The joystick instance id */
+    Uint8 button;       /**< The controller button (SDL_GameControllerButton) */
     Uint8 state;        /**< ::SDL_PRESSED or ::SDL_RELEASED */
+    Uint8 padding1;
+    Uint8 padding2;
 } SDL_ControllerButtonEvent;
 
 
@@ -339,7 +359,7 @@
 {
 	Uint32 type;        /**< ::SDL_CONTROLLERDEVICEADDED or ::SDL_CONTROLLERDEVICEREMOVED */
 	Uint32 timestamp;
-	Uint32 which;        /**< The joystick device index for ADD, instance_id for REMOVE*/
+	Uint32 which;       /**< The joystick device index for the ADDED event, instance id for the REMOVED event */
 } SDL_ControllerDeviceEvent;
 
 
@@ -348,11 +368,10 @@
  */
 typedef struct SDL_TouchFingerEvent
 {
-    Uint32 type;        /**< ::SDL_FINGERMOTION OR 
-			   SDL_FINGERDOWN OR SDL_FINGERUP*/
+    Uint32 type;        /**< ::SDL_FINGERMOTION or ::SDL_FINGERDOWN or ::SDL_FINGERUP */
     Uint32 timestamp;
     Uint32 windowID;    /**< The window with mouse focus, if any */
-    SDL_TouchID touchId;        /**< The touch device id */
+    SDL_TouchID touchId; /**< The touch device id */
     SDL_FingerID fingerId;
     Uint8 state;        /**< The current button state */
     Uint8 padding1;
@@ -476,6 +495,7 @@
 typedef union SDL_Event
 {
     Uint32 type;                    /**< Event type, shared with all events */
+    SDL_GenericEvent generic;       /**< Generic event data */
     SDL_WindowEvent window;         /**< Window event data */
     SDL_KeyboardEvent key;          /**< Keyboard event data */
     SDL_TextEditingEvent edit;      /**< Text editing event data */
--- a/include/SDL_joystick.h	Fri Mar 01 11:27:01 2013 -0800
+++ b/include/SDL_joystick.h	Sat Mar 02 17:51:32 2013 -0800
@@ -67,7 +67,7 @@
 	Uint8 data[16];
 } SDL_JoystickGUID;
 
-typedef int SDL_JoystickID;
+typedef Uint32 SDL_JoystickID;
 
 
 /* Function prototypes */
--- a/src/events/SDL_events.c	Fri Mar 01 11:27:01 2013 -0800
+++ b/src/events/SDL_events.c	Sat Mar 02 17:51:32 2013 -0800
@@ -365,7 +365,7 @@
 SDL_PushEvent(SDL_Event * event)
 {
     SDL_EventWatcher *curr;
-    event->window.timestamp = SDL_GetTicks();
+    event->generic.timestamp = SDL_GetTicks();
     if (SDL_EventOK && !SDL_EventOK(SDL_EventOKParam, event)) {
         return 0;
     }
--- a/src/joystick/SDL_sysjoystick.h	Fri Mar 01 11:27:01 2013 -0800
+++ b/src/joystick/SDL_sysjoystick.h	Sat Mar 02 17:51:32 2013 -0800
@@ -28,8 +28,8 @@
 /* The SDL joystick structure */
 struct _SDL_Joystick
 {
-    int instance_id;                /* Device instance, monotonically increasing from 0 */
-    char *name;          		 /* Joystick name - system dependent */
+    SDL_JoystickID instance_id; /* Device instance, monotonically increasing from 0 */
+    char *name;                 /* Joystick name - system dependent */
 
     int naxes;                  /* Number of axis controls on the joystick */
     Sint16 *axes;               /* Current axis states */
@@ -38,8 +38,7 @@
     Uint8 *hats;                /* Current hat states */
 
     int nballs;                 /* Number of trackballs on the joystick */
-    struct balldelta
-    {
+    struct balldelta {
         int dx;
         int dy;
     } *balls;                   /* Current ball motion deltas */
@@ -50,10 +49,10 @@
     struct joystick_hwdata *hwdata;     /* Driver dependent information */
 
     int ref_count;              /* Reference count for multiple opens */
-	
-	Uint8 closed;				/* 1 if this device is no longer valid */
-	Uint8 uncentered;			/* 1 if this device needs to have its state reset to 0 */
-	struct _SDL_Joystick *next; /* pointer to next joystick we have allocated */
+
+    Uint8 closed;               /* 1 if this device is no longer valid */
+    Uint8 uncentered;           /* 1 if this device needs to have its state reset to 0 */
+    struct _SDL_Joystick *next; /* pointer to next joystick we have allocated */
 };
 
 /* Function to scan the system for joysticks.