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.

2064 {
2065  SDL_GameController *controllerlist = SDL_gamecontrollers;
2066  while (controllerlist) {
2067  if (controllerlist->joystick == joystick) {
2069  break;
2070  }
2071  controllerlist = controllerlist->next;
2072  }
2073 }

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

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 }

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

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 }

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

1907 {
1909  while (SDL_gamecontrollers) {
1910  SDL_gamecontrollers->ref_count = 1;
1912  }
1914 }

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

Referenced by SDL_QuitSubSystem().

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

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 }

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 }

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

1436 {
1438  if (pSupportedController) {
1439  return SDL_TRUE;
1440  }
1441  return SDL_FALSE;
1442 }

References SDL_FALSE, SDL_PrivateGetControllerMappingForNameAndGUID(), and SDL_TRUE.

Referenced by SDL_ShouldIgnoreJoystick().

◆ SDL_IsJoystickHIDAPI()

SDL_bool SDL_IsJoystickHIDAPI ( SDL_JoystickGUID  guid)

Definition at line 1192 of file SDL_joystick.c.

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

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

1156 {
1157  return (GuessControllerType(vendor, product) == k_eControllerType_SwitchProController);
1158 }

References GuessControllerType(), and k_eControllerType_SwitchProController.

◆ SDL_IsJoystickPS4()

SDL_bool SDL_IsJoystickPS4 ( Uint16  vendor_id,
Uint16  product_id 
)

Definition at line 1149 of file SDL_joystick.c.

1150 {
1151  return (GuessControllerType(vendor, product) == k_eControllerType_PS4Controller);
1152 }

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

1162 {
1163  return BIsSteamController(GuessControllerType(vendor, product));
1164 }

References BIsSteamController(), and GuessControllerType().

◆ SDL_IsJoystickXbox360()

SDL_bool SDL_IsJoystickXbox360 ( Uint16  vendor_id,
Uint16  product_id 
)

Definition at line 1167 of file SDL_joystick.c.

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 }

References GuessControllerType(), k_eControllerType_XBox360Controller, and SDL_FALSE.

◆ SDL_IsJoystickXboxOne()

SDL_bool SDL_IsJoystickXboxOne ( Uint16  vendor_id,
Uint16  product_id 
)

Definition at line 1180 of file SDL_joystick.c.

1181 {
1182  return (GuessControllerType(vendor, product) == k_eControllerType_XBoxOneController);
1183 }

References GuessControllerType(), and k_eControllerType_XBoxOneController.

◆ SDL_IsJoystickXInput()

SDL_bool SDL_IsJoystickXInput ( SDL_JoystickGUID  guid)

Definition at line 1186 of file SDL_joystick.c.

1187 {
1188  return (guid.data[14] == 'x') ? SDL_TRUE : SDL_FALSE;
1189 }

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

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 }

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 }

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 
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 }

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_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 751 of file SDL_joystick.c.

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;
767  }
768 #endif /* !SDL_EVENTS_DISABLED */
769 }

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

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 }

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

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 }

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

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 }

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

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 }

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

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;
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 }

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

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 }

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, and SDL_TRUE.

Referenced by SDL_ShouldIgnoreJoystick().

◆ SDL_ShouldIgnoreJoystick()

SDL_bool SDL_ShouldIgnoreJoystick ( const char *  name,
SDL_JoystickGUID  guid 
)

Definition at line 1343 of file SDL_joystick.c.

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 }

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

