SDL 2.0
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)
 
SDL_JoystickID SDL_GetNextJoystickInstanceID (void)
 
int SDL_GameControllerInitMappings (void)
 
void SDL_GameControllerQuitMappings (void)
 
int SDL_GameControllerInit (void)
 
void SDL_GameControllerQuit (void)
 
SDL_bool SDL_GetDriverAndJoystickIndex (int device_index, struct _SDL_JoystickDriver **driver, int *driver_index)
 
int SDL_JoystickGetDeviceIndexFromInstanceID (SDL_JoystickID instance_id)
 
void SDL_GetJoystickGUIDInfo (SDL_JoystickGUID guid, Uint16 *vendor, Uint16 *product, Uint16 *version)
 
SDL_bool SDL_IsJoystickPS4 (Uint16 vendor_id, Uint16 product_id)
 
SDL_bool SDL_IsJoystickNintendoSwitchPro (Uint16 vendor_id, Uint16 product_id)
 
SDL_bool SDL_IsJoystickSteamController (Uint16 vendor_id, Uint16 product_id)
 
SDL_bool SDL_IsJoystickXbox360 (Uint16 vendor_id, Uint16 product_id)
 
SDL_bool SDL_IsJoystickXboxOne (Uint16 vendor_id, Uint16 product_id)
 
SDL_bool SDL_IsJoystickXInput (SDL_JoystickGUID guid)
 
SDL_bool SDL_IsJoystickHIDAPI (SDL_JoystickGUID guid)
 
SDL_bool SDL_ShouldIgnoreJoystick (const char *name, SDL_JoystickGUID guid)
 
SDL_bool SDL_IsGameControllerNameAndGUID (const char *name, SDL_JoystickGUID guid)
 
SDL_bool SDL_ShouldIgnoreGameController (const char *name, SDL_JoystickGUID guid)
 
void SDL_GameControllerHandleDelayedGuideButton (SDL_Joystick *joystick)
 
void SDL_PrivateJoystickAdded (SDL_JoystickID device_instance)
 
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_GameControllerHandleDelayedGuideButton()

void SDL_GameControllerHandleDelayedGuideButton ( SDL_Joystick *  joystick)

Definition at line 2088 of file SDL_gamecontroller.c.

2089{
2090 SDL_GameController *controllerlist = SDL_gamecontrollers;
2091 while (controllerlist) {
2092 if (controllerlist->joystick == joystick) {
2094 break;
2095 }
2096 controllerlist = controllerlist->next;
2097 }
2098}
#define SDL_RELEASED
Definition: SDL_events.h:49
static int SDL_PrivateGameControllerButton(SDL_GameController *gamecontroller, SDL_GameControllerButton button, Uint8 state)
static SDL_GameController * SDL_gamecontrollers
@ SDL_CONTROLLER_BUTTON_GUIDE

References SDL_GameController::joystick, SDL_CONTROLLER_BUTTON_GUIDE, SDL_gamecontrollers, SDL_PrivateGameControllerButton(), and SDL_RELEASED.

Referenced by SDL_JoystickUpdate().

◆ SDL_GameControllerInit()

int SDL_GameControllerInit ( void  )

Definition at line 1374 of file SDL_gamecontroller.c.

1375{
1376 int i;
1377
1378 /* watch for joy events and fire controller ones if needed */
1380
1381 /* Send added events for controllers currently attached */
1382 for (i = 0; i < SDL_NumJoysticks(); ++i) {
1383 if (SDL_IsGameController(i)) {
1384 SDL_Event deviceevent;
1385 deviceevent.type = SDL_CONTROLLERDEVICEADDED;
1386 deviceevent.cdevice.which = i;
1387 SDL_PushEvent(&deviceevent);
1388 }
1389 }
1390
1391 return (0);
1392}
#define SDL_PushEvent
#define SDL_NumJoysticks
#define SDL_AddEventWatch
@ SDL_CONTROLLERDEVICEADDED
Definition: SDL_events.h:123
SDL_bool SDL_IsGameController(int device_index)
static int SDL_GameControllerEventWatcher(void *userdata, SDL_Event *event)
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
#define NULL
Definition: begin_code.h:167
General event structure.
Definition: SDL_events.h:558
Uint32 type
Definition: SDL_events.h:559
SDL_ControllerDeviceEvent cdevice
Definition: SDL_events.h:576

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().

◆ SDL_GameControllerInitMappings()

int SDL_GameControllerInitMappings ( void  )

Definition at line 1345 of file SDL_gamecontroller.c.

