SDL_joystick.c File Reference
`#include "../SDL_internal.h"`
`#include "SDL.h"`
`#include "SDL_events.h"`
`#include "SDL_sysjoystick.h"`
`#include "SDL_assert.h"`
`#include "SDL_hints.h"`
`#include "../events/SDL_events_c.h"`
Include dependency graph for SDL_joystick.c:

Go to the source code of this file.

## Functions

static void | SDL_JoystickAllowBackgroundEventsChanged (void *userdata, const char *name, const char *oldValue, const char *hint)
int | SDL_JoystickInit (void)
int | SDL_NumJoysticks (void)
const char * | SDL_JoystickNameForIndex (int device_index)
SDL_Joystick * | SDL_JoystickOpen (int device_index)
int | SDL_PrivateJoystickValid (SDL_Joystick *joystick)
int | SDL_JoystickNumAxes (SDL_Joystick *joystick)
int | SDL_JoystickNumHats (SDL_Joystick *joystick)
int | SDL_JoystickNumBalls (SDL_Joystick *joystick)
int | SDL_JoystickNumButtons (SDL_Joystick *joystick)
Sint16 | SDL_JoystickGetAxis (SDL_Joystick *joystick, int axis)
Uint8 | SDL_JoystickGetHat (SDL_Joystick *joystick, int hat)
int | SDL_JoystickGetBall (SDL_Joystick *joystick, int ball, int *dx, int *dy)
Uint8 | SDL_JoystickGetButton (SDL_Joystick *joystick, int button)
SDL_bool | SDL_JoystickGetAttached (SDL_Joystick *joystick)
SDL_JoystickID | SDL_JoystickInstanceID (SDL_Joystick *joystick)
SDL_Joystick * | SDL_JoystickFromInstanceID (SDL_JoystickID joyid)
const char * | SDL_JoystickName (SDL_Joystick *joystick)
void | SDL_JoystickClose (SDL_Joystick *joystick)
void | SDL_JoystickQuit (void)
static SDL_bool | SDL_PrivateJoystickShouldIgnoreEvent ()
int | SDL_PrivateJoystickAxis (SDL_Joystick *joystick, Uint8 axis, Sint16 value)
int | SDL_PrivateJoystickHat (SDL_Joystick *joystick, Uint8 hat, Uint8 value)
int | SDL_PrivateJoystickBall (SDL_Joystick *joystick, Uint8 ball, Sint16 xrel, Sint16 yrel)
int | SDL_PrivateJoystickButton (SDL_Joystick *joystick, Uint8 button, Uint8 state)
void | SDL_JoystickUpdate (void)
int | SDL_JoystickEventState (int state)
SDL_JoystickGUID | SDL_JoystickGetDeviceGUID (int device_index)
SDL_JoystickGUID | SDL_JoystickGetGUID (SDL_Joystick *joystick)
void | SDL_JoystickGetGUIDString (SDL_JoystickGUID guid, char *pszGUID, int cbGUID)
static unsigned char | nibble (char c)
SDL_JoystickGUID | SDL_JoystickGetGUIDFromString (const char *pchGUID)
void | SDL_PrivateJoystickBatteryLevel (SDL_Joystick *joystick, SDL_JoystickPowerLevel ePowerLevel)
SDL_JoystickPowerLevel | SDL_JoystickCurrentPowerLevel (SDL_Joystick *joystick)

## Variables

static SDL_bool | SDL_joystick_allows_background_events = SDL_FALSE
static SDL_Joystick * | SDL_joysticks = NULL
static SDL_Joystick * | SDL_updating_joystick = NULL

## Function Documentation

static unsigned char nibble | ( | char | c | ) |

static

Definition at line 803 of file SDL_joystick.c.

Referenced by SDL_JoystickGetGUIDFromString().

{
if ((c >= '0') && (c <= '9')) {
return (unsigned char)(c - '0');
}
if ((c >= 'A') && (c <= 'F')) {
return (unsigned char)(c - 'A' + 0x0a);
}
if ((c >= 'a') && (c <= 'f')) {
return (unsigned char)(c - 'a' + 0x0a);
}
/* received an invalid character, and no real way to return an error */
/* AssertMsg1(false, "Q_nibble invalid hex character '%c' ", c); */
return 0;
}
c
const GLubyte * c
Definition: SDL_opengl_glext.h:11093

static void SDL_JoystickAllowBackgroundEventsChanged | ( | void * | userdata,
|  | const char * | name,
|  | const char * | oldValue,
|  | const char * | hint
| ) |  |

static

Definition at line 40 of file SDL_joystick.c.

References SDL_FALSE, SDL_joystick_allows_background_events, and SDL_TRUE.

Referenced by SDL_JoystickInit().

{
if (hint && *hint == '1') {
SDL_joystick_allows_background_events = SDL_TRUE;
} else {
SDL_joystick_allows_background_events = SDL_FALSE;
}
}
SDL_joystick_allows_background_events
static SDL_bool SDL_joystick_allows_background_events
Definition: SDL_joystick.c:35
SDL_TRUE
Definition: SDL_stdinc.h:129
SDL_FALSE
Definition: SDL_stdinc.h:128

void SDL_JoystickClose | ( | SDL_Joystick * | joystick | ) |

Close a joystick previously opened with SDL_JoystickOpen().

Definition at line 410 of file SDL_joystick.c.

References NULL, SDL_free(), SDL_joysticks, SDL_SYS_JoystickClose(), and SDL_updating_joystick.

Referenced by SDL_JoystickOpen(), SDL_JoystickQuit(), and SDL_JoystickUpdate().

{
SDL_Joystick *joysticklist;
SDL_Joystick *joysticklistprev;
if (!joystick) {
return;
}
/* First decrement ref count */
if (--joystick->ref_count > 0) {
return;
}
if (joystick == SDL_updating_joystick) {
return;
}
SDL_SYS_JoystickClose(joystick);
joystick->hwdata = NULL;
joysticklist = SDL_joysticks;
joysticklistprev = NULL;
while (joysticklist) {
if (joystick == joysticklist) {
if (joysticklistprev) {
/* unlink this entry */
joysticklistprev->next = joysticklist->next;
} else {
SDL_joysticks = joystick->next;
}
break;
}
joysticklistprev = joysticklist;
joysticklist = joysticklist->next;
}
SDL_free(joystick->name);
/* Free the data associated with this joystick */
SDL_free(joystick->axes);
SDL_free(joystick->hats);
SDL_free(joystick->balls);
SDL_free(joystick->buttons);
SDL_free(joystick);
}
SDL_updating_joystick
static SDL_Joystick * SDL_updating_joystick
Definition: SDL_joystick.c:37
SDL_free
void SDL_free(void *mem)
NULL
#define NULL
Definition: begin_code.h:143
SDL_SYS_JoystickClose
void SDL_SYS_JoystickClose(SDL_Joystick *joystick)
Definition: SDL_sysjoystick.m:586
SDL_joysticks
static SDL_Joystick * SDL_joysticks
Definition: SDL_joystick.c:36

