From 6e1e00701ed78956dfb425c37e07bf90d61eee15 Mon Sep 17 00:00:00 2001 From: Tyson Whitehead Date: Thu, 4 Apr 2024 12:06:28 -0400 Subject: [PATCH] Initialize udev before joystick manual scan so class lookup works LINUX_JoystickInit does a manual scan first so devices are sorted. If SDL_UDEV_Init hasn't run by then, then the product info cannot be looked up by SDL_UDEV_GetProductInfo and the initial-plugged- in-device classification falls back to heuristic guessing. (cherry picked from commit 0963c11af84da275208edc00b3b8c2e12be396b6) --- src/joystick/linux/SDL_sysjoystick.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/joystick/linux/SDL_sysjoystick.c b/src/joystick/linux/SDL_sysjoystick.c index b79a7b79cd..bb7c31cedc 100644 --- a/src/joystick/linux/SDL_sysjoystick.c +++ b/src/joystick/linux/SDL_sysjoystick.c @@ -1026,6 +1026,9 @@ static void LINUX_JoystickDetect(void) static int LINUX_JoystickInit(void) { const char *devices = SDL_GetHint(SDL_HINT_JOYSTICK_DEVICE); +#ifdef SDL_USE_LIBUDEV + int udev_status = SDL_UDEV_Init(); +#endif SDL_classic_joysticks = SDL_GetHintBoolean(SDL_HINT_LINUX_JOYSTICK_CLASSIC, SDL_FALSE); @@ -1076,7 +1079,7 @@ static int LINUX_JoystickInit(void) } if (enumeration_method == ENUMERATION_LIBUDEV) { - if (SDL_UDEV_Init() == 0) { + if (udev_status == 0) { /* Set up the udev callback */ if (SDL_UDEV_AddCallback(joystick_udev_callback) < 0) { SDL_UDEV_Quit();