1346{
1347 char szControllerMapPath[1024];
1348 int i = 0;
1349 const char *pMappingString = NULL;
1350 pMappingString = s_ControllerMappings[i];
1351 while (pMappingString) {
1353
1354 i++;
1355 pMappingString = s_ControllerMappings[i];
1356 }
1357
1358 if (SDL_GetControllerMappingFilePath(szControllerMapPath, sizeof(szControllerMapPath))) {
1359 SDL_GameControllerAddMappingsFromFile(szControllerMapPath);
1360 }
1361
1362 /* load in any user supplied config */
1364
1369
1370 return (0);
1371}
#define SDL_AddHintCallback
static void SDL_GameControllerLoadHints()
static SDL_bool SDL_GetControllerMappingFilePath(char *path, size_t size)
@ SDL_CONTROLLER_MAPPING_PRIORITY_DEFAULT
static void SDL_GameControllerIgnoreDevicesChanged(void *userdata, const char *name, const char *oldValue, const char *hint)
static void SDL_GameControllerIgnoreDevicesExceptChanged(void *userdata, const char *name, const char *oldValue, const char *hint)
static int SDL_PrivateGameControllerAddMapping(const char *mappingString, SDL_ControllerMappingPriority priority)
#define SDL_GameControllerAddMappingsFromFile(file)
static const char * s_ControllerMappings[]
#define SDL_HINT_GAMECONTROLLER_IGNORE_DEVICES_EXCEPT
Definition: SDL_hints.h:483
#define SDL_HINT_GAMECONTROLLER_IGNORE_DEVICES
Definition: SDL_hints.h:470

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().

◆ SDL_GameControllerQuit()

void SDL_GameControllerQuit ( void  )

Definition at line 1931 of file SDL_gamecontroller.c.

1932{
1934 while (SDL_gamecontrollers) {
1935 SDL_gamecontrollers->ref_count = 1;
1937 }
1939}
#define SDL_LockJoysticks
#define SDL_UnlockJoysticks
void SDL_GameControllerClose(SDL_GameController *gamecontroller)

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

Referenced by SDL_QuitSubSystem().

◆ SDL_GameControllerQuitMappings()

void SDL_GameControllerQuitMappings ( void  )

Definition at line 1942 of file SDL_gamecontroller.c.

1943{
1944 ControllerMapping_t *pControllerMap;
1945
1946 while (s_pSupportedControllers) {
1947 pControllerMap = s_pSupportedControllers;
1949 SDL_free(pControllerMap->name);
1950 SDL_free(pControllerMap->mapping);
1951 SDL_free(pControllerMap);
1952 }
1953
1955
1960
1964 }
1968 }
1969}
#define SDL_DelHintCallback
#define SDL_DelEventWatch
#define SDL_free
static SDL_vidpid_list SDL_allowed_controllers
static SDL_vidpid_list SDL_ignored_controllers
static ControllerMapping_t * s_pSupportedControllers
#define SDL_zero(x)
Definition: SDL_stdinc.h:416
struct _ControllerMapping_t * next

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

Referenced by SDL_JoystickQuit().

◆ SDL_GetDriverAndJoystickIndex()

SDL_bool SDL_GetDriverAndJoystickIndex ( int  device_index,
struct _SDL_JoystickDriver **  driver,
int *  driver_index 
)

◆ SDL_GetJoystickGUIDInfo()

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

Definition at line 1125 of file SDL_joystick.c.

1126{
1127 Uint16 *guid16 = (Uint16 *)guid.data;
1128
1129 /* If the GUID fits the form of BUS 0000 VENDOR 0000 PRODUCT 0000, return the data */
1130 if (/* guid16[0] is device bus type */
1131 guid16[1] == 0x0000 &&
1132 /* guid16[2] is vendor ID */
1133 guid16[3] == 0x0000 &&
1134 /* guid16[4] is product ID */
1135 guid16[5] == 0x0000
1136 /* guid16[6] is product version */
1137 ) {
1138 if (vendor) {
1139 *vendor = guid16[2];
1140 }
1141 if (product) {
1142 *product = guid16[4];
1143 }
1144 if (version) {
1145 *version = guid16[6];
1146 }
1147 } else {
1148 if (vendor) {
1149 *vendor = 0;
1150 }
1151 if (product) {
1152 *product = 0;
1153 }
1154 if (version) {
1155 *version = 0;
1156 }
1157 }
1158}
uint16_t Uint16
Definition: SDL_stdinc.h:191
Uint8 data[16]
Definition: SDL_joystick.h:71

References SDL_JoystickGUID::data.

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

◆ SDL_GetNextJoystickInstanceID()

SDL_JoystickID SDL_GetNextJoystickInstanceID ( void  )

Definition at line 163 of file SDL_joystick.c.

164{
166}
#define SDL_AtomicIncRef(a)
Increment an atomic variable used as a reference count.
Definition: SDL_atomic.h:252
static SDL_atomic_t SDL_next_joystick_instance_id
Definition: SDL_joystick.c:84

References SDL_AtomicIncRef, and SDL_next_joystick_instance_id.

Referenced by IOS_AddJoystickDevice().

◆ SDL_IsGameControllerNameAndGUID()

SDL_bool SDL_IsGameControllerNameAndGUID ( const char *  name,
SDL_JoystickGUID  guid 
)

Definition at line 1451 of file SDL_gamecontroller.c.

1452{
1454 if (pSupportedController) {
1455 return SDL_TRUE;
1456 }
1457 return SDL_FALSE;
1458}
static ControllerMapping_t * SDL_PrivateGetControllerMappingForNameAndGUID(const char *name, SDL_JoystickGUID guid)
GLuint const GLchar * name
@ SDL_TRUE
Definition: SDL_stdinc.h:164
@ SDL_FALSE
Definition: SDL_stdinc.h:163

References SDL_FALSE, SDL_PrivateGetControllerMappingForNameAndGUID(), and SDL_TRUE.

Referenced by SDL_ShouldIgnoreJoystick().

◆ SDL_IsJoystickHIDAPI()

