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