SDL_joystick_c.h File Reference
`#include "../SDL_internal.h"`
`#include "SDL_joystick.h"`
Include dependency graph for SDL_joystick_c.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

## Functions

int | SDL_JoystickInit (void)
void | SDL_JoystickQuit (void)
int | SDL_GameControllerInitMappings (void)
void | SDL_GameControllerQuitMappings (void)
int | SDL_GameControllerInit (void)
void | SDL_GameControllerQuit (void)
void | SDL_GetJoystickGUIDInfo (SDL_JoystickGUID guid, Uint16 *vendor, Uint16 *product, Uint16 *version)
SDL_bool | SDL_IsGameControllerNameAndGUID (const char *name, SDL_JoystickGUID guid)
SDL_bool | SDL_ShouldIgnoreGameController (const char *name, SDL_JoystickGUID guid)
void | SDL_PrivateJoystickAdded (int device_index)
void | SDL_PrivateJoystickRemoved (SDL_JoystickID device_instance)
int | SDL_PrivateJoystickAxis (SDL_Joystick *joystick, Uint8 axis, Sint16 value)
int | SDL_PrivateJoystickBall (SDL_Joystick *joystick, Uint8 ball, Sint16 xrel, Sint16 yrel)
int | SDL_PrivateJoystickHat (SDL_Joystick *joystick, Uint8 hat, Uint8 value)
int | SDL_PrivateJoystickButton (SDL_Joystick *joystick, Uint8 button, Uint8 state)
void | SDL_PrivateJoystickBatteryLevel (SDL_Joystick *joystick, SDL_JoystickPowerLevel ePowerLevel)
int | SDL_PrivateJoystickValid (SDL_Joystick *joystick)

## Function Documentation

## SDL_GameControllerInit()

int SDL_GameControllerInit | ( | void |  | ) |

Definition at line 1237 of file SDL_gamecontroller.c.

References SDL_Event::cdevice, i, NULL, SDL_AddEventWatch, SDL_CONTROLLERDEVICEADDED, SDL_GameControllerEventWatcher(), SDL_IsGameController(), SDL_NumJoysticks, SDL_PushEvent, SDL_Event::type, and SDL_ControllerDeviceEvent::which.

Referenced by SDL_InitSubSystem().

{
int i;
/* watch for joy events and fire controller ones if needed */
SDL_AddEventWatch(SDL_GameControllerEventWatcher, NULL);
/* Send added events for controllers currently attached */
for (i = 0; i < SDL_NumJoysticks(); ++i) {
if (SDL_IsGameController(i)) {
SDL_Event deviceevent;
deviceevent.type = SDL_CONTROLLERDEVICEADDED;
deviceevent.cdevice.which = i;
SDL_PushEvent(&deviceevent);
}
}
return (0);
}
SDL_GameControllerEventWatcher
static int SDL_GameControllerEventWatcher(void *userdata, SDL_Event *event)
Definition: SDL_gamecontroller.c:341
SDL_Event::cdevice
SDL_ControllerDeviceEvent cdevice
Definition: SDL_events.h:543
SDL_NumJoysticks
#define SDL_NumJoysticks
Definition: SDL_dynapi_overrides.h:195
SDL_CONTROLLERDEVICEADDED
Definition: SDL_events.h:120
SDL_ControllerDeviceEvent::which
Sint32 which
Definition: SDL_events.h:392
SDL_PushEvent
#define SDL_PushEvent
Definition: SDL_dynapi_overrides.h:125
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:50
SDL_IsGameController
SDL_bool SDL_IsGameController(int device_index)
Definition: SDL_gamecontroller.c:1289
NULL
#define NULL
Definition: begin_code.h:164
SDL_AddEventWatch
#define SDL_AddEventWatch
Definition: SDL_dynapi_overrides.h:128
SDL_Event
General event structure.
Definition: SDL_events.h:525
SDL_Event::type
Uint32 type
Definition: SDL_events.h:527

## SDL_GameControllerInitMappings()

int SDL_GameControllerInitMappings | ( | void |  | ) |

Definition at line 1208 of file SDL_gamecontroller.c.

