From 128b9260ec02f090b746fb1c28a0596dc96744d8 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Tue, 30 Dec 2025 14:14:51 -0800 Subject: [PATCH] Added SDL_HINT_HIDAPI_LIBUSB_GAMECUBE Fixes https://github.com/libsdl-org/SDL/issues/14682 --- include/SDL3/SDL_hints.h | 15 +++++++++++++++ src/hidapi/SDL_hidapi.c | 13 +++++++++++-- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/include/SDL3/SDL_hints.h b/include/SDL3/SDL_hints.h index d52a6de65d..474e97f049 100644 --- a/include/SDL3/SDL_hints.h +++ b/include/SDL3/SDL_hints.h @@ -1084,6 +1084,21 @@ extern "C" { */ #define SDL_HINT_HIDAPI_LIBUSB "SDL_HIDAPI_LIBUSB" + +/** + * A variable to control whether HIDAPI uses libusb for GameCube adapters. + * + * The variable can be set to the following values: + * + * - "0": HIDAPI will not use libusb for GameCube adapters. + * - "1": HIDAPI will use libusb for GameCube adapters if available. (default) + * + * This hint should be set before SDL is initialized. + * + * \since This hint is available since SDL 3.2.0. + */ +#define SDL_HINT_HIDAPI_LIBUSB_GAMECUBE "SDL_HIDAPI_LIBUSB_GAMECUBE" + /** * A variable to control whether HIDAPI uses libusb only for whitelisted * devices. diff --git a/src/hidapi/SDL_hidapi.c b/src/hidapi/SDL_hidapi.c index d008bb5ab0..f39e070579 100644 --- a/src/hidapi/SDL_hidapi.c +++ b/src/hidapi/SDL_hidapi.c @@ -32,6 +32,7 @@ #include "SDL_hidapi_c.h" #include "../joystick/usb_ids.h" +#include "../joystick/SDL_joystick_c.h" #include "../SDL_hints_c.h" // Initial type declarations @@ -875,6 +876,7 @@ static bool IsInWhitelist(Uint16 vendor, Uint16 product) #endif // HAVE_PLATFORM_BACKEND || HAVE_DRIVER_BACKEND static bool use_libusb_whitelist = SDL_HINT_HIDAPI_LIBUSB_WHITELIST_DEFAULT; +static bool use_libusb_gamecube = true; // Shared HIDAPI Implementation @@ -1052,8 +1054,14 @@ static void SDLCALL IgnoredDevicesChanged(void *userdata, const char *name, cons bool SDL_HIDAPI_ShouldIgnoreDevice(int bus, Uint16 vendor_id, Uint16 product_id, Uint16 usage_page, Uint16 usage, bool libusb) { #ifdef HAVE_LIBUSB - if (libusb && use_libusb_whitelist && !IsInWhitelist(vendor_id, product_id)) { - return true; + if (libusb) { + if (use_libusb_whitelist && !IsInWhitelist(vendor_id, product_id)) { + return true; + } + if (!use_libusb_gamecube && + vendor_id == USB_VENDOR_NINTENDO && product_id == USB_PRODUCT_NINTENDO_GAMECUBE_ADAPTER) { + return true; + } } #endif @@ -1132,6 +1140,7 @@ int SDL_hid_init(void) use_libusb_whitelist = SDL_GetHintBoolean(SDL_HINT_HIDAPI_LIBUSB_WHITELIST, SDL_HINT_HIDAPI_LIBUSB_WHITELIST_DEFAULT); + use_libusb_gamecube = SDL_GetHintBoolean(SDL_HINT_HIDAPI_LIBUSB_GAMECUBE, true); #ifdef HAVE_LIBUSB if (!SDL_GetHintBoolean(SDL_HINT_HIDAPI_LIBUSB, true)) { SDL_LogDebug(SDL_LOG_CATEGORY_INPUT,