SDL_joystick_c.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. /*
  2. Simple DirectMedia Layer
  3. Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org>
  4. This software is provided 'as-is', without any express or implied
  5. warranty. In no event will the authors be held liable for any damages
  6. arising from the use of this software.
  7. Permission is granted to anyone to use this software for any purpose,
  8. including commercial applications, and to alter it and redistribute it
  9. freely, subject to the following restrictions:
  10. 1. The origin of this software must not be misrepresented; you must not
  11. claim that you wrote the original software. If you use this software
  12. in a product, an acknowledgment in the product documentation would be
  13. appreciated but is not required.
  14. 2. Altered source versions must be plainly marked as such, and must not be
  15. misrepresented as being the original software.
  16. 3. This notice may not be removed or altered from any source distribution.
  17. */
  18. #ifndef SDL_joystick_c_h_
  19. #define SDL_joystick_c_h_
  20. #include "SDL_internal.h"
  21. // Useful functions and variables from SDL_joystick.c
  22. // Set up for C function definitions, even when using C++
  23. #ifdef __cplusplus
  24. extern "C" {
  25. #endif
  26. struct SDL_JoystickDriver;
  27. struct SDL_SteamVirtualGamepadInfo;
  28. // Initialization and shutdown functions
  29. extern bool SDL_InitJoysticks(void);
  30. extern void SDL_QuitJoysticks(void);
  31. // Return whether the joystick system is currently initialized
  32. extern bool SDL_JoysticksInitialized(void);
  33. // Return whether the joystick system is shutting down
  34. extern bool SDL_JoysticksQuitting(void);
  35. // Return whether the joysticks are currently locked
  36. extern bool SDL_JoysticksLocked(void);
  37. // Make sure we currently have the joysticks locked
  38. extern void SDL_AssertJoysticksLocked(void) SDL_ASSERT_CAPABILITY(SDL_joystick_lock);
  39. // Function to return whether there are any joysticks opened by the application
  40. extern bool SDL_JoysticksOpened(void);
  41. // Function to determine whether a device is currently detected by this driver
  42. extern bool SDL_JoystickHandledByAnotherDriver(struct SDL_JoystickDriver *driver, Uint16 vendor_id, Uint16 product_id, Uint16 version, const char *name);
  43. /* Function to standardize the name for a controller
  44. This should be freed with SDL_free() when no longer needed
  45. */
  46. extern char *SDL_CreateJoystickName(Uint16 vendor, Uint16 product, const char *vendor_name, const char *product_name);
  47. // Function to create a GUID for a joystick based on the VID/PID and name
  48. extern SDL_GUID SDL_CreateJoystickGUID(Uint16 bus, Uint16 vendor, Uint16 product, Uint16 version, const char *vendor_name, const char *product_name, Uint8 driver_signature, Uint8 driver_data);
  49. // Function to create a GUID for a joystick based on the name, with no VID/PID information
  50. extern SDL_GUID SDL_CreateJoystickGUIDForName(const char *name);
  51. // Function to set the vendor field of a joystick GUID
  52. extern void SDL_SetJoystickGUIDVendor(SDL_GUID *guid, Uint16 vendor);
  53. // Function to set the product field of a joystick GUID
  54. extern void SDL_SetJoystickGUIDProduct(SDL_GUID *guid, Uint16 product);
  55. // Function to set the version field of a joystick GUID
  56. extern void SDL_SetJoystickGUIDVersion(SDL_GUID *guid, Uint16 version);
  57. // Function to set the CRC field of a joystick GUID
  58. extern void SDL_SetJoystickGUIDCRC(SDL_GUID *guid, Uint16 crc);
  59. // Function to return the type of a controller
  60. extern SDL_GamepadType SDL_GetGamepadTypeFromVIDPID(Uint16 vendor, Uint16 product, const char *name, bool forUI);
  61. extern SDL_GamepadType SDL_GetGamepadTypeFromGUID(SDL_GUID guid, const char *name);
  62. // Function to return whether a joystick GUID uses the version field
  63. extern bool SDL_JoystickGUIDUsesVersion(SDL_GUID guid);
  64. // Function to return whether a joystick is an Xbox One controller
  65. extern bool SDL_IsJoystickXboxOne(Uint16 vendor_id, Uint16 product_id);
  66. // Function to return whether a joystick is an Xbox One Elite controller
  67. extern bool SDL_IsJoystickXboxOneElite(Uint16 vendor_id, Uint16 product_id);
  68. // Function to return whether a joystick is an Xbox Series X controller
  69. extern bool SDL_IsJoystickXboxSeriesX(Uint16 vendor_id, Uint16 product_id);
  70. // Function to return whether a joystick is an Xbox One controller connected via Bluetooth
  71. extern bool SDL_IsJoystickBluetoothXboxOne(Uint16 vendor_id, Uint16 product_id);
  72. // Function to return whether a joystick is a PS4 controller
  73. extern bool SDL_IsJoystickPS4(Uint16 vendor_id, Uint16 product_id);
  74. // Function to return whether a joystick is a PS5 controller
  75. extern bool SDL_IsJoystickPS5(Uint16 vendor_id, Uint16 product_id);
  76. extern bool SDL_IsJoystickDualSenseEdge(Uint16 vendor_id, Uint16 product_id);
  77. // Function to return whether a joystick is a Nintendo Switch Pro controller
  78. extern bool SDL_IsJoystickNintendoSwitchPro(Uint16 vendor_id, Uint16 product_id);
  79. extern bool SDL_IsJoystickNintendoSwitchProInputOnly(Uint16 vendor_id, Uint16 product_id);
  80. extern bool SDL_IsJoystickNintendoSwitchJoyCon(Uint16 vendor_id, Uint16 product_id);
  81. extern bool SDL_IsJoystickNintendoSwitchJoyConLeft(Uint16 vendor_id, Uint16 product_id);
  82. extern bool SDL_IsJoystickNintendoSwitchJoyConRight(Uint16 vendor_id, Uint16 product_id);
  83. extern bool SDL_IsJoystickNintendoSwitchJoyConGrip(Uint16 vendor_id, Uint16 product_id);
  84. extern bool SDL_IsJoystickNintendoSwitchJoyConPair(Uint16 vendor_id, Uint16 product_id);
  85. // Function to return whether a joystick is a Nintendo GameCube style controller
  86. extern bool SDL_IsJoystickGameCube(Uint16 vendor_id, Uint16 product_id);
  87. // Function to return whether a joystick is an Amazon Luna controller
  88. extern bool SDL_IsJoystickAmazonLunaController(Uint16 vendor_id, Uint16 product_id);
  89. // Function to return whether a joystick is a Google Stadia controller
  90. extern bool SDL_IsJoystickGoogleStadiaController(Uint16 vendor_id, Uint16 product_id);
  91. // Function to return whether a joystick is an NVIDIA SHIELD controller
  92. extern bool SDL_IsJoystickNVIDIASHIELDController(Uint16 vendor_id, Uint16 product_id);
  93. // Function to return whether a joystick is a Steam Virtual Gamepad
  94. extern bool SDL_IsJoystickSteamVirtualGamepad(Uint16 vendor_id, Uint16 product_id, Uint16 version);
  95. // Function to return whether a joystick is a Steam Controller
  96. extern bool SDL_IsJoystickSteamController(Uint16 vendor_id, Uint16 product_id);
  97. // Function to return whether a joystick is a HORI Steam controller
  98. extern bool SDL_IsJoystickHoriSteamController(Uint16 vendor_id, Uint16 product_id);
  99. // Function to return whether a joystick is a Steam Deck
  100. extern bool SDL_IsJoystickSteamDeck(Uint16 vendor_id, Uint16 product_id);
  101. // Function to return whether a joystick guid comes from the XInput driver
  102. extern bool SDL_IsJoystickXInput(SDL_GUID guid);
  103. // Function to return whether a joystick guid comes from the WGI driver
  104. extern bool SDL_IsJoystickWGI(SDL_GUID guid);
  105. // Function to return whether a joystick guid comes from the HIDAPI driver
  106. extern bool SDL_IsJoystickHIDAPI(SDL_GUID guid);
  107. // Function to return whether a joystick guid comes from the MFI driver
  108. extern bool SDL_IsJoystickMFI(SDL_GUID guid);
  109. // Function to return whether a joystick guid comes from the RAWINPUT driver
  110. extern bool SDL_IsJoystickRAWINPUT(SDL_GUID guid);
  111. // Function to return whether a joystick guid comes from the Virtual driver
  112. extern bool SDL_IsJoystickVIRTUAL(SDL_GUID guid);
  113. // Function to return whether a joystick is a wheel
  114. bool SDL_IsJoystickWheel(Uint16 vendor_id, Uint16 product_id);
  115. // Function to return whether a joystick should be ignored
  116. extern bool SDL_ShouldIgnoreJoystick(Uint16 vendor_id, Uint16 product_id, Uint16 version, const char *name);
  117. // Internal event queueing functions
  118. extern void SDL_PrivateJoystickAddTouchpad(SDL_Joystick *joystick, int nfingers);
  119. extern void SDL_PrivateJoystickAddSensor(SDL_Joystick *joystick, SDL_SensorType type, float rate);
  120. extern void SDL_PrivateJoystickSensorRate(SDL_Joystick *joystick, SDL_SensorType type, float rate);
  121. extern void SDL_PrivateJoystickAdded(SDL_JoystickID instance_id);
  122. extern bool SDL_IsJoystickBeingAdded(void);
  123. extern void SDL_PrivateJoystickRemoved(SDL_JoystickID instance_id);
  124. extern void SDL_PrivateJoystickForceRecentering(SDL_Joystick *joystick);
  125. extern void SDL_SendJoystickAxis(Uint64 timestamp, SDL_Joystick *joystick, Uint8 axis, Sint16 value);
  126. extern void SDL_SendJoystickBall(Uint64 timestamp, SDL_Joystick *joystick, Uint8 ball, Sint16 xrel, Sint16 yrel);
  127. extern void SDL_SendJoystickHat(Uint64 timestamp, SDL_Joystick *joystick, Uint8 hat, Uint8 value);
  128. extern void SDL_SendJoystickButton(Uint64 timestamp, SDL_Joystick *joystick, Uint8 button, bool down);
  129. extern void SDL_SendJoystickTouchpad(Uint64 timestamp, SDL_Joystick *joystick, int touchpad, int finger, bool down, float x, float y, float pressure);
  130. extern void SDL_SendJoystickSensor(Uint64 timestamp, SDL_Joystick *joystick, SDL_SensorType type, Uint64 sensor_timestamp, const float *data, int num_values);
  131. extern void SDL_SendJoystickPowerInfo(SDL_Joystick *joystick, SDL_PowerState state, int percent);
  132. // Function to get the Steam virtual gamepad info for a joystick
  133. extern const struct SDL_SteamVirtualGamepadInfo *SDL_GetJoystickVirtualGamepadInfoForID(SDL_JoystickID instance_id);
  134. // Internal sanity checking functions
  135. extern bool SDL_IsJoystickValid(SDL_Joystick *joystick);
  136. typedef enum
  137. {
  138. EMappingKind_None,
  139. EMappingKind_Button,
  140. EMappingKind_Axis,
  141. EMappingKind_Hat,
  142. } EMappingKind;
  143. typedef struct SDL_InputMapping
  144. {
  145. EMappingKind kind;
  146. Uint8 target;
  147. bool axis_reversed;
  148. bool half_axis_positive;
  149. bool half_axis_negative;
  150. } SDL_InputMapping;
  151. typedef struct SDL_GamepadMapping
  152. {
  153. SDL_InputMapping a;
  154. SDL_InputMapping b;
  155. SDL_InputMapping x;
  156. SDL_InputMapping y;
  157. SDL_InputMapping back;
  158. SDL_InputMapping guide;
  159. SDL_InputMapping start;
  160. SDL_InputMapping leftstick;
  161. SDL_InputMapping rightstick;
  162. SDL_InputMapping leftshoulder;
  163. SDL_InputMapping rightshoulder;
  164. SDL_InputMapping dpup;
  165. SDL_InputMapping dpdown;
  166. SDL_InputMapping dpleft;
  167. SDL_InputMapping dpright;
  168. SDL_InputMapping misc1;
  169. SDL_InputMapping misc2;
  170. SDL_InputMapping misc3;
  171. SDL_InputMapping misc4;
  172. SDL_InputMapping misc5;
  173. SDL_InputMapping misc6;
  174. SDL_InputMapping right_paddle1;
  175. SDL_InputMapping left_paddle1;
  176. SDL_InputMapping right_paddle2;
  177. SDL_InputMapping left_paddle2;
  178. SDL_InputMapping leftx;
  179. SDL_InputMapping lefty;
  180. SDL_InputMapping rightx;
  181. SDL_InputMapping righty;
  182. SDL_InputMapping lefttrigger;
  183. SDL_InputMapping righttrigger;
  184. SDL_InputMapping touchpad;
  185. } SDL_GamepadMapping;
  186. // Function to get autodetected gamepad controller mapping from the driver
  187. extern bool SDL_PrivateJoystickGetAutoGamepadMapping(SDL_JoystickID instance_id,
  188. SDL_GamepadMapping *out);
  189. typedef struct
  190. {
  191. const char *included_hint_name;
  192. int num_included_entries;
  193. int max_included_entries;
  194. Uint32 *included_entries;
  195. const char *excluded_hint_name;
  196. int num_excluded_entries;
  197. int max_excluded_entries;
  198. Uint32 *excluded_entries;
  199. int num_initial_entries;
  200. Uint32 *initial_entries;
  201. bool initialized;
  202. } SDL_vidpid_list;
  203. extern void SDL_LoadVIDPIDList(SDL_vidpid_list *list);
  204. extern void SDL_LoadVIDPIDListFromHints(SDL_vidpid_list *list, const char *included_list, const char *excluded_list);
  205. extern bool SDL_VIDPIDInList(Uint16 vendor_id, Uint16 product_id, const SDL_vidpid_list *list);
  206. extern void SDL_FreeVIDPIDList(SDL_vidpid_list *list);
  207. // Ends C function definitions when using C++
  208. #ifdef __cplusplus
  209. }
  210. #endif
  211. #endif // SDL_joystick_c_h_