The joystick events contain a joystick instance ID, which is a signed value, with -1 being invalid.
authorSam Lantinga <slouken@libsdl.org>
Wed, 06 Mar 2013 11:59:21 -0800
changeset 6974 11a03a79dfe8
parent 6973 ae30ec97694a
child 6975 36145df5a4dc
The joystick events contain a joystick instance ID, which is a signed value, with -1 being invalid.
include/SDL_events.h
include/SDL_joystick.h
src/joystick/windows/SDL_dxjoystick.c
--- a/include/SDL_events.h	Wed Mar 06 11:59:19 2013 -0800
+++ b/include/SDL_events.h	Wed Mar 06 11:59:21 2013 -0800
@@ -244,7 +244,7 @@
 {
     Uint32 type;        /**< ::SDL_JOYAXISMOTION */
     Uint32 timestamp;
-    Uint32 which;       /**< The joystick instance id */
+    SDL_JoystickID which; /**< The joystick instance id */
     Uint8 axis;         /**< The joystick axis index */
     Uint8 padding1;
     Uint8 padding2;
@@ -259,8 +259,8 @@
 typedef struct SDL_JoyBallEvent
 {
     Uint32 type;        /**< ::SDL_JOYBALLMOTION */
-    Uint32 timestamp;
-    Uint32 which;       /**< The joystick instance id */
+	Uint32 timestamp;
+    SDL_JoystickID which; /**< The joystick instance id */
     Uint8 ball;         /**< The joystick trackball index */
     Uint8 padding1;
     Uint8 padding2;
@@ -275,8 +275,8 @@
 typedef struct SDL_JoyHatEvent
 {
     Uint32 type;        /**< ::SDL_JOYHATMOTION */
-    Uint32 timestamp;
-    Uint32 which;       /**< The joystick instance id */
+	Uint32 timestamp;
+    SDL_JoystickID 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
@@ -295,8 +295,8 @@
 typedef struct SDL_JoyButtonEvent
 {
     Uint32 type;        /**< ::SDL_JOYBUTTONDOWN or ::SDL_JOYBUTTONUP */
-    Uint32 timestamp;
-    Uint32 which;       /**< The joystick instance id */
+	Uint32 timestamp;
+    SDL_JoystickID which; /**< The joystick instance id */
     Uint8 button;       /**< The joystick button index */
     Uint8 state;        /**< ::SDL_PRESSED or ::SDL_RELEASED */
     Uint8 padding1;
@@ -310,7 +310,7 @@
 {
 	Uint32 type;        /**< ::SDL_JOYDEVICEADDED or ::SDL_JOYDEVICEREMOVED */
 	Uint32 timestamp;
-	Uint32 which;       /**< The joystick device index for the ADDED event, instance id for the REMOVED event */
+	Sint32 which;       /**< The joystick device index for the ADDED event, instance id for the REMOVED event */
 } SDL_JoyDeviceEvent;
 
 
@@ -320,8 +320,8 @@
 typedef struct SDL_ControllerAxisEvent
 {
     Uint32 type;        /**< ::SDL_CONTROLLERAXISMOTION */
-    Uint32 timestamp;
-    Uint32 which;       /**< The joystick instance id */
+	Uint32 timestamp;
+    SDL_JoystickID which; /**< The joystick instance id */
     Uint8 axis;         /**< The controller axis (SDL_GameControllerAxis) */
     Uint8 padding1;
     Uint8 padding2;
@@ -337,8 +337,8 @@
 typedef struct SDL_ControllerButtonEvent
 {
     Uint32 type;        /**< ::SDL_CONTROLLERBUTTONDOWN or ::SDL_CONTROLLERBUTTONUP */
-    Uint32 timestamp;
-    Uint32 which;       /**< The joystick instance id */
+	Uint32 timestamp;
+    SDL_JoystickID which; /**< The joystick instance id */
     Uint8 button;       /**< The controller button (SDL_GameControllerButton) */
     Uint8 state;        /**< ::SDL_PRESSED or ::SDL_RELEASED */
     Uint8 padding1;
@@ -353,7 +353,7 @@
 {
 	Uint32 type;        /**< ::SDL_CONTROLLERDEVICEADDED, ::SDL_CONTROLLERDEVICEREMOVED, or ::SDL_CONTROLLERDEVICEREMAPPED */
 	Uint32 timestamp;
-	Uint32 which;       /**< The joystick device index for the ADDED event, instance id for the REMOVED or REMAPPED event */
+	Sint32 which;       /**< The joystick device index for the ADDED event, instance id for the REMOVED or REMAPPED event */
 } SDL_ControllerDeviceEvent;
 
 
--- a/include/SDL_joystick.h	Wed Mar 06 11:59:19 2013 -0800
+++ b/include/SDL_joystick.h	Wed Mar 06 11:59:21 2013 -0800
@@ -67,7 +67,7 @@
 	Uint8 data[16];
 } SDL_JoystickGUID;
 
-typedef Uint32 SDL_JoystickID;
+typedef Sint32 SDL_JoystickID;
 
 
 /* Function prototypes */
@@ -126,7 +126,7 @@
 extern DECLSPEC SDL_bool SDLCALL SDL_JoystickGetAttached(SDL_Joystick * joystick);
 
 /**
- *  Get the instance ID of an opened joystick.
+ *  Get the instance ID of an opened joystick or -1 if the joystick is invalid.
  */
 extern DECLSPEC SDL_JoystickID SDLCALL SDL_JoystickInstanceID(SDL_Joystick * joystick);
 
--- a/src/joystick/windows/SDL_dxjoystick.c	Wed Mar 06 11:59:19 2013 -0800
+++ b/src/joystick/windows/SDL_dxjoystick.c	Wed Mar 06 11:59:21 2013 -0800
@@ -67,7 +67,7 @@
 static LPDIRECTINPUT8 dinput = NULL;
 static SDL_bool s_bDeviceAdded = SDL_FALSE;
 static SDL_bool s_bDeviceRemoved = SDL_FALSE;
-static int s_nInstanceID = -1;
+static SDL_JoystickID s_nInstanceID = -1;
 static GUID *s_pKnownJoystickGUIDs = NULL;
 static SDL_cond *s_condJoystickThread = NULL;
 static SDL_mutex *s_mutexJoyStickEnum = NULL;
@@ -85,7 +85,7 @@
 	DIDEVICEINSTANCE dxdevice;
 	char *joystickname;
 	Uint8 send_add_event;
-	int nInstanceID;
+	SDL_JoystickID nInstanceID;
 	SDL_bool bXInputDevice;
 	Uint8 XInputUserId;
 	struct JoyStick_DeviceData_ *pNext;