1/*
2 Simple DirectMedia Layer
3 Copyright (C) 1997-2026 Sam Lantinga <slouken@libsdl.org>
4
5 This software is provided 'as-is', without any express or implied
6 warranty. In no event will the authors be held liable for any damages
7 arising from the use of this software.
8
9 Permission is granted to anyone to use this software for any purpose,
10 including commercial applications, and to alter it and redistribute it
11 freely, subject to the following restrictions:
12
13 1. The origin of this software must not be misrepresented; you must not
14 claim that you wrote the original software. If you use this software
15 in a product, an acknowledgment in the product documentation would be
16 appreciated but is not required.
17 2. Altered source versions must be plainly marked as such, and must not be
18 misrepresented as being the original software.
19 3. This notice may not be removed or altered from any source distribution.
20*/
21
22/* WIKI CATEGORY: GameController */
23
24/**
25 * # CategoryGameController
26 *
27 * Include file for SDL game controller event handling
28 */
29
30#ifndef SDL_gamecontroller_h_
31#define SDL_gamecontroller_h_
32
33#include "SDL_stdinc.h"
34#include "SDL_error.h"
35#include "SDL_rwops.h"
36#include "SDL_sensor.h"
37#include "SDL_joystick.h"
38
39#include "begin_code.h"
40/* Set up for C function definitions, even when using C++ */
41#ifdef __cplusplus
42extern "C" {
43#endif
44
45/**
46 * \file SDL_gamecontroller.h
47 *
48 * In order to use these functions, SDL_Init() must have been called
49 * with the SDL_INIT_GAMECONTROLLER flag. This causes SDL to scan the system
50 * for game controllers, and load appropriate drivers.
51 *
52 * If you would like to receive controller updates while the application
53 * is in the background, you should set the following hint before calling
54 * SDL_Init(): SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS
55 */
56
57/**
58 * The gamecontroller structure used to identify an SDL game controller
59 */
60struct _SDL_GameController;
61typedef struct _SDL_GameController SDL_GameController;
62
63typedef enum SDL_GameControllerType
64{
65 SDL_CONTROLLER_TYPE_UNKNOWN = 0,
66 SDL_CONTROLLER_TYPE_XBOX360,
67 SDL_CONTROLLER_TYPE_XBOXONE,
68 SDL_CONTROLLER_TYPE_PS3,
69 SDL_CONTROLLER_TYPE_PS4,
70 SDL_CONTROLLER_TYPE_NINTENDO_SWITCH_PRO,
71 SDL_CONTROLLER_TYPE_VIRTUAL,
72 SDL_CONTROLLER_TYPE_PS5,
73 SDL_CONTROLLER_TYPE_AMAZON_LUNA,
74 SDL_CONTROLLER_TYPE_GOOGLE_STADIA,
75 SDL_CONTROLLER_TYPE_NVIDIA_SHIELD,
76 SDL_CONTROLLER_TYPE_NINTENDO_SWITCH_JOYCON_LEFT,
77 SDL_CONTROLLER_TYPE_NINTENDO_SWITCH_JOYCON_RIGHT,
78 SDL_CONTROLLER_TYPE_NINTENDO_SWITCH_JOYCON_PAIR,
79 SDL_CONTROLLER_TYPE_MAX
80} SDL_GameControllerType;
81
82/**
83 * Types of game controller control bindings.
84 *
85 * A game controller is a collection of bindings that map arbitrary joystick
86 * buttons, axes and hat switches to specific positions on a generic
87 * console-style gamepad.
88 *
89 * \since This enum is available since SDL 2.0.0.
90 *
91 * \sa SDL_GameControllerButtonBind
92 * \sa SDL_GameControllerGetBindForAxis
93 * \sa SDL_GameControllerGetBindForButton
94 */
95typedef enum SDL_GameControllerBindType
96{
97 SDL_CONTROLLER_BINDTYPE_NONE = 0,
98 SDL_CONTROLLER_BINDTYPE_BUTTON,
99 SDL_CONTROLLER_BINDTYPE_AXIS,
100 SDL_CONTROLLER_BINDTYPE_HAT
101} SDL_GameControllerBindType;
102
103/**
104 * Get the SDL joystick layer binding for this controller button/axis mapping
105 */
106typedef struct SDL_GameControllerButtonBind
107{
108 SDL_GameControllerBindType bindType;
109 union
110 {
111 int button;
112 int axis;
113 struct {
114 int hat;
115 int hat_mask;
116 } hat;
117 } value;
118
119} SDL_GameControllerButtonBind;
120
121
122/**
123 * To count the number of game controllers in the system for the following:
124 *
125 * ```c
126 * int nJoysticks = SDL_NumJoysticks();
127 * int nGameControllers = 0;
128 * for (int i = 0; i < nJoysticks; i++) {
129 * if (SDL_IsGameController(i)) {
130 * nGameControllers++;
131 * }
132 * }
133 * ```
134 *
135 * Using the SDL_HINT_GAMECONTROLLERCONFIG hint or the SDL_GameControllerAddMapping() you can add support for controllers SDL is unaware of or cause an existing controller to have a different binding. The format is:
136 * guid,name,mappings
137 *
138 * Where GUID is the string value from SDL_JoystickGetGUIDString(), name is the human readable string for the device and mappings are controller mappings to joystick ones.
139 * Under Windows there is a reserved GUID of "xinput" that covers any XInput devices.
140 * The mapping format for joystick is:
141 * bX - a joystick button, index X
142 * hX.Y - hat X with value Y
143 * aX - axis X of the joystick
144 * Buttons can be used as a controller axis and vice versa.
145 *
146 * This string shows an example of a valid mapping for a controller
147 *
148 * ```c
149 * "03000000341a00003608000000000000,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",
150 * ```
151 */
152
153/**
154 * Load a set of Game Controller mappings from a seekable SDL data stream.
155 *
156 * You can call this function several times, if needed, to load different
157 * database files.
158 *
159 * If a new mapping is loaded for an already known controller GUID, the later
160 * version will overwrite the one currently loaded.
161 *
162 * If this function is called before SDL_Init, SDL will generate an
163 * SDL_CONTROLLERDEVICEADDED event for matching controllers that are plugged
164 * in at the time that SDL_Init is called.
165 *
166 * Mappings not belonging to the current platform or with no platform field
167 * specified will be ignored (i.e. mappings for Linux will be ignored in
168 * Windows, etc).
169 *
170 * This function will load the text database entirely in memory before
171 * processing it, so take this into consideration if you are in a memory
172 * constrained environment.
173 *
174 * \param rw the data stream for the mappings to be added.
175 * \param freerw non-zero to close the stream after being read.
176 * \returns the number of mappings added or -1 on error; call SDL_GetError()
177 * for more information.
178 *
179 * \since This function is available since SDL 2.0.2.
180 *
181 * \sa SDL_GameControllerAddMapping
182 * \sa SDL_GameControllerAddMappingsFromFile
183 * \sa SDL_GameControllerMappingForGUID
184 * \sa SDL_CONTROLLERDEVICEADDED
185 */
186extern DECLSPEC int SDLCALL SDL_GameControllerAddMappingsFromRW(SDL_RWops * rw, int freerw);
187
188/**
189 * Load a set of mappings from a file, filtered by the current
190 * SDL_GetPlatform()
191 *
192 * Convenience macro.
193 */
194#define SDL_GameControllerAddMappingsFromFile(file) SDL_GameControllerAddMappingsFromRW(SDL_RWFromFile(file, "rb"), 1)
195
196/**
197 * Add support for controllers that SDL is unaware of or to cause an existing
198 * controller to have a different binding.
199 *
200 * The mapping string has the format "GUID,name,mapping", where GUID is the
201 * string value from SDL_JoystickGetGUIDString(), name is the human readable
202 * string for the device and mappings are controller mappings to joystick
203 * ones. Under Windows there is a reserved GUID of "xinput" that covers all
204 * XInput devices. The mapping format for joystick is: {| |bX |a joystick
205 * button, index X |- |hX.Y |hat X with value Y |- |aX |axis X of the joystick
206 * |} Buttons can be used as a controller axes and vice versa.
207 *
208 * This string shows an example of a valid mapping for a controller:
209 *
210 * ```c
211 * "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"
212 * ```
213 *
214 * If this function is called before SDL_Init, SDL will generate an
215 * SDL_CONTROLLERDEVICEADDED event for matching controllers that are plugged
216 * in at the time that SDL_Init is called.
217 *
218 * \param mappingString the mapping string.
219 * \returns 1 if a new mapping is added, 0 if an existing mapping is updated,
220 * -1 on error; call SDL_GetError() for more information.
221 *
222 * \since This function is available since SDL 2.0.0.
223 *
224 * \sa SDL_GameControllerMapping
225 * \sa SDL_GameControllerMappingForGUID
226 * \sa SDL_CONTROLLERDEVICEADDED
227 */
228extern DECLSPEC int SDLCALL SDL_GameControllerAddMapping(const char* mappingString);
229
230/**
231 * Get the number of mappings installed.
232 *
233 * \returns the number of mappings.
234 *
235 * \since This function is available since SDL 2.0.6.
236 */
237extern DECLSPEC int SDLCALL SDL_GameControllerNumMappings(void);
238
239/**
240 * Get the mapping at a particular index.
241 *
242 * \param mapping_index mapping index.
243 * \returns the mapping string. Must be freed with SDL_free(). Returns NULL if
244 * the index is out of range.
245 *
246 * \since This function is available since SDL 2.0.6.
247 */
248extern DECLSPEC char * SDLCALL SDL_GameControllerMappingForIndex(int mapping_index);
249
250/**
251 * Get the game controller mapping string for a given GUID.
252 *
253 * The returned string must be freed with SDL_free().
254 *
255 * \param guid a structure containing the GUID for which a mapping is desired.
256 * \returns a mapping string or NULL on error; call SDL_GetError() for more
257 * information.
258 *
259 * \since This function is available since SDL 2.0.0.
260 *
261 * \sa SDL_JoystickGetDeviceGUID
262 * \sa SDL_JoystickGetGUID
263 */
264extern DECLSPEC char * SDLCALL SDL_GameControllerMappingForGUID(SDL_JoystickGUID guid);
265
266/**
267 * Get the current mapping of a Game Controller.
268 *
269 * The returned string must be freed with SDL_free().
270 *
271 * Details about mappings are discussed with SDL_GameControllerAddMapping().
272 *
273 * \param gamecontroller the game controller you want to get the current
274 * mapping for.
275 * \returns a string that has the controller's mapping or NULL if no mapping
276 * is available; call SDL_GetError() for more information.
277 *
278 * \since This function is available since SDL 2.0.0.
279 *
280 * \sa SDL_GameControllerAddMapping
281 * \sa SDL_GameControllerMappingForGUID
282 */
283extern DECLSPEC char * SDLCALL SDL_GameControllerMapping(SDL_GameController *gamecontroller);
284
285/**
286 * Check if the given joystick is supported by the game controller interface.
287 *
288 * `joystick_index` is the same as the `device_index` passed to
289 * SDL_JoystickOpen().
290 *
291 * \param joystick_index the device_index of a device, up to
292 * SDL_NumJoysticks().
293 * \returns SDL_TRUE if the given joystick is supported by the game controller
294 * interface, SDL_FALSE if it isn't or it's an invalid index.
295 *
296 * \since This function is available since SDL 2.0.0.
297 *
298 * \sa SDL_GameControllerNameForIndex
299 * \sa SDL_GameControllerOpen
300 */
301extern DECLSPEC SDL_bool SDLCALL SDL_IsGameController(int joystick_index);
302
303/**
304 * Get the implementation dependent name for the game controller.
305 *
306 * This function can be called before any controllers are opened.
307 *
308 * `joystick_index` is the same as the `device_index` passed to
309 * SDL_JoystickOpen().
310 *
311 * \param joystick_index the device_index of a device, from zero to
312 * SDL_NumJoysticks()-1.
313 * \returns the implementation-dependent name for the game controller, or NULL
314 * if there is no name or the index is invalid.
315 *
316 * \since This function is available since SDL 2.0.0.
317 *
318 * \sa SDL_GameControllerName
319 * \sa SDL_GameControllerOpen
320 * \sa SDL_IsGameController
321 */
322extern DECLSPEC const char *SDLCALL SDL_GameControllerNameForIndex(int joystick_index);
323
324/**
325 * Get the implementation dependent path for the game controller.
326 *
327 * This function can be called before any controllers are opened.
328 *
329 * `joystick_index` is the same as the `device_index` passed to
330 * SDL_JoystickOpen().
331 *
332 * \param joystick_index the device_index of a device, from zero to
333 * SDL_NumJoysticks()-1.
334 * \returns the implementation-dependent path for the game controller, or NULL
335 * if there is no path or the index is invalid.
336 *
337 * \since This function is available since SDL 2.24.0.
338 *
339 * \sa SDL_GameControllerPath
340 */
341extern DECLSPEC const char *SDLCALL SDL_GameControllerPathForIndex(int joystick_index);
342
343/**
344 * Get the type of a game controller.
345 *
346 * This can be called before any controllers are opened.
347 *
348 * \param joystick_index the device_index of a device, from zero to
349 * SDL_NumJoysticks()-1.
350 * \returns the controller type.
351 *
352 * \since This function is available since SDL 2.0.12.
353 */
354extern DECLSPEC SDL_GameControllerType SDLCALL SDL_GameControllerTypeForIndex(int joystick_index);
355
356/**
357 * Get the mapping of a game controller.
358 *
359 * This can be called before any controllers are opened.
360 *
361 * \param joystick_index the device_index of a device, from zero to
362 * SDL_NumJoysticks()-1.
363 * \returns the mapping string. Must be freed with SDL_free(). Returns NULL if
364 * no mapping is available.
365 *
366 * \since This function is available since SDL 2.0.9.
367 */
368extern DECLSPEC char *SDLCALL SDL_GameControllerMappingForDeviceIndex(int joystick_index);
369
370/**
371 * Open a game controller for use.
372 *
373 * `joystick_index` is the same as the `device_index` passed to
374 * SDL_JoystickOpen().
375 *
376 * The index passed as an argument refers to the N'th game controller on the
377 * system. This index is not the value which will identify this controller in
378 * future controller events. The joystick's instance id (SDL_JoystickID) will
379 * be used there instead.
380 *
381 * \param joystick_index the device_index of a device, up to
382 * SDL_NumJoysticks().
383 * \returns a gamecontroller identifier or NULL if an error occurred; call
384 * SDL_GetError() for more information.
385 *
386 * \since This function is available since SDL 2.0.0.
387 *
388 * \sa SDL_GameControllerClose
389 * \sa SDL_GameControllerNameForIndex
390 * \sa SDL_IsGameController
391 */
392extern DECLSPEC SDL_GameController *SDLCALL SDL_GameControllerOpen(int joystick_index);
393
394/**
395 * Get the SDL_GameController associated with an instance id.
396 *
397 * \param joyid the instance id to get the SDL_GameController for.
398 * \returns an SDL_GameController on success or NULL on failure; call
399 * SDL_GetError() for more information.
400 *
401 * \since This function is available since SDL 2.0.4.
402 */
403extern DECLSPEC SDL_GameController *SDLCALL SDL_GameControllerFromInstanceID(SDL_JoystickID joyid);
404
405/**
406 * Get the SDL_GameController associated with a player index.
407 *
408 * Please note that the player index is _not_ the device index, nor is it the
409 * instance id!
410 *
411 * \param player_index the player index, which is not the device index or the
412 * instance id!
413 * \returns the SDL_GameController associated with a player index.
414 *
415 * \since This function is available since SDL 2.0.12.
416 *
417 * \sa SDL_GameControllerGetPlayerIndex
418 * \sa SDL_GameControllerSetPlayerIndex
419 */
420extern DECLSPEC SDL_GameController *SDLCALL SDL_GameControllerFromPlayerIndex(int player_index);
421
422/**
423 * Get the implementation-dependent name for an opened game controller.
424 *
425 * This is the same name as returned by SDL_GameControllerNameForIndex(), but
426 * it takes a controller identifier instead of the (unstable) device index.
427 *
428 * \param gamecontroller a game controller identifier previously returned by
429 * SDL_GameControllerOpen().
430 * \returns the implementation dependent name for the game controller, or NULL
431 * if there is no name or the identifier passed is invalid.
432 *
433 * \since This function is available since SDL 2.0.0.
434 *
435 * \sa SDL_GameControllerNameForIndex
436 * \sa SDL_GameControllerOpen
437 */
438extern DECLSPEC const char *SDLCALL SDL_GameControllerName(SDL_GameController *gamecontroller);
439
440/**
441 * Get the implementation-dependent path for an opened game controller.
442 *
443 * This is the same path as returned by SDL_GameControllerNameForIndex(), but
444 * it takes a controller identifier instead of the (unstable) device index.
445 *
446 * \param gamecontroller a game controller identifier previously returned by
447 * SDL_GameControllerOpen().
448 * \returns the implementation dependent path for the game controller, or NULL
449 * if there is no path or the identifier passed is invalid.
450 *
451 * \since This function is available since SDL 2.24.0.
452 *
453 * \sa SDL_GameControllerPathForIndex
454 */
455extern DECLSPEC const char *SDLCALL SDL_GameControllerPath(SDL_GameController *gamecontroller);
456
457/**
458 * Get the type of this currently opened controller
459 *
460 * This is the same name as returned by SDL_GameControllerTypeForIndex(), but
461 * it takes a controller identifier instead of the (unstable) device index.
462 *
463 * \param gamecontroller the game controller object to query.
464 * \returns the controller type.
465 *
466 * \since This function is available since SDL 2.0.12.
467 */
468extern DECLSPEC SDL_GameControllerType SDLCALL SDL_GameControllerGetType(SDL_GameController *gamecontroller);
469
470/**
471 * Get the player index of an opened game controller.
472 *
473 * For XInput controllers this returns the XInput user index.
474 *
475 * \param gamecontroller the game controller object to query.
476 * \returns the player index for controller, or -1 if it's not available.
477 *
478 * \since This function is available since SDL 2.0.9.
479 */
480extern DECLSPEC int SDLCALL SDL_GameControllerGetPlayerIndex(SDL_GameController *gamecontroller);
481
482/**
483 * Set the player index of an opened game controller.
484 *
485 * \param gamecontroller the game controller object to adjust.
486 * \param player_index Player index to assign to this controller, or -1 to
487 * clear the player index and turn off player LEDs.
488 *
489 * \since This function is available since SDL 2.0.12.
490 */
491extern DECLSPEC void SDLCALL SDL_GameControllerSetPlayerIndex(SDL_GameController *gamecontroller, int player_index);
492
493/**
494 * Get the USB vendor ID of an opened controller, if available.
495 *
496 * If the vendor ID isn't available this function returns 0.
497 *
498 * \param gamecontroller the game controller object to query.
499 * \return the USB vendor ID, or zero if unavailable.
500 *
501 * \since This function is available since SDL 2.0.6.
502 */
503extern DECLSPEC Uint16 SDLCALL SDL_GameControllerGetVendor(SDL_GameController *gamecontroller);
504
505/**
506 * Get the USB product ID of an opened controller, if available.
507 *
508 * If the product ID isn't available this function returns 0.
509 *
510 * \param gamecontroller the game controller object to query.
511 * \return the USB product ID, or zero if unavailable.
512 *
513 * \since This function is available since SDL 2.0.6.
514 */
515extern DECLSPEC Uint16 SDLCALL SDL_GameControllerGetProduct(SDL_GameController *gamecontroller);
516
517/**
518 * Get the product version of an opened controller, if available.
519 *
520 * If the product version isn't available this function returns 0.
521 *
522 * \param gamecontroller the game controller object to query.
523 * \return the USB product version, or zero if unavailable.
524 *
525 * \since This function is available since SDL 2.0.6.
526 */
527extern DECLSPEC Uint16 SDLCALL SDL_GameControllerGetProductVersion(SDL_GameController *gamecontroller);
528
529/**
530 * Get the firmware version of an opened controller, if available.
531 *
532 * If the firmware version isn't available this function returns 0.
533 *
534 * \param gamecontroller the game controller object to query.
535 * \return the controller firmware version, or zero if unavailable.
536 *
537 * \since This function is available since SDL 2.24.0.
538 */
539extern DECLSPEC Uint16 SDLCALL SDL_GameControllerGetFirmwareVersion(SDL_GameController *gamecontroller);
540
541/**
542 * Get the serial number of an opened controller, if available.
543 *
544 * Returns the serial number of the controller, or NULL if it is not
545 * available.
546 *
547 * \param gamecontroller the game controller object to query.
548 * \return the serial number, or NULL if unavailable.
549 *
550 * \since This function is available since SDL 2.0.14.
551 */
552extern DECLSPEC const char * SDLCALL SDL_GameControllerGetSerial(SDL_GameController *gamecontroller);
553
554/**
555 * Get the Steam Input handle of an opened controller, if available.
556 *
557 * Returns an InputHandle_t for the controller that can be used with Steam
558 * Input API: https://partner.steamgames.com/doc/api/ISteamInput
559 *
560 * \param gamecontroller the game controller object to query.
561 * \returns the gamepad handle, or 0 if unavailable.
562 *
563 * \since This function is available since SDL 2.30.0.
564 */
565extern DECLSPEC Uint64 SDLCALL SDL_GameControllerGetSteamHandle(SDL_GameController *gamecontroller);
566
567
568/**
569 * Check if a controller has been opened and is currently connected.
570 *
571 * \param gamecontroller a game controller identifier previously returned by
572 * SDL_GameControllerOpen().
573 * \returns SDL_TRUE if the controller has been opened and is currently
574 * connected, or SDL_FALSE if not.
575 *
576 * \since This function is available since SDL 2.0.0.
577 *
578 * \sa SDL_GameControllerClose
579 * \sa SDL_GameControllerOpen
580 */
581extern DECLSPEC SDL_bool SDLCALL SDL_GameControllerGetAttached(SDL_GameController *gamecontroller);
582
583/**
584 * Get the Joystick ID from a Game Controller.
585 *
586 * This function will give you a SDL_Joystick object, which allows you to use
587 * the SDL_Joystick functions with a SDL_GameController object. This would be
588 * useful for getting a joystick's position at any given time, even if it
589 * hasn't moved (moving it would produce an event, which would have the axis'
590 * value).
591 *
592 * The pointer returned is owned by the SDL_GameController. You should not
593 * call SDL_JoystickClose() on it, for example, since doing so will likely
594 * cause SDL to crash.
595 *
596 * \param gamecontroller the game controller object that you want to get a
597 * joystick from.
598 * \returns a SDL_Joystick object; call SDL_GetError() for more information.
599 *
600 * \since This function is available since SDL 2.0.0.
601 */
602extern DECLSPEC SDL_Joystick *SDLCALL SDL_GameControllerGetJoystick(SDL_GameController *gamecontroller);
603
604/**
605 * Query or change current state of Game Controller events.
606 *
607 * If controller events are disabled, you must call SDL_GameControllerUpdate()
608 * yourself and check the state of the controller when you want controller
609 * information.
610 *
611 * Any number can be passed to SDL_GameControllerEventState(), but only -1, 0,
612 * and 1 will have any effect. Other numbers will just be returned.
613 *
614 * \param state can be one of `SDL_QUERY`, `SDL_IGNORE`, or `SDL_ENABLE`.
615 * \returns the same value passed to the function, with exception to -1
616 * (SDL_QUERY), which will return the current state.
617 *
618 * \since This function is available since SDL 2.0.0.
619 *
620 * \sa SDL_JoystickEventState
621 */
622extern DECLSPEC int SDLCALL SDL_GameControllerEventState(int state);
623
624/**
625 * Manually pump game controller updates if not using the loop.
626 *
627 * This function is called automatically by the event loop if events are
628 * enabled. Under such circumstances, it will not be necessary to call this
629 * function.
630 *
631 * \since This function is available since SDL 2.0.0.
632 */
633extern DECLSPEC void SDLCALL SDL_GameControllerUpdate(void);
634
635
636/**
637 * The list of axes available from a controller
638 *
639 * Thumbstick axis values range from SDL_JOYSTICK_AXIS_MIN to
640 * SDL_JOYSTICK_AXIS_MAX, and are centered within ~8000 of zero, though
641 * advanced UI will allow users to set or autodetect the dead zone, which
642 * varies between controllers.
643 *
644 * Trigger axis values range from 0 (released) to SDL_JOYSTICK_AXIS_MAX (fully
645 * pressed) when reported by SDL_GameControllerGetAxis(). Note that this is
646 * not the same range that will be reported by the lower-level
647 * SDL_GetJoystickAxis().
648 */
649typedef enum SDL_GameControllerAxis
650{
651 SDL_CONTROLLER_AXIS_INVALID = -1,
652 SDL_CONTROLLER_AXIS_LEFTX,
653 SDL_CONTROLLER_AXIS_LEFTY,
654 SDL_CONTROLLER_AXIS_RIGHTX,
655 SDL_CONTROLLER_AXIS_RIGHTY,
656 SDL_CONTROLLER_AXIS_TRIGGERLEFT,
657 SDL_CONTROLLER_AXIS_TRIGGERRIGHT,
658 SDL_CONTROLLER_AXIS_MAX
659} SDL_GameControllerAxis;
660
661/**
662 * Convert a string into SDL_GameControllerAxis enum.
663 *
664 * This function is called internally to translate SDL_GameController mapping
665 * strings for the underlying joystick device into the consistent
666 * SDL_GameController mapping. You do not normally need to call this function
667 * unless you are parsing SDL_GameController mappings in your own code.
668 *
669 * Note specially that "righttrigger" and "lefttrigger" map to
670 * `SDL_CONTROLLER_AXIS_TRIGGERRIGHT` and `SDL_CONTROLLER_AXIS_TRIGGERLEFT`,
671 * respectively.
672 *
673 * \param str string representing a SDL_GameController axis.
674 * \returns the SDL_GameControllerAxis enum corresponding to the input string,
675 * or `SDL_CONTROLLER_AXIS_INVALID` if no match was found.
676 *
677 * \since This function is available since SDL 2.0.0.
678 *
679 * \sa SDL_GameControllerGetStringForAxis
680 */
681extern DECLSPEC SDL_GameControllerAxis SDLCALL SDL_GameControllerGetAxisFromString(const char *str);
682
683/**
684 * Convert from an SDL_GameControllerAxis enum to a string.
685 *
686 * The caller should not SDL_free() the returned string.
687 *
688 * \param axis an enum value for a given SDL_GameControllerAxis.
689 * \returns a string for the given axis, or NULL if an invalid axis is
690 * specified. The string returned is of the format used by
691 * SDL_GameController mapping strings.
692 *
693 * \since This function is available since SDL 2.0.0.
694 *
695 * \sa SDL_GameControllerGetAxisFromString
696 */
697extern DECLSPEC const char* SDLCALL SDL_GameControllerGetStringForAxis(SDL_GameControllerAxis axis);
698
699/**
700 * Get the SDL joystick layer binding for a controller axis mapping.
701 *
702 * \param gamecontroller a game controller.
703 * \param axis an axis enum value (one of the SDL_GameControllerAxis values).
704 * \returns a SDL_GameControllerButtonBind describing the bind. On failure
705 * (like the given Controller axis doesn't exist on the device), its
706 * `.bindType` will be `SDL_CONTROLLER_BINDTYPE_NONE`.
707 *
708 * \since This function is available since SDL 2.0.0.
709 *
710 * \sa SDL_GameControllerGetBindForButton
711 */
712extern DECLSPEC SDL_GameControllerButtonBind SDLCALL
713SDL_GameControllerGetBindForAxis(SDL_GameController *gamecontroller,
714 SDL_GameControllerAxis axis);
715
716/**
717 * Query whether a game controller has a given axis.
718 *
719 * This merely reports whether the controller's mapping defined this axis, as
720 * that is all the information SDL has about the physical device.
721 *
722 * \param gamecontroller a game controller.
723 * \param axis an axis enum value (an SDL_GameControllerAxis value).
724 * \returns SDL_TRUE if the controller has this axis, SDL_FALSE otherwise.
725 *
726 * \since This function is available since SDL 2.0.14.
727 */
728extern DECLSPEC SDL_bool SDLCALL
729SDL_GameControllerHasAxis(SDL_GameController *gamecontroller, SDL_GameControllerAxis axis);
730
731/**
732 * Get the current state of an axis control on a game controller.
733 *
734 * The axis indices start at index 0.
735 *
736 * For thumbsticks, the state is a value ranging from -32768 (up/left) to
737 * 32767 (down/right).
738 *
739 * Triggers range from 0 when released to 32767 when fully pressed, and never
740 * return a negative value. Note that this differs from the value reported by
741 * the lower-level SDL_JoystickGetAxis(), which normally uses the full range.
742 *
743 * \param gamecontroller a game controller.
744 * \param axis an axis index (one of the SDL_GameControllerAxis values).
745 * \returns axis state (including 0) on success or 0 (also) on failure; call
746 * SDL_GetError() for more information.
747 *
748 * \since This function is available since SDL 2.0.0.
749 *
750 * \sa SDL_GameControllerGetButton
751 */
752extern DECLSPEC Sint16 SDLCALL
753SDL_GameControllerGetAxis(SDL_GameController *gamecontroller, SDL_GameControllerAxis axis);
754
755/**
756 * The list of buttons available from a controller
757 */
758typedef enum SDL_GameControllerButton
759{
760 SDL_CONTROLLER_BUTTON_INVALID = -1,
761 SDL_CONTROLLER_BUTTON_A,
762 SDL_CONTROLLER_BUTTON_B,
763 SDL_CONTROLLER_BUTTON_X,
764 SDL_CONTROLLER_BUTTON_Y,
765 SDL_CONTROLLER_BUTTON_BACK,
766 SDL_CONTROLLER_BUTTON_GUIDE,
767 SDL_CONTROLLER_BUTTON_START,
768 SDL_CONTROLLER_BUTTON_LEFTSTICK,
769 SDL_CONTROLLER_BUTTON_RIGHTSTICK,
770 SDL_CONTROLLER_BUTTON_LEFTSHOULDER,
771 SDL_CONTROLLER_BUTTON_RIGHTSHOULDER,
772 SDL_CONTROLLER_BUTTON_DPAD_UP,
773 SDL_CONTROLLER_BUTTON_DPAD_DOWN,
774 SDL_CONTROLLER_BUTTON_DPAD_LEFT,
775 SDL_CONTROLLER_BUTTON_DPAD_RIGHT,
776 SDL_CONTROLLER_BUTTON_MISC1, /* Xbox Series X share button, PS5 microphone button, Nintendo Switch Pro capture button, Amazon Luna microphone button */
777 SDL_CONTROLLER_BUTTON_PADDLE1, /* Xbox Elite paddle P1 (upper left, facing the back) */
778 SDL_CONTROLLER_BUTTON_PADDLE2, /* Xbox Elite paddle P3 (upper right, facing the back) */
779 SDL_CONTROLLER_BUTTON_PADDLE3, /* Xbox Elite paddle P2 (lower left, facing the back) */
780 SDL_CONTROLLER_BUTTON_PADDLE4, /* Xbox Elite paddle P4 (lower right, facing the back) */
781 SDL_CONTROLLER_BUTTON_TOUCHPAD, /* PS4/PS5 touchpad button */
782 SDL_CONTROLLER_BUTTON_MAX
783} SDL_GameControllerButton;
784
785/**
786 * Convert a string into an SDL_GameControllerButton enum.
787 *
788 * This function is called internally to translate SDL_GameController mapping
789 * strings for the underlying joystick device into the consistent
790 * SDL_GameController mapping. You do not normally need to call this function
791 * unless you are parsing SDL_GameController mappings in your own code.
792 *
793 * \param str string representing a SDL_GameController axis.
794 * \returns the SDL_GameControllerButton enum corresponding to the input
795 * string, or `SDL_CONTROLLER_AXIS_INVALID` if no match was found.
796 *
797 * \since This function is available since SDL 2.0.0.
798 */
799extern DECLSPEC SDL_GameControllerButton SDLCALL SDL_GameControllerGetButtonFromString(const char *str);
800
801/**
802 * Convert from an SDL_GameControllerButton enum to a string.
803 *
804 * The caller should not SDL_free() the returned string.
805 *
806 * \param button an enum value for a given SDL_GameControllerButton.
807 * \returns a string for the given button, or NULL if an invalid button is
808 * specified. The string returned is of the format used by
809 * SDL_GameController mapping strings.
810 *
811 * \since This function is available since SDL 2.0.0.
812 *
813 * \sa SDL_GameControllerGetButtonFromString
814 */
815extern DECLSPEC const char* SDLCALL SDL_GameControllerGetStringForButton(SDL_GameControllerButton button);
816
817/**
818 * Get the SDL joystick layer binding for a controller button mapping.
819 *
820 * \param gamecontroller a game controller.
821 * \param button an button enum value (an SDL_GameControllerButton value).
822 * \returns a SDL_GameControllerButtonBind describing the bind. On failure
823 * (like the given Controller button doesn't exist on the device),
824 * its `.bindType` will be `SDL_CONTROLLER_BINDTYPE_NONE`.
825 *
826 * \since This function is available since SDL 2.0.0.
827 *
828 * \sa SDL_GameControllerGetBindForAxis
829 */
830extern DECLSPEC SDL_GameControllerButtonBind SDLCALL
831SDL_GameControllerGetBindForButton(SDL_GameController *gamecontroller,
832 SDL_GameControllerButton button);
833
834/**
835 * Query whether a game controller has a given button.
836 *
837 * This merely reports whether the controller's mapping defined this button,
838 * as that is all the information SDL has about the physical device.
839 *
840 * \param gamecontroller a game controller.
841 * \param button a button enum value (an SDL_GameControllerButton value).
842 * \returns SDL_TRUE if the controller has this button, SDL_FALSE otherwise.
843 *
844 * \since This function is available since SDL 2.0.14.
845 */
846extern DECLSPEC SDL_bool SDLCALL SDL_GameControllerHasButton(SDL_GameController *gamecontroller,
847 SDL_GameControllerButton button);
848
849/**
850 * Get the current state of a button on a game controller.
851 *
852 * \param gamecontroller a game controller.
853 * \param button a button index (one of the SDL_GameControllerButton values).
854 * \returns 1 for pressed state or 0 for not pressed state or error; call
855 * SDL_GetError() for more information.
856 *
857 * \since This function is available since SDL 2.0.0.
858 *
859 * \sa SDL_GameControllerGetAxis
860 */
861extern DECLSPEC Uint8 SDLCALL SDL_GameControllerGetButton(SDL_GameController *gamecontroller,
862 SDL_GameControllerButton button);
863
864/**
865 * Get the number of touchpads on a game controller.
866 *
867 * \param gamecontroller a controller.
868 * \returns number of touchpads.
869 *
870 * \since This function is available since SDL 2.0.14.
871 */
872extern DECLSPEC int SDLCALL SDL_GameControllerGetNumTouchpads(SDL_GameController *gamecontroller);
873
874/**
875 * Get the number of supported simultaneous fingers on a touchpad on a game
876 * controller.
877 *
878 * \param gamecontroller a controller.
879 * \param touchpad a touchpad.
880 * \returns number of supported simultaneous fingers.
881 *
882 * \since This function is available since SDL 2.0.14.
883 */
884extern DECLSPEC int SDLCALL SDL_GameControllerGetNumTouchpadFingers(SDL_GameController *gamecontroller, int touchpad);
885
886/**
887 * Get the current state of a finger on a touchpad on a game controller.
888 *
889 * \param gamecontroller a controller.
890 * \param touchpad a touchpad.
891 * \param finger a finger.
892 * \param state a pointer filled with the finger state.
893 * \param x a pointer filled with the x position.
894 * \param y a pointer filled with the y position.
895 * \param pressure a pointer filled with pressure value.
896 * \returns 0 on success or negative on failure.
897 *
898 * \since This function is available since SDL 2.0.14.
899 */
900extern DECLSPEC int SDLCALL SDL_GameControllerGetTouchpadFinger(SDL_GameController *gamecontroller, int touchpad, int finger, Uint8 *state, float *x, float *y, float *pressure);
901
902/**
903 * Return whether a game controller has a particular sensor.
904 *
905 * \param gamecontroller The controller to query.
906 * \param type The type of sensor to query.
907 * \returns SDL_TRUE if the sensor exists, SDL_FALSE otherwise.
908 *
909 * \since This function is available since SDL 2.0.14.
910 */
911extern DECLSPEC SDL_bool SDLCALL SDL_GameControllerHasSensor(SDL_GameController *gamecontroller, SDL_SensorType type);
912
913/**
914 * Set whether data reporting for a game controller sensor is enabled.
915 *
916 * \param gamecontroller The controller to update.
917 * \param type The type of sensor to enable/disable.
918 * \param enabled Whether data reporting should be enabled.
919 * \returns 0 or -1 if an error occurred.
920 *
921 * \since This function is available since SDL 2.0.14.
922 */
923extern DECLSPEC int SDLCALL SDL_GameControllerSetSensorEnabled(SDL_GameController *gamecontroller, SDL_SensorType type, SDL_bool enabled);
924
925/**
926 * Query whether sensor data reporting is enabled for a game controller.
927 *
928 * \param gamecontroller The controller to query.
929 * \param type The type of sensor to query.
930 * \returns SDL_TRUE if the sensor is enabled, SDL_FALSE otherwise.
931 *
932 * \since This function is available since SDL 2.0.14.
933 */
934extern DECLSPEC SDL_bool SDLCALL SDL_GameControllerIsSensorEnabled(SDL_GameController *gamecontroller, SDL_SensorType type);
935
936/**
937 * Get the data rate (number of events per second) of a game controller
938 * sensor.
939 *
940 * \param gamecontroller The controller to query.
941 * \param type The type of sensor to query.
942 * \return the data rate, or 0.0f if the data rate is not available.
943 *
944 * \since This function is available since SDL 2.0.16.
945 */
946extern DECLSPEC float SDLCALL SDL_GameControllerGetSensorDataRate(SDL_GameController *gamecontroller, SDL_SensorType type);
947
948/**
949 * Get the current state of a game controller sensor.
950 *
951 * The number of values and interpretation of the data is sensor dependent.
952 * See SDL_sensor.h for the details for each type of sensor.
953 *
954 * \param gamecontroller The controller to query.
955 * \param type The type of sensor to query.
956 * \param data A pointer filled with the current sensor state.
957 * \param num_values The number of values to write to data.
958 * \return 0 or -1 if an error occurred.
959 *
960 * \since This function is available since SDL 2.0.14.
961 */
962extern DECLSPEC int SDLCALL SDL_GameControllerGetSensorData(SDL_GameController *gamecontroller, SDL_SensorType type, float *data, int num_values);
963
964/**
965 * Get the current state of a game controller sensor with the timestamp of the
966 * last update.
967 *
968 * The number of values and interpretation of the data is sensor dependent.
969 * See SDL_sensor.h for the details for each type of sensor.
970 *
971 * \param gamecontroller The controller to query.
972 * \param type The type of sensor to query.
973 * \param timestamp A pointer filled with the timestamp in microseconds of the
974 * current sensor reading if available, or 0 if not.
975 * \param data A pointer filled with the current sensor state.
976 * \param num_values The number of values to write to data.
977 * \return 0 or -1 if an error occurred.
978 *
979 * \since This function is available since SDL 2.26.0.
980 */
981extern DECLSPEC int SDLCALL SDL_GameControllerGetSensorDataWithTimestamp(SDL_GameController *gamecontroller, SDL_SensorType type, Uint64 *timestamp, float *data, int num_values);
982
983/**
984 * Start a rumble effect on a game controller.
985 *
986 * Each call to this function cancels any previous rumble effect, and calling
987 * it with 0 intensity stops any rumbling.
988 *
989 * \param gamecontroller The controller to vibrate.
990 * \param low_frequency_rumble The intensity of the low frequency (left)
991 * rumble motor, from 0 to 0xFFFF.
992 * \param high_frequency_rumble The intensity of the high frequency (right)
993 * rumble motor, from 0 to 0xFFFF.
994 * \param duration_ms The duration of the rumble effect, in milliseconds.
995 * \returns 0, or -1 if rumble isn't supported on this controller.
996 *
997 * \since This function is available since SDL 2.0.9.
998 *
999 * \sa SDL_GameControllerHasRumble
1000 */
1001extern DECLSPEC int SDLCALL SDL_GameControllerRumble(SDL_GameController *gamecontroller, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble, Uint32 duration_ms);
1002
1003/**
1004 * Start a rumble effect in the game controller's triggers.
1005 *
1006 * Each call to this function cancels any previous trigger rumble effect, and
1007 * calling it with 0 intensity stops any rumbling.
1008 *
1009 * Note that this is rumbling of the _triggers_ and not the game controller as
1010 * a whole. This is currently only supported on Xbox One controllers. If you
1011 * want the (more common) whole-controller rumble, use
1012 * SDL_GameControllerRumble() instead.
1013 *
1014 * \param gamecontroller The controller to vibrate.
1015 * \param left_rumble The intensity of the left trigger rumble motor, from 0
1016 * to 0xFFFF.
1017 * \param right_rumble The intensity of the right trigger rumble motor, from 0
1018 * to 0xFFFF.
1019 * \param duration_ms The duration of the rumble effect, in milliseconds.
1020 * \returns 0, or -1 if trigger rumble isn't supported on this controller.
1021 *
1022 * \since This function is available since SDL 2.0.14.
1023 *
1024 * \sa SDL_GameControllerHasRumbleTriggers
1025 */
1026extern DECLSPEC int SDLCALL SDL_GameControllerRumbleTriggers(SDL_GameController *gamecontroller, Uint16 left_rumble, Uint16 right_rumble, Uint32 duration_ms);
1027
1028/**
1029 * Query whether a game controller has an LED.
1030 *
1031 * \param gamecontroller The controller to query.
1032 * \returns SDL_TRUE, or SDL_FALSE if this controller does not have a
1033 * modifiable LED.
1034 *
1035 * \since This function is available since SDL 2.0.14.
1036 */
1037extern DECLSPEC SDL_bool SDLCALL SDL_GameControllerHasLED(SDL_GameController *gamecontroller);
1038
1039/**
1040 * Query whether a game controller has rumble support.
1041 *
1042 * \param gamecontroller The controller to query.
1043 * \returns SDL_TRUE, or SDL_FALSE if this controller does not have rumble
1044 * support.
1045 *
1046 * \since This function is available since SDL 2.0.18.
1047 *
1048 * \sa SDL_GameControllerRumble
1049 */
1050extern DECLSPEC SDL_bool SDLCALL SDL_GameControllerHasRumble(SDL_GameController *gamecontroller);
1051
1052/**
1053 * Query whether a game controller has rumble support on triggers.
1054 *
1055 * \param gamecontroller The controller to query.
1056 * \returns SDL_TRUE, or SDL_FALSE if this controller does not have trigger
1057 * rumble support.
1058 *
1059 * \since This function is available since SDL 2.0.18.
1060 *
1061 * \sa SDL_GameControllerRumbleTriggers
1062 */
1063extern DECLSPEC SDL_bool SDLCALL SDL_GameControllerHasRumbleTriggers(SDL_GameController *gamecontroller);
1064
1065/**
1066 * Update a game controller's LED color.
1067 *
1068 * \param gamecontroller The controller to update.
1069 * \param red The intensity of the red LED.
1070 * \param green The intensity of the green LED.
1071 * \param blue The intensity of the blue LED.
1072 * \returns 0, or -1 if this controller does not have a modifiable LED.
1073 *
1074 * \since This function is available since SDL 2.0.14.
1075 */
1076extern DECLSPEC int SDLCALL SDL_GameControllerSetLED(SDL_GameController *gamecontroller, Uint8 red, Uint8 green, Uint8 blue);
1077
1078/**
1079 * Send a controller specific effect packet
1080 *
1081 * \param gamecontroller The controller to affect.
1082 * \param data The data to send to the controller.
1083 * \param size The size of the data to send to the controller.
1084 * \returns 0, or -1 if this controller or driver doesn't support effect
1085 * packets.
1086 *
1087 * \since This function is available since SDL 2.0.16.
1088 */
1089extern DECLSPEC int SDLCALL SDL_GameControllerSendEffect(SDL_GameController *gamecontroller, const void *data, int size);
1090
1091/**
1092 * Close a game controller previously opened with SDL_GameControllerOpen().
1093 *
1094 * \param gamecontroller a game controller identifier previously returned by
1095 * SDL_GameControllerOpen().
1096 *
1097 * \since This function is available since SDL 2.0.0.
1098 *
1099 * \sa SDL_GameControllerOpen
1100 */
1101extern DECLSPEC void SDLCALL SDL_GameControllerClose(SDL_GameController *gamecontroller);
1102
1103/**
1104 * Return the sfSymbolsName for a given button on a game controller on Apple
1105 * platforms.
1106 *
1107 * \param gamecontroller the controller to query.
1108 * \param button a button on the game controller.
1109 * \returns the sfSymbolsName or NULL if the name can't be found.
1110 *
1111 * \since This function is available since SDL 2.0.18.
1112 *
1113 * \sa SDL_GameControllerGetAppleSFSymbolsNameForAxis
1114 */
1115extern DECLSPEC const char* SDLCALL SDL_GameControllerGetAppleSFSymbolsNameForButton(SDL_GameController *gamecontroller, SDL_GameControllerButton button);
1116
1117/**
1118 * Return the sfSymbolsName for a given axis on a game controller on Apple
1119 * platforms.
1120 *
1121 * \param gamecontroller the controller to query.
1122 * \param axis an axis on the game controller.
1123 * \returns the sfSymbolsName or NULL if the name can't be found.
1124 *
1125 * \since This function is available since SDL 2.0.18.
1126 *
1127 * \sa SDL_GameControllerGetAppleSFSymbolsNameForButton
1128 */
1129extern DECLSPEC const char* SDLCALL SDL_GameControllerGetAppleSFSymbolsNameForAxis(SDL_GameController *gamecontroller, SDL_GameControllerAxis axis);
1130
1131
1132/* Ends C function definitions when using C++ */
1133#ifdef __cplusplus
1134}
1135#endif
1136#include "close_code.h"
1137
1138#endif /* SDL_gamecontroller_h_ */
1139
1140/* vi: set ts=4 sw=4 expandtab: */
1141