Skip to content

Commit 5b3616c

Browse files
committedNov 24, 2020
Generalized the raw input controller driver and moved XInput/WGI detection into it for XInput devices
This fixes bad report parsing for various newer Xbox controllers, and this driver is now preferred over XInput, since it handles more than 4 controllers.
1 parent 0ff5d55 commit 5b3616c

23 files changed

+1796
-1355
lines changed
 

‎VisualC/SDL/SDL.vcxproj

+3-1
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,7 @@
299299
<ClInclude Include="..\..\src\audio\wasapi\SDL_wasapi.h" />
300300
<ClInclude Include="..\..\src\audio\winmm\SDL_winmm.h" />
301301
<ClInclude Include="..\..\src\core\windows\SDL_directx.h" />
302+
<ClInclude Include="..\..\src\core\windows\SDL_hid.h" />
302303
<ClInclude Include="..\..\src\core\windows\SDL_windows.h" />
303304
<ClInclude Include="..\..\src\core\windows\SDL_xinput.h" />
304305
<ClInclude Include="..\..\src\dynapi\SDL_dynapi.h" />
@@ -405,6 +406,7 @@
405406
<ClCompile Include="..\..\src\audio\winmm\SDL_winmm.c" />
406407
<ClCompile Include="..\..\src\audio\wasapi\SDL_wasapi.c" />
407408
<ClCompile Include="..\..\src\audio\wasapi\SDL_wasapi_win32.c" />
409+
<ClCompile Include="..\..\src\core\windows\SDL_hid.c" />
408410
<ClCompile Include="..\..\src\core\windows\SDL_windows.c" />
409411
<ClCompile Include="..\..\src\core\windows\SDL_xinput.c" />
410412
<ClCompile Include="..\..\src\cpuinfo\SDL_cpuinfo.c" />
@@ -426,7 +428,7 @@
426428
<ClCompile Include="..\..\src\haptic\windows\SDL_dinputhaptic.c" />
427429
<ClCompile Include="..\..\src\haptic\windows\SDL_windowshaptic.c" />
428430
<ClCompile Include="..\..\src\haptic\windows\SDL_xinputhaptic.c" />
429-
<ClCompile Include="..\..\src\hidapi\windows\hid.c" />
431+
<ClCompile Include="..\..\src\hidapi\SDL_hidapi.c" />
430432
<ClCompile Include="..\..\src\joystick\dummy\SDL_sysjoystick.c" />
431433
<ClCompile Include="..\..\src\joystick\hidapi\SDL_hidapijoystick.c" />
432434
<ClCompile Include="..\..\src\joystick\hidapi\SDL_hidapi_gamecube.c" />

‎VisualC/SDL/SDL.vcxproj.filters

