Skip to content

Commit

Permalink
Generalized the raw input controller driver and moved XInput/WGI dete…
Browse files Browse the repository at this point in the history
…ction 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.
  • Loading branch information
slouken committed Nov 24, 2020
1 parent 0ff5d55 commit 5b3616c
Show file tree
Hide file tree
Showing 23 changed files with 1,796 additions and 1,355 deletions.
4 changes: 3 additions & 1 deletion VisualC/SDL/SDL.vcxproj
Expand Up @@ -299,6 +299,7 @@
<ClInclude Include="..\..\src\audio\wasapi\SDL_wasapi.h" />
<ClInclude Include="..\..\src\audio\winmm\SDL_winmm.h" />
<ClInclude Include="..\..\src\core\windows\SDL_directx.h" />
<ClInclude Include="..\..\src\core\windows\SDL_hid.h" />
<ClInclude Include="..\..\src\core\windows\SDL_windows.h" />
<ClInclude Include="..\..\src\core\windows\SDL_xinput.h" />
<ClInclude Include="..\..\src\dynapi\SDL_dynapi.h" />
Expand Down Expand Up @@ -405,6 +406,7 @@
<ClCompile Include="..\..\src\audio\winmm\SDL_winmm.c" />
<ClCompile Include="..\..\src\audio\wasapi\SDL_wasapi.c" />
<ClCompile Include="..\..\src\audio\wasapi\SDL_wasapi_win32.c" />
<ClCompile Include="..\..\src\core\windows\SDL_hid.c" />
<ClCompile Include="..\..\src\core\windows\SDL_windows.c" />
<ClCompile Include="..\..\src\core\windows\SDL_xinput.c" />
<ClCompile Include="..\..\src\cpuinfo\SDL_cpuinfo.c" />
Expand All @@ -426,7 +428,7 @@
<ClCompile Include="..\..\src\haptic\windows\SDL_dinputhaptic.c" />
<ClCompile Include="..\..\src\haptic\windows\SDL_windowshaptic.c" />
<ClCompile Include="..\..\src\haptic\windows\SDL_xinputhaptic.c" />
<ClCompile Include="..\..\src\hidapi\windows\hid.c" />
<ClCompile Include="..\..\src\hidapi\SDL_hidapi.c" />
<ClCompile Include="..\..\src\joystick\dummy\SDL_sysjoystick.c" />
<ClCompile Include="..\..\src\joystick\hidapi\SDL_hidapijoystick.c" />
<ClCompile Include="..\..\src\joystick\hidapi\SDL_hidapi_gamecube.c" />
Expand Down
27 changes: 17 additions & 10 deletions VisualC/SDL/SDL.vcxproj.filters
Expand Up @@ -231,6 +231,7 @@
<ClInclude Include="..\..\include\SDL_vulkan.h">
<Filter>API Headers</Filter>
</ClInclude>
<ClInclude Include="..\..\include\SDL_misc.h" />
<ClInclude Include="..\..\src\audio\directsound\SDL_directsound.h" />
<ClInclude Include="..\..\src\audio\disk\SDL_diskaudio.h" />
<ClInclude Include="..\..\src\audio\dummy\SDL_dummyaudio.h" />
Expand Down Expand Up @@ -262,12 +263,15 @@
<ClInclude Include="..\..\src\haptic\windows\SDL_dinputhaptic_c.h" />
<ClInclude Include="..\..\src\haptic\windows\SDL_windowshaptic_c.h" />
<ClInclude Include="..\..\src\haptic\windows\SDL_xinputhaptic_c.h" />
<ClInclude Include="..\..\src\hidapi\hidapi\hidapi.h" />
<ClInclude Include="..\..\src\joystick\controller_type.h" />
<ClInclude Include="..\..\src\joystick\hidapi\SDL_hidapijoystick_c.h" />
<ClInclude Include="..\..\src\joystick\SDL_gamecontrollerdb.h" />
<ClInclude Include="..\..\src\joystick\SDL_joystick_c.h" />
<ClInclude Include="..\..\src\joystick\SDL_sysjoystick.h" />
<ClInclude Include="..\..\src\joystick\virtual\SDL_virtualjoystick_c.h" />
<ClInclude Include="..\..\src\joystick\windows\SDL_dinputjoystick_c.h" />
<ClInclude Include="..\..\src\joystick\windows\SDL_rawinputjoystick_c.h" />
<ClInclude Include="..\..\src\joystick\windows\SDL_windowsjoystick_c.h" />
<ClInclude Include="..\..\src\joystick\windows\SDL_xinputjoystick_c.h" />
<ClInclude Include="..\..\src\libm\math_libm.h" />
Expand All @@ -294,6 +298,7 @@
<ClInclude Include="..\..\src\sensor\dummy\SDL_dummysensor.h" />
<ClInclude Include="..\..\src\sensor\SDL_sensor_c.h" />
<ClInclude Include="..\..\src\sensor\SDL_syssensor.h" />
<ClInclude Include="..\..\src\sensor\windows\SDL_windowssensor.h" />
<ClInclude Include="..\..\src\thread\SDL_systhread.h" />
<ClInclude Include="..\..\src\thread\SDL_thread_c.h" />
<ClInclude Include="..\..\src\thread\windows\SDL_systhread_c.h" />
Expand Down Expand Up @@ -327,10 +332,7 @@
<ClInclude Include="..\..\src\video\windows\SDL_windowswindow.h" />
<ClInclude Include="..\..\src\video\windows\wmmsg.h" />
<ClInclude Include="..\..\src\video\yuv2rgb\yuv_rgb.h" />
<ClInclude Include="..\..\src\joystick\windows\SDL_rawinputjoystick_c.h" />
<ClInclude Include="..\..\src\hidapi\hidapi\hidapi.h" />
<ClInclude Include="..\..\src\joystick\SDL_gamecontrollerdb.h" />
<ClInclude Include="..\..\src\sensor\windows\SDL_windowssensor.h" />
<ClInclude Include="..\..\src\core\windows\SDL_hid.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\..\src\atomic\SDL_atomic.c" />
Expand All @@ -348,6 +350,7 @@
<ClCompile Include="..\..\src\audio\wasapi\SDL_wasapi.c" />
<ClCompile Include="..\..\src\audio\wasapi\SDL_wasapi_win32.c" />
<ClCompile Include="..\..\src\audio\winmm\SDL_winmm.c" />
<ClCompile Include="..\..\src\core\windows\SDL_hid.c" />
<ClCompile Include="..\..\src\core\windows\SDL_windows.c" />
<ClCompile Include="..\..\src\core\windows\SDL_xinput.c" />
<ClCompile Include="..\..\src\cpuinfo\SDL_cpuinfo.c" />
Expand All @@ -364,13 +367,16 @@
<ClCompile Include="..\..\src\events\SDL_windowevents.c" />
<ClCompile Include="..\..\src\file\SDL_rwops.c" />
<ClCompile Include="..\..\src\filesystem\windows\SDL_sysfilesystem.c" />
<ClCompile Include="..\..\src\haptic\dummy\SDL_syshaptic.c" />
<ClCompile Include="..\..\src\haptic\SDL_haptic.c" />
<ClCompile Include="..\..\src\haptic\windows\SDL_dinputhaptic.c" />
<ClCompile Include="..\..\src\haptic\windows\SDL_windowshaptic.c" />
<ClCompile Include="..\..\src\haptic\windows\SDL_xinputhaptic.c" />
<ClCompile Include="..\..\src\hidapi\windows\hid.c" />
<ClCompile Include="..\..\src\hidapi\SDL_hidapi.c" />
<ClCompile Include="..\..\src\joystick\dummy\SDL_sysjoystick.c" />
<ClCompile Include="..\..\src\joystick\hidapi\SDL_hidapi_gamecube.c" />
<ClCompile Include="..\..\src\joystick\hidapi\SDL_hidapi_ps4.c" />
<ClCompile Include="..\..\src\joystick\hidapi\SDL_hidapi_ps5.c" />
<ClCompile Include="..\..\src\joystick\hidapi\SDL_hidapi_rumble.c" />
<ClCompile Include="..\..\src\joystick\hidapi\SDL_hidapi_switch.c" />
<ClCompile Include="..\..\src\joystick\hidapi\SDL_hidapi_xbox360.c" />
Expand All @@ -382,6 +388,8 @@
<ClCompile Include="..\..\src\joystick\virtual\SDL_virtualjoystick.c" />
<ClCompile Include="..\..\src\joystick\windows\SDL_dinputjoystick.c" />
<ClCompile Include="..\..\src\joystick\windows\SDL_mmjoystick.c" />
<ClCompile Include="..\..\src\joystick\windows\SDL_rawinputjoystick.c" />
<ClCompile Include="..\..\src\joystick\windows\SDL_windows_gaming_input.c" />
<ClCompile Include="..\..\src\joystick\windows\SDL_windowsjoystick.c" />
<ClCompile Include="..\..\src\joystick\windows\SDL_xinputjoystick.c" />
<ClCompile Include="..\..\src\libm\e_atan2.c" />
Expand All @@ -407,6 +415,8 @@
<ClCompile Include="..\..\src\loadso\windows\SDL_sysloadso.c" />
<ClCompile Include="..\..\src\locale\SDL_locale.c" />
<ClCompile Include="..\..\src\locale\windows\SDL_syslocale.c" />
<ClCompile Include="..\..\src\misc\SDL_url.c" />
<ClCompile Include="..\..\src\misc\windows\SDL_sysurl.c" />
<ClCompile Include="..\..\src\power\SDL_power.c" />
<ClCompile Include="..\..\src\power\windows\SDL_syspower.c" />
<ClCompile Include="..\..\src\render\direct3d\SDL_render_d3d.c" />
Expand Down Expand Up @@ -435,6 +445,8 @@
<ClCompile Include="..\..\src\SDL_log.c" />
<ClCompile Include="..\..\src\sensor\dummy\SDL_dummysensor.c" />
<ClCompile Include="..\..\src\sensor\SDL_sensor.c" />
<ClCompile Include="..\..\src\sensor\windows\SDL_windowssensor.c" />
<ClCompile Include="..\..\src\stdlib\SDL_crc32.c" />
<ClCompile Include="..\..\src\stdlib\SDL_getenv.c" />
<ClCompile Include="..\..\src\stdlib\SDL_iconv.c" />
<ClCompile Include="..\..\src\stdlib\SDL_malloc.c" />
Expand Down Expand Up @@ -488,11 +500,6 @@
<ClCompile Include="..\..\src\video\windows\SDL_windowsvulkan.c" />
<ClCompile Include="..\..\src\video\windows\SDL_windowswindow.c" />
<ClCompile Include="..\..\src\video\yuv2rgb\yuv_rgb.c" />
<ClCompile Include="..\..\src\joystick\windows\SDL_rawinputjoystick.c" />
<ClCompile Include="..\..\src\sensor\windows\SDL_windowssensor.c" />
<ClCompile Include="..\..\src\haptic\dummy\SDL_syshaptic.c" />
<ClCompile Include="..\..\src\joystick\dummy\SDL_sysjoystick.c" />
<ClCompile Include="..\..\src\joystick\windows\SDL_windows_gaming_input.c" />
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="..\..\src\main\windows\version.rc" />
Expand Down
95 changes: 95 additions & 0 deletions src/core/windows/SDL_hid.c
@@ -0,0 +1,95 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "../../SDL_internal.h"

