mirror of
https://github.com/libsdl-org/SDL.git
synced 2026-06-02 23:57:45 +08: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"
|
#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
|
* A variable to control whether HIDAPI uses libusb only for whitelisted
|
||||||
* devices.
|
* devices.
|
||||||
|
|||||||
+10
-1
@@ -32,6 +32,7 @@
|
|||||||
|
|
||||||
#include "SDL_hidapi_c.h"
|
#include "SDL_hidapi_c.h"
|
||||||
#include "../joystick/usb_ids.h"
|
#include "../joystick/usb_ids.h"
|
||||||
|
#include "../joystick/SDL_joystick_c.h"
|
||||||
#include "../SDL_hints_c.h"
|
#include "../SDL_hints_c.h"
|
||||||
|
|
||||||
// Initial type declarations
|
// Initial type declarations
|
||||||
@@ -875,6 +876,7 @@ static bool IsInWhitelist(Uint16 vendor, Uint16 product)
|
|||||||
#endif // HAVE_PLATFORM_BACKEND || HAVE_DRIVER_BACKEND
|
#endif // HAVE_PLATFORM_BACKEND || HAVE_DRIVER_BACKEND
|
||||||
|
|
||||||
static bool use_libusb_whitelist = SDL_HINT_HIDAPI_LIBUSB_WHITELIST_DEFAULT;
|
static bool use_libusb_whitelist = SDL_HINT_HIDAPI_LIBUSB_WHITELIST_DEFAULT;
|
||||||
|
static bool use_libusb_gamecube = true;
|
||||||
|
|
||||||
// Shared HIDAPI Implementation
|
// Shared HIDAPI Implementation
|
||||||
|
|
||||||
@@ -1052,9 +1054,15 @@ 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)
|
bool SDL_HIDAPI_ShouldIgnoreDevice(int bus, Uint16 vendor_id, Uint16 product_id, Uint16 usage_page, Uint16 usage, bool libusb)
|
||||||
{
|
{
|
||||||
#ifdef HAVE_LIBUSB
|
#ifdef HAVE_LIBUSB
|
||||||
if (libusb && use_libusb_whitelist && !IsInWhitelist(vendor_id, product_id)) {
|
if (libusb) {
|
||||||
|
if (use_libusb_whitelist && !IsInWhitelist(vendor_id, product_id)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
if (!use_libusb_gamecube &&
|
||||||
|
vendor_id == USB_VENDOR_NINTENDO && product_id == USB_PRODUCT_NINTENDO_GAMECUBE_ADAPTER) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// See if there are any devices we should skip in enumeration
|
// See if there are any devices we should skip in enumeration
|
||||||
@@ -1132,6 +1140,7 @@ int SDL_hid_init(void)
|
|||||||
|
|
||||||
use_libusb_whitelist = SDL_GetHintBoolean(SDL_HINT_HIDAPI_LIBUSB_WHITELIST,
|
use_libusb_whitelist = SDL_GetHintBoolean(SDL_HINT_HIDAPI_LIBUSB_WHITELIST,
|
||||||
SDL_HINT_HIDAPI_LIBUSB_WHITELIST_DEFAULT);
|
SDL_HINT_HIDAPI_LIBUSB_WHITELIST_DEFAULT);
|
||||||
|
use_libusb_gamecube = SDL_GetHintBoolean(SDL_HINT_HIDAPI_LIBUSB_GAMECUBE, true);
|
||||||
#ifdef HAVE_LIBUSB
|
#ifdef HAVE_LIBUSB
|
||||||
if (!SDL_GetHintBoolean(SDL_HINT_HIDAPI_LIBUSB, true)) {
|
if (!SDL_GetHintBoolean(SDL_HINT_HIDAPI_LIBUSB, true)) {
|
||||||
SDL_LogDebug(SDL_LOG_CATEGORY_INPUT,
|
SDL_LogDebug(SDL_LOG_CATEGORY_INPUT,
|
||||||
|
|||||||
Reference in New Issue
Block a user