SDL_gamepad.h 53 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510
  1. /*
  2. Simple DirectMedia Layer
  3. Copyright (C) 1997-2024 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. * # CategoryGamepad
  20. *
  21. * SDL provides a low-level joystick API, which just treats joysticks as an
  22. * arbitrary pile of buttons, axes, and hat switches. If you're planning to
  23. * write your own control configuration screen, this can give you a lot of
  24. * flexibility, but that's a lot of work, and most things that we consider
  25. * "joysticks" now are actually console-style gamepads. So SDL provides the
  26. * gamepad API on top of the lower-level joystick functionality.
  27. *
  28. * The difference betweena joystick and a gamepad is that a gamepad tells you
  29. * _where_ a button or axis is on the device. You don't speak to gamepads in
  30. * terms of arbitrary numbers like "button 3" or "axis 2" but in standard
  31. * locations: the d-pad, the shoulder buttons, triggers, A/B/X/Y (or
  32. * X/O/Square/Triangle, if you will).
  33. *
  34. * One turns a joystick into a gamepad by providing a magic configuration
  35. * string, which tells SDL the details of a specific device: when you see this
  36. * specific hardware, if button 2 gets pressed, this is actually D-Pad Up,
  37. * etc.
  38. *
  39. * SDL has many popular controllers configured out of the box, and users can
  40. * add their own controller details through an environment variable if it's
  41. * otherwise unknown to SDL.
  42. *
  43. * In order to use these functions, SDL_Init() must have been called with the
  44. * SDL_INIT_GAMEPAD flag. This causes SDL to scan the system for gamepads, and
  45. * load appropriate drivers.
  46. *
  47. * If you would like to receive gamepad updates while the application is in
  48. * the background, you should set the following hint before calling
  49. * SDL_Init(): SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS
  50. */
  51. #ifndef SDL_gamepad_h_
  52. #define SDL_gamepad_h_
  53. #include <SDL3/SDL_stdinc.h>
  54. #include <SDL3/SDL_error.h>
  55. #include <SDL3/SDL_joystick.h>
  56. #include <SDL3/SDL_properties.h>
  57. #include <SDL3/SDL_iostream.h>
  58. #include <SDL3/SDL_sensor.h>
  59. #include <SDL3/SDL_begin_code.h>
  60. /* Set up for C function definitions, even when using C++ */
  61. #ifdef __cplusplus
  62. extern "C" {
  63. #endif
  64. /**
  65. * The structure used to identify an SDL gamepad
  66. *
  67. * \since This struct is available since SDL 3.0.0.
  68. */
  69. typedef struct SDL_Gamepad SDL_Gamepad;
  70. /**
  71. * Standard gamepad types.
  72. *
  73. * This type does not necessarily map to first-party controllers from
  74. * Microsoft/Sony/Nintendo; in many cases, third-party controllers can report
  75. * as these, either because they were designed for a specific console, or they
  76. * simply most closely match that console's controllers (does it have A/B/X/Y
  77. * buttons or X/O/Square/Triangle? Does it have a touchpad? etc).
  78. */
  79. typedef enum SDL_GamepadType
  80. {
  81. SDL_GAMEPAD_TYPE_UNKNOWN = 0,
  82. SDL_GAMEPAD_TYPE_STANDARD,
  83. SDL_GAMEPAD_TYPE_XBOX360,
  84. SDL_GAMEPAD_TYPE_XBOXONE,
  85. SDL_GAMEPAD_TYPE_PS3,
  86. SDL_GAMEPAD_TYPE_PS4,
  87. SDL_GAMEPAD_TYPE_PS5,
  88. SDL_GAMEPAD_TYPE_NINTENDO_SWITCH_PRO,
  89. SDL_GAMEPAD_TYPE_NINTENDO_SWITCH_JOYCON_LEFT,
  90. SDL_GAMEPAD_TYPE_NINTENDO_SWITCH_JOYCON_RIGHT,
  91. SDL_GAMEPAD_TYPE_NINTENDO_SWITCH_JOYCON_PAIR,
  92. SDL_GAMEPAD_TYPE_MAX
  93. } SDL_GamepadType;
  94. /**
  95. * The list of buttons available on a gamepad
  96. *
  97. * For controllers that use a diamond pattern for the face buttons, the
  98. * south/east/west/north buttons below correspond to the locations in the
  99. * diamond pattern. For Xbox controllers, this would be A/B/X/Y, for Nintendo
  100. * Switch controllers, this would be B/A/Y/X, for PlayStation controllers this
  101. * would be Cross/Circle/Square/Triangle.
  102. *
  103. * For controllers that don't use a diamond pattern for the face buttons, the
  104. * south/east/west/north buttons indicate the buttons labeled A, B, C, D, or
  105. * 1, 2, 3, 4, or for controllers that aren't labeled, they are the primary,
  106. * secondary, etc. buttons.
  107. *
  108. * The activate action is often the south button and the cancel action is
  109. * often the east button, but in some regions this is reversed, so your game
  110. * should allow remapping actions based on user preferences.
  111. *
  112. * You can query the labels for the face buttons using
  113. * SDL_GetGamepadButtonLabel()
  114. *
  115. * \since This enum is available since SDL 3.0.0.
  116. */
  117. typedef enum SDL_GamepadButton
  118. {
  119. SDL_GAMEPAD_BUTTON_INVALID = -1,
  120. SDL_GAMEPAD_BUTTON_SOUTH, /* Bottom face button (e.g. Xbox A button) */
  121. SDL_GAMEPAD_BUTTON_EAST, /* Right face button (e.g. Xbox B button) */
  122. SDL_GAMEPAD_BUTTON_WEST, /* Left face button (e.g. Xbox X button) */
  123. SDL_GAMEPAD_BUTTON_NORTH, /* Top face button (e.g. Xbox Y button) */
  124. SDL_GAMEPAD_BUTTON_BACK,
  125. SDL_GAMEPAD_BUTTON_GUIDE,
  126. SDL_GAMEPAD_BUTTON_START,
  127. SDL_GAMEPAD_BUTTON_LEFT_STICK,
  128. SDL_GAMEPAD_BUTTON_RIGHT_STICK,
  129. SDL_GAMEPAD_BUTTON_LEFT_SHOULDER,
  130. SDL_GAMEPAD_BUTTON_RIGHT_SHOULDER,
  131. SDL_GAMEPAD_BUTTON_DPAD_UP,
  132. SDL_GAMEPAD_BUTTON_DPAD_DOWN,
  133. SDL_GAMEPAD_BUTTON_DPAD_LEFT,
  134. SDL_GAMEPAD_BUTTON_DPAD_RIGHT,
  135. SDL_GAMEPAD_BUTTON_MISC1, /* Additional button (e.g. Xbox Series X share button, PS5 microphone button, Nintendo Switch Pro capture button, Amazon Luna microphone button, Google Stadia capture button) */
  136. SDL_GAMEPAD_BUTTON_RIGHT_PADDLE1, /* Upper or primary paddle, under your right hand (e.g. Xbox Elite paddle P1) */
  137. SDL_GAMEPAD_BUTTON_LEFT_PADDLE1, /* Upper or primary paddle, under your left hand (e.g. Xbox Elite paddle P3) */
  138. SDL_GAMEPAD_BUTTON_RIGHT_PADDLE2, /* Lower or secondary paddle, under your right hand (e.g. Xbox Elite paddle P2) */
  139. SDL_GAMEPAD_BUTTON_LEFT_PADDLE2, /* Lower or secondary paddle, under your left hand (e.g. Xbox Elite paddle P4) */
  140. SDL_GAMEPAD_BUTTON_TOUCHPAD, /* PS4/PS5 touchpad button */
  141. SDL_GAMEPAD_BUTTON_MISC2, /* Additional button */
  142. SDL_GAMEPAD_BUTTON_MISC3, /* Additional button */
  143. SDL_GAMEPAD_BUTTON_MISC4, /* Additional button */
  144. SDL_GAMEPAD_BUTTON_MISC5, /* Additional button */
  145. SDL_GAMEPAD_BUTTON_MISC6, /* Additional button */
  146. SDL_GAMEPAD_BUTTON_MAX
  147. } SDL_GamepadButton;
  148. /**
  149. * The set of gamepad button labels
  150. *
  151. * This isn't a complete set, just the face buttons to make it easy to show
  152. * button prompts.
  153. *
  154. * For a complete set, you should look at the button and gamepad type and have
  155. * a set of symbols that work well with your art style.
  156. *
  157. * \since This enum is available since SDL 3.0.0.
  158. */
  159. typedef enum SDL_GamepadButtonLabel
  160. {
  161. SDL_GAMEPAD_BUTTON_LABEL_UNKNOWN,
  162. SDL_GAMEPAD_BUTTON_LABEL_A,
  163. SDL_GAMEPAD_BUTTON_LABEL_B,
  164. SDL_GAMEPAD_BUTTON_LABEL_X,
  165. SDL_GAMEPAD_BUTTON_LABEL_Y,
  166. SDL_GAMEPAD_BUTTON_LABEL_CROSS,
  167. SDL_GAMEPAD_BUTTON_LABEL_CIRCLE,
  168. SDL_GAMEPAD_BUTTON_LABEL_SQUARE,
  169. SDL_GAMEPAD_BUTTON_LABEL_TRIANGLE
  170. } SDL_GamepadButtonLabel;
  171. /**
  172. * The list of axes available on a gamepad
  173. *
  174. * Thumbstick axis values range from SDL_JOYSTICK_AXIS_MIN to
  175. * SDL_JOYSTICK_AXIS_MAX, and are centered within ~8000 of zero, though
  176. * advanced UI will allow users to set or autodetect the dead zone, which
  177. * varies between gamepads.
  178. *
  179. * Trigger axis values range from 0 (released) to SDL_JOYSTICK_AXIS_MAX (fully
  180. * pressed) when reported by SDL_GetGamepadAxis(). Note that this is not the
  181. * same range that will be reported by the lower-level SDL_GetJoystickAxis().
  182. *
  183. * \since This enum is available since SDL 3.0.0.
  184. */
  185. typedef enum SDL_GamepadAxis
  186. {
  187. SDL_GAMEPAD_AXIS_INVALID = -1,
  188. SDL_GAMEPAD_AXIS_LEFTX,
  189. SDL_GAMEPAD_AXIS_LEFTY,
  190. SDL_GAMEPAD_AXIS_RIGHTX,
  191. SDL_GAMEPAD_AXIS_RIGHTY,
  192. SDL_GAMEPAD_AXIS_LEFT_TRIGGER,
  193. SDL_GAMEPAD_AXIS_RIGHT_TRIGGER,
  194. SDL_GAMEPAD_AXIS_MAX
  195. } SDL_GamepadAxis;
  196. /**
  197. * Types of gamepad control bindings.
  198. *
  199. * A gamepad is a collection of bindings that map arbitrary joystick buttons,
  200. * axes and hat switches to specific positions on a generic console-style
  201. * gamepad. This enum is used as part of SDL_GamepadBinding to specify those
  202. * mappings.
  203. *
  204. * \since This enum is available since SDL 3.0.0.
  205. */
  206. typedef enum SDL_GamepadBindingType
  207. {
  208. SDL_GAMEPAD_BINDTYPE_NONE = 0,
  209. SDL_GAMEPAD_BINDTYPE_BUTTON,
  210. SDL_GAMEPAD_BINDTYPE_AXIS,
  211. SDL_GAMEPAD_BINDTYPE_HAT
  212. } SDL_GamepadBindingType;
  213. /**
  214. * A mapping between one joystick input to a gamepad control.
  215. *
  216. * A gamepad has a collection of several bindings, to say, for example, when
  217. * joystick button number 5 is pressed, that should be treated like the
  218. * gamepad's "start" button.
  219. *
  220. * SDL has these bindings built-in for many popular controllers, and can add
  221. * more with a simple text string. Those strings are parsed into a collection
  222. * of these structs to make it easier to operate on the data.
  223. *
  224. * \since This struct is available since SDL 3.0.0.
  225. *
  226. * \sa SDL_GetGamepadBindings
  227. */
  228. typedef struct SDL_GamepadBinding
  229. {
  230. SDL_GamepadBindingType input_type;
  231. union
  232. {
  233. int button;
  234. struct
  235. {
  236. int axis;
  237. int axis_min;
  238. int axis_max;
  239. } axis;
  240. struct
  241. {
  242. int hat;
  243. int hat_mask;
  244. } hat;
  245. } input;
  246. SDL_GamepadBindingType output_type;
  247. union
  248. {
  249. SDL_GamepadButton button;
  250. struct
  251. {
  252. SDL_GamepadAxis axis;
  253. int axis_min;
  254. int axis_max;
  255. } axis;
  256. } output;
  257. } SDL_GamepadBinding;
  258. /**
  259. * Add support for gamepads that SDL is unaware of or change the binding of an
  260. * existing gamepad.
  261. *
  262. * The mapping string has the format "GUID,name,mapping", where GUID is the
  263. * string value from SDL_GUIDToString(), name is the human readable string for
  264. * the device and mappings are gamepad mappings to joystick ones. Under
  265. * Windows there is a reserved GUID of "xinput" that covers all XInput
  266. * devices. The mapping format for joystick is:
  267. *
  268. * - `bX`: a joystick button, index X
  269. * - `hX.Y`: hat X with value Y
  270. * - `aX`: axis X of the joystick
  271. *
  272. * Buttons can be used as a gamepad axes and vice versa.
  273. *
  274. * This string shows an example of a valid mapping for a gamepad:
  275. *
  276. * ```c
  277. * "341a3608000000000000504944564944,Afterglow PS3 Controller,a:b1,b:b2,y:b3,x:b0,start:b9,guide:b12,back:b8,dpup:h0.1,dpleft:h0.8,dpdown:h0.4,dpright:h0.2,leftshoulder:b4,rightshoulder:b5,leftstick:b10,rightstick:b11,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:b6,righttrigger:b7"
  278. * ```
  279. *
  280. * \param mapping the mapping string.
  281. * \returns 1 if a new mapping is added, 0 if an existing mapping is updated,
  282. * -1 on failure; call SDL_GetError() for more information.
  283. *
  284. * \threadsafety It is safe to call this function from any thread.
  285. *
  286. * \since This function is available since SDL 3.0.0.
  287. *
  288. * \sa SDL_GetGamepadMapping
  289. * \sa SDL_GetGamepadMappingForGUID
  290. */
  291. extern SDL_DECLSPEC int SDLCALL SDL_AddGamepadMapping(const char *mapping);
  292. /**
  293. * Load a set of gamepad mappings from an SDL_IOStream.
  294. *
  295. * You can call this function several times, if needed, to load different
  296. * database files.
  297. *
  298. * If a new mapping is loaded for an already known gamepad GUID, the later
  299. * version will overwrite the one currently loaded.
  300. *
  301. * Mappings not belonging to the current platform or with no platform field
  302. * specified will be ignored (i.e. mappings for Linux will be ignored in
  303. * Windows, etc).
  304. *
  305. * This function will load the text database entirely in memory before
  306. * processing it, so take this into consideration if you are in a memory
  307. * constrained environment.
  308. *
  309. * \param src the data stream for the mappings to be added.
  310. * \param closeio if SDL_TRUE, calls SDL_CloseIO() on `src` before returning,
  311. * even in the case of an error.
  312. * \returns the number of mappings added or -1 on failure; call SDL_GetError()
  313. * for more information.
  314. *
  315. * \threadsafety It is safe to call this function from any thread.
  316. *
  317. * \since This function is available since SDL 3.0.0.
  318. *
  319. * \sa SDL_AddGamepadMapping
  320. * \sa SDL_AddGamepadMappingsFromFile
  321. * \sa SDL_GetGamepadMapping
  322. * \sa SDL_GetGamepadMappingForGUID
  323. */
  324. extern SDL_DECLSPEC int SDLCALL SDL_AddGamepadMappingsFromIO(SDL_IOStream *src, SDL_bool closeio);
  325. /**
  326. * Load a set of gamepad mappings from a file.
  327. *
  328. * You can call this function several times, if needed, to load different
  329. * database files.
  330. *
  331. * If a new mapping is loaded for an already known gamepad GUID, the later
  332. * version will overwrite the one currently loaded.
  333. *
  334. * Mappings not belonging to the current platform or with no platform field
  335. * specified will be ignored (i.e. mappings for Linux will be ignored in
  336. * Windows, etc).
  337. *
  338. * \param file the mappings file to load.
  339. * \returns the number of mappings added or -1 on failure; call SDL_GetError()
  340. * for more information.
  341. *
  342. * \threadsafety It is safe to call this function from any thread.
  343. *
  344. * \since This function is available since SDL 3.0.0.
  345. *
  346. * \sa SDL_AddGamepadMapping
  347. * \sa SDL_AddGamepadMappingsFromIO
  348. * \sa SDL_GetGamepadMapping
  349. * \sa SDL_GetGamepadMappingForGUID
  350. */
  351. extern SDL_DECLSPEC int SDLCALL SDL_AddGamepadMappingsFromFile(const char *file);
  352. /**
  353. * Reinitialize the SDL mapping database to its initial state.
  354. *
  355. * This will generate gamepad events as needed if device mappings change.
  356. *
  357. * \returns 0 on success or a negative error code on failure; call
  358. * SDL_GetError() for more information.
  359. *
  360. * \since This function is available since SDL 3.0.0.
  361. */
  362. extern SDL_DECLSPEC int SDLCALL SDL_ReloadGamepadMappings(void);
  363. /**
  364. * Get the current gamepad mappings.
  365. *
  366. * This returns temporary memory which will be automatically freed later, and
  367. * can be claimed with SDL_ClaimTemporaryMemory().
  368. *
  369. * \param count a pointer filled in with the number of mappings returned, can
  370. * be NULL.
  371. * \returns an array of the mapping strings, NULL-terminated, or NULL on
  372. * failure; call SDL_GetError() for more information.
  373. *
  374. * \since This function is available since SDL 3.0.0.
  375. */
  376. extern SDL_DECLSPEC const char * const * SDLCALL SDL_GetGamepadMappings(int *count);
  377. /**
  378. * Get the gamepad mapping string for a given GUID.
  379. *
  380. * This returns temporary memory which will be automatically freed later, and
  381. * can be claimed with SDL_ClaimTemporaryMemory().
  382. *
  383. * \param guid a structure containing the GUID for which a mapping is desired.
  384. * \returns a mapping string or NULL on failure; call SDL_GetError() for more
  385. * information.
  386. *
  387. * \since This function is available since SDL 3.0.0.
  388. *
  389. * \sa SDL_GetJoystickGUIDForID
  390. * \sa SDL_GetJoystickGUID
  391. */
  392. extern SDL_DECLSPEC const char * SDLCALL SDL_GetGamepadMappingForGUID(SDL_GUID guid);
  393. /**
  394. * Get the current mapping of a gamepad.
  395. *
  396. * This returns temporary memory which will be automatically freed later, and
  397. * can be claimed with SDL_ClaimTemporaryMemory().
  398. *
  399. * Details about mappings are discussed with SDL_AddGamepadMapping().
  400. *
  401. * \param gamepad the gamepad you want to get the current mapping for.
  402. * \returns a string that has the gamepad's mapping or NULL if no mapping is
  403. * available; call SDL_GetError() for more information.
  404. *
  405. * \since This function is available since SDL 3.0.0.
  406. *
  407. * \sa SDL_AddGamepadMapping
  408. * \sa SDL_GetGamepadMappingForID
  409. * \sa SDL_GetGamepadMappingForGUID
  410. * \sa SDL_SetGamepadMapping
  411. */
  412. extern SDL_DECLSPEC const char * SDLCALL SDL_GetGamepadMapping(SDL_Gamepad *gamepad);
  413. /**
  414. * Set the current mapping of a joystick or gamepad.
  415. *
  416. * Details about mappings are discussed with SDL_AddGamepadMapping().
  417. *
  418. * \param instance_id the joystick instance ID.
  419. * \param mapping the mapping to use for this device, or NULL to clear the
  420. * mapping.
  421. * \returns 0 on success or a negative error code on failure; call
  422. * SDL_GetError() for more information.
  423. *
  424. * \since This function is available since SDL 3.0.0.
  425. *
  426. * \sa SDL_AddGamepadMapping
  427. * \sa SDL_GetGamepadMapping
  428. */
  429. extern SDL_DECLSPEC int SDLCALL SDL_SetGamepadMapping(SDL_JoystickID instance_id, const char *mapping);
  430. /**
  431. * Return whether a gamepad is currently connected.
  432. *
  433. * \returns SDL_TRUE if a gamepad is connected, SDL_FALSE otherwise.
  434. *
  435. * \since This function is available since SDL 3.0.0.
  436. *
  437. * \sa SDL_GetGamepads
  438. */
  439. extern SDL_DECLSPEC SDL_bool SDLCALL SDL_HasGamepad(void);
  440. /**
  441. * Get a list of currently connected gamepads.
  442. *
  443. * This returns temporary memory which will be automatically freed later, and
  444. * can be claimed with SDL_ClaimTemporaryMemory().
  445. *
  446. * \param count a pointer filled in with the number of gamepads returned, may
  447. * be NULL.
  448. * \returns a 0 terminated array of joystick instance IDs or NULL on failure;
  449. * call SDL_GetError() for more information.
  450. *
  451. * \since This function is available since SDL 3.0.0.
  452. *
  453. * \sa SDL_HasGamepad
  454. * \sa SDL_OpenGamepad
  455. */
  456. extern SDL_DECLSPEC const SDL_JoystickID * SDLCALL SDL_GetGamepads(int *count);
  457. /**
  458. * Check if the given joystick is supported by the gamepad interface.
  459. *
  460. * \param instance_id the joystick instance ID.
  461. * \returns SDL_TRUE if the given joystick is supported by the gamepad
  462. * interface, SDL_FALSE if it isn't or it's an invalid index.
  463. *
  464. * \since This function is available since SDL 3.0.0.
  465. *
  466. * \sa SDL_GetJoysticks
  467. * \sa SDL_OpenGamepad
  468. */
  469. extern SDL_DECLSPEC SDL_bool SDLCALL SDL_IsGamepad(SDL_JoystickID instance_id);
  470. /**
  471. * Get the implementation dependent name of a gamepad.
  472. *
  473. * This can be called before any gamepads are opened.
  474. *
  475. * This returns temporary memory which will be automatically freed later, and
  476. * can be claimed with SDL_ClaimTemporaryMemory().
  477. *
  478. * \param instance_id the joystick instance ID.
  479. * \returns the name of the selected gamepad. If no name can be found, this
  480. * function returns NULL; call SDL_GetError() for more information.
  481. *
  482. * \since This function is available since SDL 3.0.0.
  483. *
  484. * \sa SDL_GetGamepadName
  485. * \sa SDL_GetGamepads
  486. */
  487. extern SDL_DECLSPEC const char * SDLCALL SDL_GetGamepadNameForID(SDL_JoystickID instance_id);
  488. /**
  489. * Get the implementation dependent path of a gamepad.
  490. *
  491. * This can be called before any gamepads are opened.
  492. *
  493. * This returns temporary memory which will be automatically freed later, and
  494. * can be claimed with SDL_ClaimTemporaryMemory().
  495. *
  496. * \param instance_id the joystick instance ID.
  497. * \returns the path of the selected gamepad. If no path can be found, this
  498. * function returns NULL; call SDL_GetError() for more information.
  499. *
  500. * \since This function is available since SDL 3.0.0.
  501. *
  502. * \sa SDL_GetGamepadPath
  503. * \sa SDL_GetGamepads
  504. */
  505. extern SDL_DECLSPEC const char * SDLCALL SDL_GetGamepadPathForID(SDL_JoystickID instance_id);
  506. /**
  507. * Get the player index of a gamepad.
  508. *
  509. * This can be called before any gamepads are opened.
  510. *
  511. * \param instance_id the joystick instance ID.
  512. * \returns the player index of a gamepad, or -1 if it's not available.
  513. *
  514. * \since This function is available since SDL 3.0.0.
  515. *
  516. * \sa SDL_GetGamepadPlayerIndex
  517. * \sa SDL_GetGamepads
  518. */
  519. extern SDL_DECLSPEC int SDLCALL SDL_GetGamepadPlayerIndexForID(SDL_JoystickID instance_id);
  520. /**
  521. * Get the implementation-dependent GUID of a gamepad.
  522. *
  523. * This can be called before any gamepads are opened.
  524. *
  525. * \param instance_id the joystick instance ID.
  526. * \returns the GUID of the selected gamepad. If called on an invalid index,
  527. * this function returns a zero GUID.
  528. *
  529. * \since This function is available since SDL 3.0.0.
  530. *
  531. * \sa SDL_GetGamepadGUID
  532. * \sa SDL_GetGamepadGUIDString
  533. * \sa SDL_GetGamepads
  534. */
  535. extern SDL_DECLSPEC SDL_GUID SDLCALL SDL_GetGamepadGUIDForID(SDL_JoystickID instance_id);
  536. /**
  537. * Get the USB vendor ID of a gamepad, if available.
  538. *
  539. * This can be called before any gamepads are opened. If the vendor ID isn't
  540. * available this function returns 0.
  541. *
  542. * \param instance_id the joystick instance ID.
  543. * \returns the USB vendor ID of the selected gamepad. If called on an invalid
  544. * index, this function returns zero.
  545. *
  546. * \since This function is available since SDL 3.0.0.
  547. *
  548. * \sa SDL_GetGamepadVendor
  549. * \sa SDL_GetGamepads
  550. */
  551. extern SDL_DECLSPEC Uint16 SDLCALL SDL_GetGamepadVendorForID(SDL_JoystickID instance_id);
  552. /**
  553. * Get the USB product ID of a gamepad, if available.
  554. *
  555. * This can be called before any gamepads are opened. If the product ID isn't
  556. * available this function returns 0.
  557. *
  558. * \param instance_id the joystick instance ID.
  559. * \returns the USB product ID of the selected gamepad. If called on an
  560. * invalid index, this function returns zero.
  561. *
  562. * \since This function is available since SDL 3.0.0.
  563. *
  564. * \sa SDL_GetGamepadProduct
  565. * \sa SDL_GetGamepads
  566. */
  567. extern SDL_DECLSPEC Uint16 SDLCALL SDL_GetGamepadProductForID(SDL_JoystickID instance_id);
  568. /**
  569. * Get the product version of a gamepad, if available.
  570. *
  571. * This can be called before any gamepads are opened. If the product version
  572. * isn't available this function returns 0.
  573. *
  574. * \param instance_id the joystick instance ID.
  575. * \returns the product version of the selected gamepad. If called on an
  576. * invalid index, this function returns zero.
  577. *
  578. * \since This function is available since SDL 3.0.0.
  579. *
  580. * \sa SDL_GetGamepadProductVersion
  581. * \sa SDL_GetGamepads
  582. */
  583. extern SDL_DECLSPEC Uint16 SDLCALL SDL_GetGamepadProductVersionForID(SDL_JoystickID instance_id);
  584. /**
  585. * Get the type of a gamepad.
  586. *
  587. * This can be called before any gamepads are opened.
  588. *
  589. * \param instance_id the joystick instance ID.
  590. * \returns the gamepad type.
  591. *
  592. * \since This function is available since SDL 3.0.0.
  593. *
  594. * \sa SDL_GetGamepadType
  595. * \sa SDL_GetGamepads
  596. * \sa SDL_GetRealGamepadTypeForID
  597. */
  598. extern SDL_DECLSPEC SDL_GamepadType SDLCALL SDL_GetGamepadTypeForID(SDL_JoystickID instance_id);
  599. /**
  600. * Get the type of a gamepad, ignoring any mapping override.
  601. *
  602. * This can be called before any gamepads are opened.
  603. *
  604. * \param instance_id the joystick instance ID.
  605. * \returns the gamepad type.
  606. *
  607. * \since This function is available since SDL 3.0.0.
  608. *
  609. * \sa SDL_GetGamepadTypeForID
  610. * \sa SDL_GetGamepads
  611. * \sa SDL_GetRealGamepadType
  612. */
  613. extern SDL_DECLSPEC SDL_GamepadType SDLCALL SDL_GetRealGamepadTypeForID(SDL_JoystickID instance_id);
  614. /**
  615. * Get the mapping of a gamepad.
  616. *
  617. * This can be called before any gamepads are opened.
  618. *
  619. * This returns temporary memory which will be automatically freed later, and
  620. * can be claimed with SDL_ClaimTemporaryMemory().
  621. *
  622. * \param instance_id the joystick instance ID.
  623. * \returns the mapping string. Returns NULL if no mapping is available.
  624. *
  625. * \since This function is available since SDL 3.0.0.
  626. *
  627. * \sa SDL_GetGamepads
  628. * \sa SDL_GetGamepadMapping
  629. */
  630. extern SDL_DECLSPEC const char * SDLCALL SDL_GetGamepadMappingForID(SDL_JoystickID instance_id);
  631. /**
  632. * Open a gamepad for use.
  633. *
  634. * \param instance_id the joystick instance ID.
  635. * \returns a gamepad identifier or NULL if an error occurred; call
  636. * SDL_GetError() for more information.
  637. *
  638. * \since This function is available since SDL 3.0.0.
  639. *
  640. * \sa SDL_CloseGamepad
  641. * \sa SDL_IsGamepad
  642. */
  643. extern SDL_DECLSPEC SDL_Gamepad * SDLCALL SDL_OpenGamepad(SDL_JoystickID instance_id);
  644. /**
  645. * Get the SDL_Gamepad associated with a joystick instance ID, if it has been
  646. * opened.
  647. *
  648. * \param instance_id the joystick instance ID of the gamepad.
  649. * \returns an SDL_Gamepad on success or NULL on failure or if it hasn't been
  650. * opened yet; call SDL_GetError() for more information.
  651. *
  652. * \since This function is available since SDL 3.0.0.
  653. */
  654. extern SDL_DECLSPEC SDL_Gamepad * SDLCALL SDL_GetGamepadFromID(SDL_JoystickID instance_id);
  655. /**
  656. * Get the SDL_Gamepad associated with a player index.
  657. *
  658. * \param player_index the player index, which different from the instance ID.
  659. * \returns the SDL_Gamepad associated with a player index.
  660. *
  661. * \since This function is available since SDL 3.0.0.
  662. *
  663. * \sa SDL_GetGamepadPlayerIndex
  664. * \sa SDL_SetGamepadPlayerIndex
  665. */
  666. extern SDL_DECLSPEC SDL_Gamepad * SDLCALL SDL_GetGamepadFromPlayerIndex(int player_index);
  667. /**
  668. * Get the properties associated with an opened gamepad.
  669. *
  670. * These properties are shared with the underlying joystick object.
  671. *
  672. * The following read-only properties are provided by SDL:
  673. *
  674. * - `SDL_PROP_GAMEPAD_CAP_MONO_LED_BOOLEAN`: true if this gamepad has an LED
  675. * that has adjustable brightness
  676. * - `SDL_PROP_GAMEPAD_CAP_RGB_LED_BOOLEAN`: true if this gamepad has an LED
  677. * that has adjustable color
  678. * - `SDL_PROP_GAMEPAD_CAP_PLAYER_LED_BOOLEAN`: true if this gamepad has a
  679. * player LED
  680. * - `SDL_PROP_GAMEPAD_CAP_RUMBLE_BOOLEAN`: true if this gamepad has
  681. * left/right rumble
  682. * - `SDL_PROP_GAMEPAD_CAP_TRIGGER_RUMBLE_BOOLEAN`: true if this gamepad has
  683. * simple trigger rumble
  684. *
  685. * \param gamepad a gamepad identifier previously returned by
  686. * SDL_OpenGamepad().
  687. * \returns a valid property ID on success or 0 on failure; call
  688. * SDL_GetError() for more information.
  689. *
  690. * \since This function is available since SDL 3.0.0.
  691. */
  692. extern SDL_DECLSPEC SDL_PropertiesID SDLCALL SDL_GetGamepadProperties(SDL_Gamepad *gamepad);
  693. #define SDL_PROP_GAMEPAD_CAP_MONO_LED_BOOLEAN SDL_PROP_JOYSTICK_CAP_MONO_LED_BOOLEAN
  694. #define SDL_PROP_GAMEPAD_CAP_RGB_LED_BOOLEAN SDL_PROP_JOYSTICK_CAP_RGB_LED_BOOLEAN
  695. #define SDL_PROP_GAMEPAD_CAP_PLAYER_LED_BOOLEAN SDL_PROP_JOYSTICK_CAP_PLAYER_LED_BOOLEAN
  696. #define SDL_PROP_GAMEPAD_CAP_RUMBLE_BOOLEAN SDL_PROP_JOYSTICK_CAP_RUMBLE_BOOLEAN
  697. #define SDL_PROP_GAMEPAD_CAP_TRIGGER_RUMBLE_BOOLEAN SDL_PROP_JOYSTICK_CAP_TRIGGER_RUMBLE_BOOLEAN
  698. /**
  699. * Get the instance ID of an opened gamepad.
  700. *
  701. * \param gamepad a gamepad identifier previously returned by
  702. * SDL_OpenGamepad().
  703. * \returns the instance ID of the specified gamepad on success or 0 on
  704. * failure; call SDL_GetError() for more information.
  705. *
  706. * \since This function is available since SDL 3.0.0.
  707. */
  708. extern SDL_DECLSPEC SDL_JoystickID SDLCALL SDL_GetGamepadID(SDL_Gamepad *gamepad);
  709. /**
  710. * Get the implementation-dependent name for an opened gamepad.
  711. *
  712. * This returns temporary memory which will be automatically freed later, and
  713. * can be claimed with SDL_ClaimTemporaryMemory().
  714. *
  715. * \param gamepad a gamepad identifier previously returned by
  716. * SDL_OpenGamepad().
  717. * \returns the implementation dependent name for the gamepad, or NULL if
  718. * there is no name or the identifier passed is invalid.
  719. *
  720. * \since This function is available since SDL 3.0.0.
  721. *
  722. * \sa SDL_GetGamepadNameForID
  723. */
  724. extern SDL_DECLSPEC const char * SDLCALL SDL_GetGamepadName(SDL_Gamepad *gamepad);
  725. /**
  726. * Get the implementation-dependent path for an opened gamepad.
  727. *
  728. * This returns temporary memory which will be automatically freed later, and
  729. * can be claimed with SDL_ClaimTemporaryMemory().
  730. *
  731. * \param gamepad a gamepad identifier previously returned by
  732. * SDL_OpenGamepad().
  733. * \returns the implementation dependent path for the gamepad, or NULL if
  734. * there is no path or the identifier passed is invalid.
  735. *
  736. * \since This function is available since SDL 3.0.0.
  737. *
  738. * \sa SDL_GetGamepadPathForID
  739. */
  740. extern SDL_DECLSPEC const char * SDLCALL SDL_GetGamepadPath(SDL_Gamepad *gamepad);
  741. /**
  742. * Get the type of an opened gamepad.
  743. *
  744. * \param gamepad the gamepad object to query.
  745. * \returns the gamepad type, or SDL_GAMEPAD_TYPE_UNKNOWN if it's not
  746. * available.
  747. *
  748. * \since This function is available since SDL 3.0.0.
  749. *
  750. * \sa SDL_GetGamepadTypeForID
  751. */
  752. extern SDL_DECLSPEC SDL_GamepadType SDLCALL SDL_GetGamepadType(SDL_Gamepad *gamepad);
  753. /**
  754. * Get the type of an opened gamepad, ignoring any mapping override.
  755. *
  756. * \param gamepad the gamepad object to query.
  757. * \returns the gamepad type, or SDL_GAMEPAD_TYPE_UNKNOWN if it's not
  758. * available.
  759. *
  760. * \since This function is available since SDL 3.0.0.
  761. *
  762. * \sa SDL_GetRealGamepadTypeForID
  763. */
  764. extern SDL_DECLSPEC SDL_GamepadType SDLCALL SDL_GetRealGamepadType(SDL_Gamepad *gamepad);
  765. /**
  766. * Get the player index of an opened gamepad.
  767. *
  768. * For XInput gamepads this returns the XInput user index.
  769. *
  770. * \param gamepad the gamepad object to query.
  771. * \returns the player index for gamepad, or -1 if it's not available.
  772. *
  773. * \since This function is available since SDL 3.0.0.
  774. *
  775. * \sa SDL_SetGamepadPlayerIndex
  776. */
  777. extern SDL_DECLSPEC int SDLCALL SDL_GetGamepadPlayerIndex(SDL_Gamepad *gamepad);
  778. /**
  779. * Set the player index of an opened gamepad.
  780. *
  781. * \param gamepad the gamepad object to adjust.
  782. * \param player_index player index to assign to this gamepad, or -1 to clear
  783. * the player index and turn off player LEDs.
  784. * \returns 0 on success or a negative error code on failure; call
  785. * SDL_GetError() for more information.
  786. *
  787. * \since This function is available since SDL 3.0.0.
  788. *
  789. * \sa SDL_GetGamepadPlayerIndex
  790. */
  791. extern SDL_DECLSPEC int SDLCALL SDL_SetGamepadPlayerIndex(SDL_Gamepad *gamepad, int player_index);
  792. /**
  793. * Get the USB vendor ID of an opened gamepad, if available.
  794. *
  795. * If the vendor ID isn't available this function returns 0.
  796. *
  797. * \param gamepad the gamepad object to query.
  798. * \returns the USB vendor ID, or zero if unavailable.
  799. *
  800. * \since This function is available since SDL 3.0.0.
  801. *
  802. * \sa SDL_GetGamepadVendorForID
  803. */
  804. extern SDL_DECLSPEC Uint16 SDLCALL SDL_GetGamepadVendor(SDL_Gamepad *gamepad);
  805. /**
  806. * Get the USB product ID of an opened gamepad, if available.
  807. *
  808. * If the product ID isn't available this function returns 0.
  809. *
  810. * \param gamepad the gamepad object to query.
  811. * \returns the USB product ID, or zero if unavailable.
  812. *
  813. * \since This function is available since SDL 3.0.0.
  814. *
  815. * \sa SDL_GetGamepadProductForID
  816. */
  817. extern SDL_DECLSPEC Uint16 SDLCALL SDL_GetGamepadProduct(SDL_Gamepad *gamepad);
  818. /**
  819. * Get the product version of an opened gamepad, if available.
  820. *
  821. * If the product version isn't available this function returns 0.
  822. *
  823. * \param gamepad the gamepad object to query.
  824. * \returns the USB product version, or zero if unavailable.
  825. *
  826. * \since This function is available since SDL 3.0.0.
  827. *
  828. * \sa SDL_GetGamepadProductVersionForID
  829. */
  830. extern SDL_DECLSPEC Uint16 SDLCALL SDL_GetGamepadProductVersion(SDL_Gamepad *gamepad);
  831. /**
  832. * Get the firmware version of an opened gamepad, if available.
  833. *
  834. * If the firmware version isn't available this function returns 0.
  835. *
  836. * \param gamepad the gamepad object to query.
  837. * \returns the gamepad firmware version, or zero if unavailable.
  838. *
  839. * \since This function is available since SDL 3.0.0.
  840. */
  841. extern SDL_DECLSPEC Uint16 SDLCALL SDL_GetGamepadFirmwareVersion(SDL_Gamepad *gamepad);
  842. /**
  843. * Get the serial number of an opened gamepad, if available.
  844. *
  845. * Returns the serial number of the gamepad, or NULL if it is not available.
  846. *
  847. * This returns temporary memory which will be automatically freed later, and
  848. * can be claimed with SDL_ClaimTemporaryMemory().
  849. *
  850. * \param gamepad the gamepad object to query.
  851. * \returns the serial number, or NULL if unavailable.
  852. *
  853. * \since This function is available since SDL 3.0.0.
  854. */
  855. extern SDL_DECLSPEC const char * SDLCALL SDL_GetGamepadSerial(SDL_Gamepad *gamepad);
  856. /**
  857. * Get the Steam Input handle of an opened gamepad, if available.
  858. *
  859. * Returns an InputHandle_t for the gamepad that can be used with Steam Input
  860. * API: https://partner.steamgames.com/doc/api/ISteamInput
  861. *
  862. * \param gamepad the gamepad object to query.
  863. * \returns the gamepad handle, or 0 if unavailable.
  864. *
  865. * \since This function is available since SDL 3.0.0.
  866. */
  867. extern SDL_DECLSPEC Uint64 SDLCALL SDL_GetGamepadSteamHandle(SDL_Gamepad *gamepad);
  868. /**
  869. * Get the connection state of a gamepad.
  870. *
  871. * \param gamepad the gamepad object to query.
  872. * \returns the connection state on success or
  873. * `SDL_JOYSTICK_CONNECTION_INVALID` on failure; call SDL_GetError()
  874. * for more information.
  875. *
  876. * \since This function is available since SDL 3.0.0.
  877. */
  878. extern SDL_DECLSPEC SDL_JoystickConnectionState SDLCALL SDL_GetGamepadConnectionState(SDL_Gamepad *gamepad);
  879. /**
  880. * Get the battery state of a gamepad.
  881. *
  882. * You should never take a battery status as absolute truth. Batteries
  883. * (especially failing batteries) are delicate hardware, and the values
  884. * reported here are best estimates based on what that hardware reports. It's
  885. * not uncommon for older batteries to lose stored power much faster than it
  886. * reports, or completely drain when reporting it has 20 percent left, etc.
  887. *
  888. * \param gamepad the gamepad object to query.
  889. * \param percent a pointer filled in with the percentage of battery life
  890. * left, between 0 and 100, or NULL to ignore. This will be
  891. * filled in with -1 we can't determine a value or there is no
  892. * battery.
  893. * \returns the current battery state.
  894. *
  895. * \since This function is available since SDL 3.0.0.
  896. */
  897. extern SDL_DECLSPEC SDL_PowerState SDLCALL SDL_GetGamepadPowerInfo(SDL_Gamepad *gamepad, int *percent);
  898. /**
  899. * Check if a gamepad has been opened and is currently connected.
  900. *
  901. * \param gamepad a gamepad identifier previously returned by
  902. * SDL_OpenGamepad().
  903. * \returns SDL_TRUE if the gamepad has been opened and is currently
  904. * connected, or SDL_FALSE if not.
  905. *
  906. * \since This function is available since SDL 3.0.0.
  907. */
  908. extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GamepadConnected(SDL_Gamepad *gamepad);
  909. /**
  910. * Get the underlying joystick from a gamepad.
  911. *
  912. * This function will give you a SDL_Joystick object, which allows you to use
  913. * the SDL_Joystick functions with a SDL_Gamepad object. This would be useful
  914. * for getting a joystick's position at any given time, even if it hasn't
  915. * moved (moving it would produce an event, which would have the axis' value).
  916. *
  917. * The pointer returned is owned by the SDL_Gamepad. You should not call
  918. * SDL_CloseJoystick() on it, for example, since doing so will likely cause
  919. * SDL to crash.
  920. *
  921. * \param gamepad the gamepad object that you want to get a joystick from.
  922. * \returns an SDL_Joystick object, or NULL on failure; call SDL_GetError()
  923. * for more information.
  924. *
  925. * \since This function is available since SDL 3.0.0.
  926. */
  927. extern SDL_DECLSPEC SDL_Joystick * SDLCALL SDL_GetGamepadJoystick(SDL_Gamepad *gamepad);
  928. /**
  929. * Set the state of gamepad event processing.
  930. *
  931. * If gamepad events are disabled, you must call SDL_UpdateGamepads() yourself
  932. * and check the state of the gamepad when you want gamepad information.
  933. *
  934. * \param enabled whether to process gamepad events or not.
  935. *
  936. * \since This function is available since SDL 3.0.0.
  937. *
  938. * \sa SDL_GamepadEventsEnabled
  939. * \sa SDL_UpdateGamepads
  940. */
  941. extern SDL_DECLSPEC void SDLCALL SDL_SetGamepadEventsEnabled(SDL_bool enabled);
  942. /**
  943. * Query the state of gamepad event processing.
  944. *
  945. * If gamepad events are disabled, you must call SDL_UpdateGamepads() yourself
  946. * and check the state of the gamepad when you want gamepad information.
  947. *
  948. * \returns SDL_TRUE if gamepad events are being processed, SDL_FALSE
  949. * otherwise.
  950. *
  951. * \since This function is available since SDL 3.0.0.
  952. *
  953. * \sa SDL_SetGamepadEventsEnabled
  954. */
  955. extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GamepadEventsEnabled(void);
  956. /**
  957. * Get the SDL joystick layer bindings for a gamepad.
  958. *
  959. * This returns temporary memory which will be automatically freed later, and
  960. * can be claimed with SDL_ClaimTemporaryMemory().
  961. *
  962. * \param gamepad a gamepad.
  963. * \param count a pointer filled in with the number of bindings returned.
  964. * \returns a NULL terminated array of pointers to bindings or NULL on
  965. * failure; call SDL_GetError() for more information.
  966. *
  967. * \since This function is available since SDL 3.0.0.
  968. */
  969. extern SDL_DECLSPEC const SDL_GamepadBinding * const * SDLCALL SDL_GetGamepadBindings(SDL_Gamepad *gamepad, int *count);
  970. /**
  971. * Manually pump gamepad updates if not using the loop.
  972. *
  973. * This function is called automatically by the event loop if events are
  974. * enabled. Under such circumstances, it will not be necessary to call this
  975. * function.
  976. *
  977. * \since This function is available since SDL 3.0.0.
  978. */
  979. extern SDL_DECLSPEC void SDLCALL SDL_UpdateGamepads(void);
  980. /**
  981. * Convert a string into SDL_GamepadType enum.
  982. *
  983. * This function is called internally to translate SDL_Gamepad mapping strings
  984. * for the underlying joystick device into the consistent SDL_Gamepad mapping.
  985. * You do not normally need to call this function unless you are parsing
  986. * SDL_Gamepad mappings in your own code.
  987. *
  988. * \param str string representing a SDL_GamepadType type.
  989. * \returns the SDL_GamepadType enum corresponding to the input string, or
  990. * `SDL_GAMEPAD_TYPE_UNKNOWN` if no match was found.
  991. *
  992. * \since This function is available since SDL 3.0.0.
  993. *
  994. * \sa SDL_GetGamepadStringForType
  995. */
  996. extern SDL_DECLSPEC SDL_GamepadType SDLCALL SDL_GetGamepadTypeFromString(const char *str);
  997. /**
  998. * Convert from an SDL_GamepadType enum to a string.
  999. *
  1000. * This returns temporary memory which will be automatically freed later, and
  1001. * can be claimed with SDL_ClaimTemporaryMemory().
  1002. *
  1003. * \param type an enum value for a given SDL_GamepadType.
  1004. * \returns a string for the given type, or NULL if an invalid type is
  1005. * specified. The string returned is of the format used by
  1006. * SDL_Gamepad mapping strings.
  1007. *
  1008. * \since This function is available since SDL 3.0.0.
  1009. *
  1010. * \sa SDL_GetGamepadTypeFromString
  1011. */
  1012. extern SDL_DECLSPEC const char * SDLCALL SDL_GetGamepadStringForType(SDL_GamepadType type);
  1013. /**
  1014. * Convert a string into SDL_GamepadAxis enum.
  1015. *
  1016. * This function is called internally to translate SDL_Gamepad mapping strings
  1017. * for the underlying joystick device into the consistent SDL_Gamepad mapping.
  1018. * You do not normally need to call this function unless you are parsing
  1019. * SDL_Gamepad mappings in your own code.
  1020. *
  1021. * Note specially that "righttrigger" and "lefttrigger" map to
  1022. * `SDL_GAMEPAD_AXIS_RIGHT_TRIGGER` and `SDL_GAMEPAD_AXIS_LEFT_TRIGGER`,
  1023. * respectively.
  1024. *
  1025. * \param str string representing a SDL_Gamepad axis.
  1026. * \returns the SDL_GamepadAxis enum corresponding to the input string, or
  1027. * `SDL_GAMEPAD_AXIS_INVALID` if no match was found.
  1028. *
  1029. * \since This function is available since SDL 3.0.0.
  1030. *
  1031. * \sa SDL_GetGamepadStringForAxis
  1032. */
  1033. extern SDL_DECLSPEC SDL_GamepadAxis SDLCALL SDL_GetGamepadAxisFromString(const char *str);
  1034. /**
  1035. * Convert from an SDL_GamepadAxis enum to a string.
  1036. *
  1037. * This returns temporary memory which will be automatically freed later, and
  1038. * can be claimed with SDL_ClaimTemporaryMemory().
  1039. *
  1040. * \param axis an enum value for a given SDL_GamepadAxis.
  1041. * \returns a string for the given axis, or NULL if an invalid axis is
  1042. * specified. The string returned is of the format used by
  1043. * SDL_Gamepad mapping strings.
  1044. *
  1045. * \since This function is available since SDL 3.0.0.
  1046. *
  1047. * \sa SDL_GetGamepadAxisFromString
  1048. */
  1049. extern SDL_DECLSPEC const char * SDLCALL SDL_GetGamepadStringForAxis(SDL_GamepadAxis axis);
  1050. /**
  1051. * Query whether a gamepad has a given axis.
  1052. *
  1053. * This merely reports whether the gamepad's mapping defined this axis, as
  1054. * that is all the information SDL has about the physical device.
  1055. *
  1056. * \param gamepad a gamepad.
  1057. * \param axis an axis enum value (an SDL_GamepadAxis value).
  1058. * \returns SDL_TRUE if the gamepad has this axis, SDL_FALSE otherwise.
  1059. *
  1060. * \since This function is available since SDL 3.0.0.
  1061. *
  1062. * \sa SDL_GamepadHasButton
  1063. * \sa SDL_GetGamepadAxis
  1064. */
  1065. extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GamepadHasAxis(SDL_Gamepad *gamepad, SDL_GamepadAxis axis);
  1066. /**
  1067. * Get the current state of an axis control on a gamepad.
  1068. *
  1069. * The axis indices start at index 0.
  1070. *
  1071. * For thumbsticks, the state is a value ranging from -32768 (up/left) to
  1072. * 32767 (down/right).
  1073. *
  1074. * Triggers range from 0 when released to 32767 when fully pressed, and never
  1075. * return a negative value. Note that this differs from the value reported by
  1076. * the lower-level SDL_GetJoystickAxis(), which normally uses the full range.
  1077. *
  1078. * \param gamepad a gamepad.
  1079. * \param axis an axis index (one of the SDL_GamepadAxis values).
  1080. * \returns axis state (including 0) on success or 0 (also) on failure; call
  1081. * SDL_GetError() for more information.
  1082. *
  1083. * \since This function is available since SDL 3.0.0.
  1084. *
  1085. * \sa SDL_GamepadHasAxis
  1086. * \sa SDL_GetGamepadButton
  1087. */
  1088. extern SDL_DECLSPEC Sint16 SDLCALL SDL_GetGamepadAxis(SDL_Gamepad *gamepad, SDL_GamepadAxis axis);
  1089. /**
  1090. * Convert a string into an SDL_GamepadButton enum.
  1091. *
  1092. * This function is called internally to translate SDL_Gamepad mapping strings
  1093. * for the underlying joystick device into the consistent SDL_Gamepad mapping.
  1094. * You do not normally need to call this function unless you are parsing
  1095. * SDL_Gamepad mappings in your own code.
  1096. *
  1097. * \param str string representing a SDL_Gamepad axis.
  1098. * \returns the SDL_GamepadButton enum corresponding to the input string, or
  1099. * `SDL_GAMEPAD_BUTTON_INVALID` if no match was found.
  1100. *
  1101. * \since This function is available since SDL 3.0.0.
  1102. *
  1103. * \sa SDL_GetGamepadStringForButton
  1104. */
  1105. extern SDL_DECLSPEC SDL_GamepadButton SDLCALL SDL_GetGamepadButtonFromString(const char *str);
  1106. /**
  1107. * Convert from an SDL_GamepadButton enum to a string.
  1108. *
  1109. * This returns temporary memory which will be automatically freed later, and
  1110. * can be claimed with SDL_ClaimTemporaryMemory().
  1111. *
  1112. * \param button an enum value for a given SDL_GamepadButton.
  1113. * \returns a string for the given button, or NULL if an invalid button is
  1114. * specified. The string returned is of the format used by
  1115. * SDL_Gamepad mapping strings.
  1116. *
  1117. * \since This function is available since SDL 3.0.0.
  1118. *
  1119. * \sa SDL_GetGamepadButtonFromString
  1120. */
  1121. extern SDL_DECLSPEC const char * SDLCALL SDL_GetGamepadStringForButton(SDL_GamepadButton button);
  1122. /**
  1123. * Query whether a gamepad has a given button.
  1124. *
  1125. * This merely reports whether the gamepad's mapping defined this button, as
  1126. * that is all the information SDL has about the physical device.
  1127. *
  1128. * \param gamepad a gamepad.
  1129. * \param button a button enum value (an SDL_GamepadButton value).
  1130. * \returns SDL_TRUE if the gamepad has this button, SDL_FALSE otherwise.
  1131. *
  1132. * \since This function is available since SDL 3.0.0.
  1133. *
  1134. * \sa SDL_GamepadHasAxis
  1135. */
  1136. extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GamepadHasButton(SDL_Gamepad *gamepad, SDL_GamepadButton button);
  1137. /**
  1138. * Get the current state of a button on a gamepad.
  1139. *
  1140. * \param gamepad a gamepad.
  1141. * \param button a button index (one of the SDL_GamepadButton values).
  1142. * \returns 1 for pressed state or 0 for not pressed state or failure; call
  1143. * SDL_GetError() for more information.
  1144. *
  1145. * \since This function is available since SDL 3.0.0.
  1146. *
  1147. * \sa SDL_GamepadHasButton
  1148. * \sa SDL_GetGamepadAxis
  1149. */
  1150. extern SDL_DECLSPEC Uint8 SDLCALL SDL_GetGamepadButton(SDL_Gamepad *gamepad, SDL_GamepadButton button);
  1151. /**
  1152. * Get the label of a button on a gamepad.
  1153. *
  1154. * \param type the type of gamepad to check.
  1155. * \param button a button index (one of the SDL_GamepadButton values).
  1156. * \returns the SDL_GamepadButtonLabel enum corresponding to the button label.
  1157. *
  1158. * \since This function is available since SDL 3.0.0.
  1159. *
  1160. * \sa SDL_GetGamepadButtonLabel
  1161. */
  1162. extern SDL_DECLSPEC SDL_GamepadButtonLabel SDLCALL SDL_GetGamepadButtonLabelForType(SDL_GamepadType type, SDL_GamepadButton button);
  1163. /**
  1164. * Get the label of a button on a gamepad.
  1165. *
  1166. * \param gamepad a gamepad.
  1167. * \param button a button index (one of the SDL_GamepadButton values).
  1168. * \returns the SDL_GamepadButtonLabel enum corresponding to the button label.
  1169. *
  1170. * \since This function is available since SDL 3.0.0.
  1171. *
  1172. * \sa SDL_GetGamepadButtonLabelForType
  1173. */
  1174. extern SDL_DECLSPEC SDL_GamepadButtonLabel SDLCALL SDL_GetGamepadButtonLabel(SDL_Gamepad *gamepad, SDL_GamepadButton button);
  1175. /**
  1176. * Get the number of touchpads on a gamepad.
  1177. *
  1178. * \param gamepad a gamepad.
  1179. * \returns number of touchpads.
  1180. *
  1181. * \since This function is available since SDL 3.0.0.
  1182. *
  1183. * \sa SDL_GetNumGamepadTouchpadFingers
  1184. */
  1185. extern SDL_DECLSPEC int SDLCALL SDL_GetNumGamepadTouchpads(SDL_Gamepad *gamepad);
  1186. /**
  1187. * Get the number of supported simultaneous fingers on a touchpad on a game
  1188. * gamepad.
  1189. *
  1190. * \param gamepad a gamepad.
  1191. * \param touchpad a touchpad.
  1192. * \returns number of supported simultaneous fingers.
  1193. *
  1194. * \since This function is available since SDL 3.0.0.
  1195. *
  1196. * \sa SDL_GetGamepadTouchpadFinger
  1197. * \sa SDL_GetNumGamepadTouchpads
  1198. */
  1199. extern SDL_DECLSPEC int SDLCALL SDL_GetNumGamepadTouchpadFingers(SDL_Gamepad *gamepad, int touchpad);
  1200. /**
  1201. * Get the current state of a finger on a touchpad on a gamepad.
  1202. *
  1203. * \param gamepad a gamepad.
  1204. * \param touchpad a touchpad.
  1205. * \param finger a finger.
  1206. * \param state filled with state.
  1207. * \param x filled with x position, normalized 0 to 1, with the origin in the
  1208. * upper left.
  1209. * \param y filled with y position, normalized 0 to 1, with the origin in the
  1210. * upper left.
  1211. * \param pressure filled with pressure value.
  1212. * \returns 0 on success or a negative error code on failure; call
  1213. * SDL_GetError() for more information.
  1214. *
  1215. * \since This function is available since SDL 3.0.0.
  1216. *
  1217. * \sa SDL_GetNumGamepadTouchpadFingers
  1218. */
  1219. extern SDL_DECLSPEC int SDLCALL SDL_GetGamepadTouchpadFinger(SDL_Gamepad *gamepad, int touchpad, int finger, Uint8 *state, float *x, float *y, float *pressure);
  1220. /**
  1221. * Return whether a gamepad has a particular sensor.
  1222. *
  1223. * \param gamepad the gamepad to query.
  1224. * \param type the type of sensor to query.
  1225. * \returns SDL_TRUE if the sensor exists, SDL_FALSE otherwise.
  1226. *
  1227. * \since This function is available since SDL 3.0.0.
  1228. *
  1229. * \sa SDL_GetGamepadSensorData
  1230. * \sa SDL_GetGamepadSensorDataRate
  1231. * \sa SDL_SetGamepadSensorEnabled
  1232. */
  1233. extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GamepadHasSensor(SDL_Gamepad *gamepad, SDL_SensorType type);
  1234. /**
  1235. * Set whether data reporting for a gamepad sensor is enabled.
  1236. *
  1237. * \param gamepad the gamepad to update.
  1238. * \param type the type of sensor to enable/disable.
  1239. * \param enabled whether data reporting should be enabled.
  1240. * \returns 0 on success or a negative error code on failure; call
  1241. * SDL_GetError() for more information.
  1242. *
  1243. * \since This function is available since SDL 3.0.0.
  1244. *
  1245. * \sa SDL_GamepadHasSensor
  1246. * \sa SDL_GamepadSensorEnabled
  1247. */
  1248. extern SDL_DECLSPEC int SDLCALL SDL_SetGamepadSensorEnabled(SDL_Gamepad *gamepad, SDL_SensorType type, SDL_bool enabled);
  1249. /**
  1250. * Query whether sensor data reporting is enabled for a gamepad.
  1251. *
  1252. * \param gamepad the gamepad to query.
  1253. * \param type the type of sensor to query.
  1254. * \returns SDL_TRUE if the sensor is enabled, SDL_FALSE otherwise.
  1255. *
  1256. * \since This function is available since SDL 3.0.0.
  1257. *
  1258. * \sa SDL_SetGamepadSensorEnabled
  1259. */
  1260. extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GamepadSensorEnabled(SDL_Gamepad *gamepad, SDL_SensorType type);
  1261. /**
  1262. * Get the data rate (number of events per second) of a gamepad sensor.
  1263. *
  1264. * \param gamepad the gamepad to query.
  1265. * \param type the type of sensor to query.
  1266. * \returns the data rate, or 0.0f if the data rate is not available.
  1267. *
  1268. * \since This function is available since SDL 3.0.0.
  1269. */
  1270. extern SDL_DECLSPEC float SDLCALL SDL_GetGamepadSensorDataRate(SDL_Gamepad *gamepad, SDL_SensorType type);
  1271. /**
  1272. * Get the current state of a gamepad sensor.
  1273. *
  1274. * The number of values and interpretation of the data is sensor dependent.
  1275. * See SDL_sensor.h for the details for each type of sensor.
  1276. *
  1277. * \param gamepad the gamepad to query.
  1278. * \param type the type of sensor to query.
  1279. * \param data a pointer filled with the current sensor state.
  1280. * \param num_values the number of values to write to data.
  1281. * \returns 0 on success or a negative error code on failure; call
  1282. * SDL_GetError() for more information.
  1283. *
  1284. * \since This function is available since SDL 3.0.0.
  1285. */
  1286. extern SDL_DECLSPEC int SDLCALL SDL_GetGamepadSensorData(SDL_Gamepad *gamepad, SDL_SensorType type, float *data, int num_values);
  1287. /**
  1288. * Start a rumble effect on a gamepad.
  1289. *
  1290. * Each call to this function cancels any previous rumble effect, and calling
  1291. * it with 0 intensity stops any rumbling.
  1292. *
  1293. * This function requires you to process SDL events or call
  1294. * SDL_UpdateJoysticks() to update rumble state.
  1295. *
  1296. * \param gamepad the gamepad to vibrate.
  1297. * \param low_frequency_rumble the intensity of the low frequency (left)
  1298. * rumble motor, from 0 to 0xFFFF.
  1299. * \param high_frequency_rumble the intensity of the high frequency (right)
  1300. * rumble motor, from 0 to 0xFFFF.
  1301. * \param duration_ms the duration of the rumble effect, in milliseconds.
  1302. * \returns 0, or -1 if rumble isn't supported on this gamepad.
  1303. *
  1304. * \since This function is available since SDL 3.0.0.
  1305. */
  1306. extern SDL_DECLSPEC int SDLCALL SDL_RumbleGamepad(SDL_Gamepad *gamepad, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble, Uint32 duration_ms);
  1307. /**
  1308. * Start a rumble effect in the gamepad's triggers.
  1309. *
  1310. * Each call to this function cancels any previous trigger rumble effect, and
  1311. * calling it with 0 intensity stops any rumbling.
  1312. *
  1313. * Note that this is rumbling of the _triggers_ and not the gamepad as a
  1314. * whole. This is currently only supported on Xbox One gamepads. If you want
  1315. * the (more common) whole-gamepad rumble, use SDL_RumbleGamepad() instead.
  1316. *
  1317. * This function requires you to process SDL events or call
  1318. * SDL_UpdateJoysticks() to update rumble state.
  1319. *
  1320. * \param gamepad the gamepad to vibrate.
  1321. * \param left_rumble the intensity of the left trigger rumble motor, from 0
  1322. * to 0xFFFF.
  1323. * \param right_rumble the intensity of the right trigger rumble motor, from 0
  1324. * to 0xFFFF.
  1325. * \param duration_ms the duration of the rumble effect, in milliseconds.
  1326. * \returns 0 on success or a negative error code on failure; call
  1327. * SDL_GetError() for more information.
  1328. *
  1329. * \since This function is available since SDL 3.0.0.
  1330. *
  1331. * \sa SDL_RumbleGamepad
  1332. */
  1333. extern SDL_DECLSPEC int SDLCALL SDL_RumbleGamepadTriggers(SDL_Gamepad *gamepad, Uint16 left_rumble, Uint16 right_rumble, Uint32 duration_ms);
  1334. /**
  1335. * Update a gamepad's LED color.
  1336. *
  1337. * An example of a joystick LED is the light on the back of a PlayStation 4's
  1338. * DualShock 4 controller.
  1339. *
  1340. * For gamepads with a single color LED, the maximum of the RGB values will be
  1341. * used as the LED brightness.
  1342. *
  1343. * \param gamepad the gamepad to update.
  1344. * \param red the intensity of the red LED.
  1345. * \param green the intensity of the green LED.
  1346. * \param blue the intensity of the blue LED.
  1347. * \returns 0 on success or a negative error code on failure; call
  1348. * SDL_GetError() for more information.
  1349. *
  1350. * \since This function is available since SDL 3.0.0.
  1351. */
  1352. extern SDL_DECLSPEC int SDLCALL SDL_SetGamepadLED(SDL_Gamepad *gamepad, Uint8 red, Uint8 green, Uint8 blue);
  1353. /**
  1354. * Send a gamepad specific effect packet.
  1355. *
  1356. * \param gamepad the gamepad to affect.
  1357. * \param data the data to send to the gamepad.
  1358. * \param size the size of the data to send to the gamepad.
  1359. * \returns 0 on success or a negative error code on failure; call
  1360. * SDL_GetError() for more information.
  1361. *
  1362. * \since This function is available since SDL 3.0.0.
  1363. */
  1364. extern SDL_DECLSPEC int SDLCALL SDL_SendGamepadEffect(SDL_Gamepad *gamepad, const void *data, int size);
  1365. /**
  1366. * Close a gamepad previously opened with SDL_OpenGamepad().
  1367. *
  1368. * \param gamepad a gamepad identifier previously returned by
  1369. * SDL_OpenGamepad().
  1370. *
  1371. * \since This function is available since SDL 3.0.0.
  1372. *
  1373. * \sa SDL_OpenGamepad
  1374. */
  1375. extern SDL_DECLSPEC void SDLCALL SDL_CloseGamepad(SDL_Gamepad *gamepad);
  1376. /**
  1377. * Return the sfSymbolsName for a given button on a gamepad on Apple
  1378. * platforms.
  1379. *
  1380. * This returns temporary memory which will be automatically freed later, and
  1381. * can be claimed with SDL_ClaimTemporaryMemory().
  1382. *
  1383. * \param gamepad the gamepad to query.
  1384. * \param button a button on the gamepad.
  1385. * \returns the sfSymbolsName or NULL if the name can't be found.
  1386. *
  1387. * \since This function is available since SDL 3.0.0.
  1388. *
  1389. * \sa SDL_GetGamepadAppleSFSymbolsNameForAxis
  1390. */
  1391. extern SDL_DECLSPEC const char * SDLCALL SDL_GetGamepadAppleSFSymbolsNameForButton(SDL_Gamepad *gamepad, SDL_GamepadButton button);
  1392. /**
  1393. * Return the sfSymbolsName for a given axis on a gamepad on Apple platforms.
  1394. *
  1395. * This returns temporary memory which will be automatically freed later, and
  1396. * can be claimed with SDL_ClaimTemporaryMemory().
  1397. *
  1398. * \param gamepad the gamepad to query.
  1399. * \param axis an axis on the gamepad.
  1400. * \returns the sfSymbolsName or NULL if the name can't be found.
  1401. *
  1402. * \since This function is available since SDL 3.0.0.
  1403. *
  1404. * \sa SDL_GetGamepadAppleSFSymbolsNameForButton
  1405. */
  1406. extern SDL_DECLSPEC const char * SDLCALL SDL_GetGamepadAppleSFSymbolsNameForAxis(SDL_Gamepad *gamepad, SDL_GamepadAxis axis);
  1407. /* Ends C function definitions when using C++ */
  1408. #ifdef __cplusplus
  1409. }
  1410. #endif
  1411. #include <SDL3/SDL_close_code.h>
  1412. #endif /* SDL_gamepad_h_ */