Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/thirdparty/sdl/core/windows/SDL_xinput.h
9905 views
1
/*
2
Simple DirectMedia Layer
3
Copyright (C) 1997-2025 Sam Lantinga <[email protected]>
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
#include "SDL_internal.h"
22
23
#ifndef SDL_xinput_h_
24
#define SDL_xinput_h_
25
26
#include "SDL_windows.h"
27
28
#ifdef HAVE_XINPUT_H
29
#if defined(SDL_PLATFORM_XBOXONE) || defined(SDL_PLATFORM_XBOXSERIES)
30
// Xbox supports an XInput wrapper which is a C++-only header...
31
#include <math.h> // Required to compile with recent MSVC...
32
#include <XInputOnGameInput.h>
33
using namespace XInputOnGameInput;
34
#else
35
#include <xinput.h>
36
#endif
37
#endif // HAVE_XINPUT_H
38
39
#ifndef XUSER_MAX_COUNT
40
#define XUSER_MAX_COUNT 4
41
#endif
42
#ifndef XUSER_INDEX_ANY
43
#define XUSER_INDEX_ANY 0x000000FF
44
#endif
45
#ifndef XINPUT_CAPS_FFB_SUPPORTED
46
#define XINPUT_CAPS_FFB_SUPPORTED 0x0001
47
#endif
48
#ifndef XINPUT_CAPS_WIRELESS
49
#define XINPUT_CAPS_WIRELESS 0x0002
50
#endif
51
52
#ifndef XINPUT_DEVSUBTYPE_UNKNOWN
53
#define XINPUT_DEVSUBTYPE_UNKNOWN 0x00
54
#endif
55
#ifndef XINPUT_DEVSUBTYPE_GAMEPAD
56
#define XINPUT_DEVSUBTYPE_GAMEPAD 0x01
57
#endif
58
#ifndef XINPUT_DEVSUBTYPE_WHEEL
59
#define XINPUT_DEVSUBTYPE_WHEEL 0x02
60
#endif
61
#ifndef XINPUT_DEVSUBTYPE_ARCADE_STICK
62
#define XINPUT_DEVSUBTYPE_ARCADE_STICK 0x03
63
#endif
64
#ifndef XINPUT_DEVSUBTYPE_FLIGHT_STICK
65
#define XINPUT_DEVSUBTYPE_FLIGHT_STICK 0x04
66
#endif
67
#ifndef XINPUT_DEVSUBTYPE_DANCE_PAD
68
#define XINPUT_DEVSUBTYPE_DANCE_PAD 0x05
69
#endif
70
#ifndef XINPUT_DEVSUBTYPE_GUITAR
71
#define XINPUT_DEVSUBTYPE_GUITAR 0x06
72
#endif
73
#ifndef XINPUT_DEVSUBTYPE_GUITAR_ALTERNATE
74
#define XINPUT_DEVSUBTYPE_GUITAR_ALTERNATE 0x07
75
#endif
76
#ifndef XINPUT_DEVSUBTYPE_DRUM_KIT
77
#define XINPUT_DEVSUBTYPE_DRUM_KIT 0x08
78
#endif
79
#ifndef XINPUT_DEVSUBTYPE_GUITAR_BASS
80
#define XINPUT_DEVSUBTYPE_GUITAR_BASS 0x0B
81
#endif
82
#ifndef XINPUT_DEVSUBTYPE_ARCADE_PAD
83
#define XINPUT_DEVSUBTYPE_ARCADE_PAD 0x13
84
#endif
85
86
#ifndef XINPUT_FLAG_GAMEPAD
87
#define XINPUT_FLAG_GAMEPAD 0x01
88
#endif
89
90
#ifndef XINPUT_GAMEPAD_DPAD_UP
91
#define XINPUT_GAMEPAD_DPAD_UP 0x0001
92
#endif
93
#ifndef XINPUT_GAMEPAD_DPAD_DOWN
94
#define XINPUT_GAMEPAD_DPAD_DOWN 0x0002
95
#endif
96
#ifndef XINPUT_GAMEPAD_DPAD_LEFT
97
#define XINPUT_GAMEPAD_DPAD_LEFT 0x0004
98
#endif
99
#ifndef XINPUT_GAMEPAD_DPAD_RIGHT
100
#define XINPUT_GAMEPAD_DPAD_RIGHT 0x0008
101
#endif
102
#ifndef XINPUT_GAMEPAD_START
103
#define XINPUT_GAMEPAD_START 0x0010
104
#endif
105
#ifndef XINPUT_GAMEPAD_BACK
106
#define XINPUT_GAMEPAD_BACK 0x0020
107
#endif
108
#ifndef XINPUT_GAMEPAD_LEFT_THUMB
109
#define XINPUT_GAMEPAD_LEFT_THUMB 0x0040
110
#endif
111
#ifndef XINPUT_GAMEPAD_RIGHT_THUMB
112
#define XINPUT_GAMEPAD_RIGHT_THUMB 0x0080
113
#endif
114
#ifndef XINPUT_GAMEPAD_LEFT_SHOULDER
115
#define XINPUT_GAMEPAD_LEFT_SHOULDER 0x0100
116
#endif
117
#ifndef XINPUT_GAMEPAD_RIGHT_SHOULDER
118
#define XINPUT_GAMEPAD_RIGHT_SHOULDER 0x0200
119
#endif
120
#ifndef XINPUT_GAMEPAD_A
121
#define XINPUT_GAMEPAD_A 0x1000
122
#endif
123
#ifndef XINPUT_GAMEPAD_B
124
#define XINPUT_GAMEPAD_B 0x2000
125
#endif
126
#ifndef XINPUT_GAMEPAD_X
127
#define XINPUT_GAMEPAD_X 0x4000
128
#endif
129
#ifndef XINPUT_GAMEPAD_Y
130
#define XINPUT_GAMEPAD_Y 0x8000
131
#endif
132
133
#ifndef XINPUT_GAMEPAD_GUIDE
134
#define XINPUT_GAMEPAD_GUIDE 0x0400
135
#endif
136
137
#ifndef BATTERY_DEVTYPE_GAMEPAD
138
#define BATTERY_DEVTYPE_GAMEPAD 0x00
139
#endif
140
141
#ifndef BATTERY_TYPE_DISCONNECTED
142
#define BATTERY_TYPE_DISCONNECTED 0x00
143
#endif
144
#ifndef BATTERY_TYPE_WIRED
145
#define BATTERY_TYPE_WIRED 0x01
146
#endif
147
#ifndef BATTERY_TYPE_UNKNOWN
148
#define BATTERY_TYPE_UNKNOWN 0xFF
149
#endif
150
#ifndef BATTERY_LEVEL_EMPTY
151
#define BATTERY_LEVEL_EMPTY 0x00
152
#endif
153
#ifndef BATTERY_LEVEL_LOW
154
#define BATTERY_LEVEL_LOW 0x01
155
#endif
156
#ifndef BATTERY_LEVEL_MEDIUM
157
#define BATTERY_LEVEL_MEDIUM 0x02
158
#endif
159
#ifndef BATTERY_LEVEL_FULL
160
#define BATTERY_LEVEL_FULL 0x03
161
#endif
162
163
// Set up for C function definitions, even when using C++
164
#ifdef __cplusplus
165
extern "C" {
166
#endif
167
168
// typedef's for XInput structs we use
169
170
171
// This is the same as XINPUT_BATTERY_INFORMATION, but always defined instead of just if WIN32_WINNT >= _WIN32_WINNT_WIN8
172
typedef struct
173
{
174
BYTE BatteryType;
175
BYTE BatteryLevel;
176
} XINPUT_BATTERY_INFORMATION_EX;
177
178
#ifndef HAVE_XINPUT_H
179
180
typedef struct
181
{
182
WORD wButtons;
183
BYTE bLeftTrigger;
184
BYTE bRightTrigger;
185
SHORT sThumbLX;
186
SHORT sThumbLY;
187
SHORT sThumbRX;
188
SHORT sThumbRY;
189
} XINPUT_GAMEPAD;
190
191
typedef struct
192
{
193
DWORD dwPacketNumber;
194
XINPUT_GAMEPAD Gamepad;
195
} XINPUT_STATE;
196
197
typedef struct
198
{
199
WORD wLeftMotorSpeed;
200
WORD wRightMotorSpeed;
201
} XINPUT_VIBRATION;
202
203
typedef struct
204
{
205
BYTE Type;
206
BYTE SubType;
207
WORD Flags;
208
XINPUT_GAMEPAD Gamepad;
209
XINPUT_VIBRATION Vibration;
210
} XINPUT_CAPABILITIES;
211
212
#endif // HAVE_XINPUT_H
213
214
// This struct is not defined in XInput headers.
215
typedef struct
216
{
217
XINPUT_CAPABILITIES Capabilities;
218
WORD VendorId;
219
WORD ProductId;
220
WORD ProductVersion;
221
WORD unk1;
222
DWORD unk2;
223
} SDL_XINPUT_CAPABILITIES_EX;
224
225
// Forward decl's for XInput API's we load dynamically and use if available
226
typedef DWORD(WINAPI *XInputGetState_t)(
227
DWORD dwUserIndex, // [in] Index of the gamer associated with the device
228
XINPUT_STATE *pState // [out] Receives the current state
229
);
230
231
typedef DWORD(WINAPI *XInputSetState_t)(
232
DWORD dwUserIndex, // [in] Index of the gamer associated with the device
233
XINPUT_VIBRATION *pVibration // [in, out] The vibration information to send to the controller
234
);
235
236
typedef DWORD(WINAPI *XInputGetCapabilities_t)(
237
DWORD dwUserIndex, // [in] Index of the gamer associated with the device
238
DWORD dwFlags, // [in] Input flags that identify the device type
239
XINPUT_CAPABILITIES *pCapabilities // [out] Receives the capabilities
240
);
241
242
// Only available in XInput 1.4 that is shipped with Windows 8 and newer.
243
typedef DWORD(WINAPI *XInputGetCapabilitiesEx_t)(
244
DWORD dwReserved, // [in] Must be 1
245
DWORD dwUserIndex, // [in] Index of the gamer associated with the device
246
DWORD dwFlags, // [in] Input flags that identify the device type
247
SDL_XINPUT_CAPABILITIES_EX *pCapabilitiesEx // [out] Receives the capabilities
248
);
249
250
typedef DWORD(WINAPI *XInputGetBatteryInformation_t)(
251
DWORD dwUserIndex,
252
BYTE devType,
253
XINPUT_BATTERY_INFORMATION_EX *pBatteryInformation);
254
255
extern bool WIN_LoadXInputDLL(void);
256
extern void WIN_UnloadXInputDLL(void);
257
258
extern XInputGetState_t SDL_XInputGetState;
259
extern XInputSetState_t SDL_XInputSetState;
260
extern XInputGetCapabilities_t SDL_XInputGetCapabilities;
261
extern XInputGetCapabilitiesEx_t SDL_XInputGetCapabilitiesEx;
262
extern XInputGetBatteryInformation_t SDL_XInputGetBatteryInformation;
263
extern DWORD SDL_XInputVersion; // ((major << 16) & 0xFF00) | (minor & 0xFF)
264
265
// Ends C function definitions when using C++
266
#ifdef __cplusplus
267
}
268
#endif
269
270
#define XINPUTGETSTATE SDL_XInputGetState
271
#define XINPUTSETSTATE SDL_XInputSetState
272
#define XINPUTGETCAPABILITIES SDL_XInputGetCapabilities
273
#define XINPUTGETCAPABILITIESEX SDL_XInputGetCapabilitiesEx
274
#define XINPUTGETBATTERYINFORMATION SDL_XInputGetBatteryInformation
275
276
#endif // SDL_xinput_h_
277
278