References i, NULL, s_ControllerMappings, SDL_AddHintCallback, SDL_CONTROLLER_MAPPING_PRIORITY_DEFAULT, SDL_GameControllerAddMappingsFromFile, SDL_GameControllerIgnoreDevicesChanged(), SDL_GameControllerIgnoreDevicesExceptChanged(), SDL_GameControllerLoadHints(), SDL_GetControllerMappingFilePath(), SDL_HINT_GAMECONTROLLER_IGNORE_DEVICES, SDL_HINT_GAMECONTROLLER_IGNORE_DEVICES_EXCEPT, and SDL_PrivateGameControllerAddMapping().

Referenced by SDL_JoystickInit().

{
char szControllerMapPath[1024];
int i = 0;
const char *pMappingString = NULL;
pMappingString = s_ControllerMappings[i];
while (pMappingString) {
SDL_PrivateGameControllerAddMapping(pMappingString, SDL_CONTROLLER_MAPPING_PRIORITY_DEFAULT);
i++;
pMappingString = s_ControllerMappings[i];
}
if (SDL_GetControllerMappingFilePath(szControllerMapPath, sizeof(szControllerMapPath))) {
SDL_GameControllerAddMappingsFromFile(szControllerMapPath);
}
/* load in any user supplied config */
SDL_GameControllerLoadHints();
SDL_AddHintCallback(SDL_HINT_GAMECONTROLLER_IGNORE_DEVICES,
SDL_GameControllerIgnoreDevicesChanged, NULL);
SDL_AddHintCallback(SDL_HINT_GAMECONTROLLER_IGNORE_DEVICES_EXCEPT,
SDL_GameControllerIgnoreDevicesExceptChanged, NULL);
return (0);
}
SDL_GetControllerMappingFilePath
static SDL_bool SDL_GetControllerMappingFilePath(char *path, size_t size)
Definition: SDL_gamecontroller.c:1192
SDL_GameControllerLoadHints
static void SDL_GameControllerLoadHints()
Definition: SDL_gamecontroller.c:1159
SDL_PrivateGameControllerAddMapping
static int SDL_PrivateGameControllerAddMapping(const char *mappingString, SDL_ControllerMappingPriority priority)
Definition: SDL_gamecontroller.c:1017
SDL_HINT_GAMECONTROLLER_IGNORE_DEVICES_EXCEPT
#define SDL_HINT_GAMECONTROLLER_IGNORE_DEVICES_EXCEPT
Definition: SDL_hints.h:453
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:50
NULL
#define NULL
Definition: begin_code.h:164
SDL_GameControllerIgnoreDevicesExceptChanged
static void SDL_GameControllerIgnoreDevicesExceptChanged(void *userdata, const char *name, const char *oldValue, const char *hint)
Definition: SDL_gamecontroller.c:183
s_ControllerMappings
static const char * s_ControllerMappings[]
Definition: SDL_gamecontrollerdb.h:32
SDL_CONTROLLER_MAPPING_PRIORITY_DEFAULT
Definition: SDL_gamecontroller.c:84
SDL_AddHintCallback
#define SDL_AddHintCallback
Definition: SDL_dynapi_overrides.h:192
SDL_GameControllerAddMappingsFromFile
#define SDL_GameControllerAddMappingsFromFile(file)
Definition: SDL_gamecontroller.h:129
SDL_HINT_GAMECONTROLLER_IGNORE_DEVICES
#define SDL_HINT_GAMECONTROLLER_IGNORE_DEVICES
Definition: SDL_hints.h:440
SDL_GameControllerIgnoreDevicesChanged
static void SDL_GameControllerIgnoreDevicesChanged(void *userdata, const char *name, const char *oldValue, const char *hint)
Definition: SDL_gamecontroller.c:177

## SDL_GameControllerQuit()

void SDL_GameControllerQuit | ( | void |  | ) |

Definition at line 1733 of file SDL_gamecontroller.c.

References SDL_GameControllerClose(), SDL_gamecontrollers, SDL_LockJoysticks, and SDL_UnlockJoysticks.

Referenced by SDL_QuitSubSystem().

