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 697411a03a79dfe8
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
     1.1 --- a/include/SDL_events.h	Wed Mar 06 11:59:19 2013 -0800
     1.2 +++ b/include/SDL_events.h	Wed Mar 06 11:59:21 2013 -0800
     1.3 @@ -244,7 +244,7 @@
     1.4  {
     1.5      Uint32 type;        /**< ::SDL_JOYAXISMOTION */
     1.6      Uint32 timestamp;
     1.7 -    Uint32 which;       /**< The joystick instance id */
     1.8 +    SDL_JoystickID which; /**< The joystick instance id */
     1.9      Uint8 axis;         /**< The joystick axis index */
    1.10      Uint8 padding1;
    1.11      Uint8 padding2;
    1.12 @@ -259,8 +259,8 @@
    1.13  typedef struct SDL_JoyBallEvent
    1.14  {
    1.15      Uint32 type;        /**< ::SDL_JOYBALLMOTION */
    1.16 -    Uint32 timestamp;
    1.17 -    Uint32 which;       /**< The joystick instance id */
    1.18 +	Uint32 timestamp;
    1.19 +    SDL_JoystickID which; /**< The joystick instance id */
    1.20      Uint8 ball;         /**< The joystick trackball index */
    1.21      Uint8 padding1;
    1.22      Uint8 padding2;
    1.23 @@ -275,8 +275,8 @@
    1.24  typedef struct SDL_JoyHatEvent
    1.25  {
    1.26      Uint32 type;        /**< ::SDL_JOYHATMOTION */
    1.27 -    Uint32 timestamp;
    1.28 -    Uint32 which;       /**< The joystick instance id */
    1.29 +	Uint32 timestamp;
    1.30 +    SDL_JoystickID which; /**< The joystick instance id */
    1.31      Uint8 hat;          /**< The joystick hat index */
    1.32      Uint8 value;        /**< The hat position value.
    1.33                           *   \sa ::SDL_HAT_LEFTUP ::SDL_HAT_UP ::SDL_HAT_RIGHTUP
    1.34 @@ -295,8 +295,8 @@
    1.35  typedef struct SDL_JoyButtonEvent
    1.36  {
    1.37      Uint32 type;        /**< ::SDL_JOYBUTTONDOWN or ::SDL_JOYBUTTONUP */
    1.38 -    Uint32 timestamp;
    1.39 -    Uint32 which;       /**< The joystick instance id */
    1.40 +	Uint32 timestamp;
    1.41 +    SDL_JoystickID which; /**< The joystick instance id */
    1.42      Uint8 button;       /**< The joystick button index */
    1.43      Uint8 state;        /**< ::SDL_PRESSED or ::SDL_RELEASED */
    1.44      Uint8 padding1;
    1.45 @@ -310,7 +310,7 @@
    1.46  {
    1.47  	Uint32 type;        /**< ::SDL_JOYDEVICEADDED or ::SDL_JOYDEVICEREMOVED */
    1.48  	Uint32 timestamp;
    1.49 -	Uint32 which;       /**< The joystick device index for the ADDED event, instance id for the REMOVED event */
    1.50 +	Sint32 which;       /**< The joystick device index for the ADDED event, instance id for the REMOVED event */
    1.51  } SDL_JoyDeviceEvent;
    1.52  
    1.53  
    1.54 @@ -320,8 +320,8 @@
    1.55  typedef struct SDL_ControllerAxisEvent
    1.56  {
    1.57      Uint32 type;        /**< ::SDL_CONTROLLERAXISMOTION */
    1.58 -    Uint32 timestamp;
    1.59 -    Uint32 which;       /**< The joystick instance id */
    1.60 +	Uint32 timestamp;
    1.61 +    SDL_JoystickID which; /**< The joystick instance id */
    1.62      Uint8 axis;         /**< The controller axis (SDL_GameControllerAxis) */
    1.63      Uint8 padding1;
    1.64      Uint8 padding2;
    1.65 @@ -337,8 +337,8 @@
    1.66  typedef struct SDL_ControllerButtonEvent
    1.67  {
    1.68      Uint32 type;        /**< ::SDL_CONTROLLERBUTTONDOWN or ::SDL_CONTROLLERBUTTONUP */
    1.69 -    Uint32 timestamp;
    1.70 -    Uint32 which;       /**< The joystick instance id */
    1.71 +	Uint32 timestamp;
    1.72 +    SDL_JoystickID which; /**< The joystick instance id */
    1.73      Uint8 button;       /**< The controller button (SDL_GameControllerButton) */
    1.74      Uint8 state;        /**< ::SDL_PRESSED or ::SDL_RELEASED */
    1.75      Uint8 padding1;
    1.76 @@ -353,7 +353,7 @@
    1.77  {
    1.78  	Uint32 type;        /**< ::SDL_CONTROLLERDEVICEADDED, ::SDL_CONTROLLERDEVICEREMOVED, or ::SDL_CONTROLLERDEVICEREMAPPED */
    1.79  	Uint32 timestamp;
    1.80 -	Uint32 which;       /**< The joystick device index for the ADDED event, instance id for the REMOVED or REMAPPED event */
    1.81 +	Sint32 which;       /**< The joystick device index for the ADDED event, instance id for the REMOVED or REMAPPED event */
    1.82  } SDL_ControllerDeviceEvent;
    1.83  
    1.84  
     2.1 --- a/include/SDL_joystick.h	Wed Mar 06 11:59:19 2013 -0800
     2.2 +++ b/include/SDL_joystick.h	Wed Mar 06 11:59:21 2013 -0800
     2.3 @@ -67,7 +67,7 @@
     2.4  	Uint8 data[16];
     2.5  } SDL_JoystickGUID;
     2.6  
     2.7 -typedef Uint32 SDL_JoystickID;
     2.8 +typedef Sint32 SDL_JoystickID;
     2.9  
    2.10  
    2.11  /* Function prototypes */
    2.12 @@ -126,7 +126,7 @@
    2.13  extern DECLSPEC SDL_bool SDLCALL SDL_JoystickGetAttached(SDL_Joystick * joystick);
    2.14  
    2.15  /**
    2.16 - *  Get the instance ID of an opened joystick.
    2.17 + *  Get the instance ID of an opened joystick or -1 if the joystick is invalid.
    2.18   */
    2.19  extern DECLSPEC SDL_JoystickID SDLCALL SDL_JoystickInstanceID(SDL_Joystick * joystick);
    2.20  
     3.1 --- a/src/joystick/windows/SDL_dxjoystick.c	Wed Mar 06 11:59:19 2013 -0800
     3.2 +++ b/src/joystick/windows/SDL_dxjoystick.c	Wed Mar 06 11:59:21 2013 -0800
     3.3 @@ -67,7 +67,7 @@
     3.4  static LPDIRECTINPUT8 dinput = NULL;
     3.5  static SDL_bool s_bDeviceAdded = SDL_FALSE;
     3.6  static SDL_bool s_bDeviceRemoved = SDL_FALSE;
     3.7 -static int s_nInstanceID = -1;
     3.8 +static SDL_JoystickID s_nInstanceID = -1;
     3.9  static GUID *s_pKnownJoystickGUIDs = NULL;
    3.10  static SDL_cond *s_condJoystickThread = NULL;
    3.11  static SDL_mutex *s_mutexJoyStickEnum = NULL;
    3.12 @@ -85,7 +85,7 @@
    3.13  	DIDEVICEINSTANCE dxdevice;
    3.14  	char *joystickname;
    3.15  	Uint8 send_add_event;
    3.16 -	int nInstanceID;
    3.17 +	SDL_JoystickID nInstanceID;
    3.18  	SDL_bool bXInputDevice;
    3.19  	Uint8 XInputUserId;
    3.20  	struct JoyStick_DeviceData_ *pNext;