SDL_bool SDL_IsJoystickHIDAPI ( SDL_JoystickGUID  guid)

Definition at line 1208 of file SDL_joystick.c.

1209{
1210 return (guid.data[14] == 'h') ? SDL_TRUE : SDL_FALSE;
1211}

References SDL_JoystickGUID::data, SDL_FALSE, and SDL_TRUE.

Referenced by SDL_PrivateGetControllerMappingForGUID(), and SDL_PrivateGetControllerMappingForNameAndGUID().

◆ SDL_IsJoystickNintendoSwitchPro()

SDL_bool SDL_IsJoystickNintendoSwitchPro ( Uint16  vendor_id,
Uint16  product_id 
)

Definition at line 1167 of file SDL_joystick.c.

1168{
1169 EControllerType eType = GuessControllerType(vendor, product);
1170 return (eType == k_eControllerType_SwitchProController ||
1172}
EControllerType
@ k_eControllerType_SwitchProController
@ k_eControllerType_SwitchInputOnlyController
static EControllerType GuessControllerType(int nVID, int nPID)

References GuessControllerType(), k_eControllerType_SwitchInputOnlyController, and k_eControllerType_SwitchProController.

◆ SDL_IsJoystickPS4()

SDL_bool SDL_IsJoystickPS4 ( Uint16  vendor_id,
Uint16  product_id 
)

Definition at line 1161 of file SDL_joystick.c.

1162{
1163 return (GuessControllerType(vendor, product) == k_eControllerType_PS4Controller);
1164}
@ k_eControllerType_PS4Controller

References GuessControllerType(), and k_eControllerType_PS4Controller.

Referenced by SDL_ShouldIgnoreJoystick().

◆ SDL_IsJoystickSteamController()

SDL_bool SDL_IsJoystickSteamController ( Uint16  vendor_id,
Uint16  product_id 
)

Definition at line 1175 of file SDL_joystick.c.

1176{
1177 EControllerType eType = GuessControllerType(vendor, product);
1178 return (eType == k_eControllerType_SteamController ||
1180}
@ k_eControllerType_SteamController
@ k_eControllerType_SteamControllerV2

References GuessControllerType(), k_eControllerType_SteamController, and k_eControllerType_SteamControllerV2.

◆ SDL_IsJoystickXbox360()

SDL_bool SDL_IsJoystickXbox360 ( Uint16  vendor_id,
Uint16  product_id 
)

Definition at line 1183 of file SDL_joystick.c.

1184{
1185 /* Filter out some bogus values here */
1186 if (vendor == 0x0000 && product == 0x0000) {
1187 return SDL_FALSE;
1188 }
1189 if (vendor == 0x0001 && product == 0x0001) {
1190 return SDL_FALSE;
1191 }
1192 return (GuessControllerType(vendor, product) == k_eControllerType_XBox360Controller);
1193}
@ k_eControllerType_XBox360Controller

References GuessControllerType(), k_eControllerType_XBox360Controller, and SDL_FALSE.

◆ SDL_IsJoystickXboxOne()

SDL_bool SDL_IsJoystickXboxOne ( Uint16  vendor_id,
Uint16  product_id 
)

Definition at line 1196 of file SDL_joystick.c.

1197{
1198 return (GuessControllerType(vendor, product) == k_eControllerType_XBoxOneController);
1199}
@ k_eControllerType_XBoxOneController

References GuessControllerType(), and k_eControllerType_XBoxOneController.

◆ SDL_IsJoystickXInput()

SDL_bool SDL_IsJoystickXInput ( SDL_JoystickGUID  guid)

Definition at line 1202 of file SDL_joystick.c.

1203{
1204 return (guid.data[14] == 'x') ? SDL_TRUE : SDL_FALSE;
1205}

References SDL_JoystickGUID::data, SDL_FALSE, and SDL_TRUE.

Referenced by SDL_GetJoystickGUIDType(), and SDL_PrivateGetControllerMappingForGUID().

◆ SDL_JoystickGetDeviceIndexFromInstanceID()

int SDL_JoystickGetDeviceIndexFromInstanceID ( SDL_JoystickID  instance_id)

Definition at line 1560 of file SDL_joystick.c.

1561{
1562 int i, num_joysticks, device_index = -1;
1563
1565 num_joysticks = SDL_NumJoysticks();
1566 for (i = 0; i < num_joysticks; ++i) {
1567 if (SDL_JoystickGetDeviceInstanceID(i) == instance_id) {
1568 device_index = i;
1569 break;
1570 }
1571 }
1573
1574 return device_index;
1575}
SDL_JoystickID SDL_JoystickGetDeviceInstanceID(int device_index)
int SDL_NumJoysticks(void)
Definition: SDL_joystick.c:148
void SDL_LockJoysticks(void)
Definition: SDL_joystick.c:87
void SDL_UnlockJoysticks(void)
Definition: SDL_joystick.c:95

References i, SDL_JoystickGetDeviceInstanceID(), SDL_LockJoysticks(), SDL_NumJoysticks(), and SDL_UnlockJoysticks().

Referenced by SDL_PrivateJoystickAdded().

◆ SDL_JoystickInit()

int SDL_JoystickInit ( void  )

Definition at line 114 of file SDL_joystick.c.

115{
116 int i, status;
117
119
120 /* Create the joystick list lock */
121 if (!SDL_joystick_lock) {
123 }
124
125 /* See if we should allow joystick events while in the background */
128
129#if !SDL_EVENTS_DISABLED
131 return -1;
132 }
133#endif /* !SDL_EVENTS_DISABLED */
134
135 status = -1;
136 for (i = 0; i < SDL_arraysize(SDL_joystick_drivers); ++i) {
137 if (SDL_joystick_drivers[i]->Init() >= 0) {
138 status = 0;
139 }
140 }
141 return status;
142}
#define SDL_INIT_EVENTS
Definition: SDL.h:83
#define SDL_InitSubSystem
#define SDL_CreateMutex
int SDL_GameControllerInitMappings(void)
#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:496
static SDL_JoystickDriver * SDL_joystick_drivers[]
Definition: SDL_joystick.c:48
static void SDL_JoystickAllowBackgroundEventsChanged(void *userdata, const char *name, const char *oldValue, const char *hint)
Definition: SDL_joystick.c:104
static SDL_mutex * SDL_joystick_lock
Definition: SDL_joystick.c:83
#define SDL_arraysize(array)
Definition: SDL_stdinc.h:115

References i, NULL, SDL_AddHintCallback, SDL_arraysize, SDL_CreateMutex, SDL_GameControllerInitMappings(), SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS, SDL_INIT_EVENTS, SDL_InitSubSystem, SDL_joystick_drivers, SDL_joystick_lock, and SDL_JoystickAllowBackgroundEventsChanged().

Referenced by SDL_InitSubSystem().

◆ SDL_JoystickQuit()

void SDL_JoystickQuit ( void  )

Definition at line 697 of file SDL_joystick.c.

698{
699 int i;
700
701 /* Make sure we're not getting called in the middle of updating joysticks */
703 while (SDL_updating_joystick) {
705 SDL_Delay(1);
707 }
708
709 /* Stop the event polling */
710 while (SDL_joysticks) {
711 SDL_joysticks->ref_count = 1;
713 }
714
715 /* Quit the joystick setup */
716 for (i = 0; i < SDL_arraysize(SDL_joystick_drivers); ++i) {
718 }
719
721
722#if !SDL_EVENTS_DISABLED
724#endif
725
728
729 if (SDL_joystick_lock) {
733 }
734
736}
#define SDL_Delay
#define SDL_DestroyMutex
#define SDL_QuitSubSystem
void SDL_GameControllerQuitMappings(void)
void SDL_JoystickClose(SDL_Joystick *joystick)
Definition: SDL_joystick.c:643
static SDL_bool SDL_updating_joystick
Definition: SDL_joystick.c:82
static SDL_Joystick * SDL_joysticks
Definition: SDL_joystick.c:81
void(* Quit)(void)
static SDL_mutex * mutex
Definition: testlock.c:23

References i, mutex, NULL, SDL_JoystickDriver::Quit, SDL_arraysize, SDL_Delay, SDL_DelHintCallback, SDL_DestroyMutex, SDL_GameControllerQuitMappings(), SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS, SDL_INIT_EVENTS, SDL_joystick_drivers, SDL_joystick_lock, SDL_JoystickAllowBackgroundEventsChanged(), SDL_JoystickClose(), SDL_joysticks, SDL_LockJoysticks(), SDL_QuitSubSystem, SDL_UnlockJoysticks(), and SDL_updating_joystick.

Referenced by SDL_QuitSubSystem().

◆ SDL_PrivateJoystickAdded()

void SDL_PrivateJoystickAdded ( SDL_JoystickID  device_instance)

Definition at line 755 of file SDL_joystick.c.

756{
757#if !SDL_EVENTS_DISABLED
759 int device_index;
760
761 device_index = SDL_JoystickGetDeviceIndexFromInstanceID(device_instance);
762 if (device_index < 0) {
763 return;
764 }
765
766 event.type = SDL_JOYDEVICEADDED;
767
768 if (SDL_GetEventState(event.type) == SDL_ENABLE) {
769 event.jdevice.which = device_index;
771 }
772#endif /* !SDL_EVENTS_DISABLED */
773}
@ SDL_JOYDEVICEADDED
Definition: SDL_events.h:116
#define SDL_GetEventState(type)
Definition: SDL_events.h:772
#define SDL_ENABLE
Definition: SDL_events.h:759
int SDL_JoystickGetDeviceIndexFromInstanceID(SDL_JoystickID instance_id)
struct _cl_event * event

References SDL_ENABLE, SDL_GetEventState, SDL_JOYDEVICEADDED, SDL_JoystickGetDeviceIndexFromInstanceID(), and SDL_PushEvent.

Referenced by IOS_AddJoystickDevice().

◆ SDL_PrivateJoystickAxis()

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

Definition at line 833 of file SDL_joystick.c.

834{
835 int posted;
836
837 /* Make sure we're not getting garbage or duplicate events */
838 if (axis >= joystick->naxes) {
839 return 0;
840 }
841 if (!joystick->axes[axis].has_initial_value) {
842 joystick->axes[axis].initial_value = value;
843 joystick->axes[axis].value = value;
844 joystick->axes[axis].zero = value;
845 joystick->axes[axis].has_initial_value = SDL_TRUE;
846 }
847 if (value == joystick->axes[axis].value) {
848 return 0;
849 }
850 if (!joystick->axes[axis].sent_initial_value) {
851 /* Make sure we don't send motion until there's real activity on this axis */
852 const int MAX_ALLOWED_JITTER = SDL_JOYSTICK_AXIS_MAX / 80; /* ShanWan PS3 controller needed 96 */
853 if (SDL_abs(value - joystick->axes[axis].value) <= MAX_ALLOWED_JITTER) {
854 return 0;
855 }
856 joystick->axes[axis].sent_initial_value = SDL_TRUE;
857 joystick->axes[axis].value = value; /* Just so we pass the check above */
858 SDL_PrivateJoystickAxis(joystick, axis, joystick->axes[axis].initial_value);
859 }
860
861 /* We ignore events if we don't have keyboard focus, except for centering
862 * events.
863 */
865 if ((value > joystick->axes[axis].zero && value >= joystick->axes[axis].value) ||
866 (value < joystick->axes[axis].zero && value <= joystick->axes[axis].value)) {
867 return 0;
868 }
869 }
870
871 /* Update internal joystick state */
872 joystick->axes[axis].value = value;
873
874 /* Post the event, if desired */
875 posted = 0;
876#if !SDL_EVENTS_DISABLED
879 event.type = SDL_JOYAXISMOTION;
880 event.jaxis.which = joystick->instance_id;
881 event.jaxis.axis = axis;
882 event.jaxis.value = value;
883 posted = SDL_PushEvent(&event) == 1;
884 }
885#endif /* !SDL_EVENTS_DISABLED */
886 return posted;
887}
#define SDL_abs
@ SDL_JOYAXISMOTION
Definition: SDL_events.h:111
static SDL_bool SDL_PrivateJoystickShouldIgnoreEvent()
Definition: SDL_joystick.c:740
int SDL_PrivateJoystickAxis(SDL_Joystick *joystick, Uint8 axis, Sint16 value)
Definition: SDL_joystick.c:833
#define SDL_JOYSTICK_AXIS_MAX
Definition: SDL_joystick.h:301
GLsizei const GLfloat * value
SDL_Texture * axis

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 IOS_AccelerometerUpdate(), IOS_MFIJoystickUpdate(), SDL_JoystickUpdate(), and SDL_PrivateJoystickAxis().

