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 2063 of file SDL_gamecontroller.c.

References SDL_CONTROLLER_BUTTON_GUIDE, SDL_gamecontrollers, SDL_PrivateGameControllerButton(), and SDL_RELEASED.

Referenced by SDL_JoystickUpdate().

2064 {
2065  SDL_GameController *controllerlist = SDL_gamecontrollers;
2066  while (controllerlist) {
2067  if (controllerlist->joystick == joystick) {
2069  break;
2070  }
2071  controllerlist = controllerlist->next;
2072  }
2073 }
static SDL_GameController * SDL_gamecontrollers
static int SDL_PrivateGameControllerButton(SDL_GameController *gamecontroller, SDL_GameControllerButton button, Uint8 state)
#define SDL_RELEASED
Definition: SDL_events.h:49

◆ SDL_GameControllerInit()

int SDL_GameControllerInit ( void  )

Definition at line 1358 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().

1359 {
1360  int i;
1361 
1362  /* watch for joy events and fire controller ones if needed */
1364 
1365  /* Send added events for controllers currently attached */
1366  for (i = 0; i < SDL_NumJoysticks(); ++i) {
1367  if (SDL_IsGameController(i)) {
1368  SDL_Event deviceevent;
1369  deviceevent.type = SDL_CONTROLLERDEVICEADDED;
1370  deviceevent.cdevice.which = i;
1371  SDL_PushEvent(&deviceevent);
1372  }
1373  }
1374 
1375  return (0);
1376 }
static int SDL_GameControllerEventWatcher(void *userdata, SDL_Event *event)
SDL_ControllerDeviceEvent cdevice
Definition: SDL_events.h:576
#define SDL_NumJoysticks
#define SDL_PushEvent
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_bool SDL_IsGameController(int device_index)
#define NULL
Definition: begin_code.h:164
#define SDL_AddEventWatch
General event structure.
Definition: SDL_events.h:557
Uint32 type
Definition: SDL_events.h:559

◆ SDL_GameControllerInitMappings()

int SDL_GameControllerInitMappings ( void  )

Definition at line 1329 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().

1330 {
1331  char szControllerMapPath[1024];
1332  int i = 0;
1333  const char *pMappingString = NULL;
1334  pMappingString = s_ControllerMappings[i];
1335  while (pMappingString) {
1337 
1338  i++;
1339  pMappingString = s_ControllerMappings[i];
1340  }
1341 
1342  if (SDL_GetControllerMappingFilePath(szControllerMapPath, sizeof(szControllerMapPath))) {
1343  SDL_GameControllerAddMappingsFromFile(szControllerMapPath);
1344  }
1345 
1346  /* load in any user supplied config */
1348 
1353 
1354  return (0);
1355 }
static SDL_bool SDL_GetControllerMappingFilePath(char *path, size_t size)
static void SDL_GameControllerLoadHints()
static int SDL_PrivateGameControllerAddMapping(const char *mappingString, SDL_ControllerMappingPriority priority)
#define SDL_HINT_GAMECONTROLLER_IGNORE_DEVICES_EXCEPT
Definition: SDL_hints.h:463
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:164
static void SDL_GameControllerIgnoreDevicesExceptChanged(void *userdata, const char *name, const char *oldValue, const char *hint)
static const char * s_ControllerMappings[]
#define SDL_AddHintCallback
#define SDL_GameControllerAddMappingsFromFile(file)
#define SDL_HINT_GAMECONTROLLER_IGNORE_DEVICES
Definition: SDL_hints.h:450
static void SDL_GameControllerIgnoreDevicesChanged(void *userdata, const char *name, const char *oldValue, const char *hint)

◆ SDL_GameControllerQuit()

void SDL_GameControllerQuit ( void  )

Definition at line 1906 of file SDL_gamecontroller.c.

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

Referenced by SDL_QuitSubSystem().

1907 {
1909  while (SDL_gamecontrollers) {
1910  SDL_gamecontrollers->ref_count = 1;
1912  }
1914 }
#define SDL_UnlockJoysticks
void SDL_GameControllerClose(SDL_GameController *gamecontroller)
static SDL_GameController * SDL_gamecontrollers
#define SDL_LockJoysticks

◆ SDL_GameControllerQuitMappings()

