SDL_gamepad.h 53 KB

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