SDL_JoystickPowerLevel SDL_JoystickCurrentPowerLevel | ( | SDL_Joystick * | joystick | ) |

Return the battery level of this joystick

Definition at line 854 of file SDL_joystick.c.

References SDL_JOYSTICK_POWER_UNKNOWN, and SDL_PrivateJoystickValid().

{
if (!SDL_PrivateJoystickValid(joystick)) {
return (SDL_JOYSTICK_POWER_UNKNOWN);
}
return joystick->epowerlevel;
}
SDL_PrivateJoystickValid
int SDL_PrivateJoystickValid(SDL_Joystick *joystick)
Definition: SDL_joystick.c:199
SDL_JOYSTICK_POWER_UNKNOWN
Definition: SDL_joystick.h:76

int SDL_JoystickEventState | ( | int | state | ) |

Enable/disable joystick event polling.

If joystick events are disabled, you must call SDL_JoystickUpdate() yourself and check the state of the joystick when you want joystick information.

The state can be one of SDL_QUERY, SDL_ENABLE or SDL_IGNORE.

Definition at line 722 of file SDL_joystick.c.

References i, SDL_arraysize, SDL_DISABLE, SDL_ENABLE, SDL_EventState, SDL_JOYAXISMOTION, SDL_JOYBALLMOTION, SDL_JOYBUTTONDOWN, SDL_JOYBUTTONUP, SDL_JOYDEVICEADDED, SDL_JOYDEVICEREMOVED, SDL_JOYHATMOTION, and SDL_QUERY.

{
#if SDL_EVENTS_DISABLED
return SDL_DISABLE;
#else
const Uint32 event_list[] = {
SDL_JOYAXISMOTION, SDL_JOYBALLMOTION, SDL_JOYHATMOTION,
SDL_JOYBUTTONDOWN, SDL_JOYBUTTONUP, SDL_JOYDEVICEADDED, SDL_JOYDEVICEREMOVED
};
unsigned int i;
switch (state) {
case SDL_QUERY:
state = SDL_DISABLE;
for (i = 0; i < SDL_arraysize(event_list); ++i) {
state = SDL_EventState(event_list[i], SDL_QUERY);
if (state == SDL_ENABLE) {
break;
}
}
break;
default:
for (i = 0; i < SDL_arraysize(event_list); ++i) {
SDL_EventState(event_list[i], state);
}
break;
}
return (state);
#endif /* SDL_EVENTS_DISABLED */
}
SDL_JOYBUTTONUP
Definition: SDL_events.h:112
SDL_JOYHATMOTION
Definition: SDL_events.h:110
Uint32
uint32_t Uint32
An unsigned 32-bit integer type.
Definition: SDL_stdinc.h:155
SDL_JOYDEVICEADDED
Definition: SDL_events.h:113
state
struct xkb_state * state
Definition: SDL_waylandsym.h:94
SDL_ENABLE
#define SDL_ENABLE
Definition: SDL_events.h:718
SDL_JOYBALLMOTION
Definition: SDL_events.h:109
SDL_JOYAXISMOTION
Definition: SDL_events.h:108
SDL_JOYDEVICEREMOVED
Definition: SDL_events.h:114
SDL_JOYBUTTONDOWN
Definition: SDL_events.h:111
i
return Display return Display Bool Bool int int int return Display XEvent Bool(*) XPointer return Display return Display Drawable _Xconst char unsigned int unsigned int return Display Pixmap Pixmap XColor XColor unsigned int unsigned int return Display _Xconst char char int char return Display Visual unsigned int int int char unsigned int unsigned int in i)
Definition: SDL_x11sym.h:42
SDL_DISABLE
#define SDL_DISABLE
Definition: SDL_events.h:717
SDL_EventState
#define SDL_EventState
Definition: SDL_dynapi_overrides.h:137
SDL_arraysize
#define SDL_arraysize(array)
Definition: SDL_stdinc.h:93
SDL_QUERY
#define SDL_QUERY
Definition: SDL_events.h:715

SDL_Joystick* SDL_JoystickFromInstanceID | ( | SDL_JoystickID | joyid | ) |

Return the SDL_Joystick associated with an instance id.

Definition at line 380 of file SDL_joystick.c.

References NULL, and SDL_joysticks.

{
SDL_Joystick *joystick = SDL_joysticks;
while (joystick) {
if (joystick->instance_id == joyid) {
return joystick;
}
joystick = joystick->next;
}
return NULL;
}
NULL
#define NULL
Definition: begin_code.h:143
SDL_joysticks
static SDL_Joystick * SDL_joysticks
Definition: SDL_joystick.c:36

SDL_bool SDL_JoystickGetAttached | ( | SDL_Joystick * | joystick | ) |

Returns SDL_TRUE if the joystick has been opened and currently connected, or SDL_FALSE if it has not.

Definition at line 354 of file SDL_joystick.c.

References SDL_FALSE, SDL_PrivateJoystickValid(), and SDL_SYS_JoystickAttached().

{
if (!SDL_PrivateJoystickValid(joystick)) {
return SDL_FALSE;
}
return SDL_SYS_JoystickAttached(joystick);
}
SDL_PrivateJoystickValid
int SDL_PrivateJoystickValid(SDL_Joystick *joystick)
Definition: SDL_joystick.c:199
SDL_SYS_JoystickAttached
SDL_bool SDL_SYS_JoystickAttached(SDL_Joystick *joystick)
Definition: SDL_sysjoystick.m:382
SDL_FALSE
Definition: SDL_stdinc.h:128

Sint16 SDL_JoystickGetAxis | ( | SDL_Joystick * | joystick,
|  | int | axis
| ) |  |

Get the current state of an axis control on a joystick.

The state is a value ranging from -32768 to 32767.

The axis indices start at index 0.

Definition at line 265 of file SDL_joystick.c.

References axis, SDL_PrivateJoystickValid(), SDL_SetError, and state.

{
Sint16 state;
if (!SDL_PrivateJoystickValid(joystick)) {
return (0);
}
if (axis < joystick->naxes) {
state = joystick->axes[axis];
} else {
SDL_SetError("Joystick only has %d axes", joystick->naxes);
state = 0;
}
return (state);
}
SDL_PrivateJoystickValid
int SDL_PrivateJoystickValid(SDL_Joystick *joystick)
Definition: SDL_joystick.c:199
state
struct xkb_state * state
Definition: SDL_waylandsym.h:94
axis
SDL_Texture * axis
Definition: testgamecontroller.c:67
SDL_SetError
#define SDL_SetError
Definition: SDL_dynapi_overrides.h:36
Sint16
int16_t Sint16
A signed 16-bit integer type.
Definition: SDL_stdinc.h:143