◆ SDL_PrivateJoystickBall()

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

Definition at line 930 of file SDL_joystick.c.

932{
933 int posted;
934
935 /* Make sure we're not getting garbage events */
936 if (ball >= joystick->nballs) {
937 return 0;
938 }
939
940 /* We ignore events if we don't have keyboard focus. */
942 return 0;
943 }
944
945 /* Update internal mouse state */
946 joystick->balls[ball].dx += xrel;
947 joystick->balls[ball].dy += yrel;
948
949 /* Post the event, if desired */
950 posted = 0;
951#if !SDL_EVENTS_DISABLED
954 event.jball.type = SDL_JOYBALLMOTION;
955 event.jball.which = joystick->instance_id;
956 event.jball.ball = ball;
957 event.jball.xrel = xrel;
958 event.jball.yrel = yrel;
959 posted = SDL_PushEvent(&event) == 1;
960 }
961#endif /* !SDL_EVENTS_DISABLED */
962 return posted;
963}
@ SDL_JOYBALLMOTION
Definition: SDL_events.h:112

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

◆ SDL_PrivateJoystickBatteryLevel()

void SDL_PrivateJoystickBatteryLevel ( SDL_Joystick *  joystick,
SDL_JoystickPowerLevel  ePowerLevel 
)

Definition at line 1696 of file SDL_joystick.c.