void SDL_GameControllerQuitMappings ( void  )

Definition at line 1917 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().

1918 {
1919  ControllerMapping_t *pControllerMap;
1920 
1921  while (s_pSupportedControllers) {
1922  pControllerMap = s_pSupportedControllers;
1924  SDL_free(pControllerMap->name);
1925  SDL_free(pControllerMap->mapping);
1926  SDL_free(pControllerMap);
1927  }
1928 
1930 
1935 
1939  }
1943  }
1944 }
#define SDL_DelEventWatch
static int SDL_GameControllerEventWatcher(void *userdata, SDL_Event *event)
struct _ControllerMapping_t * next
static SDL_vidpid_list SDL_ignored_controllers
static ControllerMapping_t * s_pSupportedControllers
#define SDL_free
#define SDL_HINT_GAMECONTROLLER_IGNORE_DEVICES_EXCEPT
Definition: SDL_hints.h:463
#define SDL_zero(x)
Definition: SDL_stdinc.h:416
#define NULL
Definition: begin_code.h:164
static void SDL_GameControllerIgnoreDevicesExceptChanged(void *userdata, const char *name, const char *oldValue, const char *hint)
static SDL_vidpid_list SDL_allowed_controllers
#define SDL_DelHintCallback
#define SDL_HINT_GAMECONTROLLER_IGNORE_DEVICES
Definition: SDL_hints.h:450
static void SDL_GameControllerIgnoreDevicesChanged(void *userdata, const char *name, const char *oldValue, const char *hint)

◆ 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 1113 of file SDL_joystick.c.

References SDL_JoystickGUID::data, and if.

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