+17-10
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,7 @@
231231
<ClInclude Include="..\..\include\SDL_vulkan.h">
232232
<Filter>API Headers</Filter>
233233
</ClInclude>
234+
<ClInclude Include="..\..\include\SDL_misc.h" />
234235
<ClInclude Include="..\..\src\audio\directsound\SDL_directsound.h" />
235236
<ClInclude Include="..\..\src\audio\disk\SDL_diskaudio.h" />
236237
<ClInclude Include="..\..\src\audio\dummy\SDL_dummyaudio.h" />
@@ -262,12 +263,15 @@
262263
<ClInclude Include="..\..\src\haptic\windows\SDL_dinputhaptic_c.h" />
263264
<ClInclude Include="..\..\src\haptic\windows\SDL_windowshaptic_c.h" />
264265
<ClInclude Include="..\..\src\haptic\windows\SDL_xinputhaptic_c.h" />
266+
<ClInclude Include="..\..\src\hidapi\hidapi\hidapi.h" />
265267
<ClInclude Include="..\..\src\joystick\controller_type.h" />
266268
<ClInclude Include="..\..\src\joystick\hidapi\SDL_hidapijoystick_c.h" />
269+
<ClInclude Include="..\..\src\joystick\SDL_gamecontrollerdb.h" />
267270
<ClInclude Include="..\..\src\joystick\SDL_joystick_c.h" />
268271
<ClInclude Include="..\..\src\joystick\SDL_sysjoystick.h" />
269272
<ClInclude Include="..\..\src\joystick\virtual\SDL_virtualjoystick_c.h" />
270273
<ClInclude Include="..\..\src\joystick\windows\SDL_dinputjoystick_c.h" />
274+
<ClInclude Include="..\..\src\joystick\windows\SDL_rawinputjoystick_c.h" />
271275
<ClInclude Include="..\..\src\joystick\windows\SDL_windowsjoystick_c.h" />
272276
<ClInclude Include="..\..\src\joystick\windows\SDL_xinputjoystick_c.h" />
273277
<ClInclude Include="..\..\src\libm\math_libm.h" />
@@ -294,6 +298,7 @@
294298
<ClInclude Include="..\..\src\sensor\dummy\SDL_dummysensor.h" />
295299
<ClInclude Include="..\..\src\sensor\SDL_sensor_c.h" />
296300
<ClInclude Include="..\..\src\sensor\SDL_syssensor.h" />
301+
<ClInclude Include="..\..\src\sensor\windows\SDL_windowssensor.h" />
297302
<ClInclude Include="..\..\src\thread\SDL_systhread.h" />
298303
<ClInclude Include="..\..\src\thread\SDL_thread_c.h" />
299304
<ClInclude Include="..\..\src\thread\windows\SDL_systhread_c.h" />
@@ -327,10 +332,7 @@
327332
<ClInclude Include="..\..\src\video\windows\SDL_windowswindow.h" />
328333
<ClInclude Include="..\..\src\video\windows\wmmsg.h" />
329334
<ClInclude Include="..\..\src\video\yuv2rgb\yuv_rgb.h" />
330-
<ClInclude Include="..\..\src\joystick\windows\SDL_rawinputjoystick_c.h" />
331-
<ClInclude Include="..\..\src\hidapi\hidapi\hidapi.h" />
332-
<ClInclude Include="..\..\src\joystick\SDL_gamecontrollerdb.h" />
333-
<ClInclude Include="..\..\src\sensor\windows\SDL_windowssensor.h" />
335+
<ClInclude Include="..\..\src\core\windows\SDL_hid.h" />
334336
</ItemGroup>
335337
<ItemGroup>
336338
<ClCompile Include="..\..\src\atomic\SDL_atomic.c" />
@@ -348,6 +350,7 @@
348350
<ClCompile Include="..\..\src\audio\wasapi\SDL_wasapi.c" />
349351
<ClCompile Include="..\..\src\audio\wasapi\SDL_wasapi_win32.c" />
350352
<ClCompile Include="..\..\src\audio\winmm\SDL_winmm.c" />
353+
<ClCompile Include="..\..\src\core\windows\SDL_hid.c" />
351354
<ClCompile Include="..\..\src\core\windows\SDL_windows.c" />
352355
<ClCompile Include="..\..\src\core\windows\SDL_xinput.c" />
353356
<ClCompile Include="..\..\src\cpuinfo\SDL_cpuinfo.c" />
@@ -364,13 +367,16 @@
364367
<ClCompile Include="..\..\src\events\SDL_windowevents.c" />
365368
<ClCompile Include="..\..\src\file\SDL_rwops.c" />
366369
<ClCompile Include="..\..\src\filesystem\windows\SDL_sysfilesystem.c" />
370+
<ClCompile Include="..\..\src\haptic\dummy\SDL_syshaptic.c" />
367371
<ClCompile Include="..\..\src\haptic\SDL_haptic.c" />
368372
<ClCompile Include="..\..\src\haptic\windows\SDL_dinputhaptic.c" />
369373
<ClCompile Include="..\..\src\haptic\windows\SDL_windowshaptic.c" />
370374
<ClCompile Include="..\..\src\haptic\windows\SDL_xinputhaptic.c" />
371-
<ClCompile Include="..\..\src\hidapi\windows\hid.c" />
375+
<ClCompile Include="..\..\src\hidapi\SDL_hidapi.c" />
376+
<ClCompile Include="..\..\src\joystick\dummy\SDL_sysjoystick.c" />
372377
<ClCompile Include="..\..\src\joystick\hidapi\SDL_hidapi_gamecube.c" />
373378
<ClCompile Include="..\..\src\joystick\hidapi\SDL_hidapi_ps4.c" />
379+
<ClCompile Include="..\..\src\joystick\hidapi\SDL_hidapi_ps5.c" />
374380
<ClCompile Include="..\..\src\joystick\hidapi\SDL_hidapi_rumble.c" />
375381
<ClCompile Include="..\..\src\joystick\hidapi\SDL_hidapi_switch.c" />
376382
<ClCompile Include="..\..\src\joystick\hidapi\SDL_hidapi_xbox360.c" />
@@ -382,6 +388,8 @@
382388
<ClCompile Include="..\..\src\joystick\virtual\SDL_virtualjoystick.c" />
383389
<ClCompile Include="..\..\src\joystick\windows\SDL_dinputjoystick.c" />
384390
<ClCompile Include="..\..\src\joystick\windows\SDL_mmjoystick.c" />
391+
<ClCompile Include="..\..\src\joystick\windows\SDL_rawinputjoystick.c" />
392+
<ClCompile Include="..\..\src\joystick\windows\SDL_windows_gaming_input.c" />
385393
<ClCompile Include="..\..\src\joystick\windows\SDL_windowsjoystick.c" />
386394
<ClCompile Include="..\..\src\joystick\windows\SDL_xinputjoystick.c" />
387395
<ClCompile Include="..\..\src\libm\e_atan2.c" />
@@ -407,6 +415,8 @@
407415
<ClCompile Include="..\..\src\loadso\windows\SDL_sysloadso.c" />
408416
<ClCompile Include="..\..\src\locale\SDL_locale.c" />
409417
<ClCompile Include="..\..\src\locale\windows\SDL_syslocale.c" />
418+
<ClCompile Include="..\..\src\misc\SDL_url.c" />
419+
<ClCompile Include="..\..\src\misc\windows\SDL_sysurl.c" />
410420
<ClCompile Include="..\..\src\power\SDL_power.c" />
411421
<ClCompile Include="..\..\src\power\windows\SDL_syspower.c" />
412422
<ClCompile Include="..\..\src\render\direct3d\SDL_render_d3d.c" />
@@ -435,6 +445,8 @@
435445
<ClCompile Include="..\..\src\SDL_log.c" />
436446
<ClCompile Include="..\..\src\sensor\dummy\SDL_dummysensor.c" />
437447
<ClCompile Include="..\..\src\sensor\SDL_sensor.c" />
448+
<ClCompile Include="..\..\src\sensor\windows\SDL_windowssensor.c" />
449+
<ClCompile Include="..\..\src\stdlib\SDL_crc32.c" />
438450
<ClCompile Include="..\..\src\stdlib\SDL_getenv.c" />
439451
<ClCompile Include="..\..\src\stdlib\SDL_iconv.c" />
440452
<ClCompile Include="..\..\src\stdlib\SDL_malloc.c" />
@@ -488,11 +500,6 @@
488500
<ClCompile Include="..\..\src\video\windows\SDL_windowsvulkan.c" />
489501
<ClCompile Include="..\..\src\video\windows\SDL_windowswindow.c" />
490502
<ClCompile Include="..\..\src\video\yuv2rgb\yuv_rgb.c" />
491-
<ClCompile Include="..\..\src\joystick\windows\SDL_rawinputjoystick.c" />
492-
<ClCompile Include="..\..\src\sensor\windows\SDL_windowssensor.c" />
493-
<ClCompile Include="..\..\src\haptic\dummy\SDL_syshaptic.c" />
494-
<ClCompile Include="..\..\src\joystick\dummy\SDL_sysjoystick.c" />
495-
<ClCompile Include="..\..\src\joystick\windows\SDL_windows_gaming_input.c" />
496503
</ItemGroup>
497504
<ItemGroup>
498505
<ResourceCompile Include="..\..\src\main\windows\version.rc" />