{
SDL_LockJoysticks();
while (SDL_gamecontrollers) {
SDL_gamecontrollers->ref_count = 1;
SDL_GameControllerClose(SDL_gamecontrollers);
}
SDL_UnlockJoysticks();
}
SDL_UnlockJoysticks
#define SDL_UnlockJoysticks
Definition: SDL_dynapi_overrides.h:639
SDL_GameControllerClose
void SDL_GameControllerClose(SDL_GameController *gamecontroller)
Definition: SDL_gamecontroller.c:1687
SDL_gamecontrollers
static SDL_GameController * SDL_gamecontrollers
Definition: SDL_gamecontroller.c:44
SDL_LockJoysticks
#define SDL_LockJoysticks
Definition: SDL_dynapi_overrides.h:638

## SDL_GameControllerQuitMappings()

void SDL_GameControllerQuitMappings | ( | void |  | ) |

Definition at line 1744 of file SDL_gamecontroller.c.

References SDL_vidpid_list::entries, ControllerMapping_t::mapping, ControllerMapping_t::name, ControllerMapping_t::next, NULL, s_pSupportedControllers, SDL_DelEventWatch, SDL_DelHintCallback, SDL_free, SDL_GameControllerEventWatcher(), SDL_GameControllerIgnoreDevicesChanged(), SDL_GameControllerIgnoreDevicesExceptChanged(), SDL_HINT_GAMECONTROLLER_IGNORE_DEVICES, SDL_HINT_GAMECONTROLLER_IGNORE_DEVICES_EXCEPT, and SDL_zero.

Referenced by SDL_JoystickQuit().

{
ControllerMapping_t *pControllerMap;
while (s_pSupportedControllers) {
pControllerMap = s_pSupportedControllers;
s_pSupportedControllers = s_pSupportedControllers->next;
SDL_free(pControllerMap->name);
SDL_free(pControllerMap->mapping);
SDL_free(pControllerMap);
}
SDL_DelEventWatch(SDL_GameControllerEventWatcher, NULL);
SDL_DelHintCallback(SDL_HINT_GAMECONTROLLER_IGNORE_DEVICES,
SDL_GameControllerIgnoreDevicesChanged, NULL);
SDL_DelHintCallback(SDL_HINT_GAMECONTROLLER_IGNORE_DEVICES_EXCEPT,
SDL_GameControllerIgnoreDevicesExceptChanged, NULL);
if (SDL_allowed_controllers.entries) {
SDL_free(SDL_allowed_controllers.entries);
SDL_zero(SDL_allowed_controllers);
}
if (SDL_ignored_controllers.entries) {
SDL_free(SDL_ignored_controllers.entries);
SDL_zero(SDL_ignored_controllers);
}
}
SDL_DelEventWatch
#define SDL_DelEventWatch
Definition: SDL_dynapi_overrides.h:129
SDL_GameControllerEventWatcher
static int SDL_GameControllerEventWatcher(void *userdata, SDL_Event *event)
Definition: SDL_gamecontroller.c:341
ControllerMapping_t::next
struct _ControllerMapping_t * next
Definition: SDL_gamecontroller.c:95
SDL_ignored_controllers
static SDL_vidpid_list SDL_ignored_controllers
Definition: SDL_gamecontroller.c:128
s_pSupportedControllers
static ControllerMapping_t * s_pSupportedControllers
Definition: SDL_gamecontroller.c:99
SDL_free
#define SDL_free
Definition: SDL_dynapi_overrides.h:377
SDL_HINT_GAMECONTROLLER_IGNORE_DEVICES_EXCEPT
#define SDL_HINT_GAMECONTROLLER_IGNORE_DEVICES_EXCEPT
Definition: SDL_hints.h:453
SDL_zero
#define SDL_zero(x)
Definition: SDL_stdinc.h:416
ControllerMapping_t::name
char * name
Definition: SDL_gamecontroller.c:92
SDL_vidpid_list::entries
Uint32 * entries
Definition: SDL_gamecontroller.c:124
ControllerMapping_t::mapping
char * mapping
Definition: SDL_gamecontroller.c:93
NULL
#define NULL
Definition: begin_code.h:164
SDL_GameControllerIgnoreDevicesExceptChanged
static void SDL_GameControllerIgnoreDevicesExceptChanged(void *userdata, const char *name, const char *oldValue, const char *hint)
Definition: SDL_gamecontroller.c:183
ControllerMapping_t
Definition: SDL_gamecontroller.c:89
SDL_allowed_controllers
static SDL_vidpid_list SDL_allowed_controllers
Definition: SDL_gamecontroller.c:127
SDL_DelHintCallback
#define SDL_DelHintCallback
Definition: SDL_dynapi_overrides.h:193
SDL_HINT_GAMECONTROLLER_IGNORE_DEVICES
#define SDL_HINT_GAMECONTROLLER_IGNORE_DEVICES
Definition: SDL_hints.h:440
SDL_GameControllerIgnoreDevicesChanged
static void SDL_GameControllerIgnoreDevicesChanged(void *userdata, const char *name, const char *oldValue, const char *hint)
Definition: SDL_gamecontroller.c:177

