21 #include "../../SDL_internal.h"
23 #include "../SDL_sysjoystick.h"
25 #if SDL_JOYSTICK_XINPUT
32 #include "../hidapi/SDL_hidapijoystick_c.h"
38 static char *s_arrXInputDevicePath[XUSER_MAX_COUNT];
42 SDL_XInputUseOldJoystickMapping()
49 static int s_XInputUseOldJoystickMapping = -1;
50 if (s_XInputUseOldJoystickMapping < 0) {
53 return (s_XInputUseOldJoystickMapping > 0);
59 return s_bXInputEnabled;
67 #ifdef SDL_JOYSTICK_RAWINPUT
74 if (s_bXInputEnabled && WIN_LoadXInputDLL() < 0) {
81 GetXInputName(
const Uint8 userid, BYTE SubType)
85 if (SDL_XInputUseOldJoystickMapping()) {
89 case XINPUT_DEVSUBTYPE_GAMEPAD:
92 case XINPUT_DEVSUBTYPE_WHEEL:
95 case XINPUT_DEVSUBTYPE_ARCADE_STICK:
98 case XINPUT_DEVSUBTYPE_FLIGHT_STICK:
101 case XINPUT_DEVSUBTYPE_DANCE_PAD:
104 case XINPUT_DEVSUBTYPE_GUITAR:
105 case XINPUT_DEVSUBTYPE_GUITAR_ALTERNATE:
106 case XINPUT_DEVSUBTYPE_GUITAR_BASS:
109 case XINPUT_DEVSUBTYPE_DRUM_KIT:
112 case XINPUT_DEVSUBTYPE_ARCADE_PAD:
132 UINT
i,
j, device_count = 0;
134 if ((GetRawInputDeviceList(
NULL, &device_count,
sizeof(RAWINPUTDEVICELIST)) == -1) || (!device_count)) {
138 devices = (PRAWINPUTDEVICELIST)
SDL_malloc(
sizeof(RAWINPUTDEVICELIST) * device_count);
143 if (GetRawInputDeviceList(
devices, &device_count,
sizeof(RAWINPUTDEVICELIST)) == -1) {
149 if (s_arrXInputDevicePath[userid]) {
150 for (
i = 0;
i < device_count;
i++) {
153 UINT rdiSize =
sizeof(rdi);
156 rdi.cbSize =
sizeof(rdi);
157 if (
devices[
i].dwType == RIM_TYPEHID &&
158 GetRawInputDeviceInfoA(
devices[
i].hDevice, RIDI_DEVICEINFO, &rdi, &rdiSize) != (UINT)-1 &&
159 GetRawInputDeviceInfoA(
devices[
i].hDevice, RIDI_DEVICENAME, devName, &nameSize) != (UINT)-1) {
160 if (
SDL_strcmp(devName, s_arrXInputDevicePath[userid]) == 0) {
161 *pVID = (
Uint16)rdi.hid.dwVendorId;
162 *pPID = (
Uint16)rdi.hid.dwProductId;
163 *pVersion = (
Uint16)rdi.hid.dwVersionNumber;
171 for (
i = 0;
i < device_count;
i++) {
173 char devName[MAX_PATH];
174 UINT rdiSize =
sizeof(rdi);
177 rdi.cbSize =
sizeof(rdi);
178 if (
devices[
i].dwType == RIM_TYPEHID &&
179 GetRawInputDeviceInfoA(
devices[
i].hDevice, RIDI_DEVICEINFO, &rdi, &rdiSize) != (UINT)-1 &&
180 GetRawInputDeviceInfoA(
devices[
i].hDevice, RIDI_DEVICENAME, devName, &nameSize) != (UINT)-1) {
181 #ifdef DEBUG_JOYSTICK
182 SDL_Log(
"Raw input device: VID = 0x%x, PID = 0x%x, %s\n", rdi.hid.dwVendorId, rdi.hid.dwProductId, devName);
187 if (!s_arrXInputDevicePath[
j]) {
190 if (
SDL_strcmp(devName, s_arrXInputDevicePath[
j]) == 0) {
204 *pVID = (
Uint16)rdi.hid.dwVendorId;
205 *pPID = (
Uint16)rdi.hid.dwProductId;
206 *pVersion = (
Uint16)rdi.hid.dwVersionNumber;
207 if (s_arrXInputDevicePath[userid]) {
208 SDL_free(s_arrXInputDevicePath[userid]);
210 s_arrXInputDevicePath[userid] =
SDL_strdup(devName);
234 if (SDL_XInputUseOldJoystickMapping() && SubType != XINPUT_DEVSUBTYPE_GAMEPAD)
237 if (SubType == XINPUT_DEVSUBTYPE_UNKNOWN)
240 while (pNewJoystick) {
243 if (pNewJoystick == *pContext) {
244 *pContext = pNewJoystick->
pNext;
245 }
else if (pPrevJoystick) {
254 pPrevJoystick = pNewJoystick;
255 pNewJoystick = pNewJoystick->
pNext;
264 if (!SDL_XInputUseOldJoystickMapping()) {
267 GuessXInputDevice(userid, &vendor, &product, &version);
280 pNewJoystick->
guid.
data[15] = SubType;
282 pNewJoystick->
SubType = SubType;
295 #ifdef SDL_JOYSTICK_HIDAPI
304 #ifdef SDL_JOYSTICK_RAWINPUT
316 DelXInputDevice(
Uint8 userid)
318 if (s_arrXInputDevicePath[userid]) {
319 SDL_free(s_arrXInputDevicePath[userid]);
320 s_arrXInputDevicePath[userid] =
NULL;
329 if (!s_bXInputEnabled) {
334 for (iuserid = XUSER_MAX_COUNT - 1; iuserid >= 0; iuserid--) {
336 XINPUT_CAPABILITIES capabilities;
337 if (XINPUTGETCAPABILITIES(userid, XINPUT_FLAG_GAMEPAD, &capabilities) == ERROR_SUCCESS) {
343 for (iuserid2 = iuserid - 1; iuserid2 >= 0; iuserid2--) {
345 XINPUT_CAPABILITIES capabilities2;
346 if (XINPUTGETCAPABILITIES(userid2, XINPUT_FLAG_GAMEPAD, &capabilities2) != ERROR_SUCCESS) {
347 DelXInputDevice(userid2);
350 AddXInputDevice(userid, capabilities.SubType, pContext);
352 DelXInputDevice(userid);
361 XINPUT_CAPABILITIES capabilities;
362 XINPUT_VIBRATION
state;
371 if (XINPUTGETCAPABILITIES(userId, XINPUT_FLAG_GAMEPAD, &capabilities) != ERROR_SUCCESS) {
374 return SDL_SetError(
"Failed to obtain XInput device capabilities. Device disconnected?");
377 joystick->hwdata->bXInputHaptic = (XINPUTSETSTATE(userId, &
state) == ERROR_SUCCESS);
381 if (SDL_XInputUseOldJoystickMapping()) {
393 UpdateXInputJoystickBatteryInformation(SDL_Joystick *
joystick, XINPUT_BATTERY_INFORMATION_EX *pBatteryInformation)
395 if (pBatteryInformation->BatteryType != BATTERY_TYPE_UNKNOWN) {
397 if (pBatteryInformation->BatteryType == BATTERY_TYPE_WIRED) {
400 switch (pBatteryInformation->BatteryLevel) {
401 case BATTERY_LEVEL_EMPTY:
404 case BATTERY_LEVEL_LOW:
407 case BATTERY_LEVEL_MEDIUM:
411 case BATTERY_LEVEL_FULL:
422 UpdateXInputJoystickState_OLD(SDL_Joystick *
joystick, XINPUT_STATE_EX *pXInputState, XINPUT_BATTERY_INFORMATION_EX *pBatteryInformation)
424 static WORD s_XInputButtons[] = {
425 XINPUT_GAMEPAD_DPAD_UP, XINPUT_GAMEPAD_DPAD_DOWN, XINPUT_GAMEPAD_DPAD_LEFT, XINPUT_GAMEPAD_DPAD_RIGHT,
426 XINPUT_GAMEPAD_START, XINPUT_GAMEPAD_BACK, XINPUT_GAMEPAD_LEFT_THUMB, XINPUT_GAMEPAD_RIGHT_THUMB,
427 XINPUT_GAMEPAD_LEFT_SHOULDER, XINPUT_GAMEPAD_RIGHT_SHOULDER,
428 XINPUT_GAMEPAD_A, XINPUT_GAMEPAD_B, XINPUT_GAMEPAD_X, XINPUT_GAMEPAD_Y,
431 WORD wButtons = pXInputState->Gamepad.wButtons;
445 UpdateXInputJoystickBatteryInformation(
joystick, pBatteryInformation);
449 UpdateXInputJoystickState(SDL_Joystick *
joystick, XINPUT_STATE_EX *pXInputState, XINPUT_BATTERY_INFORMATION_EX *pBatteryInformation)
451 static WORD s_XInputButtons[] = {
452 XINPUT_GAMEPAD_A, XINPUT_GAMEPAD_B, XINPUT_GAMEPAD_X, XINPUT_GAMEPAD_Y,
453 XINPUT_GAMEPAD_LEFT_SHOULDER, XINPUT_GAMEPAD_RIGHT_SHOULDER, XINPUT_GAMEPAD_BACK, XINPUT_GAMEPAD_START,
454 XINPUT_GAMEPAD_LEFT_THUMB, XINPUT_GAMEPAD_RIGHT_THUMB,
457 WORD wButtons = pXInputState->Gamepad.wButtons;
472 if (wButtons & XINPUT_GAMEPAD_DPAD_UP) {
475 if (wButtons & XINPUT_GAMEPAD_DPAD_DOWN) {
478 if (wButtons & XINPUT_GAMEPAD_DPAD_LEFT) {
481 if (wButtons & XINPUT_GAMEPAD_DPAD_RIGHT) {
486 UpdateXInputJoystickBatteryInformation(
joystick, pBatteryInformation);
492 XINPUT_VIBRATION XVibration;
494 if (!XINPUTSETSTATE) {
498 XVibration.wLeftMotorSpeed = low_frequency_rumble;
499 XVibration.wRightMotorSpeed = high_frequency_rumble;
500 if (XINPUTSETSTATE(
joystick->hwdata->userid, &XVibration) != ERROR_SUCCESS) {
510 XINPUT_STATE_EX XInputState;
511 XINPUT_BATTERY_INFORMATION_EX XBatteryInformation;
517 if (
result == ERROR_DEVICE_NOT_CONNECTED) {
522 if (XINPUTGETBATTERYINFORMATION) {
523 result = XINPUTGETBATTERYINFORMATION(
joystick->hwdata->userid, BATTERY_DEVTYPE_GAMEPAD, &XBatteryInformation);
527 if (XInputState.dwPacketNumber && XInputState.dwPacketNumber !=
joystick->hwdata->dwPacketNumber) {
528 if (SDL_XInputUseOldJoystickMapping()) {
529 UpdateXInputJoystickState_OLD(
joystick, &XInputState, &XBatteryInformation);
531 UpdateXInputJoystickState(
joystick, &XInputState, &XBatteryInformation);
533 joystick->hwdata->dwPacketNumber = XInputState.dwPacketNumber;
545 if (s_bXInputEnabled) {
546 WIN_UnloadXInputDLL();
#define SDL_assert(condition)
#define SDL_GetHintBoolean
#define SDL_Unsupported()
SDL_bool HIDAPI_IsDevicePresent(Uint16 vendor_id, Uint16 product_id, Uint16 version, const char *name)
#define SDL_HINT_XINPUT_ENABLED
A variable that lets you disable the detection and use of Xinput gamepad devices.
#define SDL_HINT_XINPUT_USE_OLD_JOYSTICK_MAPPING
A variable that causes SDL to use the old axis and button mapping for XInput devices.
void SDL_PrivateJoystickBatteryLevel(SDL_Joystick *joystick, SDL_JoystickPowerLevel ePowerLevel)
int SDL_PrivateJoystickHat(SDL_Joystick *joystick, Uint8 hat, Uint8 value)
int SDL_PrivateJoystickAxis(SDL_Joystick *joystick, Uint8 axis, Sint16 value)
SDL_bool SDL_ShouldIgnoreJoystick(const char *name, SDL_JoystickGUID guid)
int SDL_PrivateJoystickButton(SDL_Joystick *joystick, Uint8 button, Uint8 state)
char * SDL_CreateJoystickName(Uint16 vendor, Uint16 product, const char *vendor_name, const char *product_name)
@ SDL_JOYSTICK_POWER_FULL
@ SDL_JOYSTICK_POWER_MEDIUM
@ SDL_JOYSTICK_POWER_EMPTY
@ SDL_JOYSTICK_POWER_UNKNOWN
@ SDL_JOYSTICK_POWER_WIRED
GLuint const GLchar * name
#define SDL_arraysize(array)
#define SDL_HARDWARE_BUS_USB
void WINDOWS_AddJoystickDevice(JoyStick_DeviceData *device)
JoyStick_DeviceData * SYS_Joystick
return Display return Display Bool Bool int int int return Display XEvent Bool(*) XPointer return Display return Display Drawable _Xconst char unsigned int unsigned int return Display Pixmap Pixmap XColor XColor unsigned int unsigned int return Display _Xconst char char int char return Display Visual unsigned int int int char unsigned int unsigned int in i)
return Display return Display Bool Bool int int int return Display XEvent Bool(*) XPointer return Display return Display Drawable _Xconst char unsigned int unsigned int return Display Pixmap Pixmap XColor XColor unsigned int unsigned int return Display _Xconst char char int char return Display Visual unsigned int int int char unsigned int unsigned int int in j)
set set set set set set set macro pixldst1 abits if abits op else op endif endm macro pixldst2 abits if abits op else op endif endm macro pixldst4 abits if abits op else op endif endm macro pixldst0 abits op endm macro pixldst3 mem_operand op endm macro pixldst30 mem_operand op endm macro pixldst abits if abits elseif abits elseif abits elseif abits elseif abits pixldst0 abits else pixldst0 abits pixldst0 abits pixldst0 abits pixldst0 abits endif elseif abits else pixldst0 abits pixldst0 abits endif elseif abits else error unsupported bpp *numpix else pixst endif endm macro pixld1_s mem_operand if asr adds SRC_WIDTH_FIXED bpl add asl mov asr adds SRC_WIDTH_FIXED bpl add asl mov asr adds SRC_WIDTH_FIXED bpl add asl mov asr adds SRC_WIDTH_FIXED bpl add asl elseif asr adds SRC_WIDTH_FIXED bpl add asl mov asr adds SRC_WIDTH_FIXED bpl add asl else error unsupported endif endm macro pixld2_s mem_operand if mov asr add asl add asl mov asr sub UNIT_X add asl mov asr add asl add asl mov asr add UNIT_X add asl else pixld1_s mem_operand pixld1_s mem_operand endif endm macro pixld0_s mem_operand if asr adds SRC_WIDTH_FIXED bpl add asl elseif asr adds SRC_WIDTH_FIXED bpl add asl endif endm macro pixld_s_internal mem_operand if mem_operand pixld2_s mem_operand pixdeinterleave basereg elseif mem_operand elseif mem_operand elseif mem_operand elseif mem_operand pixld0_s mem_operand else pixld0_s mem_operand pixld0_s mem_operand pixld0_s mem_operand pixld0_s mem_operand endif elseif mem_operand else pixld0_s mem_operand pixld0_s mem_operand endif elseif mem_operand else error unsupported mem_operand if bpp mem_operand endif endm macro vuzp8 reg2 vuzp d d ®2 endm macro vzip8 reg2 vzip d d ®2 endm macro pixdeinterleave basereg basereg basereg basereg basereg endif endm macro pixinterleave basereg basereg basereg basereg basereg endif endm macro PF boost_increment endif if endif PF tst PF addne PF subne PF cmp ORIG_W if endif if endif if endif PF subge ORIG_W PF subges if endif if endif if endif endif endm macro cache_preload_simple endif if dst_r_bpp pld[DST_R, #(PREFETCH_DISTANCE_SIMPLE *dst_r_bpp/8)] endif if mask_bpp pld if[MASK, #(PREFETCH_DISTANCE_SIMPLE *mask_bpp/8)] endif endif endm macro fetch_mask_pixblock pixld mask_basereg pixblock_size MASK endm macro ensure_destination_ptr_alignment process_pixblock_tail_head if beq irp skip1(dst_w_bpp<=(lowbit *8)) &&((lowbit *8)<(pixblock_size *dst_w_bpp)) .if lowbit< 16 tst DST_R
struct JoyStick_DeviceData * pNext
static SDL_Joystick * joystick
#define USB_VENDOR_MICROSOFT
#define USB_PRODUCT_XBOX_ONE_XINPUT_CONTROLLER