1697{
1698 joystick->epowerlevel = ePowerLevel;
1699}

◆ SDL_PrivateJoystickButton()

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

Definition at line 966 of file SDL_joystick.c.

967{
968 int posted;
969#if !SDL_EVENTS_DISABLED
971
972 switch (state) {
973 case SDL_PRESSED:
974 event.type = SDL_JOYBUTTONDOWN;
975 break;
976 case SDL_RELEASED:
977 event.type = SDL_JOYBUTTONUP;
978 break;
979 default:
980 /* Invalid state -- bail */
981 return 0;
982 }
983#endif /* !SDL_EVENTS_DISABLED */
984
985 /* Make sure we're not getting garbage or duplicate events */
986 if (button >= joystick->nbuttons) {
987 return 0;
988 }
989 if (state == joystick->buttons[button]) {
990 return 0;
991 }
992
993 /* We ignore events if we don't have keyboard focus, except for button
994 * release. */
996 if (state == SDL_PRESSED) {
997 return 0;
998 }
999 }
1000
1001 /* Update internal joystick state */
1002 joystick->buttons[button] = state;
1003
1004 /* Post the event, if desired */
1005 posted = 0;
1006#if !SDL_EVENTS_DISABLED
1007 if (SDL_GetEventState(event.type) == SDL_ENABLE) {
1008 event.jbutton.which = joystick->instance_id;
1009 event.jbutton.button = button;
1010 event.jbutton.state = state;
1011 posted = SDL_PushEvent(&event) == 1;
1012 }
1013#endif /* !SDL_EVENTS_DISABLED */
1014 return posted;
1015}
@ SDL_JOYBUTTONDOWN
Definition: SDL_events.h:114
@ SDL_JOYBUTTONUP
Definition: SDL_events.h:115
#define SDL_PRESSED
Definition: SDL_events.h:50
struct xkb_state * state
SDL_Texture * button

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