## SDL_GetJoystickGUIDInfo()

void SDL_GetJoystickGUIDInfo | ( | SDL_JoystickGUID | guid,
|  | Uint16 * | vendor,
|  | Uint16 * | product,
|  | Uint16 * | version
| ) |  |

Definition at line 933 of file SDL_joystick.c.

References SDL_JoystickGUID::data.

Referenced by SDL_GetJoystickGUIDType(), SDL_JoystickGetDeviceProduct(), SDL_JoystickGetDeviceProductVersion(), SDL_JoystickGetDeviceVendor(), SDL_JoystickGetProduct(), SDL_JoystickGetProductVersion(), SDL_JoystickGetVendor(), and SDL_ShouldIgnoreGameController().

{
Uint16 *guid16 = (Uint16 *)guid.data;
/* If the GUID fits the form of BUS 0000 VENDOR 0000 PRODUCT 0000, return the data */
if (/* guid16[0] is device bus type */
guid16[1] == 0x0000 &&
/* guid16[2] is vendor ID */
guid16[3] == 0x0000 &&
/* guid16[4] is product ID */
guid16[5] == 0x0000
/* guid16[6] is product version */
) {
if (vendor) {
*vendor = guid16[2];
}
if (product) {
*product = guid16[4];
}
if (version) {
*version = guid16[6];
}
} else {
if (vendor) {
*vendor = 0;
}
if (product) {
*product = 0;
}
if (version) {
*version = 0;
}
}
}
SDL_JoystickGUID::data
Uint8 data[16]
Definition: SDL_joystick.h:71
Uint16
uint16_t Uint16
Definition: SDL_stdinc.h:169

## SDL_IsGameControllerNameAndGUID()

SDL_bool SDL_IsGameControllerNameAndGUID | ( | const char * | name,
|  | SDL_JoystickGUID | guid
| ) |  |

Definition at line 1276 of file SDL_gamecontroller.c.

References SDL_FALSE, SDL_PrivateGetControllerMappingForNameAndGUID(), and SDL_TRUE.

{
ControllerMapping_t *pSupportedController = SDL_PrivateGetControllerMappingForNameAndGUID(name, guid);
if (pSupportedController) {
return SDL_TRUE;
}
return SDL_FALSE;
}
SDL_TRUE
Definition: SDL_stdinc.h:142
SDL_FALSE
Definition: SDL_stdinc.h:141
SDL_PrivateGetControllerMappingForNameAndGUID
static ControllerMapping_t * SDL_PrivateGetControllerMappingForNameAndGUID(const char *name, SDL_JoystickGUID guid)
Definition: SDL_gamecontroller.c:875
name
GLuint const GLchar * name
Definition: SDL_opengl_glext.h:660
ControllerMapping_t
Definition: SDL_gamecontroller.c:89

## SDL_JoystickInit()

int SDL_JoystickInit | ( | void |  | ) |

Definition at line 70 of file SDL_joystick.c.

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

Referenced by SDL_InitSubSystem().

