SDL_gamepad.h 51 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469
  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. * \param count a pointer filled in with the number of mappings returned, can
  367. * be NULL.
  368. * \returns an array of the mapping strings, NULL-terminated, or NULL on
  369. * failure; call SDL_GetError() for more information. This is a
  370. * single allocation that should be freed with SDL_free() when it is
  371. * no longer needed.
  372. *
  373. * \since This function is available since SDL 3.0.0.
  374. */
  375. extern SDL_DECLSPEC char ** SDLCALL SDL_GetGamepadMappings(int *count);
  376. /**
  377. * Get the gamepad mapping string for a given GUID.
  378. *
  379. * \param guid a structure containing the GUID for which a mapping is desired.
  380. * \returns a mapping string or NULL on failure; call SDL_GetError() for more
  381. * information. This should be freed with SDL_free() when it is no
  382. * longer needed.
  383. *
  384. * \since This function is available since SDL 3.0.0.
  385. *
  386. * \sa SDL_GetJoystickGUIDForID
  387. * \sa SDL_GetJoystickGUID
  388. */
  389. extern SDL_DECLSPEC char * SDLCALL SDL_GetGamepadMappingForGUID(SDL_GUID guid);
  390. /**
  391. * Get the current mapping of a gamepad.
  392. *
  393. * Details about mappings are discussed with SDL_AddGamepadMapping().
  394. *
  395. * \param gamepad the gamepad you want to get the current mapping for.
  396. * \returns a string that has the gamepad's mapping or NULL if no mapping is
  397. * available; call SDL_GetError() for more information. This should
  398. * be freed with SDL_free() when it is no longer needed.
  399. *
  400. * \since This function is available since SDL 3.0.0.
  401. *
  402. * \sa SDL_AddGamepadMapping
  403. * \sa SDL_GetGamepadMappingForID
  404. * \sa SDL_GetGamepadMappingForGUID
  405. * \sa SDL_SetGamepadMapping
  406. */
  407. extern SDL_DECLSPEC char * SDLCALL SDL_GetGamepadMapping(SDL_Gamepad *gamepad);
  408. /**
  409. * Set the current mapping of a joystick or gamepad.
  410. *
  411. * Details about mappings are discussed with SDL_AddGamepadMapping().
  412. *
  413. * \param instance_id the joystick instance ID.
  414. * \param mapping the mapping to use for this device, or NULL to clear the
  415. * mapping.
  416. * \returns 0 on success or a negative error code on failure; call
  417. * SDL_GetError() for more information.
  418. *
  419. * \since This function is available since SDL 3.0.0.
  420. *
  421. * \sa SDL_AddGamepadMapping
  422. * \sa SDL_GetGamepadMapping
  423. */
  424. extern SDL_DECLSPEC int SDLCALL SDL_SetGamepadMapping(SDL_JoystickID instance_id, const char *mapping);
  425. /**
  426. * Return whether a gamepad is currently connected.
  427. *
  428. * \returns SDL_TRUE if a gamepad is connected, SDL_FALSE otherwise.
  429. *
  430. * \since This function is available since SDL 3.0.0.
  431. *
  432. * \sa SDL_GetGamepads
  433. */
  434. extern SDL_DECLSPEC SDL_bool SDLCALL SDL_HasGamepad(void);
  435. /**
  436. * Get a list of currently connected gamepads.
  437. *
  438. * \param count a pointer filled in with the number of gamepads returned, may
  439. * be NULL.
  440. * \returns a 0 terminated array of joystick instance IDs or NULL on failure;
  441. * call SDL_GetError() for more information. This should be freed
  442. * with SDL_free() when it is no longer needed.
  443. *
  444. * \since This function is available since SDL 3.0.0.
  445. *
  446. * \sa SDL_HasGamepad
  447. * \sa SDL_OpenGamepad
  448. */
  449. extern SDL_DECLSPEC SDL_JoystickID * SDLCALL SDL_GetGamepads(int *count);
  450. /**
  451. * Check if the given joystick is supported by the gamepad interface.
  452. *
  453. * \param instance_id the joystick instance ID.
  454. * \returns SDL_TRUE if the given joystick is supported by the gamepad
  455. * interface, SDL_FALSE if it isn't or it's an invalid index.
  456. *
  457. * \since This function is available since SDL 3.0.0.
  458. *
  459. * \sa SDL_GetJoysticks
  460. * \sa SDL_OpenGamepad
  461. */
  462. extern SDL_DECLSPEC SDL_bool SDLCALL SDL_IsGamepad(SDL_JoystickID instance_id);
  463. /**
  464. * Get the implementation dependent name of a gamepad.
  465. *
  466. * This can be called before any gamepads are opened.
  467. *
  468. * \param instance_id the joystick instance ID.
  469. * \returns the name of the selected gamepad. If no name can be found, this
  470. * function returns NULL; call SDL_GetError() for more information.
  471. *
  472. * \since This function is available since SDL 3.0.0.
  473. *
  474. * \sa SDL_GetGamepadName
  475. * \sa SDL_GetGamepads
  476. */
  477. extern SDL_DECLSPEC const char * SDLCALL SDL_GetGamepadNameForID(SDL_JoystickID instance_id);
  478. /**
  479. * Get the implementation dependent path of a gamepad.
  480. *
  481. * This can be called before any gamepads are opened.
  482. *
  483. * \param instance_id the joystick instance ID.
  484. * \returns the path of the selected gamepad. If no path can be found, this
  485. * function returns NULL; call SDL_GetError() for more information.
  486. *
  487. * \since This function is available since SDL 3.0.0.
  488. *
  489. * \sa SDL_GetGamepadPath
  490. * \sa SDL_GetGamepads
  491. */
  492. extern SDL_DECLSPEC const char * SDLCALL SDL_GetGamepadPathForID(SDL_JoystickID instance_id);
  493. /**
  494. * Get the player index of a gamepad.
  495. *
  496. * This can be called before any gamepads are opened.
  497. *
  498. * \param instance_id the joystick instance ID.
  499. * \returns the player index of a gamepad, or -1 if it's not available.
  500. *
  501. * \since This function is available since SDL 3.0.0.
  502. *
  503. * \sa SDL_GetGamepadPlayerIndex
  504. * \sa SDL_GetGamepads
  505. */
  506. extern SDL_DECLSPEC int SDLCALL SDL_GetGamepadPlayerIndexForID(SDL_JoystickID instance_id);
  507. /**
  508. * Get the implementation-dependent GUID of a gamepad.
  509. *
  510. * This can be called before any gamepads are opened.
  511. *
  512. * \param instance_id the joystick instance ID.
  513. * \returns the GUID of the selected gamepad. If called on an invalid index,
  514. * this function returns a zero GUID.
  515. *
  516. * \since This function is available since SDL 3.0.0.
  517. *
  518. * \sa SDL_GUIDToString
  519. * \sa SDL_GetGamepads
  520. */
  521. extern SDL_DECLSPEC SDL_GUID SDLCALL SDL_GetGamepadGUIDForID(SDL_JoystickID instance_id);
  522. /**
  523. * Get the USB vendor ID of a gamepad, if available.
  524. *
  525. * This can be called before any gamepads are opened. If the vendor ID isn't
  526. * available this function returns 0.
  527. *
  528. * \param instance_id the joystick instance ID.
  529. * \returns the USB vendor ID of the selected gamepad. If called on an invalid
  530. * index, this function returns zero.
  531. *
  532. * \since This function is available since SDL 3.0.0.
  533. *
  534. * \sa SDL_GetGamepadVendor
  535. * \sa SDL_GetGamepads
  536. */
  537. extern SDL_DECLSPEC Uint16 SDLCALL SDL_GetGamepadVendorForID(SDL_JoystickID instance_id);
  538. /**
  539. * Get the USB product ID of a gamepad, if available.
  540. *
  541. * This can be called before any gamepads are opened. If the product ID isn't
  542. * available this function returns 0.
  543. *
  544. * \param instance_id the joystick instance ID.
  545. * \returns the USB product ID of the selected gamepad. If called on an
  546. * invalid index, this function returns zero.
  547. *
  548. * \since This function is available since SDL 3.0.0.
  549. *
  550. * \sa SDL_GetGamepadProduct
  551. * \sa SDL_GetGamepads
  552. */
  553. extern SDL_DECLSPEC Uint16 SDLCALL SDL_GetGamepadProductForID(SDL_JoystickID instance_id);
  554. /**
  555. * Get the product version of a gamepad, if available.
  556. *
  557. * This can be called before any gamepads are opened. If the product version
  558. * isn't available this function returns 0.
  559. *
  560. * \param instance_id the joystick instance ID.
  561. * \returns the product version of the selected gamepad. If called on an
  562. * invalid index, this function returns zero.
  563. *
  564. * \since This function is available since SDL 3.0.0.
  565. *
  566. * \sa SDL_GetGamepadProductVersion
  567. * \sa SDL_GetGamepads
  568. */
  569. extern SDL_DECLSPEC Uint16 SDLCALL SDL_GetGamepadProductVersionForID(SDL_JoystickID instance_id);
  570. /**
  571. * Get the type of a gamepad.
  572. *
  573. * This can be called before any gamepads are opened.
  574. *
  575. * \param instance_id the joystick instance ID.
  576. * \returns the gamepad type.
  577. *
  578. * \since This function is available since SDL 3.0.0.
  579. *
  580. * \sa SDL_GetGamepadType
  581. * \sa SDL_GetGamepads
  582. * \sa SDL_GetRealGamepadTypeForID
  583. */
  584. extern SDL_DECLSPEC SDL_GamepadType SDLCALL SDL_GetGamepadTypeForID(SDL_JoystickID instance_id);
  585. /**
  586. * Get the type of a gamepad, ignoring any mapping override.
  587. *
  588. * This can be called before any gamepads are opened.
  589. *
  590. * \param instance_id the joystick instance ID.
  591. * \returns the gamepad type.
  592. *
  593. * \since This function is available since SDL 3.0.0.
  594. *
  595. * \sa SDL_GetGamepadTypeForID
  596. * \sa SDL_GetGamepads
  597. * \sa SDL_GetRealGamepadType
  598. */
  599. extern SDL_DECLSPEC SDL_GamepadType SDLCALL SDL_GetRealGamepadTypeForID(SDL_JoystickID instance_id);
  600. /**
  601. * Get the mapping of a gamepad.
  602. *
  603. * This can be called before any gamepads are opened.
  604. *
  605. * \param instance_id the joystick instance ID.
  606. * \returns the mapping string. Returns NULL if no mapping is available. This
  607. * should be freed with SDL_free() when it is no longer needed.
  608. *
  609. * \since This function is available since SDL 3.0.0.
  610. *
  611. * \sa SDL_GetGamepads
  612. * \sa SDL_GetGamepadMapping
  613. */
  614. extern SDL_DECLSPEC char * SDLCALL SDL_GetGamepadMappingForID(SDL_JoystickID instance_id);
  615. /**
  616. * Open a gamepad for use.
  617. *
  618. * \param instance_id the joystick instance ID.
  619. * \returns a gamepad identifier or NULL if an error occurred; call
  620. * SDL_GetError() for more information.
  621. *
  622. * \since This function is available since SDL 3.0.0.
  623. *
  624. * \sa SDL_CloseGamepad
  625. * \sa SDL_IsGamepad
  626. */
  627. extern SDL_DECLSPEC SDL_Gamepad * SDLCALL SDL_OpenGamepad(SDL_JoystickID instance_id);
  628. /**
  629. * Get the SDL_Gamepad associated with a joystick instance ID, if it has been
  630. * opened.
  631. *
  632. * \param instance_id the joystick instance ID of the gamepad.
  633. * \returns an SDL_Gamepad on success or NULL on failure or if it hasn't been
  634. * opened yet; call SDL_GetError() for more information.
  635. *
  636. * \since This function is available since SDL 3.0.0.
  637. */
  638. extern SDL_DECLSPEC SDL_Gamepad * SDLCALL SDL_GetGamepadFromID(SDL_JoystickID instance_id);
  639. /**
  640. * Get the SDL_Gamepad associated with a player index.
  641. *
  642. * \param player_index the player index, which different from the instance ID.
  643. * \returns the SDL_Gamepad associated with a player index.
  644. *
  645. * \since This function is available since SDL 3.0.0.
  646. *
  647. * \sa SDL_GetGamepadPlayerIndex
  648. * \sa SDL_SetGamepadPlayerIndex
  649. */
  650. extern SDL_DECLSPEC SDL_Gamepad * SDLCALL SDL_GetGamepadFromPlayerIndex(int player_index);
  651. /**
  652. * Get the properties associated with an opened gamepad.
  653. *
  654. * These properties are shared with the underlying joystick object.
  655. *
  656. * The following read-only properties are provided by SDL:
  657. *
  658. * - `SDL_PROP_GAMEPAD_CAP_MONO_LED_BOOLEAN`: true if this gamepad has an LED
  659. * that has adjustable brightness
  660. * - `SDL_PROP_GAMEPAD_CAP_RGB_LED_BOOLEAN`: true if this gamepad has an LED
  661. * that has adjustable color
  662. * - `SDL_PROP_GAMEPAD_CAP_PLAYER_LED_BOOLEAN`: true if this gamepad has a
  663. * player LED
  664. * - `SDL_PROP_GAMEPAD_CAP_RUMBLE_BOOLEAN`: true if this gamepad has
  665. * left/right rumble
  666. * - `SDL_PROP_GAMEPAD_CAP_TRIGGER_RUMBLE_BOOLEAN`: true if this gamepad has
  667. * simple trigger rumble
  668. *
  669. * \param gamepad a gamepad identifier previously returned by
  670. * SDL_OpenGamepad().
  671. * \returns a valid property ID on success or 0 on failure; call
  672. * SDL_GetError() for more information.
  673. *
  674. * \since This function is available since SDL 3.0.0.
  675. */
  676. extern SDL_DECLSPEC SDL_PropertiesID SDLCALL SDL_GetGamepadProperties(SDL_Gamepad *gamepad);
  677. #define SDL_PROP_GAMEPAD_CAP_MONO_LED_BOOLEAN SDL_PROP_JOYSTICK_CAP_MONO_LED_BOOLEAN
  678. #define SDL_PROP_GAMEPAD_CAP_RGB_LED_BOOLEAN SDL_PROP_JOYSTICK_CAP_RGB_LED_BOOLEAN
  679. #define SDL_PROP_GAMEPAD_CAP_PLAYER_LED_BOOLEAN SDL_PROP_JOYSTICK_CAP_PLAYER_LED_BOOLEAN
  680. #define SDL_PROP_GAMEPAD_CAP_RUMBLE_BOOLEAN SDL_PROP_JOYSTICK_CAP_RUMBLE_BOOLEAN
  681. #define SDL_PROP_GAMEPAD_CAP_TRIGGER_RUMBLE_BOOLEAN SDL_PROP_JOYSTICK_CAP_TRIGGER_RUMBLE_BOOLEAN
  682. /**
  683. * Get the instance ID of an opened gamepad.
  684. *
  685. * \param gamepad a gamepad identifier previously returned by
  686. * SDL_OpenGamepad().
  687. * \returns the instance ID of the specified gamepad on success or 0 on
  688. * failure; call SDL_GetError() for more information.
  689. *
  690. * \since This function is available since SDL 3.0.0.
  691. */
  692. extern SDL_DECLSPEC SDL_JoystickID SDLCALL SDL_GetGamepadID(SDL_Gamepad *gamepad);
  693. /**
  694. * Get the implementation-dependent name for an opened gamepad.
  695. *
  696. * \param gamepad a gamepad identifier previously returned by
  697. * SDL_OpenGamepad().
  698. * \returns the implementation dependent name for the gamepad, or NULL if
  699. * there is no name or the identifier passed is invalid.
  700. *
  701. * \since This function is available since SDL 3.0.0.
  702. *
  703. * \sa SDL_GetGamepadNameForID
  704. */
  705. extern SDL_DECLSPEC const char * SDLCALL SDL_GetGamepadName(SDL_Gamepad *gamepad);
  706. /**
  707. * Get the implementation-dependent path for an opened gamepad.
  708. *
  709. * \param gamepad a gamepad identifier previously returned by
  710. * SDL_OpenGamepad().
  711. * \returns the implementation dependent path for the gamepad, or NULL if
  712. * there is no path or the identifier passed is invalid.
  713. *
  714. * \since This function is available since SDL 3.0.0.
  715. *
  716. * \sa SDL_GetGamepadPathForID
  717. */
  718. extern SDL_DECLSPEC const char * SDLCALL SDL_GetGamepadPath(SDL_Gamepad *gamepad);
  719. /**
  720. * Get the type of an opened gamepad.
  721. *
  722. * \param gamepad the gamepad object to query.
  723. * \returns the gamepad type, or SDL_GAMEPAD_TYPE_UNKNOWN if it's not
  724. * available.
  725. *
  726. * \since This function is available since SDL 3.0.0.
  727. *
  728. * \sa SDL_GetGamepadTypeForID
  729. */
  730. extern SDL_DECLSPEC SDL_GamepadType SDLCALL SDL_GetGamepadType(SDL_Gamepad *gamepad);
  731. /**
  732. * Get the type of an opened gamepad, ignoring any mapping override.
  733. *
  734. * \param gamepad the gamepad object to query.
  735. * \returns the gamepad type, or SDL_GAMEPAD_TYPE_UNKNOWN if it's not
  736. * available.
  737. *
  738. * \since This function is available since SDL 3.0.0.
  739. *
  740. * \sa SDL_GetRealGamepadTypeForID
  741. */
  742. extern SDL_DECLSPEC SDL_GamepadType SDLCALL SDL_GetRealGamepadType(SDL_Gamepad *gamepad);
  743. /**
  744. * Get the player index of an opened gamepad.
  745. *
  746. * For XInput gamepads this returns the XInput user index.
  747. *
  748. * \param gamepad the gamepad object to query.
  749. * \returns the player index for gamepad, or -1 if it's not available.
  750. *
  751. * \since This function is available since SDL 3.0.0.
  752. *
  753. * \sa SDL_SetGamepadPlayerIndex
  754. */
  755. extern SDL_DECLSPEC int SDLCALL SDL_GetGamepadPlayerIndex(SDL_Gamepad *gamepad);
  756. /**
  757. * Set the player index of an opened gamepad.
  758. *
  759. * \param gamepad the gamepad object to adjust.
  760. * \param player_index player index to assign to this gamepad, or -1 to clear
  761. * the player index and turn off player LEDs.
  762. * \returns 0 on success or a negative error code on failure; call
  763. * SDL_GetError() for more information.
  764. *
  765. * \since This function is available since SDL 3.0.0.
  766. *
  767. * \sa SDL_GetGamepadPlayerIndex
  768. */
  769. extern SDL_DECLSPEC int SDLCALL SDL_SetGamepadPlayerIndex(SDL_Gamepad *gamepad, int player_index);
  770. /**
  771. * Get the USB vendor ID of an opened gamepad, if available.
  772. *
  773. * If the vendor ID isn't available this function returns 0.
  774. *
  775. * \param gamepad the gamepad object to query.
  776. * \returns the USB vendor ID, or zero if unavailable.
  777. *
  778. * \since This function is available since SDL 3.0.0.
  779. *
  780. * \sa SDL_GetGamepadVendorForID
  781. */
  782. extern SDL_DECLSPEC Uint16 SDLCALL SDL_GetGamepadVendor(SDL_Gamepad *gamepad);
  783. /**
  784. * Get the USB product ID of an opened gamepad, if available.
  785. *
  786. * If the product ID isn't available this function returns 0.
  787. *
  788. * \param gamepad the gamepad object to query.
  789. * \returns the USB product ID, or zero if unavailable.
  790. *
  791. * \since This function is available since SDL 3.0.0.
  792. *
  793. * \sa SDL_GetGamepadProductForID
  794. */
  795. extern SDL_DECLSPEC Uint16 SDLCALL SDL_GetGamepadProduct(SDL_Gamepad *gamepad);
  796. /**
  797. * Get the product version of an opened gamepad, if available.
  798. *
  799. * If the product version isn't available this function returns 0.
  800. *
  801. * \param gamepad the gamepad object to query.
  802. * \returns the USB product version, or zero if unavailable.
  803. *
  804. * \since This function is available since SDL 3.0.0.
  805. *
  806. * \sa SDL_GetGamepadProductVersionForID
  807. */
  808. extern SDL_DECLSPEC Uint16 SDLCALL SDL_GetGamepadProductVersion(SDL_Gamepad *gamepad);
  809. /**
  810. * Get the firmware version of an opened gamepad, if available.
  811. *
  812. * If the firmware version isn't available this function returns 0.
  813. *
  814. * \param gamepad the gamepad object to query.
  815. * \returns the gamepad firmware version, or zero if unavailable.
  816. *
  817. * \since This function is available since SDL 3.0.0.
  818. */
  819. extern SDL_DECLSPEC Uint16 SDLCALL SDL_GetGamepadFirmwareVersion(SDL_Gamepad *gamepad);
  820. /**
  821. * Get the serial number of an opened gamepad, if available.
  822. *
  823. * Returns the serial number of the gamepad, or NULL if it is not available.
  824. *
  825. * \param gamepad the gamepad object to query.
  826. * \returns the serial number, or NULL if unavailable.
  827. *
  828. * \since This function is available since SDL 3.0.0.
  829. */
  830. extern SDL_DECLSPEC const char * SDLCALL SDL_GetGamepadSerial(SDL_Gamepad *gamepad);
  831. /**
  832. * Get the Steam Input handle of an opened gamepad, if available.
  833. *
  834. * Returns an InputHandle_t for the gamepad that can be used with Steam Input
  835. * API: https://partner.steamgames.com/doc/api/ISteamInput
  836. *
  837. * \param gamepad the gamepad object to query.
  838. * \returns the gamepad handle, or 0 if unavailable.
  839. *
  840. * \since This function is available since SDL 3.0.0.
  841. */
  842. extern SDL_DECLSPEC Uint64 SDLCALL SDL_GetGamepadSteamHandle(SDL_Gamepad *gamepad);
  843. /**
  844. * Get the connection state of a gamepad.
  845. *
  846. * \param gamepad the gamepad object to query.
  847. * \returns the connection state on success or
  848. * `SDL_JOYSTICK_CONNECTION_INVALID` on failure; call SDL_GetError()
  849. * for more information.
  850. *
  851. * \since This function is available since SDL 3.0.0.
  852. */
  853. extern SDL_DECLSPEC SDL_JoystickConnectionState SDLCALL SDL_GetGamepadConnectionState(SDL_Gamepad *gamepad);
  854. /**
  855. * Get the battery state of a gamepad.
  856. *
  857. * You should never take a battery status as absolute truth. Batteries
  858. * (especially failing batteries) are delicate hardware, and the values
  859. * reported here are best estimates based on what that hardware reports. It's
  860. * not uncommon for older batteries to lose stored power much faster than it
  861. * reports, or completely drain when reporting it has 20 percent left, etc.
  862. *
  863. * \param gamepad the gamepad object to query.
  864. * \param percent a pointer filled in with the percentage of battery life
  865. * left, between 0 and 100, or NULL to ignore. This will be
  866. * filled in with -1 we can't determine a value or there is no
  867. * battery.
  868. * \returns the current battery state.
  869. *
  870. * \since This function is available since SDL 3.0.0.
  871. */
  872. extern SDL_DECLSPEC SDL_PowerState SDLCALL SDL_GetGamepadPowerInfo(SDL_Gamepad *gamepad, int *percent);
  873. /**
  874. * Check if a gamepad has been opened and is currently connected.
  875. *
  876. * \param gamepad a gamepad identifier previously returned by
  877. * SDL_OpenGamepad().
  878. * \returns SDL_TRUE if the gamepad has been opened and is currently
  879. * connected, or SDL_FALSE if not.
  880. *
  881. * \since This function is available since SDL 3.0.0.
  882. */
  883. extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GamepadConnected(SDL_Gamepad *gamepad);
  884. /**
  885. * Get the underlying joystick from a gamepad.
  886. *
  887. * This function will give you a SDL_Joystick object, which allows you to use
  888. * the SDL_Joystick functions with a SDL_Gamepad object. This would be useful
  889. * for getting a joystick's position at any given time, even if it hasn't
  890. * moved (moving it would produce an event, which would have the axis' value).
  891. *
  892. * The pointer returned is owned by the SDL_Gamepad. You should not call
  893. * SDL_CloseJoystick() on it, for example, since doing so will likely cause
  894. * SDL to crash.
  895. *
  896. * \param gamepad the gamepad object that you want to get a joystick from.
  897. * \returns an SDL_Joystick object, or NULL on failure; call SDL_GetError()
  898. * for more information.
  899. *
  900. * \since This function is available since SDL 3.0.0.
  901. */
  902. extern SDL_DECLSPEC SDL_Joystick * SDLCALL SDL_GetGamepadJoystick(SDL_Gamepad *gamepad);
  903. /**
  904. * Set the state of gamepad event processing.
  905. *
  906. * If gamepad events are disabled, you must call SDL_UpdateGamepads() yourself
  907. * and check the state of the gamepad when you want gamepad information.
  908. *
  909. * \param enabled whether to process gamepad events or not.
  910. *
  911. * \since This function is available since SDL 3.0.0.
  912. *
  913. * \sa SDL_GamepadEventsEnabled
  914. * \sa SDL_UpdateGamepads
  915. */
  916. extern SDL_DECLSPEC void SDLCALL SDL_SetGamepadEventsEnabled(SDL_bool enabled);
  917. /**
  918. * Query the state of gamepad event processing.
  919. *
  920. * If gamepad events are disabled, you must call SDL_UpdateGamepads() yourself
  921. * and check the state of the gamepad when you want gamepad information.
  922. *
  923. * \returns SDL_TRUE if gamepad events are being processed, SDL_FALSE
  924. * otherwise.
  925. *
  926. * \since This function is available since SDL 3.0.0.
  927. *
  928. * \sa SDL_SetGamepadEventsEnabled
  929. */
  930. extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GamepadEventsEnabled(void);
  931. /**
  932. * Get the SDL joystick layer bindings for a gamepad.
  933. *
  934. * \param gamepad a gamepad.
  935. * \param count a pointer filled in with the number of bindings returned.
  936. * \returns a NULL terminated array of pointers to bindings or NULL on
  937. * failure; call SDL_GetError() for more information. This is a
  938. * single allocation that should be freed with SDL_free() when it is
  939. * no longer needed.
  940. *
  941. * \since This function is available since SDL 3.0.0.
  942. */
  943. extern SDL_DECLSPEC SDL_GamepadBinding ** SDLCALL SDL_GetGamepadBindings(SDL_Gamepad *gamepad, int *count);
  944. /**
  945. * Manually pump gamepad updates if not using the loop.
  946. *
  947. * This function is called automatically by the event loop if events are
  948. * enabled. Under such circumstances, it will not be necessary to call this
  949. * function.
  950. *
  951. * \since This function is available since SDL 3.0.0.
  952. */
  953. extern SDL_DECLSPEC void SDLCALL SDL_UpdateGamepads(void);
  954. /**
  955. * Convert a string into SDL_GamepadType enum.
  956. *
  957. * This function is called internally to translate SDL_Gamepad mapping strings
  958. * for the underlying joystick device into the consistent SDL_Gamepad mapping.
  959. * You do not normally need to call this function unless you are parsing
  960. * SDL_Gamepad mappings in your own code.
  961. *
  962. * \param str string representing a SDL_GamepadType type.
  963. * \returns the SDL_GamepadType enum corresponding to the input string, or
  964. * `SDL_GAMEPAD_TYPE_UNKNOWN` if no match was found.
  965. *
  966. * \since This function is available since SDL 3.0.0.
  967. *
  968. * \sa SDL_GetGamepadStringForType
  969. */
  970. extern SDL_DECLSPEC SDL_GamepadType SDLCALL SDL_GetGamepadTypeFromString(const char *str);
  971. /**
  972. * Convert from an SDL_GamepadType enum to a string.
  973. *
  974. * \param type an enum value for a given SDL_GamepadType.
  975. * \returns a string for the given type, or NULL if an invalid type is
  976. * specified. The string returned is of the format used by
  977. * SDL_Gamepad mapping strings.
  978. *
  979. * \since This function is available since SDL 3.0.0.
  980. *
  981. * \sa SDL_GetGamepadTypeFromString
  982. */
  983. extern SDL_DECLSPEC const char * SDLCALL SDL_GetGamepadStringForType(SDL_GamepadType type);
  984. /**
  985. * Convert a string into SDL_GamepadAxis enum.
  986. *
  987. * This function is called internally to translate SDL_Gamepad mapping strings
  988. * for the underlying joystick device into the consistent SDL_Gamepad mapping.
  989. * You do not normally need to call this function unless you are parsing
  990. * SDL_Gamepad mappings in your own code.
  991. *
  992. * Note specially that "righttrigger" and "lefttrigger" map to
  993. * `SDL_GAMEPAD_AXIS_RIGHT_TRIGGER` and `SDL_GAMEPAD_AXIS_LEFT_TRIGGER`,
  994. * respectively.
  995. *
  996. * \param str string representing a SDL_Gamepad axis.
  997. * \returns the SDL_GamepadAxis enum corresponding to the input string, or
  998. * `SDL_GAMEPAD_AXIS_INVALID` if no match was found.
  999. *
  1000. * \since This function is available since SDL 3.0.0.
  1001. *
  1002. * \sa SDL_GetGamepadStringForAxis
  1003. */
  1004. extern SDL_DECLSPEC SDL_GamepadAxis SDLCALL SDL_GetGamepadAxisFromString(const char *str);
  1005. /**
  1006. * Convert from an SDL_GamepadAxis enum to a string.
  1007. *
  1008. * \param axis an enum value for a given SDL_GamepadAxis.
  1009. * \returns a string for the given axis, or NULL if an invalid axis is
  1010. * specified. The string returned is of the format used by
  1011. * SDL_Gamepad mapping strings.
  1012. *
  1013. * \since This function is available since SDL 3.0.0.
  1014. *
  1015. * \sa SDL_GetGamepadAxisFromString
  1016. */
  1017. extern SDL_DECLSPEC const char * SDLCALL SDL_GetGamepadStringForAxis(SDL_GamepadAxis axis);
  1018. /**
  1019. * Query whether a gamepad has a given axis.
  1020. *
  1021. * This merely reports whether the gamepad's mapping defined this axis, as
  1022. * that is all the information SDL has about the physical device.
  1023. *
  1024. * \param gamepad a gamepad.
  1025. * \param axis an axis enum value (an SDL_GamepadAxis value).
  1026. * \returns SDL_TRUE if the gamepad has this axis, SDL_FALSE otherwise.
  1027. *
  1028. * \since This function is available since SDL 3.0.0.
  1029. *
  1030. * \sa SDL_GamepadHasButton
  1031. * \sa SDL_GetGamepadAxis
  1032. */
  1033. extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GamepadHasAxis(SDL_Gamepad *gamepad, SDL_GamepadAxis axis);
  1034. /**
  1035. * Get the current state of an axis control on a gamepad.
  1036. *
  1037. * The axis indices start at index 0.
  1038. *
  1039. * For thumbsticks, the state is a value ranging from -32768 (up/left) to
  1040. * 32767 (down/right).
  1041. *
  1042. * Triggers range from 0 when released to 32767 when fully pressed, and never
  1043. * return a negative value. Note that this differs from the value reported by
  1044. * the lower-level SDL_GetJoystickAxis(), which normally uses the full range.
  1045. *
  1046. * \param gamepad a gamepad.
  1047. * \param axis an axis index (one of the SDL_GamepadAxis values).
  1048. * \returns axis state (including 0) on success or 0 (also) on failure; call
  1049. * SDL_GetError() for more information.
  1050. *
  1051. * \since This function is available since SDL 3.0.0.
  1052. *
  1053. * \sa SDL_GamepadHasAxis
  1054. * \sa SDL_GetGamepadButton
  1055. */
  1056. extern SDL_DECLSPEC Sint16 SDLCALL SDL_GetGamepadAxis(SDL_Gamepad *gamepad, SDL_GamepadAxis axis);
  1057. /**
  1058. * Convert a string into an SDL_GamepadButton enum.
  1059. *
  1060. * This function is called internally to translate SDL_Gamepad mapping strings
  1061. * for the underlying joystick device into the consistent SDL_Gamepad mapping.
  1062. * You do not normally need to call this function unless you are parsing
  1063. * SDL_Gamepad mappings in your own code.
  1064. *
  1065. * \param str string representing a SDL_Gamepad axis.
  1066. * \returns the SDL_GamepadButton enum corresponding to the input string, or
  1067. * `SDL_GAMEPAD_BUTTON_INVALID` if no match was found.
  1068. *
  1069. * \since This function is available since SDL 3.0.0.
  1070. *
  1071. * \sa SDL_GetGamepadStringForButton
  1072. */
  1073. extern SDL_DECLSPEC SDL_GamepadButton SDLCALL SDL_GetGamepadButtonFromString(const char *str);
  1074. /**
  1075. * Convert from an SDL_GamepadButton enum to a string.
  1076. *
  1077. * \param button an enum value for a given SDL_GamepadButton.
  1078. * \returns a string for the given button, or NULL if an invalid button is
  1079. * specified. The string returned is of the format used by
  1080. * SDL_Gamepad mapping strings.
  1081. *
  1082. * \since This function is available since SDL 3.0.0.
  1083. *
  1084. * \sa SDL_GetGamepadButtonFromString
  1085. */
  1086. extern SDL_DECLSPEC const char * SDLCALL SDL_GetGamepadStringForButton(SDL_GamepadButton button);
  1087. /**
  1088. * Query whether a gamepad has a given button.
  1089. *
  1090. * This merely reports whether the gamepad's mapping defined this button, as
  1091. * that is all the information SDL has about the physical device.
  1092. *
  1093. * \param gamepad a gamepad.
  1094. * \param button a button enum value (an SDL_GamepadButton value).
  1095. * \returns SDL_TRUE if the gamepad has this button, SDL_FALSE otherwise.
  1096. *
  1097. * \since This function is available since SDL 3.0.0.
  1098. *
  1099. * \sa SDL_GamepadHasAxis
  1100. */
  1101. extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GamepadHasButton(SDL_Gamepad *gamepad, SDL_GamepadButton button);
  1102. /**
  1103. * Get the current state of a button on a gamepad.
  1104. *
  1105. * \param gamepad a gamepad.
  1106. * \param button a button index (one of the SDL_GamepadButton values).
  1107. * \returns 1 for pressed state or 0 for not pressed state or failure; call
  1108. * SDL_GetError() for more information.
  1109. *
  1110. * \since This function is available since SDL 3.0.0.
  1111. *
  1112. * \sa SDL_GamepadHasButton
  1113. * \sa SDL_GetGamepadAxis
  1114. */
  1115. extern SDL_DECLSPEC Uint8 SDLCALL SDL_GetGamepadButton(SDL_Gamepad *gamepad, SDL_GamepadButton button);
  1116. /**
  1117. * Get the label of a button on a gamepad.
  1118. *
  1119. * \param type the type of gamepad to check.
  1120. * \param button a button index (one of the SDL_GamepadButton values).
  1121. * \returns the SDL_GamepadButtonLabel enum corresponding to the button label.
  1122. *
  1123. * \since This function is available since SDL 3.0.0.
  1124. *
  1125. * \sa SDL_GetGamepadButtonLabel
  1126. */
  1127. extern SDL_DECLSPEC SDL_GamepadButtonLabel SDLCALL SDL_GetGamepadButtonLabelForType(SDL_GamepadType type, SDL_GamepadButton button);
  1128. /**
  1129. * Get the label of a button on a gamepad.
  1130. *
  1131. * \param gamepad a gamepad.
  1132. * \param button a button index (one of the SDL_GamepadButton values).
  1133. * \returns the SDL_GamepadButtonLabel enum corresponding to the button label.
  1134. *
  1135. * \since This function is available since SDL 3.0.0.
  1136. *
  1137. * \sa SDL_GetGamepadButtonLabelForType
  1138. */
  1139. extern SDL_DECLSPEC SDL_GamepadButtonLabel SDLCALL SDL_GetGamepadButtonLabel(SDL_Gamepad *gamepad, SDL_GamepadButton button);
  1140. /**
  1141. * Get the number of touchpads on a gamepad.
  1142. *
  1143. * \param gamepad a gamepad.
  1144. * \returns number of touchpads.
  1145. *
  1146. * \since This function is available since SDL 3.0.0.
  1147. *
  1148. * \sa SDL_GetNumGamepadTouchpadFingers
  1149. */
  1150. extern SDL_DECLSPEC int SDLCALL SDL_GetNumGamepadTouchpads(SDL_Gamepad *gamepad);
  1151. /**
  1152. * Get the number of supported simultaneous fingers on a touchpad on a game
  1153. * gamepad.
  1154. *
  1155. * \param gamepad a gamepad.
  1156. * \param touchpad a touchpad.
  1157. * \returns number of supported simultaneous fingers.
  1158. *
  1159. * \since This function is available since SDL 3.0.0.
  1160. *
  1161. * \sa SDL_GetGamepadTouchpadFinger
  1162. * \sa SDL_GetNumGamepadTouchpads
  1163. */
  1164. extern SDL_DECLSPEC int SDLCALL SDL_GetNumGamepadTouchpadFingers(SDL_Gamepad *gamepad, int touchpad);
  1165. /**
  1166. * Get the current state of a finger on a touchpad on a gamepad.
  1167. *
  1168. * \param gamepad a gamepad.
  1169. * \param touchpad a touchpad.
  1170. * \param finger a finger.
  1171. * \param state filled with state.
  1172. * \param x filled with x position, normalized 0 to 1, with the origin in the
  1173. * upper left.
  1174. * \param y filled with y position, normalized 0 to 1, with the origin in the
  1175. * upper left.
  1176. * \param pressure filled with pressure value.
  1177. * \returns 0 on success or a negative error code on failure; call
  1178. * SDL_GetError() for more information.
  1179. *
  1180. * \since This function is available since SDL 3.0.0.
  1181. *
  1182. * \sa SDL_GetNumGamepadTouchpadFingers
  1183. */
  1184. extern SDL_DECLSPEC int SDLCALL SDL_GetGamepadTouchpadFinger(SDL_Gamepad *gamepad, int touchpad, int finger, Uint8 *state, float *x, float *y, float *pressure);
  1185. /**
  1186. * Return whether a gamepad has a particular sensor.
  1187. *
  1188. * \param gamepad the gamepad to query.
  1189. * \param type the type of sensor to query.
  1190. * \returns SDL_TRUE if the sensor exists, SDL_FALSE otherwise.
  1191. *
  1192. * \since This function is available since SDL 3.0.0.
  1193. *
  1194. * \sa SDL_GetGamepadSensorData
  1195. * \sa SDL_GetGamepadSensorDataRate
  1196. * \sa SDL_SetGamepadSensorEnabled
  1197. */
  1198. extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GamepadHasSensor(SDL_Gamepad *gamepad, SDL_SensorType type);
  1199. /**
  1200. * Set whether data reporting for a gamepad sensor is enabled.
  1201. *
  1202. * \param gamepad the gamepad to update.
  1203. * \param type the type of sensor to enable/disable.
  1204. * \param enabled whether data reporting should be enabled.
  1205. * \returns 0 on success or a negative error code on failure; call
  1206. * SDL_GetError() for more information.
  1207. *
  1208. * \since This function is available since SDL 3.0.0.
  1209. *
  1210. * \sa SDL_GamepadHasSensor
  1211. * \sa SDL_GamepadSensorEnabled
  1212. */
  1213. extern SDL_DECLSPEC int SDLCALL SDL_SetGamepadSensorEnabled(SDL_Gamepad *gamepad, SDL_SensorType type, SDL_bool enabled);
  1214. /**
  1215. * Query whether sensor data reporting is enabled for a gamepad.
  1216. *
  1217. * \param gamepad the gamepad to query.
  1218. * \param type the type of sensor to query.
  1219. * \returns SDL_TRUE if the sensor is enabled, SDL_FALSE otherwise.
  1220. *
  1221. * \since This function is available since SDL 3.0.0.
  1222. *
  1223. * \sa SDL_SetGamepadSensorEnabled
  1224. */
  1225. extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GamepadSensorEnabled(SDL_Gamepad *gamepad, SDL_SensorType type);
  1226. /**
  1227. * Get the data rate (number of events per second) of a gamepad sensor.
  1228. *
  1229. * \param gamepad the gamepad to query.
  1230. * \param type the type of sensor to query.
  1231. * \returns the data rate, or 0.0f if the data rate is not available.
  1232. *
  1233. * \since This function is available since SDL 3.0.0.
  1234. */
  1235. extern SDL_DECLSPEC float SDLCALL SDL_GetGamepadSensorDataRate(SDL_Gamepad *gamepad, SDL_SensorType type);
  1236. /**
  1237. * Get the current state of a gamepad sensor.
  1238. *
  1239. * The number of values and interpretation of the data is sensor dependent.
  1240. * See SDL_sensor.h for the details for each type of sensor.
  1241. *
  1242. * \param gamepad the gamepad to query.
  1243. * \param type the type of sensor to query.
  1244. * \param data a pointer filled with the current sensor state.
  1245. * \param num_values the number of values to write to data.
  1246. * \returns 0 on success or a negative error code on failure; call
  1247. * SDL_GetError() for more information.
  1248. *
  1249. * \since This function is available since SDL 3.0.0.
  1250. */
  1251. extern SDL_DECLSPEC int SDLCALL SDL_GetGamepadSensorData(SDL_Gamepad *gamepad, SDL_SensorType type, float *data, int num_values);
  1252. /**
  1253. * Start a rumble effect on a gamepad.
  1254. *
  1255. * Each call to this function cancels any previous rumble effect, and calling
  1256. * it with 0 intensity stops any rumbling.
  1257. *
  1258. * This function requires you to process SDL events or call
  1259. * SDL_UpdateJoysticks() to update rumble state.
  1260. *
  1261. * \param gamepad the gamepad to vibrate.
  1262. * \param low_frequency_rumble the intensity of the low frequency (left)
  1263. * rumble motor, from 0 to 0xFFFF.
  1264. * \param high_frequency_rumble the intensity of the high frequency (right)
  1265. * rumble motor, from 0 to 0xFFFF.
  1266. * \param duration_ms the duration of the rumble effect, in milliseconds.
  1267. * \returns 0, or -1 if rumble isn't supported on this gamepad.
  1268. *
  1269. * \since This function is available since SDL 3.0.0.
  1270. */
  1271. extern SDL_DECLSPEC int SDLCALL SDL_RumbleGamepad(SDL_Gamepad *gamepad, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble, Uint32 duration_ms);
  1272. /**
  1273. * Start a rumble effect in the gamepad's triggers.
  1274. *
  1275. * Each call to this function cancels any previous trigger rumble effect, and
  1276. * calling it with 0 intensity stops any rumbling.
  1277. *
  1278. * Note that this is rumbling of the _triggers_ and not the gamepad as a
  1279. * whole. This is currently only supported on Xbox One gamepads. If you want
  1280. * the (more common) whole-gamepad rumble, use SDL_RumbleGamepad() instead.
  1281. *
  1282. * This function requires you to process SDL events or call
  1283. * SDL_UpdateJoysticks() to update rumble state.
  1284. *
  1285. * \param gamepad the gamepad to vibrate.
  1286. * \param left_rumble the intensity of the left trigger rumble motor, from 0
  1287. * to 0xFFFF.
  1288. * \param right_rumble the intensity of the right trigger rumble motor, from 0
  1289. * to 0xFFFF.
  1290. * \param duration_ms the duration of the rumble effect, in milliseconds.
  1291. * \returns 0 on success or a negative error code on failure; call
  1292. * SDL_GetError() for more information.
  1293. *
  1294. * \since This function is available since SDL 3.0.0.
  1295. *
  1296. * \sa SDL_RumbleGamepad
  1297. */
  1298. extern SDL_DECLSPEC int SDLCALL SDL_RumbleGamepadTriggers(SDL_Gamepad *gamepad, Uint16 left_rumble, Uint16 right_rumble, Uint32 duration_ms);
  1299. /**
  1300. * Update a gamepad's LED color.
  1301. *
  1302. * An example of a joystick LED is the light on the back of a PlayStation 4's
  1303. * DualShock 4 controller.
  1304. *
  1305. * For gamepads with a single color LED, the maximum of the RGB values will be
  1306. * used as the LED brightness.
  1307. *
  1308. * \param gamepad the gamepad to update.
  1309. * \param red the intensity of the red LED.
  1310. * \param green the intensity of the green LED.
  1311. * \param blue the intensity of the blue LED.
  1312. * \returns 0 on success or a negative error code on failure; call
  1313. * SDL_GetError() for more information.
  1314. *
  1315. * \since This function is available since SDL 3.0.0.
  1316. */
  1317. extern SDL_DECLSPEC int SDLCALL SDL_SetGamepadLED(SDL_Gamepad *gamepad, Uint8 red, Uint8 green, Uint8 blue);
  1318. /**
  1319. * Send a gamepad specific effect packet.
  1320. *
  1321. * \param gamepad the gamepad to affect.
  1322. * \param data the data to send to the gamepad.
  1323. * \param size the size of the data to send to the gamepad.
  1324. * \returns 0 on success or a negative error code on failure; call
  1325. * SDL_GetError() for more information.
  1326. *
  1327. * \since This function is available since SDL 3.0.0.
  1328. */
  1329. extern SDL_DECLSPEC int SDLCALL SDL_SendGamepadEffect(SDL_Gamepad *gamepad, const void *data, int size);
  1330. /**
  1331. * Close a gamepad previously opened with SDL_OpenGamepad().
  1332. *
  1333. * \param gamepad a gamepad identifier previously returned by
  1334. * SDL_OpenGamepad().
  1335. *
  1336. * \since This function is available since SDL 3.0.0.
  1337. *
  1338. * \sa SDL_OpenGamepad
  1339. */
  1340. extern SDL_DECLSPEC void SDLCALL SDL_CloseGamepad(SDL_Gamepad *gamepad);
  1341. /**
  1342. * Return the sfSymbolsName for a given button on a gamepad on Apple
  1343. * platforms.
  1344. *
  1345. * \param gamepad the gamepad to query.
  1346. * \param button a button on the gamepad.
  1347. * \returns the sfSymbolsName or NULL if the name can't be found.
  1348. *
  1349. * \since This function is available since SDL 3.0.0.
  1350. *
  1351. * \sa SDL_GetGamepadAppleSFSymbolsNameForAxis
  1352. */
  1353. extern SDL_DECLSPEC const char * SDLCALL SDL_GetGamepadAppleSFSymbolsNameForButton(SDL_Gamepad *gamepad, SDL_GamepadButton button);
  1354. /**
  1355. * Return the sfSymbolsName for a given axis on a gamepad on Apple platforms.
  1356. *
  1357. * \param gamepad the gamepad to query.
  1358. * \param axis an axis on the gamepad.
  1359. * \returns the sfSymbolsName or NULL if the name can't be found.
  1360. *
  1361. * \since This function is available since SDL 3.0.0.
  1362. *
  1363. * \sa SDL_GetGamepadAppleSFSymbolsNameForButton
  1364. */
  1365. extern SDL_DECLSPEC const char * SDLCALL SDL_GetGamepadAppleSFSymbolsNameForAxis(SDL_Gamepad *gamepad, SDL_GamepadAxis axis);
  1366. /* Ends C function definitions when using C++ */
  1367. #ifdef __cplusplus
  1368. }
  1369. #endif
  1370. #include <SDL3/SDL_close_code.h>
  1371. #endif /* SDL_gamepad_h_ */