Simple Directmedia Layer

SDL_ShouldIgnoreGamepad() should take product IDs rather than a guid.

This lets us early out when scanning for new hardware more quickly.

+42 -65
+4 -10
src/joystick/SDL_gamepad.c
··· 2595 2595 /* 2596 2596 * Return 1 if the gamepad should be ignored by SDL 2597 2597 */ 2598 - bool SDL_ShouldIgnoreGamepad(const char *name, SDL_GUID guid) 2598 + bool SDL_ShouldIgnoreGamepad(Uint16 vendor_id, Uint16 product_id, Uint16 version, const char *name) 2599 2599 { 2600 - Uint16 vendor; 2601 - Uint16 product; 2602 - Uint16 version; 2603 - 2604 2600 #ifdef SDL_PLATFORM_LINUX 2605 2601 if (SDL_endswith(name, " Motion Sensors")) { 2606 2602 // Don't treat the PS3 and PS4 motion controls as a separate gamepad ··· 2624 2620 return true; 2625 2621 } 2626 2622 2627 - SDL_GetJoystickGUIDInfo(guid, &vendor, &product, &version, NULL); 2628 - 2629 - if (SDL_IsJoystickSteamVirtualGamepad(vendor, product, version)) { 2623 + if (SDL_IsJoystickSteamVirtualGamepad(vendor_id, product_id, version)) { 2630 2624 return !SDL_GetHintBoolean("SDL_GAMECONTROLLER_ALLOW_STEAM_VIRTUAL_GAMEPAD", false); 2631 2625 } 2632 2626 2633 2627 if (SDL_allowed_gamepads.num_included_entries > 0) { 2634 - if (SDL_VIDPIDInList(vendor, product, &SDL_allowed_gamepads)) { 2628 + if (SDL_VIDPIDInList(vendor_id, product_id, &SDL_allowed_gamepads)) { 2635 2629 return false; 2636 2630 } 2637 2631 return true; 2638 2632 } else { 2639 - if (SDL_VIDPIDInList(vendor, product, &SDL_ignored_gamepads)) { 2633 + if (SDL_VIDPIDInList(vendor_id, product_id, &SDL_ignored_gamepads)) { 2640 2634 return true; 2641 2635 } 2642 2636 return false;
+1 -1
src/joystick/SDL_gamepad_c.h
··· 39 39 extern bool SDL_IsGamepadNameAndGUID(const char *name, SDL_GUID guid); 40 40 41 41 // Function to return whether a gamepad should be ignored 42 - extern bool SDL_ShouldIgnoreGamepad(const char *name, SDL_GUID guid); 42 + extern bool SDL_ShouldIgnoreGamepad(Uint16 vendor_id, Uint16 product_id, Uint16 version, const char *name); 43 43 44 44 // Handle delayed guide button on a gamepad 45 45 extern void SDL_GamepadHandleDelayedGuideButton(SDL_Joystick *joystick);
+4 -9
src/joystick/SDL_joystick.c
··· 3236 3236 return SDL_JOYSTICK_TYPE_UNKNOWN; 3237 3237 } 3238 3238 3239 - bool SDL_ShouldIgnoreJoystick(const char *name, SDL_GUID guid) 3239 + bool SDL_ShouldIgnoreJoystick(Uint16 vendor_id, Uint16 product_id, Uint16 version, const char *name) 3240 3240 { 3241 - Uint16 vendor; 3242 - Uint16 product; 3243 - 3244 - SDL_GetJoystickGUIDInfo(guid, &vendor, &product, NULL, NULL); 3245 - 3246 3241 // Check the joystick blacklist 3247 - if (SDL_VIDPIDInList(vendor, product, &blacklist_devices)) { 3242 + if (SDL_VIDPIDInList(vendor_id, product_id, &blacklist_devices)) { 3248 3243 return true; 3249 3244 } 3250 3245 if (!SDL_GetHintBoolean(SDL_HINT_JOYSTICK_ROG_CHAKRAM, false)) { 3251 - if (SDL_VIDPIDInList(vendor, product, &rog_gamepad_mice)) { 3246 + if (SDL_VIDPIDInList(vendor_id, product_id, &rog_gamepad_mice)) { 3252 3247 return true; 3253 3248 } 3254 3249 } 3255 3250 3256 - if (SDL_ShouldIgnoreGamepad(name, guid)) { 3251 + if (SDL_ShouldIgnoreGamepad(vendor_id, product_id, version, name)) { 3257 3252 return true; 3258 3253 } 3259 3254
+1 -1
src/joystick/SDL_joystick_c.h
··· 157 157 extern bool SDL_IsJoystickVIRTUAL(SDL_GUID guid); 158 158 159 159 // Function to return whether a joystick should be ignored 160 - extern bool SDL_ShouldIgnoreJoystick(const char *name, SDL_GUID guid); 160 + extern bool SDL_ShouldIgnoreJoystick(Uint16 vendor_id, Uint16 product_id, Uint16 version, const char *name); 161 161 162 162 // Internal event queueing functions 163 163 extern void SDL_PrivateJoystickAddTouchpad(SDL_Joystick *joystick, int nfingers);
+4 -4
src/joystick/apple/SDL_mfijoystick.m
··· 498 498 return false; 499 499 } 500 500 501 + if (SDL_ShouldIgnoreJoystick(vendor, product, 0, name)) { 502 + return false; 503 + } 504 + 501 505 #ifdef ENABLE_PHYSICAL_INPUT_PROFILE 502 506 if (@available(macOS 10.16, iOS 14.0, tvOS 14.0, *)) { 503 507 NSDictionary<NSString *, GCControllerElement *> *elements = controller.physicalInputProfile.elements; ··· 665 669 signature = device->button_mask; 666 670 } 667 671 device->guid = SDL_CreateJoystickGUID(SDL_HARDWARE_BUS_BLUETOOTH, vendor, product, signature, NULL, name, 'm', subtype); 668 - 669 - if (SDL_ShouldIgnoreJoystick(name, device->guid)) { 670 - return false; 671 - } 672 672 673 673 /* This will be set when the first button press of the controller is 674 674 * detected. */
+1 -1
src/joystick/bsd/SDL_bsdjoystick.c
··· 426 426 name = SDL_CreateJoystickName(di.udi_vendorNo, di.udi_productNo, di.udi_vendor, di.udi_product); 427 427 guid = SDL_CreateJoystickGUID(SDL_HARDWARE_BUS_USB, di.udi_vendorNo, di.udi_productNo, di.udi_releaseNo, di.udi_vendor, di.udi_product, 0, 0); 428 428 429 - if (SDL_ShouldIgnoreJoystick(name, guid) || 429 + if (SDL_ShouldIgnoreJoystick(di.udi_vendorNo, di.udi_productNo, di.udi_releaseNo, name) || 430 430 SDL_JoystickHandledByAnotherDriver(&SDL_BSD_JoystickDriver, di.udi_vendorNo, di.udi_productNo, di.udi_releaseNo, name)) { 431 431 SDL_free(name); 432 432 FreeHwData(hw);
+4 -5
src/joystick/darwin/SDL_iokitjoystick.c
··· 495 495 SDL_free(name); 496 496 } 497 497 498 + if (SDL_ShouldIgnoreJoystick(vendor, product, version, pDevice->product)) { 499 + return false; 500 + } 501 + 498 502 if (SDL_JoystickHandledByAnotherDriver(&SDL_DARWIN_JoystickDriver, vendor, product, version, pDevice->product)) { 499 503 return false; 500 504 } ··· 551 555 if (!GetDeviceInfo(ioHIDDeviceObject, device)) { 552 556 FreeDevice(device); 553 557 return; // not a device we care about, probably. 554 - } 555 - 556 - if (SDL_ShouldIgnoreJoystick(device->product, device->guid)) { 557 - FreeDevice(device); 558 - return; 559 558 } 560 559 561 560 // Get notified when this device is disconnected.
+1 -1
src/joystick/hidapi/SDL_hidapijoystick.c
··· 328 328 return &SDL_HIDAPI_DriverCombined; 329 329 } 330 330 331 - if (SDL_ShouldIgnoreJoystick(device->name, device->guid)) { 331 + if (SDL_ShouldIgnoreJoystick(device->vendor_id, device->product_id, device->version, device->name)) { 332 332 return NULL; 333 333 } 334 334
+2 -3
src/joystick/linux/SDL_sysjoystick.c
··· 329 329 SDL_Log("Joystick: %s, bustype = %d, vendor = 0x%.4x, product = 0x%.4x, version = %d\n", name, inpid.bustype, inpid.vendor, inpid.product, inpid.version); 330 330 #endif 331 331 332 - *guid = SDL_CreateJoystickGUID(inpid.bustype, inpid.vendor, inpid.product, inpid.version, NULL, product_string, 0, 0); 333 - 334 - if (SDL_ShouldIgnoreJoystick(name, *guid)) { 332 + if (SDL_ShouldIgnoreJoystick(inpid.vendor, inpid.product, inpid.version, name)) { 335 333 SDL_free(name); 336 334 return false; 337 335 } 338 336 *name_return = name; 339 337 *vendor_return = inpid.vendor; 340 338 *product_return = inpid.product; 339 + *guid = SDL_CreateJoystickGUID(inpid.bustype, inpid.vendor, inpid.product, inpid.version, NULL, product_string, 0, 0); 341 340 return true; 342 341 } 343 342
+2 -4
src/joystick/windows/SDL_dinputjoystick.c
··· 472 472 CHECK(QueryDeviceInfo(device, &vendor, &product)); 473 473 474 474 CHECK(!SDL_IsXInputDevice(vendor, product, hidPath)); 475 + CHECK(!SDL_ShouldIgnoreJoystick(vendor, product, version, name)); 476 + CHECK(!SDL_JoystickHandledByAnotherDriver(&SDL_WINDOWS_JoystickDriver, vendor, product, version, name)); 475 477 476 478 pNewJoystick = *(JoyStick_DeviceData **)pContext; 477 479 while (pNewJoystick) { ··· 513 515 } else { 514 516 pNewJoystick->guid = SDL_CreateJoystickGUID(SDL_HARDWARE_BUS_BLUETOOTH, vendor, product, version, NULL, name, 0, 0); 515 517 } 516 - 517 - CHECK(!SDL_ShouldIgnoreJoystick(pNewJoystick->joystickname, pNewJoystick->guid)); 518 - 519 - CHECK(!SDL_JoystickHandledByAnotherDriver(&SDL_WINDOWS_JoystickDriver, vendor, product, version, pNewJoystick->joystickname)); 520 518 521 519 WINDOWS_AddJoystickDevice(pNewJoystick); 522 520 pNewJoystick = NULL;
+2
src/joystick/windows/SDL_rawinputjoystick.c
··· 881 881 CHECK(GetRawInputDeviceInfoA(hDevice, RIDI_DEVICENAME, dev_name, &size) != (UINT)-1); 882 882 // Only take XInput-capable devices 883 883 CHECK(SDL_strstr(dev_name, "IG_") != NULL); 884 + CHECK(!SDL_ShouldIgnoreJoystick((Uint16)rdi.hid.dwVendorId, (Uint16)rdi.hid.dwProductId, (Uint16)rdi.hid.dwVersionNumber, "")); 884 885 CHECK(!SDL_JoystickHandledByAnotherDriver(&SDL_RAWINPUT_JoystickDriver, (Uint16)rdi.hid.dwVendorId, (Uint16)rdi.hid.dwProductId, (Uint16)rdi.hid.dwVersionNumber, "")); 886 + 885 887 device = (SDL_RAWINPUT_Device *)SDL_calloc(1, sizeof(SDL_RAWINPUT_Device)); 886 888 CHECK(device); 887 889 device->hDevice = hDevice;
+9 -14
src/joystick/windows/SDL_windows_gaming_input.c
··· 399 399 hr = __x_ABI_CWindows_CGaming_CInput_CIRawGameController_QueryInterface(e, &IID___x_ABI_CWindows_CGaming_CInput_CIRawGameController, (void **)&controller); 400 400 if (SUCCEEDED(hr)) { 401 401 char *name = NULL; 402 - SDL_GUID guid = { 0 }; 403 402 Uint16 bus = SDL_HARDWARE_BUS_USB; 404 403 Uint16 vendor = 0; 405 404 Uint16 product = 0; ··· 446 445 name = SDL_strdup(""); 447 446 } 448 447 448 + if (!ignore_joystick && SDL_ShouldIgnoreJoystick(vendor, product, version, name)) { 449 + ignore_joystick = true; 450 + } 451 + 449 452 if (!ignore_joystick && SDL_JoystickHandledByAnotherDriver(&SDL_WGI_JoystickDriver, vendor, product, version, name)) { 450 453 ignore_joystick = true; 451 454 } ··· 456 459 } 457 460 458 461 if (!ignore_joystick) { 459 - if (game_controller) { 460 - type = GetGameControllerType(game_controller); 461 - } 462 - 463 - guid = SDL_CreateJoystickGUID(bus, vendor, product, version, NULL, name, 'w', (Uint8)type); 464 - 465 - if (SDL_ShouldIgnoreJoystick(name, guid)) { 466 - ignore_joystick = true; 467 - } 468 - } 469 - 470 - if (!ignore_joystick) { 471 462 // New device, add it 472 463 WindowsGamingInputControllerState *controllers = SDL_realloc(wgi.controllers, sizeof(wgi.controllers[0]) * (wgi.controller_count + 1)); 473 464 if (controllers) { 474 465 WindowsGamingInputControllerState *state = &controllers[wgi.controller_count]; 475 466 SDL_JoystickID joystickID = SDL_GetNextObjectID(); 476 467 468 + if (game_controller) { 469 + type = GetGameControllerType(game_controller); 470 + } 471 + 477 472 SDL_zerop(state); 478 473 state->instance_id = joystickID; 479 474 state->controller = controller; 480 475 state->name = name; 481 - state->guid = guid; 476 + state->guid = SDL_CreateJoystickGUID(bus, vendor, product, version, NULL, name, 'w', (Uint8)type); 482 477 state->type = type; 483 478 state->steam_virtual_gamepad_slot = GetSteamVirtualGamepadSlot(controller, vendor, product); 484 479
+7 -12
src/joystick/windows/SDL_xinputjoystick.c
··· 185 185 pNewJoystick = pNewJoystick->pNext; 186 186 } 187 187 188 + name = GetXInputName(userid, SubType); 189 + GetXInputDeviceInfo(userid, &vendor, &product, &version); 190 + if (SDL_ShouldIgnoreJoystick(vendor, product, version, name) || 191 + SDL_JoystickHandledByAnotherDriver(&SDL_WINDOWS_JoystickDriver, vendor, product, version, name)) { 192 + return; 193 + } 194 + 188 195 pNewJoystick = (JoyStick_DeviceData *)SDL_calloc(1, sizeof(JoyStick_DeviceData)); 189 196 if (!pNewJoystick) { 190 197 return; // better luck next time? 191 198 } 192 199 193 - name = GetXInputName(userid, SubType); 194 - GetXInputDeviceInfo(userid, &vendor, &product, &version); 195 200 pNewJoystick->bXInputDevice = true; 196 201 pNewJoystick->joystickname = SDL_CreateJoystickName(vendor, product, NULL, name); 197 202 if (!pNewJoystick->joystickname) { ··· 202 207 pNewJoystick->guid = SDL_CreateJoystickGUID(SDL_HARDWARE_BUS_USB, vendor, product, version, NULL, name, 'x', SubType); 203 208 pNewJoystick->SubType = SubType; 204 209 pNewJoystick->XInputUserId = userid; 205 - 206 - if (SDL_ShouldIgnoreJoystick(pNewJoystick->joystickname, pNewJoystick->guid)) { 207 - SDL_free(pNewJoystick); 208 - return; 209 - } 210 - 211 - if (SDL_JoystickHandledByAnotherDriver(&SDL_WINDOWS_JoystickDriver, vendor, product, version, pNewJoystick->joystickname)) { 212 - SDL_free(pNewJoystick); 213 - return; 214 - } 215 210 216 211 WINDOWS_AddJoystickDevice(pNewJoystick); 217 212 }