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