int SDL_JoystickGetBall | ( | SDL_Joystick * | joystick,
|  | int | ball,
|  | int * | dx,
|  | int * | dy
| ) |  |

Get the ball axis change since the last poll.

Returns
  0, or -1 if you passed it invalid parameters.

The ball indices start at index 0.

Definition at line 305 of file SDL_joystick.c.

References retval, SDL_PrivateJoystickValid(), and SDL_SetError.

{
int retval;
if (!SDL_PrivateJoystickValid(joystick)) {
return (-1);
}
retval = 0;
if (ball < joystick->nballs) {
if (dx) {
*dx = joystick->balls[ball].dx;
}
if (dy) {
*dy = joystick->balls[ball].dy;
}
joystick->balls[ball].dx = 0;
joystick->balls[ball].dy = 0;
} else {
return SDL_SetError("Joystick only has %d balls", joystick->nballs);
}
return (retval);
}
SDL_PrivateJoystickValid
int SDL_PrivateJoystickValid(SDL_Joystick *joystick)
Definition: SDL_joystick.c:199
retval
SDL_bool retval
Definition: testgamecontroller.c:65
SDL_SetError
#define SDL_SetError
Definition: SDL_dynapi_overrides.h:36

Uint8 SDL_JoystickGetButton | ( | SDL_Joystick * | joystick,
|  | int | button
| ) |  |

Get the current state of a button on a joystick.

The button indices start at index 0.

Definition at line 333 of file SDL_joystick.c.

References button, SDL_PrivateJoystickValid(), SDL_SetError, and state.

{
Uint8 state;
if (!SDL_PrivateJoystickValid(joystick)) {
return (0);
}
if (button < joystick->nbuttons) {
state = joystick->buttons[button];
} else {
SDL_SetError("Joystick only has %d buttons", joystick->nbuttons);
state = 0;
}
return (state);
}
SDL_PrivateJoystickValid
int SDL_PrivateJoystickValid(SDL_Joystick *joystick)
Definition: SDL_joystick.c:199
button
SDL_Texture * button
Definition: testgamecontroller.c:67
state
struct xkb_state * state
Definition: SDL_waylandsym.h:94
Uint8
uint8_t Uint8
An unsigned 8-bit integer type.
Definition: SDL_stdinc.h:139
SDL_SetError
#define SDL_SetError
Definition: SDL_dynapi_overrides.h:36

SDL_JoystickGUID SDL_JoystickGetDeviceGUID | ( | int | device_index | ) |

Return the GUID for the joystick at this index

Definition at line 754 of file SDL_joystick.c.

References SDL_NumJoysticks(), SDL_SetError, SDL_SYS_JoystickGetDeviceGUID(), and SDL_zero.

{
if ((device_index < 0) || (device_index >= SDL_NumJoysticks())) {
SDL_JoystickGUID emptyGUID;
SDL_SetError("There are %d joysticks available", SDL_NumJoysticks());
SDL_zero(emptyGUID);
return emptyGUID;
}
return SDL_SYS_JoystickGetDeviceGUID(device_index);
}
SDL_NumJoysticks
int SDL_NumJoysticks(void)
Definition: SDL_joystick.c:75
SDL_zero
#define SDL_zero(x)
Definition: SDL_stdinc.h:355
SDL_SetError
#define SDL_SetError
Definition: SDL_dynapi_overrides.h:36
SDL_JoystickGUID
Definition: SDL_joystick.h:68
SDL_SYS_JoystickGetDeviceGUID
SDL_JoystickGUID SDL_SYS_JoystickGetDeviceGUID(int device_index)
Definition: SDL_sysjoystick.m:639

SDL_JoystickGUID SDL_JoystickGetGUID | ( | SDL_Joystick * | joystick | ) |

Return the GUID for this opened joystick

Definition at line 766 of file SDL_joystick.c.

References SDL_PrivateJoystickValid(), SDL_SYS_JoystickGetGUID(), and SDL_zero.

{
if (!SDL_PrivateJoystickValid(joystick)) {
SDL_JoystickGUID emptyGUID;
SDL_zero(emptyGUID);
return emptyGUID;
}
return SDL_SYS_JoystickGetGUID(joystick);
}
SDL_PrivateJoystickValid
int SDL_PrivateJoystickValid(SDL_Joystick *joystick)
Definition: SDL_joystick.c:199
SDL_zero
#define SDL_zero(x)
Definition: SDL_stdinc.h:355
SDL_SYS_JoystickGetGUID
SDL_JoystickGUID SDL_SYS_JoystickGetGUID(SDL_Joystick *joystick)
Definition: SDL_sysjoystick.m:652
SDL_JoystickGUID
Definition: SDL_joystick.h:68

SDL_JoystickGUID SDL_JoystickGetGUIDFromString | ( | const char * | pchGUID | ) |

convert a string into a joystick formatted guid

Definition at line 824 of file SDL_joystick.c.

References i, nibble(), SDL_memset, and SDL_strlen.

{
SDL_JoystickGUID guid;
int maxoutputbytes= sizeof(guid);
size_t len = SDL_strlen(pchGUID);
Uint8 *p;
size_t i;
/* Make sure it's even */
len = (len) & ~0x1;
SDL_memset(&guid, 0x00, sizeof(guid));
p = (Uint8 *)&guid;
for (i = 0; (i < len) && ((p - (Uint8 *)&guid) < maxoutputbytes); i+=2, p++) {
*p = (nibble(pchGUID[i]) << 4) | nibble(pchGUID[i+1]);
}
return guid;
}
x1
GLuint GLfloat GLfloat GLfloat x1
Definition: SDL_opengl_glext.h:8583
p
GLfloat GLfloat p
Definition: SDL_opengl_glext.h:11090
len
GLenum GLsizei len
Definition: SDL_opengl_glext.h:2926
Uint8
uint8_t Uint8
An unsigned 8-bit integer type.
Definition: SDL_stdinc.h:139
i
return Display return Display Bool Bool int int int return Display XEvent Bool(*) XPointer return Display return Display Drawable _Xconst char unsigned int unsigned int return Display Pixmap Pixmap XColor XColor unsigned int unsigned int return Display _Xconst char char int char return Display Visual unsigned int int int char unsigned int unsigned int in i)
Definition: SDL_x11sym.h:42
nibble
static unsigned char nibble(char c)
Definition: SDL_joystick.c:803
SDL_strlen
#define SDL_strlen
Definition: SDL_dynapi_overrides.h:399
SDL_JoystickGUID
Definition: SDL_joystick.h:68
SDL_memset
#define SDL_memset
Definition: SDL_dynapi_overrides.h:392

void SDL_JoystickGetGUIDString | ( | SDL_JoystickGUID | guid,
|  | char * | pszGUID,
|  | int | cbGUID
| ) |  |

Return a string representation for this guid. pszGUID must point to at least 33 bytes (32 for the string plus a NULL terminator).

Definition at line 777 of file SDL_joystick.c.

References SDL_JoystickGUID::data, i, and NULL.