#ifndef __WINRT__

#include "SDL_assert.h"
#include "SDL_hid.h"


HidD_GetString_t SDL_HidD_GetManufacturerString;
HidD_GetString_t SDL_HidD_GetProductString;
HidD_GetPreparsedData_t SDL_HidD_GetPreparsedData;
HidD_FreePreparsedData_t SDL_HidD_FreePreparsedData;
HidP_GetCaps_t SDL_HidP_GetCaps;
HidP_GetButtonCaps_t SDL_HidP_GetButtonCaps;
HidP_GetValueCaps_t SDL_HidP_GetValueCaps;
HidP_MaxDataListLength_t SDL_HidP_MaxDataListLength;
HidP_GetData_t SDL_HidP_GetData;

static HMODULE s_pHIDDLL = 0;
static int s_HIDDLLRefCount = 0;


int
WIN_LoadHIDDLL(void)
{
if (s_pHIDDLL) {
SDL_assert(s_HIDDLLRefCount > 0);
s_HIDDLLRefCount++;
return 0; /* already loaded */
}

s_pHIDDLL = LoadLibrary(L"hid.dll");
if (!s_pHIDDLL) {
return -1;
}

SDL_assert(s_HIDDLLRefCount == 0);
s_HIDDLLRefCount = 1;

SDL_HidD_GetManufacturerString = (HidD_GetString_t)GetProcAddress(s_pHIDDLL, "HidD_GetManufacturerString");
SDL_HidD_GetProductString = (HidD_GetString_t)GetProcAddress(s_pHIDDLL, "HidD_GetProductString");
SDL_HidD_GetPreparsedData = (HidD_GetPreparsedData_t)GetProcAddress(s_pHIDDLL, "HidD_GetPreparsedData");
SDL_HidD_FreePreparsedData = (HidD_FreePreparsedData_t)GetProcAddress(s_pHIDDLL, "HidD_FreePreparsedData");
SDL_HidP_GetCaps = (HidP_GetCaps_t)GetProcAddress(s_pHIDDLL, "HidP_GetCaps");
SDL_HidP_GetButtonCaps = (HidP_GetButtonCaps_t)GetProcAddress(s_pHIDDLL, "HidP_GetButtonCaps");
SDL_HidP_GetValueCaps = (HidP_GetValueCaps_t)GetProcAddress(s_pHIDDLL, "HidP_GetValueCaps");
SDL_HidP_MaxDataListLength = (HidP_MaxDataListLength_t)GetProcAddress(s_pHIDDLL, "HidP_MaxDataListLength");
SDL_HidP_GetData = (HidP_GetData_t)GetProcAddress(s_pHIDDLL, "HidP_GetData");
if (!SDL_HidD_GetManufacturerString || !SDL_HidD_GetProductString || !SDL_HidD_GetPreparsedData ||
!SDL_HidD_FreePreparsedData || !SDL_HidP_GetCaps || !SDL_HidP_GetButtonCaps ||
!SDL_HidP_GetValueCaps || !SDL_HidP_MaxDataListLength || !SDL_HidP_GetData) {
WIN_UnloadHIDDLL();
return -1;
}

return 0;
}

void
WIN_UnloadHIDDLL(void)
{
if (s_pHIDDLL) {
SDL_assert(s_HIDDLLRefCount > 0);
if (--s_HIDDLLRefCount == 0) {
FreeLibrary(s_pHIDDLL);
s_pHIDDLL = NULL;
}
} else {
SDL_assert(s_HIDDLLRefCount == 0);
}
}

#endif /* !__WINRT__ */

/* vi: set ts=4 sw=4 expandtab: */

0 comments on commit 5b3616c

Please sign in to comment.