mirror of
https://github.com/libsdl-org/SDL.git
synced 2026-03-20 15:51:07 +01:00
Added SDL_HINT_HIDAPI_LIBUSB_GAMECUBE
Fixes https://github.com/libsdl-org/SDL/issues/14682
This commit is contained in:
@@ -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.
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user