Rolling back GameCube HIDAPI support
authorSam Lantinga <slouken@libsdl.org>
Wed, 19 Jun 2019 15:54:21 -0700
changeset 12896b91647e1a977
parent 12895 ae044ecb144f
child 12897 25998acc4810
Rolling back GameCube HIDAPI support
It causes the HIDAPI devices to always be opened on enumeration, which causes crashes in the Windows drivers when multiple applications are reading and writing at the same time. We can revisit this after 2.0.10 release.
VisualC/SDL/SDL.vcxproj
VisualC/SDL/SDL.vcxproj.filters
Xcode-iOS/SDL/SDL.xcodeproj/project.pbxproj
Xcode/SDL/SDL.xcodeproj/project.pbxproj
include/SDL_hints.h
src/joystick/SDL_joystick.c
src/joystick/SDL_joystick_c.h
src/joystick/SDL_sysjoystick.h
src/joystick/controller_type.h
src/joystick/hidapi/SDL_hidapi_gamecube.c
src/joystick/hidapi/SDL_hidapi_ps4.c
src/joystick/hidapi/SDL_hidapi_switch.c
src/joystick/hidapi/SDL_hidapi_xbox360.c
src/joystick/hidapi/SDL_hidapi_xboxone.c
src/joystick/hidapi/SDL_hidapijoystick.c
src/joystick/hidapi/SDL_hidapijoystick_c.h
     1.1 --- a/VisualC/SDL/SDL.vcxproj	Wed Jun 19 06:43:54 2019 -0700
     1.2 +++ b/VisualC/SDL/SDL.vcxproj	Wed Jun 19 15:54:21 2019 -0700
     1.3 @@ -421,7 +421,6 @@
     1.4      <ClCompile Include="..\..\src\haptic\windows\SDL_xinputhaptic.c" />
     1.5      <ClCompile Include="..\..\src\hidapi\windows\hid.c" />
     1.6      <ClCompile Include="..\..\src\joystick\hidapi\SDL_hidapijoystick.c" />
     1.7 -    <ClCompile Include="..\..\src\joystick\hidapi\SDL_hidapi_gamecube.c" />
     1.8      <ClCompile Include="..\..\src\joystick\hidapi\SDL_hidapi_ps4.c" />
     1.9      <ClCompile Include="..\..\src\joystick\hidapi\SDL_hidapi_switch.c" />
    1.10      <ClCompile Include="..\..\src\joystick\hidapi\SDL_hidapi_xbox360.c" />
     2.1 --- a/VisualC/SDL/SDL.vcxproj.filters	Wed Jun 19 06:43:54 2019 -0700
     2.2 +++ b/VisualC/SDL/SDL.vcxproj.filters	Wed Jun 19 15:54:21 2019 -0700
     2.3 @@ -360,7 +360,6 @@
     2.4      <ClCompile Include="..\..\src\haptic\windows\SDL_windowshaptic.c" />
     2.5      <ClCompile Include="..\..\src\haptic\windows\SDL_xinputhaptic.c" />
     2.6      <ClCompile Include="..\..\src\hidapi\windows\hid.c" />
     2.7 -    <ClCompile Include="..\..\src\joystick\hidapi\SDL_hidapi_gamecube.c" />
     2.8      <ClCompile Include="..\..\src\joystick\hidapi\SDL_hidapi_ps4.c" />
     2.9      <ClCompile Include="..\..\src\joystick\hidapi\SDL_hidapi_switch.c" />
    2.10      <ClCompile Include="..\..\src\joystick\hidapi\SDL_hidapi_xbox360.c" />
     3.1 --- a/Xcode-iOS/SDL/SDL.xcodeproj/project.pbxproj	Wed Jun 19 06:43:54 2019 -0700
     3.2 +++ b/Xcode-iOS/SDL/SDL.xcodeproj/project.pbxproj	Wed Jun 19 15:54:21 2019 -0700
     3.3 @@ -468,9 +468,6 @@
     3.4  		F3BDD79B20F51CB8004ECBF3 /* SDL_hidapijoystick_c.h in Headers */ = {isa = PBXBuildFile; fileRef = F3BDD79020F51CB8004ECBF3 /* SDL_hidapijoystick_c.h */; };
     3.5  		F3BDD79C20F51CB8004ECBF3 /* SDL_hidapijoystick.c in Sources */ = {isa = PBXBuildFile; fileRef = F3BDD79120F51CB8004ECBF3 /* SDL_hidapijoystick.c */; };
     3.6  		F3BDD79D20F51CB8004ECBF3 /* SDL_hidapijoystick.c in Sources */ = {isa = PBXBuildFile; fileRef = F3BDD79120F51CB8004ECBF3 /* SDL_hidapijoystick.c */; };
     3.7 -		F3E3C55D223DEC6C007D243C /* SDL_hidapi_gamecube.c in Sources */ = {isa = PBXBuildFile; fileRef = F3E3C55C223DEC6C007D243C /* SDL_hidapi_gamecube.c */; };
     3.8 -		F3E3C55E223DEC6C007D243C /* SDL_hidapi_gamecube.c in Sources */ = {isa = PBXBuildFile; fileRef = F3E3C55C223DEC6C007D243C /* SDL_hidapi_gamecube.c */; };
     3.9 -		F3E3C55F224065AE007D243C /* SDL_hidapi_gamecube.c in Sources */ = {isa = PBXBuildFile; fileRef = F3E3C55C223DEC6C007D243C /* SDL_hidapi_gamecube.c */; };
    3.10  		F3E3C658224069CE007D243C /* SDL_uikit_main.c in Sources */ = {isa = PBXBuildFile; fileRef = F3E3C657224069CE007D243C /* SDL_uikit_main.c */; };
    3.11  		F3E3C65B2241389A007D243C /* SDL_blit.h in Headers */ = {isa = PBXBuildFile; fileRef = FDA683010DF2374E00F98A1A /* SDL_blit.h */; };
    3.12  		F3E3C65C2241389A007D243C /* SDL_uikitmetalview.h in Headers */ = {isa = PBXBuildFile; fileRef = 4D7517191EE1D32200820EEA /* SDL_uikitmetalview.h */; };
    3.13 @@ -657,7 +654,6 @@
    3.14  		F3E3C7122241389A007D243C /* SDL_uikitevents.m in Sources */ = {isa = PBXBuildFile; fileRef = FD689F0D0E26E5D900F90B21 /* SDL_uikitevents.m */; };
    3.15  		F3E3C7132241389A007D243C /* yuv_rgb.c in Sources */ = {isa = PBXBuildFile; fileRef = AA13B3561FB8B46300D9FEE6 /* yuv_rgb.c */; };
    3.16  		F3E3C7142241389A007D243C /* SDL_uikitopengles.m in Sources */ = {isa = PBXBuildFile; fileRef = FD689F0F0E26E5D900F90B21 /* SDL_uikitopengles.m */; };
    3.17 -		F3E3C7152241389A007D243C /* SDL_hidapi_gamecube.c in Sources */ = {isa = PBXBuildFile; fileRef = F3E3C55C223DEC6C007D243C /* SDL_hidapi_gamecube.c */; };
    3.18  		F3E3C7162241389A007D243C /* SDL_uikitvideo.m in Sources */ = {isa = PBXBuildFile; fileRef = FD689F110E26E5D900F90B21 /* SDL_uikitvideo.m */; };
    3.19  		F3E3C7172241389A007D243C /* SDL_uikitview.m in Sources */ = {isa = PBXBuildFile; fileRef = FD689F130E26E5D900F90B21 /* SDL_uikitview.m */; };
    3.20  		F3E3C7182241389A007D243C /* SDL_displayevents.c in Sources */ = {isa = PBXBuildFile; fileRef = A7C19D28212E552B00DF2152 /* SDL_displayevents.c */; };
    3.21 @@ -1062,7 +1058,6 @@
    3.22  		F3BDD78E20F51CB8004ECBF3 /* SDL_hidapi_ps4.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = SDL_hidapi_ps4.c; sourceTree = "<group>"; };
    3.23  		F3BDD79020F51CB8004ECBF3 /* SDL_hidapijoystick_c.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDL_hidapijoystick_c.h; sourceTree = "<group>"; };
    3.24  		F3BDD79120F51CB8004ECBF3 /* SDL_hidapijoystick.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = SDL_hidapijoystick.c; sourceTree = "<group>"; };
    3.25 -		F3E3C55C223DEC6C007D243C /* SDL_hidapi_gamecube.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = SDL_hidapi_gamecube.c; sourceTree = "<group>"; };
    3.26  		F3E3C65222406928007D243C /* libSDLmain.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libSDLmain.a; sourceTree = BUILT_PRODUCTS_DIR; };
    3.27  		F3E3C657224069CE007D243C /* SDL_uikit_main.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = SDL_uikit_main.c; sourceTree = "<group>"; };
    3.28  		F3E3C7572241389A007D243C /* libSDL2.dylib */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libSDL2.dylib; sourceTree = BUILT_PRODUCTS_DIR; };
    3.29 @@ -1463,7 +1458,6 @@
    3.30  		F3BDD78A20F51C8D004ECBF3 /* hidapi */ = {
    3.31  			isa = PBXGroup;
    3.32  			children = (
    3.33 -				F3E3C55C223DEC6C007D243C /* SDL_hidapi_gamecube.c */,
    3.34  				F3BDD78E20F51CB8004ECBF3 /* SDL_hidapi_ps4.c */,
    3.35  				F3BDD78C20F51CB8004ECBF3 /* SDL_hidapi_switch.c */,
    3.36  				F3BDD78B20F51CB8004ECBF3 /* SDL_hidapi_xbox360.c */,
    3.37 @@ -2518,7 +2512,6 @@
    3.38  				52ED1E24222889500061FCE0 /* SDL_uikitevents.m in Sources */,
    3.39  				52ED1E25222889500061FCE0 /* yuv_rgb.c in Sources */,
    3.40  				52ED1E26222889500061FCE0 /* SDL_uikitopengles.m in Sources */,
    3.41 -				F3E3C55F224065AE007D243C /* SDL_hidapi_gamecube.c in Sources */,
    3.42  				52ED1E27222889500061FCE0 /* SDL_uikitvideo.m in Sources */,
    3.43  				52ED1E28222889500061FCE0 /* SDL_uikitview.m in Sources */,
    3.44  				52ED1E29222889500061FCE0 /* SDL_displayevents.c in Sources */,
    3.45 @@ -2647,7 +2640,6 @@
    3.46  				F3E3C7122241389A007D243C /* SDL_uikitevents.m in Sources */,
    3.47  				F3E3C7132241389A007D243C /* yuv_rgb.c in Sources */,
    3.48  				F3E3C7142241389A007D243C /* SDL_uikitopengles.m in Sources */,
    3.49 -				F3E3C7152241389A007D243C /* SDL_hidapi_gamecube.c in Sources */,
    3.50  				F3E3C7162241389A007D243C /* SDL_uikitvideo.m in Sources */,
    3.51  				F3E3C7172241389A007D243C /* SDL_uikitview.m in Sources */,
    3.52  				F3E3C7182241389A007D243C /* SDL_displayevents.c in Sources */,
    3.53 @@ -2824,7 +2816,6 @@
    3.54  				FAB598BD1BB5C31600BE72C5 /* SDL_hints.c in Sources */,
    3.55  				FAB598BE1BB5C31600BE72C5 /* SDL_log.c in Sources */,
    3.56  				FAB598BF1BB5C31600BE72C5 /* SDL.c in Sources */,
    3.57 -				F3E3C55E223DEC6C007D243C /* SDL_hidapi_gamecube.c in Sources */,
    3.58  			);
    3.59  			runOnlyForDeploymentPostprocessing = 0;
    3.60  		};
    3.61 @@ -2895,7 +2886,6 @@
    3.62  				FD689F1D0E26E5D900F90B21 /* SDL_uikitevents.m in Sources */,
    3.63  				AA13B35A1FB8B46400D9FEE6 /* yuv_rgb.c in Sources */,
    3.64  				FD689F1F0E26E5D900F90B21 /* SDL_uikitopengles.m in Sources */,
    3.65 -				F3E3C55D223DEC6C007D243C /* SDL_hidapi_gamecube.c in Sources */,
    3.66  				FD689F210E26E5D900F90B21 /* SDL_uikitvideo.m in Sources */,
    3.67  				FD689F230E26E5D900F90B21 /* SDL_uikitview.m in Sources */,
    3.68  				A7C19D2A212E552C00DF2152 /* SDL_displayevents.c in Sources */,
     4.1 --- a/Xcode/SDL/SDL.xcodeproj/project.pbxproj	Wed Jun 19 06:43:54 2019 -0700
     4.2 +++ b/Xcode/SDL/SDL.xcodeproj/project.pbxproj	Wed Jun 19 15:54:21 2019 -0700
     4.3 @@ -919,9 +919,6 @@
     4.4  		F3950CD8212BC88D00F51292 /* SDL_sensor.h in Headers */ = {isa = PBXBuildFile; fileRef = F3950CD7212BC88D00F51292 /* SDL_sensor.h */; settings = {ATTRIBUTES = (Public, ); }; };
     4.5  		F3950CD9212BC88D00F51292 /* SDL_sensor.h in Headers */ = {isa = PBXBuildFile; fileRef = F3950CD7212BC88D00F51292 /* SDL_sensor.h */; settings = {ATTRIBUTES = (Public, ); }; };
     4.6  		F3950CDA212BC88D00F51292 /* SDL_sensor.h in Headers */ = {isa = PBXBuildFile; fileRef = F3950CD7212BC88D00F51292 /* SDL_sensor.h */; settings = {ATTRIBUTES = (Public, ); }; };
     4.7 -		F3E3C559223DEBC7007D243C /* SDL_hidapi_gamecube.c in Sources */ = {isa = PBXBuildFile; fileRef = F3E3C558223DEBC7007D243C /* SDL_hidapi_gamecube.c */; };
     4.8 -		F3E3C55A223DEBC7007D243C /* SDL_hidapi_gamecube.c in Sources */ = {isa = PBXBuildFile; fileRef = F3E3C558223DEBC7007D243C /* SDL_hidapi_gamecube.c */; };
     4.9 -		F3E3C55B223DEBC7007D243C /* SDL_hidapi_gamecube.c in Sources */ = {isa = PBXBuildFile; fileRef = F3E3C558223DEBC7007D243C /* SDL_hidapi_gamecube.c */; };
    4.10  		FA73671D19A540EF004122E4 /* CoreVideo.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = FA73671C19A540EF004122E4 /* CoreVideo.framework */; };
    4.11  		FA73671E19A54140004122E4 /* CoreVideo.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = FA73671C19A540EF004122E4 /* CoreVideo.framework */; };
    4.12  		FA73671F19A54144004122E4 /* CoreVideo.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = FA73671C19A540EF004122E4 /* CoreVideo.framework */; };
    4.13 @@ -1252,7 +1249,6 @@
    4.14  		F30D9CCB212EB4810047DF2E /* SDL_displayevents_c.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDL_displayevents_c.h; sourceTree = "<group>"; };
    4.15  		F30D9CCC212EB4810047DF2E /* SDL_displayevents.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = SDL_displayevents.c; sourceTree = "<group>"; };
    4.16  		F3950CD7212BC88D00F51292 /* SDL_sensor.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDL_sensor.h; sourceTree = "<group>"; };
    4.17 -		F3E3C558223DEBC7007D243C /* SDL_hidapi_gamecube.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = SDL_hidapi_gamecube.c; sourceTree = "<group>"; };
    4.18  		F59C710300D5CB5801000001 /* ReadMe.txt */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = text; path = ReadMe.txt; sourceTree = "<group>"; };
    4.19  		F59C710600D5CB5801000001 /* SDL.info */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = text; path = SDL.info; sourceTree = "<group>"; };
    4.20  		F5A2EF3900C6A39A01000001 /* BUGS.txt */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = text; name = BUGS.txt; path = ../../BUGS.txt; sourceTree = SOURCE_ROOT; };
    4.21 @@ -1932,7 +1928,6 @@
    4.22  		A704170C20F09AA600A82227 /* hidapi */ = {
    4.23  			isa = PBXGroup;
    4.24  			children = (
    4.25 -				F3E3C558223DEBC7007D243C /* SDL_hidapi_gamecube.c */,
    4.26  				A704171120F09AC900A82227 /* SDL_hidapi_ps4.c */,
    4.27  				A704170F20F09AC800A82227 /* SDL_hidapi_switch.c */,
    4.28  				A704171320F09AC900A82227 /* SDL_hidapi_xbox360.c */,
    4.29 @@ -2707,7 +2702,6 @@
    4.30  				04BD005B12E6671800899322 /* SDL_syshaptic.c in Sources */,
    4.31  				04BD005F12E6671800899322 /* SDL_haptic.c in Sources */,
    4.32  				4D1664551EDD60AD003DE88E /* SDL_cocoavulkan.m in Sources */,
    4.33 -				F3E3C559223DEBC7007D243C /* SDL_hidapi_gamecube.c in Sources */,
    4.34  				04BD006612E6671800899322 /* SDL_sysjoystick.c in Sources */,
    4.35  				04BD007012E6671800899322 /* SDL_joystick.c in Sources */,
    4.36  				04BD008812E6671800899322 /* SDL_sysloadso.c in Sources */,
    4.37 @@ -2846,7 +2840,6 @@
    4.38  				04BD026D12E6671800899322 /* SDL_quit.c in Sources */,
    4.39  				04BD026F12E6671800899322 /* SDL_touch.c in Sources */,
    4.40  				04BD027112E6671800899322 /* SDL_windowevents.c in Sources */,
    4.41 -				F3E3C55A223DEBC7007D243C /* SDL_hidapi_gamecube.c in Sources */,
    4.42  				04BD027412E6671800899322 /* SDL_rwopsbundlesupport.m in Sources */,
    4.43  				04BD027512E6671800899322 /* SDL_rwops.c in Sources */,
    4.44  				04BD027612E6671800899322 /* SDL_syshaptic.c in Sources */,
    4.45 @@ -2985,7 +2978,6 @@
    4.46  				DB31401017554B71006C0E22 /* SDL_quit.c in Sources */,
    4.47  				DB31401117554B71006C0E22 /* SDL_touch.c in Sources */,
    4.48  				DB31401217554B71006C0E22 /* SDL_windowevents.c in Sources */,
    4.49 -				F3E3C55B223DEBC7007D243C /* SDL_hidapi_gamecube.c in Sources */,
    4.50  				DB31401317554B71006C0E22 /* SDL_rwopsbundlesupport.m in Sources */,
    4.51  				DB31401417554B71006C0E22 /* SDL_rwops.c in Sources */,
    4.52  				DB31401517554B71006C0E22 /* SDL_syshaptic.c in Sources */,
     5.1 --- a/include/SDL_hints.h	Wed Jun 19 06:43:54 2019 -0700
     5.2 +++ b/include/SDL_hints.h	Wed Jun 19 15:54:21 2019 -0700
     5.3 @@ -566,17 +566,6 @@
     5.4  #define SDL_HINT_JOYSTICK_HIDAPI_XBOX   "SDL_JOYSTICK_HIDAPI_XBOX"
     5.5  
     5.6  /**
     5.7 - *  \brief  A variable controlling whether the HIDAPI driver for Nintendo GameCube controllers should be used.
     5.8 - *
     5.9 - *  This variable can be set to the following values:
    5.10 - *    "0"       - HIDAPI driver is not used
    5.11 - *    "1"       - HIDAPI driver is used
    5.12 - *
    5.13 - *  The default is the value of SDL_HINT_JOYSTICK_HIDAPI
    5.14 - */
    5.15 -#define SDL_HINT_JOYSTICK_HIDAPI_GAMECUBE "SDL_JOYSTICK_HIDAPI_GAMECUBE"
    5.16 -
    5.17 -/**
    5.18   *  \brief  A variable that controls whether Steam Controllers should be exposed using the SDL joystick and game controller APIs
    5.19   *
    5.20   *  The variable can be set to the following values:
     6.1 --- a/src/joystick/SDL_joystick.c	Wed Jun 19 06:43:54 2019 -0700
     6.2 +++ b/src/joystick/SDL_joystick.c	Wed Jun 19 15:54:21 2019 -0700
     6.3 @@ -1037,11 +1037,6 @@
     6.4      /* Make sure the list is unlocked while dispatching events to prevent application deadlocks */
     6.5      SDL_UnlockJoysticks();
     6.6  
     6.7 -    /* Special function for HIDAPI devices, as a single device can provide multiple SDL_Joysticks */
     6.8 -#ifdef SDL_JOYSTICK_HIDAPI
     6.9 -    SDL_HIDAPI_UpdateDevices();
    6.10 -#endif /* SDL_JOYSTICK_HIDAPI */
    6.11 -
    6.12      for (joystick = SDL_joysticks; joystick; joystick = joystick->next) {
    6.13          if (joystick->attached) {
    6.14              /* This should always be true, but seeing a crash in the wild...? */
    6.15 @@ -1200,12 +1195,6 @@
    6.16  }
    6.17  
    6.18  SDL_bool
    6.19 -SDL_IsJoystickGameCube(Uint16 vendor, Uint16 product)
    6.20 -{
    6.21 -    return (GuessControllerType(vendor, product) == k_eControllerType_GameCube);
    6.22 -}
    6.23 -
    6.24 -SDL_bool
    6.25  SDL_IsJoystickXInput(SDL_JoystickGUID guid)
    6.26  {
    6.27      return (guid.data[14] == 'x') ? SDL_TRUE : SDL_FALSE;
     7.1 --- a/src/joystick/SDL_joystick_c.h	Wed Jun 19 06:43:54 2019 -0700
     7.2 +++ b/src/joystick/SDL_joystick_c.h	Wed Jun 19 15:54:21 2019 -0700
     7.3 @@ -66,9 +66,6 @@
     7.4  /* Function to return whether a joystick is an Xbox One controller */
     7.5  extern SDL_bool SDL_IsJoystickXboxOne(Uint16 vendor_id, Uint16 product_id);
     7.6  
     7.7 -/* Function to return whether a joystick is a GameCube controller */
     7.8 -extern SDL_bool SDL_IsJoystickGameCube(Uint16 vendor_id, Uint16 product_id);
     7.9 -
    7.10  /* Function to return whether a joystick guid comes from the XInput driver */
    7.11  extern SDL_bool SDL_IsJoystickXInput(SDL_JoystickGUID guid);
    7.12  
     8.1 --- a/src/joystick/SDL_sysjoystick.h	Wed Jun 19 06:43:54 2019 -0700
     8.2 +++ b/src/joystick/SDL_sysjoystick.h	Wed Jun 19 15:54:21 2019 -0700
     8.3 @@ -152,9 +152,6 @@
     8.4  extern SDL_JoystickDriver SDL_LINUX_JoystickDriver;
     8.5  extern SDL_JoystickDriver SDL_WINDOWS_JoystickDriver;
     8.6  
     8.7 -/* Special function to update HIDAPI devices */
     8.8 -extern void SDL_HIDAPI_UpdateDevices(void);
     8.9 -
    8.10  #endif /* SDL_sysjoystick_h_ */
    8.11  
    8.12  /* vi: set ts=4 sw=4 expandtab: */
     9.1 --- a/src/joystick/controller_type.h	Wed Jun 19 06:43:54 2019 -0700
     9.2 +++ b/src/joystick/controller_type.h	Wed Jun 19 15:54:21 2019 -0700
     9.3 @@ -57,7 +57,6 @@
     9.4  	k_eControllerType_SwitchJoyConPair = 41,
     9.5      k_eControllerType_SwitchInputOnlyController = 42,
     9.6  	k_eControllerType_MobileTouch = 43,
     9.7 -        k_eControllerType_GameCube = 44,
     9.8  	k_eControllerType_LastController,			// Don't add game controllers below this enumeration - this enumeration can change value
     9.9  
    9.10  	// Keyboards and Mice
    9.11 @@ -388,8 +387,6 @@
    9.12      { MAKE_CONTROLLER_ID( 0x20d6, 0xa711 ), k_eControllerType_SwitchInputOnlyController },  // PowerA Wired Controller Plus
    9.13      { MAKE_CONTROLLER_ID( 0x0f0d, 0x0092 ), k_eControllerType_SwitchInputOnlyController },  // HORI Pokken Tournament DX Pro Pad
    9.14  
    9.15 -    { MAKE_CONTROLLER_ID( 0x057e, 0x0337 ), k_eControllerType_GameCube }, // Nintendo Wii U/Switch GameCube USB Adapter
    9.16 -
    9.17  
    9.18  	// Valve products - don't add to public list
    9.19      { MAKE_CONTROLLER_ID( 0x0000, 0x11fb ), k_eControllerType_MobileTouch },		// Streaming mobile touch virtual controls
    10.1 --- a/src/joystick/hidapi/SDL_hidapi_gamecube.c	Wed Jun 19 06:43:54 2019 -0700
    10.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    10.3 @@ -1,380 +0,0 @@
    10.4 -/*
    10.5 -  Simple DirectMedia Layer
    10.6 -  Copyright (C) 1997-2019 Sam Lantinga <slouken@libsdl.org>
    10.7 -
    10.8 -  This software is provided 'as-is', without any express or implied
    10.9 -  warranty.  In no event will the authors be held liable for any damages
   10.10 -  arising from the use of this software.
   10.11 -
   10.12 -  Permission is granted to anyone to use this software for any purpose,
   10.13 -  including commercial applications, and to alter it and redistribute it
   10.14 -  freely, subject to the following restrictions:
   10.15 -
   10.16 -  1. The origin of this software must not be misrepresented; you must not
   10.17 -     claim that you wrote the original software. If you use this software
   10.18 -     in a product, an acknowledgment in the product documentation would be
   10.19 -     appreciated but is not required.
   10.20 -  2. Altered source versions must be plainly marked as such, and must not be
   10.21 -     misrepresented as being the original software.
   10.22 -  3. This notice may not be removed or altered from any source distribution.
   10.23 -*/
   10.24 -#include "../../SDL_internal.h"
   10.25 -
   10.26 -#ifdef SDL_JOYSTICK_HIDAPI
   10.27 -
   10.28 -#include "SDL_hints.h"
   10.29 -#include "SDL_log.h"
   10.30 -#include "SDL_events.h"
   10.31 -#include "SDL_timer.h"
   10.32 -#include "SDL_haptic.h"
   10.33 -#include "SDL_joystick.h"
   10.34 -#include "SDL_gamecontroller.h"
   10.35 -#include "../SDL_sysjoystick.h"
   10.36 -#include "SDL_hidapijoystick_c.h"
   10.37 -
   10.38 -
   10.39 -#ifdef SDL_JOYSTICK_HIDAPI_GAMECUBE
   10.40 -
   10.41 -typedef struct {
   10.42 -    SDL_JoystickID joysticks[4];
   10.43 -    Uint8 wireless[4];
   10.44 -    Uint8 rumbleAllowed[4];
   10.45 -    Uint8 rumble[5];
   10.46 -    Uint32 rumbleExpiration[4];
   10.47 -    /* Without this variable, hid_write starts to lag a TON */
   10.48 -    Uint8 rumbleUpdate;
   10.49 -} SDL_DriverGameCube_Context;
   10.50 -
   10.51 -static SDL_bool
   10.52 -HIDAPI_DriverGameCube_IsSupportedDevice(Uint16 vendor_id, Uint16 product_id, Uint16 version, int interface_number)
   10.53 -{
   10.54 -    return SDL_IsJoystickGameCube(vendor_id, product_id);
   10.55 -}
   10.56 -
   10.57 -static const char *
   10.58 -HIDAPI_DriverGameCube_GetDeviceName(Uint16 vendor_id, Uint16 product_id)
   10.59 -{
   10.60 -    /* Give a user friendly name for this controller */
   10.61 -    if (SDL_IsJoystickGameCube(vendor_id, product_id)) {
   10.62 -        return "Nintendo GameCube Controller";
   10.63 -    }
   10.64 -    return NULL;
   10.65 -}
   10.66 -
   10.67 -static SDL_bool
   10.68 -HIDAPI_DriverGameCube_InitDriver(SDL_HIDAPI_DriverData *context, Uint16 vendor_id, Uint16 product_id, int *num_joysticks)
   10.69 -{
   10.70 -    SDL_DriverGameCube_Context *ctx;
   10.71 -    Uint8 packet[37];
   10.72 -    Uint8 *curSlot;
   10.73 -    Uint8 i;
   10.74 -    int size;
   10.75 -    Uint8 initMagic = 0x13;
   10.76 -    Uint8 rumbleMagic = 0x11;
   10.77 -
   10.78 -    ctx = (SDL_DriverGameCube_Context *)SDL_calloc(1, sizeof(*ctx));
   10.79 -    if (!ctx) {
   10.80 -        SDL_OutOfMemory();
   10.81 -        return SDL_FALSE;
   10.82 -    }
   10.83 -    ctx->joysticks[0] = -1;
   10.84 -    ctx->joysticks[1] = -1;
   10.85 -    ctx->joysticks[2] = -1;
   10.86 -    ctx->joysticks[3] = -1;
   10.87 -    ctx->rumble[0] = rumbleMagic;
   10.88 -
   10.89 -    context->context = ctx;
   10.90 -
   10.91 -    /* This is all that's needed to initialize the device. Really! */
   10.92 -    if (hid_write(context->device, &initMagic, sizeof(initMagic)) <= 0) {
   10.93 -        SDL_SetError("Couldn't initialize WUP-028");
   10.94 -        SDL_free(ctx);
   10.95 -        return SDL_FALSE;
   10.96 -    }
   10.97 -
   10.98 -    /* Add all the applicable joysticks */
   10.99 -    while ((size = hid_read_timeout(context->device, packet, sizeof(packet), 0)) > 0) {
  10.100 -        if (size < 37 || packet[0] != 0x21) {
  10.101 -            continue; /* Nothing to do yet...? */
  10.102 -        }
  10.103 -
  10.104 -        /* Go through all 4 slots */
  10.105 -        curSlot = packet + 1;
  10.106 -        for (i = 0; i < 4; i += 1, curSlot += 9) {
  10.107 -            ctx->wireless[i] = (curSlot[0] & 0x20) != 0;
  10.108 -
  10.109 -            /* Only allow rumble if the adapter's second USB cable is connected */
  10.110 -            ctx->rumbleAllowed[i] = (curSlot[0] & 0x04) != 0 && !ctx->wireless[i];
  10.111 -
  10.112 -            if (curSlot[0] & 0x30) { /* 0x10 - Wired, 0x20 - Wireless */
  10.113 -                if (ctx->joysticks[i] == -1) {
  10.114 -                    ctx->joysticks[i] = SDL_GetNextJoystickInstanceID();
  10.115 -
  10.116 -                    *num_joysticks += 1;
  10.117 -
  10.118 -                    SDL_PrivateJoystickAdded(ctx->joysticks[i]);
  10.119 -                }
  10.120 -            } else {
  10.121 -                if (ctx->joysticks[i] != -1) {
  10.122 -                    SDL_PrivateJoystickRemoved(ctx->joysticks[i]);
  10.123 -
  10.124 -                    *num_joysticks -= 1;
  10.125 -
  10.126 -                    ctx->joysticks[i] = -1;
  10.127 -                }
  10.128 -                continue;
  10.129 -            }
  10.130 -        }
  10.131 -    }
  10.132 -
  10.133 -    return SDL_TRUE;
  10.134 -}
  10.135 -
  10.136 -static void
  10.137 -HIDAPI_DriverGameCube_QuitDriver(SDL_HIDAPI_DriverData *context, SDL_bool send_event, int *num_joysticks)
  10.138 -{
  10.139 -    SDL_DriverGameCube_Context *ctx = (SDL_DriverGameCube_Context *)context->context;
  10.140 -    Uint8 i;
  10.141 -
  10.142 -    /* Stop all rumble activity */
  10.143 -    for (i = 1; i < 5; i += 1) {
  10.144 -        ctx->rumble[i] = 0;
  10.145 -    }
  10.146 -    hid_write(context->device, ctx->rumble, sizeof(ctx->rumble));
  10.147 -
  10.148 -    /* Remove all joysticks! */
  10.149 -    for (i = 0; i < 4; i += 1) {
  10.150 -        if (ctx->joysticks[i] != -1) {
  10.151 -            *num_joysticks -= 1;
  10.152 -            if (send_event) {
  10.153 -                SDL_PrivateJoystickRemoved(ctx->joysticks[i]);
  10.154 -            }
  10.155 -        }
  10.156 -    }
  10.157 -
  10.158 -    SDL_free(context->context);
  10.159 -}
  10.160 -
  10.161 -static SDL_bool
  10.162 -HIDAPI_DriverGameCube_UpdateDriver(SDL_HIDAPI_DriverData *context, int *num_joysticks)
  10.163 -{
  10.164 -    SDL_DriverGameCube_Context *ctx = (SDL_DriverGameCube_Context *)context->context;
  10.165 -    SDL_Joystick *joystick;
  10.166 -    Uint8 packet[37];
  10.167 -    Uint8 *curSlot;
  10.168 -    Uint32 now;
  10.169 -    Uint8 i;
  10.170 -    int size;
  10.171 -
  10.172 -    /* Read input packet */
  10.173 -    while ((size = hid_read_timeout(context->device, packet, sizeof(packet), 0)) > 0) {
  10.174 -        if (size < 37 || packet[0] != 0x21) {
  10.175 -            continue; /* Nothing to do right now...? */
  10.176 -        }
  10.177 -
  10.178 -        /* Go through all 4 slots */
  10.179 -        curSlot = packet + 1;
  10.180 -        for (i = 0; i < 4; i += 1, curSlot += 9) {
  10.181 -            ctx->wireless[i] = (curSlot[0] & 0x20) != 0;
  10.182 -
  10.183 -            /* Only allow rumble if the adapter's second USB cable is connected */
  10.184 -            ctx->rumbleAllowed[i] = (curSlot[0] & 0x04) != 0 && !ctx->wireless[i];
  10.185 -
  10.186 -            if (curSlot[0] & 0x30) { /* 0x10 - Wired, 0x20 - Wireless */
  10.187 -                if (ctx->joysticks[i] == -1) {
  10.188 -                    ctx->joysticks[i] = SDL_GetNextJoystickInstanceID();
  10.189 -
  10.190 -                    *num_joysticks += 1;
  10.191 -
  10.192 -                    SDL_PrivateJoystickAdded(ctx->joysticks[i]);
  10.193 -                }
  10.194 -                joystick = SDL_JoystickFromInstanceID(ctx->joysticks[i]);
  10.195 -
  10.196 -                /* Hasn't been opened yet, skip */
  10.197 -                if (joystick == NULL) {
  10.198 -                    continue;
  10.199 -                }
  10.200 -            } else {
  10.201 -                if (ctx->joysticks[i] != -1) {
  10.202 -                    SDL_PrivateJoystickRemoved(ctx->joysticks[i]);
  10.203 -
  10.204 -                    *num_joysticks -= 1;
  10.205 -
  10.206 -                    ctx->joysticks[i] = -1;
  10.207 -                }
  10.208 -                continue;
  10.209 -            }
  10.210 -
  10.211 -            #define READ_BUTTON(off, flag, button) \
  10.212 -                SDL_PrivateJoystickButton( \
  10.213 -                    joystick, \
  10.214 -                    button, \
  10.215 -                    (curSlot[off] & flag) ? SDL_PRESSED : SDL_RELEASED \
  10.216 -                );
  10.217 -            READ_BUTTON(1, 0x01, 0) /* A */
  10.218 -            READ_BUTTON(1, 0x02, 1) /* B */
  10.219 -            READ_BUTTON(1, 0x04, 2) /* X */
  10.220 -            READ_BUTTON(1, 0x08, 3) /* Y */
  10.221 -            READ_BUTTON(1, 0x10, 4) /* DPAD_LEFT */
  10.222 -            READ_BUTTON(1, 0x20, 5) /* DPAD_RIGHT */
  10.223 -            READ_BUTTON(1, 0x40, 6) /* DPAD_DOWN */
  10.224 -            READ_BUTTON(1, 0x80, 7) /* DPAD_UP */
  10.225 -            READ_BUTTON(2, 0x01, 8) /* START */
  10.226 -            READ_BUTTON(2, 0x02, 9) /* RIGHTSHOULDER */
  10.227 -            /* These two buttons are for the bottoms of the analog triggers.
  10.228 -             * More than likely, you're going to want to read the axes instead!
  10.229 -             * -flibit
  10.230 -             */
  10.231 -            READ_BUTTON(2, 0x04, 10) /* TRIGGERRIGHT */
  10.232 -            READ_BUTTON(2, 0x08, 11) /* TRIGGERLEFT */
  10.233 -            #undef READ_BUTTON
  10.234 -
  10.235 -            /* Axis math taken from SDL_xinputjoystick.c */
  10.236 -            #define READ_AXIS(off, axis) \
  10.237 -                SDL_PrivateJoystickAxis( \
  10.238 -                    joystick, \
  10.239 -                    axis, \
  10.240 -                    (Sint16)(((int)curSlot[off] * 257) - 32768) \
  10.241 -                );
  10.242 -            READ_AXIS(3, 0) /* LEFTX */
  10.243 -            READ_AXIS(4, 1) /* LEFTY */
  10.244 -            READ_AXIS(5, 2) /* RIGHTX */
  10.245 -            READ_AXIS(6, 3) /* RIGHTY */
  10.246 -            READ_AXIS(7, 4) /* TRIGGERLEFT */
  10.247 -            READ_AXIS(8, 5) /* TRIGGERRIGHT */
  10.248 -            #undef READ_AXIS
  10.249 -        }
  10.250 -    }
  10.251 -
  10.252 -    /* Write rumble packet */
  10.253 -    now = SDL_GetTicks();
  10.254 -    for (i = 0; i < 4; i += 1) {
  10.255 -        if (ctx->rumbleExpiration[i] > 0) {
  10.256 -            if (SDL_TICKS_PASSED(now, ctx->rumbleExpiration[i]) || !ctx->rumbleAllowed[i]) {
  10.257 -                ctx->rumble[i + 1] = 0;
  10.258 -                ctx->rumbleExpiration[i] = 0;
  10.259 -                ctx->rumbleUpdate = 1;
  10.260 -            }
  10.261 -        }
  10.262 -    }
  10.263 -    if (ctx->rumbleUpdate) {
  10.264 -        hid_write(context->device, ctx->rumble, sizeof(ctx->rumble));
  10.265 -        ctx->rumbleUpdate = 0;
  10.266 -    }
  10.267 -
  10.268 -    /* If we got here, nothing bad happened! */
  10.269 -    return SDL_TRUE;
  10.270 -}
  10.271 -
  10.272 -static int
  10.273 -HIDAPI_DriverGameCube_NumJoysticks(SDL_HIDAPI_DriverData *context)
  10.274 -{
  10.275 -    SDL_DriverGameCube_Context *ctx = (SDL_DriverGameCube_Context *)context->context;
  10.276 -    int i, joysticks = 0;
  10.277 -    for (i = 0; i < 4; i += 1) {
  10.278 -        if (ctx->joysticks[i] != -1) {
  10.279 -            joysticks += 1;
  10.280 -        }
  10.281 -    }
  10.282 -    return joysticks;
  10.283 -}
  10.284 -
  10.285 -static int
  10.286 -HIDAPI_DriverGameCube_PlayerIndexForIndex(SDL_HIDAPI_DriverData *context, int index)
  10.287 -{
  10.288 -    SDL_DriverGameCube_Context *ctx = (SDL_DriverGameCube_Context *)context->context;
  10.289 -    Uint8 i;
  10.290 -    for (i = 0; i < 4; i += 1) {
  10.291 -        if (ctx->joysticks[i] != -1) {
  10.292 -            if (index == 0) {
  10.293 -                return i;
  10.294 -            }
  10.295 -            index -= 1;
  10.296 -        }
  10.297 -    }
  10.298 -    return -1; /* Should never get here! */
  10.299 -}
  10.300 -
  10.301 -static SDL_JoystickID
  10.302 -HIDAPI_DriverGameCube_InstanceIDForIndex(SDL_HIDAPI_DriverData *context, int index)
  10.303 -{
  10.304 -    SDL_DriverGameCube_Context *ctx = (SDL_DriverGameCube_Context *)context->context;
  10.305 -    Uint8 i;
  10.306 -    for (i = 0; i < 4; i += 1) {
  10.307 -        if (ctx->joysticks[i] != -1) {
  10.308 -            if (index == 0) {
  10.309 -                return ctx->joysticks[i];
  10.310 -            }
  10.311 -            index -= 1;
  10.312 -        }
  10.313 -    }
  10.314 -    return -1; /* Should never get here! */
  10.315 -}
  10.316 -
  10.317 -static SDL_bool
  10.318 -HIDAPI_DriverGameCube_OpenJoystick(SDL_HIDAPI_DriverData *context, SDL_Joystick *joystick)
  10.319 -{
  10.320 -    SDL_DriverGameCube_Context *ctx = (SDL_DriverGameCube_Context *)context->context;
  10.321 -    SDL_JoystickID instance = SDL_JoystickInstanceID(joystick);
  10.322 -    Uint8 i;
  10.323 -    for (i = 0; i < 4; i += 1) {
  10.324 -        if (instance == ctx->joysticks[i]) {
  10.325 -            joystick->nbuttons = 12;
  10.326 -            joystick->naxes = 6;
  10.327 -            joystick->epowerlevel = ctx->wireless[i] ? SDL_JOYSTICK_POWER_UNKNOWN : SDL_JOYSTICK_POWER_WIRED;
  10.328 -            joystick->player_index = i;
  10.329 -            return SDL_TRUE;
  10.330 -        }
  10.331 -    }
  10.332 -    return SDL_FALSE; /* Should never get here! */
  10.333 -}
  10.334 -
  10.335 -static int
  10.336 -HIDAPI_DriverGameCube_Rumble(SDL_HIDAPI_DriverData *context, SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble, Uint32 duration_ms)
  10.337 -{
  10.338 -    SDL_DriverGameCube_Context *ctx = (SDL_DriverGameCube_Context *)context->context;
  10.339 -    SDL_JoystickID instance = SDL_JoystickInstanceID(joystick);
  10.340 -    Uint8 i, val;
  10.341 -    for (i = 0; i < 4; i += 1) {
  10.342 -        if (instance == ctx->joysticks[i]) {
  10.343 -            if (ctx->wireless[i]) {
  10.344 -                return SDL_SetError("Ninteno GameCube WaveBird controllers do not support rumble");
  10.345 -            }
  10.346 -            if (!ctx->rumbleAllowed[i]) {
  10.347 -                return SDL_SetError("Second USB cable for WUP-028 not connected");
  10.348 -            }
  10.349 -            val = (low_frequency_rumble > 0 || high_frequency_rumble > 0);
  10.350 -            if (val != ctx->rumble[i + 1]) {
  10.351 -                ctx->rumble[i + 1] = val;
  10.352 -                ctx->rumbleUpdate = 1;
  10.353 -            }
  10.354 -            if (val && duration_ms < SDL_HAPTIC_INFINITY) {
  10.355 -                ctx->rumbleExpiration[i] = SDL_GetTicks() + duration_ms;
  10.356 -            } else {
  10.357 -                ctx->rumbleExpiration[i] = 0;
  10.358 -            }
  10.359 -            return 0;
  10.360 -        }
  10.361 -    }
  10.362 -    return -1; /* Should never get here! */
  10.363 -}
  10.364 -
  10.365 -SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverGameCube =
  10.366 -{
  10.367 -    SDL_HINT_JOYSTICK_HIDAPI_GAMECUBE,
  10.368 -    SDL_TRUE,
  10.369 -    HIDAPI_DriverGameCube_IsSupportedDevice,
  10.370 -    HIDAPI_DriverGameCube_GetDeviceName,
  10.371 -    HIDAPI_DriverGameCube_InitDriver,
  10.372 -    HIDAPI_DriverGameCube_QuitDriver,
  10.373 -    HIDAPI_DriverGameCube_UpdateDriver,
  10.374 -    HIDAPI_DriverGameCube_NumJoysticks,
  10.375 -    HIDAPI_DriverGameCube_PlayerIndexForIndex,
  10.376 -    HIDAPI_DriverGameCube_InstanceIDForIndex,
  10.377 -    HIDAPI_DriverGameCube_OpenJoystick,
  10.378 -    HIDAPI_DriverGameCube_Rumble
  10.379 -};
  10.380 -
  10.381 -#endif /* SDL_JOYSTICK_HIDAPI_GAMECUBE */
  10.382 -
  10.383 -#endif /* SDL_JOYSTICK_HIDAPI */
    11.1 --- a/src/joystick/hidapi/SDL_hidapi_ps4.c	Wed Jun 19 06:43:54 2019 -0700
    11.2 +++ b/src/joystick/hidapi/SDL_hidapi_ps4.c	Wed Jun 19 15:54:21 2019 -0700
    11.3 @@ -108,7 +108,6 @@
    11.4  } DS4EffectsState_t;
    11.5  
    11.6  typedef struct {
    11.7 -    SDL_JoystickID joystickID;
    11.8      SDL_bool is_dongle;
    11.9      SDL_bool is_bluetooth;
   11.10      SDL_bool audio_supported;
   11.11 @@ -273,8 +272,10 @@
   11.12      return SDL_TRUE;
   11.13  }
   11.14  
   11.15 +static int HIDAPI_DriverPS4_Rumble(SDL_Joystick *joystick, hid_device *dev, void *context, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble, Uint32 duration_ms);
   11.16 +
   11.17  static SDL_bool
   11.18 -HIDAPI_DriverPS4_InitDriver(SDL_HIDAPI_DriverData *context, Uint16 vendor_id, Uint16 product_id, int *num_joysticks)
   11.19 +HIDAPI_DriverPS4_Init(SDL_Joystick *joystick, hid_device *dev, Uint16 vendor_id, Uint16 product_id, void **context)
   11.20  {
   11.21      SDL_DriverPS4_Context *ctx;
   11.22  
   11.23 @@ -283,14 +284,14 @@
   11.24          SDL_OutOfMemory();
   11.25          return SDL_FALSE;
   11.26      }
   11.27 -    context->context = ctx;
   11.28 +    *context = ctx;
   11.29  
   11.30      /* Check for type of connection */
   11.31      ctx->is_dongle = (vendor_id == SONY_USB_VID && product_id == SONY_DS4_DONGLE_PID);
   11.32      if (ctx->is_dongle) {
   11.33          ctx->is_bluetooth = SDL_FALSE;
   11.34      } else if (vendor_id == SONY_USB_VID) {
   11.35 -        ctx->is_bluetooth = !CheckUSBConnected(context->device);
   11.36 +        ctx->is_bluetooth = !CheckUSBConnected(dev);
   11.37      } else {
   11.38          /* Third party controllers appear to all be wired */
   11.39          ctx->is_bluetooth = SDL_FALSE;
   11.40 @@ -313,51 +314,8 @@
   11.41          }
   11.42      }
   11.43  
   11.44 -    ctx->joystickID = SDL_GetNextJoystickInstanceID();
   11.45 -    *num_joysticks += 1;
   11.46 -    SDL_PrivateJoystickAdded(ctx->joystickID);
   11.47 -
   11.48 -    return SDL_TRUE;
   11.49 -}
   11.50 -
   11.51 -static void
   11.52 -HIDAPI_DriverPS4_QuitDriver(SDL_HIDAPI_DriverData *context, SDL_bool send_event, int *num_joysticks)
   11.53 -{
   11.54 -    SDL_DriverPS4_Context *ctx = (SDL_DriverPS4_Context *)context->context;
   11.55 -
   11.56 -    *num_joysticks -= 1;
   11.57 -    if (send_event) {
   11.58 -        SDL_PrivateJoystickRemoved(ctx->joystickID);
   11.59 -    }
   11.60 -    SDL_free(context->context);
   11.61 -}
   11.62 -
   11.63 -static int
   11.64 -HIDAPI_DriverPS4_NumJoysticks(SDL_HIDAPI_DriverData *context)
   11.65 -{
   11.66 -    return 1;
   11.67 -}
   11.68 -
   11.69 -static int
   11.70 -HIDAPI_DriverPS4_PlayerIndexForIndex(SDL_HIDAPI_DriverData *context, int index)
   11.71 -{
   11.72 -    return -1;
   11.73 -}
   11.74 -
   11.75 -static SDL_JoystickID
   11.76 -HIDAPI_DriverPS4_InstanceIDForIndex(SDL_HIDAPI_DriverData *context, int index)
   11.77 -{
   11.78 -    SDL_DriverPS4_Context *ctx = (SDL_DriverPS4_Context *)context->context;
   11.79 -    return ctx->joystickID;
   11.80 -}
   11.81 -
   11.82 -static int HIDAPI_DriverPS4_Rumble(SDL_HIDAPI_DriverData *context, SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble, Uint32 duration_ms);
   11.83 -
   11.84 -static SDL_bool
   11.85 -HIDAPI_DriverPS4_OpenJoystick(SDL_HIDAPI_DriverData *context, SDL_Joystick *joystick)
   11.86 -{
   11.87      /* Initialize LED and effect state */
   11.88 -    HIDAPI_DriverPS4_Rumble(context, joystick, 0, 0, 0);
   11.89 +    HIDAPI_DriverPS4_Rumble(joystick, dev, ctx, 0, 0, 0);
   11.90  
   11.91      /* Initialize the joystick capabilities */
   11.92      joystick->nbuttons = 16;
   11.93 @@ -368,9 +326,9 @@
   11.94  }
   11.95  
   11.96  static int
   11.97 -HIDAPI_DriverPS4_Rumble(SDL_HIDAPI_DriverData *context, SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble, Uint32 duration_ms)
   11.98 +HIDAPI_DriverPS4_Rumble(SDL_Joystick *joystick, hid_device *dev, void *context, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble, Uint32 duration_ms)
   11.99  {
  11.100 -    SDL_DriverPS4_Context *ctx = (SDL_DriverPS4_Context *)context->context;
  11.101 +    SDL_DriverPS4_Context *ctx = (SDL_DriverPS4_Context *)context;
  11.102      DS4EffectsState_t *effects;
  11.103      Uint8 data[78];
  11.104      int report_size, offset;
  11.105 @@ -428,7 +386,7 @@
  11.106          SDL_memcpy(&data[report_size - sizeof(unCRC)], &unCRC, sizeof(unCRC));
  11.107      }
  11.108  
  11.109 -    if (hid_write(context->device, data, report_size) != report_size) {
  11.110 +    if (hid_write(dev, data, report_size) != report_size) {
  11.111          return SDL_SetError("Couldn't send rumble packet");
  11.112      }
  11.113  
  11.114 @@ -551,25 +509,20 @@
  11.115  }
  11.116  
  11.117  static SDL_bool
  11.118 -HIDAPI_DriverPS4_UpdateDriver(SDL_HIDAPI_DriverData *context, int *num_joysticks)
  11.119 +HIDAPI_DriverPS4_Update(SDL_Joystick *joystick, hid_device *dev, void *context)
  11.120  {
  11.121 -    SDL_DriverPS4_Context *ctx = (SDL_DriverPS4_Context *)context->context;
  11.122 -    SDL_Joystick *joystick = SDL_JoystickFromInstanceID(ctx->joystickID);
  11.123 +    SDL_DriverPS4_Context *ctx = (SDL_DriverPS4_Context *)context;
  11.124      Uint8 data[USB_PACKET_LENGTH];
  11.125      int size;
  11.126  
  11.127 -    if (joystick == NULL) {
  11.128 -        return SDL_TRUE; /* Nothing to do right now! */
  11.129 -    }
  11.130 -
  11.131 -    while ((size = hid_read_timeout(context->device, data, sizeof(data), 0)) > 0) {
  11.132 +    while ((size = hid_read_timeout(dev, data, sizeof(data), 0)) > 0) {
  11.133          switch (data[0]) {
  11.134          case k_EPS4ReportIdUsbState:
  11.135 -            HIDAPI_DriverPS4_HandleStatePacket(joystick, context->device, ctx, (PS4StatePacket_t *)&data[1]);
  11.136 +            HIDAPI_DriverPS4_HandleStatePacket(joystick, dev, ctx, (PS4StatePacket_t *)&data[1]);
  11.137              break;
  11.138          case k_EPS4ReportIdBluetoothState:
  11.139              /* Bluetooth state packets have two additional bytes at the beginning */
  11.140 -            HIDAPI_DriverPS4_HandleStatePacket(joystick, context->device, ctx, (PS4StatePacket_t *)&data[3]);
  11.141 +            HIDAPI_DriverPS4_HandleStatePacket(joystick, dev, ctx, (PS4StatePacket_t *)&data[3]);
  11.142              break;
  11.143          default:
  11.144  #ifdef DEBUG_JOYSTICK
  11.145 @@ -582,27 +535,29 @@
  11.146      if (ctx->rumble_expiration) {
  11.147          Uint32 now = SDL_GetTicks();
  11.148          if (SDL_TICKS_PASSED(now, ctx->rumble_expiration)) {
  11.149 -            HIDAPI_DriverPS4_Rumble(context, joystick, 0, 0, 0);
  11.150 +            HIDAPI_DriverPS4_Rumble(joystick, dev, context, 0, 0, 0);
  11.151          }
  11.152      }
  11.153  
  11.154      return (size >= 0);
  11.155  }
  11.156  
  11.157 +static void
  11.158 +HIDAPI_DriverPS4_Quit(SDL_Joystick *joystick, hid_device *dev, void *context)
  11.159 +{
  11.160 +    SDL_free(context);
  11.161 +}
  11.162 +
  11.163  SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverPS4 =
  11.164  {
  11.165      SDL_HINT_JOYSTICK_HIDAPI_PS4,
  11.166      SDL_TRUE,
  11.167      HIDAPI_DriverPS4_IsSupportedDevice,
  11.168      HIDAPI_DriverPS4_GetDeviceName,
  11.169 -    HIDAPI_DriverPS4_InitDriver,
  11.170 -    HIDAPI_DriverPS4_QuitDriver,
  11.171 -    HIDAPI_DriverPS4_UpdateDriver,
  11.172 -    HIDAPI_DriverPS4_NumJoysticks,
  11.173 -    HIDAPI_DriverPS4_PlayerIndexForIndex,
  11.174 -    HIDAPI_DriverPS4_InstanceIDForIndex,
  11.175 -    HIDAPI_DriverPS4_OpenJoystick,
  11.176 -    HIDAPI_DriverPS4_Rumble
  11.177 +    HIDAPI_DriverPS4_Init,
  11.178 +    HIDAPI_DriverPS4_Rumble,
  11.179 +    HIDAPI_DriverPS4_Update,
  11.180 +    HIDAPI_DriverPS4_Quit
  11.181  };
  11.182  
  11.183  #endif /* SDL_JOYSTICK_HIDAPI_PS4 */
    12.1 --- a/src/joystick/hidapi/SDL_hidapi_switch.c	Wed Jun 19 06:43:54 2019 -0700
    12.2 +++ b/src/joystick/hidapi/SDL_hidapi_switch.c	Wed Jun 19 15:54:21 2019 -0700
    12.3 @@ -183,7 +183,6 @@
    12.4  #pragma pack()
    12.5  
    12.6  typedef struct {
    12.7 -    SDL_JoystickID joystickID;
    12.8      hid_device *dev;
    12.9      SDL_bool m_bIsUsingBluetooth;
   12.10      Uint8 m_nCommandNumber;
   12.11 @@ -571,7 +570,7 @@
   12.12  }
   12.13  
   12.14  static SDL_bool
   12.15 -HIDAPI_DriverSwitch_InitDriver(SDL_HIDAPI_DriverData *context, Uint16 vendor_id, Uint16 product_id, int *num_joysticks)
   12.16 +HIDAPI_DriverSwitch_Init(SDL_Joystick *joystick, hid_device *dev, Uint16 vendor_id, Uint16 product_id, void **context)
   12.17  {
   12.18      SDL_DriverSwitch_Context *ctx;
   12.19      Uint8 input_mode;
   12.20 @@ -581,9 +580,9 @@
   12.21          SDL_OutOfMemory();
   12.22          return SDL_FALSE;
   12.23      }
   12.24 -    ctx->dev = context->device;
   12.25 +    ctx->dev = dev;
   12.26  
   12.27 -    context->context = ctx;
   12.28 +    *context = ctx;
   12.29  
   12.30      /* Initialize rumble data */
   12.31      SetNeutralRumble(&ctx->m_RumblePacket.rumbleData[0]);
   12.32 @@ -628,18 +627,6 @@
   12.33          }
   12.34      }
   12.35  
   12.36 -    ctx->joystickID = SDL_GetNextJoystickInstanceID();
   12.37 -    *num_joysticks += 1;
   12.38 -    SDL_PrivateJoystickAdded(ctx->joystickID);
   12.39 -
   12.40 -    return SDL_TRUE;
   12.41 -}
   12.42 -
   12.43 -static SDL_bool
   12.44 -HIDAPI_DriverSwitch_OpenJoystick(SDL_HIDAPI_DriverData *context, SDL_Joystick *joystick)
   12.45 -{
   12.46 -    SDL_DriverSwitch_Context *ctx = (SDL_DriverSwitch_Context *)context->context;
   12.47 -
   12.48      /* Set the LED state */
   12.49      SetHomeLED(ctx, 100);
   12.50      SetSlotLED(ctx, (joystick->instance_id % 4));
   12.51 @@ -653,9 +640,9 @@
   12.52  }
   12.53  
   12.54  static int
   12.55 -HIDAPI_DriverSwitch_Rumble(SDL_HIDAPI_DriverData *context, SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble, Uint32 duration_ms)
   12.56 +HIDAPI_DriverSwitch_Rumble(SDL_Joystick *joystick, hid_device *dev, void *context, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble, Uint32 duration_ms)
   12.57  {
   12.58 -    SDL_DriverSwitch_Context *ctx = (SDL_DriverSwitch_Context *)context->context;
   12.59 +    SDL_DriverSwitch_Context *ctx = (SDL_DriverSwitch_Context *)context;
   12.60  
   12.61      /* Experimentally determined rumble values. These will only matter on some controllers as tested ones
   12.62       * seem to disregard these and just use any non-zero rumble values as a binary flag for constant rumble
   12.63 @@ -860,16 +847,11 @@
   12.64  }
   12.65  
   12.66  static SDL_bool
   12.67 -HIDAPI_DriverSwitch_UpdateDriver(SDL_HIDAPI_DriverData *context, int *num_joysticks)
   12.68 +HIDAPI_DriverSwitch_Update(SDL_Joystick *joystick, hid_device *dev, void *context)
   12.69  {
   12.70 -    SDL_DriverSwitch_Context *ctx = (SDL_DriverSwitch_Context *)context->context;
   12.71 -    SDL_Joystick *joystick = SDL_JoystickFromInstanceID(ctx->joystickID);
   12.72 +    SDL_DriverSwitch_Context *ctx = (SDL_DriverSwitch_Context *)context;
   12.73      int size;
   12.74  
   12.75 -    if (joystick == NULL) {
   12.76 -        return SDL_TRUE; /* Nothing to do right now! */
   12.77 -    }
   12.78 -
   12.79      while ((size = ReadInput(ctx)) > 0) {
   12.80          switch (ctx->m_rgucReadBuffer[0]) {
   12.81          case k_eSwitchInputReportIDs_SimpleControllerState:
   12.82 @@ -886,7 +868,7 @@
   12.83      if (ctx->m_nRumbleExpiration) {
   12.84          Uint32 now = SDL_GetTicks();
   12.85          if (SDL_TICKS_PASSED(now, ctx->m_nRumbleExpiration)) {
   12.86 -            HIDAPI_DriverSwitch_Rumble(context, joystick, 0, 0, 0);
   12.87 +            HIDAPI_DriverSwitch_Rumble(joystick, dev, context, 0, 0, 0);
   12.88          }
   12.89      }
   12.90  
   12.91 @@ -894,37 +876,14 @@
   12.92  }
   12.93  
   12.94  static void
   12.95 -HIDAPI_DriverSwitch_QuitDriver(SDL_HIDAPI_DriverData *context, SDL_bool send_event, int *num_joysticks)
   12.96 +HIDAPI_DriverSwitch_Quit(SDL_Joystick *joystick, hid_device *dev, void *context)
   12.97  {
   12.98 -    SDL_DriverSwitch_Context *ctx = (SDL_DriverSwitch_Context *)context->context;
   12.99 +    SDL_DriverSwitch_Context *ctx = (SDL_DriverSwitch_Context *)context;
  12.100  
  12.101      /* Restore simple input mode for other applications */
  12.102      SetInputMode(ctx, k_eSwitchInputReportIDs_SimpleControllerState);
  12.103  
  12.104 -    *num_joysticks -= 1;
  12.105 -    if (send_event) {
  12.106 -        SDL_PrivateJoystickRemoved(ctx->joystickID);
  12.107 -    }
  12.108 -    SDL_free(context->context);
  12.109 -}
  12.110 -
  12.111 -static int
  12.112 -HIDAPI_DriverSwitch_NumJoysticks(SDL_HIDAPI_DriverData *context)
  12.113 -{
  12.114 -    return 1;
  12.115 -}
  12.116 -
  12.117 -static int
  12.118 -HIDAPI_DriverSwitch_PlayerIndexForIndex(SDL_HIDAPI_DriverData *context, int index)
  12.119 -{
  12.120 -    return -1;
  12.121 -}
  12.122 -
  12.123 -static SDL_JoystickID
  12.124 -HIDAPI_DriverSwitch_InstanceIDForIndex(SDL_HIDAPI_DriverData *context, int index)
  12.125 -{
  12.126 -    SDL_DriverSwitch_Context *ctx = (SDL_DriverSwitch_Context *)context->context;
  12.127 -    return ctx->joystickID;
  12.128 +    SDL_free(context);
  12.129  }
  12.130  
  12.131  SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverSwitch =
  12.132 @@ -933,14 +892,10 @@
  12.133      SDL_TRUE,
  12.134      HIDAPI_DriverSwitch_IsSupportedDevice,
  12.135      HIDAPI_DriverSwitch_GetDeviceName,
  12.136 -    HIDAPI_DriverSwitch_InitDriver,
  12.137 -    HIDAPI_DriverSwitch_QuitDriver,
  12.138 -    HIDAPI_DriverSwitch_UpdateDriver,
  12.139 -    HIDAPI_DriverSwitch_NumJoysticks,
  12.140 -    HIDAPI_DriverSwitch_PlayerIndexForIndex,
  12.141 -    HIDAPI_DriverSwitch_InstanceIDForIndex,
  12.142 -    HIDAPI_DriverSwitch_OpenJoystick,
  12.143 -    HIDAPI_DriverSwitch_Rumble
  12.144 +    HIDAPI_DriverSwitch_Init,
  12.145 +    HIDAPI_DriverSwitch_Rumble,
  12.146 +    HIDAPI_DriverSwitch_Update,
  12.147 +    HIDAPI_DriverSwitch_Quit
  12.148  };
  12.149  
  12.150  #endif /* SDL_JOYSTICK_HIDAPI_SWITCH */
    13.1 --- a/src/joystick/hidapi/SDL_hidapi_xbox360.c	Wed Jun 19 06:43:54 2019 -0700
    13.2 +++ b/src/joystick/hidapi/SDL_hidapi_xbox360.c	Wed Jun 19 15:54:21 2019 -0700
    13.3 @@ -54,7 +54,6 @@
    13.4  
    13.5  
    13.6  typedef struct {
    13.7 -    SDL_JoystickID joystickID;
    13.8      Uint8 last_state[USB_PACKET_LENGTH];
    13.9      Uint32 rumble_expiration;
   13.10  #ifdef SDL_JOYSTICK_HIDAPI_WINDOWS_XINPUT
   13.11 @@ -282,7 +281,7 @@
   13.12  }
   13.13  
   13.14  static SDL_bool
   13.15 -HIDAPI_DriverXbox360_InitDriver(SDL_HIDAPI_DriverData *context, Uint16 vendor_id, Uint16 product_id, int *num_joysticks)
   13.16 +HIDAPI_DriverXbox360_Init(SDL_Joystick *joystick, hid_device *dev, Uint16 vendor_id, Uint16 product_id, void **context)
   13.17  {
   13.18      SDL_DriverXbox360_Context *ctx;
   13.19  
   13.20 @@ -301,20 +300,10 @@
   13.21  #ifdef SDL_JOYSTICK_HIDAPI_WINDOWS_GAMING_INPUT
   13.22      HIDAPI_DriverXbox360_InitWindowsGamingInput(ctx);
   13.23  #endif
   13.24 -    context->context = ctx;
   13.25 +    *context = ctx;
   13.26  
   13.27 -    ctx->joystickID = SDL_GetNextJoystickInstanceID();
   13.28 -    *num_joysticks += 1;
   13.29 -    SDL_PrivateJoystickAdded(ctx->joystickID);
   13.30 -
   13.31 -    return SDL_TRUE;
   13.32 -}
   13.33 -
   13.34 -static SDL_bool
   13.35 -HIDAPI_DriverXbox360_OpenJoystick(SDL_HIDAPI_DriverData *context, SDL_Joystick *joystick)
   13.36 -{
   13.37      /* Set the controller LED */
   13.38 -    SetSlotLED(context->device, (joystick->instance_id % 4));
   13.39 +    SetSlotLED(dev, (joystick->instance_id % 4));
   13.40  
   13.41      /* Initialize the joystick capabilities */
   13.42      joystick->nbuttons = SDL_CONTROLLER_BUTTON_MAX;
   13.43 @@ -325,28 +314,9 @@
   13.44  }
   13.45  
   13.46  static int
   13.47 -HIDAPI_DriverXbox360_NumJoysticks(SDL_HIDAPI_DriverData *context)
   13.48 +HIDAPI_DriverXbox360_Rumble(SDL_Joystick *joystick, hid_device *dev, void *context, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble, Uint32 duration_ms)
   13.49  {
   13.50 -    return 1;
   13.51 -}
   13.52 -
   13.53 -static int
   13.54 -HIDAPI_DriverXbox360_PlayerIndexForIndex(SDL_HIDAPI_DriverData *context, int index)
   13.55 -{
   13.56 -    return -1;
   13.57 -}
   13.58 -
   13.59 -static SDL_JoystickID
   13.60 -HIDAPI_DriverXbox360_InstanceIDForIndex(SDL_HIDAPI_DriverData *context, int index)
   13.61 -{
   13.62 -    SDL_DriverXbox360_Context *ctx = (SDL_DriverXbox360_Context *)context->context;
   13.63 -    return ctx->joystickID;
   13.64 -}
   13.65 -
   13.66 -static int
   13.67 -HIDAPI_DriverXbox360_Rumble(SDL_HIDAPI_DriverData *context, SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble, Uint32 duration_ms)
   13.68 -{
   13.69 -    SDL_DriverXbox360_Context *ctx = (SDL_DriverXbox360_Context *)context->context;
   13.70 +    SDL_DriverXbox360_Context *ctx = (SDL_DriverXbox360_Context *)context;
   13.71  
   13.72  #ifdef __WIN32__
   13.73      SDL_bool rumbled = SDL_FALSE;
   13.74 @@ -399,7 +369,7 @@
   13.75      rumble_packet[4] = (high_frequency_rumble >> 8);
   13.76  #endif
   13.77  
   13.78 -    if (hid_write(context->device, rumble_packet, sizeof(rumble_packet)) != sizeof(rumble_packet)) {
   13.79 +    if (hid_write(dev, rumble_packet, sizeof(rumble_packet)) != sizeof(rumble_packet)) {
   13.80          return SDL_SetError("Couldn't send rumble packet");
   13.81      }
   13.82  #endif /* __WIN32__ */
   13.83 @@ -739,31 +709,26 @@
   13.84  #endif /* __MACOSX__ */
   13.85  
   13.86  static SDL_bool
   13.87 -HIDAPI_DriverXbox360_UpdateDriver(SDL_HIDAPI_DriverData *context, int *num_joysticks)
   13.88 +HIDAPI_DriverXbox360_Update(SDL_Joystick *joystick, hid_device *dev, void *context)
   13.89  {
   13.90 -    SDL_DriverXbox360_Context *ctx = (SDL_DriverXbox360_Context *)context->context;
   13.91 -    SDL_Joystick *joystick = SDL_JoystickFromInstanceID(ctx->joystickID);
   13.92 +    SDL_DriverXbox360_Context *ctx = (SDL_DriverXbox360_Context *)context;
   13.93      Uint8 data[USB_PACKET_LENGTH];
   13.94      int size;
   13.95  
   13.96 -    if (joystick == NULL) {
   13.97 -        return SDL_TRUE; /* Nothing to do right now! */
   13.98 -    }
   13.99 -
  13.100 -    while ((size = hid_read_timeout(context->device, data, sizeof(data), 0)) > 0) {
  13.101 +    while ((size = hid_read_timeout(dev, data, sizeof(data), 0)) > 0) {
  13.102  #ifdef __WIN32__
  13.103 -        HIDAPI_DriverXbox360_HandleStatePacket(joystick, context->device, ctx, data, size);
  13.104 +        HIDAPI_DriverXbox360_HandleStatePacket(joystick, dev, ctx, data, size);
  13.105  #else
  13.106          switch (data[0]) {
  13.107          case 0x00:
  13.108 -            HIDAPI_DriverXbox360_HandleStatePacket(joystick, context->device, ctx, data, size);
  13.109 +            HIDAPI_DriverXbox360_HandleStatePacket(joystick, dev, ctx, data, size);
  13.110              break;
  13.111  #ifdef __MACOSX__
  13.112          case 0x01:
  13.113 -            HIDAPI_DriverXboxOneS_HandleStatePacket(joystick, context->device, ctx, data, size);
  13.114 +            HIDAPI_DriverXboxOneS_HandleStatePacket(joystick, dev, ctx, data, size);
  13.115              break;
  13.116          case 0x02:
  13.117 -            HIDAPI_DriverXboxOneS_HandleGuidePacket(joystick, context->device, ctx, data, size);
  13.118 +            HIDAPI_DriverXboxOneS_HandleGuidePacket(joystick, dev, ctx, data, size);
  13.119              break;
  13.120  #endif
  13.121          default:
  13.122 @@ -781,7 +746,7 @@
  13.123      if (ctx->rumble_expiration) {
  13.124          Uint32 now = SDL_GetTicks();
  13.125          if (SDL_TICKS_PASSED(now, ctx->rumble_expiration)) {
  13.126 -            HIDAPI_DriverXbox360_Rumble(context, joystick, 0, 0, 0);
  13.127 +            HIDAPI_DriverXbox360_Rumble(joystick, dev, context, 0, 0, 0);
  13.128          }
  13.129      }
  13.130  
  13.131 @@ -789,9 +754,11 @@
  13.132  }
  13.133  
  13.134  static void
  13.135 -HIDAPI_DriverXbox360_QuitDriver(SDL_HIDAPI_DriverData *context, SDL_bool send_event, int *num_joysticks)
  13.136 +HIDAPI_DriverXbox360_Quit(SDL_Joystick *joystick, hid_device *dev, void *context)
  13.137  {
  13.138 -    SDL_DriverXbox360_Context *ctx = (SDL_DriverXbox360_Context *)context->context;
  13.139 +#if defined(SDL_JOYSTICK_HIDAPI_WINDOWS_XINPUT) || defined(SDL_JOYSTICK_HIDAPI_WINDOWS_GAMING_INPUT)
  13.140 +    SDL_DriverXbox360_Context *ctx = (SDL_DriverXbox360_Context *)context;
  13.141 +#endif
  13.142  
  13.143  #ifdef SDL_JOYSTICK_HIDAPI_WINDOWS_XINPUT
  13.144      if (ctx->xinput_enabled) {
  13.145 @@ -802,11 +769,7 @@
  13.146  #ifdef SDL_JOYSTICK_HIDAPI_WINDOWS_GAMING_INPUT
  13.147      HIDAPI_DriverXbox360_InitWindowsGamingInput(ctx);
  13.148  #endif
  13.149 -    *num_joysticks -= 1;
  13.150 -    if (send_event) {
  13.151 -        SDL_PrivateJoystickRemoved(ctx->joystickID);
  13.152 -    }
  13.153 -    SDL_free(context->context);
  13.154 +    SDL_free(context);
  13.155  }
  13.156  
  13.157  SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverXbox360 =
  13.158 @@ -815,14 +778,10 @@
  13.159      SDL_TRUE,
  13.160      HIDAPI_DriverXbox360_IsSupportedDevice,
  13.161      HIDAPI_DriverXbox360_GetDeviceName,
  13.162 -    HIDAPI_DriverXbox360_InitDriver,
  13.163 -    HIDAPI_DriverXbox360_QuitDriver,
  13.164 -    HIDAPI_DriverXbox360_UpdateDriver,
  13.165 -    HIDAPI_DriverXbox360_NumJoysticks,
  13.166 -    HIDAPI_DriverXbox360_PlayerIndexForIndex,
  13.167 -    HIDAPI_DriverXbox360_InstanceIDForIndex,
  13.168 -    HIDAPI_DriverXbox360_OpenJoystick,
  13.169 -    HIDAPI_DriverXbox360_Rumble
  13.170 +    HIDAPI_DriverXbox360_Init,
  13.171 +    HIDAPI_DriverXbox360_Rumble,
  13.172 +    HIDAPI_DriverXbox360_Update,
  13.173 +    HIDAPI_DriverXbox360_Quit
  13.174  };
  13.175  
  13.176  #endif /* SDL_JOYSTICK_HIDAPI_XBOX360 */
    14.1 --- a/src/joystick/hidapi/SDL_hidapi_xboxone.c	Wed Jun 19 06:43:54 2019 -0700
    14.2 +++ b/src/joystick/hidapi/SDL_hidapi_xboxone.c	Wed Jun 19 15:54:21 2019 -0700
    14.3 @@ -124,7 +124,6 @@
    14.4  };
    14.5  
    14.6  typedef struct {
    14.7 -    SDL_JoystickID joystickID;
    14.8      Uint8 sequence;
    14.9      Uint8 last_state[USB_PACKET_LENGTH];
   14.10      Uint32 rumble_expiration;
   14.11 @@ -144,7 +143,7 @@
   14.12  }
   14.13  
   14.14  static SDL_bool
   14.15 -HIDAPI_DriverXboxOne_InitDriver(SDL_HIDAPI_DriverData *context, Uint16 vendor_id, Uint16 product_id, int *num_joysticks)
   14.16 +HIDAPI_DriverXboxOne_Init(SDL_Joystick *joystick, hid_device *dev, Uint16 vendor_id, Uint16 product_id, void **context)
   14.17  {
   14.18      SDL_DriverXboxOne_Context *ctx;
   14.19      int i;
   14.20 @@ -155,7 +154,7 @@
   14.21          SDL_OutOfMemory();
   14.22          return SDL_FALSE;
   14.23      }
   14.24 -    context->context = ctx;
   14.25 +    *context = ctx;
   14.26  
   14.27      /* Send the controller init data */
   14.28      for (i = 0; i < SDL_arraysize(xboxone_init_packets); ++i) {
   14.29 @@ -163,7 +162,7 @@
   14.30          if (!packet->vendor_id || (vendor_id == packet->vendor_id && product_id == packet->product_id)) {
   14.31              SDL_memcpy(init_packet, packet->data, packet->size);
   14.32              init_packet[2] = ctx->sequence++;
   14.33 -            if (hid_write(context->device, init_packet, packet->size) != packet->size) {
   14.34 +            if (hid_write(dev, init_packet, packet->size) != packet->size) {
   14.35                  SDL_SetError("Couldn't write Xbox One initialization packet");
   14.36                  SDL_free(ctx);
   14.37                  return SDL_FALSE;
   14.38 @@ -171,16 +170,6 @@
   14.39          }
   14.40      }
   14.41  
   14.42 -    ctx->joystickID = SDL_GetNextJoystickInstanceID();
   14.43 -    *num_joysticks += 1;
   14.44 -    SDL_PrivateJoystickAdded(ctx->joystickID);
   14.45 -
   14.46 -    return SDL_TRUE;
   14.47 -}
   14.48 -
   14.49 -static SDL_bool
   14.50 -HIDAPI_DriverXboxOne_OpenJoystick(SDL_HIDAPI_DriverData *context, SDL_Joystick *joystick)
   14.51 -{
   14.52      /* Initialize the joystick capabilities */
   14.53      joystick->nbuttons = SDL_CONTROLLER_BUTTON_MAX;
   14.54      joystick->naxes = SDL_CONTROLLER_AXIS_MAX;
   14.55 @@ -189,41 +178,10 @@
   14.56      return SDL_TRUE;
   14.57  }
   14.58  
   14.59 -static void
   14.60 -HIDAPI_DriverXboxOne_QuitDriver(SDL_HIDAPI_DriverData *context, SDL_bool send_event, int *num_joysticks)
   14.61 +static int
   14.62 +HIDAPI_DriverXboxOne_Rumble(SDL_Joystick *joystick, hid_device *dev, void *context, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble, Uint32 duration_ms)
   14.63  {
   14.64 -    SDL_DriverXboxOne_Context *ctx = (SDL_DriverXboxOne_Context *)context->context;
   14.65 -
   14.66 -    *num_joysticks -= 1;
   14.67 -    if (send_event) {
   14.68 -        SDL_PrivateJoystickRemoved(ctx->joystickID);
   14.69 -    }
   14.70 -    SDL_free(context->context);
   14.71 -}
   14.72 -
   14.73 -static int
   14.74 -HIDAPI_DriverXboxOne_NumJoysticks(SDL_HIDAPI_DriverData *context)
   14.75 -{
   14.76 -    return 1;
   14.77 -}
   14.78 -
   14.79 -static int
   14.80 -HIDAPI_DriverXboxOne_PlayerIndexForIndex(SDL_HIDAPI_DriverData *context, int index)
   14.81 -{
   14.82 -    return -1;
   14.83 -}
   14.84 -
   14.85 -static SDL_JoystickID
   14.86 -HIDAPI_DriverXboxOne_InstanceIDForIndex(SDL_HIDAPI_DriverData *context, int index)
   14.87 -{
   14.88 -    SDL_DriverXboxOne_Context *ctx = (SDL_DriverXboxOne_Context *)context->context;
   14.89 -    return ctx->joystickID;
   14.90 -}
   14.91 -
   14.92 -static int
   14.93 -HIDAPI_DriverXboxOne_Rumble(SDL_HIDAPI_DriverData *context, SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble, Uint32 duration_ms)
   14.94 -{
   14.95 -    SDL_DriverXboxOne_Context *ctx = (SDL_DriverXboxOne_Context *)context->context;
   14.96 +    SDL_DriverXboxOne_Context *ctx = (SDL_DriverXboxOne_Context *)context;
   14.97      Uint8 rumble_packet[] = { 0x09, 0x00, 0x00, 0x09, 0x00, 0x0F, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00, 0xFF };
   14.98  
   14.99      /* The Rock Candy Xbox One Controller limits the range of
  14.100 @@ -236,7 +194,7 @@
  14.101      rumble_packet[8] = (low_frequency_rumble >> 9);
  14.102      rumble_packet[9] = (high_frequency_rumble >> 9);
  14.103  
  14.104 -    if (hid_write(context->device, rumble_packet, sizeof(rumble_packet)) != sizeof(rumble_packet)) {
  14.105 +    if (hid_write(dev, rumble_packet, sizeof(rumble_packet)) != sizeof(rumble_packet)) {
  14.106          return SDL_SetError("Couldn't send rumble packet");
  14.107      }
  14.108  
  14.109 @@ -309,24 +267,19 @@
  14.110  }
  14.111  
  14.112  static SDL_bool
  14.113 -HIDAPI_DriverXboxOne_UpdateDriver(SDL_HIDAPI_DriverData *context, int *num_joysticks)
  14.114 +HIDAPI_DriverXboxOne_Update(SDL_Joystick *joystick, hid_device *dev, void *context)
  14.115  {
  14.116 -    SDL_DriverXboxOne_Context *ctx = (SDL_DriverXboxOne_Context *)context->context;
  14.117 -    SDL_Joystick *joystick = SDL_JoystickFromInstanceID(ctx->joystickID);
  14.118 +    SDL_DriverXboxOne_Context *ctx = (SDL_DriverXboxOne_Context *)context;
  14.119      Uint8 data[USB_PACKET_LENGTH];
  14.120      int size;
  14.121  
  14.122 -    if (joystick == NULL) {
  14.123 -        return SDL_TRUE; /* Nothing to do right now! */
  14.124 -    }
  14.125 -
  14.126 -    while ((size = hid_read_timeout(context->device, data, sizeof(data), 0)) > 0) {
  14.127 +    while ((size = hid_read_timeout(dev, data, sizeof(data), 0)) > 0) {
  14.128          switch (data[0]) {
  14.129          case 0x20:
  14.130 -            HIDAPI_DriverXboxOne_HandleStatePacket(joystick, context->device, ctx, data, size);
  14.131 +            HIDAPI_DriverXboxOne_HandleStatePacket(joystick, dev, ctx, data, size);
  14.132              break;
  14.133          case 0x07:
  14.134 -            HIDAPI_DriverXboxOne_HandleModePacket(joystick, context->device, ctx, data, size);
  14.135 +            HIDAPI_DriverXboxOne_HandleModePacket(joystick, dev, ctx, data, size);
  14.136              break;
  14.137          default:
  14.138  #ifdef DEBUG_JOYSTICK
  14.139 @@ -339,27 +292,29 @@
  14.140      if (ctx->rumble_expiration) {
  14.141          Uint32 now = SDL_GetTicks();
  14.142          if (SDL_TICKS_PASSED(now, ctx->rumble_expiration)) {
  14.143 -            HIDAPI_DriverXboxOne_Rumble(context, joystick, 0, 0, 0);
  14.144 +            HIDAPI_DriverXboxOne_Rumble(joystick, dev, context, 0, 0, 0);
  14.145          }
  14.146      }
  14.147  
  14.148      return (size >= 0);
  14.149  }
  14.150  
  14.151 +static void
  14.152 +HIDAPI_DriverXboxOne_Quit(SDL_Joystick *joystick, hid_device *dev, void *context)
  14.153 +{
  14.154 +    SDL_free(context);
  14.155 +}
  14.156 +
  14.157  SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverXboxOne =
  14.158  {
  14.159      SDL_HINT_JOYSTICK_HIDAPI_XBOX,
  14.160      SDL_TRUE,
  14.161      HIDAPI_DriverXboxOne_IsSupportedDevice,
  14.162      HIDAPI_DriverXboxOne_GetDeviceName,
  14.163 -    HIDAPI_DriverXboxOne_InitDriver,
  14.164 -    HIDAPI_DriverXboxOne_QuitDriver,
  14.165 -    HIDAPI_DriverXboxOne_UpdateDriver,
  14.166 -    HIDAPI_DriverXboxOne_NumJoysticks,
  14.167 -    HIDAPI_DriverXboxOne_PlayerIndexForIndex,
  14.168 -    HIDAPI_DriverXboxOne_InstanceIDForIndex,
  14.169 -    HIDAPI_DriverXboxOne_OpenJoystick,
  14.170 -    HIDAPI_DriverXboxOne_Rumble
  14.171 +    HIDAPI_DriverXboxOne_Init,
  14.172 +    HIDAPI_DriverXboxOne_Rumble,
  14.173 +    HIDAPI_DriverXboxOne_Update,
  14.174 +    HIDAPI_DriverXboxOne_Quit
  14.175  };
  14.176  
  14.177  #endif /* SDL_JOYSTICK_HIDAPI_XBOXONE */
    15.1 --- a/src/joystick/hidapi/SDL_hidapijoystick.c	Wed Jun 19 06:43:54 2019 -0700
    15.2 +++ b/src/joystick/hidapi/SDL_hidapijoystick.c	Wed Jun 19 15:54:21 2019 -0700
    15.3 @@ -50,10 +50,18 @@
    15.4  #endif
    15.5  #endif
    15.6  
    15.7 +struct joystick_hwdata
    15.8 +{
    15.9 +    SDL_HIDAPI_DeviceDriver *driver;
   15.10 +    void *context;
   15.11 +
   15.12 +    SDL_mutex *mutex;
   15.13 +    hid_device *dev;
   15.14 +};
   15.15 +
   15.16  typedef struct _SDL_HIDAPI_Device
   15.17  {
   15.18 -    SDL_HIDAPI_DriverData devdata;
   15.19 -    SDL_mutex *mutex;
   15.20 +    SDL_JoystickID instance_id;
   15.21      char *name;
   15.22      char *path;
   15.23      Uint16 vendor_id;
   15.24 @@ -87,9 +95,6 @@
   15.25  #ifdef SDL_JOYSTICK_HIDAPI_XBOXONE
   15.26      &SDL_HIDAPI_DriverXboxOne,
   15.27  #endif
   15.28 -#ifdef SDL_JOYSTICK_HIDAPI_GAMECUBE
   15.29 -    &SDL_HIDAPI_DriverGameCube,
   15.30 -#endif
   15.31  };
   15.32  static SDL_HIDAPI_Device *SDL_HIDAPI_devices;
   15.33  static int SDL_HIDAPI_numjoysticks = 0;
   15.34 @@ -388,36 +393,6 @@
   15.35  #endif
   15.36  }
   15.37  
   15.38 -static void
   15.39 -HIDAPI_InitDriver(SDL_HIDAPI_Device *device)
   15.40 -{
   15.41 -    device->devdata.device = hid_open_path(device->path, 0);
   15.42 -    if (!device->devdata.device) {
   15.43 -        SDL_SetError("Couldn't open HID device %s", device->path);
   15.44 -        device->driver = NULL;
   15.45 -    } else {
   15.46 -        device->driver->InitDriver(
   15.47 -            &device->devdata,
   15.48 -            device->vendor_id,
   15.49 -            device->product_id,
   15.50 -            &SDL_HIDAPI_numjoysticks
   15.51 -        );
   15.52 -        device->mutex = SDL_CreateMutex();
   15.53 -    }
   15.54 -}
   15.55 -
   15.56 -static void
   15.57 -HIDAPI_QuitDriver(SDL_HIDAPI_Device *device, SDL_bool send_event)
   15.58 -{
   15.59 -    device->driver->QuitDriver(
   15.60 -        &device->devdata,
   15.61 -        send_event,
   15.62 -        &SDL_HIDAPI_numjoysticks
   15.63 -    );
   15.64 -    hid_close(device->devdata.device);
   15.65 -    SDL_DestroyMutex(device->mutex);
   15.66 -    device->driver = NULL;
   15.67 -}
   15.68  
   15.69  const char *
   15.70  HIDAPI_XboxControllerName(Uint16 vendor_id, Uint16 product_id)
   15.71 @@ -630,17 +605,15 @@
   15.72  }
   15.73  
   15.74  static SDL_HIDAPI_Device *
   15.75 -HIDAPI_GetDeviceByIndex(int device_index)
   15.76 +HIDAPI_GetJoystickByIndex(int device_index)
   15.77  {
   15.78      SDL_HIDAPI_Device *device = SDL_HIDAPI_devices;
   15.79 -    int joysticks;
   15.80      while (device) {
   15.81          if (device->driver) {
   15.82 -            joysticks = device->driver->NumJoysticks(&device->devdata);
   15.83 -            if (device_index < joysticks) {
   15.84 +            if (device_index == 0) {
   15.85                  break;
   15.86              }
   15.87 -            device_index -= joysticks;
   15.88 +            --device_index;
   15.89          }
   15.90          device = device->next;
   15.91      }
   15.92 @@ -687,12 +660,20 @@
   15.93      while (device) {
   15.94          if (device->driver) {
   15.95              if (!device->driver->enabled) {
   15.96 -                HIDAPI_QuitDriver(device, SDL_TRUE);
   15.97 +                device->driver = NULL;
   15.98 +
   15.99 +                --SDL_HIDAPI_numjoysticks;
  15.100 +
  15.101 +                SDL_PrivateJoystickRemoved(device->instance_id);
  15.102              }
  15.103          } else {
  15.104              device->driver = HIDAPI_GetDeviceDriver(device);
  15.105              if (device->driver) {
  15.106 -                HIDAPI_InitDriver(device);
  15.107 +                device->instance_id = SDL_GetNextJoystickInstanceID();
  15.108 +
  15.109 +                ++SDL_HIDAPI_numjoysticks;
  15.110 +
  15.111 +                SDL_PrivateJoystickAdded(device->instance_id);
  15.112              }
  15.113          }
  15.114          device = device->next;
  15.115 @@ -742,6 +723,7 @@
  15.116      if (!device) {
  15.117          return;
  15.118      }
  15.119 +    device->instance_id = -1;
  15.120      device->seen = SDL_TRUE;
  15.121      device->vendor_id = info->vendor_id;
  15.122      device->product_id = info->product_id;
  15.123 @@ -836,8 +818,12 @@
  15.124      }
  15.125  
  15.126      if (device->driver) {
  15.127 -        /* It's a joystick device! */
  15.128 -        HIDAPI_InitDriver(device);
  15.129 +        /* It's a joystick! */
  15.130 +        device->instance_id = SDL_GetNextJoystickInstanceID();
  15.131 +
  15.132 +        ++SDL_HIDAPI_numjoysticks;
  15.133 +
  15.134 +        SDL_PrivateJoystickAdded(device->instance_id);
  15.135      }
  15.136  }
  15.137  
  15.138 @@ -854,8 +840,11 @@
  15.139                  SDL_HIDAPI_devices = curr->next;
  15.140              }
  15.141  
  15.142 -            if (device->driver) {
  15.143 -                HIDAPI_QuitDriver(device, send_event);
  15.144 +            if (device->driver && send_event) {
  15.145 +                /* Need to decrement the joystick count before we post the event */
  15.146 +                --SDL_HIDAPI_numjoysticks;
  15.147 +
  15.148 +                SDL_PrivateJoystickRemoved(device->instance_id);
  15.149              }
  15.150  
  15.151              SDL_free(device->name);
  15.152 @@ -942,85 +931,101 @@
  15.153  static const char *
  15.154  HIDAPI_JoystickGetDeviceName(int device_index)
  15.155  {
  15.156 -    return HIDAPI_GetDeviceByIndex(device_index)->name;
  15.157 +    return HIDAPI_GetJoystickByIndex(device_index)->name;
  15.158  }
  15.159  
  15.160  static int
  15.161  HIDAPI_JoystickGetDevicePlayerIndex(int device_index)
  15.162  {
  15.163 -    SDL_HIDAPI_Device *device = SDL_HIDAPI_devices;
  15.164 -    int joysticks;
  15.165 -    while (device) {
  15.166 -        if (device->driver) {
  15.167 -            joysticks = device->driver->NumJoysticks(&device->devdata);
  15.168 -            if (device_index < joysticks) {
  15.169 -                break;
  15.170 -            }
  15.171 -            device_index -= joysticks;
  15.172 -        }
  15.173 -        device = device->next;
  15.174 -    }
  15.175 -    return device->driver->PlayerIndexForIndex(&device->devdata, device_index);
  15.176 +    return -1;
  15.177  }
  15.178  
  15.179  static SDL_JoystickGUID
  15.180  HIDAPI_JoystickGetDeviceGUID(int device_index)
  15.181  {
  15.182 -    return HIDAPI_GetDeviceByIndex(device_index)->guid;
  15.183 +    return HIDAPI_GetJoystickByIndex(device_index)->guid;
  15.184  }
  15.185  
  15.186  static SDL_JoystickID
  15.187  HIDAPI_JoystickGetDeviceInstanceID(int device_index)
  15.188  {
  15.189 -    SDL_HIDAPI_Device *device = SDL_HIDAPI_devices;
  15.190 -    int joysticks;
  15.191 -    while (device) {
  15.192 -        if (device->driver) {
  15.193 -            joysticks = device->driver->NumJoysticks(&device->devdata);
  15.194 -            if (device_index < joysticks) {
  15.195 -                break;
  15.196 -            }
  15.197 -            device_index -= joysticks;
  15.198 -        }
  15.199 -        device = device->next;
  15.200 -    }
  15.201 -    return device->driver->InstanceIDForIndex(&device->devdata, device_index);
  15.202 +    return HIDAPI_GetJoystickByIndex(device_index)->instance_id;
  15.203  }
  15.204  
  15.205  static int
  15.206  HIDAPI_JoystickOpen(SDL_Joystick * joystick, int device_index)
  15.207  {
  15.208 -    SDL_HIDAPI_Device *device = HIDAPI_GetDeviceByIndex(device_index);
  15.209 +    SDL_HIDAPI_Device *device = HIDAPI_GetJoystickByIndex(device_index);
  15.210 +    struct joystick_hwdata *hwdata;
  15.211  
  15.212 -    if (!device->driver->OpenJoystick(&device->devdata, joystick)) {
  15.213 +    hwdata = (struct joystick_hwdata *)SDL_calloc(1, sizeof(*hwdata));
  15.214 +    if (!hwdata) {
  15.215 +        return SDL_OutOfMemory();
  15.216 +    }
  15.217 +
  15.218 +    hwdata->driver = device->driver;
  15.219 +    hwdata->dev = hid_open_path(device->path, 0);
  15.220 +    if (!hwdata->dev) {
  15.221 +        SDL_free(hwdata);
  15.222 +        return SDL_SetError("Couldn't open HID device %s", device->path);
  15.223 +    }
  15.224 +    hwdata->mutex = SDL_CreateMutex();
  15.225 +
  15.226 +    if (!device->driver->Init(joystick, hwdata->dev, device->vendor_id, device->product_id, &hwdata->context)) {
  15.227 +        hid_close(hwdata->dev);
  15.228 +        SDL_free(hwdata);
  15.229          return -1;
  15.230      }
  15.231  
  15.232 -    joystick->hwdata = (struct joystick_hwdata *)device;
  15.233 +    joystick->hwdata = hwdata;
  15.234      return 0;
  15.235  }
  15.236  
  15.237  static int
  15.238  HIDAPI_JoystickRumble(SDL_Joystick * joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble, Uint32 duration_ms)
  15.239  {
  15.240 -    SDL_HIDAPI_Device *device = (SDL_HIDAPI_Device *)joystick->hwdata;
  15.241 +    struct joystick_hwdata *hwdata = joystick->hwdata;
  15.242 +    SDL_HIDAPI_DeviceDriver *driver = hwdata->driver;
  15.243      int result;
  15.244  
  15.245 -    SDL_LockMutex(device->mutex);
  15.246 -    result = device->driver->Rumble(&device->devdata, joystick, low_frequency_rumble, high_frequency_rumble, duration_ms);
  15.247 -    SDL_UnlockMutex(device->mutex);
  15.248 +    SDL_LockMutex(hwdata->mutex);
  15.249 +    result = driver->Rumble(joystick, hwdata->dev, hwdata->context, low_frequency_rumble, high_frequency_rumble, duration_ms);
  15.250 +    SDL_UnlockMutex(hwdata->mutex);
  15.251      return result;
  15.252  }
  15.253  
  15.254  static void
  15.255  HIDAPI_JoystickUpdate(SDL_Joystick * joystick)
  15.256  {
  15.257 -    /* No-op, all updates are done in SDL_HIDAPI_UpdateDevices */
  15.258 +    struct joystick_hwdata *hwdata = joystick->hwdata;
  15.259 +    SDL_HIDAPI_DeviceDriver *driver = hwdata->driver;
  15.260 +    SDL_bool succeeded;
  15.261 +
  15.262 +    SDL_LockMutex(hwdata->mutex);
  15.263 +    succeeded = driver->Update(joystick, hwdata->dev, hwdata->context);
  15.264 +    SDL_UnlockMutex(hwdata->mutex);
  15.265 +    
  15.266 +    if (!succeeded) {
  15.267 +        SDL_HIDAPI_Device *device;
  15.268 +        for (device = SDL_HIDAPI_devices; device; device = device->next) {
  15.269 +            if (device->instance_id == joystick->instance_id) {
  15.270 +                HIDAPI_DelDevice(device, SDL_TRUE);
  15.271 +                break;
  15.272 +            }
  15.273 +        }
  15.274 +    }
  15.275  }
  15.276  
  15.277  static void
  15.278  HIDAPI_JoystickClose(SDL_Joystick * joystick)
  15.279  {
  15.280 +    struct joystick_hwdata *hwdata = joystick->hwdata;
  15.281 +    SDL_HIDAPI_DeviceDriver *driver = hwdata->driver;
  15.282 +    driver->Quit(joystick, hwdata->dev, hwdata->context);
  15.283 +
  15.284 +    hid_close(hwdata->dev);
  15.285 +    SDL_DestroyMutex(hwdata->mutex);
  15.286 +    SDL_free(hwdata);
  15.287      joystick->hwdata = NULL;
  15.288  }
  15.289  
  15.290 @@ -1045,30 +1050,6 @@
  15.291      hid_exit();
  15.292  }
  15.293  
  15.294 -void
  15.295 -SDL_HIDAPI_UpdateDevices(void)
  15.296 -{
  15.297 -    SDL_HIDAPI_Device *next, *device = SDL_HIDAPI_devices;
  15.298 -    SDL_bool succeeded;
  15.299 -
  15.300 -    while (device) {
  15.301 -        if (device->driver) {
  15.302 -            SDL_LockMutex(device->mutex);
  15.303 -            succeeded = device->driver->UpdateDriver(&device->devdata, &SDL_HIDAPI_numjoysticks);
  15.304 -            SDL_UnlockMutex(device->mutex);
  15.305 -            if (!succeeded) {
  15.306 -                next = device->next;
  15.307 -                HIDAPI_DelDevice(device, SDL_TRUE);
  15.308 -                device = next;
  15.309 -            } else {
  15.310 -                device = device->next;
  15.311 -            }
  15.312 -        } else {
  15.313 -            device = device->next;
  15.314 -        }
  15.315 -    }
  15.316 -}
  15.317 -
  15.318  SDL_JoystickDriver SDL_HIDAPI_JoystickDriver =
  15.319  {
  15.320      HIDAPI_JoystickInit,
    16.1 --- a/src/joystick/hidapi/SDL_hidapijoystick_c.h	Wed Jun 19 06:43:54 2019 -0700
    16.2 +++ b/src/joystick/hidapi/SDL_hidapijoystick_c.h	Wed Jun 19 15:54:21 2019 -0700
    16.3 @@ -30,7 +30,6 @@
    16.4  #define SDL_JOYSTICK_HIDAPI_SWITCH
    16.5  #define SDL_JOYSTICK_HIDAPI_XBOX360
    16.6  #define SDL_JOYSTICK_HIDAPI_XBOXONE
    16.7 -#define SDL_JOYSTICK_HIDAPI_GAMECUBE
    16.8  
    16.9  #ifdef __WINDOWS__
   16.10  /* On Windows, Xbox One controllers are handled by the Xbox 360 driver */
   16.11 @@ -44,38 +43,16 @@
   16.12  #undef SDL_JOYSTICK_HIDAPI_XBOXONE
   16.13  #endif
   16.14  
   16.15 -typedef struct _SDL_HIDAPI_DriverData
   16.16 -{
   16.17 -    hid_device *device;
   16.18 -    void *context;
   16.19 -} SDL_HIDAPI_DriverData;
   16.20 -
   16.21  typedef struct _SDL_HIDAPI_DeviceDriver
   16.22  {
   16.23      const char *hint;
   16.24      SDL_bool enabled;
   16.25      SDL_bool (*IsSupportedDevice)(Uint16 vendor_id, Uint16 product_id, Uint16 version, int interface_number);
   16.26      const char *(*GetDeviceName)(Uint16 vendor_id, Uint16 product_id);
   16.27 -
   16.28 -    SDL_bool       (*InitDriver)(SDL_HIDAPI_DriverData *context,
   16.29 -                                 Uint16 vendor_id, Uint16 product_id, int *num_joysticks);
   16.30 -    void           (*QuitDriver)(SDL_HIDAPI_DriverData *context,
   16.31 -                                 SDL_bool send_event,
   16.32 -                                 int *num_joysticks);
   16.33 -    SDL_bool       (*UpdateDriver)(SDL_HIDAPI_DriverData *context,
   16.34 -                                   int *num_joysticks);
   16.35 -    int            (*NumJoysticks)(SDL_HIDAPI_DriverData *context);
   16.36 -    int            (*PlayerIndexForIndex)(SDL_HIDAPI_DriverData *context,
   16.37 -                                          int index);
   16.38 -    SDL_JoystickID (*InstanceIDForIndex)(SDL_HIDAPI_DriverData *context,
   16.39 -                                         int index);
   16.40 -    SDL_bool       (*OpenJoystick)(SDL_HIDAPI_DriverData *context,
   16.41 -                                   SDL_Joystick *joystick);
   16.42 -    int            (*Rumble)(SDL_HIDAPI_DriverData *context,
   16.43 -                             SDL_Joystick *joystick,
   16.44 -                             Uint16 low_frequency_rumble,
   16.45 -                             Uint16 high_frequency_rumble,
   16.46 -                             Uint32 duration_ms);
   16.47 +    SDL_bool (*Init)(SDL_Joystick *joystick, hid_device *dev, Uint16 vendor_id, Uint16 product_id, void **context);
   16.48 +    int (*Rumble)(SDL_Joystick *joystick, hid_device *dev, void *context, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble, Uint32 duration_ms);
   16.49 +    SDL_bool (*Update)(SDL_Joystick *joystick, hid_device *dev, void *context);
   16.50 +    void (*Quit)(SDL_Joystick *joystick, hid_device *dev, void *context);
   16.51  
   16.52  } SDL_HIDAPI_DeviceDriver;
   16.53  
   16.54 @@ -85,7 +62,6 @@
   16.55  extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverSwitch;
   16.56  extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverXbox360;
   16.57  extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverXboxOne;
   16.58 -extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverGameCube;
   16.59  
   16.60  /* Return true if a HID device is present and supported as a joystick */
   16.61  extern SDL_bool HIDAPI_IsDevicePresent(Uint16 vendor_id, Uint16 product_id, Uint16 version);