{
int status;
SDL_GameControllerInitMappings();
/* Create the joystick list lock */
if (!SDL_joystick_lock) {
SDL_joystick_lock = SDL_CreateMutex();
}
/* 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:466
SDL_INIT_EVENTS
#define SDL_INIT_EVENTS
Definition: SDL.h:82
SDL_GameControllerInitMappings
int SDL_GameControllerInitMappings(void)
Definition: SDL_gamecontroller.c:1208
SDL_joystick_lock
static SDL_mutex * SDL_joystick_lock
Definition: SDL_joystick.c:40
SDL_CreateMutex
#define SDL_CreateMutex
Definition: SDL_dynapi_overrides.h:259
SDL_InitSubSystem
#define SDL_InitSubSystem
Definition: SDL_dynapi_overrides.h:55
SDL_SYS_JoystickInit
int SDL_SYS_JoystickInit(void)
Definition: SDL_sysjoystick.m:330
NULL
#define NULL
Definition: begin_code.h:164
SDL_AddHintCallback
#define SDL_AddHintCallback
Definition: SDL_dynapi_overrides.h:192
SDL_JoystickAllowBackgroundEventsChanged
static void SDL_JoystickAllowBackgroundEventsChanged(void *userdata, const char *name, const char *oldValue, const char *hint)
Definition: SDL_joystick.c:60

## SDL_JoystickQuit()

void SDL_JoystickQuit | ( | void |  | ) |

Definition at line 545 of file SDL_joystick.c.

References NULL, SDL_assert, SDL_DelHintCallback, SDL_DestroyMutex, SDL_GameControllerQuitMappings(), SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS, SDL_INIT_EVENTS, SDL_JoystickAllowBackgroundEventsChanged(), SDL_JoystickClose(), SDL_joysticks, SDL_LockJoysticks(), SDL_QuitSubSystem, SDL_SYS_JoystickQuit(), SDL_UnlockJoysticks(), 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);
SDL_LockJoysticks();
/* Stop the event polling */
while (SDL_joysticks) {
SDL_joysticks->ref_count = 1;
SDL_JoystickClose(SDL_joysticks);
}
/* Quit the joystick setup */
SDL_SYS_JoystickQuit();
SDL_UnlockJoysticks();
#if !SDL_EVENTS_DISABLED
SDL_QuitSubSystem(SDL_INIT_EVENTS);
#endif
SDL_DelHintCallback(SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS,
SDL_JoystickAllowBackgroundEventsChanged, NULL);
if (SDL_joystick_lock) {
SDL_DestroyMutex(SDL_joystick_lock);
SDL_joystick_lock = NULL;
}
SDL_GameControllerQuitMappings();
}
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:466
SDL_INIT_EVENTS
#define SDL_INIT_EVENTS
Definition: SDL.h:82
SDL_LockJoysticks
void SDL_LockJoysticks(void)
Definition: SDL_joystick.c:43
SDL_JoystickClose
void SDL_JoystickClose(SDL_Joystick *joystick)
Definition: SDL_joystick.c:491
SDL_GameControllerQuitMappings
void SDL_GameControllerQuitMappings(void)
Definition: SDL_gamecontroller.c:1744
SDL_joystick_lock
static SDL_mutex * SDL_joystick_lock
Definition: SDL_joystick.c:40
SDL_QuitSubSystem
#define SDL_QuitSubSystem
Definition: SDL_dynapi_overrides.h:56
SDL_SYS_JoystickQuit
void SDL_SYS_JoystickQuit(void)
Definition: SDL_sysjoystick.m:734
SDL_UnlockJoysticks
void SDL_UnlockJoysticks(void)
Definition: SDL_joystick.c:51
SDL_assert
#define SDL_assert(condition)
Definition: SDL_assert.h:169
NULL
#define NULL
Definition: begin_code.h:164
SDL_DestroyMutex
#define SDL_DestroyMutex
Definition: SDL_dynapi_overrides.h:263
SDL_DelHintCallback
#define SDL_DelHintCallback
Definition: SDL_dynapi_overrides.h:193
SDL_JoystickAllowBackgroundEventsChanged
static void SDL_JoystickAllowBackgroundEventsChanged(void *userdata, const char *name, const char *oldValue, const char *hint)
Definition: SDL_joystick.c:60
SDL_updating_joystick
static SDL_bool SDL_updating_joystick
Definition: SDL_joystick.c:39
SDL_joysticks
static SDL_Joystick * SDL_joysticks
Definition: SDL_joystick.c:38

## SDL_PrivateJoystickAdded()

void SDL_PrivateJoystickAdded | ( | int | device_index | ) |

Definition at line 595 of file SDL_joystick.c.

