Use SDL_GetHint() instead of SDL_getenv() for Linux joystick hints

This commit is contained in:
Sam Lantinga 2021-08-24 17:01:06 -07:00
parent 0ae2a9f8c3
commit cbccf5bb50
1 changed files with 9 additions and 7 deletions

View File

@ -627,14 +627,16 @@ LINUX_JoystickDetect(void)
static int static int
LINUX_JoystickInit(void) LINUX_JoystickInit(void)
{ {
const char *devices = SDL_GetHint("SDL_JOYSTICK_DEVICE");
#if SDL_USE_LIBUDEV #if SDL_USE_LIBUDEV
if (enumeration_method == ENUMERATION_UNSET) { if (enumeration_method == ENUMERATION_UNSET) {
if (SDL_getenv("SDL_JOYSTICK_DISABLE_UDEV") != NULL) { if (!SDL_GetHintBoolean("SDL_JOYSTICK_DISABLE_UDEV", SDL_FALSE)) {
SDL_LogDebug(SDL_LOG_CATEGORY_INPUT, SDL_LogDebug(SDL_LOG_CATEGORY_INPUT,
"udev disabled by SDL_JOYSTICK_DISABLE_UDEV"); "udev disabled by SDL_JOYSTICK_DISABLE_UDEV");
enumeration_method = ENUMERATION_FALLBACK; enumeration_method = ENUMERATION_FALLBACK;
}
else if (access("/.flatpak-info", F_OK) == 0 } else if (access("/.flatpak-info", F_OK) == 0
|| access("/run/host/container-manager", F_OK) == 0) { || access("/run/host/container-manager", F_OK) == 0) {
/* Explicitly check `/.flatpak-info` because, for old versions of /* Explicitly check `/.flatpak-info` because, for old versions of
* Flatpak, this was the only available way to tell if we were in * Flatpak, this was the only available way to tell if we were in
@ -642,8 +644,8 @@ LINUX_JoystickInit(void)
SDL_LogDebug(SDL_LOG_CATEGORY_INPUT, SDL_LogDebug(SDL_LOG_CATEGORY_INPUT,
"Container detected, disabling udev integration"); "Container detected, disabling udev integration");
enumeration_method = ENUMERATION_FALLBACK; enumeration_method = ENUMERATION_FALLBACK;
}
else { } else {
SDL_LogDebug(SDL_LOG_CATEGORY_INPUT, SDL_LogDebug(SDL_LOG_CATEGORY_INPUT,
"Using udev for joystick device discovery"); "Using udev for joystick device discovery");
enumeration_method = ENUMERATION_LIBUDEV; enumeration_method = ENUMERATION_LIBUDEV;
@ -652,9 +654,9 @@ LINUX_JoystickInit(void)
#endif #endif
/* First see if the user specified one or more joysticks to use */ /* First see if the user specified one or more joysticks to use */
if (SDL_getenv("SDL_JOYSTICK_DEVICE") != NULL) { if (devices != NULL) {
char *envcopy, *envpath, *delim; char *envcopy, *envpath, *delim;
envcopy = SDL_strdup(SDL_getenv("SDL_JOYSTICK_DEVICE")); envcopy = SDL_strdup(devices);
envpath = envcopy; envpath = envcopy;
while (envpath != NULL) { while (envpath != NULL) {
delim = SDL_strchr(envpath, ':'); delim = SDL_strchr(envpath, ':');