1114 {
1115  Uint16 *guid16 = (Uint16 *)guid.data;
1116 
1117  /* If the GUID fits the form of BUS 0000 VENDOR 0000 PRODUCT 0000, return the data */
1118  if (/* guid16[0] is device bus type */
1119  guid16[1] == 0x0000 &&
1120  /* guid16[2] is vendor ID */
1121  guid16[3] == 0x0000 &&
1122  /* guid16[4] is product ID */
1123  guid16[5] == 0x0000
1124  /* guid16[6] is product version */
1125  ) {
1126  if (vendor) {
1127  *vendor = guid16[2];
1128  }
1129  if (product) {
1130  *product = guid16[4];
1131  }
1132  if (version) {
1133  *version = guid16[6];
1134  }
1135  } else {
1136  if (vendor) {
1137  *vendor = 0;
1138  }
1139  if (product) {
1140  *product = 0;
1141  }
1142  if (version) {
1143  *version = 0;
1144  }
1145  }
1146 }
set set set set set set set macro pixldst1 abits if abits op else op endif endm macro pixldst2 abits if abits op else op endif endm macro pixldst4 abits if abits op else op endif endm macro pixldst0 abits op endm macro pixldst3 mem_operand op endm macro pixldst30 mem_operand op endm macro pixldst abits if abits elseif abits elseif abits elseif abits elseif abits pixldst0 abits else pixldst0 abits pixldst0 abits pixldst0 abits pixldst0 abits endif elseif abits else pixldst0 abits pixldst0 abits endif elseif abits else error unsupported bpp *numpix else pixst endif endm macro pixld1_s mem_operand if asr adds SRC_WIDTH_FIXED bpl add asl mov asr adds SRC_WIDTH_FIXED bpl add asl mov asr adds SRC_WIDTH_FIXED bpl add asl mov asr adds SRC_WIDTH_FIXED bpl add asl elseif asr adds SRC_WIDTH_FIXED bpl add asl mov asr adds SRC_WIDTH_FIXED bpl add asl else error unsupported endif endm macro pixld2_s mem_operand if mov asr add asl add asl mov asr sub UNIT_X add asl mov asr add asl add asl mov asr add UNIT_X add asl else pixld1_s mem_operand pixld1_s mem_operand endif endm macro pixld0_s mem_operand if asr adds SRC_WIDTH_FIXED bpl add asl elseif asr adds SRC_WIDTH_FIXED bpl add asl endif endm macro pixld_s_internal mem_operand if mem_operand pixld2_s mem_operand pixdeinterleave basereg elseif mem_operand elseif mem_operand elseif mem_operand elseif mem_operand pixld0_s mem_operand else pixld0_s mem_operand pixld0_s mem_operand pixld0_s mem_operand pixld0_s mem_operand endif elseif mem_operand else pixld0_s mem_operand pixld0_s mem_operand endif elseif mem_operand else error unsupported mem_operand if bpp mem_operand endif endm macro vuzp8 reg2 vuzp d d &reg2 endm macro vzip8 reg2 vzip d d &reg2 endm macro pixdeinterleave basereg basereg basereg basereg basereg endif endm macro pixinterleave basereg basereg basereg basereg basereg endif endm macro PF boost_increment endif if endif PF tst PF addne PF subne PF cmp ORIG_W if endif if endif if endif PF subge ORIG_W PF subges if endif if endif if endif endif endm macro cache_preload_simple endif if dst_r_bpp pld [DST_R, #(PREFETCH_DISTANCE_SIMPLE *dst_r_bpp/8)] endif if mask_bpp pld if[MASK, #(PREFETCH_DISTANCE_SIMPLE *mask_bpp/8)] endif endif endm macro fetch_mask_pixblock pixld mask_basereg pixblock_size MASK endm macro ensure_destination_ptr_alignment process_pixblock_tail_head if beq irp local skip1(dst_w_bpp<=(lowbit *8)) &&((lowbit *8)<(pixblock_size *dst_w_bpp)) .if lowbit< 16 tst DST_R
uint16_t Uint16
Definition: SDL_stdinc.h:191
Uint8 data[16]
Definition: SDL_joystick.h:71

◆ SDL_GetNextJoystickInstanceID()

SDL_JoystickID SDL_GetNextJoystickInstanceID ( void  )

Definition at line 163 of file SDL_joystick.c.

References SDL_AtomicIncRef.

Referenced by IOS_AddJoystickDevice().

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

◆ SDL_IsGameControllerNameAndGUID()

SDL_bool SDL_IsGameControllerNameAndGUID ( const char *  name,
SDL_JoystickGUID  guid 
)

Definition at line 1435 of file SDL_gamecontroller.c.

References SDL_FALSE, SDL_PrivateGetControllerMappingForNameAndGUID(), and SDL_TRUE.

Referenced by SDL_ShouldIgnoreJoystick().

1436 {
1438  if (pSupportedController) {
1439  return SDL_TRUE;
1440  }
1441  return SDL_FALSE;
1442 }
static ControllerMapping_t * SDL_PrivateGetControllerMappingForNameAndGUID(const char *name, SDL_JoystickGUID guid)
GLuint const GLchar * name

◆ SDL_IsJoystickHIDAPI()

SDL_bool SDL_IsJoystickHIDAPI ( SDL_JoystickGUID  guid)

Definition at line 1192 of file SDL_joystick.c.

References SDL_JoystickGUID::data, SDL_FALSE, and SDL_TRUE.

Referenced by SDL_PrivateGetControllerMappingForGUID(), and SDL_PrivateGetControllerMappingForNameAndGUID().

1193 {
1194  return (guid.data[14] == 'h') ? SDL_TRUE : SDL_FALSE;
1195 }
Uint8 data[16]
Definition: SDL_joystick.h:71

◆ SDL_IsJoystickNintendoSwitchPro()

SDL_bool SDL_IsJoystickNintendoSwitchPro ( Uint16  vendor_id,
Uint16  product_id 
)

Definition at line 1155 of file SDL_joystick.c.

References GuessControllerType(), and k_eControllerType_SwitchProController.

1156 {
1157  return (GuessControllerType(vendor, product) == k_eControllerType_SwitchProController);
1158 }
static EControllerType GuessControllerType(int nVID, int nPID)

◆ SDL_IsJoystickPS4()

SDL_bool SDL_IsJoystickPS4 ( Uint16  vendor_id,
Uint16  product_id 
)

Definition at line 1149 of file SDL_joystick.c.

References GuessControllerType(), and k_eControllerType_PS4Controller.

Referenced by SDL_ShouldIgnoreJoystick().

1150 {
1151  return (GuessControllerType(vendor, product) == k_eControllerType_PS4Controller);
1152 }
static EControllerType GuessControllerType(int nVID, int nPID)

◆ SDL_IsJoystickSteamController()

SDL_bool SDL_IsJoystickSteamController ( Uint16  vendor_id,
Uint16  product_id 
)

Definition at line 1161 of file SDL_joystick.c.

References BIsSteamController(), and GuessControllerType().

1162 {
1163  return BIsSteamController(GuessControllerType(vendor, product));
1164 }
static EControllerType GuessControllerType(int nVID, int nPID)
static SDL_bool BIsSteamController(EControllerType eType)

◆ SDL_IsJoystickXbox360()

SDL_bool SDL_IsJoystickXbox360 ( Uint16  vendor_id,
Uint16  product_id 
)

Definition at line 1167 of file SDL_joystick.c.

References GuessControllerType(), k_eControllerType_XBox360Controller, and SDL_FALSE.

1168 {
1169  /* Filter out some bogus values here */
1170  if (vendor == 0x0000 && product == 0x0000) {
1171  return SDL_FALSE;
1172  }
1173  if (vendor == 0x0001 && product == 0x0001) {
1174  return SDL_FALSE;
1175  }
1176  return (GuessControllerType(vendor, product) == k_eControllerType_XBox360Controller);
1177 }
static EControllerType GuessControllerType(int nVID, int nPID)

◆ SDL_IsJoystickXboxOne()

SDL_bool SDL_IsJoystickXboxOne ( Uint16  vendor_id,
Uint16  product_id 
)

Definition at line 1180 of file SDL_joystick.c.

References GuessControllerType(), and k_eControllerType_XBoxOneController.

1181 {
1182  return (GuessControllerType(vendor, product) == k_eControllerType_XBoxOneController);
1183 }
static EControllerType GuessControllerType(int nVID, int nPID)

◆ SDL_IsJoystickXInput()

SDL_bool SDL_IsJoystickXInput ( SDL_JoystickGUID  guid)

Definition at line 1186 of file SDL_joystick.c.

References SDL_JoystickGUID::data, SDL_FALSE, and SDL_TRUE.

Referenced by SDL_GetJoystickGUIDType(), and SDL_PrivateGetControllerMappingForGUID().

1187 {
1188  return (guid.data[14] == 'x') ? SDL_TRUE : SDL_FALSE;
1189 }
Uint8 data[16]
Definition: SDL_joystick.h:71

◆ SDL_JoystickGetDeviceIndexFromInstanceID()

int SDL_JoystickGetDeviceIndexFromInstanceID ( SDL_JoystickID  instance_id)

Definition at line 1434 of file SDL_joystick.c.

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

Referenced by SDL_PrivateJoystickAdded().

1435 {
1436  int i, num_joysticks, device_index = -1;
1437 
1439  num_joysticks = SDL_NumJoysticks();
1440  for (i = 0; i < num_joysticks; ++i) {
1441  if (SDL_JoystickGetDeviceInstanceID(i) == instance_id) {
1442  device_index = i;
1443  break;
1444  }
1445  }
1447 
1448  return device_index;
1449 }
void SDL_LockJoysticks(void)
Definition: SDL_joystick.c:87
int SDL_NumJoysticks(void)
Definition: SDL_joystick.c:148
void SDL_UnlockJoysticks(void)
Definition: SDL_joystick.c:95
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_JoystickID SDL_JoystickGetDeviceInstanceID(int device_index)

◆ SDL_JoystickInit()

int SDL_JoystickInit ( void  )

Definition at line 114 of file SDL_joystick.c.

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

Referenced by SDL_InitSubSystem().

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_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:476
#define SDL_INIT_EVENTS
Definition: SDL.h:83
int SDL_GameControllerInitMappings(void)
static SDL_mutex * SDL_joystick_lock
Definition: SDL_joystick.c:83
#define SDL_CreateMutex
#define SDL_InitSubSystem
static SDL_JoystickDriver * SDL_joystick_drivers[]
Definition: SDL_joystick.c:48
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:164
#define SDL_AddHintCallback
#define SDL_arraysize(array)
Definition: SDL_stdinc.h:115
static void SDL_JoystickAllowBackgroundEventsChanged(void *userdata, const char *name, const char *oldValue, const char *hint)
Definition: SDL_joystick.c:104

◆ SDL_JoystickQuit()

void SDL_JoystickQuit ( void  )

Definition at line 697 of file SDL_joystick.c.

References i, NULL, SDL_JoystickDriver::Quit, SDL_arraysize, 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_UnlockJoysticks(), and SDL_updating_joystick.

Referenced by SDL_QuitSubSystem().

698 {
699  int i;
700 
701  /* Make sure we're not getting called in the middle of updating joysticks */
703 
705 
706  /* Stop the event polling */
707  while (SDL_joysticks) {
708  SDL_joysticks->ref_count = 1;
710  }
711 
712  /* Quit the joystick setup */
713  for (i = 0; i < SDL_arraysize(SDL_joystick_drivers); ++i) {
715  }
716 
718 
719 #if !SDL_EVENTS_DISABLED
721 #endif
722 
725 
726  if (SDL_joystick_lock) {
729  }
730 
732 }
#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:476
#define SDL_INIT_EVENTS
Definition: SDL.h:83
void SDL_LockJoysticks(void)
Definition: SDL_joystick.c:87
void(* Quit)(void)
void SDL_JoystickClose(SDL_Joystick *joystick)
Definition: SDL_joystick.c:643
void SDL_GameControllerQuitMappings(void)
static SDL_mutex * SDL_joystick_lock
Definition: SDL_joystick.c:83
#define SDL_QuitSubSystem
static SDL_JoystickDriver * SDL_joystick_drivers[]
Definition: SDL_joystick.c:48
void SDL_UnlockJoysticks(void)
Definition: SDL_joystick.c:95
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 SDL_assert(condition)
Definition: SDL_assert.h:169
#define NULL
Definition: begin_code.h:164
#define SDL_DestroyMutex
#define SDL_DelHintCallback
#define SDL_arraysize(array)
Definition: SDL_stdinc.h:115
static void SDL_JoystickAllowBackgroundEventsChanged(void *userdata, const char *name, const char *oldValue, const char *hint)
Definition: SDL_joystick.c:104
static SDL_bool SDL_updating_joystick
Definition: SDL_joystick.c:82
static SDL_Joystick * SDL_joysticks
Definition: SDL_joystick.c:81

◆ SDL_PrivateJoystickAdded()

void SDL_PrivateJoystickAdded ( SDL_JoystickID  device_instance)

Definition at line 751 of file SDL_joystick.c.

References SDL_ENABLE, SDL_GetEventState, SDL_JOYDEVICEADDED, SDL_JoystickGetDeviceIndexFromInstanceID(), SDL_PushEvent, and SDL_Event::type.

Referenced by IOS_AddJoystickDevice().

752 {
753 #if !SDL_EVENTS_DISABLED
755  int device_index;
756 
757  device_index = SDL_JoystickGetDeviceIndexFromInstanceID(device_instance);
758  if (device_index < 0) {
759  return;
760  }
761 
762  event.type = SDL_JOYDEVICEADDED;
763 
764  if (SDL_GetEventState(event.type) == SDL_ENABLE) {
765  event.jdevice.which = device_index;
766  SDL_PushEvent(&event);
767  }
768 #endif /* !SDL_EVENTS_DISABLED */
769 }
int SDL_JoystickGetDeviceIndexFromInstanceID(SDL_JoystickID instance_id)
#define SDL_ENABLE
Definition: SDL_events.h:756
#define SDL_GetEventState(type)
Definition: SDL_events.h:769
struct _cl_event * event
#define SDL_PushEvent
General event structure.
Definition: SDL_events.h:557
Uint32 type
Definition: SDL_events.h:559

◆ SDL_PrivateJoystickAxis()

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

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

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

◆ SDL_PrivateJoystickBall()

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

Definition at line 925 of file SDL_joystick.c.

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

927 {
928  int posted;
929 
930  /* Make sure we're not getting garbage events */
931  if (ball >= joystick->nballs) {
932  return 0;
933  }
934 
935  /* We ignore events if we don't have keyboard focus. */
937  return 0;
938  }
939 
940  /* Update internal mouse state */
941  joystick->balls[ball].dx += xrel;
942  joystick->balls[ball].dy += yrel;
943 
944  /* Post the event, if desired */
945  posted = 0;
946 #if !SDL_EVENTS_DISABLED
949  event.jball.type = SDL_JOYBALLMOTION;
950  event.jball.which = joystick->instance_id;
951  event.jball.ball = ball;
952  event.jball.xrel = xrel;
953  event.jball.yrel = yrel;
954  posted = SDL_PushEvent(&event) == 1;
955  }
956 #endif /* !SDL_EVENTS_DISABLED */
957  return posted;
958 }
#define SDL_ENABLE
Definition: SDL_events.h:756
#define SDL_GetEventState(type)
Definition: SDL_events.h:769
struct _cl_event * event
#define SDL_PushEvent
static SDL_bool SDL_PrivateJoystickShouldIgnoreEvent()
Definition: SDL_joystick.c:736
General event structure.
Definition: SDL_events.h:557