References SDL_ENABLE, SDL_GetEventState, SDL_JOYDEVICEADDED, SDL_PushEvent, and SDL_Event::type.

Referenced by SDL_SYS_AddJoystickDevice(), and SteamControllerConnectedCallback().

{
#if !SDL_EVENTS_DISABLED
SDL_Event event;
event.type = SDL_JOYDEVICEADDED;
if (SDL_GetEventState(event.type) == SDL_ENABLE) {
event.jdevice.which = device_index;
SDL_PushEvent(&event);
}
#endif /* !SDL_EVENTS_DISABLED */
}
SDL_JOYDEVICEADDED
Definition: SDL_events.h:113
SDL_ENABLE
#define SDL_ENABLE
Definition: SDL_events.h:722
SDL_GetEventState
#define SDL_GetEventState(type)
Definition: SDL_events.h:735
event
struct _cl_event * event
Definition: SDL_opengl_glext.h:2649
SDL_PushEvent
#define SDL_PushEvent
Definition: SDL_dynapi_overrides.h:125
SDL_Event
General event structure.
Definition: SDL_events.h:525
SDL_Event::type
Uint32 type
Definition: SDL_events.h:527

## SDL_PrivateJoystickAxis()

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

Definition at line 655 of file SDL_joystick.c.

References axis, SDL_abs, SDL_ENABLE, SDL_GetEventState, SDL_JOYAXISMOTION, SDL_JOYSTICK_AXIS_MAX, SDL_PrivateJoystickAxis(), SDL_PrivateJoystickShouldIgnoreEvent(), SDL_PushEvent, and SDL_TRUE.

Referenced by SDL_JoystickUpdate(), SDL_PrivateJoystickAxis(), 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 (!joystick->axes[axis].has_initial_value) {
joystick->axes[axis].initial_value = value;
joystick->axes[axis].value = value;
joystick->axes[axis].zero = value;
joystick->axes[axis].has_initial_value = SDL_TRUE;
}
if (value == joystick->axes[axis].value) {
return 0;
}
if (!joystick->axes[axis].sent_initial_value) {
/* Make sure we don't send motion until there's real activity on this axis */
const int MAX_ALLOWED_JITTER = SDL_JOYSTICK_AXIS_MAX / 80; /* ShanWan PS3 controller needed 96 */
if (SDL_abs(value - joystick->axes[axis].value) <= MAX_ALLOWED_JITTER) {
return 0;
}
joystick->axes[axis].sent_initial_value = SDL_TRUE;
joystick->axes[axis].value = value; /* Just so we pass the check above */
SDL_PrivateJoystickAxis(joystick, axis, joystick->axes[axis].initial_value);
}
/* We ignore events if we don't have keyboard focus, except for centering
* events.
*/
if (SDL_PrivateJoystickShouldIgnoreEvent()) {
if ((value > joystick->axes[axis].zero && value >= joystick->axes[axis].value) ||
(value < joystick->axes[axis].zero && value <= joystick->axes[axis].value)) {
return 0;
}
}
/* Update internal joystick state */
joystick->axes[axis].value = 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_abs
#define SDL_abs
Definition: SDL_dynapi_overrides.h:381
SDL_TRUE
Definition: SDL_stdinc.h:142
SDL_ENABLE
#define SDL_ENABLE
Definition: SDL_events.h:722
axis
SDL_Texture * axis
Definition: testgamecontroller.c:67
SDL_JOYAXISMOTION
Definition: SDL_events.h:108
SDL_PrivateJoystickAxis
int SDL_PrivateJoystickAxis(SDL_Joystick *joystick, Uint8 axis, Sint16 value)
Definition: SDL_joystick.c:655
SDL_JOYSTICK_AXIS_MAX
#define SDL_JOYSTICK_AXIS_MAX
Definition: SDL_joystick.h:288
SDL_GetEventState
#define SDL_GetEventState(type)
Definition: SDL_events.h:735
event
struct _cl_event * event
Definition: SDL_opengl_glext.h:2649
SDL_PushEvent
#define SDL_PushEvent
Definition: SDL_dynapi_overrides.h:125
value
GLsizei const GLfloat * value
Definition: SDL_opengl_glext.h:698
SDL_PrivateJoystickShouldIgnoreEvent
static SDL_bool SDL_PrivateJoystickShouldIgnoreEvent()
Definition: SDL_joystick.c:580
SDL_Event
General event structure.
Definition: SDL_events.h:525