{
static const char k_rgchHexToASCII[] = "0123456789abcdef";
int i;
if ((pszGUID == NULL) || (cbGUID <= 0)) {
return;
}
for (i = 0; i < sizeof(guid.data) && i < (cbGUID-1)/2; i++) {
/* each input byte writes 2 ascii chars, and might write a null byte. */
/* If we don't have room for next input byte, stop */
unsigned char c = guid.data[i];
*pszGUID++ = k_rgchHexToASCII[c >> 4];
*pszGUID++ = k_rgchHexToASCII[c & 0x0F];
}
*pszGUID = '\0';
}
SDL_JoystickGUID::data
Uint8 data[16]
Definition: SDL_joystick.h:69
c
const GLubyte * c
Definition: SDL_opengl_glext.h:11093
i
return Display return Display Bool Bool int int int return Display XEvent Bool(*) XPointer return Display return Display Drawable _Xconst char unsigned int unsigned int return Display Pixmap Pixmap XColor XColor unsigned int unsigned int return Display _Xconst char char int char return Display Visual unsigned int int int char unsigned int unsigned int in i)
Definition: SDL_x11sym.h:42
NULL
#define NULL
Definition: begin_code.h:143

Uint8 SDL_JoystickGetHat | ( | SDL_Joystick * | joystick,
|  | int | hat
| ) |  |

Get the current state of a POV hat on a joystick.

The hat indices start at index 0.

Returns
  The return value is one of the following positions:
  - SDL_HAT_CENTERED
  - SDL_HAT_UP
  - SDL_HAT_RIGHT
  - SDL_HAT_DOWN
  - SDL_HAT_LEFT
  - SDL_HAT_RIGHTUP
  - SDL_HAT_RIGHTDOWN
  - SDL_HAT_LEFTUP
  - SDL_HAT_LEFTDOWN

Definition at line 285 of file SDL_joystick.c.

References SDL_PrivateJoystickValid(), SDL_SetError, and state.

{
Uint8 state;
if (!SDL_PrivateJoystickValid(joystick)) {
return (0);
}
if (hat < joystick->nhats) {
state = joystick->hats[hat];
} else {
SDL_SetError("Joystick only has %d hats", joystick->nhats);
state = 0;
}
return (state);
}
SDL_PrivateJoystickValid
int SDL_PrivateJoystickValid(SDL_Joystick *joystick)
Definition: SDL_joystick.c:199
state
struct xkb_state * state
Definition: SDL_waylandsym.h:94
Uint8
uint8_t Uint8
An unsigned 8-bit integer type.
Definition: SDL_stdinc.h:139
SDL_SetError
#define SDL_SetError
Definition: SDL_dynapi_overrides.h:36

int SDL_JoystickInit | ( | void |  | ) |

Definition at line 50 of file SDL_joystick.c.

References NULL, SDL_AddHintCallback, SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS, SDL_INIT_EVENTS, SDL_InitSubSystem, SDL_JoystickAllowBackgroundEventsChanged(), and SDL_SYS_JoystickInit().

Referenced by SDL_InitSubSystem().

{
int status;
/* See if we should allow joystick events while in the background */
SDL_AddHintCallback(SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS,
SDL_JoystickAllowBackgroundEventsChanged, NULL);
#if !SDL_EVENTS_DISABLED
if (SDL_InitSubSystem(SDL_INIT_EVENTS) < 0) {
return -1;
}
#endif /* !SDL_EVENTS_DISABLED */
status = SDL_SYS_JoystickInit();
if (status >= 0) {
status = 0;
}
return (status);
}
SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS
#define SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS
A variable that lets you enable joystick (and gamecontroller) events even when your app is in the bac...
Definition: SDL_hints.h:334
SDL_INIT_EVENTS
#define SDL_INIT_EVENTS
Definition: SDL.h:81
SDL_InitSubSystem
#define SDL_InitSubSystem
Definition: SDL_dynapi_overrides.h:61
SDL_SYS_JoystickInit
int SDL_SYS_JoystickInit(void)
Definition: SDL_sysjoystick.m:260
NULL
#define NULL
Definition: begin_code.h:143
SDL_AddHintCallback
#define SDL_AddHintCallback
Definition: SDL_dynapi_overrides.h:198
SDL_JoystickAllowBackgroundEventsChanged
static void SDL_JoystickAllowBackgroundEventsChanged(void *userdata, const char *name, const char *oldValue, const char *hint)
Definition: SDL_joystick.c:40

SDL_JoystickID SDL_JoystickInstanceID | ( | SDL_Joystick * | joystick | ) |

Get the instance ID of an opened joystick or -1 if the joystick is invalid.

Definition at line 367 of file SDL_joystick.c.

References SDL_PrivateJoystickValid().

{
if (!SDL_PrivateJoystickValid(joystick)) {
return (-1);
}
return (joystick->instance_id);
}
SDL_PrivateJoystickValid
int SDL_PrivateJoystickValid(SDL_Joystick *joystick)
Definition: SDL_joystick.c:199

const char* SDL_JoystickName | ( | SDL_Joystick * | joystick | ) |

Return the name for this currently opened joystick. If no name can be found, this function returns NULL.

Definition at line 397 of file SDL_joystick.c.

References NULL, and SDL_PrivateJoystickValid().

{
if (!SDL_PrivateJoystickValid(joystick)) {
return (NULL);
}
return (joystick->name);
}
SDL_PrivateJoystickValid
int SDL_PrivateJoystickValid(SDL_Joystick *joystick)
Definition: SDL_joystick.c:199
NULL
#define NULL
Definition: begin_code.h:143

const char* SDL_JoystickNameForIndex | ( | int | device_index | ) |

Get the implementation dependent name of a joystick. This can be called before any joysticks are opened. If no name can be found, this function returns NULL.

Definition at line 84 of file SDL_joystick.c.

References NULL, SDL_NumJoysticks(), SDL_SetError, and SDL_SYS_JoystickNameForDeviceIndex().

{
if ((device_index < 0) || (device_index >= SDL_NumJoysticks())) {
SDL_SetError("There are %d joysticks available", SDL_NumJoysticks());
return (NULL);
}
return (SDL_SYS_JoystickNameForDeviceIndex(device_index));
}
SDL_NumJoysticks
int SDL_NumJoysticks(void)
Definition: SDL_joystick.c:75
SDL_SYS_JoystickNameForDeviceIndex
const char * SDL_SYS_JoystickNameForDeviceIndex(int device_index)
Definition: SDL_sysjoystick.m:320
NULL
#define NULL
Definition: begin_code.h:143
SDL_SetError
#define SDL_SetError
Definition: SDL_dynapi_overrides.h:36

int SDL_JoystickNumAxes | ( | SDL_Joystick * | joystick | ) |

Get the number of general axis controls on a joystick.

Definition at line 217 of file SDL_joystick.c.

References SDL_PrivateJoystickValid().