◆ SDL_PrivateJoystickBatteryLevel()

void SDL_PrivateJoystickBatteryLevel ( SDL_Joystick *  joystick,
SDL_JoystickPowerLevel  ePowerLevel 
)

Definition at line 1570 of file SDL_joystick.c.

1571 {
1572  joystick->epowerlevel = ePowerLevel;
1573 }

◆ SDL_PrivateJoystickButton()

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

Definition at line 961 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 IOS_MFIJoystickUpdate(), and SDL_JoystickUpdate().

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

◆ SDL_PrivateJoystickHat()

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

Definition at line 885 of file SDL_joystick.c.

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

Referenced by IOS_MFIJoystickUpdate(), and SDL_JoystickUpdate().

886 {
887  int posted;
888 
889  /* Make sure we're not getting garbage or duplicate events */
890  if (hat >= joystick->nhats) {
891  return 0;
892  }
893  if (value == joystick->hats[hat]) {
894  return 0;
895  }
896 
897  /* We ignore events if we don't have keyboard focus, except for centering
898  * events.
899  */
901  if (value != SDL_HAT_CENTERED) {
902  return 0;
903  }
904  }
905 
906  /* Update internal joystick state */
907  joystick->hats[hat] = value;
908 
909  /* Post the event, if desired */
910  posted = 0;
911 #if !SDL_EVENTS_DISABLED
914  event.jhat.type = SDL_JOYHATMOTION;
915  event.jhat.which = joystick->instance_id;
916  event.jhat.hat = hat;
917  event.jhat.value = value;
918  posted = SDL_PushEvent(&event) == 1;
919  }
920 #endif /* !SDL_EVENTS_DISABLED */
921  return posted;
922 }
#define SDL_ENABLE
Definition: SDL_events.h:756
#define SDL_GetEventState(type)
Definition: SDL_events.h:769
struct _cl_event * event
#define SDL_PushEvent
GLsizei const GLfloat * value
static SDL_bool SDL_PrivateJoystickShouldIgnoreEvent()
Definition: SDL_joystick.c:736
General event structure.
Definition: SDL_events.h:557
#define SDL_HAT_CENTERED
Definition: SDL_joystick.h:329