SDL_zero
#define SDL_zero(x)
Definition: SDL_stdinc.h:416
SDL_Event::type
Uint32 type
Definition: SDL_events.h:559
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:476
SDL_IsGameController
SDL_bool SDL_IsGameController(int device_index)
Definition: SDL_gamecontroller.c:1448
SDL_GameControllerEventWatcher
static int SDL_GameControllerEventWatcher(void *userdata, SDL_Event *event)
Definition: SDL_gamecontroller.c:346
Uint16
uint16_t Uint16
Definition: SDL_stdinc.h:191
SDL_gamecontrollers
static SDL_GameController * SDL_gamecontrollers
Definition: SDL_gamecontroller.c:48
SDL_abs
#define SDL_abs
Definition: SDL_dynapi_overrides.h:381
SDL_UnlockJoysticks
#define SDL_UnlockJoysticks
Definition: SDL_dynapi_overrides.h:639
SDL_HAT_CENTERED
#define SDL_HAT_CENTERED
Definition: SDL_joystick.h:329
NULL
#define NULL
Definition: begin_code.h:164
k_eControllerType_SwitchProController
@ k_eControllerType_SwitchProController
Definition: controller_type.h:54
SDL_JoystickGetDeviceIndexFromInstanceID
int SDL_JoystickGetDeviceIndexFromInstanceID(SDL_JoystickID instance_id)
Definition: SDL_joystick.c:1434
SDL_IsPS4RemapperRunning
static SDL_bool SDL_IsPS4RemapperRunning(void)
Definition: SDL_joystick.c:1310
SDL_INIT_EVENTS
#define SDL_INIT_EVENTS
Definition: SDL.h:83
SDL_IsJoystickPS4
SDL_bool SDL_IsJoystickPS4(Uint16 vendor, Uint16 product)
Definition: SDL_joystick.c:1149
SDL_GameControllerIgnoreDevicesChanged
static void SDL_GameControllerIgnoreDevicesChanged(void *userdata, const char *name, const char *oldValue, const char *hint)
Definition: SDL_gamecontroller.c:182
SDL_NumJoysticks
#define SDL_NumJoysticks
Definition: SDL_dynapi_overrides.h:195
ControllerMapping_t
Definition: SDL_gamecontroller.c:94
SDL_AtomicIncRef
#define SDL_AtomicIncRef(a)
Increment an atomic variable used as a reference count.
Definition: SDL_atomic.h:234
SDL_QuitSubSystem
#define SDL_QuitSubSystem
Definition: SDL_dynapi_overrides.h:56
SDL_CreateMutex
#define SDL_CreateMutex
Definition: SDL_dynapi_overrides.h:259
SDL_vidpid_list::entries
Uint32 * entries
Definition: SDL_gamecontroller.c:129
SDL_ControllerDeviceEvent::which
Sint32 which
Definition: SDL_events.h:413
Uint32
uint32_t Uint32
Definition: SDL_stdinc.h:203
SDL_ENABLE
#define SDL_ENABLE
Definition: SDL_events.h:756
SDL_NumJoysticks
int SDL_NumJoysticks(void)
Definition: SDL_joystick.c:148
BIsSteamController
static SDL_bool BIsSteamController(EControllerType eType)
Definition: controller_type.h:67
SDL_UnlockJoysticks
void SDL_UnlockJoysticks(void)
Definition: SDL_joystick.c:95
SDL_JoystickGUID::data
Uint8 data[16]
Definition: SDL_joystick.h:71
SDL_JOYDEVICEREMOVED
@ SDL_JOYDEVICEREMOVED
Definition: SDL_events.h:117
SDL_RELEASED
#define SDL_RELEASED
Definition: SDL_events.h:49
ControllerMapping_t::next
struct _ControllerMapping_t * next
Definition: SDL_gamecontroller.c:99
SDL_JoystickGetDeviceInstanceID
SDL_JoystickID SDL_JoystickGetDeviceInstanceID(int device_index)
Definition: SDL_joystick.c:1420
SDL_InitSubSystem
#define SDL_InitSubSystem
Definition: SDL_dynapi_overrides.h:55
s_pSupportedControllers
static ControllerMapping_t * s_pSupportedControllers
Definition: SDL_gamecontroller.c:103
SDL_CONTROLLERDEVICEADDED
@ SDL_CONTROLLERDEVICEADDED
Definition: SDL_events.h:123
SDL_ShouldIgnoreGameController
SDL_bool SDL_ShouldIgnoreGameController(const char *name, SDL_JoystickGUID guid)
Definition: SDL_gamecontroller.c:1460
SDL_PrivateJoystickAxis
int SDL_PrivateJoystickAxis(SDL_Joystick *joystick, Uint8 axis, Sint16 value)
Definition: SDL_joystick.c:828
SDL_vidpid_list::num_entries
int num_entries
Definition: SDL_gamecontroller.c:127
k_eControllerType_PS4Controller
@ k_eControllerType_PS4Controller
Definition: controller_type.h:50
SDL_PRESSED
#define SDL_PRESSED
Definition: SDL_events.h:50
SDL_GetHintBoolean
#define SDL_GetHintBoolean
Definition: SDL_dynapi_overrides.h:608
event
struct _cl_event * event
Definition: SDL_opengl_glext.h:2649
SDL_GetEventState
#define SDL_GetEventState(type)
Definition: SDL_events.h:769
k_eControllerType_XBox360Controller
@ k_eControllerType_XBox360Controller
Definition: controller_type.h:47
SDL_GetJoystickGUIDInfo
void SDL_GetJoystickGUIDInfo(SDL_JoystickGUID guid, Uint16 *vendor, Uint16 *product, Uint16 *version)
Definition: SDL_joystick.c:1113
SDL_free
#define SDL_free
Definition: SDL_dynapi_overrides.h:377
SDL_updating_joystick
static SDL_bool SDL_updating_joystick
Definition: SDL_joystick.c:82
UpdateEventsForDeviceRemoval
static void UpdateEventsForDeviceRemoval()
Definition: SDL_joystick.c:776
SDL_PushEvent
#define SDL_PushEvent
Definition: SDL_dynapi_overrides.h:125
SDL_HINT_GAMECONTROLLER_IGNORE_DEVICES_EXCEPT
#define SDL_HINT_GAMECONTROLLER_IGNORE_DEVICES_EXCEPT
Definition: SDL_hints.h:463
SDL_ignored_controllers
static SDL_vidpid_list SDL_ignored_controllers
Definition: SDL_gamecontroller.c:133
ControllerMapping_t::name
char * name
Definition: SDL_gamecontroller.c:96
SDL_PrivateJoystickShouldIgnoreEvent
static SDL_bool SDL_PrivateJoystickShouldIgnoreEvent()
Definition: SDL_joystick.c:736
SDL_JoystickDriver::Quit
void(* Quit)(void)
Definition: SDL_sysjoystick.h:139
name
GLuint const GLchar * name
Definition: SDL_opengl_glext.h:660
s_ControllerMappings
static const char * s_ControllerMappings[]
Definition: SDL_gamecontrollerdb.h:32
SDL_GameControllerInitMappings
int SDL_GameControllerInitMappings(void)
Definition: SDL_gamecontroller.c:1329
GuessControllerType
static EControllerType GuessControllerType(int nVID, int nPID)
Definition: controller_type.h:410
MAKE_VIDPID
#define MAKE_VIDPID(VID, PID)
Definition: SDL_sysjoystick.h:90
SDL_JOYAXISMOTION
@ SDL_JOYAXISMOTION
Definition: SDL_events.h:111
SDL_next_joystick_instance_id
static SDL_atomic_t SDL_next_joystick_instance_id
Definition: SDL_joystick.c:84
SDL_JoystickAllowBackgroundEventsChanged
static void SDL_JoystickAllowBackgroundEventsChanged(void *userdata, const char *name, const char *oldValue, const char *hint)
Definition: SDL_joystick.c:104
SDL_GameControllerLoadHints
static void SDL_GameControllerLoadHints()
Definition: SDL_gamecontroller.c:1280
SDL_TRUE
@ SDL_TRUE
Definition: SDL_stdinc.h:164
SDL_joystick_lock
static SDL_mutex * SDL_joystick_lock
Definition: SDL_joystick.c:83
SDL_JOYSTICK_AXIS_MAX
#define SDL_JOYSTICK_AXIS_MAX
Definition: SDL_joystick.h:301
SDL_LockJoysticks
void SDL_LockJoysticks(void)
Definition: SDL_joystick.c:87
SDL_assert
#define SDL_assert(condition)
Definition: SDL_assert.h:169
SDL_joystick_drivers
static SDL_JoystickDriver * SDL_joystick_drivers[]
Definition: SDL_joystick.c:48
axis
SDL_Texture * axis
Definition: testgamecontroller.c:67
SDL_arraysize
#define SDL_arraysize(array)
Definition: SDL_stdinc.h:115
SDL_PrivateGameControllerAddMapping
static int SDL_PrivateGameControllerAddMapping(const char *mappingString, SDL_ControllerMappingPriority priority)
Definition: SDL_gamecontroller.c:1135
SDL_GameControllerQuitMappings
void SDL_GameControllerQuitMappings(void)
Definition: SDL_gamecontroller.c:1917
SDL_AddHintCallback
#define SDL_AddHintCallback
Definition: SDL_dynapi_overrides.h:192
ControllerMapping_t::mapping
char * mapping
Definition: SDL_gamecontroller.c:97
SDL_JoystickClose
void SDL_JoystickClose(SDL_Joystick *joystick)
Definition: SDL_joystick.c:643
SDL_allowed_controllers
static SDL_vidpid_list SDL_allowed_controllers
Definition: SDL_gamecontroller.c:132
value
GLsizei const GLfloat * value
Definition: SDL_opengl_glext.h:698
SDL_PrivateGetControllerMappingForNameAndGUID
static ControllerMapping_t * SDL_PrivateGetControllerMappingForNameAndGUID(const char *name, SDL_JoystickGUID guid)
Definition: SDL_gamecontroller.c:1006
SDL_SetError
#define SDL_SetError
Definition: SDL_dynapi_overrides.h:30
SDL_GameControllerClose
void SDL_GameControllerClose(SDL_GameController *gamecontroller)
Definition: SDL_gamecontroller.c:1860
SDL_IsGameControllerNameAndGUID
SDL_bool SDL_IsGameControllerNameAndGUID(const char *name, SDL_JoystickGUID guid)
Definition: SDL_gamecontroller.c:1435
SDL_JOYBUTTONUP
@ SDL_JOYBUTTONUP
Definition: SDL_events.h:115
SDL_DestroyMutex
#define SDL_DestroyMutex
Definition: SDL_dynapi_overrides.h:263
SDL_AddEventWatch
#define SDL_AddEventWatch
Definition: SDL_dynapi_overrides.h:128
SDL_joysticks
static SDL_Joystick * SDL_joysticks
Definition: SDL_joystick.c:81
SDL_CONTROLLER_MAPPING_PRIORITY_DEFAULT
@ SDL_CONTROLLER_MAPPING_PRIORITY_DEFAULT
Definition: SDL_gamecontroller.c:88
SDL_JOYDEVICEADDED
@ SDL_JOYDEVICEADDED
Definition: SDL_events.h:116
SDL_bool
SDL_bool
Definition: SDL_stdinc.h:162
SDL_Event
General event structure.
Definition: SDL_events.h:558
SDL_PrivateGameControllerButton
static int SDL_PrivateGameControllerButton(SDL_GameController *gamecontroller, SDL_GameControllerButton button, Uint8 state)
Definition: SDL_gamecontroller.c:1974
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:450
SDL_FALSE
@ SDL_FALSE
Definition: SDL_stdinc.h:163
SDL_JOYBUTTONDOWN
@ SDL_JOYBUTTONDOWN
Definition: SDL_events.h:114
SDL_Event::cdevice
SDL_ControllerDeviceEvent cdevice
Definition: SDL_events.h:576
state
struct xkb_state * state
Definition: SDL_waylandsym.h:113
SDL_GameControllerAddMappingsFromFile
#define SDL_GameControllerAddMappingsFromFile(file)
Definition: SDL_gamecontroller.h:129
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_JOYHATMOTION
@ SDL_JOYHATMOTION
Definition: SDL_events.h:113
SDL_LockJoysticks
#define SDL_LockJoysticks
Definition: SDL_dynapi_overrides.h:638
button
SDL_Texture * button
Definition: testgamecontroller.c:67
k_eControllerType_XBoxOneController
@ k_eControllerType_XBoxOneController
Definition: controller_type.h:48
SDL_GetControllerMappingFilePath
static SDL_bool SDL_GetControllerMappingFilePath(char *path, size_t size)
Definition: SDL_gamecontroller.c:1313
SDL_JOYBALLMOTION
@ SDL_JOYBALLMOTION
Definition: SDL_events.h:112
SDL_DelEventWatch
#define SDL_DelEventWatch
Definition: SDL_dynapi_overrides.h:129
SDL_GameControllerIgnoreDevicesExceptChanged
static void SDL_GameControllerIgnoreDevicesExceptChanged(void *userdata, const char *name, const char *oldValue, const char *hint)
Definition: SDL_gamecontroller.c:188
SDL_CONTROLLER_BUTTON_GUIDE
@ SDL_CONTROLLER_BUTTON_GUIDE
Definition: SDL_gamecontroller.h:324