1 /*
2   Simple DirectMedia Layer
3   Copyright (C) 1997-2020 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 #include "../../SDL_internal.h"
22 
23 #ifndef SDL_xinput_h_
24 #define SDL_xinput_h_
25 
26 #ifdef HAVE_XINPUT_H
27 
28 #include "SDL_windows.h"
29 #include <xinput.h>
30 
31 #ifndef XUSER_MAX_COUNT
32 #define XUSER_MAX_COUNT 4
33 #endif
34 #ifndef XUSER_INDEX_ANY
35 #define XUSER_INDEX_ANY     0x000000FF
36 #endif
37 #ifndef XINPUT_CAPS_FFB_SUPPORTED
38 #define XINPUT_CAPS_FFB_SUPPORTED 0x0001
39 #endif
40 
41 #ifndef XINPUT_DEVSUBTYPE_UNKNOWN
42 #define XINPUT_DEVSUBTYPE_UNKNOWN 0x00
43 #endif
44 #ifndef XINPUT_DEVSUBTYPE_GAMEPAD
45 #define XINPUT_DEVSUBTYPE_GAMEPAD 0x01
46 #endif
47 #ifndef XINPUT_DEVSUBTYPE_WHEEL
48 #define XINPUT_DEVSUBTYPE_WHEEL 0x02
49 #endif
50 #ifndef XINPUT_DEVSUBTYPE_ARCADE_STICK
51 #define XINPUT_DEVSUBTYPE_ARCADE_STICK 0x03
52 #endif
53 #ifndef XINPUT_DEVSUBTYPE_FLIGHT_STICK
54 #define XINPUT_DEVSUBTYPE_FLIGHT_STICK 0x04
55 #endif
56 #ifndef XINPUT_DEVSUBTYPE_DANCE_PAD
57 #define XINPUT_DEVSUBTYPE_DANCE_PAD 0x05
58 #endif
59 #ifndef XINPUT_DEVSUBTYPE_GUITAR
60 #define XINPUT_DEVSUBTYPE_GUITAR 0x06
61 #endif
62 #ifndef XINPUT_DEVSUBTYPE_GUITAR_ALTERNATE
63 #define XINPUT_DEVSUBTYPE_GUITAR_ALTERNATE 0x07
64 #endif
65 #ifndef XINPUT_DEVSUBTYPE_DRUM_KIT
66 #define XINPUT_DEVSUBTYPE_DRUM_KIT 0x08
67 #endif
68 #ifndef XINPUT_DEVSUBTYPE_GUITAR_BASS
69 #define XINPUT_DEVSUBTYPE_GUITAR_BASS 0x0B
70 #endif
71 #ifndef XINPUT_DEVSUBTYPE_ARCADE_PAD
72 #define XINPUT_DEVSUBTYPE_ARCADE_PAD 0x13
73 #endif
74 
75 #ifndef XINPUT_GAMEPAD_GUIDE
76 #define XINPUT_GAMEPAD_GUIDE 0x0400
77 #endif
78 
79 #ifndef BATTERY_DEVTYPE_GAMEPAD
80 #define BATTERY_DEVTYPE_GAMEPAD         0x00
81 #endif
82 #ifndef BATTERY_TYPE_WIRED
83 #define BATTERY_TYPE_WIRED              0x01
84 #endif
85 
86 #ifndef BATTERY_TYPE_UNKNOWN
87 #define BATTERY_TYPE_UNKNOWN            0xFF
88 #endif
89 #ifndef BATTERY_LEVEL_EMPTY
90 #define BATTERY_LEVEL_EMPTY             0x00
91 #endif
92 #ifndef BATTERY_LEVEL_LOW
93 #define BATTERY_LEVEL_LOW               0x01
94 #endif
95 #ifndef BATTERY_LEVEL_MEDIUM
96 #define BATTERY_LEVEL_MEDIUM            0x02
97 #endif
98 #ifndef BATTERY_LEVEL_FULL
99 #define BATTERY_LEVEL_FULL              0x03
100 #endif
101 
102 /* typedef's for XInput structs we use */
103 
104 #ifndef HAVE_XINPUT_GAMEPAD_EX
105 typedef struct
106 {
107     WORD wButtons;
108     BYTE bLeftTrigger;
109     BYTE bRightTrigger;
110     SHORT sThumbLX;
111     SHORT sThumbLY;
112     SHORT sThumbRX;
113     SHORT sThumbRY;
114     DWORD dwPaddingReserved;
115 } XINPUT_GAMEPAD_EX;
116 #endif
117 
118 #ifndef HAVE_XINPUT_STATE_EX
119 typedef struct
120 {
121     DWORD dwPacketNumber;
122     XINPUT_GAMEPAD_EX Gamepad;
123 } XINPUT_STATE_EX;
124 #endif
125 
126 typedef struct
127 {
128     BYTE BatteryType;
129     BYTE BatteryLevel;
130 } XINPUT_BATTERY_INFORMATION_EX;
131 
132 /* Forward decl's for XInput API's we load dynamically and use if available */
133 typedef DWORD (WINAPI *XInputGetState_t)
134     (
135     DWORD         dwUserIndex,  /* [in] Index of the gamer associated with the device */
136     XINPUT_STATE_EX* pState     /* [out] Receives the current state */
137     );
138 
139 typedef DWORD (WINAPI *XInputSetState_t)
140     (
141     DWORD             dwUserIndex,  /* [in] Index of the gamer associated with the device */
142     XINPUT_VIBRATION* pVibration    /* [in, out] The vibration information to send to the controller */
143     );
144 
145 typedef DWORD (WINAPI *XInputGetCapabilities_t)
146     (
147     DWORD                dwUserIndex,   /* [in] Index of the gamer associated with the device */
148     DWORD                dwFlags,       /* [in] Input flags that identify the device type */
149     XINPUT_CAPABILITIES* pCapabilities  /* [out] Receives the capabilities */
150     );
151 
152 typedef DWORD (WINAPI *XInputGetBatteryInformation_t)
153     (
154     DWORD                         dwUserIndex,
155     BYTE                          devType,
156     XINPUT_BATTERY_INFORMATION_EX *pBatteryInformation
157     );
158 
159 extern int WIN_LoadXInputDLL(void);
160 extern void WIN_UnloadXInputDLL(void);
161 
162 extern XInputGetState_t SDL_XInputGetState;
163 extern XInputSetState_t SDL_XInputSetState;
164 extern XInputGetCapabilities_t SDL_XInputGetCapabilities;
165 extern XInputGetBatteryInformation_t SDL_XInputGetBatteryInformation;
166 extern DWORD SDL_XInputVersion;  /* ((major << 16) & 0xFF00) | (minor & 0xFF) */
167 
168 #define XINPUTGETSTATE          SDL_XInputGetState
169 #define XINPUTSETSTATE          SDL_XInputSetState
170 #define XINPUTGETCAPABILITIES   SDL_XInputGetCapabilities
171 #define XINPUTGETBATTERYINFORMATION   SDL_XInputGetBatteryInformation
172 
173 #endif /* HAVE_XINPUT_H */
174 
175 #endif /* SDL_xinput_h_ */
176 
177 /* vi: set ts=4 sw=4 expandtab: */
178