evdev: refactor joystick/gamepad detection
authorJosé Expósito <jose.exposito89@gmail.com>
Tue, 23 Nov 2021 17:07:27 +0000 (18:07 +0100)
committerPeter Hutterer <peter.hutterer@who-t.net>
Fri, 3 Dec 2021 00:20:47 +0000 (00:20 +0000)
Move the logic to detect joysticks and gamepads to its own function.

Refactor, no functional changes.

Signed-off-by: José Expósito <jose.exposito89@gmail.com>
src/evdev.c

index d8dfdad..9eb2d30 100644 (file)
@@ -1850,6 +1850,18 @@ evdev_disable_accelerometer_axes(struct evdev_device *device)
        libevdev_disable_event_code(evdev, EV_ABS, REL_Z);
 }
 
+static bool
+evdev_device_is_joystick_or_gamepad(struct evdev_device *device)
+{
+       enum evdev_device_udev_tags udev_tags;
+
+       udev_tags = evdev_device_get_udev_tags(device, device->udev_device);
+       if (udev_tags == (EVDEV_UDEV_TAG_INPUT|EVDEV_UDEV_TAG_JOYSTICK))
+               return true;
+
+       return false;
+}
+
 static struct evdev_dispatch *
 evdev_configure_device(struct evdev_device *device)
 {
@@ -1893,9 +1905,9 @@ evdev_configure_device(struct evdev_device *device)
                evdev_disable_accelerometer_axes(device);
        }
 
-       if (udev_tags == (EVDEV_UDEV_TAG_INPUT|EVDEV_UDEV_TAG_JOYSTICK)) {
+       if (evdev_device_is_joystick_or_gamepad(device)) {
                evdev_log_info(device,
-                              "device is a joystick, ignoring\n");
+                              "device is a joystick or a gamepad, ignoring\n");
                return NULL;
        }