Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Commit

Permalink
Fixed the joystick id usage in the joystick and game controller events.
Browse files Browse the repository at this point in the history
  • Loading branch information
slouken committed Mar 3, 2013
1 parent e25dec0 commit 6e2423a
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 27 deletions.
54 changes: 37 additions & 17 deletions include/SDL_events.h
Expand Up @@ -130,6 +130,15 @@ typedef enum
SDL_LASTEVENT = 0xFFFF
} 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.*)
*/
Expand Down Expand Up @@ -241,11 +250,13 @@ typedef struct SDL_JoyAxisEvent
{
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;

/**
Expand All @@ -255,12 +266,13 @@ typedef struct SDL_JoyBallEvent
{
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;

/**
Expand All @@ -270,7 +282,7 @@ typedef struct SDL_JoyHatEvent
{
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
Expand All @@ -280,6 +292,7 @@ typedef struct SDL_JoyHatEvent
* Note that zero means the POV is centered.
*/
Uint8 padding1;
Uint8 padding2;
} SDL_JoyHatEvent;

/**
Expand All @@ -289,10 +302,11 @@ typedef struct SDL_JoyButtonEvent
{
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;

/**
Expand All @@ -302,7 +316,7 @@ typedef struct SDL_JoyDeviceEvent
{
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;


Expand All @@ -313,9 +327,13 @@ typedef struct SDL_ControllerAxisEvent
{
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;


Expand All @@ -326,9 +344,11 @@ typedef struct SDL_ControllerButtonEvent
{
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;


Expand All @@ -339,7 +359,7 @@ typedef struct SDL_ControllerDeviceEvent
{
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;


Expand All @@ -348,11 +368,10 @@ typedef struct SDL_ControllerDeviceEvent
*/
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;
Expand Down Expand Up @@ -476,6 +495,7 @@ typedef struct SDL_SysWMEvent
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 */
Expand Down
2 changes: 1 addition & 1 deletion include/SDL_joystick.h
Expand Up @@ -67,7 +67,7 @@ typedef struct {
Uint8 data[16];
} SDL_JoystickGUID;

typedef int SDL_JoystickID;
typedef Uint32 SDL_JoystickID;


/* Function prototypes */
Expand Down
2 changes: 1 addition & 1 deletion src/events/SDL_events.c
Expand Up @@ -365,7 +365,7 @@ int
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;
}
Expand Down
15 changes: 7 additions & 8 deletions src/joystick/SDL_sysjoystick.h
Expand Up @@ -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 */
Expand All @@ -38,8 +38,7 @@ struct _SDL_Joystick
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 */
Expand All @@ -50,10 +49,10 @@ struct _SDL_Joystick
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.
Expand Down

0 comments on commit 6e2423a

Please sign in to comment.