From 67c4b996399e64e03ba50f8cb58b894497d7fc9f Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Wed, 15 Dec 2021 10:39:42 -0800
Subject: [PATCH] Fixed enabling udev hotplug detection on Linux
---
src/hidapi/SDL_hidapi.c | 20 ++++++++++++++++++++
1 file changed, 20 insertions(+)
diff --git a/src/hidapi/SDL_hidapi.c b/src/hidapi/SDL_hidapi.c
index a725c58fe1c..6e96c387b91 100644
--- a/src/hidapi/SDL_hidapi.c
+++ b/src/hidapi/SDL_hidapi.c
@@ -1011,6 +1011,26 @@ int SDL_hid_init(void)
return 0;
}
+#if defined(SDL_USE_LIBUDEV)
+ if (SDL_getenv("SDL_HIDAPI_JOYSTICK_DISABLE_UDEV") != NULL) {
+ SDL_LogDebug(SDL_LOG_CATEGORY_INPUT,
+ "udev disabled by SDL_HIDAPI_JOYSTICK_DISABLE_UDEV");
+ linux_enumeration_method = ENUMERATION_FALLBACK;
+ } else if (access("/.flatpak-info", F_OK) == 0
+ || access("/run/host/container-manager", F_OK) == 0) {
+ /* Explicitly check `/.flatpak-info` because, for old versions of
+ * Flatpak, this was the only available way to tell if we were in
+ * a Flatpak container. */
+ SDL_LogDebug(SDL_LOG_CATEGORY_INPUT,
+ "Container detected, disabling HIDAPI udev integration");
+ linux_enumeration_method = ENUMERATION_FALLBACK;
+ } else {
+ SDL_LogDebug(SDL_LOG_CATEGORY_INPUT,
+ "Using udev for HIDAPI joystick device discovery");
+ linux_enumeration_method = ENUMERATION_LIBUDEV;
+ }
+#endif
+
#ifdef SDL_LIBUSB_DYNAMIC
++attempts;
libusb_ctx.libhandle = SDL_LoadObject(SDL_LIBUSB_DYNAMIC);