SDL: Set udev class for accelerometer

From c6ec9998692e7638b7316c8e9e5a8ecf93bbb299 Mon Sep 17 00:00:00 2001
From: meyraud705 <[EMAIL REDACTED]>
Date: Sun, 3 Mar 2024 09:25:52 +0100
Subject: [PATCH] Set udev class for accelerometer

---
 src/core/linux/SDL_udev.c            | 5 +++++
 src/joystick/linux/SDL_sysjoystick.c | 2 +-
 2 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/src/core/linux/SDL_udev.c b/src/core/linux/SDL_udev.c
index 167176fa30972..b8205027d2790 100644
--- a/src/core/linux/SDL_udev.c
+++ b/src/core/linux/SDL_udev.c
@@ -428,6 +428,11 @@ static int device_class(struct udev_device *dev)
             devclass |= SDL_UDEV_DEVICE_JOYSTICK;
         }
 
+        val = _this->syms.udev_device_get_property_value(dev, "ID_INPUT_ACCELEROMETER");
+        if (val && SDL_strcmp(val, "1") == 0) {
+            devclass |= SDL_UDEV_DEVICE_ACCELEROMETER;
+        }
+
         val = _this->syms.udev_device_get_property_value(dev, "ID_INPUT_MOUSE");
         if (val && SDL_strcmp(val, "1") == 0) {
             devclass |= SDL_UDEV_DEVICE_MOUSE;
diff --git a/src/joystick/linux/SDL_sysjoystick.c b/src/joystick/linux/SDL_sysjoystick.c
index 17935745bb0cb..10f074414364d 100644
--- a/src/joystick/linux/SDL_sysjoystick.c
+++ b/src/joystick/linux/SDL_sysjoystick.c
@@ -360,7 +360,7 @@ static void joystick_udev_callback(SDL_UDEV_deviceevent udev_type, int udev_clas
 
     switch (udev_type) {
     case SDL_UDEV_DEVICEADDED:
-        if (!(udev_class & SDL_UDEV_DEVICE_JOYSTICK)) {
+        if (!(udev_class & (SDL_UDEV_DEVICE_JOYSTICK | SDL_UDEV_DEVICE_ACCELEROMETER))) {
             return;
         }
         if (SDL_classic_joysticks) {