Referenced by IOS_MFIJoystickUpdate(), and SDL_JoystickUpdate().

◆ SDL_PrivateJoystickHat()

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

Definition at line 890 of file SDL_joystick.c.

891{
892 int posted;
893
894 /* Make sure we're not getting garbage or duplicate events */
895 if (hat >= joystick->nhats) {
896 return 0;
897 }
898 if (value == joystick->hats[hat]) {
899 return 0;
900 }
901
902 /* We ignore events if we don't have keyboard focus, except for centering
903 * events.
904 */
906 if (value != SDL_HAT_CENTERED) {
907 return 0;
908 }
909 }
910
911 /* Update internal joystick state */
912 joystick->hats[hat] = value;
913
914 /* Post the event, if desired */
915 posted = 0;
916#if !SDL_EVENTS_DISABLED
919 event.jhat.type = SDL_JOYHATMOTION;
920 event.jhat.which = joystick->instance_id;
921 event.jhat.hat = hat;
922 event.jhat.value = value;
923 posted = SDL_PushEvent(&event) == 1;
924 }
925#endif /* !SDL_EVENTS_DISABLED */
926 return posted;
927}
@ SDL_JOYHATMOTION
Definition: SDL_events.h:113
#define SDL_HAT_CENTERED
Definition: SDL_joystick.h:329

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

Referenced by IOS_MFIJoystickUpdate(), and SDL_JoystickUpdate().

◆ SDL_PrivateJoystickRemoved()

void SDL_PrivateJoystickRemoved ( SDL_JoystickID  device_instance)

Definition at line 805 of file SDL_joystick.c.

806{
807 SDL_Joystick *joystick;
808
809#if !SDL_EVENTS_DISABLED
811
812 event.type = SDL_JOYDEVICEREMOVED;
813
814 if (SDL_GetEventState(event.type) == SDL_ENABLE) {
815 event.jdevice.which = device_instance;
817 }
818
820#endif /* !SDL_EVENTS_DISABLED */
821
822 /* Mark this joystick as no longer attached */
823 for (joystick = SDL_joysticks; joystick; joystick = joystick->next) {
824 if (joystick->instance_id == device_instance) {
825 joystick->attached = SDL_FALSE;
826 joystick->force_recentering = SDL_TRUE;
827 break;
828 }
829 }
830}
@ SDL_JOYDEVICEREMOVED
Definition: SDL_events.h:117
static void UpdateEventsForDeviceRemoval()
Definition: SDL_joystick.c:780

References SDL_ENABLE, SDL_FALSE, SDL_GetEventState, SDL_JOYDEVICEREMOVED, SDL_joysticks, SDL_PushEvent, SDL_TRUE, and UpdateEventsForDeviceRemoval().

Referenced by IOS_RemoveJoystickDevice().

◆ SDL_PrivateJoystickValid()

int SDL_PrivateJoystickValid ( SDL_Joystick *  joystick)

◆ SDL_ShouldIgnoreGameController()

SDL_bool SDL_ShouldIgnoreGameController ( const char *  name,
SDL_JoystickGUID  guid 
)

Definition at line 1476 of file SDL_gamecontroller.c.

1477{
1478 int i;
1479 Uint16 vendor;
1480 Uint16 product;
1481 Uint16 version;
1482 Uint32 vidpid;
1483
1484#if defined(__LINUX__)
1485 if (name && SDL_strstr(name, "Wireless Controller Motion Sensors")) {
1486 /* Don't treat the PS4 motion controls as a separate game controller */
1487 return SDL_TRUE;
1488 }
1489#endif
1490
1493 return SDL_FALSE;
1494 }
1495
1496 SDL_GetJoystickGUIDInfo(guid, &vendor, &product, &version);
1497
1498 if (SDL_GetHintBoolean("SDL_GAMECONTROLLER_ALLOW_STEAM_VIRTUAL_GAMEPAD", SDL_FALSE)) {
1499 /* 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 */
1500 SDL_bool bSteamVirtualGamepad = SDL_FALSE;
1501#if defined(__LINUX__)
1502 bSteamVirtualGamepad = (vendor == 0x28DE && product == 0x11FF);
1503#elif defined(__MACOSX__)
1504 bSteamVirtualGamepad = (vendor == 0x045E && product == 0x028E && version == 1);
1505#elif defined(__WIN32__)
1506 /* We can't tell on Windows, but Steam will block others in input hooks */
1507 bSteamVirtualGamepad = SDL_TRUE;
1508#endif
1509 if (bSteamVirtualGamepad) {
1510 return SDL_FALSE;
1511 }
1512 }
1513
1514 vidpid = MAKE_VIDPID(vendor, product);
1515
1517 for (i = 0; i < SDL_allowed_controllers.num_entries; ++i) {
1518 if (vidpid == SDL_allowed_controllers.entries[i]) {
1519 return SDL_FALSE;
1520 }
1521 }
1522 return SDL_TRUE;
1523 } else {
1524 for (i = 0; i < SDL_ignored_controllers.num_entries; ++i) {
1525 if (vidpid == SDL_ignored_controllers.entries[i]) {
1526 return SDL_TRUE;
1527 }
1528 }
1529 return SDL_FALSE;
1530 }
1531}
#define SDL_strstr
#define SDL_GetHintBoolean
void SDL_GetJoystickGUIDInfo(SDL_JoystickGUID guid, Uint16 *vendor, Uint16 *product, Uint16 *version)
SDL_bool
Definition: SDL_stdinc.h:162
uint32_t Uint32
Definition: SDL_stdinc.h:203
#define MAKE_VIDPID(VID, PID)