‎src/core/windows/SDL_hid.c

+95
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
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 __WINRT__
24+
25+
#include "SDL_assert.h"
26+
#include "SDL_hid.h"
27+
28+
29+
HidD_GetString_t SDL_HidD_GetManufacturerString;
30+
HidD_GetString_t SDL_HidD_GetProductString;
31+
HidD_GetPreparsedData_t SDL_HidD_GetPreparsedData;
32+
HidD_FreePreparsedData_t SDL_HidD_FreePreparsedData;
33+
HidP_GetCaps_t SDL_HidP_GetCaps;
34+
HidP_GetButtonCaps_t SDL_HidP_GetButtonCaps;
35+
HidP_GetValueCaps_t SDL_HidP_GetValueCaps;
36+
HidP_MaxDataListLength_t SDL_HidP_MaxDataListLength;
37+
HidP_GetData_t SDL_HidP_GetData;
38+
39+
static HMODULE s_pHIDDLL = 0;
40+
static int s_HIDDLLRefCount = 0;
41+
42+
43+
int
44+
WIN_LoadHIDDLL(void)
45+
{
46+
if (s_pHIDDLL) {
47+
SDL_assert(s_HIDDLLRefCount > 0);
48+
s_HIDDLLRefCount++;
49+
return 0; /* already loaded */
50+
}
51+
52+
s_pHIDDLL = LoadLibrary(L"hid.dll");
53+
if (!s_pHIDDLL) {
54+
return -1;
55+
}
56+
57+
SDL_assert(s_HIDDLLRefCount == 0);
58+
s_HIDDLLRefCount = 1;
59+
60+
SDL_HidD_GetManufacturerString = (HidD_GetString_t)GetProcAddress(s_pHIDDLL, "HidD_GetManufacturerString");
61+
SDL_HidD_GetProductString = (HidD_GetString_t)GetProcAddress(s_pHIDDLL, "HidD_GetProductString");
62+
SDL_HidD_GetPreparsedData = (HidD_GetPreparsedData_t)GetProcAddress(s_pHIDDLL, "HidD_GetPreparsedData");
63+
SDL_HidD_FreePreparsedData = (HidD_FreePreparsedData_t)GetProcAddress(s_pHIDDLL, "HidD_FreePreparsedData");
64+
SDL_HidP_GetCaps = (HidP_GetCaps_t)GetProcAddress(s_pHIDDLL, "HidP_GetCaps");
65+
SDL_HidP_GetButtonCaps = (HidP_GetButtonCaps_t)GetProcAddress(s_pHIDDLL, "HidP_GetButtonCaps");
66+
SDL_HidP_GetValueCaps = (HidP_GetValueCaps_t)GetProcAddress(s_pHIDDLL, "HidP_GetValueCaps");
67+
SDL_HidP_MaxDataListLength = (HidP_MaxDataListLength_t)GetProcAddress(s_pHIDDLL, "HidP_MaxDataListLength");
68+
SDL_HidP_GetData = (HidP_GetData_t)GetProcAddress(s_pHIDDLL, "HidP_GetData");
69+
if (!SDL_HidD_GetManufacturerString || !SDL_HidD_GetProductString || !SDL_HidD_GetPreparsedData ||
70+
!SDL_HidD_FreePreparsedData || !SDL_HidP_GetCaps || !SDL_HidP_GetButtonCaps ||
71+
!SDL_HidP_GetValueCaps || !SDL_HidP_MaxDataListLength || !SDL_HidP_GetData) {
72+
WIN_UnloadHIDDLL();
73+
return -1;
74+
}
75+
76+
return 0;
77+
}
78+
79+
void
80+
WIN_UnloadHIDDLL(void)
81+
{
82+
if (s_pHIDDLL) {
83+
SDL_assert(s_HIDDLLRefCount > 0);
84+
if (--s_HIDDLLRefCount == 0) {
85+
FreeLibrary(s_pHIDDLL);
86+
s_pHIDDLL = NULL;
87+
}
88+
} else {
89+
SDL_assert(s_HIDDLLRefCount == 0);
90+
}
91+
}
92+
93+
#endif /* !__WINRT__ */
94+
95+
/* vi: set ts=4 sw=4 expandtab: */

0 commit comments

Comments
 (0)
Please sign in to comment.