Better fix to make sure we're only returning controllers from the HIDAPI joystick API
authorSam Lantinga <slouken@libsdl.org>
Fri, 31 Aug 2018 18:10:21 -0700
changeset 12168a5459597367f
parent 12167 af78f50636e0
child 12169 be34b836f738
Better fix to make sure we're only returning controllers from the HIDAPI joystick API
src/joystick/controller_type.h
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/src/joystick/controller_type.h	Fri Aug 31 17:47:34 2018 -0700
     1.2 +++ b/src/joystick/controller_type.h	Fri Aug 31 18:10:21 2018 -0700
     1.3 @@ -286,7 +286,7 @@
     1.4  	{ MAKE_CONTROLLER_ID( 0x1430, 0x4748 ), k_eControllerType_XBox360Controller },	// RedOctane Guitar Hero X-plorer
     1.5  	{ MAKE_CONTROLLER_ID( 0x1430, 0xf801 ), k_eControllerType_XBox360Controller },	// RedOctane Controller
     1.6  	{ MAKE_CONTROLLER_ID( 0x146b, 0x0601 ), k_eControllerType_XBox360Controller },	// BigBen Interactive XBOX 360 Controller
     1.7 -//	{ MAKE_CONTROLLER_ID( 0x1532, 0x0037 ), k_eControllerType_XBox360Controller },	// Razer Sabertooth - The Razer DeathAdder mouse also shows up as this VID/PID
     1.8 +	{ MAKE_CONTROLLER_ID( 0x1532, 0x0037 ), k_eControllerType_XBox360Controller },	// Razer Sabertooth
     1.9  	{ MAKE_CONTROLLER_ID( 0x1532, 0x0a00 ), k_eControllerType_XBoxOneController },	// Razer Atrox Arcade Stick
    1.10  	{ MAKE_CONTROLLER_ID( 0x1532, 0x0a03 ), k_eControllerType_XBoxOneController },	// Razer Wildcat
    1.11  	{ MAKE_CONTROLLER_ID( 0x15e4, 0x3f00 ), k_eControllerType_XBox360Controller },	// Power A Mini Pro Elite
     2.1 --- a/src/joystick/hidapi/SDL_hidapi_ps4.c	Fri Aug 31 17:47:34 2018 -0700
     2.2 +++ b/src/joystick/hidapi/SDL_hidapi_ps4.c	Fri Aug 31 18:10:21 2018 -0700
     2.3 @@ -214,16 +214,8 @@
     2.4  }
     2.5  
     2.6  static SDL_bool
     2.7 -HIDAPI_DriverPS4_IsSupportedDevice(Uint16 vendor_id, Uint16 product_id, Uint16 version, int interface_number, Uint16 usage_page, Uint16 usage)
     2.8 +HIDAPI_DriverPS4_IsSupportedDevice(Uint16 vendor_id, Uint16 product_id, Uint16 version, int interface_number)
     2.9  {
    2.10 -    /* The Revolution Pro Controller and Razer Raiju expose multiple interfaces on Windows */
    2.11 -    const Uint16 NACON_USB_VID = 0x146b;
    2.12 -    const Uint16 RAZER_USB_VID = 0x1532;
    2.13 -    if ((vendor_id == NACON_USB_VID || vendor_id == RAZER_USB_VID) &&
    2.14 -        (usage_page != 0 && usage_page != 1)) {
    2.15 -        return SDL_FALSE;
    2.16 -    }
    2.17 -
    2.18      return SDL_IsJoystickPS4(vendor_id, product_id);
    2.19  }
    2.20  
     3.1 --- a/src/joystick/hidapi/SDL_hidapi_switch.c	Fri Aug 31 17:47:34 2018 -0700
     3.2 +++ b/src/joystick/hidapi/SDL_hidapi_switch.c	Fri Aug 31 18:10:21 2018 -0700
     3.3 @@ -210,7 +210,7 @@
     3.4  
     3.5  
     3.6  static SDL_bool
     3.7 -HIDAPI_DriverSwitch_IsSupportedDevice(Uint16 vendor_id, Uint16 product_id, Uint16 version, int interface_number, Uint16 usage_page, Uint16 usage)
     3.8 +HIDAPI_DriverSwitch_IsSupportedDevice(Uint16 vendor_id, Uint16 product_id, Uint16 version, int interface_number)
     3.9  {
    3.10      return SDL_IsJoystickNintendoSwitchPro(vendor_id, product_id);
    3.11  }
     4.1 --- a/src/joystick/hidapi/SDL_hidapi_xbox360.c	Fri Aug 31 17:47:34 2018 -0700
     4.2 +++ b/src/joystick/hidapi/SDL_hidapi_xbox360.c	Fri Aug 31 18:10:21 2018 -0700
     4.3 @@ -107,7 +107,7 @@
     4.4  #endif /* __WIN32__ */
     4.5  
     4.6  static SDL_bool
     4.7 -HIDAPI_DriverXbox360_IsSupportedDevice(Uint16 vendor_id, Uint16 product_id, Uint16 version, int interface_number, Uint16 usage_page, Uint16 usage)
     4.8 +HIDAPI_DriverXbox360_IsSupportedDevice(Uint16 vendor_id, Uint16 product_id, Uint16 version, int interface_number)
     4.9  {
    4.10  #if defined(__MACOSX__) || defined(__WIN32__)
    4.11      if (vendor_id == 0x045e && product_id == 0x028e && version == 1) {
     5.1 --- a/src/joystick/hidapi/SDL_hidapi_xboxone.c	Fri Aug 31 17:47:34 2018 -0700
     5.2 +++ b/src/joystick/hidapi/SDL_hidapi_xboxone.c	Fri Aug 31 18:10:21 2018 -0700
     5.3 @@ -131,7 +131,7 @@
     5.4  
     5.5  
     5.6  static SDL_bool
     5.7 -HIDAPI_DriverXboxOne_IsSupportedDevice(Uint16 vendor_id, Uint16 product_id, Uint16 version, int interface_number, Uint16 usage_page, Uint16 usage)
     5.8 +HIDAPI_DriverXboxOne_IsSupportedDevice(Uint16 vendor_id, Uint16 product_id, Uint16 version, int interface_number)
     5.9  {
    5.10      return SDL_IsJoystickXboxOne(vendor_id, product_id);
    5.11  }
     6.1 --- a/src/joystick/hidapi/SDL_hidapijoystick.c	Fri Aug 31 17:47:34 2018 -0700
     6.2 +++ b/src/joystick/hidapi/SDL_hidapijoystick.c	Fri Aug 31 18:10:21 2018 -0700
     6.3 @@ -552,7 +552,7 @@
     6.4  
     6.5      for (i = 0; i < SDL_arraysize(SDL_HIDAPI_drivers); ++i) {
     6.6          SDL_HIDAPI_DeviceDriver *driver = SDL_HIDAPI_drivers[i];
     6.7 -        if (driver->enabled && driver->IsSupportedDevice(vendor_id, product_id, version, -1, 0, 0)) {
     6.8 +        if (driver->enabled && driver->IsSupportedDevice(vendor_id, product_id, version, -1)) {
     6.9              return SDL_TRUE;
    6.10          }
    6.11      }
    6.12 @@ -562,15 +562,26 @@
    6.13  static SDL_HIDAPI_DeviceDriver *
    6.14  HIDAPI_GetDeviceDriver(SDL_HIDAPI_Device *device)
    6.15  {
    6.16 +    const Uint16 USAGE_PAGE_GENERIC_DESKTOP = 0x0001;
    6.17 +    const Uint16 USAGE_JOYSTICK = 0x0004;
    6.18 +    const Uint16 USAGE_GAMEPAD = 0x0005;
    6.19 +    const Uint16 USAGE_MULTIAXISCONTROLLER = 0x0008;
    6.20      int i;
    6.21  
    6.22      if (SDL_ShouldIgnoreJoystick(device->name, device->guid)) {
    6.23          return NULL;
    6.24      }
    6.25  
    6.26 +    if (device->usage_page && device->usage_page != USAGE_PAGE_GENERIC_DESKTOP) {
    6.27 +        return NULL;
    6.28 +    }
    6.29 +    if (device->usage && device->usage != USAGE_JOYSTICK && device->usage != USAGE_GAMEPAD && device->usage != USAGE_MULTIAXISCONTROLLER) {
    6.30 +        return NULL;
    6.31 +    }
    6.32 +
    6.33      for (i = 0; i < SDL_arraysize(SDL_HIDAPI_drivers); ++i) {
    6.34          SDL_HIDAPI_DeviceDriver *driver = SDL_HIDAPI_drivers[i];
    6.35 -        if (driver->enabled && driver->IsSupportedDevice(device->vendor_id, device->product_id, device->version, device->interface_number, device->usage_page, device->usage)) {
    6.36 +        if (driver->enabled && driver->IsSupportedDevice(device->vendor_id, device->product_id, device->version, device->interface_number)) {
    6.37              return driver;
    6.38          }
    6.39      }
     7.1 --- a/src/joystick/hidapi/SDL_hidapijoystick_c.h	Fri Aug 31 17:47:34 2018 -0700
     7.2 +++ b/src/joystick/hidapi/SDL_hidapijoystick_c.h	Fri Aug 31 18:10:21 2018 -0700
     7.3 @@ -45,7 +45,7 @@
     7.4  {
     7.5      const char *hint;
     7.6      SDL_bool enabled;
     7.7 -    SDL_bool (*IsSupportedDevice)(Uint16 vendor_id, Uint16 product_id, Uint16 version, int interface_number, Uint16 usage_page, Uint16 usage);
     7.8 +    SDL_bool (*IsSupportedDevice)(Uint16 vendor_id, Uint16 product_id, Uint16 version, int interface_number);
     7.9      const char *(*GetDeviceName)(Uint16 vendor_id, Uint16 product_id);
    7.10      SDL_bool (*Init)(SDL_Joystick *joystick, hid_device *dev, Uint16 vendor_id, Uint16 product_id, void **context);
    7.11      int (*Rumble)(SDL_Joystick *joystick, hid_device *dev, void *context, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble, Uint32 duration_ms);