◆ SDL_PrivateJoystickRemoved()

void SDL_PrivateJoystickRemoved ( SDL_JoystickID  device_instance)

Definition at line 800 of file SDL_joystick.c.

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

Referenced by IOS_RemoveJoystickDevice().

801 {
802  SDL_Joystick *joystick;
803 
804 #if !SDL_EVENTS_DISABLED
806 
807  event.type = SDL_JOYDEVICEREMOVED;
808 
809  if (SDL_GetEventState(event.type) == SDL_ENABLE) {
810  event.jdevice.which = device_instance;
811  SDL_PushEvent(&event);
812  }
813 
815 #endif /* !SDL_EVENTS_DISABLED */
816 
817  /* Mark this joystick as no longer attached */
818  for (joystick = SDL_joysticks; joystick; joystick = joystick->next) {
819  if (joystick->instance_id == device_instance) {
820  joystick->attached = SDL_FALSE;
821  joystick->force_recentering = SDL_TRUE;
822  break;
823  }
824  }
825 }
#define SDL_ENABLE
Definition: SDL_events.h:756
static void UpdateEventsForDeviceRemoval()
Definition: SDL_joystick.c:776
#define SDL_GetEventState(type)
Definition: SDL_events.h:769
struct _cl_event * event
#define SDL_PushEvent
General event structure.
Definition: SDL_events.h:557
Uint32 type
Definition: SDL_events.h:559
static SDL_Joystick * SDL_joysticks
Definition: SDL_joystick.c:81

