Added SDL_HINT_HIDAPI_LIBUSB, SDL_HINT_HIDAPI_LIBUSB_WHITELIST, and SDL_HINT_HIDAPI_UDEV

This commit is contained in:
Sam Lantinga 2024-08-03 11:42:06 -07:00
parent 8a5b9559dc
commit 0da346f129
4 changed files with 59 additions and 11 deletions

View File

@ -812,6 +812,8 @@ The following environment variables have been removed:
* SDL_DISKAUDIOFILE - replaced with the hint SDL_HINT_AUDIO_DISK_OUTPUT_FILE
* SDL_DISKAUDIOFILEIN - replaced with the hint SDL_HINT_AUDIO_DISK_INPUT_FILE
* SDL_DUMMYAUDIODELAY - replaced with the hint SDL_HINT_AUDIO_DUMMY_TIMESCALE which allows scaling the audio time rather than specifying an absolute delay.
* SDL_HIDAPI_DISABLE_LIBUSB - replaced with the hint SDL_HINT_HIDAPI_LIBUSB
* SDL_HIDAPI_JOYSTICK_DISABLE_UDEV - replaced with the hint SDL_HINT_HIDAPI_UDEV
* VITA_DISABLE_TOUCH_BACK - replaced with the hint SDL_HINT_VITA_ENABLE_BACK_TOUCH
* VITA_DISABLE_TOUCH_FRONT - replaced with the hint SDL_HINT_VITA_ENABLE_FRONT_TOUCH
* VITA_MODULE_PATH - replaced with the hint SDL_HINT_VITA_MODULE_PATH

View File

