SDL: Added support for touchpads in the Linux evdev code (thanks Francisco!)

From 373216ae5be62b710ad68524777ae38ca712c53d Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Thu, 7 Oct 2021 18:14:16 -0700
Subject: [PATCH] Added support for touchpads in the Linux evdev code (thanks
 Francisco!)

---
 src/core/linux/SDL_evdev.c              | 7 +++++--
 src/core/linux/SDL_evdev_capabilities.c | 2 +-
 src/core/linux/SDL_evdev_capabilities.h | 3 ++-
 3 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/src/core/linux/SDL_evdev.c b/src/core/linux/SDL_evdev.c
index 36359201d2..9d7c39a87a 100644
--- a/src/core/linux/SDL_evdev.c
+++ b/src/core/linux/SDL_evdev.c
@@ -218,8 +218,11 @@ static void SDL_EVDEV_udev_callback(SDL_UDEV_deviceevent udev_event, int udev_cl
 
     switch(udev_event) {
     case SDL_UDEV_DEVICEADDED:
-        if (!(udev_class & (SDL_UDEV_DEVICE_MOUSE | SDL_UDEV_DEVICE_KEYBOARD |
-            SDL_UDEV_DEVICE_TOUCHSCREEN)))
+        if (udev_class & SDL_UDEV_DEVICE_TOUCHPAD) {
+            udev_class |= SDL_UDEV_DEVICE_TOUCHSCREEN;
+        }
+
+        if (!(udev_class & (SDL_UDEV_DEVICE_MOUSE | SDL_UDEV_DEVICE_KEYBOARD | SDL_UDEV_DEVICE_TOUCHSCREEN)))
             return;
 
         if ((udev_class & SDL_UDEV_DEVICE_JOYSTICK))
diff --git a/src/core/linux/SDL_evdev_capabilities.c b/src/core/linux/SDL_evdev_capabilities.c
index 1373f0e9be..72bdba17f3 100644
--- a/src/core/linux/SDL_evdev_capabilities.c
+++ b/src/core/linux/SDL_evdev_capabilities.c
@@ -78,7 +78,7 @@ SDL_EVDEV_GuessDeviceClass(unsigned long bitmask_ev[NBITS(EV_MAX)],
         if (test_bit(BTN_STYLUS, bitmask_key) || test_bit(BTN_TOOL_PEN, bitmask_key)) {
             ; /* ID_INPUT_TABLET */
         } else if (test_bit(BTN_TOOL_FINGER, bitmask_key) && !test_bit(BTN_TOOL_PEN, bitmask_key)) {
-            ; /* ID_INPUT_TOUCHPAD */
+            devclass |= SDL_UDEV_DEVICE_TOUCHPAD; /* ID_INPUT_TOUCHPAD */
         } else if (test_bit(BTN_MOUSE, bitmask_key)) {
             devclass |= SDL_UDEV_DEVICE_MOUSE; /* ID_INPUT_MOUSE */
         } else if (test_bit(BTN_TOUCH, bitmask_key)) {
diff --git a/src/core/linux/SDL_evdev_capabilities.h b/src/core/linux/SDL_evdev_capabilities.h
index 6822425eb2..6167ebbf89 100644
--- a/src/core/linux/SDL_evdev_capabilities.h
+++ b/src/core/linux/SDL_evdev_capabilities.h
@@ -38,7 +38,8 @@ typedef enum
     SDL_UDEV_DEVICE_JOYSTICK    = 0x0004,
     SDL_UDEV_DEVICE_SOUND       = 0x0008,
     SDL_UDEV_DEVICE_TOUCHSCREEN = 0x0010,
-    SDL_UDEV_DEVICE_ACCELEROMETER = 0x0020
+    SDL_UDEV_DEVICE_ACCELEROMETER = 0x0020,
+    SDL_UDEV_DEVICE_TOUCHPAD    = 0x0040
 } SDL_UDEV_deviceclass;
 
 #define BITS_PER_LONG           (sizeof(unsigned long) * 8)