1 /*
2   Simple DirectMedia Layer
3   Copyright (C) 1997-2016 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 typedef struct
104 {
105     WORD wButtons;
106     BYTE bLeftTrigger;
107     BYTE bRightTrigger;
108     SHORT sThumbLX;
109     SHORT sThumbLY;
110     SHORT sThumbRX;
111     SHORT sThumbRY;
112     DWORD dwPaddingReserved;
113 } XINPUT_GAMEPAD_EX;
114 
115 typedef struct
116 {
117     DWORD dwPacketNumber;
118     XINPUT_GAMEPAD_EX Gamepad;
119 } XINPUT_STATE_EX;
120 
121 typedef struct
122 {
123     BYTE BatteryType;
124     BYTE BatteryLevel;
125 } XINPUT_BATTERY_INFORMATION_EX;
126 
127 /* Forward decl's for XInput API's we load dynamically and use if available */
128 typedef DWORD (WINAPI *XInputGetState_t)
129     (
130     DWORD         dwUserIndex,  /* [in] Index of the gamer associated with the device */
131     XINPUT_STATE_EX* pState     /* [out] Receives the current state */
132     );
133 
134 typedef DWORD (WINAPI *XInputSetState_t)
135     (
136     DWORD             dwUserIndex,  /* [in] Index of the gamer associated with the device */
137     XINPUT_VIBRATION* pVibration    /* [in, out] The vibration information to send to the controller */
138     );
139 
140 typedef DWORD (WINAPI *XInputGetCapabilities_t)
141     (
142     DWORD                dwUserIndex,   /* [in] Index of the gamer associated with the device */
143     DWORD                dwFlags,       /* [in] Input flags that identify the device type */
144     XINPUT_CAPABILITIES* pCapabilities  /* [out] Receives the capabilities */
145     );
146 
147 typedef DWORD (WINAPI *XInputGetBatteryInformation_t)
148     (
149     DWORD                         dwUserIndex,
150     BYTE                          devType,
151     XINPUT_BATTERY_INFORMATION_EX *pBatteryInformation
152     );
153 
154 extern int WIN_LoadXInputDLL(void);
155 extern void WIN_UnloadXInputDLL(void);
156 
157 extern XInputGetState_t SDL_XInputGetState;
158 extern XInputSetState_t SDL_XInputSetState;
159 extern XInputGetCapabilities_t SDL_XInputGetCapabilities;
160 extern XInputGetBatteryInformation_t SDL_XInputGetBatteryInformation;
161 extern DWORD SDL_XInputVersion;  /* ((major << 16) & 0xFF00) | (minor & 0xFF) */
162 
163 #define XINPUTGETSTATE          SDL_XInputGetState
164 #define XINPUTSETSTATE          SDL_XInputSetState
165 #define XINPUTGETCAPABILITIES   SDL_XInputGetCapabilities
166 #define XINPUTGETBATTERYINFORMATION   SDL_XInputGetBatteryInformation
167 
168 #endif /* HAVE_XINPUT_H */
169 
170 #endif /* _SDL_xinput_h */
171 
172 /* vi: set ts=4 sw=4 expandtab: */
173