{
if (!SDL_PrivateJoystickValid(joystick)) {
return (-1);
}
return (joystick->naxes);
}
SDL_PrivateJoystickValid
int SDL_PrivateJoystickValid(SDL_Joystick *joystick)
Definition: SDL_joystick.c:199

int SDL_JoystickNumBalls | ( | SDL_Joystick * | joystick | ) |

Get the number of trackballs on a joystick.

Joystick trackballs have only relative motion events associated with them and their state cannot be polled.

Definition at line 241 of file SDL_joystick.c.

References SDL_PrivateJoystickValid().

{
if (!SDL_PrivateJoystickValid(joystick)) {
return (-1);
}
return (joystick->nballs);
}
SDL_PrivateJoystickValid
int SDL_PrivateJoystickValid(SDL_Joystick *joystick)
Definition: SDL_joystick.c:199

int SDL_JoystickNumButtons | ( | SDL_Joystick * | joystick | ) |

Get the number of buttons on a joystick.

Definition at line 253 of file SDL_joystick.c.

References SDL_PrivateJoystickValid().

{
if (!SDL_PrivateJoystickValid(joystick)) {
return (-1);
}
return (joystick->nbuttons);
}
SDL_PrivateJoystickValid
int SDL_PrivateJoystickValid(SDL_Joystick *joystick)
Definition: SDL_joystick.c:199

int SDL_JoystickNumHats | ( | SDL_Joystick * | joystick | ) |

Get the number of POV hats on a joystick.

Definition at line 229 of file SDL_joystick.c.

References SDL_PrivateJoystickValid().

{
if (!SDL_PrivateJoystickValid(joystick)) {
return (-1);
}
return (joystick->nhats);
}
SDL_PrivateJoystickValid
int SDL_PrivateJoystickValid(SDL_Joystick *joystick)
Definition: SDL_joystick.c:199

SDL_Joystick* SDL_JoystickOpen | ( | int | device_index | ) |

Open a joystick for use. The index passed as an argument refers to the N'th joystick on the system. This index is not the value which will identify this joystick in future joystick events. The joystick's instance id (SDL_JoystickID) will be used there instead.

Returns
  A joystick identifier, or NULL if an error occurred.

Definition at line 101 of file SDL_joystick.c.

References SDL_GameController::joystick, NULL, SDL_free(), SDL_JOYSTICK_POWER_UNKNOWN, SDL_JoystickClose(), SDL_joysticks, SDL_malloc, SDL_memset, SDL_NumJoysticks(), SDL_OutOfMemory, SDL_SetError, SDL_strdup, SDL_SYS_GetInstanceIdOfDeviceIndex(), SDL_SYS_JoystickNameForDeviceIndex(), SDL_SYS_JoystickOpen(), and SDL_SYS_JoystickUpdate().

{
SDL_Joystick *joystick;
SDL_Joystick *joysticklist;
const char *joystickname = NULL;
if ((device_index < 0) || (device_index >= SDL_NumJoysticks())) {
SDL_SetError("There are %d joysticks available", SDL_NumJoysticks());
return (NULL);
}
joysticklist = SDL_joysticks;
/* If the joystick is already open, return it
* it is important that we have a single joystick * for each instance id
*/
while (joysticklist) {
if (SDL_SYS_GetInstanceIdOfDeviceIndex(device_index) == joysticklist->instance_id) {
joystick = joysticklist;
++joystick->ref_count;
return (joystick);
}
joysticklist = joysticklist->next;
}
/* Create and initialize the joystick */
joystick = (SDL_Joystick *) SDL_malloc((sizeof *joystick));
if (joystick == NULL) {
SDL_OutOfMemory();
return NULL;
}
SDL_memset(joystick, 0, (sizeof *joystick));
if (SDL_SYS_JoystickOpen(joystick, device_index) < 0) {
SDL_free(joystick);
return NULL;
}
joystickname = SDL_SYS_JoystickNameForDeviceIndex(device_index);
if (joystickname)
joystick->name = SDL_strdup(joystickname);
else
joystick->name = NULL;
if (joystick->naxes > 0) {
joystick->axes = (Sint16 *) SDL_malloc
(joystick->naxes * sizeof(Sint16));
}
if (joystick->nhats > 0) {
joystick->hats = (Uint8 *) SDL_malloc
(joystick->nhats * sizeof(Uint8));
}
if (joystick->nballs > 0) {
joystick->balls = (struct balldelta *) SDL_malloc
(joystick->nballs * sizeof(*joystick->balls));
}
if (joystick->nbuttons > 0) {
joystick->buttons = (Uint8 *) SDL_malloc
(joystick->nbuttons * sizeof(Uint8));
}
if (((joystick->naxes > 0) && !joystick->axes)
|| ((joystick->nhats > 0) && !joystick->hats)
|| ((joystick->nballs > 0) && !joystick->balls)
|| ((joystick->nbuttons > 0) && !joystick->buttons)) {
SDL_OutOfMemory();
SDL_JoystickClose(joystick);
return NULL;
}
if (joystick->axes) {
SDL_memset(joystick->axes, 0, joystick->naxes * sizeof(Sint16));
}
if (joystick->hats) {
SDL_memset(joystick->hats, 0, joystick->nhats * sizeof(Uint8));
}
if (joystick->balls) {
SDL_memset(joystick->balls, 0,
joystick->nballs * sizeof(*joystick->balls));
}
if (joystick->buttons) {
SDL_memset(joystick->buttons, 0, joystick->nbuttons * sizeof(Uint8));
}
joystick->epowerlevel = SDL_JOYSTICK_POWER_UNKNOWN;
/* Add joystick to list */
++joystick->ref_count;
/* Link the joystick in the list */
joystick->next = SDL_joysticks;
SDL_joysticks = joystick;
SDL_SYS_JoystickUpdate(joystick);
return (joystick);
}
SDL_JoystickClose
void SDL_JoystickClose(SDL_Joystick *joystick)
Definition: SDL_joystick.c:410
SDL_NumJoysticks
int SDL_NumJoysticks(void)
Definition: SDL_joystick.c:75
Uint8
uint8_t Uint8
An unsigned 8-bit integer type.
Definition: SDL_stdinc.h:139
SDL_free
void SDL_free(void *mem)
SDL_SYS_JoystickNameForDeviceIndex
const char * SDL_SYS_JoystickNameForDeviceIndex(int device_index)
Definition: SDL_sysjoystick.m:320
SDL_JOYSTICK_POWER_UNKNOWN
Definition: SDL_joystick.h:76
SDL_SYS_JoystickUpdate
void SDL_SYS_JoystickUpdate(SDL_Joystick *joystick)
Definition: SDL_sysjoystick.m:569
NULL
#define NULL
Definition: begin_code.h:143
SDL_OutOfMemory
#define SDL_OutOfMemory()
Definition: SDL_error.h:52
SDL_SetError
#define SDL_SetError
Definition: SDL_dynapi_overrides.h:36
SDL_strdup
#define SDL_strdup
Definition: SDL_dynapi_overrides.h:403
SDL_SYS_GetInstanceIdOfDeviceIndex
SDL_JoystickID SDL_SYS_GetInstanceIdOfDeviceIndex(int device_index)
Definition: SDL_sysjoystick.m:327
SDL_SYS_JoystickOpen
int SDL_SYS_JoystickOpen(SDL_Joystick *joystick, int device_index)
Definition: SDL_sysjoystick.m:339
SDL_malloc
#define SDL_malloc
Definition: SDL_dynapi_overrides.h:380
SDL_memset
#define SDL_memset
Definition: SDL_dynapi_overrides.h:392
Sint16
int16_t Sint16
A signed 16-bit integer type.
Definition: SDL_stdinc.h:143
SDL_joysticks
static SDL_Joystick * SDL_joysticks
Definition: SDL_joystick.c:36

