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 | /** |
23 | * # CategoryJoystick |
24 | * |
25 | * SDL joystick support. |
26 | * |
27 | * This is the lower-level joystick handling. If you want the simpler option, |
28 | * where what each button does is well-defined, you should use the gamepad API |
29 | * instead. |
30 | * |
31 | * The term "instance_id" is the current instantiation of a joystick device in |
32 | * the system, if the joystick is removed and then re-inserted then it will |
33 | * get a new instance_id, instance_id's are monotonically increasing |
34 | * identifiers of a joystick plugged in. |
35 | * |
36 | * The term "player_index" is the number assigned to a player on a specific |
37 | * controller. For XInput controllers this returns the XInput user index. Many |
38 | * joysticks will not be able to supply this information. |
39 | * |
40 | * SDL_GUID is used as a stable 128-bit identifier for a joystick device that |
41 | * does not change over time. It identifies class of the device (a X360 wired |
42 | * controller for example). This identifier is platform dependent. |
43 | * |
44 | * In order to use these functions, SDL_Init() must have been called with the |
45 | * SDL_INIT_JOYSTICK flag. This causes SDL to scan the system for joysticks, |
46 | * and load appropriate drivers. |
47 | * |
48 | * If you would like to receive joystick updates while the application is in |
49 | * the background, you should set the following hint before calling |
50 | * SDL_Init(): SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS |
51 | */ |
52 | |
53 | #ifndef SDL_joystick_h_ |
54 | #define SDL_joystick_h_ |
55 | |
56 | #include <SDL3/SDL_stdinc.h> |
57 | #include <SDL3/SDL_error.h> |
58 | #include <SDL3/SDL_guid.h> |
59 | #include <SDL3/SDL_mutex.h> |
60 | #include <SDL3/SDL_power.h> |
61 | #include <SDL3/SDL_properties.h> |
62 | #include <SDL3/SDL_sensor.h> |
63 | |
64 | #include <SDL3/SDL_begin_code.h> |
65 | /* Set up for C function definitions, even when using C++ */ |
66 | #ifdef __cplusplus |
67 | extern "C" { |
68 | #endif |
69 | |
70 | #ifdef SDL_THREAD_SAFETY_ANALYSIS |
71 | /* |
72 | * This is not an exported symbol from SDL, this is only in the headers to |
73 | * help Clang's thread safety analysis tools to function. Do not attempt |
74 | * to access this symbol from your app, it will not work! |
75 | */ |
76 | extern SDL_Mutex *SDL_joystick_lock; |
77 | #endif |
78 | |
79 | /** |
80 | * The joystick structure used to identify an SDL joystick. |
81 | * |
82 | * This is opaque data. |
83 | * |
84 | * \since This struct is available since SDL 3.2.0. |
85 | */ |
86 | typedef struct SDL_Joystick SDL_Joystick; |
87 | |
88 | /** |
89 | * This is a unique ID for a joystick for the time it is connected to the |
90 | * system, and is never reused for the lifetime of the application. |
91 | * |
92 | * If the joystick is disconnected and reconnected, it will get a new ID. |
93 | * |
94 | * The value 0 is an invalid ID. |
95 | * |
96 | * \since This datatype is available since SDL 3.2.0. |
97 | */ |
98 | typedef Uint32 SDL_JoystickID; |
99 | |
100 | /** |
101 | * An enum of some common joystick types. |
102 | * |
103 | * In some cases, SDL can identify a low-level joystick as being a certain |
104 | * type of device, and will report it through SDL_GetJoystickType (or |
105 | * SDL_GetJoystickTypeForID). |
106 | * |
107 | * This is by no means a complete list of everything that can be plugged into |
108 | * a computer. |
109 | * |
110 | * You may refer to |
111 | * [XInput Controller Types](https://learn.microsoft.com/en-us/windows/win32/xinput/xinput-and-controller-subtypes) |
112 | * table for a general understanding of each joystick type. |
113 | * |
114 | * \since This enum is available since SDL 3.2.0. |
115 | */ |
116 | typedef enum SDL_JoystickType |
117 | { |
118 | SDL_JOYSTICK_TYPE_UNKNOWN, |
119 | SDL_JOYSTICK_TYPE_GAMEPAD, |
120 | SDL_JOYSTICK_TYPE_WHEEL, |
121 | SDL_JOYSTICK_TYPE_ARCADE_STICK, |
122 | SDL_JOYSTICK_TYPE_FLIGHT_STICK, |
123 | SDL_JOYSTICK_TYPE_DANCE_PAD, |
124 | SDL_JOYSTICK_TYPE_GUITAR, |
125 | SDL_JOYSTICK_TYPE_DRUM_KIT, |
126 | SDL_JOYSTICK_TYPE_ARCADE_PAD, |
127 | SDL_JOYSTICK_TYPE_THROTTLE, |
128 | SDL_JOYSTICK_TYPE_COUNT |
129 | } SDL_JoystickType; |
130 | |
131 | /** |
132 | * Possible connection states for a joystick device. |
133 | * |
134 | * This is used by SDL_GetJoystickConnectionState to report how a device is |
135 | * connected to the system. |
136 | * |
137 | * \since This enum is available since SDL 3.2.0. |
138 | */ |
139 | typedef enum SDL_JoystickConnectionState |
140 | { |
141 | SDL_JOYSTICK_CONNECTION_INVALID = -1, |
142 | SDL_JOYSTICK_CONNECTION_UNKNOWN, |
143 | SDL_JOYSTICK_CONNECTION_WIRED, |
144 | SDL_JOYSTICK_CONNECTION_WIRELESS |
145 | } SDL_JoystickConnectionState; |
146 | |
147 | /** |
148 | * The largest value an SDL_Joystick's axis can report. |
149 | * |
150 | * \since This macro is available since SDL 3.2.0. |
151 | * |
152 | * \sa SDL_JOYSTICK_AXIS_MIN |
153 | */ |
154 | #define SDL_JOYSTICK_AXIS_MAX 32767 |
155 | |
156 | /** |
157 | * The smallest value an SDL_Joystick's axis can report. |
158 | * |
159 | * This is a negative number! |
160 | * |
161 | * \since This macro is available since SDL 3.2.0. |
162 | * |
163 | * \sa SDL_JOYSTICK_AXIS_MAX |
164 | */ |
165 | #define SDL_JOYSTICK_AXIS_MIN -32768 |
166 | |
167 | |
168 | /* Function prototypes */ |
169 | |
170 | /** |
171 | * Locking for atomic access to the joystick API. |
172 | * |
173 | * The SDL joystick functions are thread-safe, however you can lock the |
174 | * joysticks while processing to guarantee that the joystick list won't change |
175 | * and joystick and gamepad events will not be delivered. |
176 | * |
177 | * \since This function is available since SDL 3.2.0. |
178 | */ |
179 | extern SDL_DECLSPEC void SDLCALL SDL_LockJoysticks(void) SDL_ACQUIRE(SDL_joystick_lock); |
180 | |
181 | /** |
182 | * Unlocking for atomic access to the joystick API. |
183 | * |
184 | * \since This function is available since SDL 3.2.0. |
185 | */ |
186 | extern SDL_DECLSPEC void SDLCALL SDL_UnlockJoysticks(void) SDL_RELEASE(SDL_joystick_lock); |
187 | |
188 | /** |
189 | * Return whether a joystick is currently connected. |
190 | * |
191 | * \returns true if a joystick is connected, false otherwise. |
192 | * |
193 | * \since This function is available since SDL 3.2.0. |
194 | * |
195 | * \sa SDL_GetJoysticks |
196 | */ |
197 | extern SDL_DECLSPEC bool SDLCALL SDL_HasJoystick(void); |
198 | |
199 | /** |
200 | * Get a list of currently connected joysticks. |
201 | * |
202 | * \param count a pointer filled in with the number of joysticks returned, may |
203 | * be NULL. |
204 | * \returns a 0 terminated array of joystick instance IDs or NULL on failure; |
205 | * call SDL_GetError() for more information. This should be freed |
206 | * with SDL_free() when it is no longer needed. |
207 | * |
208 | * \since This function is available since SDL 3.2.0. |
209 | * |
210 | * \sa SDL_HasJoystick |
211 | * \sa SDL_OpenJoystick |
212 | */ |
213 | extern SDL_DECLSPEC SDL_JoystickID * SDLCALL SDL_GetJoysticks(int *count); |
214 | |
215 | /** |
216 | * Get the implementation dependent name of a joystick. |
217 | * |
218 | * This can be called before any joysticks are opened. |
219 | * |
220 | * \param instance_id the joystick instance ID. |
221 | * \returns the name of the selected joystick. If no name can be found, this |
222 | * function returns NULL; call SDL_GetError() for more information. |
223 | * |
224 | * \since This function is available since SDL 3.2.0. |
225 | * |
226 | * \sa SDL_GetJoystickName |
227 | * \sa SDL_GetJoysticks |
228 | */ |
229 | extern SDL_DECLSPEC const char * SDLCALL SDL_GetJoystickNameForID(SDL_JoystickID instance_id); |
230 | |
231 | /** |
232 | * Get the implementation dependent path of a joystick. |
233 | * |
234 | * This can be called before any joysticks are opened. |
235 | * |
236 | * \param instance_id the joystick instance ID. |
237 | * \returns the path of the selected joystick. If no path can be found, this |
238 | * function returns NULL; call SDL_GetError() for more information. |
239 | * |
240 | * \since This function is available since SDL 3.2.0. |
241 | * |
242 | * \sa SDL_GetJoystickPath |
243 | * \sa SDL_GetJoysticks |
244 | */ |
245 | extern SDL_DECLSPEC const char * SDLCALL SDL_GetJoystickPathForID(SDL_JoystickID instance_id); |
246 | |
247 | /** |
248 | * Get the player index of a joystick. |
249 | * |
250 | * This can be called before any joysticks are opened. |
251 | * |
252 | * \param instance_id the joystick instance ID. |
253 | * \returns the player index of a joystick, or -1 if it's not available. |
254 | * |
255 | * \since This function is available since SDL 3.2.0. |
256 | * |
257 | * \sa SDL_GetJoystickPlayerIndex |
258 | * \sa SDL_GetJoysticks |
259 | */ |
260 | extern SDL_DECLSPEC int SDLCALL SDL_GetJoystickPlayerIndexForID(SDL_JoystickID instance_id); |
261 | |
262 | /** |
263 | * Get the implementation-dependent GUID of a joystick. |
264 | * |
265 | * This can be called before any joysticks are opened. |
266 | * |
267 | * \param instance_id the joystick instance ID. |
268 | * \returns the GUID of the selected joystick. If called with an invalid |
269 | * instance_id, this function returns a zero GUID. |
270 | * |
271 | * \since This function is available since SDL 3.2.0. |
272 | * |
273 | * \sa SDL_GetJoystickGUID |
274 | * \sa SDL_GUIDToString |
275 | */ |
276 | extern SDL_DECLSPEC SDL_GUID SDLCALL SDL_GetJoystickGUIDForID(SDL_JoystickID instance_id); |
277 | |
278 | /** |
279 | * Get the USB vendor ID of a joystick, if available. |
280 | * |
281 | * This can be called before any joysticks are opened. If the vendor ID isn't |
282 | * available this function returns 0. |
283 | * |
284 | * \param instance_id the joystick instance ID. |
285 | * \returns the USB vendor ID of the selected joystick. If called with an |
286 | * invalid instance_id, this function returns 0. |
287 | * |
288 | * \since This function is available since SDL 3.2.0. |
289 | * |
290 | * \sa SDL_GetJoystickVendor |
291 | * \sa SDL_GetJoysticks |
292 | */ |
293 | extern SDL_DECLSPEC Uint16 SDLCALL SDL_GetJoystickVendorForID(SDL_JoystickID instance_id); |
294 | |
295 | /** |
296 | * Get the USB product ID of a joystick, if available. |
297 | * |
298 | * This can be called before any joysticks are opened. If the product ID isn't |
299 | * available this function returns 0. |
300 | * |
301 | * \param instance_id the joystick instance ID. |
302 | * \returns the USB product ID of the selected joystick. If called with an |
303 | * invalid instance_id, this function returns 0. |
304 | * |
305 | * \since This function is available since SDL 3.2.0. |
306 | * |
307 | * \sa SDL_GetJoystickProduct |
308 | * \sa SDL_GetJoysticks |
309 | */ |
310 | extern SDL_DECLSPEC Uint16 SDLCALL SDL_GetJoystickProductForID(SDL_JoystickID instance_id); |
311 | |
312 | /** |
313 | * Get the product version of a joystick, if available. |
314 | * |
315 | * This can be called before any joysticks are opened. If the product version |
316 | * isn't available this function returns 0. |
317 | * |
318 | * \param instance_id the joystick instance ID. |
319 | * \returns the product version of the selected joystick. If called with an |
320 | * invalid instance_id, this function returns 0. |
321 | * |
322 | * \since This function is available since SDL 3.2.0. |
323 | * |
324 | * \sa SDL_GetJoystickProductVersion |
325 | * \sa SDL_GetJoysticks |
326 | */ |
327 | extern SDL_DECLSPEC Uint16 SDLCALL SDL_GetJoystickProductVersionForID(SDL_JoystickID instance_id); |
328 | |
329 | /** |
330 | * Get the type of a joystick, if available. |
331 | * |
332 | * This can be called before any joysticks are opened. |
333 | * |
334 | * \param instance_id the joystick instance ID. |
335 | * \returns the SDL_JoystickType of the selected joystick. If called with an |
336 | * invalid instance_id, this function returns |
337 | * `SDL_JOYSTICK_TYPE_UNKNOWN`. |
338 | * |
339 | * \since This function is available since SDL 3.2.0. |
340 | * |
341 | * \sa SDL_GetJoystickType |
342 | * \sa SDL_GetJoysticks |
343 | */ |
344 | extern SDL_DECLSPEC SDL_JoystickType SDLCALL SDL_GetJoystickTypeForID(SDL_JoystickID instance_id); |
345 | |
346 | /** |
347 | * Open a joystick for use. |
348 | * |
349 | * The joystick subsystem must be initialized before a joystick can be opened |
350 | * for use. |
351 | * |
352 | * \param instance_id the joystick instance ID. |
353 | * \returns a joystick identifier or NULL on failure; call SDL_GetError() for |
354 | * more information. |
355 | * |
356 | * \since This function is available since SDL 3.2.0. |
357 | * |
358 | * \sa SDL_CloseJoystick |
359 | */ |
360 | extern SDL_DECLSPEC SDL_Joystick * SDLCALL SDL_OpenJoystick(SDL_JoystickID instance_id); |
361 | |
362 | /** |
363 | * Get the SDL_Joystick associated with an instance ID, if it has been opened. |
364 | * |
365 | * \param instance_id the instance ID to get the SDL_Joystick for. |
366 | * \returns an SDL_Joystick on success or NULL on failure or if it hasn't been |
367 | * opened yet; call SDL_GetError() for more information. |
368 | * |
369 | * \since This function is available since SDL 3.2.0. |
370 | */ |
371 | extern SDL_DECLSPEC SDL_Joystick * SDLCALL SDL_GetJoystickFromID(SDL_JoystickID instance_id); |
372 | |
373 | /** |
374 | * Get the SDL_Joystick associated with a player index. |
375 | * |
376 | * \param player_index the player index to get the SDL_Joystick for. |
377 | * \returns an SDL_Joystick on success or NULL on failure; call SDL_GetError() |
378 | * for more information. |
379 | * |
380 | * \since This function is available since SDL 3.2.0. |
381 | * |
382 | * \sa SDL_GetJoystickPlayerIndex |
383 | * \sa SDL_SetJoystickPlayerIndex |
384 | */ |
385 | extern SDL_DECLSPEC SDL_Joystick * SDLCALL SDL_GetJoystickFromPlayerIndex(int player_index); |
386 | |
387 | /** |
388 | * The structure that describes a virtual joystick touchpad. |
389 | * |
390 | * \since This struct is available since SDL 3.2.0. |
391 | * |
392 | * \sa SDL_VirtualJoystickDesc |
393 | */ |
394 | typedef struct SDL_VirtualJoystickTouchpadDesc |
395 | { |
396 | Uint16 nfingers; /**< the number of simultaneous fingers on this touchpad */ |
397 | Uint16 padding[3]; |
398 | } SDL_VirtualJoystickTouchpadDesc; |
399 | |
400 | /** |
401 | * The structure that describes a virtual joystick sensor. |
402 | * |
403 | * \since This struct is available since SDL 3.2.0. |
404 | * |
405 | * \sa SDL_VirtualJoystickDesc |
406 | */ |
407 | typedef struct SDL_VirtualJoystickSensorDesc |
408 | { |
409 | SDL_SensorType type; /**< the type of this sensor */ |
410 | float rate; /**< the update frequency of this sensor, may be 0.0f */ |
411 | } SDL_VirtualJoystickSensorDesc; |
412 | |
413 | /** |
414 | * The structure that describes a virtual joystick. |
415 | * |
416 | * This structure should be initialized using SDL_INIT_INTERFACE(). All |
417 | * elements of this structure are optional. |
418 | * |
419 | * \since This struct is available since SDL 3.2.0. |
420 | * |
421 | * \sa SDL_AttachVirtualJoystick |
422 | * \sa SDL_INIT_INTERFACE |
423 | * \sa SDL_VirtualJoystickSensorDesc |
424 | * \sa SDL_VirtualJoystickTouchpadDesc |
425 | */ |
426 | typedef struct SDL_VirtualJoystickDesc |
427 | { |
428 | Uint32 version; /**< the version of this interface */ |
429 | Uint16 type; /**< `SDL_JoystickType` */ |
430 | Uint16 padding; /**< unused */ |
431 | Uint16 vendor_id; /**< the USB vendor ID of this joystick */ |
432 | Uint16 product_id; /**< the USB product ID of this joystick */ |
433 | Uint16 naxes; /**< the number of axes on this joystick */ |
434 | Uint16 nbuttons; /**< the number of buttons on this joystick */ |
435 | Uint16 nballs; /**< the number of balls on this joystick */ |
436 | Uint16 nhats; /**< the number of hats on this joystick */ |
437 | Uint16 ntouchpads; /**< the number of touchpads on this joystick, requires `touchpads` to point at valid descriptions */ |
438 | Uint16 nsensors; /**< the number of sensors on this joystick, requires `sensors` to point at valid descriptions */ |
439 | Uint16 padding2[2]; /**< unused */ |
440 | Uint32 button_mask; /**< A mask of which buttons are valid for this controller |
441 | e.g. (1 << SDL_GAMEPAD_BUTTON_SOUTH) */ |
442 | Uint32 axis_mask; /**< A mask of which axes are valid for this controller |
443 | e.g. (1 << SDL_GAMEPAD_AXIS_LEFTX) */ |
444 | const char *name; /**< the name of the joystick */ |
445 | const SDL_VirtualJoystickTouchpadDesc *touchpads; /**< A pointer to an array of touchpad descriptions, required if `ntouchpads` is > 0 */ |
446 | const SDL_VirtualJoystickSensorDesc *sensors; /**< A pointer to an array of sensor descriptions, required if `nsensors` is > 0 */ |
447 | |
448 | void *userdata; /**< User data pointer passed to callbacks */ |
449 | void (SDLCALL *Update)(void *userdata); /**< Called when the joystick state should be updated */ |
450 | void (SDLCALL *SetPlayerIndex)(void *userdata, int player_index); /**< Called when the player index is set */ |
451 | bool (SDLCALL *Rumble)(void *userdata, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble); /**< Implements SDL_RumbleJoystick() */ |
452 | bool (SDLCALL *RumbleTriggers)(void *userdata, Uint16 left_rumble, Uint16 right_rumble); /**< Implements SDL_RumbleJoystickTriggers() */ |
453 | bool (SDLCALL *SetLED)(void *userdata, Uint8 red, Uint8 green, Uint8 blue); /**< Implements SDL_SetJoystickLED() */ |
454 | bool (SDLCALL *SendEffect)(void *userdata, const void *data, int size); /**< Implements SDL_SendJoystickEffect() */ |
455 | bool (SDLCALL *SetSensorsEnabled)(void *userdata, bool enabled); /**< Implements SDL_SetGamepadSensorEnabled() */ |
456 | void (SDLCALL *Cleanup)(void *userdata); /**< Cleans up the userdata when the joystick is detached */ |
457 | } SDL_VirtualJoystickDesc; |
458 | |
459 | /* Check the size of SDL_VirtualJoystickDesc |
460 | * |
461 | * If this assert fails, either the compiler is padding to an unexpected size, |
462 | * or the interface has been updated and this should be updated to match and |
463 | * the code using this interface should be updated to handle the old version. |
464 | */ |
465 | SDL_COMPILE_TIME_ASSERT(SDL_VirtualJoystickDesc_SIZE, |
466 | (sizeof(void *) == 4 && sizeof(SDL_VirtualJoystickDesc) == 84) || |
467 | (sizeof(void *) == 8 && sizeof(SDL_VirtualJoystickDesc) == 136)); |
468 | |
469 | /** |
470 | * Attach a new virtual joystick. |
471 | * |
472 | * \param desc joystick description, initialized using SDL_INIT_INTERFACE(). |
473 | * \returns the joystick instance ID, or 0 on failure; call SDL_GetError() for |
474 | * more information. |
475 | * |
476 | * \since This function is available since SDL 3.2.0. |
477 | * |
478 | * \sa SDL_DetachVirtualJoystick |
479 | */ |
480 | extern SDL_DECLSPEC SDL_JoystickID SDLCALL SDL_AttachVirtualJoystick(const SDL_VirtualJoystickDesc *desc); |
481 | |
482 | /** |
483 | * Detach a virtual joystick. |
484 | * |
485 | * \param instance_id the joystick instance ID, previously returned from |
486 | * SDL_AttachVirtualJoystick(). |
487 | * \returns true on success or false on failure; call SDL_GetError() for more |
488 | * information. |
489 | * |
490 | * \since This function is available since SDL 3.2.0. |
491 | * |
492 | * \sa SDL_AttachVirtualJoystick |
493 | */ |
494 | extern SDL_DECLSPEC bool SDLCALL SDL_DetachVirtualJoystick(SDL_JoystickID instance_id); |
495 | |
496 | /** |
497 | * Query whether or not a joystick is virtual. |
498 | * |
499 | * \param instance_id the joystick instance ID. |
500 | * \returns true if the joystick is virtual, false otherwise. |
501 | * |
502 | * \since This function is available since SDL 3.2.0. |
503 | */ |
504 | extern SDL_DECLSPEC bool SDLCALL SDL_IsJoystickVirtual(SDL_JoystickID instance_id); |
505 | |
506 | /** |
507 | * Set the state of an axis on an opened virtual joystick. |
508 | * |
509 | * Please note that values set here will not be applied until the next call to |
510 | * SDL_UpdateJoysticks, which can either be called directly, or can be called |
511 | * indirectly through various other SDL APIs, including, but not limited to |
512 | * the following: SDL_PollEvent, SDL_PumpEvents, SDL_WaitEventTimeout, |
513 | * SDL_WaitEvent. |
514 | * |
515 | * Note that when sending trigger axes, you should scale the value to the full |
516 | * range of Sint16. For example, a trigger at rest would have the value of |
517 | * `SDL_JOYSTICK_AXIS_MIN`. |
518 | * |
519 | * \param joystick the virtual joystick on which to set state. |
520 | * \param axis the index of the axis on the virtual joystick to update. |
521 | * \param value the new value for the specified axis. |
522 | * \returns true on success or false on failure; call SDL_GetError() for more |
523 | * information. |
524 | * |
525 | * \since This function is available since SDL 3.2.0. |
526 | */ |
527 | extern SDL_DECLSPEC bool SDLCALL SDL_SetJoystickVirtualAxis(SDL_Joystick *joystick, int axis, Sint16 value); |
528 | |
529 | /** |
530 | * Generate ball motion on an opened virtual joystick. |
531 | * |
532 | * Please note that values set here will not be applied until the next call to |
533 | * SDL_UpdateJoysticks, which can either be called directly, or can be called |
534 | * indirectly through various other SDL APIs, including, but not limited to |
535 | * the following: SDL_PollEvent, SDL_PumpEvents, SDL_WaitEventTimeout, |
536 | * SDL_WaitEvent. |
537 | * |
538 | * \param joystick the virtual joystick on which to set state. |
539 | * \param ball the index of the ball on the virtual joystick to update. |
540 | * \param xrel the relative motion on the X axis. |
541 | * \param yrel the relative motion on the Y axis. |
542 | * \returns true on success or false on failure; call SDL_GetError() for more |
543 | * information. |
544 | * |
545 | * \since This function is available since SDL 3.2.0. |
546 | */ |
547 | extern SDL_DECLSPEC bool SDLCALL SDL_SetJoystickVirtualBall(SDL_Joystick *joystick, int ball, Sint16 xrel, Sint16 yrel); |
548 | |
549 | /** |
550 | * Set the state of a button on an opened virtual joystick. |
551 | * |
552 | * Please note that values set here will not be applied until the next call to |
553 | * SDL_UpdateJoysticks, which can either be called directly, or can be called |
554 | * indirectly through various other SDL APIs, including, but not limited to |
555 | * the following: SDL_PollEvent, SDL_PumpEvents, SDL_WaitEventTimeout, |
556 | * SDL_WaitEvent. |
557 | * |
558 | * \param joystick the virtual joystick on which to set state. |
559 | * \param button the index of the button on the virtual joystick to update. |
560 | * \param down true if the button is pressed, false otherwise. |
561 | * \returns true on success or false on failure; call SDL_GetError() for more |
562 | * information. |
563 | * |
564 | * \since This function is available since SDL 3.2.0. |
565 | */ |
566 | extern SDL_DECLSPEC bool SDLCALL SDL_SetJoystickVirtualButton(SDL_Joystick *joystick, int button, bool down); |
567 | |
568 | /** |
569 | * Set the state of a hat on an opened virtual joystick. |
570 | * |
571 | * Please note that values set here will not be applied until the next call to |
572 | * SDL_UpdateJoysticks, which can either be called directly, or can be called |
573 | * indirectly through various other SDL APIs, including, but not limited to |
574 | * the following: SDL_PollEvent, SDL_PumpEvents, SDL_WaitEventTimeout, |
575 | * SDL_WaitEvent. |
576 | * |
577 | * \param joystick the virtual joystick on which to set state. |
578 | * \param hat the index of the hat on the virtual joystick to update. |
579 | * \param value the new value for the specified hat. |
580 | * \returns true on success or false on failure; call SDL_GetError() for more |
581 | * information. |
582 | * |
583 | * \since This function is available since SDL 3.2.0. |
584 | */ |
585 | extern SDL_DECLSPEC bool SDLCALL SDL_SetJoystickVirtualHat(SDL_Joystick *joystick, int hat, Uint8 value); |
586 | |
587 | /** |
588 | * Set touchpad finger state on an opened virtual joystick. |
589 | * |
590 | * Please note that values set here will not be applied until the next call to |
591 | * SDL_UpdateJoysticks, which can either be called directly, or can be called |
592 | * indirectly through various other SDL APIs, including, but not limited to |
593 | * the following: SDL_PollEvent, SDL_PumpEvents, SDL_WaitEventTimeout, |
594 | * SDL_WaitEvent. |
595 | * |
596 | * \param joystick the virtual joystick on which to set state. |
597 | * \param touchpad the index of the touchpad on the virtual joystick to |
598 | * update. |
599 | * \param finger the index of the finger on the touchpad to set. |
600 | * \param down true if the finger is pressed, false if the finger is released. |
601 | * \param x the x coordinate of the finger on the touchpad, normalized 0 to 1, |
602 | * with the origin in the upper left. |
603 | * \param y the y coordinate of the finger on the touchpad, normalized 0 to 1, |
604 | * with the origin in the upper left. |
605 | * \param pressure the pressure of the finger. |
606 | * \returns true on success or false on failure; call SDL_GetError() for more |
607 | * information. |
608 | * |
609 | * \since This function is available since SDL 3.2.0. |
610 | */ |
611 | extern SDL_DECLSPEC bool SDLCALL SDL_SetJoystickVirtualTouchpad(SDL_Joystick *joystick, int touchpad, int finger, bool down, float x, float y, float pressure); |
612 | |
613 | /** |
614 | * Send a sensor update for an opened virtual joystick. |
615 | * |
616 | * Please note that values set here will not be applied until the next call to |
617 | * SDL_UpdateJoysticks, which can either be called directly, or can be called |
618 | * indirectly through various other SDL APIs, including, but not limited to |
619 | * the following: SDL_PollEvent, SDL_PumpEvents, SDL_WaitEventTimeout, |
620 | * SDL_WaitEvent. |
621 | * |
622 | * \param joystick the virtual joystick on which to set state. |
623 | * \param type the type of the sensor on the virtual joystick to update. |
624 | * \param sensor_timestamp a 64-bit timestamp in nanoseconds associated with |
625 | * the sensor reading. |
626 | * \param data the data associated with the sensor reading. |
627 | * \param num_values the number of values pointed to by `data`. |
628 | * \returns true on success or false on failure; call SDL_GetError() for more |
629 | * information. |
630 | * |
631 | * \since This function is available since SDL 3.2.0. |
632 | */ |
633 | extern SDL_DECLSPEC bool SDLCALL SDL_SendJoystickVirtualSensorData(SDL_Joystick *joystick, SDL_SensorType type, Uint64 sensor_timestamp, const float *data, int num_values); |
634 | |
635 | /** |
636 | * Get the properties associated with a joystick. |
637 | * |
638 | * The following read-only properties are provided by SDL: |
639 | * |
640 | * - `SDL_PROP_JOYSTICK_CAP_MONO_LED_BOOLEAN`: true if this joystick has an |
641 | * LED that has adjustable brightness |
642 | * - `SDL_PROP_JOYSTICK_CAP_RGB_LED_BOOLEAN`: true if this joystick has an LED |
643 | * that has adjustable color |
644 | * - `SDL_PROP_JOYSTICK_CAP_PLAYER_LED_BOOLEAN`: true if this joystick has a |
645 | * player LED |
646 | * - `SDL_PROP_JOYSTICK_CAP_RUMBLE_BOOLEAN`: true if this joystick has |
647 | * left/right rumble |
648 | * - `SDL_PROP_JOYSTICK_CAP_TRIGGER_RUMBLE_BOOLEAN`: true if this joystick has |
649 | * simple trigger rumble |
650 | * |
651 | * \param joystick the SDL_Joystick obtained from SDL_OpenJoystick(). |
652 | * \returns a valid property ID on success or 0 on failure; call |
653 | * SDL_GetError() for more information. |
654 | * |
655 | * \since This function is available since SDL 3.2.0. |
656 | */ |
657 | extern SDL_DECLSPEC SDL_PropertiesID SDLCALL SDL_GetJoystickProperties(SDL_Joystick *joystick); |
658 | |
659 | #define SDL_PROP_JOYSTICK_CAP_MONO_LED_BOOLEAN "SDL.joystick.cap.mono_led" |
660 | #define SDL_PROP_JOYSTICK_CAP_RGB_LED_BOOLEAN "SDL.joystick.cap.rgb_led" |
661 | #define SDL_PROP_JOYSTICK_CAP_PLAYER_LED_BOOLEAN "SDL.joystick.cap.player_led" |
662 | #define SDL_PROP_JOYSTICK_CAP_RUMBLE_BOOLEAN "SDL.joystick.cap.rumble" |
663 | #define SDL_PROP_JOYSTICK_CAP_TRIGGER_RUMBLE_BOOLEAN "SDL.joystick.cap.trigger_rumble" |
664 | |
665 | /** |
666 | * Get the implementation dependent name of a joystick. |
667 | * |
668 | * \param joystick the SDL_Joystick obtained from SDL_OpenJoystick(). |
669 | * \returns the name of the selected joystick. If no name can be found, this |
670 | * function returns NULL; call SDL_GetError() for more information. |
671 | * |
672 | * \since This function is available since SDL 3.2.0. |
673 | * |
674 | * \sa SDL_GetJoystickNameForID |
675 | */ |
676 | extern SDL_DECLSPEC const char * SDLCALL SDL_GetJoystickName(SDL_Joystick *joystick); |
677 | |
678 | /** |
679 | * Get the implementation dependent path of a joystick. |
680 | * |
681 | * \param joystick the SDL_Joystick obtained from SDL_OpenJoystick(). |
682 | * \returns the path of the selected joystick. If no path can be found, this |
683 | * function returns NULL; call SDL_GetError() for more information. |
684 | * |
685 | * \since This function is available since SDL 3.2.0. |
686 | * |
687 | * \sa SDL_GetJoystickPathForID |
688 | */ |
689 | extern SDL_DECLSPEC const char * SDLCALL SDL_GetJoystickPath(SDL_Joystick *joystick); |
690 | |
691 | /** |
692 | * Get the player index of an opened joystick. |
693 | * |
694 | * For XInput controllers this returns the XInput user index. Many joysticks |
695 | * will not be able to supply this information. |
696 | * |
697 | * \param joystick the SDL_Joystick obtained from SDL_OpenJoystick(). |
698 | * \returns the player index, or -1 if it's not available. |
699 | * |
700 | * \since This function is available since SDL 3.2.0. |
701 | * |
702 | * \sa SDL_SetJoystickPlayerIndex |
703 | */ |
704 | extern SDL_DECLSPEC int SDLCALL SDL_GetJoystickPlayerIndex(SDL_Joystick *joystick); |
705 | |
706 | /** |
707 | * Set the player index of an opened joystick. |
708 | * |
709 | * \param joystick the SDL_Joystick obtained from SDL_OpenJoystick(). |
710 | * \param player_index player index to assign to this joystick, or -1 to clear |
711 | * the player index and turn off player LEDs. |
712 | * \returns true on success or false on failure; call SDL_GetError() for more |
713 | * information. |
714 | * |
715 | * \since This function is available since SDL 3.2.0. |
716 | * |
717 | * \sa SDL_GetJoystickPlayerIndex |
718 | */ |
719 | extern SDL_DECLSPEC bool SDLCALL SDL_SetJoystickPlayerIndex(SDL_Joystick *joystick, int player_index); |
720 | |
721 | /** |
722 | * Get the implementation-dependent GUID for the joystick. |
723 | * |
724 | * This function requires an open joystick. |
725 | * |
726 | * \param joystick the SDL_Joystick obtained from SDL_OpenJoystick(). |
727 | * \returns the GUID of the given joystick. If called on an invalid index, |
728 | * this function returns a zero GUID; call SDL_GetError() for more |
729 | * information. |
730 | * |
731 | * \since This function is available since SDL 3.2.0. |
732 | * |
733 | * \sa SDL_GetJoystickGUIDForID |
734 | * \sa SDL_GUIDToString |
735 | */ |
736 | extern SDL_DECLSPEC SDL_GUID SDLCALL SDL_GetJoystickGUID(SDL_Joystick *joystick); |
737 | |
738 | /** |
739 | * Get the USB vendor ID of an opened joystick, if available. |
740 | * |
741 | * If the vendor ID isn't available this function returns 0. |
742 | * |
743 | * \param joystick the SDL_Joystick obtained from SDL_OpenJoystick(). |
744 | * \returns the USB vendor ID of the selected joystick, or 0 if unavailable. |
745 | * |
746 | * \since This function is available since SDL 3.2.0. |
747 | * |
748 | * \sa SDL_GetJoystickVendorForID |
749 | */ |
750 | extern SDL_DECLSPEC Uint16 SDLCALL SDL_GetJoystickVendor(SDL_Joystick *joystick); |
751 | |
752 | /** |
753 | * Get the USB product ID of an opened joystick, if available. |
754 | * |
755 | * If the product ID isn't available this function returns 0. |
756 | * |
757 | * \param joystick the SDL_Joystick obtained from SDL_OpenJoystick(). |
758 | * \returns the USB product ID of the selected joystick, or 0 if unavailable. |
759 | * |
760 | * \since This function is available since SDL 3.2.0. |
761 | * |
762 | * \sa SDL_GetJoystickProductForID |
763 | */ |
764 | extern SDL_DECLSPEC Uint16 SDLCALL SDL_GetJoystickProduct(SDL_Joystick *joystick); |
765 | |
766 | /** |
767 | * Get the product version of an opened joystick, if available. |
768 | * |
769 | * If the product version isn't available this function returns 0. |
770 | * |
771 | * \param joystick the SDL_Joystick obtained from SDL_OpenJoystick(). |
772 | * \returns the product version of the selected joystick, or 0 if unavailable. |
773 | * |
774 | * \since This function is available since SDL 3.2.0. |
775 | * |
776 | * \sa SDL_GetJoystickProductVersionForID |
777 | */ |
778 | extern SDL_DECLSPEC Uint16 SDLCALL SDL_GetJoystickProductVersion(SDL_Joystick *joystick); |
779 | |
780 | /** |
781 | * Get the firmware version of an opened joystick, if available. |
782 | * |
783 | * If the firmware version isn't available this function returns 0. |
784 | * |
785 | * \param joystick the SDL_Joystick obtained from SDL_OpenJoystick(). |
786 | * \returns the firmware version of the selected joystick, or 0 if |
787 | * unavailable. |
788 | * |
789 | * \since This function is available since SDL 3.2.0. |
790 | */ |
791 | extern SDL_DECLSPEC Uint16 SDLCALL SDL_GetJoystickFirmwareVersion(SDL_Joystick *joystick); |
792 | |
793 | /** |
794 | * Get the serial number of an opened joystick, if available. |
795 | * |
796 | * Returns the serial number of the joystick, or NULL if it is not available. |
797 | * |
798 | * \param joystick the SDL_Joystick obtained from SDL_OpenJoystick(). |
799 | * \returns the serial number of the selected joystick, or NULL if |
800 | * unavailable. |
801 | * |
802 | * \since This function is available since SDL 3.2.0. |
803 | */ |
804 | extern SDL_DECLSPEC const char * SDLCALL SDL_GetJoystickSerial(SDL_Joystick *joystick); |
805 | |
806 | /** |
807 | * Get the type of an opened joystick. |
808 | * |
809 | * \param joystick the SDL_Joystick obtained from SDL_OpenJoystick(). |
810 | * \returns the SDL_JoystickType of the selected joystick. |
811 | * |
812 | * \since This function is available since SDL 3.2.0. |
813 | * |
814 | * \sa SDL_GetJoystickTypeForID |
815 | */ |
816 | extern SDL_DECLSPEC SDL_JoystickType SDLCALL SDL_GetJoystickType(SDL_Joystick *joystick); |
817 | |
818 | /** |
819 | * Get the device information encoded in a SDL_GUID structure. |
820 | * |
821 | * \param guid the SDL_GUID you wish to get info about. |
822 | * \param vendor a pointer filled in with the device VID, or 0 if not |
823 | * available. |
824 | * \param product a pointer filled in with the device PID, or 0 if not |
825 | * available. |
826 | * \param version a pointer filled in with the device version, or 0 if not |
827 | * available. |
828 | * \param crc16 a pointer filled in with a CRC used to distinguish different |
829 | * products with the same VID/PID, or 0 if not available. |
830 | * |
831 | * \since This function is available since SDL 3.2.0. |
832 | * |
833 | * \sa SDL_GetJoystickGUIDForID |
834 | */ |
835 | extern SDL_DECLSPEC void SDLCALL SDL_GetJoystickGUIDInfo(SDL_GUID guid, Uint16 *vendor, Uint16 *product, Uint16 *version, Uint16 *crc16); |
836 | |
837 | /** |
838 | * Get the status of a specified joystick. |
839 | * |
840 | * \param joystick the joystick to query. |
841 | * \returns true if the joystick has been opened, false if it has not; call |
842 | * SDL_GetError() for more information. |
843 | * |
844 | * \since This function is available since SDL 3.2.0. |
845 | */ |
846 | extern SDL_DECLSPEC bool SDLCALL SDL_JoystickConnected(SDL_Joystick *joystick); |
847 | |
848 | /** |
849 | * Get the instance ID of an opened joystick. |
850 | * |
851 | * \param joystick an SDL_Joystick structure containing joystick information. |
852 | * \returns the instance ID of the specified joystick on success or 0 on |
853 | * failure; call SDL_GetError() for more information. |
854 | * |
855 | * \since This function is available since SDL 3.2.0. |
856 | */ |
857 | extern SDL_DECLSPEC SDL_JoystickID SDLCALL SDL_GetJoystickID(SDL_Joystick *joystick); |
858 | |
859 | /** |
860 | * Get the number of general axis controls on a joystick. |
861 | * |
862 | * Often, the directional pad on a game controller will either look like 4 |
863 | * separate buttons or a POV hat, and not axes, but all of this is up to the |
864 | * device and platform. |
865 | * |
866 | * \param joystick an SDL_Joystick structure containing joystick information. |
867 | * \returns the number of axis controls/number of axes on success or -1 on |
868 | * failure; call SDL_GetError() for more information. |
869 | * |
870 | * \since This function is available since SDL 3.2.0. |
871 | * |
872 | * \sa SDL_GetJoystickAxis |
873 | * \sa SDL_GetNumJoystickBalls |
874 | * \sa SDL_GetNumJoystickButtons |
875 | * \sa SDL_GetNumJoystickHats |
876 | */ |
877 | extern SDL_DECLSPEC int SDLCALL SDL_GetNumJoystickAxes(SDL_Joystick *joystick); |
878 | |
879 | /** |
880 | * Get the number of trackballs on a joystick. |
881 | * |
882 | * Joystick trackballs have only relative motion events associated with them |
883 | * and their state cannot be polled. |
884 | * |
885 | * Most joysticks do not have trackballs. |
886 | * |
887 | * \param joystick an SDL_Joystick structure containing joystick information. |
888 | * \returns the number of trackballs on success or -1 on failure; call |
889 | * SDL_GetError() for more information. |
890 | * |
891 | * \since This function is available since SDL 3.2.0. |
892 | * |
893 | * \sa SDL_GetJoystickBall |
894 | * \sa SDL_GetNumJoystickAxes |
895 | * \sa SDL_GetNumJoystickButtons |
896 | * \sa SDL_GetNumJoystickHats |
897 | */ |
898 | extern SDL_DECLSPEC int SDLCALL SDL_GetNumJoystickBalls(SDL_Joystick *joystick); |
899 | |
900 | /** |
901 | * Get the number of POV hats on a joystick. |
902 | * |
903 | * \param joystick an SDL_Joystick structure containing joystick information. |
904 | * \returns the number of POV hats on success or -1 on failure; call |
905 | * SDL_GetError() for more information. |
906 | * |
907 | * \since This function is available since SDL 3.2.0. |
908 | * |
909 | * \sa SDL_GetJoystickHat |
910 | * \sa SDL_GetNumJoystickAxes |
911 | * \sa SDL_GetNumJoystickBalls |
912 | * \sa SDL_GetNumJoystickButtons |
913 | */ |
914 | extern SDL_DECLSPEC int SDLCALL SDL_GetNumJoystickHats(SDL_Joystick *joystick); |
915 | |
916 | /** |
917 | * Get the number of buttons on a joystick. |
918 | * |
919 | * \param joystick an SDL_Joystick structure containing joystick information. |
920 | * \returns the number of buttons on success or -1 on failure; call |
921 | * SDL_GetError() for more information. |
922 | * |
923 | * \since This function is available since SDL 3.2.0. |
924 | * |
925 | * \sa SDL_GetJoystickButton |
926 | * \sa SDL_GetNumJoystickAxes |
927 | * \sa SDL_GetNumJoystickBalls |
928 | * \sa SDL_GetNumJoystickHats |
929 | */ |
930 | extern SDL_DECLSPEC int SDLCALL SDL_GetNumJoystickButtons(SDL_Joystick *joystick); |
931 | |
932 | /** |
933 | * Set the state of joystick event processing. |
934 | * |
935 | * If joystick events are disabled, you must call SDL_UpdateJoysticks() |
936 | * yourself and check the state of the joystick when you want joystick |
937 | * information. |
938 | * |
939 | * \param enabled whether to process joystick events or not. |
940 | * |
941 | * \since This function is available since SDL 3.2.0. |
942 | * |
943 | * \sa SDL_JoystickEventsEnabled |
944 | * \sa SDL_UpdateJoysticks |
945 | */ |
946 | extern SDL_DECLSPEC void SDLCALL SDL_SetJoystickEventsEnabled(bool enabled); |
947 | |
948 | /** |
949 | * Query the state of joystick event processing. |
950 | * |
951 | * If joystick events are disabled, you must call SDL_UpdateJoysticks() |
952 | * yourself and check the state of the joystick when you want joystick |
953 | * information. |
954 | * |
955 | * \returns true if joystick events are being processed, false otherwise. |
956 | * |
957 | * \since This function is available since SDL 3.2.0. |
958 | * |
959 | * \sa SDL_SetJoystickEventsEnabled |
960 | */ |
961 | extern SDL_DECLSPEC bool SDLCALL SDL_JoystickEventsEnabled(void); |
962 | |
963 | /** |
964 | * Update the current state of the open joysticks. |
965 | * |
966 | * This is called automatically by the event loop if any joystick events are |
967 | * enabled. |
968 | * |
969 | * \since This function is available since SDL 3.2.0. |
970 | */ |
971 | extern SDL_DECLSPEC void SDLCALL SDL_UpdateJoysticks(void); |
972 | |
973 | /** |
974 | * Get the current state of an axis control on a joystick. |
975 | * |
976 | * SDL makes no promises about what part of the joystick any given axis refers |
977 | * to. Your game should have some sort of configuration UI to let users |
978 | * specify what each axis should be bound to. Alternately, SDL's higher-level |
979 | * Game Controller API makes a great effort to apply order to this lower-level |
980 | * interface, so you know that a specific axis is the "left thumb stick," etc. |
981 | * |
982 | * The value returned by SDL_GetJoystickAxis() is a signed integer (-32768 to |
983 | * 32767) representing the current position of the axis. It may be necessary |
984 | * to impose certain tolerances on these values to account for jitter. |
985 | * |
986 | * \param joystick an SDL_Joystick structure containing joystick information. |
987 | * \param axis the axis to query; the axis indices start at index 0. |
988 | * \returns a 16-bit signed integer representing the current position of the |
989 | * axis or 0 on failure; call SDL_GetError() for more information. |
990 | * |
991 | * \since This function is available since SDL 3.2.0. |
992 | * |
993 | * \sa SDL_GetNumJoystickAxes |
994 | */ |
995 | extern SDL_DECLSPEC Sint16 SDLCALL SDL_GetJoystickAxis(SDL_Joystick *joystick, int axis); |
996 | |
997 | /** |
998 | * Get the initial state of an axis control on a joystick. |
999 | * |
1000 | * The state is a value ranging from -32768 to 32767. |
1001 | * |
1002 | * The axis indices start at index 0. |
1003 | * |
1004 | * \param joystick an SDL_Joystick structure containing joystick information. |
1005 | * \param axis the axis to query; the axis indices start at index 0. |
1006 | * \param state upon return, the initial value is supplied here. |
1007 | * \returns true if this axis has any initial value, or false if not. |
1008 | * |
1009 | * \since This function is available since SDL 3.2.0. |
1010 | */ |
1011 | extern SDL_DECLSPEC bool SDLCALL SDL_GetJoystickAxisInitialState(SDL_Joystick *joystick, int axis, Sint16 *state); |
1012 | |
1013 | /** |
1014 | * Get the ball axis change since the last poll. |
1015 | * |
1016 | * Trackballs can only return relative motion since the last call to |
1017 | * SDL_GetJoystickBall(), these motion deltas are placed into `dx` and `dy`. |
1018 | * |
1019 | * Most joysticks do not have trackballs. |
1020 | * |
1021 | * \param joystick the SDL_Joystick to query. |
1022 | * \param ball the ball index to query; ball indices start at index 0. |
1023 | * \param dx stores the difference in the x axis position since the last poll. |
1024 | * \param dy stores the difference in the y axis position since the last poll. |
1025 | * \returns true on success or false on failure; call SDL_GetError() for more |
1026 | * information. |
1027 | * |
1028 | * \since This function is available since SDL 3.2.0. |
1029 | * |
1030 | * \sa SDL_GetNumJoystickBalls |
1031 | */ |
1032 | extern SDL_DECLSPEC bool SDLCALL SDL_GetJoystickBall(SDL_Joystick *joystick, int ball, int *dx, int *dy); |
1033 | |
1034 | /** |
1035 | * Get the current state of a POV hat on a joystick. |
1036 | * |
1037 | * The returned value will be one of the `SDL_HAT_*` values. |
1038 | * |
1039 | * \param joystick an SDL_Joystick structure containing joystick information. |
1040 | * \param hat the hat index to get the state from; indices start at index 0. |
1041 | * \returns the current hat position. |
1042 | * |
1043 | * \since This function is available since SDL 3.2.0. |
1044 | * |
1045 | * \sa SDL_GetNumJoystickHats |
1046 | */ |
1047 | extern SDL_DECLSPEC Uint8 SDLCALL SDL_GetJoystickHat(SDL_Joystick *joystick, int hat); |
1048 | |
1049 | #define SDL_HAT_CENTERED 0x00u |
1050 | #define SDL_HAT_UP 0x01u |
1051 | #define SDL_HAT_RIGHT 0x02u |
1052 | #define SDL_HAT_DOWN 0x04u |
1053 | #define SDL_HAT_LEFT 0x08u |
1054 | #define SDL_HAT_RIGHTUP (SDL_HAT_RIGHT|SDL_HAT_UP) |
1055 | #define SDL_HAT_RIGHTDOWN (SDL_HAT_RIGHT|SDL_HAT_DOWN) |
1056 | #define SDL_HAT_LEFTUP (SDL_HAT_LEFT|SDL_HAT_UP) |
1057 | #define SDL_HAT_LEFTDOWN (SDL_HAT_LEFT|SDL_HAT_DOWN) |
1058 | |
1059 | /** |
1060 | * Get the current state of a button on a joystick. |
1061 | * |
1062 | * \param joystick an SDL_Joystick structure containing joystick information. |
1063 | * \param button the button index to get the state from; indices start at |
1064 | * index 0. |
1065 | * \returns true if the button is pressed, false otherwise. |
1066 | * |
1067 | * \since This function is available since SDL 3.2.0. |
1068 | * |
1069 | * \sa SDL_GetNumJoystickButtons |
1070 | */ |
1071 | extern SDL_DECLSPEC bool SDLCALL SDL_GetJoystickButton(SDL_Joystick *joystick, int button); |
1072 | |
1073 | /** |
1074 | * Start a rumble effect. |
1075 | * |
1076 | * Each call to this function cancels any previous rumble effect, and calling |
1077 | * it with 0 intensity stops any rumbling. |
1078 | * |
1079 | * This function requires you to process SDL events or call |
1080 | * SDL_UpdateJoysticks() to update rumble state. |
1081 | * |
1082 | * \param joystick the joystick to vibrate. |
1083 | * \param low_frequency_rumble the intensity of the low frequency (left) |
1084 | * rumble motor, from 0 to 0xFFFF. |
1085 | * \param high_frequency_rumble the intensity of the high frequency (right) |
1086 | * rumble motor, from 0 to 0xFFFF. |
1087 | * \param duration_ms the duration of the rumble effect, in milliseconds. |
1088 | * \returns true, or false if rumble isn't supported on this joystick. |
1089 | * |
1090 | * \since This function is available since SDL 3.2.0. |
1091 | */ |
1092 | extern SDL_DECLSPEC bool SDLCALL SDL_RumbleJoystick(SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble, Uint32 duration_ms); |
1093 | |
1094 | /** |
1095 | * Start a rumble effect in the joystick's triggers. |
1096 | * |
1097 | * Each call to this function cancels any previous trigger rumble effect, and |
1098 | * calling it with 0 intensity stops any rumbling. |
1099 | * |
1100 | * Note that this is rumbling of the _triggers_ and not the game controller as |
1101 | * a whole. This is currently only supported on Xbox One controllers. If you |
1102 | * want the (more common) whole-controller rumble, use SDL_RumbleJoystick() |
1103 | * instead. |
1104 | * |
1105 | * This function requires you to process SDL events or call |
1106 | * SDL_UpdateJoysticks() to update rumble state. |
1107 | * |
1108 | * \param joystick the joystick to vibrate. |
1109 | * \param left_rumble the intensity of the left trigger rumble motor, from 0 |
1110 | * to 0xFFFF. |
1111 | * \param right_rumble the intensity of the right trigger rumble motor, from 0 |
1112 | * to 0xFFFF. |
1113 | * \param duration_ms the duration of the rumble effect, in milliseconds. |
1114 | * \returns true on success or false on failure; call SDL_GetError() for more |
1115 | * information. |
1116 | * |
1117 | * \since This function is available since SDL 3.2.0. |
1118 | * |
1119 | * \sa SDL_RumbleJoystick |
1120 | */ |
1121 | extern SDL_DECLSPEC bool SDLCALL SDL_RumbleJoystickTriggers(SDL_Joystick *joystick, Uint16 left_rumble, Uint16 right_rumble, Uint32 duration_ms); |
1122 | |
1123 | /** |
1124 | * Update a joystick's LED color. |
1125 | * |
1126 | * An example of a joystick LED is the light on the back of a PlayStation 4's |
1127 | * DualShock 4 controller. |
1128 | * |
1129 | * For joysticks with a single color LED, the maximum of the RGB values will |
1130 | * be used as the LED brightness. |
1131 | * |
1132 | * \param joystick the joystick to update. |
1133 | * \param red the intensity of the red LED. |
1134 | * \param green the intensity of the green LED. |
1135 | * \param blue the intensity of the blue LED. |
1136 | * \returns true on success or false on failure; call SDL_GetError() for more |
1137 | * information. |
1138 | * |
1139 | * \since This function is available since SDL 3.2.0. |
1140 | */ |
1141 | extern SDL_DECLSPEC bool SDLCALL SDL_SetJoystickLED(SDL_Joystick *joystick, Uint8 red, Uint8 green, Uint8 blue); |
1142 | |
1143 | /** |
1144 | * Send a joystick specific effect packet. |
1145 | * |
1146 | * \param joystick the joystick to affect. |
1147 | * \param data the data to send to the joystick. |
1148 | * \param size the size of the data to send to the joystick. |
1149 | * \returns true on success or false on failure; call SDL_GetError() for more |
1150 | * information. |
1151 | * |
1152 | * \since This function is available since SDL 3.2.0. |
1153 | */ |
1154 | extern SDL_DECLSPEC bool SDLCALL SDL_SendJoystickEffect(SDL_Joystick *joystick, const void *data, int size); |
1155 | |
1156 | /** |
1157 | * Close a joystick previously opened with SDL_OpenJoystick(). |
1158 | * |
1159 | * \param joystick the joystick device to close. |
1160 | * |
1161 | * \since This function is available since SDL 3.2.0. |
1162 | * |
1163 | * \sa SDL_OpenJoystick |
1164 | */ |
1165 | extern SDL_DECLSPEC void SDLCALL SDL_CloseJoystick(SDL_Joystick *joystick); |
1166 | |
1167 | /** |
1168 | * Get the connection state of a joystick. |
1169 | * |
1170 | * \param joystick the joystick to query. |
1171 | * \returns the connection state on success or |
1172 | * `SDL_JOYSTICK_CONNECTION_INVALID` on failure; call SDL_GetError() |
1173 | * for more information. |
1174 | * |
1175 | * \since This function is available since SDL 3.2.0. |
1176 | */ |
1177 | extern SDL_DECLSPEC SDL_JoystickConnectionState SDLCALL SDL_GetJoystickConnectionState(SDL_Joystick *joystick); |
1178 | |
1179 | /** |
1180 | * Get the battery state of a joystick. |
1181 | * |
1182 | * You should never take a battery status as absolute truth. Batteries |
1183 | * (especially failing batteries) are delicate hardware, and the values |
1184 | * reported here are best estimates based on what that hardware reports. It's |
1185 | * not uncommon for older batteries to lose stored power much faster than it |
1186 | * reports, or completely drain when reporting it has 20 percent left, etc. |
1187 | * |
1188 | * \param joystick the joystick to query. |
1189 | * \param percent a pointer filled in with the percentage of battery life |
1190 | * left, between 0 and 100, or NULL to ignore. This will be |
1191 | * filled in with -1 we can't determine a value or there is no |
1192 | * battery. |
1193 | * \returns the current battery state or `SDL_POWERSTATE_ERROR` on failure; |
1194 | * call SDL_GetError() for more information. |
1195 | * |
1196 | * \since This function is available since SDL 3.2.0. |
1197 | */ |
1198 | extern SDL_DECLSPEC SDL_PowerState SDLCALL SDL_GetJoystickPowerInfo(SDL_Joystick *joystick, int *percent); |
1199 | |
1200 | /* Ends C function definitions when using C++ */ |
1201 | #ifdef __cplusplus |
1202 | } |
1203 | #endif |
1204 | #include <SDL3/SDL_close_code.h> |
1205 | |
1206 | #endif /* SDL_joystick_h_ */ |
1207 | |