Commit 130b6bebaec4bc9f37c103a69595e8c261f2af49

Sam Lantinga 2021-08-24T17:01:34

Manually scan for Linux joysticks before udev scan runs This allows us to have joysticks sorted by insert time at startup, fixing https://github.com/libsdl-org/SDL/issues/4688

diff --git a/src/joystick/linux/SDL_sysjoystick.c b/src/joystick/linux/SDL_sysjoystick.c
index af21d79..a3936e6 100644
--- a/src/joystick/linux/SDL_sysjoystick.c
+++ b/src/joystick/linux/SDL_sysjoystick.c
@@ -676,6 +676,9 @@ LINUX_JoystickInit(void)
     last_joy_detect_time = 0;
     last_input_dir_mtime = 0;
 
+    /* Manually scan first, since we sort by device number and udev doesn't */
+    LINUX_JoystickDetect();
+
 #if SDL_USE_LIBUDEV
     if (enumeration_method == ENUMERATION_LIBUDEV) {
         if (SDL_UDEV_Init() < 0) {
@@ -717,9 +720,6 @@ LINUX_JoystickInit(void)
             }
         }
 #endif /* HAVE_INOTIFY */
-
-        /* Report all devices currently present */
-        LINUX_JoystickDetect();
     }
 
     return 0;