void SDL_JoystickQuit | ( | void |  | ) |

Definition at line 458 of file SDL_joystick.c.

References SDL_assert, SDL_INIT_EVENTS, SDL_JoystickClose(), SDL_joysticks, SDL_QuitSubSystem, SDL_SYS_JoystickQuit(), and SDL_updating_joystick.

Referenced by SDL_QuitSubSystem().

{
/* Make sure we're not getting called in the middle of updating joysticks */
SDL_assert(!SDL_updating_joystick);
/* Stop the event polling */
while (SDL_joysticks) {
SDL_joysticks->ref_count = 1;
SDL_JoystickClose(SDL_joysticks);
}
/* Quit the joystick setup */
SDL_SYS_JoystickQuit();
#if !SDL_EVENTS_DISABLED
SDL_QuitSubSystem(SDL_INIT_EVENTS);
#endif
}
SDL_INIT_EVENTS
#define SDL_INIT_EVENTS
Definition: SDL.h:81
SDL_updating_joystick
static SDL_Joystick * SDL_updating_joystick
Definition: SDL_joystick.c:37
SDL_JoystickClose
void SDL_JoystickClose(SDL_Joystick *joystick)
Definition: SDL_joystick.c:410
SDL_QuitSubSystem
#define SDL_QuitSubSystem
Definition: SDL_dynapi_overrides.h:62
SDL_SYS_JoystickQuit
void SDL_SYS_JoystickQuit(void)
Definition: SDL_sysjoystick.m:611
SDL_assert
#define SDL_assert(condition)
Definition: SDL_assert.h:167
SDL_joysticks
static SDL_Joystick * SDL_joysticks
Definition: SDL_joystick.c:36

void SDL_JoystickUpdate | ( | void |  | ) |

Update the current state of the open joysticks.

This is called automatically by the event loop if any joystick events are enabled.

Definition at line 670 of file SDL_joystick.c.

References i, NULL, SDL_FALSE, SDL_HAT_CENTERED, SDL_JoystickClose(), SDL_joysticks, SDL_PrivateJoystickAxis(), SDL_PrivateJoystickButton(), SDL_PrivateJoystickHat(), SDL_SYS_JoystickDetect(), SDL_SYS_JoystickUpdate(), and SDL_updating_joystick.

{
SDL_Joystick *joystick;
joystick = SDL_joysticks;
while (joystick) {
SDL_Joystick *joysticknext;
/* save off the next pointer, the Update call may cause a joystick removed event
* and cause our joystick pointer to be freed
*/
joysticknext = joystick->next;
SDL_updating_joystick = joystick;
SDL_SYS_JoystickUpdate(joystick);
if (joystick->force_recentering) {
int i;
/* Tell the app that everything is centered/unpressed... */
for (i = 0; i < joystick->naxes; i++) {
SDL_PrivateJoystickAxis(joystick, i, 0);
}
for (i = 0; i < joystick->nbuttons; i++) {
SDL_PrivateJoystickButton(joystick, i, 0);
}
for (i = 0; i < joystick->nhats; i++) {
SDL_PrivateJoystickHat(joystick, i, SDL_HAT_CENTERED);
}
joystick->force_recentering = SDL_FALSE;
}
SDL_updating_joystick = NULL;
/* If the joystick was closed while updating, free it here */
if (joystick->ref_count <= 0) {
SDL_JoystickClose(joystick);
}
joystick = joysticknext;
}
/* this needs to happen AFTER walking the joystick list above, so that any
dangling hardware data from removed devices can be free'd
*/
SDL_SYS_JoystickDetect();
}
SDL_updating_joystick
static SDL_Joystick * SDL_updating_joystick
Definition: SDL_joystick.c:37
SDL_JoystickClose
void SDL_JoystickClose(SDL_Joystick *joystick)
Definition: SDL_joystick.c:410
SDL_PrivateJoystickHat
int SDL_PrivateJoystickHat(SDL_Joystick *joystick, Uint8 hat, Uint8 value)
Definition: SDL_joystick.c:542
SDL_PrivateJoystickButton
int SDL_PrivateJoystickButton(SDL_Joystick *joystick, Uint8 button, Uint8 state)
Definition: SDL_joystick.c:618
SDL_PrivateJoystickAxis
int SDL_PrivateJoystickAxis(SDL_Joystick *joystick, Uint8 axis, Sint16 value)
Definition: SDL_joystick.c:501
SDL_SYS_JoystickDetect
void SDL_SYS_JoystickDetect()
Definition: SDL_sysjoystick.m:314
SDL_SYS_JoystickUpdate
void SDL_SYS_JoystickUpdate(SDL_Joystick *joystick)
Definition: SDL_sysjoystick.m:569
i
return Display return Display Bool Bool int int int return Display XEvent Bool(*) XPointer return Display return Display Drawable _Xconst char unsigned int unsigned int return Display Pixmap Pixmap XColor XColor unsigned int unsigned int return Display _Xconst char char int char return Display Visual unsigned int int int char unsigned int unsigned int in i)
Definition: SDL_x11sym.h:42
NULL
#define NULL
Definition: begin_code.h:143
SDL_FALSE
Definition: SDL_stdinc.h:128
SDL_HAT_CENTERED
#define SDL_HAT_CENTERED
Definition: SDL_joystick.h:207
SDL_joysticks
static SDL_Joystick * SDL_joysticks
Definition: SDL_joystick.c:36

int SDL_NumJoysticks | ( | void |  | ) |

Count the number of joysticks attached to the system right now

Definition at line 75 of file SDL_joystick.c.

References SDL_SYS_NumJoysticks().

Referenced by SDL_JoystickGetDeviceGUID(), SDL_JoystickNameForIndex(), and SDL_JoystickOpen().

{
return SDL_SYS_NumJoysticks();
}
SDL_SYS_NumJoysticks
int SDL_SYS_NumJoysticks()
Definition: SDL_sysjoystick.m:309

