SDL_joystick.h 44 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202
  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. /**
  19. * # CategoryJoystick
  20. *
  21. * SDL joystick support.
  22. *
  23. * This is the lower-level joystick handling. If you want the simpler option,
  24. * where what each button does is well-defined, you should use the gamepad API
  25. * instead.
  26. *
  27. * The term "instance_id" is the current instantiation of a joystick device in
  28. * the system, if the joystick is removed and then re-inserted then it will
  29. * get a new instance_id, instance_id's are monotonically increasing
  30. * identifiers of a joystick plugged in.
  31. *
  32. * The term "player_index" is the number assigned to a player on a specific
  33. * controller. For XInput controllers this returns the XInput user index. Many
  34. * joysticks will not be able to supply this information.
  35. *
  36. * SDL_GUID is used as a stable 128-bit identifier for a joystick device that
  37. * does not change over time. It identifies class of the device (a X360 wired
  38. * controller for example). This identifier is platform dependent.
  39. *
  40. * In order to use these functions, SDL_Init() must have been called with the
  41. * SDL_INIT_JOYSTICK flag. This causes SDL to scan the system for joysticks,
  42. * and load appropriate drivers.
  43. *
  44. * If you would like to receive joystick updates while the application is in
  45. * the background, you should set the following hint before calling
  46. * SDL_Init(): SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS
  47. */
  48. #ifndef SDL_joystick_h_
  49. #define SDL_joystick_h_
  50. #include <SDL3/SDL_stdinc.h>
  51. #include <SDL3/SDL_error.h>
  52. #include <SDL3/SDL_guid.h>
  53. #include <SDL3/SDL_mutex.h>
  54. #include <SDL3/SDL_power.h>
  55. #include <SDL3/SDL_properties.h>
  56. #include <SDL3/SDL_sensor.h>
  57. #include <SDL3/SDL_begin_code.h>
  58. /* Set up for C function definitions, even when using C++ */
  59. #ifdef __cplusplus
  60. extern "C" {
  61. #endif
  62. #ifdef SDL_THREAD_SAFETY_ANALYSIS
  63. /*
  64. * This is not an exported symbol from SDL, this is only in the headers to
  65. * help Clang's thread safety analysis tools to function. Do not attempt
  66. * to access this symbol from your app, it will not work!
  67. */
  68. extern SDL_Mutex *SDL_joystick_lock;
  69. #endif
  70. /**
  71. * The joystick structure used to identify an SDL joystick.
  72. *
  73. * This is opaque data.
  74. *
  75. * \since This struct is available since SDL 3.2.0.
  76. */
  77. typedef struct SDL_Joystick SDL_Joystick;
  78. /**
  79. * This is a unique ID for a joystick for the time it is connected to the
  80. * system, and is never reused for the lifetime of the application.
  81. *
  82. * If the joystick is disconnected and reconnected, it will get a new ID.
  83. *
  84. * The value 0 is an invalid ID.
  85. *
  86. * \since This datatype is available since SDL 3.2.0.
  87. */
  88. typedef Uint32 SDL_JoystickID;
  89. /**
  90. * An enum of some common joystick types.
  91. *
  92. * In some cases, SDL can identify a low-level joystick as being a certain
  93. * type of device, and will report it through SDL_GetJoystickType (or
  94. * SDL_GetJoystickTypeForID).
  95. *
  96. * This is by no means a complete list of everything that can be plugged into
  97. * a computer.
  98. *
  99. * \since This enum is available since SDL 3.2.0.
  100. */
  101. typedef enum SDL_JoystickType
  102. {
  103. SDL_JOYSTICK_TYPE_UNKNOWN,
  104. SDL_JOYSTICK_TYPE_GAMEPAD,
  105. SDL_JOYSTICK_TYPE_WHEEL,
  106. SDL_JOYSTICK_TYPE_ARCADE_STICK,
  107. SDL_JOYSTICK_TYPE_FLIGHT_STICK,
  108. SDL_JOYSTICK_TYPE_DANCE_PAD,
  109. SDL_JOYSTICK_TYPE_GUITAR,
  110. SDL_JOYSTICK_TYPE_DRUM_KIT,
  111. SDL_JOYSTICK_TYPE_ARCADE_PAD,
  112. SDL_JOYSTICK_TYPE_THROTTLE,
  113. SDL_JOYSTICK_TYPE_COUNT
  114. } SDL_JoystickType;
  115. /**
  116. * Possible connection states for a joystick device.
  117. *
  118. * This is used by SDL_GetJoystickConnectionState to report how a device is
  119. * connected to the system.
  120. *
  121. * \since This enum is available since SDL 3.2.0.
  122. */
  123. typedef enum SDL_JoystickConnectionState
  124. {
  125. SDL_JOYSTICK_CONNECTION_INVALID = -1,
  126. SDL_JOYSTICK_CONNECTION_UNKNOWN,
  127. SDL_JOYSTICK_CONNECTION_WIRED,
  128. SDL_JOYSTICK_CONNECTION_WIRELESS
  129. } SDL_JoystickConnectionState;
  130. /**
  131. * The largest value an SDL_Joystick's axis can report.
  132. *
  133. * \since This macro is available since SDL 3.2.0.
  134. *
  135. * \sa SDL_JOYSTICK_AXIS_MIN
  136. */
  137. #define SDL_JOYSTICK_AXIS_MAX 32767
  138. /**
  139. * The smallest value an SDL_Joystick's axis can report.
  140. *
  141. * This is a negative number!
  142. *
  143. * \since This macro is available since SDL 3.2.0.
  144. *
  145. * \sa SDL_JOYSTICK_AXIS_MAX
  146. */
  147. #define SDL_JOYSTICK_AXIS_MIN -32768
  148. /* Function prototypes */
  149. /**
  150. * Locking for atomic access to the joystick API.
  151. *
  152. * The SDL joystick functions are thread-safe, however you can lock the
  153. * joysticks while processing to guarantee that the joystick list won't change
  154. * and joystick and gamepad events will not be delivered.
  155. *
  156. * \since This function is available since SDL 3.2.0.
  157. */
  158. extern SDL_DECLSPEC void SDLCALL SDL_LockJoysticks(void) SDL_ACQUIRE(SDL_joystick_lock);
  159. /**
  160. * Unlocking for atomic access to the joystick API.
  161. *
  162. * \since This function is available since SDL 3.2.0.
  163. */
  164. extern SDL_DECLSPEC void SDLCALL SDL_UnlockJoysticks(void) SDL_RELEASE(SDL_joystick_lock);
  165. /**
  166. * Return whether a joystick is currently connected.
  167. *
  168. * \returns true if a joystick is connected, false otherwise.
  169. *
  170. * \since This function is available since SDL 3.2.0.
  171. *
  172. * \sa SDL_GetJoysticks
  173. */
  174. extern SDL_DECLSPEC bool SDLCALL SDL_HasJoystick(void);
  175. /**
  176. * Get a list of currently connected joysticks.
  177. *
  178. * \param count a pointer filled in with the number of joysticks returned, may
  179. * be NULL.
  180. * \returns a 0 terminated array of joystick instance IDs or NULL on failure;
  181. * call SDL_GetError() for more information. This should be freed
  182. * with SDL_free() when it is no longer needed.
  183. *
  184. * \since This function is available since SDL 3.2.0.
  185. *
  186. * \sa SDL_HasJoystick
  187. * \sa SDL_OpenJoystick
  188. */
  189. extern SDL_DECLSPEC SDL_JoystickID * SDLCALL SDL_GetJoysticks(int *count);
  190. /**
  191. * Get the implementation dependent name of a joystick.
  192. *
  193. * This can be called before any joysticks are opened.
  194. *
  195. * \param instance_id the joystick instance ID.
  196. * \returns the name of the selected joystick. If no name can be found, this
  197. * function returns NULL; call SDL_GetError() for more information.
  198. *
  199. * \since This function is available since SDL 3.2.0.
  200. *
  201. * \sa SDL_GetJoystickName
  202. * \sa SDL_GetJoysticks
  203. */
  204. extern SDL_DECLSPEC const char * SDLCALL SDL_GetJoystickNameForID(SDL_JoystickID instance_id);
  205. /**
  206. * Get the implementation dependent path of a joystick.
  207. *
  208. * This can be called before any joysticks are opened.
  209. *
  210. * \param instance_id the joystick instance ID.
  211. * \returns the path of the selected joystick. If no path can be found, this
  212. * function returns NULL; call SDL_GetError() for more information.
  213. *
  214. * \since This function is available since SDL 3.2.0.
  215. *
  216. * \sa SDL_GetJoystickPath
  217. * \sa SDL_GetJoysticks
  218. */
  219. extern SDL_DECLSPEC const char * SDLCALL SDL_GetJoystickPathForID(SDL_JoystickID instance_id);
  220. /**
  221. * Get the player index of a joystick.
  222. *
  223. * This can be called before any joysticks are opened.
  224. *
  225. * \param instance_id the joystick instance ID.
  226. * \returns the player index of a joystick, or -1 if it's not available.
  227. *
  228. * \since This function is available since SDL 3.2.0.
  229. *
  230. * \sa SDL_GetJoystickPlayerIndex
  231. * \sa SDL_GetJoysticks
  232. */
  233. extern SDL_DECLSPEC int SDLCALL SDL_GetJoystickPlayerIndexForID(SDL_JoystickID instance_id);
  234. /**
  235. * Get the implementation-dependent GUID of a joystick.
  236. *
  237. * This can be called before any joysticks are opened.
  238. *
  239. * \param instance_id the joystick instance ID.
  240. * \returns the GUID of the selected joystick. If called with an invalid
  241. * instance_id, this function returns a zero GUID.
  242. *
  243. * \since This function is available since SDL 3.2.0.
  244. *
  245. * \sa SDL_GetJoystickGUID
  246. * \sa SDL_GUIDToString
  247. */
  248. extern SDL_DECLSPEC SDL_GUID SDLCALL SDL_GetJoystickGUIDForID(SDL_JoystickID instance_id);
  249. /**
  250. * Get the USB vendor ID of a joystick, if available.
  251. *
  252. * This can be called before any joysticks are opened. If the vendor ID isn't
  253. * available this function returns 0.
  254. *
  255. * \param instance_id the joystick instance ID.
  256. * \returns the USB vendor ID of the selected joystick. If called with an
  257. * invalid instance_id, this function returns 0.
  258. *
  259. * \since This function is available since SDL 3.2.0.
  260. *
  261. * \sa SDL_GetJoystickVendor
  262. * \sa SDL_GetJoysticks
  263. */
  264. extern SDL_DECLSPEC Uint16 SDLCALL SDL_GetJoystickVendorForID(SDL_JoystickID instance_id);
  265. /**
  266. * Get the USB product ID of a joystick, if available.
  267. *
  268. * This can be called before any joysticks are opened. If the product ID isn't
  269. * available this function returns 0.
  270. *
  271. * \param instance_id the joystick instance ID.
  272. * \returns the USB product ID of the selected joystick. If called with an
  273. * invalid instance_id, this function returns 0.
  274. *
  275. * \since This function is available since SDL 3.2.0.
  276. *
  277. * \sa SDL_GetJoystickProduct
  278. * \sa SDL_GetJoysticks
  279. */
  280. extern SDL_DECLSPEC Uint16 SDLCALL SDL_GetJoystickProductForID(SDL_JoystickID instance_id);
  281. /**
  282. * Get the product version of a joystick, if available.
  283. *
  284. * This can be called before any joysticks are opened. If the product version
  285. * isn't available this function returns 0.
  286. *
  287. * \param instance_id the joystick instance ID.
  288. * \returns the product version of the selected joystick. If called with an
  289. * invalid instance_id, this function returns 0.
  290. *
  291. * \since This function is available since SDL 3.2.0.
  292. *
  293. * \sa SDL_GetJoystickProductVersion
  294. * \sa SDL_GetJoysticks
  295. */
  296. extern SDL_DECLSPEC Uint16 SDLCALL SDL_GetJoystickProductVersionForID(SDL_JoystickID instance_id);
  297. /**
  298. * Get the type of a joystick, if available.
  299. *
  300. * This can be called before any joysticks are opened.
  301. *
  302. * \param instance_id the joystick instance ID.
  303. * \returns the SDL_JoystickType of the selected joystick. If called with an
  304. * invalid instance_id, this function returns
  305. * `SDL_JOYSTICK_TYPE_UNKNOWN`.
  306. *
  307. * \since This function is available since SDL 3.2.0.
  308. *
  309. * \sa SDL_GetJoystickType
  310. * \sa SDL_GetJoysticks
  311. */
  312. extern SDL_DECLSPEC SDL_JoystickType SDLCALL SDL_GetJoystickTypeForID(SDL_JoystickID instance_id);
  313. /**
  314. * Open a joystick for use.
  315. *
  316. * The joystick subsystem must be initialized before a joystick can be opened
  317. * for use.
  318. *
  319. * \param instance_id the joystick instance ID.
  320. * \returns a joystick identifier or NULL on failure; call SDL_GetError() for
  321. * more information.
  322. *
  323. * \since This function is available since SDL 3.2.0.
  324. *
  325. * \sa SDL_CloseJoystick
  326. */
  327. extern SDL_DECLSPEC SDL_Joystick * SDLCALL SDL_OpenJoystick(SDL_JoystickID instance_id);
  328. /**
  329. * Get the SDL_Joystick associated with an instance ID, if it has been opened.
  330. *
  331. * \param instance_id the instance ID to get the SDL_Joystick for.
  332. * \returns an SDL_Joystick on success or NULL on failure or if it hasn't been
  333. * opened yet; call SDL_GetError() for more information.
  334. *
  335. * \since This function is available since SDL 3.2.0.
  336. */
  337. extern SDL_DECLSPEC SDL_Joystick * SDLCALL SDL_GetJoystickFromID(SDL_JoystickID instance_id);
  338. /**
  339. * Get the SDL_Joystick associated with a player index.
  340. *
  341. * \param player_index the player index to get the SDL_Joystick for.
  342. * \returns an SDL_Joystick on success or NULL on failure; call SDL_GetError()
  343. * for more information.
  344. *
  345. * \since This function is available since SDL 3.2.0.
  346. *
  347. * \sa SDL_GetJoystickPlayerIndex
  348. * \sa SDL_SetJoystickPlayerIndex
  349. */
  350. extern SDL_DECLSPEC SDL_Joystick * SDLCALL SDL_GetJoystickFromPlayerIndex(int player_index);
  351. /**
  352. * The structure that describes a virtual joystick touchpad.
  353. *
  354. * \since This struct is available since SDL 3.2.0.
  355. *
  356. * \sa SDL_VirtualJoystickDesc
  357. */
  358. typedef struct SDL_VirtualJoystickTouchpadDesc
  359. {
  360. Uint16 nfingers; /**< the number of simultaneous fingers on this touchpad */
  361. Uint16 padding[3];
  362. } SDL_VirtualJoystickTouchpadDesc;
  363. /**
  364. * The structure that describes a virtual joystick sensor.
  365. *
  366. * \since This struct is available since SDL 3.2.0.
  367. *
  368. * \sa SDL_VirtualJoystickDesc
  369. */
  370. typedef struct SDL_VirtualJoystickSensorDesc
  371. {
  372. SDL_SensorType type; /**< the type of this sensor */
  373. float rate; /**< the update frequency of this sensor, may be 0.0f */
  374. } SDL_VirtualJoystickSensorDesc;
  375. /**
  376. * The structure that describes a virtual joystick.
  377. *
  378. * This structure should be initialized using SDL_INIT_INTERFACE(). All
  379. * elements of this structure are optional.
  380. *
  381. * \since This struct is available since SDL 3.2.0.
  382. *
  383. * \sa SDL_AttachVirtualJoystick
  384. * \sa SDL_INIT_INTERFACE
  385. * \sa SDL_VirtualJoystickSensorDesc
  386. * \sa SDL_VirtualJoystickTouchpadDesc
  387. */
  388. typedef struct SDL_VirtualJoystickDesc
  389. {
  390. Uint32 version; /**< the version of this interface */
  391. Uint16 type; /**< `SDL_JoystickType` */
  392. Uint16 padding; /**< unused */
  393. Uint16 vendor_id; /**< the USB vendor ID of this joystick */
  394. Uint16 product_id; /**< the USB product ID of this joystick */
  395. Uint16 naxes; /**< the number of axes on this joystick */
  396. Uint16 nbuttons; /**< the number of buttons on this joystick */
  397. Uint16 nballs; /**< the number of balls on this joystick */
  398. Uint16 nhats; /**< the number of hats on this joystick */
  399. Uint16 ntouchpads; /**< the number of touchpads on this joystick, requires `touchpads` to point at valid descriptions */
  400. Uint16 nsensors; /**< the number of sensors on this joystick, requires `sensors` to point at valid descriptions */
  401. Uint16 padding2[2]; /**< unused */
  402. Uint32 button_mask; /**< A mask of which buttons are valid for this controller
  403. e.g. (1 << SDL_GAMEPAD_BUTTON_SOUTH) */
  404. Uint32 axis_mask; /**< A mask of which axes are valid for this controller
  405. e.g. (1 << SDL_GAMEPAD_AXIS_LEFTX) */
  406. const char *name; /**< the name of the joystick */
  407. const SDL_VirtualJoystickTouchpadDesc *touchpads; /**< A pointer to an array of touchpad descriptions, required if `ntouchpads` is > 0 */
  408. const SDL_VirtualJoystickSensorDesc *sensors; /**< A pointer to an array of sensor descriptions, required if `nsensors` is > 0 */
  409. void *userdata; /**< User data pointer passed to callbacks */
  410. void (SDLCALL *Update)(void *userdata); /**< Called when the joystick state should be updated */
  411. void (SDLCALL *SetPlayerIndex)(void *userdata, int player_index); /**< Called when the player index is set */
  412. bool (SDLCALL *Rumble)(void *userdata, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble); /**< Implements SDL_RumbleJoystick() */
  413. bool (SDLCALL *RumbleTriggers)(void *userdata, Uint16 left_rumble, Uint16 right_rumble); /**< Implements SDL_RumbleJoystickTriggers() */
  414. bool (SDLCALL *SetLED)(void *userdata, Uint8 red, Uint8 green, Uint8 blue); /**< Implements SDL_SetJoystickLED() */
  415. bool (SDLCALL *SendEffect)(void *userdata, const void *data, int size); /**< Implements SDL_SendJoystickEffect() */
  416. bool (SDLCALL *SetSensorsEnabled)(void *userdata, bool enabled); /**< Implements SDL_SetGamepadSensorEnabled() */
  417. void (SDLCALL *Cleanup)(void *userdata); /**< Cleans up the userdata when the joystick is detached */
  418. } SDL_VirtualJoystickDesc;
  419. /* Check the size of SDL_VirtualJoystickDesc
  420. *
  421. * If this assert fails, either the compiler is padding to an unexpected size,
  422. * or the interface has been updated and this should be updated to match and
  423. * the code using this interface should be updated to handle the old version.
  424. */
  425. SDL_COMPILE_TIME_ASSERT(SDL_VirtualJoystickDesc_SIZE,
  426. (sizeof(void *) == 4 && sizeof(SDL_VirtualJoystickDesc) == 84) ||
  427. (sizeof(void *) == 8 && sizeof(SDL_VirtualJoystickDesc) == 136));
  428. /**
  429. * Attach a new virtual joystick.
  430. *
  431. * \param desc joystick description, initialized using SDL_INIT_INTERFACE().
  432. * \returns the joystick instance ID, or 0 on failure; call SDL_GetError() for
  433. * more information.
  434. *
  435. * \since This function is available since SDL 3.2.0.
  436. *
  437. * \sa SDL_DetachVirtualJoystick
  438. */
  439. extern SDL_DECLSPEC SDL_JoystickID SDLCALL SDL_AttachVirtualJoystick(const SDL_VirtualJoystickDesc *desc);
  440. /**
  441. * Detach a virtual joystick.
  442. *
  443. * \param instance_id the joystick instance ID, previously returned from
  444. * SDL_AttachVirtualJoystick().
  445. * \returns true on success or false on failure; call SDL_GetError() for more
  446. * information.
  447. *
  448. * \since This function is available since SDL 3.2.0.
  449. *
  450. * \sa SDL_AttachVirtualJoystick
  451. */
  452. extern SDL_DECLSPEC bool SDLCALL SDL_DetachVirtualJoystick(SDL_JoystickID instance_id);
  453. /**
  454. * Query whether or not a joystick is virtual.
  455. *
  456. * \param instance_id the joystick instance ID.
  457. * \returns true if the joystick is virtual, false otherwise.
  458. *
  459. * \since This function is available since SDL 3.2.0.
  460. */
  461. extern SDL_DECLSPEC bool SDLCALL SDL_IsJoystickVirtual(SDL_JoystickID instance_id);
  462. /**
  463. * Set the state of an axis on an opened virtual joystick.
  464. *
  465. * Please note that values set here will not be applied until the next call to
  466. * SDL_UpdateJoysticks, which can either be called directly, or can be called
  467. * indirectly through various other SDL APIs, including, but not limited to
  468. * the following: SDL_PollEvent, SDL_PumpEvents, SDL_WaitEventTimeout,
  469. * SDL_WaitEvent.
  470. *
  471. * Note that when sending trigger axes, you should scale the value to the full
  472. * range of Sint16. For example, a trigger at rest would have the value of
  473. * `SDL_JOYSTICK_AXIS_MIN`.
  474. *
  475. * \param joystick the virtual joystick on which to set state.
  476. * \param axis the index of the axis on the virtual joystick to update.
  477. * \param value the new value for the specified axis.
  478. * \returns true on success or false on failure; call SDL_GetError() for more
  479. * information.
  480. *
  481. * \since This function is available since SDL 3.2.0.
  482. */
  483. extern SDL_DECLSPEC bool SDLCALL SDL_SetJoystickVirtualAxis(SDL_Joystick *joystick, int axis, Sint16 value);
  484. /**
  485. * Generate ball motion on an opened virtual joystick.
  486. *
  487. * Please note that values set here will not be applied until the next call to
  488. * SDL_UpdateJoysticks, which can either be called directly, or can be called
  489. * indirectly through various other SDL APIs, including, but not limited to
  490. * the following: SDL_PollEvent, SDL_PumpEvents, SDL_WaitEventTimeout,
  491. * SDL_WaitEvent.
  492. *
  493. * \param joystick the virtual joystick on which to set state.
  494. * \param ball the index of the ball on the virtual joystick to update.
  495. * \param xrel the relative motion on the X axis.
  496. * \param yrel the relative motion on the Y axis.
  497. * \returns true on success or false on failure; call SDL_GetError() for more
  498. * information.
  499. *
  500. * \since This function is available since SDL 3.2.0.
  501. */
  502. extern SDL_DECLSPEC bool SDLCALL SDL_SetJoystickVirtualBall(SDL_Joystick *joystick, int ball, Sint16 xrel, Sint16 yrel);
  503. /**
  504. * Set the state of a button on an opened virtual joystick.
  505. *
  506. * Please note that values set here will not be applied until the next call to
  507. * SDL_UpdateJoysticks, which can either be called directly, or can be called
  508. * indirectly through various other SDL APIs, including, but not limited to
  509. * the following: SDL_PollEvent, SDL_PumpEvents, SDL_WaitEventTimeout,
  510. * SDL_WaitEvent.
  511. *
  512. * \param joystick the virtual joystick on which to set state.
  513. * \param button the index of the button on the virtual joystick to update.
  514. * \param down true if the button is pressed, false otherwise.
  515. * \returns true on success or false on failure; call SDL_GetError() for more
  516. * information.
  517. *
  518. * \since This function is available since SDL 3.2.0.
  519. */
  520. extern SDL_DECLSPEC bool SDLCALL SDL_SetJoystickVirtualButton(SDL_Joystick *joystick, int button, bool down);
  521. /**
  522. * Set the state of a hat on an opened virtual joystick.
  523. *
  524. * Please note that values set here will not be applied until the next call to
  525. * SDL_UpdateJoysticks, which can either be called directly, or can be called
  526. * indirectly through various other SDL APIs, including, but not limited to
  527. * the following: SDL_PollEvent, SDL_PumpEvents, SDL_WaitEventTimeout,
  528. * SDL_WaitEvent.
  529. *
  530. * \param joystick the virtual joystick on which to set state.
  531. * \param hat the index of the hat on the virtual joystick to update.
  532. * \param value the new value for the specified hat.
  533. * \returns true on success or false on failure; call SDL_GetError() for more
  534. * information.
  535. *
  536. * \since This function is available since SDL 3.2.0.
  537. */
  538. extern SDL_DECLSPEC bool SDLCALL SDL_SetJoystickVirtualHat(SDL_Joystick *joystick, int hat, Uint8 value);
  539. /**
  540. * Set touchpad finger state on an opened virtual joystick.
  541. *
  542. * Please note that values set here will not be applied until the next call to
  543. * SDL_UpdateJoysticks, which can either be called directly, or can be called
  544. * indirectly through various other SDL APIs, including, but not limited to
  545. * the following: SDL_PollEvent, SDL_PumpEvents, SDL_WaitEventTimeout,
  546. * SDL_WaitEvent.
  547. *
  548. * \param joystick the virtual joystick on which to set state.
  549. * \param touchpad the index of the touchpad on the virtual joystick to
  550. * update.
  551. * \param finger the index of the finger on the touchpad to set.
  552. * \param down true if the finger is pressed, false if the finger is released.
  553. * \param x the x coordinate of the finger on the touchpad, normalized 0 to 1,
  554. * with the origin in the upper left.
  555. * \param y the y coordinate of the finger on the touchpad, normalized 0 to 1,
  556. * with the origin in the upper left.
  557. * \param pressure the pressure of the finger.
  558. * \returns true on success or false on failure; call SDL_GetError() for more
  559. * information.
  560. *
  561. * \since This function is available since SDL 3.2.0.
  562. */
  563. extern SDL_DECLSPEC bool SDLCALL SDL_SetJoystickVirtualTouchpad(SDL_Joystick *joystick, int touchpad, int finger, bool down, float x, float y, float pressure);
  564. /**
  565. * Send a sensor update for an opened virtual joystick.
  566. *
  567. * Please note that values set here will not be applied until the next call to
  568. * SDL_UpdateJoysticks, which can either be called directly, or can be called
  569. * indirectly through various other SDL APIs, including, but not limited to
  570. * the following: SDL_PollEvent, SDL_PumpEvents, SDL_WaitEventTimeout,
  571. * SDL_WaitEvent.
  572. *
  573. * \param joystick the virtual joystick on which to set state.
  574. * \param type the type of the sensor on the virtual joystick to update.
  575. * \param sensor_timestamp a 64-bit timestamp in nanoseconds associated with
  576. * the sensor reading.
  577. * \param data the data associated with the sensor reading.
  578. * \param num_values the number of values pointed to by `data`.
  579. * \returns true on success or false on failure; call SDL_GetError() for more
  580. * information.
  581. *
  582. * \since This function is available since SDL 3.2.0.
  583. */
  584. extern SDL_DECLSPEC bool SDLCALL SDL_SendJoystickVirtualSensorData(SDL_Joystick *joystick, SDL_SensorType type, Uint64 sensor_timestamp, const float *data, int num_values);
  585. /**
  586. * Get the properties associated with a joystick.
  587. *
  588. * The following read-only properties are provided by SDL:
  589. *
  590. * - `SDL_PROP_JOYSTICK_CAP_MONO_LED_BOOLEAN`: true if this joystick has an
  591. * LED that has adjustable brightness
  592. * - `SDL_PROP_JOYSTICK_CAP_RGB_LED_BOOLEAN`: true if this joystick has an LED
  593. * that has adjustable color
  594. * - `SDL_PROP_JOYSTICK_CAP_PLAYER_LED_BOOLEAN`: true if this joystick has a
  595. * player LED
  596. * - `SDL_PROP_JOYSTICK_CAP_RUMBLE_BOOLEAN`: true if this joystick has
  597. * left/right rumble
  598. * - `SDL_PROP_JOYSTICK_CAP_TRIGGER_RUMBLE_BOOLEAN`: true if this joystick has
  599. * simple trigger rumble
  600. *
  601. * \param joystick the SDL_Joystick obtained from SDL_OpenJoystick().
  602. * \returns a valid property ID on success or 0 on failure; call
  603. * SDL_GetError() for more information.
  604. *
  605. * \since This function is available since SDL 3.2.0.
  606. */
  607. extern SDL_DECLSPEC SDL_PropertiesID SDLCALL SDL_GetJoystickProperties(SDL_Joystick *joystick);
  608. #define SDL_PROP_JOYSTICK_CAP_MONO_LED_BOOLEAN "SDL.joystick.cap.mono_led"
  609. #define SDL_PROP_JOYSTICK_CAP_RGB_LED_BOOLEAN "SDL.joystick.cap.rgb_led"
  610. #define SDL_PROP_JOYSTICK_CAP_PLAYER_LED_BOOLEAN "SDL.joystick.cap.player_led"
  611. #define SDL_PROP_JOYSTICK_CAP_RUMBLE_BOOLEAN "SDL.joystick.cap.rumble"
  612. #define SDL_PROP_JOYSTICK_CAP_TRIGGER_RUMBLE_BOOLEAN "SDL.joystick.cap.trigger_rumble"
  613. /**
  614. * Get the implementation dependent name of a joystick.
  615. *
  616. * \param joystick the SDL_Joystick obtained from SDL_OpenJoystick().
  617. * \returns the name of the selected joystick. If no name can be found, this
  618. * function returns NULL; call SDL_GetError() for more information.
  619. *
  620. * \since This function is available since SDL 3.2.0.
  621. *
  622. * \sa SDL_GetJoystickNameForID
  623. */
  624. extern SDL_DECLSPEC const char * SDLCALL SDL_GetJoystickName(SDL_Joystick *joystick);
  625. /**
  626. * Get the implementation dependent path of a joystick.
  627. *
  628. * \param joystick the SDL_Joystick obtained from SDL_OpenJoystick().
  629. * \returns the path of the selected joystick. If no path can be found, this
  630. * function returns NULL; call SDL_GetError() for more information.
  631. *
  632. * \since This function is available since SDL 3.2.0.
  633. *
  634. * \sa SDL_GetJoystickPathForID
  635. */
  636. extern SDL_DECLSPEC const char * SDLCALL SDL_GetJoystickPath(SDL_Joystick *joystick);
  637. /**
  638. * Get the player index of an opened joystick.
  639. *
  640. * For XInput controllers this returns the XInput user index. Many joysticks
  641. * will not be able to supply this information.
  642. *
  643. * \param joystick the SDL_Joystick obtained from SDL_OpenJoystick().
  644. * \returns the player index, or -1 if it's not available.
  645. *
  646. * \since This function is available since SDL 3.2.0.
  647. *
  648. * \sa SDL_SetJoystickPlayerIndex
  649. */
  650. extern SDL_DECLSPEC int SDLCALL SDL_GetJoystickPlayerIndex(SDL_Joystick *joystick);
  651. /**
  652. * Set the player index of an opened joystick.
  653. *
  654. * \param joystick the SDL_Joystick obtained from SDL_OpenJoystick().
  655. * \param player_index player index to assign to this joystick, or -1 to clear
  656. * the player index and turn off player LEDs.
  657. * \returns true on success or false on failure; call SDL_GetError() for more
  658. * information.
  659. *
  660. * \since This function is available since SDL 3.2.0.
  661. *
  662. * \sa SDL_GetJoystickPlayerIndex
  663. */
  664. extern SDL_DECLSPEC bool SDLCALL SDL_SetJoystickPlayerIndex(SDL_Joystick *joystick, int player_index);
  665. /**
  666. * Get the implementation-dependent GUID for the joystick.
  667. *
  668. * This function requires an open joystick.
  669. *
  670. * \param joystick the SDL_Joystick obtained from SDL_OpenJoystick().
  671. * \returns the GUID of the given joystick. If called on an invalid index,
  672. * this function returns a zero GUID; call SDL_GetError() for more
  673. * information.
  674. *
  675. * \since This function is available since SDL 3.2.0.
  676. *
  677. * \sa SDL_GetJoystickGUIDForID
  678. * \sa SDL_GUIDToString
  679. */
  680. extern SDL_DECLSPEC SDL_GUID SDLCALL SDL_GetJoystickGUID(SDL_Joystick *joystick);
  681. /**
  682. * Get the USB vendor ID of an opened joystick, if available.
  683. *
  684. * If the vendor ID isn't available this function returns 0.
  685. *
  686. * \param joystick the SDL_Joystick obtained from SDL_OpenJoystick().
  687. * \returns the USB vendor ID of the selected joystick, or 0 if unavailable.
  688. *
  689. * \since This function is available since SDL 3.2.0.
  690. *
  691. * \sa SDL_GetJoystickVendorForID
  692. */
  693. extern SDL_DECLSPEC Uint16 SDLCALL SDL_GetJoystickVendor(SDL_Joystick *joystick);
  694. /**
  695. * Get the USB product ID of an opened joystick, if available.
  696. *
  697. * If the product ID isn't available this function returns 0.
  698. *
  699. * \param joystick the SDL_Joystick obtained from SDL_OpenJoystick().
  700. * \returns the USB product ID of the selected joystick, or 0 if unavailable.
  701. *
  702. * \since This function is available since SDL 3.2.0.
  703. *
  704. * \sa SDL_GetJoystickProductForID
  705. */
  706. extern SDL_DECLSPEC Uint16 SDLCALL SDL_GetJoystickProduct(SDL_Joystick *joystick);
  707. /**
  708. * Get the product version of an opened joystick, if available.
  709. *
  710. * If the product version isn't available this function returns 0.
  711. *
  712. * \param joystick the SDL_Joystick obtained from SDL_OpenJoystick().
  713. * \returns the product version of the selected joystick, or 0 if unavailable.
  714. *
  715. * \since This function is available since SDL 3.2.0.
  716. *
  717. * \sa SDL_GetJoystickProductVersionForID
  718. */
  719. extern SDL_DECLSPEC Uint16 SDLCALL SDL_GetJoystickProductVersion(SDL_Joystick *joystick);
  720. /**
  721. * Get the firmware version of an opened joystick, if available.
  722. *
  723. * If the firmware version isn't available this function returns 0.
  724. *
  725. * \param joystick the SDL_Joystick obtained from SDL_OpenJoystick().
  726. * \returns the firmware version of the selected joystick, or 0 if
  727. * unavailable.
  728. *
  729. * \since This function is available since SDL 3.2.0.
  730. */
  731. extern SDL_DECLSPEC Uint16 SDLCALL SDL_GetJoystickFirmwareVersion(SDL_Joystick *joystick);
  732. /**
  733. * Get the serial number of an opened joystick, if available.
  734. *
  735. * Returns the serial number of the joystick, or NULL if it is not available.
  736. *
  737. * \param joystick the SDL_Joystick obtained from SDL_OpenJoystick().
  738. * \returns the serial number of the selected joystick, or NULL if
  739. * unavailable.
  740. *
  741. * \since This function is available since SDL 3.2.0.
  742. */
  743. extern SDL_DECLSPEC const char * SDLCALL SDL_GetJoystickSerial(SDL_Joystick *joystick);
  744. /**
  745. * Get the type of an opened joystick.
  746. *
  747. * \param joystick the SDL_Joystick obtained from SDL_OpenJoystick().
  748. * \returns the SDL_JoystickType of the selected joystick.
  749. *
  750. * \since This function is available since SDL 3.2.0.
  751. *
  752. * \sa SDL_GetJoystickTypeForID
  753. */
  754. extern SDL_DECLSPEC SDL_JoystickType SDLCALL SDL_GetJoystickType(SDL_Joystick *joystick);
  755. /**
  756. * Get the device information encoded in a SDL_GUID structure.
  757. *
  758. * \param guid the SDL_GUID you wish to get info about.
  759. * \param vendor a pointer filled in with the device VID, or 0 if not
  760. * available.
  761. * \param product a pointer filled in with the device PID, or 0 if not
  762. * available.
  763. * \param version a pointer filled in with the device version, or 0 if not
  764. * available.
  765. * \param crc16 a pointer filled in with a CRC used to distinguish different
  766. * products with the same VID/PID, or 0 if not available.
  767. *
  768. * \since This function is available since SDL 3.2.0.
  769. *
  770. * \sa SDL_GetJoystickGUIDForID
  771. */
  772. extern SDL_DECLSPEC void SDLCALL SDL_GetJoystickGUIDInfo(SDL_GUID guid, Uint16 *vendor, Uint16 *product, Uint16 *version, Uint16 *crc16);
  773. /**
  774. * Get the status of a specified joystick.
  775. *
  776. * \param joystick the joystick to query.
  777. * \returns true if the joystick has been opened, false if it has not; call
  778. * SDL_GetError() for more information.
  779. *
  780. * \since This function is available since SDL 3.2.0.
  781. */
  782. extern SDL_DECLSPEC bool SDLCALL SDL_JoystickConnected(SDL_Joystick *joystick);
  783. /**
  784. * Get the instance ID of an opened joystick.
  785. *
  786. * \param joystick an SDL_Joystick structure containing joystick information.
  787. * \returns the instance ID of the specified joystick on success or 0 on
  788. * failure; call SDL_GetError() for more information.
  789. *
  790. * \since This function is available since SDL 3.2.0.
  791. */
  792. extern SDL_DECLSPEC SDL_JoystickID SDLCALL SDL_GetJoystickID(SDL_Joystick *joystick);
  793. /**
  794. * Get the number of general axis controls on a joystick.
  795. *
  796. * Often, the directional pad on a game controller will either look like 4
  797. * separate buttons or a POV hat, and not axes, but all of this is up to the
  798. * device and platform.
  799. *
  800. * \param joystick an SDL_Joystick structure containing joystick information.
  801. * \returns the number of axis controls/number of axes on success or -1 on
  802. * failure; call SDL_GetError() for more information.
  803. *
  804. * \since This function is available since SDL 3.2.0.
  805. *
  806. * \sa SDL_GetJoystickAxis
  807. * \sa SDL_GetNumJoystickBalls
  808. * \sa SDL_GetNumJoystickButtons
  809. * \sa SDL_GetNumJoystickHats
  810. */
  811. extern SDL_DECLSPEC int SDLCALL SDL_GetNumJoystickAxes(SDL_Joystick *joystick);
  812. /**
  813. * Get the number of trackballs on a joystick.
  814. *
  815. * Joystick trackballs have only relative motion events associated with them
  816. * and their state cannot be polled.
  817. *
  818. * Most joysticks do not have trackballs.
  819. *
  820. * \param joystick an SDL_Joystick structure containing joystick information.
  821. * \returns the number of trackballs on success or -1 on failure; call
  822. * SDL_GetError() for more information.
  823. *
  824. * \since This function is available since SDL 3.2.0.
  825. *
  826. * \sa SDL_GetJoystickBall
  827. * \sa SDL_GetNumJoystickAxes
  828. * \sa SDL_GetNumJoystickButtons
  829. * \sa SDL_GetNumJoystickHats
  830. */
  831. extern SDL_DECLSPEC int SDLCALL SDL_GetNumJoystickBalls(SDL_Joystick *joystick);
  832. /**
  833. * Get the number of POV hats on a joystick.
  834. *
  835. * \param joystick an SDL_Joystick structure containing joystick information.
  836. * \returns the number of POV hats on success or -1 on failure; call
  837. * SDL_GetError() for more information.
  838. *
  839. * \since This function is available since SDL 3.2.0.
  840. *
  841. * \sa SDL_GetJoystickHat
  842. * \sa SDL_GetNumJoystickAxes
  843. * \sa SDL_GetNumJoystickBalls
  844. * \sa SDL_GetNumJoystickButtons
  845. */
  846. extern SDL_DECLSPEC int SDLCALL SDL_GetNumJoystickHats(SDL_Joystick *joystick);
  847. /**
  848. * Get the number of buttons on a joystick.
  849. *
  850. * \param joystick an SDL_Joystick structure containing joystick information.
  851. * \returns the number of buttons on success or -1 on failure; call
  852. * SDL_GetError() for more information.
  853. *
  854. * \since This function is available since SDL 3.2.0.
  855. *
  856. * \sa SDL_GetJoystickButton
  857. * \sa SDL_GetNumJoystickAxes
  858. * \sa SDL_GetNumJoystickBalls
  859. * \sa SDL_GetNumJoystickHats
  860. */
  861. extern SDL_DECLSPEC int SDLCALL SDL_GetNumJoystickButtons(SDL_Joystick *joystick);
  862. /**
  863. * Set the state of joystick event processing.
  864. *
  865. * If joystick events are disabled, you must call SDL_UpdateJoysticks()
  866. * yourself and check the state of the joystick when you want joystick
  867. * information.
  868. *
  869. * \param enabled whether to process joystick events or not.
  870. *
  871. * \since This function is available since SDL 3.2.0.
  872. *
  873. * \sa SDL_JoystickEventsEnabled
  874. * \sa SDL_UpdateJoysticks
  875. */
  876. extern SDL_DECLSPEC void SDLCALL SDL_SetJoystickEventsEnabled(bool enabled);
  877. /**
  878. * Query the state of joystick event processing.
  879. *
  880. * If joystick events are disabled, you must call SDL_UpdateJoysticks()
  881. * yourself and check the state of the joystick when you want joystick
  882. * information.
  883. *
  884. * \returns true if joystick events are being processed, false otherwise.
  885. *
  886. * \since This function is available since SDL 3.2.0.
  887. *
  888. * \sa SDL_SetJoystickEventsEnabled
  889. */
  890. extern SDL_DECLSPEC bool SDLCALL SDL_JoystickEventsEnabled(void);
  891. /**
  892. * Update the current state of the open joysticks.
  893. *
  894. * This is called automatically by the event loop if any joystick events are
  895. * enabled.
  896. *
  897. * \since This function is available since SDL 3.2.0.
  898. */
  899. extern SDL_DECLSPEC void SDLCALL SDL_UpdateJoysticks(void);
  900. /**
  901. * Get the current state of an axis control on a joystick.
  902. *
  903. * SDL makes no promises about what part of the joystick any given axis refers
  904. * to. Your game should have some sort of configuration UI to let users
  905. * specify what each axis should be bound to. Alternately, SDL's higher-level
  906. * Game Controller API makes a great effort to apply order to this lower-level
  907. * interface, so you know that a specific axis is the "left thumb stick," etc.
  908. *
  909. * The value returned by SDL_GetJoystickAxis() is a signed integer (-32768 to
  910. * 32767) representing the current position of the axis. It may be necessary
  911. * to impose certain tolerances on these values to account for jitter.
  912. *
  913. * \param joystick an SDL_Joystick structure containing joystick information.
  914. * \param axis the axis to query; the axis indices start at index 0.
  915. * \returns a 16-bit signed integer representing the current position of the
  916. * axis or 0 on failure; call SDL_GetError() for more information.
  917. *
  918. * \since This function is available since SDL 3.2.0.
  919. *
  920. * \sa SDL_GetNumJoystickAxes
  921. */
  922. extern SDL_DECLSPEC Sint16 SDLCALL SDL_GetJoystickAxis(SDL_Joystick *joystick, int axis);
  923. /**
  924. * Get the initial state of an axis control on a joystick.
  925. *
  926. * The state is a value ranging from -32768 to 32767.
  927. *
  928. * The axis indices start at index 0.
  929. *
  930. * \param joystick an SDL_Joystick structure containing joystick information.
  931. * \param axis the axis to query; the axis indices start at index 0.
  932. * \param state upon return, the initial value is supplied here.
  933. * \returns true if this axis has any initial value, or false if not.
  934. *
  935. * \since This function is available since SDL 3.2.0.
  936. */
  937. extern SDL_DECLSPEC bool SDLCALL SDL_GetJoystickAxisInitialState(SDL_Joystick *joystick, int axis, Sint16 *state);
  938. /**
  939. * Get the ball axis change since the last poll.
  940. *
  941. * Trackballs can only return relative motion since the last call to
  942. * SDL_GetJoystickBall(), these motion deltas are placed into `dx` and `dy`.
  943. *
  944. * Most joysticks do not have trackballs.
  945. *
  946. * \param joystick the SDL_Joystick to query.
  947. * \param ball the ball index to query; ball indices start at index 0.
  948. * \param dx stores the difference in the x axis position since the last poll.
  949. * \param dy stores the difference in the y axis position since the last poll.
  950. * \returns true on success or false on failure; call SDL_GetError() for more
  951. * information.
  952. *
  953. * \since This function is available since SDL 3.2.0.
  954. *
  955. * \sa SDL_GetNumJoystickBalls
  956. */
  957. extern SDL_DECLSPEC bool SDLCALL SDL_GetJoystickBall(SDL_Joystick *joystick, int ball, int *dx, int *dy);
  958. /**
  959. * Get the current state of a POV hat on a joystick.
  960. *
  961. * The returned value will be one of the `SDL_HAT_*` values.
  962. *
  963. * \param joystick an SDL_Joystick structure containing joystick information.
  964. * \param hat the hat index to get the state from; indices start at index 0.
  965. * \returns the current hat position.
  966. *
  967. * \since This function is available since SDL 3.2.0.
  968. *
  969. * \sa SDL_GetNumJoystickHats
  970. */
  971. extern SDL_DECLSPEC Uint8 SDLCALL SDL_GetJoystickHat(SDL_Joystick *joystick, int hat);
  972. #define SDL_HAT_CENTERED 0x00u
  973. #define SDL_HAT_UP 0x01u
  974. #define SDL_HAT_RIGHT 0x02u
  975. #define SDL_HAT_DOWN 0x04u
  976. #define SDL_HAT_LEFT 0x08u
  977. #define SDL_HAT_RIGHTUP (SDL_HAT_RIGHT|SDL_HAT_UP)
  978. #define SDL_HAT_RIGHTDOWN (SDL_HAT_RIGHT|SDL_HAT_DOWN)
  979. #define SDL_HAT_LEFTUP (SDL_HAT_LEFT|SDL_HAT_UP)
  980. #define SDL_HAT_LEFTDOWN (SDL_HAT_LEFT|SDL_HAT_DOWN)
  981. /**
  982. * Get the current state of a button on a joystick.
  983. *
  984. * \param joystick an SDL_Joystick structure containing joystick information.
  985. * \param button the button index to get the state from; indices start at
  986. * index 0.
  987. * \returns true if the button is pressed, false otherwise.
  988. *
  989. * \since This function is available since SDL 3.2.0.
  990. *
  991. * \sa SDL_GetNumJoystickButtons
  992. */
  993. extern SDL_DECLSPEC bool SDLCALL SDL_GetJoystickButton(SDL_Joystick *joystick, int button);
  994. /**
  995. * Start a rumble effect.
  996. *
  997. * Each call to this function cancels any previous rumble effect, and calling
  998. * it with 0 intensity stops any rumbling.
  999. *
  1000. * This function requires you to process SDL events or call
  1001. * SDL_UpdateJoysticks() to update rumble state.
  1002. *
  1003. * \param joystick the joystick to vibrate.
  1004. * \param low_frequency_rumble the intensity of the low frequency (left)
  1005. * rumble motor, from 0 to 0xFFFF.
  1006. * \param high_frequency_rumble the intensity of the high frequency (right)
  1007. * rumble motor, from 0 to 0xFFFF.
  1008. * \param duration_ms the duration of the rumble effect, in milliseconds.
  1009. * \returns true, or false if rumble isn't supported on this joystick.
  1010. *
  1011. * \since This function is available since SDL 3.2.0.
  1012. */
  1013. extern SDL_DECLSPEC bool SDLCALL SDL_RumbleJoystick(SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble, Uint32 duration_ms);
  1014. /**
  1015. * Start a rumble effect in the joystick's triggers.
  1016. *
  1017. * Each call to this function cancels any previous trigger rumble effect, and
  1018. * calling it with 0 intensity stops any rumbling.
  1019. *
  1020. * Note that this is rumbling of the _triggers_ and not the game controller as
  1021. * a whole. This is currently only supported on Xbox One controllers. If you
  1022. * want the (more common) whole-controller rumble, use SDL_RumbleJoystick()
  1023. * instead.
  1024. *
  1025. * This function requires you to process SDL events or call
  1026. * SDL_UpdateJoysticks() to update rumble state.
  1027. *
  1028. * \param joystick the joystick to vibrate.
  1029. * \param left_rumble the intensity of the left trigger rumble motor, from 0
  1030. * to 0xFFFF.
  1031. * \param right_rumble the intensity of the right trigger rumble motor, from 0
  1032. * to 0xFFFF.
  1033. * \param duration_ms the duration of the rumble effect, in milliseconds.
  1034. * \returns true on success or false on failure; call SDL_GetError() for more
  1035. * information.
  1036. *
  1037. * \since This function is available since SDL 3.2.0.
  1038. *
  1039. * \sa SDL_RumbleJoystick
  1040. */
  1041. extern SDL_DECLSPEC bool SDLCALL SDL_RumbleJoystickTriggers(SDL_Joystick *joystick, Uint16 left_rumble, Uint16 right_rumble, Uint32 duration_ms);
  1042. /**
  1043. * Update a joystick's LED color.
  1044. *
  1045. * An example of a joystick LED is the light on the back of a PlayStation 4's
  1046. * DualShock 4 controller.
  1047. *
  1048. * For joysticks with a single color LED, the maximum of the RGB values will
  1049. * be used as the LED brightness.
  1050. *
  1051. * \param joystick the joystick to update.
  1052. * \param red the intensity of the red LED.
  1053. * \param green the intensity of the green LED.
  1054. * \param blue the intensity of the blue LED.
  1055. * \returns true on success or false on failure; call SDL_GetError() for more
  1056. * information.
  1057. *
  1058. * \since This function is available since SDL 3.2.0.
  1059. */
  1060. extern SDL_DECLSPEC bool SDLCALL SDL_SetJoystickLED(SDL_Joystick *joystick, Uint8 red, Uint8 green, Uint8 blue);
  1061. /**
  1062. * Send a joystick specific effect packet.
  1063. *
  1064. * \param joystick the joystick to affect.
  1065. * \param data the data to send to the joystick.
  1066. * \param size the size of the data to send to the joystick.
  1067. * \returns true on success or false on failure; call SDL_GetError() for more
  1068. * information.
  1069. *
  1070. * \since This function is available since SDL 3.2.0.
  1071. */
  1072. extern SDL_DECLSPEC bool SDLCALL SDL_SendJoystickEffect(SDL_Joystick *joystick, const void *data, int size);
  1073. /**
  1074. * Close a joystick previously opened with SDL_OpenJoystick().
  1075. *
  1076. * \param joystick the joystick device to close.
  1077. *
  1078. * \since This function is available since SDL 3.2.0.
  1079. *
  1080. * \sa SDL_OpenJoystick
  1081. */
  1082. extern SDL_DECLSPEC void SDLCALL SDL_CloseJoystick(SDL_Joystick *joystick);
  1083. /**
  1084. * Get the connection state of a joystick.
  1085. *
  1086. * \param joystick the joystick to query.
  1087. * \returns the connection state on success or
  1088. * `SDL_JOYSTICK_CONNECTION_INVALID` on failure; call SDL_GetError()
  1089. * for more information.
  1090. *
  1091. * \since This function is available since SDL 3.2.0.
  1092. */
  1093. extern SDL_DECLSPEC SDL_JoystickConnectionState SDLCALL SDL_GetJoystickConnectionState(SDL_Joystick *joystick);
  1094. /**
  1095. * Get the battery state of a joystick.
  1096. *
  1097. * You should never take a battery status as absolute truth. Batteries
  1098. * (especially failing batteries) are delicate hardware, and the values
  1099. * reported here are best estimates based on what that hardware reports. It's
  1100. * not uncommon for older batteries to lose stored power much faster than it
  1101. * reports, or completely drain when reporting it has 20 percent left, etc.
  1102. *
  1103. * \param joystick the joystick to query.
  1104. * \param percent a pointer filled in with the percentage of battery life
  1105. * left, between 0 and 100, or NULL to ignore. This will be
  1106. * filled in with -1 we can't determine a value or there is no
  1107. * battery.
  1108. * \returns the current battery state or `SDL_POWERSTATE_ERROR` on failure;
  1109. * call SDL_GetError() for more information.
  1110. *
  1111. * \since This function is available since SDL 3.2.0.
  1112. */
  1113. extern SDL_DECLSPEC SDL_PowerState SDLCALL SDL_GetJoystickPowerInfo(SDL_Joystick *joystick, int *percent);
  1114. /* Ends C function definitions when using C++ */
  1115. #ifdef __cplusplus
  1116. }
  1117. #endif
  1118. #include <SDL3/SDL_close_code.h>
  1119. #endif /* SDL_joystick_h_ */