SDL_joystick.h 44 KB

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