int SDL_PrivateJoystickAxis | ( | SDL_Joystick * | joystick,
|  | Uint8 | axis,
|  | Sint16 | value
| ) |  |

Definition at line 501 of file SDL_joystick.c.

References axis, SDL_ENABLE, SDL_GetEventState, SDL_JOYAXISMOTION, SDL_PrivateJoystickShouldIgnoreEvent(), and SDL_PushEvent.

Referenced by SDL_JoystickUpdate(), SDL_SYS_AccelerometerUpdate(), and SDL_SYS_MFIJoystickUpdate().

{
int posted;
/* Make sure we're not getting garbage or duplicate events */
if (axis >= joystick->naxes) {
return 0;
}
if (value == joystick->axes[axis]) {
return 0;
}
/* We ignore events if we don't have keyboard focus, except for centering
* events.
*/
if (SDL_PrivateJoystickShouldIgnoreEvent()) {
if ((value > 0 && value >= joystick->axes[axis]) ||
(value < 0 && value <= joystick->axes[axis])) {
return 0;
}
}
/* Update internal joystick state */
joystick->axes[axis] = value;
/* Post the event, if desired */
posted = 0;
#if !SDL_EVENTS_DISABLED
if (SDL_GetEventState(SDL_JOYAXISMOTION) == SDL_ENABLE) {
SDL_Event event;
event.type = SDL_JOYAXISMOTION;
event.jaxis.which = joystick->instance_id;
event.jaxis.axis = axis;
event.jaxis.value = value;
posted = SDL_PushEvent(&event) == 1;
}
#endif /* !SDL_EVENTS_DISABLED */
return (posted);
}
SDL_ENABLE
#define SDL_ENABLE
Definition: SDL_events.h:718
axis
SDL_Texture * axis
Definition: testgamecontroller.c:67
SDL_JOYAXISMOTION
Definition: SDL_events.h:108
SDL_GetEventState
#define SDL_GetEventState(type)
Definition: SDL_events.h:731
value
GLsizei const GLfloat * value
Definition: SDL_opengl_glext.h:698
event
struct _cl_event * event
Definition: SDL_opengl_glext.h:2649
SDL_PushEvent
#define SDL_PushEvent
Definition: SDL_dynapi_overrides.h:131
SDL_PrivateJoystickShouldIgnoreEvent
static SDL_bool SDL_PrivateJoystickShouldIgnoreEvent()
Definition: SDL_joystick.c:479
SDL_Event
General event structure.
Definition: SDL_events.h:521

int SDL_PrivateJoystickBall | ( | SDL_Joystick * | joystick,
|  | Uint8 | ball,
|  | Sint16 | xrel,
|  | Sint16 | yrel
| ) |  |

Definition at line 582 of file SDL_joystick.c.

References SDL_ENABLE, SDL_GetEventState, SDL_JOYBALLMOTION, SDL_PrivateJoystickShouldIgnoreEvent(), and SDL_PushEvent.

{
int posted;
/* Make sure we're not getting garbage events */
if (ball >= joystick->nballs) {
return 0;
}
/* We ignore events if we don't have keyboard focus. */
if (SDL_PrivateJoystickShouldIgnoreEvent()) {
return 0;
}
/* Update internal mouse state */
joystick->balls[ball].dx += xrel;
joystick->balls[ball].dy += yrel;
/* Post the event, if desired */
posted = 0;
#if !SDL_EVENTS_DISABLED
if (SDL_GetEventState(SDL_JOYBALLMOTION) == SDL_ENABLE) {
SDL_Event event;
event.jball.type = SDL_JOYBALLMOTION;
event.jball.which = joystick->instance_id;
event.jball.ball = ball;
event.jball.xrel = xrel;
event.jball.yrel = yrel;
posted = SDL_PushEvent(&event) == 1;
}
#endif /* !SDL_EVENTS_DISABLED */
return (posted);
}
SDL_ENABLE
#define SDL_ENABLE
Definition: SDL_events.h:718
SDL_JOYBALLMOTION
Definition: SDL_events.h:109
SDL_GetEventState
#define SDL_GetEventState(type)
Definition: SDL_events.h:731
event
struct _cl_event * event
Definition: SDL_opengl_glext.h:2649
SDL_PushEvent
#define SDL_PushEvent
Definition: SDL_dynapi_overrides.h:131
SDL_PrivateJoystickShouldIgnoreEvent
static SDL_bool SDL_PrivateJoystickShouldIgnoreEvent()
Definition: SDL_joystick.c:479
SDL_Event
General event structure.
Definition: SDL_events.h:521

void SDL_PrivateJoystickBatteryLevel | ( | SDL_Joystick * | joystick,
|  | SDL_JoystickPowerLevel | ePowerLevel
| ) |  |

Definition at line 847 of file SDL_joystick.c.

{
joystick->epowerlevel = ePowerLevel;
}

int SDL_PrivateJoystickButton | ( | SDL_Joystick * | joystick,
|  | Uint8 | button,
|  | Uint8 | state
| ) |  |

Definition at line 618 of file SDL_joystick.c.

References button, SDL_ENABLE, SDL_GetEventState, SDL_JOYBUTTONDOWN, SDL_JOYBUTTONUP, SDL_PRESSED, SDL_PrivateJoystickShouldIgnoreEvent(), SDL_PushEvent, SDL_RELEASED, state, and SDL_Event::type.

Referenced by SDL_JoystickUpdate(), and SDL_SYS_MFIJoystickUpdate().

{
int posted;
#if !SDL_EVENTS_DISABLED
SDL_Event event;
switch (state) {
case SDL_PRESSED:
event.type = SDL_JOYBUTTONDOWN;
break;
case SDL_RELEASED:
event.type = SDL_JOYBUTTONUP;
break;
default:
/* Invalid state -- bail */
return (0);
}
#endif /* !SDL_EVENTS_DISABLED */
/* Make sure we're not getting garbage or duplicate events */
if (button >= joystick->nbuttons) {
return 0;
}
if (state == joystick->buttons[button]) {
return 0;
}
/* We ignore events if we don't have keyboard focus, except for button
* release. */
if (SDL_PrivateJoystickShouldIgnoreEvent()) {
if (state == SDL_PRESSED) {
return 0;
}
}
/* Update internal joystick state */
joystick->buttons[button] = state;
/* Post the event, if desired */
posted = 0;
#if !SDL_EVENTS_DISABLED
if (SDL_GetEventState(event.type) == SDL_ENABLE) {
event.jbutton.which = joystick->instance_id;
event.jbutton.button = button;
event.jbutton.state = state;
posted = SDL_PushEvent(&event) == 1;
}
#endif /* !SDL_EVENTS_DISABLED */
return (posted);
}
SDL_JOYBUTTONUP
Definition: SDL_events.h:112
button
SDL_Texture * button
Definition: testgamecontroller.c:67
state
struct xkb_state * state
Definition: SDL_waylandsym.h:94
SDL_ENABLE
#define SDL_ENABLE
Definition: SDL_events.h:718
SDL_GetEventState
#define SDL_GetEventState(type)
Definition: SDL_events.h:731
SDL_JOYBUTTONDOWN
Definition: SDL_events.h:111
event
struct _cl_event * event
Definition: SDL_opengl_glext.h:2649
SDL_PushEvent
#define SDL_PushEvent
Definition: SDL_dynapi_overrides.h:131
SDL_PrivateJoystickShouldIgnoreEvent
static SDL_bool SDL_PrivateJoystickShouldIgnoreEvent()
Definition: SDL_joystick.c:479
SDL_Event
General event structure.
Definition: SDL_events.h:521
SDL_PRESSED
#define SDL_PRESSED
Definition: SDL_events.h:50
SDL_RELEASED
#define SDL_RELEASED
Definition: SDL_events.h:49
SDL_Event::type
Uint32 type
Definition: SDL_events.h:523