◆ SDL_PrivateJoystickValid()

int SDL_PrivateJoystickValid ( SDL_Joystick *  joystick)

◆ SDL_ShouldIgnoreGameController()

SDL_bool SDL_ShouldIgnoreGameController ( const char *  name,
SDL_JoystickGUID  guid 
)

Definition at line 1460 of file SDL_gamecontroller.c.

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

Referenced by SDL_ShouldIgnoreJoystick().

1461 {
1462  int i;
1463  Uint16 vendor;
1464  Uint16 product;
1465  Uint16 version;
1466  Uint32 vidpid;
1467 
1470  return SDL_FALSE;
1471  }
1472 
1473  SDL_GetJoystickGUIDInfo(guid, &vendor, &product, &version);
1474 
1475  if (SDL_GetHintBoolean("SDL_GAMECONTROLLER_ALLOW_STEAM_VIRTUAL_GAMEPAD", SDL_FALSE)) {
1476  /* 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 */
1477  SDL_bool bSteamVirtualGamepad = SDL_FALSE;
1478 #if defined(__LINUX__)
1479  bSteamVirtualGamepad = (vendor == 0x28DE && product == 0x11FF);
1480 #elif defined(__MACOSX__)
1481  bSteamVirtualGamepad = (vendor == 0x045E && product == 0x028E && version == 1);
1482 #elif defined(__WIN32__)
1483  /* We can't tell on Windows, but Steam will block others in input hooks */
1484  bSteamVirtualGamepad = SDL_TRUE;
1485 #endif
1486  if (bSteamVirtualGamepad) {
1487  return SDL_FALSE;
1488  }
1489  }
1490 
1491  vidpid = MAKE_VIDPID(vendor, product);
1492 
1494  for (i = 0; i < SDL_allowed_controllers.num_entries; ++i) {
1495  if (vidpid == SDL_allowed_controllers.entries[i]) {
1496  return SDL_FALSE;
1497  }
1498  }
1499  return SDL_TRUE;
1500  } else {
1501  for (i = 0; i < SDL_ignored_controllers.num_entries; ++i) {
1502  if (vidpid == SDL_ignored_controllers.entries[i]) {
1503  return SDL_TRUE;
1504  }
1505  }
1506  return SDL_FALSE;
1507  }
1508 }
#define MAKE_VIDPID(VID, PID)
static SDL_vidpid_list SDL_ignored_controllers
uint16_t Uint16
Definition: SDL_stdinc.h:191
#define SDL_GetHintBoolean
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_bool
Definition: SDL_stdinc.h:161
static SDL_vidpid_list SDL_allowed_controllers
void SDL_GetJoystickGUIDInfo(SDL_JoystickGUID guid, Uint16 *vendor, Uint16 *product, Uint16 *version)
uint32_t Uint32
Definition: SDL_stdinc.h:203