## SDL_PrivateJoystickBall()

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

Definition at line 752 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:722
SDL_JOYBALLMOTION
Definition: SDL_events.h:109
SDL_GetEventState
#define SDL_GetEventState(type)
Definition: SDL_events.h:735
event
struct _cl_event * event
Definition: SDL_opengl_glext.h:2649
SDL_PushEvent
#define SDL_PushEvent
Definition: SDL_dynapi_overrides.h:125
SDL_PrivateJoystickShouldIgnoreEvent
static SDL_bool SDL_PrivateJoystickShouldIgnoreEvent()
Definition: SDL_joystick.c:580
SDL_Event
General event structure.
Definition: SDL_events.h:525

## SDL_PrivateJoystickBatteryLevel()

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

Definition at line 1261 of file SDL_joystick.c.

{
joystick->epowerlevel = ePowerLevel;
}

## SDL_PrivateJoystickButton()

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

Definition at line 788 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:113
SDL_ENABLE
#define SDL_ENABLE
Definition: SDL_events.h:722
SDL_GetEventState
#define SDL_GetEventState(type)
Definition: SDL_events.h:735
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:125
SDL_PrivateJoystickShouldIgnoreEvent
static SDL_bool SDL_PrivateJoystickShouldIgnoreEvent()
Definition: SDL_joystick.c:580
SDL_Event
General event structure.
Definition: SDL_events.h:525
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:527

## SDL_PrivateJoystickHat()

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

Definition at line 712 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:722
SDL_GetEventState
#define SDL_GetEventState(type)
Definition: SDL_events.h:735
event
struct _cl_event * event
Definition: SDL_opengl_glext.h:2649
SDL_PushEvent
#define SDL_PushEvent
Definition: SDL_dynapi_overrides.h:125
value
GLsizei const GLfloat * value
Definition: SDL_opengl_glext.h:698
SDL_PrivateJoystickShouldIgnoreEvent
static SDL_bool SDL_PrivateJoystickShouldIgnoreEvent()
Definition: SDL_joystick.c:580
SDL_Event
General event structure.
Definition: SDL_events.h:525
SDL_HAT_CENTERED
#define SDL_HAT_CENTERED
Definition: SDL_joystick.h:316

## SDL_PrivateJoystickRemoved()

void SDL_PrivateJoystickRemoved | ( | SDL_JoystickID | device_instance | ) |

Definition at line 638 of file SDL_joystick.c.

References SDL_ENABLE, SDL_GetEventState, SDL_JOYDEVICEREMOVED, SDL_PushEvent, SDL_Event::type, and UpdateEventsForDeviceRemoval().

Referenced by SDL_SYS_RemoveJoystickDevice().

{
#if !SDL_EVENTS_DISABLED
SDL_Event event;
event.type = SDL_JOYDEVICEREMOVED;
if (SDL_GetEventState(event.type) == SDL_ENABLE) {
event.jdevice.which = device_instance;
SDL_PushEvent(&event);
}
UpdateEventsForDeviceRemoval();
#endif /* !SDL_EVENTS_DISABLED */
}
SDL_ENABLE
#define SDL_ENABLE
Definition: SDL_events.h:722
SDL_JOYDEVICEREMOVED
Definition: SDL_events.h:114
UpdateEventsForDeviceRemoval
static void UpdateEventsForDeviceRemoval()
Definition: SDL_joystick.c:614
SDL_GetEventState
#define SDL_GetEventState(type)
Definition: SDL_events.h:735
event
struct _cl_event * event
Definition: SDL_opengl_glext.h:2649
SDL_PushEvent
#define SDL_PushEvent
Definition: SDL_dynapi_overrides.h:125
SDL_Event
General event structure.
Definition: SDL_events.h:525
SDL_Event::type
Uint32 type
Definition: SDL_events.h:527

## SDL_PrivateJoystickValid()

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

Definition at line 259 of file SDL_joystick.c.

References NULL, and SDL_SetError.

