SDL: evdev: correctly handle composite devices

From 6eca02a0e7da78d8f951865ef3c3c2c0acb8cb95 Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Wed, 23 Oct 2024 10:52:50 -0700
Subject: [PATCH] evdev: correctly handle composite devices

These can be both mouse and keyboard and should be initialized and exposed to the application as both.
---
 src/core/linux/SDL_evdev.c | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)

diff --git a/src/core/linux/SDL_evdev.c b/src/core/linux/SDL_evdev.c
index c5b62ae780acc..e655eea6ef0f1 100644
--- a/src/core/linux/SDL_evdev.c
+++ b/src/core/linux/SDL_evdev.c
@@ -933,14 +933,18 @@ static bool SDL_EVDEV_device_added(const char *dev_path, int udev_class)
             SDL_free(item);
             return false;
         }
-    } else if (udev_class & SDL_UDEV_DEVICE_MOUSE) {
+    }
+
+    if (udev_class & SDL_UDEV_DEVICE_MOUSE) {
         if (!SDL_EVDEV_init_mouse(item, udev_class)) {
             close(item->fd);
             SDL_free(item->path);
             SDL_free(item);
             return false;
         }
-    } else if (udev_class & SDL_UDEV_DEVICE_KEYBOARD) {
+    }
+
+    if (udev_class & SDL_UDEV_DEVICE_KEYBOARD) {
         if (!SDL_EVDEV_init_keyboard(item, udev_class)) {
             close(item->fd);
             SDL_free(item->path);
@@ -981,11 +985,14 @@ static bool SDL_EVDEV_device_removed(const char *dev_path)
             if (item == _this->last) {
                 _this->last = prev;
             }
+
             if (item->is_touchscreen) {
                 SDL_EVDEV_destroy_touchscreen(item);
-            } else if (item->udev_class & SDL_UDEV_DEVICE_MOUSE) {
+            }
+            if (item->udev_class & SDL_UDEV_DEVICE_MOUSE) {
                 SDL_EVDEV_destroy_mouse(item);
-            } else if (item->udev_class & SDL_UDEV_DEVICE_KEYBOARD) {
+            }
+            if (item->udev_class & SDL_UDEV_DEVICE_KEYBOARD) {
                 SDL_EVDEV_destroy_keyboard(item);
             }
             close(item->fd);