Separate the controller protocol from the controller style This allows us to handle controllers that use the Xbox protocol but look like Nintendo Switch or Playstation controllers, like the Qanba Dragon Arcade Stick in PC mode
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 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554
diff --git a/src/joystick/SDL_joystick.c b/src/joystick/SDL_joystick.c
index 9bf6e61..cf4dd72 100644
--- a/src/joystick/SDL_joystick.c
+++ b/src/joystick/SDL_joystick.c
@@ -1837,23 +1837,48 @@ SDL_CreateJoystickName(Uint16 vendor, Uint16 product, const char *vendor_name, c
if (*vendor_name && *product_name) {
len = (SDL_strlen(vendor_name) + 1 + SDL_strlen(product_name) + 1);
name = (char *)SDL_malloc(len);
- if (!name) {
- return NULL;
+ if (name) {
+ SDL_snprintf(name, len, "%s %s", vendor_name, product_name);
}
- SDL_snprintf(name, len, "%s %s", vendor_name, product_name);
} else if (*product_name) {
name = SDL_strdup(product_name);
} else if (vendor || product) {
- len = (6 + 1 + 6 + 1);
- name = (char *)SDL_malloc(len);
- if (!name) {
- return NULL;
+ /* Couldn't find a controller name, try to give it one based on device type */
+ switch (SDL_GetJoystickGameControllerTypeFromVIDPID(vendor, product, NULL, SDL_TRUE)) {
+ case SDL_CONTROLLER_TYPE_XBOX360:
+ name = SDL_strdup("Xbox 360 Controller");
+ break;
+ case SDL_CONTROLLER_TYPE_XBOXONE:
+ name = SDL_strdup("Xbox One Controller");
+ break;
+ case SDL_CONTROLLER_TYPE_PS3:
+ name = SDL_strdup("PS3 Controller");
+ break;
+ case SDL_CONTROLLER_TYPE_PS4:
+ name = SDL_strdup("PS4 Controller");
+ break;
+ case SDL_CONTROLLER_TYPE_PS5:
+ name = SDL_strdup("PS5 Controller");
+ break;
+ case SDL_CONTROLLER_TYPE_NINTENDO_SWITCH_PRO:
+ name = SDL_strdup("Nintendo Switch Pro Controller");
+ break;
+ default:
+ len = (6 + 1 + 6 + 1);
+ name = (char *)SDL_malloc(len);
+ if (name) {
+ SDL_snprintf(name, len, "0x%.4x/0x%.4x", vendor, product);
+ }
+ break;
}
- SDL_snprintf(name, len, "0x%.4x/0x%.4x", vendor, product);
} else {
name = SDL_strdup("Controller");
}
+ if (!name) {
+ return NULL;
+ }
+
/* Trim trailing whitespace */
for (len = SDL_strlen(name); (len > 0 && name[len - 1] == ' '); --len) {
/* continue */
@@ -1902,171 +1927,102 @@ SDL_CreateJoystickName(Uint16 vendor, Uint16 product, const char *vendor_name, c
}
SDL_GameControllerType
-SDL_GetJoystickGameControllerTypeFromVIDPID(Uint16 vendor, Uint16 product)
+SDL_GetJoystickGameControllerTypeFromVIDPID(Uint16 vendor, Uint16 product, const char *name, SDL_bool forUI)
{
- return SDL_GetJoystickGameControllerType(NULL, vendor, product, -1, 0, 0, 0);
-}
-
-SDL_GameControllerType
-SDL_GetJoystickGameControllerTypeFromGUID(SDL_JoystickGUID guid, const char *name)
-{
- SDL_GameControllerType type;
- Uint16 vendor, product;
+ SDL_GameControllerType type = SDL_CONTROLLER_TYPE_UNKNOWN;
- SDL_GetJoystickGUIDInfo(guid, &vendor, &product, NULL);
- type = SDL_GetJoystickGameControllerType(name, vendor, product, -1, 0, 0, 0);
- if (type == SDL_CONTROLLER_TYPE_UNKNOWN) {
- if (SDL_IsJoystickXInput(guid)) {
- /* This is probably an Xbox One controller */
- return SDL_CONTROLLER_TYPE_XBOXONE;
+ if (vendor == 0x0000 && product == 0x0000) {
+ /* Some devices are only identifiable by their name */
+ if (name &&
+ (SDL_strcmp(name, "Lic Pro Controller") == 0 ||
+ SDL_strcmp(name, "Nintendo Wireless Gamepad") == 0 ||
+ SDL_strcmp(name, "Wireless Gamepad") == 0)) {
+ /* HORI or PowerA Switch Pro Controller clone */
+ type = SDL_CONTROLLER_TYPE_NINTENDO_SWITCH_PRO;
}
- }
- return type;
-}
-
-SDL_GameControllerType
-SDL_GetJoystickGameControllerType(const char *name, Uint16 vendor, Uint16 product, int interface_number, int interface_class, int interface_subclass, int interface_protocol)
-{
- static const int LIBUSB_CLASS_VENDOR_SPEC = 0xFF;
- static const int XB360_IFACE_SUBCLASS = 93;
- static const int XB360_IFACE_PROTOCOL = 1; /* Wired */
- static const int XB360W_IFACE_PROTOCOL = 129; /* Wireless */
- static const int XBONE_IFACE_SUBCLASS = 71;
- static const int XBONE_IFACE_PROTOCOL = 208;
- SDL_GameControllerType type = SDL_CONTROLLER_TYPE_UNKNOWN;
+ } else if (vendor == 0x0001 && product == 0x0001) {
+ type = SDL_CONTROLLER_TYPE_UNKNOWN;
- /* This code should match the checks in libusb/hid.c and HIDDeviceManager.java */
- if (interface_class == LIBUSB_CLASS_VENDOR_SPEC &&
- interface_subclass == XB360_IFACE_SUBCLASS &&
- (interface_protocol == XB360_IFACE_PROTOCOL ||
- interface_protocol == XB360W_IFACE_PROTOCOL)) {
-
- static const int SUPPORTED_VENDORS[] = {
- 0x0079, /* GPD Win 2 */
- 0x044f, /* Thrustmaster */
- 0x045e, /* Microsoft */
- 0x046d, /* Logitech */
- 0x056e, /* Elecom */
- 0x06a3, /* Saitek */
- 0x0738, /* Mad Catz */
- 0x07ff, /* Mad Catz */
- 0x0e6f, /* PDP */
- 0x0f0d, /* Hori */
- 0x1038, /* SteelSeries */
- 0x11c9, /* Nacon */
- 0x12ab, /* Unknown */
- 0x1430, /* RedOctane */
- 0x146b, /* BigBen */
- 0x1532, /* Razer */
- 0x15e4, /* Numark */
- 0x162e, /* Joytech */
- 0x1689, /* Razer Onza */
- 0x1949, /* Lab126, Inc. */
- 0x1bad, /* Harmonix */
- 0x20d6, /* PowerA */
- 0x24c6, /* PowerA */
- 0x2c22, /* Qanba */
- };
+ } else if (vendor == USB_VENDOR_MICROSOFT && product == USB_PRODUCT_XBOX_ONE_XINPUT_CONTROLLER) {
+ type = SDL_CONTROLLER_TYPE_XBOXONE;
- int i;
- for (i = 0; i < SDL_arraysize(SUPPORTED_VENDORS); ++i) {
- if (vendor == SUPPORTED_VENDORS[i]) {
- type = SDL_CONTROLLER_TYPE_XBOX360;
- break;
- }
- }
- }
+ } 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;
- if (interface_number == 0 &&
- interface_class == LIBUSB_CLASS_VENDOR_SPEC &&
- interface_subclass == XBONE_IFACE_SUBCLASS &&
- interface_protocol == XBONE_IFACE_PROTOCOL) {
+ } else if (vendor == USB_VENDOR_GOOGLE && product == USB_PRODUCT_GOOGLE_STADIA_CONTROLLER) {
+ type = SDL_CONTROLLER_TYPE_GOOGLE_STADIA;
- static const int SUPPORTED_VENDORS[] = {
- 0x045e, /* Microsoft */
- 0x0738, /* Mad Catz */
- 0x0e6f, /* PDP */
- 0x0f0d, /* Hori */
- 0x1532, /* Razer */
- 0x20d6, /* PowerA */
- 0x24c6, /* PowerA */
- 0x2e24, /* Hyperkin */
- };
+ } else if (vendor == USB_VENDOR_NINTENDO && product == USB_PRODUCT_NINTENDO_SWITCH_JOY_CON_GRIP) {
+ type = SDL_GetHintBoolean(SDL_HINT_JOYSTICK_HIDAPI_JOY_CONS, SDL_FALSE) ? SDL_CONTROLLER_TYPE_NINTENDO_SWITCH_PRO : SDL_CONTROLLER_TYPE_UNKNOWN;
- int i;
- for (i = 0; i < SDL_arraysize(SUPPORTED_VENDORS); ++i) {
- if (vendor == SUPPORTED_VENDORS[i]) {
- type = SDL_CONTROLLER_TYPE_XBOXONE;
- break;
+ } else {
+ switch (GuessControllerType(vendor, product)) {
+ case k_eControllerType_XBox360Controller:
+ type = SDL_CONTROLLER_TYPE_XBOX360;
+ break;
+ case k_eControllerType_XBoxOneController:
+ type = SDL_CONTROLLER_TYPE_XBOXONE;
+ break;
+ case k_eControllerType_PS3Controller:
+ type = SDL_CONTROLLER_TYPE_PS3;
+ break;
+ case k_eControllerType_PS4Controller:
+ type = SDL_CONTROLLER_TYPE_PS4;
+ break;
+ case k_eControllerType_PS5Controller:
+ type = SDL_CONTROLLER_TYPE_PS5;
+ break;
+ case k_eControllerType_XInputPS4Controller:
+ if (forUI) {
+ type = SDL_CONTROLLER_TYPE_PS4;
+ } else {
+ type = SDL_CONTROLLER_TYPE_UNKNOWN;
}
- }
- }
-
- if (type == SDL_CONTROLLER_TYPE_UNKNOWN) {
- if (vendor == 0x0000 && product == 0x0000) {
- /* Some devices are only identifiable by their name */
- if (name &&
- (SDL_strcmp(name, "Lic Pro Controller") == 0 ||
- SDL_strcmp(name, "Nintendo Wireless Gamepad") == 0 ||
- SDL_strcmp(name, "Wireless Gamepad") == 0)) {
- /* HORI or PowerA Switch Pro Controller clone */
+ break;
+ case k_eControllerType_SwitchProController:
+ case k_eControllerType_SwitchInputOnlyController:
+ type = SDL_CONTROLLER_TYPE_NINTENDO_SWITCH_PRO;
+ break;
+ case k_eControllerType_XInputSwitchController:
+ if (forUI) {
type = SDL_CONTROLLER_TYPE_NINTENDO_SWITCH_PRO;
- } else if (name && SDL_strcmp(name, "Virtual Joystick") == 0) {
- type = SDL_CONTROLLER_TYPE_VIRTUAL;
} else {
type = SDL_CONTROLLER_TYPE_UNKNOWN;
}
-
- } else if (vendor == 0x0001 && product == 0x0001) {
- type = SDL_CONTROLLER_TYPE_UNKNOWN;
-
- } else if (vendor == USB_VENDOR_MICROSOFT && product == USB_PRODUCT_XBOX_ONE_XINPUT_CONTROLLER) {
- type = SDL_CONTROLLER_TYPE_XBOXONE;
-
- } 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 if (vendor == USB_VENDOR_NINTENDO && product == USB_PRODUCT_NINTENDO_SWITCH_JOY_CON_GRIP) {
- type = SDL_GetHintBoolean(SDL_HINT_JOYSTICK_HIDAPI_JOY_CONS, SDL_FALSE) ? SDL_CONTROLLER_TYPE_NINTENDO_SWITCH_PRO : SDL_CONTROLLER_TYPE_UNKNOWN;
-
- } else {
- switch (GuessControllerType(vendor, product)) {
- case k_eControllerType_XBox360Controller:
- type = SDL_CONTROLLER_TYPE_XBOX360;
- break;
- case k_eControllerType_XBoxOneController:
- type = SDL_CONTROLLER_TYPE_XBOXONE;
- break;
- case k_eControllerType_PS3Controller:
- type = SDL_CONTROLLER_TYPE_PS3;
- break;
- case k_eControllerType_PS4Controller:
- type = SDL_CONTROLLER_TYPE_PS4;
- break;
- case k_eControllerType_PS5Controller:
- type = SDL_CONTROLLER_TYPE_PS5;
- break;
- case k_eControllerType_SwitchProController:
- case k_eControllerType_SwitchInputOnlyController:
+ break;
+ case k_eControllerType_SwitchJoyConLeft:
+ case k_eControllerType_SwitchJoyConRight:
+ /* We always support the Nintendo Online NES Controllers */
+ if (name && SDL_strncmp(name, "NES Controller", 14) == 0) {
type = SDL_CONTROLLER_TYPE_NINTENDO_SWITCH_PRO;
- break;
- case k_eControllerType_SwitchJoyConLeft:
- case k_eControllerType_SwitchJoyConRight:
- /* We always support the Nintendo Online NES Controllers */
- if (name && SDL_strncmp(name, "NES Controller", 14) == 0) {
- return SDL_CONTROLLER_TYPE_NINTENDO_SWITCH_PRO;
- }
+ } else {
type = SDL_GetHintBoolean(SDL_HINT_JOYSTICK_HIDAPI_JOY_CONS, SDL_FALSE) ? SDL_CONTROLLER_TYPE_NINTENDO_SWITCH_PRO : SDL_CONTROLLER_TYPE_UNKNOWN;
- break;
- default:
- type = SDL_CONTROLLER_TYPE_UNKNOWN;
- break;
}
+ break;
+ default:
+ break;
+ }
+ }
+ return type;
+}
+
+SDL_GameControllerType
+SDL_GetJoystickGameControllerTypeFromGUID(SDL_JoystickGUID guid, const char *name)
+{
+ SDL_GameControllerType type;
+ Uint16 vendor, product;
+
+ SDL_GetJoystickGUIDInfo(guid, &vendor, &product, NULL);
+ type = SDL_GetJoystickGameControllerTypeFromVIDPID(vendor, product, name, SDL_TRUE);
+ if (type == SDL_CONTROLLER_TYPE_UNKNOWN) {
+ if (SDL_IsJoystickXInput(guid)) {
+ /* This is probably an Xbox One controller */
+ return SDL_CONTROLLER_TYPE_XBOXONE;
+ }
+ if (SDL_IsJoystickVirtual(guid)) {
+ return SDL_CONTROLLER_TYPE_VIRTUAL;
}
}
return type;
@@ -2580,7 +2536,7 @@ SDL_bool SDL_ShouldIgnoreJoystick(const char *name, SDL_JoystickGUID guid)
}
}
- type = SDL_GetJoystickGameControllerType(name, vendor, product, -1, 0, 0, 0);
+ type = SDL_GetJoystickGameControllerTypeFromVIDPID(vendor, product, name, SDL_FALSE);
if ((type == SDL_CONTROLLER_TYPE_PS4 || type == SDL_CONTROLLER_TYPE_PS5) && SDL_IsPS4RemapperRunning()) {
return SDL_TRUE;
}
diff --git a/src/joystick/SDL_joystick_c.h b/src/joystick/SDL_joystick_c.h
index d6f3888..a52167d 100644
--- a/src/joystick/SDL_joystick_c.h
+++ b/src/joystick/SDL_joystick_c.h
@@ -58,9 +58,8 @@ extern void SDL_GetJoystickGUIDInfo(SDL_JoystickGUID guid, Uint16 *vendor, Uint1
extern char *SDL_CreateJoystickName(Uint16 vendor, Uint16 product, const char *vendor_name, const char *product_name);
/* Function to return the type of a controller */
-extern SDL_GameControllerType SDL_GetJoystickGameControllerTypeFromVIDPID(Uint16 vendor, Uint16 product);
+extern SDL_GameControllerType SDL_GetJoystickGameControllerTypeFromVIDPID(Uint16 vendor, Uint16 product, const char *name, SDL_bool forUI);
extern SDL_GameControllerType SDL_GetJoystickGameControllerTypeFromGUID(SDL_JoystickGUID guid, const char *name);
-extern SDL_GameControllerType SDL_GetJoystickGameControllerType(const char *name, Uint16 vendor, Uint16 product, int interface_number, int interface_class, int interface_subclass, int interface_protocol);
/* Function to return whether a joystick is an Xbox One controller */
extern SDL_bool SDL_IsJoystickXboxOne(Uint16 vendor_id, Uint16 product_id);
diff --git a/src/joystick/controller_type.c b/src/joystick/controller_type.c
index 481fb41..36b024b 100644
--- a/src/joystick/controller_type.c
+++ b/src/joystick/controller_type.c
@@ -277,8 +277,8 @@ static const ControllerDescription_t arrControllers[] = {
{ MAKE_CONTROLLER_ID( 0x24c6, 0xfafc ), k_eControllerType_XBox360Controller, NULL }, // Afterglow Gamepad 1
{ MAKE_CONTROLLER_ID( 0x24c6, 0xfafd ), k_eControllerType_XBox360Controller, NULL }, // Afterglow Gamepad 3
{ MAKE_CONTROLLER_ID( 0x24c6, 0xfafe ), k_eControllerType_XBox360Controller, NULL }, // Rock Candy Gamepad for Xbox 360
- { MAKE_CONTROLLER_ID( 0x2c22, 0x2303 ), k_eControllerType_XBox360Controller, "Qanba Obsidian Arcade Joystick" }, // Qanba Obsidian Arcade Joystick
- { MAKE_CONTROLLER_ID( 0x2c22, 0x2503 ), k_eControllerType_XBox360Controller, "Qanba Dragon Arcade Joystick" }, // Qanba Dragon Arcade Joystick
+ { MAKE_CONTROLLER_ID( 0x2c22, 0x2303 ), k_eControllerType_XInputPS4Controller, "Qanba Obsidian Arcade Joystick" }, // Qanba Obsidian Arcade Joystick
+ { MAKE_CONTROLLER_ID( 0x2c22, 0x2503 ), k_eControllerType_XInputPS4Controller, "Qanba Dragon Arcade Joystick" }, // Qanba Dragon Arcade Joystick
{ MAKE_CONTROLLER_ID( 0x045e, 0x02d1 ), k_eControllerType_XBoxOneController, "Xbox One Controller" }, // Microsoft X-Box One pad
{ MAKE_CONTROLLER_ID( 0x045e, 0x02dd ), k_eControllerType_XBoxOneController, "Xbox One Controller" }, // Microsoft X-Box One pad (Firmware 2015)
diff --git a/src/joystick/controller_type.h b/src/joystick/controller_type.h
index 2fbeed7..9ec6c57 100644
--- a/src/joystick/controller_type.h
+++ b/src/joystick/controller_type.h
@@ -53,8 +53,9 @@ typedef enum
k_eControllerType_SwitchJoyConPair = 41,
k_eControllerType_SwitchInputOnlyController = 42,
k_eControllerType_MobileTouch = 43,
- k_eControllerType_XInputSwitchController = 44, // Client-side only, used to mark Switch-compatible controllers as not supporting Switch controller protocol
+ k_eControllerType_XInputSwitchController = 44, // Client-side only, used to mark Nintendo Switch style controllers as using XInput instead of the Nintendo Switch protocol
k_eControllerType_PS5Controller = 45,
+ k_eControllerType_XInputPS4Controller = 46, // Client-side only, used to mark DualShock 4 style controllers using XInput instead of the DualShock 4 controller protocol
k_eControllerType_LastController, // Don't add game controllers below this enumeration - this enumeration can change value
// Keyboards and Mice
diff --git a/src/joystick/hidapi/SDL_hidapijoystick.c b/src/joystick/hidapi/SDL_hidapijoystick.c
index 0c5dc1e..38164b0 100644
--- a/src/joystick/hidapi/SDL_hidapijoystick.c
+++ b/src/joystick/hidapi/SDL_hidapijoystick.c
@@ -110,11 +110,96 @@ HIDAPI_RemapVal(float val, float val_min, float val_max, float output_min, float
static void HIDAPI_JoystickDetect(void);
static void HIDAPI_JoystickClose(SDL_Joystick *joystick);
+static SDL_GameControllerType
+SDL_GetJoystickGameControllerProtocol(const char *name, Uint16 vendor, Uint16 product, int interface_number, int interface_class, int interface_subclass, int interface_protocol)
+{
+ static const int LIBUSB_CLASS_VENDOR_SPEC = 0xFF;
+ static const int XB360_IFACE_SUBCLASS = 93;
+ static const int XB360_IFACE_PROTOCOL = 1; /* Wired */
+ static const int XB360W_IFACE_PROTOCOL = 129; /* Wireless */
+ static const int XBONE_IFACE_SUBCLASS = 71;
+ static const int XBONE_IFACE_PROTOCOL = 208;
+
+ SDL_GameControllerType type = SDL_CONTROLLER_TYPE_UNKNOWN;
+
+ /* This code should match the checks in libusb/hid.c and HIDDeviceManager.java */
+ if (interface_class == LIBUSB_CLASS_VENDOR_SPEC &&
+ interface_subclass == XB360_IFACE_SUBCLASS &&
+ (interface_protocol == XB360_IFACE_PROTOCOL ||
+ interface_protocol == XB360W_IFACE_PROTOCOL)) {
+
+ static const int SUPPORTED_VENDORS[] = {
+ 0x0079, /* GPD Win 2 */
+ 0x044f, /* Thrustmaster */
+ 0x045e, /* Microsoft */
+ 0x046d, /* Logitech */
+ 0x056e, /* Elecom */
+ 0x06a3, /* Saitek */
+ 0x0738, /* Mad Catz */
+ 0x07ff, /* Mad Catz */
+ 0x0e6f, /* PDP */
+ 0x0f0d, /* Hori */
+ 0x1038, /* SteelSeries */
+ 0x11c9, /* Nacon */
+ 0x12ab, /* Unknown */
+ 0x1430, /* RedOctane */
+ 0x146b, /* BigBen */
+ 0x1532, /* Razer */
+ 0x15e4, /* Numark */
+ 0x162e, /* Joytech */
+ 0x1689, /* Razer Onza */
+ 0x1949, /* Lab126, Inc. */
+ 0x1bad, /* Harmonix */
+ 0x20d6, /* PowerA */
+ 0x24c6, /* PowerA */
+ 0x2c22, /* Qanba */
+ };
+
+ int i;
+ for (i = 0; i < SDL_arraysize(SUPPORTED_VENDORS); ++i) {
+ if (vendor == SUPPORTED_VENDORS[i]) {
+ type = SDL_CONTROLLER_TYPE_XBOX360;
+ break;
+ }
+ }
+ }
+
+ if (interface_number == 0 &&
+ interface_class == LIBUSB_CLASS_VENDOR_SPEC &&
+ interface_subclass == XBONE_IFACE_SUBCLASS &&
+ interface_protocol == XBONE_IFACE_PROTOCOL) {
+
+ static const int SUPPORTED_VENDORS[] = {
+ 0x045e, /* Microsoft */
+ 0x0738, /* Mad Catz */
+ 0x0e6f, /* PDP */
+ 0x0f0d, /* Hori */
+ 0x1532, /* Razer */
+ 0x20d6, /* PowerA */
+ 0x24c6, /* PowerA */
+ 0x2e24, /* Hyperkin */
+ };
+
+ int i;
+ for (i = 0; i < SDL_arraysize(SUPPORTED_VENDORS); ++i) {
+ if (vendor == SUPPORTED_VENDORS[i]) {
+ type = SDL_CONTROLLER_TYPE_XBOXONE;
+ break;
+ }
+ }
+ }
+
+ if (type == SDL_CONTROLLER_TYPE_UNKNOWN) {
+ type = SDL_GetJoystickGameControllerTypeFromVIDPID(vendor, product, name, SDL_FALSE);
+ }
+ return type;
+}
+
static SDL_bool
HIDAPI_IsDeviceSupported(Uint16 vendor_id, Uint16 product_id, Uint16 version, const char *name)
{
int i;
- SDL_GameControllerType type = SDL_GetJoystickGameControllerType(name, vendor_id, product_id, -1, 0, 0, 0);
+ SDL_GameControllerType type = SDL_GetJoystickGameControllerProtocol(name, vendor_id, product_id, -1, 0, 0, 0);
for (i = 0; i < SDL_arraysize(SDL_HIDAPI_drivers); ++i) {
SDL_HIDAPI_DeviceDriver *driver = SDL_HIDAPI_drivers[i];
@@ -148,7 +233,7 @@ HIDAPI_GetDeviceDriver(SDL_HIDAPI_Device *device)
}
}
- type = SDL_GetJoystickGameControllerType(device->name, device->vendor_id, device->product_id, device->interface_number, device->interface_class, device->interface_subclass, device->interface_protocol);
+ type = SDL_GetJoystickGameControllerProtocol(device->name, device->vendor_id, device->product_id, device->interface_number, device->interface_class, device->interface_subclass, device->interface_protocol);
for (i = 0; i < SDL_arraysize(SDL_HIDAPI_drivers); ++i) {
SDL_HIDAPI_DeviceDriver *driver = SDL_HIDAPI_drivers[i];
if (driver->enabled && driver->IsSupportedDevice(device->name, type, device->vendor_id, device->product_id, device->version, device->interface_number, device->interface_class, device->interface_subclass, device->interface_protocol)) {
@@ -457,38 +542,6 @@ HIDAPI_AddDevice(struct SDL_hid_device_info *info)
char *serial_number = HIDAPI_ConvertString(info->serial_number);
device->name = SDL_CreateJoystickName(device->vendor_id, device->product_id, manufacturer_string, product_string);
- if (SDL_strncmp(device->name, "0x", 2) == 0) {
- /* Couldn't find a controller name, try to give it one based on device type */
- const char *name = NULL;
-
- switch (SDL_GetJoystickGameControllerType(NULL, device->vendor_id, device->product_id, device->interface_number, device->interface_class, device->interface_subclass, device->interface_protocol)) {
- case SDL_CONTROLLER_TYPE_XBOX360:
- name = "Xbox 360 Controller";
- break;
- case SDL_CONTROLLER_TYPE_XBOXONE:
- name = "Xbox One Controller";
- break;
- case SDL_CONTROLLER_TYPE_PS3:
- name = "PS3 Controller";
- break;
- case SDL_CONTROLLER_TYPE_PS4:
- name = "PS4 Controller";
- break;
- case SDL_CONTROLLER_TYPE_PS5:
- name = "PS5 Controller";
- break;
- case SDL_CONTROLLER_TYPE_NINTENDO_SWITCH_PRO:
- name = "Nintendo Switch Pro Controller";
- break;
- default:
- break;
- }
-
- if (name) {
- SDL_free(device->name);
- device->name = SDL_strdup(name);
- }
- }
if (manufacturer_string) {
SDL_free(manufacturer_string);
@@ -621,13 +674,13 @@ HIDAPI_IsEquivalentToDevice(Uint16 vendor_id, Uint16 product_id, SDL_HIDAPI_Devi
/* If we're looking for the raw input Xbox One controller, match it against any other Xbox One controller */
if (product_id == USB_PRODUCT_XBOX_ONE_XBOXGIP_CONTROLLER &&
- SDL_GetJoystickGameControllerType(device->name, device->vendor_id, device->product_id, device->interface_number, device->interface_class, device->interface_subclass, device->interface_protocol) == SDL_CONTROLLER_TYPE_XBOXONE) {
+ SDL_GetJoystickGameControllerProtocol(device->name, device->vendor_id, device->product_id, device->interface_number, device->interface_class, device->interface_subclass, device->interface_protocol) == SDL_CONTROLLER_TYPE_XBOXONE) {
return SDL_TRUE;
}
/* If we're looking for an XInput controller, match it against any other Xbox controller */
if (product_id == USB_PRODUCT_XBOX_ONE_XINPUT_CONTROLLER) {
- SDL_GameControllerType type = SDL_GetJoystickGameControllerType(device->name, device->vendor_id, device->product_id, device->interface_number, device->interface_class, device->interface_subclass, device->interface_protocol);
+ SDL_GameControllerType type = SDL_GetJoystickGameControllerProtocol(device->name, device->vendor_id, device->product_id, device->interface_number, device->interface_class, device->interface_subclass, device->interface_protocol);
if (type == SDL_CONTROLLER_TYPE_XBOX360 || type == SDL_CONTROLLER_TYPE_XBOXONE) {
return SDL_TRUE;
}
@@ -656,7 +709,7 @@ HIDAPI_IsDeviceTypePresent(SDL_GameControllerType type)
device = SDL_HIDAPI_devices;
while (device) {
if (device->driver &&
- SDL_GetJoystickGameControllerType(device->name, device->vendor_id, device->product_id, device->interface_number, device->interface_class, device->interface_subclass, device->interface_protocol) == type) {
+ SDL_GetJoystickGameControllerProtocol(device->name, device->vendor_id, device->product_id, device->interface_number, device->interface_class, device->interface_subclass, device->interface_protocol) == type) {
result = SDL_TRUE;
break;
}
diff --git a/src/joystick/windows/SDL_dinputjoystick.c b/src/joystick/windows/SDL_dinputjoystick.c
index 7b4c23e..da35ebb 100644
--- a/src/joystick/windows/SDL_dinputjoystick.c
+++ b/src/joystick/windows/SDL_dinputjoystick.c
@@ -253,7 +253,7 @@ SDL_IsXInputDevice(Uint16 vendor_id, Uint16 product_id, const char* hidPath)
return SDL_TRUE;
}
- type = SDL_GetJoystickGameControllerType("", vendor_id, product_id, -1, 0, 0, 0);
+ type = SDL_GetJoystickGameControllerTypeFromVIDPID(vendor_id, product_id, NULL, SDL_FALSE);
if (type == SDL_CONTROLLER_TYPE_XBOX360 ||
type == SDL_CONTROLLER_TYPE_XBOXONE ||
(vendor_id == USB_VENDOR_VALVE && product_id == USB_PRODUCT_STEAM_VIRTUAL_GAMEPAD)) {