Referenced by SDL_HapticOpenFromJoystick(), SDL_JoystickCurrentPowerLevel(), SDL_JoystickGetAttached(), SDL_JoystickGetAxis(), SDL_JoystickGetAxisInitialState(), 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:164
SDL_SetError
#define SDL_SetError
Definition: SDL_dynapi_overrides.h:30

## SDL_ShouldIgnoreGameController()

SDL_bool SDL_ShouldIgnoreGameController | ( | const char * | name,
|  | SDL_JoystickGUID | guid
| ) |  |

Definition at line 1301 of file SDL_gamecontroller.c.

References SDL_vidpid_list::entries, i, MAKE_VIDPID, NULL, SDL_vidpid_list::num_entries, recDevice::product, SDL_FALSE, SDL_GetHintBoolean, SDL_GetJoystickGUIDInfo(), SDL_strncmp, and SDL_TRUE.

{
int i;
Uint16 vendor;
Uint16 product;
Uint32 vidpid;
if (SDL_allowed_controllers.num_entries == 0 &&
SDL_ignored_controllers.num_entries == 0) {
return SDL_FALSE;
}
SDL_GetJoystickGUIDInfo(guid, &vendor, &product, NULL);
vidpid = MAKE_VIDPID(vendor, product);
if (SDL_GetHintBoolean("SDL_GAMECONTROLLER_ALLOW_STEAM_VIRTUAL_GAMEPAD", SDL_FALSE)) {
/* We shouldn't ignore Steam's virtual gamepad since it's using the hints to filter out the real controllers so it can remap input for the virtual controller */
SDL_bool bSteamVirtualGamepad = SDL_FALSE;
#if defined(__LINUX__)
bSteamVirtualGamepad = (vendor == 0x28DE && product == 0x11FF);
#elif defined(__MACOSX__)
bSteamVirtualGamepad = (SDL_strncmp(name, "GamePad-", 8) == 0);
#elif defined(__WIN32__)
/* We can't tell on Windows, but Steam will block others in input hooks */
bSteamVirtualGamepad = SDL_TRUE;
#endif
if (bSteamVirtualGamepad) {
return SDL_FALSE;
}
}
if (SDL_allowed_controllers.num_entries > 0) {
for (i = 0; i < SDL_allowed_controllers.num_entries; ++i) {
if (vidpid == SDL_allowed_controllers.entries[i]) {
return SDL_FALSE;
}
}
return SDL_TRUE;
} else {
for (i = 0; i < SDL_ignored_controllers.num_entries; ++i) {
if (vidpid == SDL_ignored_controllers.entries[i]) {
return SDL_TRUE;
}
}
return SDL_FALSE;
}
}
SDL_vidpid_list::num_entries
int num_entries
Definition: SDL_gamecontroller.c:122
MAKE_VIDPID
#define MAKE_VIDPID(VID, PID)
Definition: SDL_sysjoystick.h:72
SDL_TRUE
Definition: SDL_stdinc.h:142
SDL_FALSE
Definition: SDL_stdinc.h:141
SDL_ignored_controllers
static SDL_vidpid_list SDL_ignored_controllers
Definition: SDL_gamecontroller.c:128
Uint32
uint32_t Uint32
Definition: SDL_stdinc.h:181
SDL_strncmp
#define SDL_strncmp
Definition: SDL_dynapi_overrides.h:418
name
GLuint const GLchar * name
Definition: SDL_opengl_glext.h:660
SDL_GetHintBoolean
#define SDL_GetHintBoolean
Definition: SDL_dynapi_overrides.h:608
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:50
SDL_vidpid_list::entries
Uint32 * entries
Definition: SDL_gamecontroller.c:124
NULL
#define NULL
Definition: begin_code.h:164
SDL_bool
SDL_bool
Definition: SDL_stdinc.h:139
SDL_allowed_controllers
static SDL_vidpid_list SDL_allowed_controllers
Definition: SDL_gamecontroller.c:127
SDL_GetJoystickGUIDInfo
void SDL_GetJoystickGUIDInfo(SDL_JoystickGUID guid, Uint16 *vendor, Uint16 *product, Uint16 *version)
Definition: SDL_joystick.c:933
Uint16
uint16_t Uint16
Definition: SDL_stdinc.h:169