Added SDL_GameControllerType enumerations for the Amazon Luna and Google Stadia controllers Fixes bug https://github.com/libsdl-org/SDL/issues/4019
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
diff --git a/include/SDL_gamecontroller.h b/include/SDL_gamecontroller.h
index de019ae..720a75a 100644
--- a/include/SDL_gamecontroller.h
+++ b/include/SDL_gamecontroller.h
@@ -67,7 +67,9 @@ typedef enum
SDL_CONTROLLER_TYPE_PS4,
SDL_CONTROLLER_TYPE_NINTENDO_SWITCH_PRO,
SDL_CONTROLLER_TYPE_VIRTUAL,
- SDL_CONTROLLER_TYPE_PS5
+ SDL_CONTROLLER_TYPE_PS5,
+ SDL_CONTROLLER_TYPE_AMAZON_LUNA,
+ SDL_CONTROLLER_TYPE_GOOGLE_STADIA
} SDL_GameControllerType;
typedef enum
diff --git a/src/joystick/SDL_joystick.c b/src/joystick/SDL_joystick.c
index aa03a51..3c5e595 100644
--- a/src/joystick/SDL_joystick.c
+++ b/src/joystick/SDL_joystick.c
@@ -1898,6 +1898,13 @@ SDL_GetJoystickGameControllerType(const char *name, Uint16 vendor, Uint16 produc
} else if (vendor == 0x0001 && product == 0x0001) {
type = SDL_CONTROLLER_TYPE_UNKNOWN;
+ } else if ((vendor == USB_VENDOR_AMAZON && product == USB_PRODUCT_AMAZON_LUNA_CONTROLLER) ||
+ (vendor == BLUETOOTH_VENDOR_AMAZON && product == BLUETOOTH_PRODUCT_LUNA_CONTROLLER)) {
+ type = SDL_CONTROLLER_TYPE_AMAZON_LUNA;
+
+ } else if (vendor == USB_VENDOR_GOOGLE && product == USB_PRODUCT_GOOGLE_STADIA_CONTROLLER) {
+ type = SDL_CONTROLLER_TYPE_GOOGLE_STADIA;
+
} else {
switch (GuessControllerType(vendor, product)) {
case k_eControllerType_XBox360Controller:
diff --git a/src/joystick/hidapi/SDL_hidapi_luna.c b/src/joystick/hidapi/SDL_hidapi_luna.c
index e39b568..78d5c5e 100644
--- a/src/joystick/hidapi/SDL_hidapi_luna.c
+++ b/src/joystick/hidapi/SDL_hidapi_luna.c
@@ -50,11 +50,7 @@ typedef struct {
static SDL_bool
HIDAPI_DriverLuna_IsSupportedDevice(const char *name, SDL_GameControllerType type, Uint16 vendor_id, Uint16 product_id, Uint16 version, int interface_number, int interface_class, int interface_subclass, int interface_protocol)
{
- if ((vendor_id == USB_VENDOR_AMAZON && product_id == USB_PRODUCT_AMAZON_LUNA_CONTROLLER) ||
- (vendor_id == BLUETOOTH_VENDOR_AMAZON && product_id == BLUETOOTH_PRODUCT_LUNA_CONTROLLER)) {
- return SDL_TRUE;
- }
- return SDL_FALSE;
+ return (type == SDL_CONTROLLER_TYPE_AMAZON_LUNA) ? SDL_TRUE : SDL_FALSE;
}
static const char *
diff --git a/src/joystick/hidapi/SDL_hidapi_stadia.c b/src/joystick/hidapi/SDL_hidapi_stadia.c
index 896b480..c11aadd 100644
--- a/src/joystick/hidapi/SDL_hidapi_stadia.c
+++ b/src/joystick/hidapi/SDL_hidapi_stadia.c
@@ -51,10 +51,7 @@ typedef struct {
static SDL_bool
HIDAPI_DriverStadia_IsSupportedDevice(const char *name, SDL_GameControllerType type, Uint16 vendor_id, Uint16 product_id, Uint16 version, int interface_number, int interface_class, int interface_subclass, int interface_protocol)
{
- if (vendor_id == USB_VENDOR_GOOGLE && product_id == USB_PRODUCT_GOOGLE_STADIA_CONTROLLER) {
- return SDL_TRUE;
- }
- return SDL_FALSE;
+ return (type == SDL_CONTROLLER_TYPE_GOOGLE_STADIA) ? SDL_TRUE : SDL_FALSE;
}
static const char *
diff --git a/test/testgamecontroller.c b/test/testgamecontroller.c
index 71de641..8a3ff92 100644
--- a/test/testgamecontroller.c
+++ b/test/testgamecontroller.c
@@ -554,11 +554,14 @@ main(int argc, char *argv[])
controller_count++;
name = SDL_GameControllerNameForIndex(i);
switch (SDL_GameControllerTypeForIndex(i)) {
- case SDL_CONTROLLER_TYPE_XBOX360:
- description = "XBox 360 Controller";
+ case SDL_CONTROLLER_TYPE_AMAZON_LUNA:
+ description = "Amazon Luna Controller";
break;
- case SDL_CONTROLLER_TYPE_XBOXONE:
- description = "XBox One Controller";
+ case SDL_CONTROLLER_TYPE_GOOGLE_STADIA:
+ description = "Google Stadia Controller";
+ break;
+ case SDL_CONTROLLER_TYPE_NINTENDO_SWITCH_PRO:
+ description = "Nintendo Switch Pro Controller";
break;
case SDL_CONTROLLER_TYPE_PS3:
description = "PS3 Controller";
@@ -566,8 +569,14 @@ main(int argc, char *argv[])
case SDL_CONTROLLER_TYPE_PS4:
description = "PS4 Controller";
break;
- case SDL_CONTROLLER_TYPE_NINTENDO_SWITCH_PRO:
- description = "Nintendo Switch Pro Controller";
+ case SDL_CONTROLLER_TYPE_PS5:
+ description = "PS5 Controller";
+ break;
+ case SDL_CONTROLLER_TYPE_XBOX360:
+ description = "XBox 360 Controller";
+ break;
+ case SDL_CONTROLLER_TYPE_XBOXONE:
+ description = "XBox One Controller";
break;
case SDL_CONTROLLER_TYPE_VIRTUAL:
description = "Virtual Game Controller";