From ad0f387ccaaa512198f5de0fe842930431e9a2d6 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Wed, 6 Mar 2013 11:59:21 -0800 Subject: [PATCH] The joystick events contain a joystick instance ID, which is a signed value, with -1 being invalid. --- include/SDL_events.h | 26 +++++++++++++------------- include/SDL_joystick.h | 4 ++-- src/joystick/windows/SDL_dxjoystick.c | 4 ++-- 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/include/SDL_events.h b/include/SDL_events.h index 27e23ee2a..205467e9a 100644 --- a/include/SDL_events.h +++ b/include/SDL_events.h @@ -244,7 +244,7 @@ typedef struct SDL_JoyAxisEvent { 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_JoyAxisEvent 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_JoyBallEvent 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_JoyHatEvent 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 @@ typedef struct SDL_JoyDeviceEvent { 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_JoyDeviceEvent 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_ControllerAxisEvent 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 @@ typedef struct SDL_ControllerDeviceEvent { 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; diff --git a/include/SDL_joystick.h b/include/SDL_joystick.h index 7d218925c..c948c05b3 100644 --- a/include/SDL_joystick.h +++ b/include/SDL_joystick.h @@ -67,7 +67,7 @@ typedef struct { Uint8 data[16]; } SDL_JoystickGUID; -typedef Uint32 SDL_JoystickID; +typedef Sint32 SDL_JoystickID; /* Function prototypes */ @@ -126,7 +126,7 @@ extern DECLSPEC SDL_JoystickGUID SDLCALL SDL_JoystickGetGUIDFromString(const cha 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); diff --git a/src/joystick/windows/SDL_dxjoystick.c b/src/joystick/windows/SDL_dxjoystick.c index cf909170b..9c493cb20 100644 --- a/src/joystick/windows/SDL_dxjoystick.c +++ b/src/joystick/windows/SDL_dxjoystick.c @@ -67,7 +67,7 @@ static SDL_bool coinitialized = SDL_FALSE; 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 @@ struct JoyStick_DeviceData_ DIDEVICEINSTANCE dxdevice; char *joystickname; Uint8 send_add_event; - int nInstanceID; + SDL_JoystickID nInstanceID; SDL_bool bXInputDevice; Uint8 XInputUserId; struct JoyStick_DeviceData_ *pNext;