int SDL_PrivateJoystickHat | ( | SDL_Joystick * | joystick,
|  | Uint8 | hat,
|  | Uint8 | value
| ) |  |

Definition at line 542 of file SDL_joystick.c.

References SDL_ENABLE, SDL_GetEventState, SDL_HAT_CENTERED, SDL_JOYHATMOTION, SDL_PrivateJoystickShouldIgnoreEvent(), and SDL_PushEvent.

Referenced by SDL_JoystickUpdate(), and SDL_SYS_MFIJoystickUpdate().

{
int posted;
/* Make sure we're not getting garbage or duplicate events */
if (hat >= joystick->nhats) {
return 0;
}
if (value == joystick->hats[hat]) {
return 0;
}
/* We ignore events if we don't have keyboard focus, except for centering
* events.
*/
if (SDL_PrivateJoystickShouldIgnoreEvent()) {
if (value != SDL_HAT_CENTERED) {
return 0;
}
}
/* Update internal joystick state */
joystick->hats[hat] = value;
/* Post the event, if desired */
posted = 0;
#if !SDL_EVENTS_DISABLED
if (SDL_GetEventState(SDL_JOYHATMOTION) == SDL_ENABLE) {
SDL_Event event;
event.jhat.type = SDL_JOYHATMOTION;
event.jhat.which = joystick->instance_id;
event.jhat.hat = hat;
event.jhat.value = value;
posted = SDL_PushEvent(&event) == 1;
}
#endif /* !SDL_EVENTS_DISABLED */
return (posted);
}
SDL_JOYHATMOTION
Definition: SDL_events.h:110
SDL_ENABLE
#define SDL_ENABLE
Definition: SDL_events.h:718
SDL_GetEventState
#define SDL_GetEventState(type)
Definition: SDL_events.h:731
value
GLsizei const GLfloat * value
Definition: SDL_opengl_glext.h:698
event
struct _cl_event * event
Definition: SDL_opengl_glext.h:2649
SDL_PushEvent
#define SDL_PushEvent
Definition: SDL_dynapi_overrides.h:131
SDL_PrivateJoystickShouldIgnoreEvent
static SDL_bool SDL_PrivateJoystickShouldIgnoreEvent()
Definition: SDL_joystick.c:479
SDL_Event
General event structure.
Definition: SDL_events.h:521
SDL_HAT_CENTERED
#define SDL_HAT_CENTERED
Definition: SDL_joystick.h:207

static SDL_bool SDL_PrivateJoystickShouldIgnoreEvent | ( |  | ) |

static

Definition at line 479 of file SDL_joystick.c.

References NULL, SDL_FALSE, SDL_GetKeyboardFocus, SDL_INIT_VIDEO, SDL_joystick_allows_background_events, SDL_TRUE, and SDL_WasInit.

Referenced by SDL_PrivateJoystickAxis(), SDL_PrivateJoystickBall(), SDL_PrivateJoystickButton(), and SDL_PrivateJoystickHat().

{
if (SDL_joystick_allows_background_events) {
return SDL_FALSE;
}
if (SDL_WasInit(SDL_INIT_VIDEO)) {
if (SDL_GetKeyboardFocus() == NULL) {
/* Video is initialized and we don't have focus, ignore the event. */
return SDL_TRUE;
} else {
return SDL_FALSE;
}
}
/* Video subsystem wasn't initialized, always allow the event */
return SDL_FALSE;
}
SDL_GetKeyboardFocus
#define SDL_GetKeyboardFocus
Definition: SDL_dynapi_overrides.h:222
SDL_joystick_allows_background_events
static SDL_bool SDL_joystick_allows_background_events
Definition: SDL_joystick.c:35
SDL_TRUE
Definition: SDL_stdinc.h:129
NULL
#define NULL
Definition: begin_code.h:143
SDL_FALSE
Definition: SDL_stdinc.h:128
SDL_WasInit
#define SDL_WasInit
Definition: SDL_dynapi_overrides.h:63
SDL_INIT_VIDEO
#define SDL_INIT_VIDEO
Definition: SDL.h:77

int SDL_PrivateJoystickValid | ( | SDL_Joystick * | joystick | ) |

Definition at line 199 of file SDL_joystick.c.

References NULL, and SDL_SetError.

Referenced by SDL_HapticOpenFromJoystick(), SDL_JoystickCurrentPowerLevel(), SDL_JoystickGetAttached(), SDL_JoystickGetAxis(), SDL_JoystickGetBall(), SDL_JoystickGetButton(), SDL_JoystickGetGUID(), SDL_JoystickGetHat(), SDL_JoystickInstanceID(), SDL_JoystickIsHaptic(), SDL_JoystickName(), SDL_JoystickNumAxes(), SDL_JoystickNumBalls(), SDL_JoystickNumButtons(), and SDL_JoystickNumHats().

{
int valid;
if (joystick == NULL) {
SDL_SetError("Joystick hasn't been opened yet");
valid = 0;
} else {
valid = 1;
}
return valid;
}
NULL
#define NULL
Definition: begin_code.h:143
SDL_SetError
#define SDL_SetError
Definition: SDL_dynapi_overrides.h:36

## Variable Documentation

SDL_bool SDL_joystick_allows_background_events = SDL_FALSE

static

Definition at line 35 of file SDL_joystick.c.

Referenced by SDL_JoystickAllowBackgroundEventsChanged(), and SDL_PrivateJoystickShouldIgnoreEvent().

SDL_Joystick* SDL_joysticks = NULL

static

Definition at line 36 of file SDL_joystick.c.

Referenced by SDL_JoystickClose(), SDL_JoystickFromInstanceID(), SDL_JoystickOpen(), SDL_JoystickQuit(), and SDL_JoystickUpdate().

SDL_Joystick* SDL_updating_joystick = NULL

static

Definition at line 37 of file SDL_joystick.c.

Referenced by SDL_JoystickClose(), SDL_JoystickQuit(), and SDL_JoystickUpdate().