@ -930,6 +930,52 @@ extern "C" {
*/
#define SDL_HINT_GDK_TEXTINPUT_TITLE "SDL_GDK_TEXTINPUT_TITLE"
/**
* A variable to control whether HIDAPI uses libusb for device access.
*
* By default libusb will only be used for a few devices that require direct USB access, and this can be controlled with SDL_HINT_HIDAPI_LIBUSB_WHITELIST.
*
* The variable can be set to the following values:
*
* - "0": HIDAPI will not use libusb for device access.
* - "1": HIDAPI will use libusb for device access if available. (default)
*
* This hint should be set before SDL is initialized.
*
* \since This hint is available since SDL 3.0.0.
*/
#define SDL_HINT_HIDAPI_LIBUSB "SDL_HIDAPI_LIBUSB"
/**
* A variable to control whether HIDAPI uses libusb only for whitelisted devices.
*
* By default libusb will only be used for a few devices that require direct USB access.
*
* The variable can be set to the following values:
*
* - "0": HIDAPI will use libusb for all device access.
* - "1": HIDAPI will use libusb only for whitelisted devices. (default)
*
* This hint should be set before SDL is initialized.
*
* \since This hint is available since SDL 3.0.0.
*/
#define SDL_HINT_HIDAPI_LIBUSB_WHITELIST "SDL_HIDAPI_LIBUSB_WHITELIST"
/**
* A variable to control whether HIDAPI uses udev for device detection.
*
* The variable can be set to the following values:
*
* - "0": HIDAPI will poll for device changes.
* - "1": HIDAPI will use udev for device detection. (default)
*
* This hint should be set before SDL is initialized.
*
* \since This hint is available since SDL 3.0.0.
*/
#define SDL_HINT_HIDAPI_UDEV "SDL_HIDAPI_UDEV"
/**
* A variable to control whether SDL_hid_enumerate() enumerates all HID
* devices or only controllers.

View File

@ -909,13 +909,13 @@ static SDL_bool IsInWhitelist(Uint16 vendor, Uint16 product)
#if defined(HAVE_PLATFORM_BACKEND) || defined(HAVE_DRIVER_BACKEND)
/* We have another way to get HID devices, so use the whitelist to get devices where libusb is preferred */
#define SDL_HIDAPI_LIBUSB_WHITELIST_DEFAULT SDL_TRUE
#define SDL_HINT_HIDAPI_LIBUSB_WHITELIST_DEFAULT SDL_TRUE
#else
/* libusb is the only way to get HID devices, so don't use the whitelist, get them all */
#define SDL_HIDAPI_LIBUSB_WHITELIST_DEFAULT SDL_FALSE
#define SDL_HINT_HIDAPI_LIBUSB_WHITELIST_DEFAULT SDL_FALSE
#endif /* HAVE_PLATFORM_BACKEND || HAVE_DRIVER_BACKEND */
static SDL_bool use_libusb_whitelist = SDL_HIDAPI_LIBUSB_WHITELIST_DEFAULT;
static SDL_bool use_libusb_whitelist = SDL_HINT_HIDAPI_LIBUSB_WHITELIST_DEFAULT;
/* Shared HIDAPI Implementation */
@ -1140,9 +1140,9 @@ int SDL_hid_init(void)
SDL_AddHintCallback(SDL_HINT_HIDAPI_IGNORE_DEVICES, IgnoredDevicesChanged, NULL);
#ifdef SDL_USE_LIBUDEV
if (SDL_getenv("SDL_HIDAPI_JOYSTICK_DISABLE_UDEV") != NULL) {
if (!SDL_GetHintBoolean(SDL_HINT_HIDAPI_UDEV, SDL_TRUE)) {
SDL_LogDebug(SDL_LOG_CATEGORY_INPUT,
"udev disabled by SDL_HIDAPI_JOYSTICK_DISABLE_UDEV");
"udev disabled by SDL_HINT_HIDAPI_UDEV");
linux_enumeration_method = ENUMERATION_FALLBACK;
} else if (SDL_DetectSandbox() != SDL_SANDBOX_NONE) {
SDL_LogDebug(SDL_LOG_CATEGORY_INPUT,
@ -1155,12 +1155,12 @@ int SDL_hid_init(void)
}
#endif
use_libusb_whitelist = SDL_GetHintBoolean("SDL_HIDAPI_LIBUSB_WHITELIST",
SDL_HIDAPI_LIBUSB_WHITELIST_DEFAULT);
use_libusb_whitelist = SDL_GetHintBoolean(SDL_HINT_HIDAPI_LIBUSB_WHITELIST,
SDL_HINT_HIDAPI_LIBUSB_WHITELIST_DEFAULT);
#ifdef HAVE_LIBUSB
if (SDL_getenv("SDL_HIDAPI_DISABLE_LIBUSB") != NULL) {
if (!SDL_GetHintBoolean(SDL_HINT_HIDAPI_LIBUSB, SDL_TRUE)) {
SDL_LogDebug(SDL_LOG_CATEGORY_INPUT,
"libusb disabled by SDL_HIDAPI_DISABLE_LIBUSB");
"libusb disabled with SDL_HINT_HIDAPI_LIBUSB");
libusb_ctx.libhandle = NULL;
} else {
++attempts;

View File

@ -579,9 +579,9 @@ static int HIDAPI_JoystickInit(void)
#ifdef SDL_USE_LIBUDEV
if (linux_enumeration_method == ENUMERATION_UNSET) {
if (SDL_getenv("SDL_HIDAPI_JOYSTICK_DISABLE_UDEV") != NULL) {
if (!SDL_GetHintBoolean(SDL_HINT_HIDAPI_UDEV, SDL_TRUE)) {
SDL_LogDebug(SDL_LOG_CATEGORY_INPUT,
"udev disabled by SDL_HIDAPI_JOYSTICK_DISABLE_UDEV");
"udev disabled by SDL_HINT_HIDAPI_UDEV");
linux_enumeration_method = ENUMERATION_FALLBACK;
} else if (SDL_DetectSandbox() != SDL_SANDBOX_NONE) {
SDL_LogDebug(SDL_LOG_CATEGORY_INPUT,