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 | #ifndef SDL_joystick_c_h_ |
23 | #define SDL_joystick_c_h_ |
24 | |
25 | #include "SDL_internal.h" |
26 | |
27 | // Useful functions and variables from SDL_joystick.c |
28 | |
29 | // Set up for C function definitions, even when using C++ |
30 | #ifdef __cplusplus |
31 | extern "C" { |
32 | #endif |
33 | |
34 | struct SDL_JoystickDriver; |
35 | struct SDL_SteamVirtualGamepadInfo; |
36 | |
37 | // Initialization and shutdown functions |
38 | extern bool SDL_InitJoysticks(void); |
39 | extern void SDL_QuitJoysticks(void); |
40 | |
41 | // Return whether the joystick system is currently initialized |
42 | extern bool SDL_JoysticksInitialized(void); |
43 | |
44 | // Return whether the joystick system is shutting down |
45 | extern bool SDL_JoysticksQuitting(void); |
46 | |
47 | // Return whether the joysticks are currently locked |
48 | extern bool SDL_JoysticksLocked(void); |
49 | |
50 | // Make sure we currently have the joysticks locked |
51 | extern void SDL_AssertJoysticksLocked(void) SDL_ASSERT_CAPABILITY(SDL_joystick_lock); |
52 | |
53 | // Function to return whether there are any joysticks opened by the application |
54 | extern bool SDL_JoysticksOpened(void); |
55 | |
56 | // Function to determine whether a device is currently detected by this driver |
57 | extern bool SDL_JoystickHandledByAnotherDriver(struct SDL_JoystickDriver *driver, Uint16 vendor_id, Uint16 product_id, Uint16 version, const char *name); |
58 | |
59 | /* Function to standardize the name for a controller |
60 | This should be freed with SDL_free() when no longer needed |
61 | */ |
62 | extern char *SDL_CreateJoystickName(Uint16 vendor, Uint16 product, const char *vendor_name, const char *product_name); |
63 | |
64 | // Function to create a GUID for a joystick based on the VID/PID and name |
65 | extern SDL_GUID SDL_CreateJoystickGUID(Uint16 bus, Uint16 vendor, Uint16 product, Uint16 version, const char *vendor_name, const char *product_name, Uint8 driver_signature, Uint8 driver_data); |
66 | |
67 | // Function to create a GUID for a joystick based on the name, with no VID/PID information |
68 | extern SDL_GUID SDL_CreateJoystickGUIDForName(const char *name); |
69 | |
70 | // Function to set the vendor field of a joystick GUID |
71 | extern void SDL_SetJoystickGUIDVendor(SDL_GUID *guid, Uint16 vendor); |
72 | |
73 | // Function to set the product field of a joystick GUID |
74 | extern void SDL_SetJoystickGUIDProduct(SDL_GUID *guid, Uint16 product); |
75 | |
76 | // Function to set the version field of a joystick GUID |
77 | extern void SDL_SetJoystickGUIDVersion(SDL_GUID *guid, Uint16 version); |
78 | |
79 | // Function to set the CRC field of a joystick GUID |
80 | extern void SDL_SetJoystickGUIDCRC(SDL_GUID *guid, Uint16 crc); |
81 | |
82 | // Function to return the type of a controller |
83 | extern SDL_GamepadType SDL_GetGamepadTypeFromVIDPID(Uint16 vendor, Uint16 product, const char *name, bool forUI); |
84 | extern SDL_GamepadType SDL_GetGamepadTypeFromGUID(SDL_GUID guid, const char *name); |
85 | |
86 | // Function to return whether a joystick GUID uses the version field |
87 | extern bool SDL_JoystickGUIDUsesVersion(SDL_GUID guid); |
88 | |
89 | // Function to return whether a joystick is an Xbox One controller |
90 | extern bool SDL_IsJoystickXboxOne(Uint16 vendor_id, Uint16 product_id); |
91 | |
92 | // Function to return whether a joystick is an Xbox One Elite controller |
93 | extern bool SDL_IsJoystickXboxOneElite(Uint16 vendor_id, Uint16 product_id); |
94 | |
95 | // Function to return whether a joystick is an Xbox Series X controller |
96 | extern bool SDL_IsJoystickXboxSeriesX(Uint16 vendor_id, Uint16 product_id); |
97 | |
98 | // Function to return whether a joystick is an Xbox One controller connected via Bluetooth |
99 | extern bool SDL_IsJoystickBluetoothXboxOne(Uint16 vendor_id, Uint16 product_id); |
100 | |
101 | // Function to return whether a joystick is a PS4 controller |
102 | extern bool SDL_IsJoystickPS4(Uint16 vendor_id, Uint16 product_id); |
103 | |
104 | // Function to return whether a joystick is a PS5 controller |
105 | extern bool SDL_IsJoystickPS5(Uint16 vendor_id, Uint16 product_id); |
106 | extern bool SDL_IsJoystickDualSenseEdge(Uint16 vendor_id, Uint16 product_id); |
107 | |
108 | // Function to return whether a joystick is a Nintendo Switch Pro controller |
109 | extern bool SDL_IsJoystickNintendoSwitchPro(Uint16 vendor_id, Uint16 product_id); |
110 | extern bool SDL_IsJoystickNintendoSwitchProInputOnly(Uint16 vendor_id, Uint16 product_id); |
111 | extern bool SDL_IsJoystickNintendoSwitchJoyCon(Uint16 vendor_id, Uint16 product_id); |
112 | extern bool SDL_IsJoystickNintendoSwitchJoyConLeft(Uint16 vendor_id, Uint16 product_id); |
113 | extern bool SDL_IsJoystickNintendoSwitchJoyConRight(Uint16 vendor_id, Uint16 product_id); |
114 | extern bool SDL_IsJoystickNintendoSwitchJoyConGrip(Uint16 vendor_id, Uint16 product_id); |
115 | extern bool SDL_IsJoystickNintendoSwitchJoyConPair(Uint16 vendor_id, Uint16 product_id); |
116 | |
117 | // Function to return whether a joystick is a Nintendo GameCube style controller |
118 | extern bool SDL_IsJoystickGameCube(Uint16 vendor_id, Uint16 product_id); |
119 | |
120 | // Function to return whether a joystick is an Amazon Luna controller |
121 | extern bool SDL_IsJoystickAmazonLunaController(Uint16 vendor_id, Uint16 product_id); |
122 | |
123 | // Function to return whether a joystick is a Google Stadia controller |
124 | extern bool SDL_IsJoystickGoogleStadiaController(Uint16 vendor_id, Uint16 product_id); |
125 | |
126 | // Function to return whether a joystick is an NVIDIA SHIELD controller |
127 | extern bool SDL_IsJoystickNVIDIASHIELDController(Uint16 vendor_id, Uint16 product_id); |
128 | |
129 | // Function to return whether a joystick is a Steam Virtual Gamepad |
130 | extern bool SDL_IsJoystickSteamVirtualGamepad(Uint16 vendor_id, Uint16 product_id, Uint16 version); |
131 | |
132 | // Function to return whether a joystick is a Steam Controller |
133 | extern bool SDL_IsJoystickSteamController(Uint16 vendor_id, Uint16 product_id); |
134 | |
135 | // Function to return whether a joystick is a HORI Steam controller |
136 | extern bool SDL_IsJoystickHoriSteamController(Uint16 vendor_id, Uint16 product_id); |
137 | |
138 | // Function to return whether a joystick is a Steam Deck |
139 | extern bool SDL_IsJoystickSteamDeck(Uint16 vendor_id, Uint16 product_id); |
140 | |
141 | // Function to return whether a joystick guid comes from the XInput driver |
142 | extern bool SDL_IsJoystickXInput(SDL_GUID guid); |
143 | |
144 | // Function to return whether a joystick guid comes from the WGI driver |
145 | extern bool SDL_IsJoystickWGI(SDL_GUID guid); |
146 | |
147 | // Function to return whether a joystick guid comes from the HIDAPI driver |
148 | extern bool SDL_IsJoystickHIDAPI(SDL_GUID guid); |
149 | |
150 | // Function to return whether a joystick guid comes from the MFI driver |
151 | extern bool SDL_IsJoystickMFI(SDL_GUID guid); |
152 | |
153 | // Function to return whether a joystick guid comes from the RAWINPUT driver |
154 | extern bool SDL_IsJoystickRAWINPUT(SDL_GUID guid); |
155 | |
156 | // Function to return whether a joystick guid comes from the Virtual driver |
157 | extern bool SDL_IsJoystickVIRTUAL(SDL_GUID guid); |
158 | |
159 | // Function to return whether a joystick is a wheel |
160 | bool SDL_IsJoystickWheel(Uint16 vendor_id, Uint16 product_id); |
161 | |
162 | // Function to return whether a joystick should be ignored |
163 | extern bool SDL_ShouldIgnoreJoystick(Uint16 vendor_id, Uint16 product_id, Uint16 version, const char *name); |
164 | |
165 | // Internal event queueing functions |
166 | extern void SDL_PrivateJoystickAddTouchpad(SDL_Joystick *joystick, int nfingers); |
167 | extern void SDL_PrivateJoystickAddSensor(SDL_Joystick *joystick, SDL_SensorType type, float rate); |
168 | extern void SDL_PrivateJoystickSensorRate(SDL_Joystick *joystick, SDL_SensorType type, float rate); |
169 | extern void SDL_PrivateJoystickAdded(SDL_JoystickID instance_id); |
170 | extern bool SDL_IsJoystickBeingAdded(void); |
171 | extern void SDL_PrivateJoystickRemoved(SDL_JoystickID instance_id); |
172 | extern void SDL_PrivateJoystickForceRecentering(SDL_Joystick *joystick); |
173 | extern void SDL_SendJoystickAxis(Uint64 timestamp, SDL_Joystick *joystick, Uint8 axis, Sint16 value); |
174 | extern void SDL_SendJoystickBall(Uint64 timestamp, SDL_Joystick *joystick, Uint8 ball, Sint16 xrel, Sint16 yrel); |
175 | extern void SDL_SendJoystickHat(Uint64 timestamp, SDL_Joystick *joystick, Uint8 hat, Uint8 value); |
176 | extern void SDL_SendJoystickButton(Uint64 timestamp, SDL_Joystick *joystick, Uint8 button, bool down); |
177 | extern void SDL_SendJoystickTouchpad(Uint64 timestamp, SDL_Joystick *joystick, int touchpad, int finger, bool down, float x, float y, float pressure); |
178 | extern void SDL_SendJoystickSensor(Uint64 timestamp, SDL_Joystick *joystick, SDL_SensorType type, Uint64 sensor_timestamp, const float *data, int num_values); |
179 | extern void SDL_SendJoystickPowerInfo(SDL_Joystick *joystick, SDL_PowerState state, int percent); |
180 | |
181 | // Function to get the Steam virtual gamepad info for a joystick |
182 | extern const struct SDL_SteamVirtualGamepadInfo *SDL_GetJoystickVirtualGamepadInfoForID(SDL_JoystickID instance_id); |
183 | |
184 | // Internal sanity checking functions |
185 | extern bool SDL_IsJoystickValid(SDL_Joystick *joystick); |
186 | |
187 | typedef enum |
188 | { |
189 | EMappingKind_None, |
190 | EMappingKind_Button, |
191 | EMappingKind_Axis, |
192 | EMappingKind_Hat, |
193 | } EMappingKind; |
194 | |
195 | typedef struct SDL_InputMapping |
196 | { |
197 | EMappingKind kind; |
198 | Uint8 target; |
199 | bool axis_reversed; |
200 | bool half_axis_positive; |
201 | bool half_axis_negative; |
202 | } SDL_InputMapping; |
203 | |
204 | typedef struct SDL_GamepadMapping |
205 | { |
206 | SDL_InputMapping a; |
207 | SDL_InputMapping b; |
208 | SDL_InputMapping x; |
209 | SDL_InputMapping y; |
210 | SDL_InputMapping back; |
211 | SDL_InputMapping guide; |
212 | SDL_InputMapping start; |
213 | SDL_InputMapping leftstick; |
214 | SDL_InputMapping rightstick; |
215 | SDL_InputMapping leftshoulder; |
216 | SDL_InputMapping rightshoulder; |
217 | SDL_InputMapping dpup; |
218 | SDL_InputMapping dpdown; |
219 | SDL_InputMapping dpleft; |
220 | SDL_InputMapping dpright; |
221 | SDL_InputMapping misc1; |
222 | SDL_InputMapping misc2; |
223 | SDL_InputMapping misc3; |
224 | SDL_InputMapping misc4; |
225 | SDL_InputMapping misc5; |
226 | SDL_InputMapping misc6; |
227 | SDL_InputMapping right_paddle1; |
228 | SDL_InputMapping left_paddle1; |
229 | SDL_InputMapping right_paddle2; |
230 | SDL_InputMapping left_paddle2; |
231 | SDL_InputMapping leftx; |
232 | SDL_InputMapping lefty; |
233 | SDL_InputMapping rightx; |
234 | SDL_InputMapping righty; |
235 | SDL_InputMapping lefttrigger; |
236 | SDL_InputMapping righttrigger; |
237 | SDL_InputMapping touchpad; |
238 | } SDL_GamepadMapping; |
239 | |
240 | // Function to get autodetected gamepad controller mapping from the driver |
241 | extern bool SDL_PrivateJoystickGetAutoGamepadMapping(SDL_JoystickID instance_id, |
242 | SDL_GamepadMapping *out); |
243 | |
244 | |
245 | typedef struct |
246 | { |
247 | const char *included_hint_name; |
248 | int num_included_entries; |
249 | int max_included_entries; |
250 | Uint32 *included_entries; |
251 | |
252 | const char *excluded_hint_name; |
253 | int num_excluded_entries; |
254 | int max_excluded_entries; |
255 | Uint32 *excluded_entries; |
256 | |
257 | int num_initial_entries; |
258 | Uint32 *initial_entries; |
259 | |
260 | bool initialized; |
261 | } SDL_vidpid_list; |
262 | |
263 | extern void SDL_LoadVIDPIDList(SDL_vidpid_list *list); |
264 | extern void SDL_LoadVIDPIDListFromHints(SDL_vidpid_list *list, const char *included_list, const char *excluded_list); |
265 | extern bool SDL_VIDPIDInList(Uint16 vendor_id, Uint16 product_id, const SDL_vidpid_list *list); |
266 | extern void SDL_FreeVIDPIDList(SDL_vidpid_list *list); |
267 | |
268 | // Ends C function definitions when using C++ |
269 | #ifdef __cplusplus |
270 | } |
271 | #endif |
272 | |
273 | #endif // SDL_joystick_c_h_ |
274 | |