◆ SDL_ShouldIgnoreJoystick()

SDL_bool SDL_ShouldIgnoreJoystick ( const char *  name,
SDL_JoystickGUID  guid 
)

Definition at line 1343 of file SDL_joystick.c.

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

1344 {
1345  Uint16 vendor;
1346  Uint16 product;
1347 
1348  SDL_GetJoystickGUIDInfo(guid, &vendor, &product, NULL);
1349 
1350  if (SDL_IsJoystickPS4(vendor, product) && SDL_IsPS4RemapperRunning()) {
1351  return SDL_TRUE;
1352  }
1353 
1356  return SDL_TRUE;
1357  }
1358 
1359  return SDL_FALSE;
1360 }
SDL_bool SDL_IsJoystickPS4(Uint16 vendor, Uint16 product)
uint16_t Uint16
Definition: SDL_stdinc.h:191
GLuint const GLchar * name
static SDL_bool SDL_IsPS4RemapperRunning(void)
SDL_bool SDL_ShouldIgnoreGameController(const char *name, SDL_JoystickGUID guid)
SDL_bool SDL_IsGameControllerNameAndGUID(const char *name, SDL_JoystickGUID guid)
#define NULL
Definition: begin_code.h:164
void SDL_GetJoystickGUIDInfo(SDL_JoystickGUID guid, Uint16 *vendor, Uint16 *product, Uint16 *version)