References SDL_vidpid_list::entries, i, MAKE_VIDPID, SDL_vidpid_list::num_entries, SDL_allowed_controllers, SDL_FALSE, SDL_GetHintBoolean, SDL_GetJoystickGUIDInfo(), SDL_ignored_controllers, SDL_strstr, and SDL_TRUE.

Referenced by SDL_ShouldIgnoreJoystick().

◆ SDL_ShouldIgnoreJoystick()

SDL_bool SDL_ShouldIgnoreJoystick ( const char *  name,
SDL_JoystickGUID  guid 
)

Definition at line 1359 of file SDL_joystick.c.

1360{
1361 /* This list is taken from:
1362 https://raw.githubusercontent.com/denilsonsa/udev-joystick-blacklist/master/generate_rules.py
1363 */
1364 static Uint32 joystick_blacklist[] = {
1365 /* Microsoft Microsoft Wireless Optical Desktop® 2.10 */
1366 /* Microsoft Wireless Desktop - Comfort Edition */
1367 MAKE_VIDPID(0x045e, 0x009d),
1368
1369 /* Microsoft Microsoft® Digital Media Pro Keyboard */
1370 /* Microsoft Corp. Digital Media Pro Keyboard */
1371 MAKE_VIDPID(0x045e, 0x00b0),
1372
1373 /* Microsoft Microsoft® Digital Media Keyboard */
1374 /* Microsoft Corp. Digital Media Keyboard 1.0A */
1375 MAKE_VIDPID(0x045e, 0x00b4),
1376
1377 /* Microsoft Microsoft® Digital Media Keyboard 3000 */
1378 MAKE_VIDPID(0x045e, 0x0730),
1379
1380 /* Microsoft Microsoft® 2.4GHz Transceiver v6.0 */
1381 /* Microsoft Microsoft® 2.4GHz Transceiver v8.0 */
1382 /* Microsoft Corp. Nano Transceiver v1.0 for Bluetooth */
1383 /* Microsoft Wireless Mobile Mouse 1000 */
1384 /* Microsoft Wireless Desktop 3000 */
1385 MAKE_VIDPID(0x045e, 0x0745),
1386
1387 /* Microsoft® SideWinder(TM) 2.4GHz Transceiver */
1388 MAKE_VIDPID(0x045e, 0x0748),
1389
1390 /* Microsoft Corp. Wired Keyboard 600 */
1391 MAKE_VIDPID(0x045e, 0x0750),
1392
1393 /* Microsoft Corp. Sidewinder X4 keyboard */
1394 MAKE_VIDPID(0x045e, 0x0768),
1395
1396 /* Microsoft Corp. Arc Touch Mouse Transceiver */
1397 MAKE_VIDPID(0x045e, 0x0773),
1398
1399 /* Microsoft® 2.4GHz Transceiver v9.0 */
1400 /* Microsoft® Nano Transceiver v2.1 */
1401 /* Microsoft Sculpt Ergonomic Keyboard (5KV-00001) */
1402 MAKE_VIDPID(0x045e, 0x07a5),
1403
1404 /* Microsoft® Nano Transceiver v1.0 */
1405 /* Microsoft Wireless Keyboard 800 */
1406 MAKE_VIDPID(0x045e, 0x07b2),
1407
1408 /* Microsoft® Nano Transceiver v2.0 */
1409 MAKE_VIDPID(0x045e, 0x0800),
1410
1411 MAKE_VIDPID(0x046d, 0xc30a), /* Logitech, Inc. iTouch Composite keboard */
1412
1413 MAKE_VIDPID(0x04d9, 0xa0df), /* Tek Syndicate Mouse (E-Signal USB Gaming Mouse) */
1414
1415 /* List of Wacom devices at: http://linuxwacom.sourceforge.net/wiki/index.php/Device_IDs */
1416 MAKE_VIDPID(0x056a, 0x0010), /* Wacom ET-0405 Graphire */
1417 MAKE_VIDPID(0x056a, 0x0011), /* Wacom ET-0405A Graphire2 (4x5) */
1418 MAKE_VIDPID(0x056a, 0x0012), /* Wacom ET-0507A Graphire2 (5x7) */
1419 MAKE_VIDPID(0x056a, 0x0013), /* Wacom CTE-430 Graphire3 (4x5) */
1420 MAKE_VIDPID(0x056a, 0x0014), /* Wacom CTE-630 Graphire3 (6x8) */
1421 MAKE_VIDPID(0x056a, 0x0015), /* Wacom CTE-440 Graphire4 (4x5) */
1422 MAKE_VIDPID(0x056a, 0x0016), /* Wacom CTE-640 Graphire4 (6x8) */
1423 MAKE_VIDPID(0x056a, 0x0017), /* Wacom CTE-450 Bamboo Fun (4x5) */
1424 MAKE_VIDPID(0x056a, 0x0018), /* Wacom CTE-650 Bamboo Fun 6x8 */
1425 MAKE_VIDPID(0x056a, 0x0019), /* Wacom CTE-631 Bamboo One */
1426 MAKE_VIDPID(0x056a, 0x00d1), /* Wacom Bamboo Pen and Touch CTH-460 */
1427 MAKE_VIDPID(0x056a, 0x030e), /* Wacom Intuos Pen (S) CTL-480 */
1428
1429 MAKE_VIDPID(0x09da, 0x054f), /* A4 Tech Co., G7 750 mouse */
1430 MAKE_VIDPID(0x09da, 0x1410), /* A4 Tech Co., Ltd Bloody AL9 mouse */
1431 MAKE_VIDPID(0x09da, 0x3043), /* A4 Tech Co., Ltd Bloody R8A Gaming Mouse */
1432 MAKE_VIDPID(0x09da, 0x31b5), /* A4 Tech Co., Ltd Bloody TL80 Terminator Laser Gaming Mouse */
1433 MAKE_VIDPID(0x09da, 0x3997), /* A4 Tech Co., Ltd Bloody RT7 Terminator Wireless */
1434 MAKE_VIDPID(0x09da, 0x3f8b), /* A4 Tech Co., Ltd Bloody V8 mouse */
1435 MAKE_VIDPID(0x09da, 0x51f4), /* Modecom MC-5006 Keyboard */
1436 MAKE_VIDPID(0x09da, 0x5589), /* A4 Tech Co., Ltd Terminator TL9 Laser Gaming Mouse */
1437 MAKE_VIDPID(0x09da, 0x7b22), /* A4 Tech Co., Ltd Bloody V5 */
1438 MAKE_VIDPID(0x09da, 0x7f2d), /* A4 Tech Co., Ltd Bloody R3 mouse */
1439 MAKE_VIDPID(0x09da, 0x8090), /* A4 Tech Co., Ltd X-718BK Oscar Optical Gaming Mouse */
1440 MAKE_VIDPID(0x09da, 0x9033), /* A4 Tech Co., X7 X-705K */
1441 MAKE_VIDPID(0x09da, 0x9066), /* A4 Tech Co., Sharkoon Fireglider Optical */
1442 MAKE_VIDPID(0x09da, 0x9090), /* A4 Tech Co., Ltd XL-730K / XL-750BK / XL-755BK Laser Mouse */
1443 MAKE_VIDPID(0x09da, 0x90c0), /* A4 Tech Co., Ltd X7 G800V keyboard */
1444 MAKE_VIDPID(0x09da, 0xf012), /* A4 Tech Co., Ltd Bloody V7 mouse */
1445 MAKE_VIDPID(0x09da, 0xf32a), /* A4 Tech Co., Ltd Bloody B540 keyboard */
1446 MAKE_VIDPID(0x09da, 0xf613), /* A4 Tech Co., Ltd Bloody V2 mouse */
1447 MAKE_VIDPID(0x09da, 0xf624), /* A4 Tech Co., Ltd Bloody B120 Keyboard */
1448
1449 MAKE_VIDPID(0x1b1c, 0x1b3c), /* Corsair Harpoon RGB gaming mouse */
1450
1451 MAKE_VIDPID(0x1d57, 0xad03), /* [T3] 2.4GHz and IR Air Mouse Remote Control */
1452
1453 MAKE_VIDPID(0x1e7d, 0x2e4a), /* Roccat Tyon Mouse */
1454
1455 MAKE_VIDPID(0x20a0, 0x422d), /* Winkeyless.kr Keyboards */
1456
1457 MAKE_VIDPID(0x2516, 0x001f), /* Cooler Master Storm Mizar Mouse */
1458 MAKE_VIDPID(0x2516, 0x0028), /* Cooler Master Storm Alcor Mouse */
1459 };
1460
1461 unsigned int i;
1462 Uint32 id;
1463 Uint16 vendor;
1464 Uint16 product;
1465
1466 SDL_GetJoystickGUIDInfo(guid, &vendor, &product, NULL);
1467
1468 /* Check the joystick blacklist */
1469 id = MAKE_VIDPID(vendor, product);
1470 for (i = 0; i < SDL_arraysize(joystick_blacklist); ++i) {
1471 if (id == joystick_blacklist[i]) {
1472 return SDL_TRUE;
1473 }
1474 }
1475
1476 if (SDL_IsJoystickPS4(vendor, product) && SDL_IsPS4RemapperRunning()) {
1477 return SDL_TRUE;
1478 }
1479
1482 return SDL_TRUE;
1483 }
1484
1485 return SDL_FALSE;
1486}
SDL_bool SDL_IsGameControllerNameAndGUID(const char *name, SDL_JoystickGUID guid)
SDL_bool SDL_ShouldIgnoreGameController(const char *name, SDL_JoystickGUID guid)
SDL_bool SDL_IsJoystickPS4(Uint16 vendor, Uint16 product)
static SDL_bool SDL_IsPS4RemapperRunning(void)
GLuint id

References i, MAKE_VIDPID, NULL, SDL_arraysize, SDL_FALSE, SDL_GetJoystickGUIDInfo(), SDL_IsGameControllerNameAndGUID(), SDL_IsJoystickPS4(), SDL_IsPS4RemapperRunning(), SDL_ShouldIgnoreGameController(), and SDL_TRUE.