From aaec90e5c5a0e75045428ffec41dd1d59d482ec1 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Fri, 6 Sep 2019 08:42:54 -0700 Subject: [PATCH] Fixed bug 4789 - Linux accelerometers no longer available as joysticks Daniel Drake A long time ago, it was possible to play neverball on Linux using the accelerometer found in HP laptops. The kernel exposes the accelerometer as a joystick (/dev/input/jsX) as well as an evdev device (/dev/input/eventX). I guess it worked fine when SDL was using the js interface, but then stopped working here: http://hg.libsdl.org/SDL/rev/fdaeea9e7567 Looking at current code which uses udev to discover joysticks, it looks for the udev tag ID_INPUT_JOYSTICK. However udev's internal input_id logic specifically tags accelerometers as ID_INPUT_ACCELEROMETER and nothing else. This looks like a good fit for SDL_HINT_ACCELEROMETER_AS_JOYSTICK. --- src/core/linux/SDL_udev.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/core/linux/SDL_udev.c b/src/core/linux/SDL_udev.c index ecb7c5e7c0bdd..5b47200d4eeb7 100644 --- a/src/core/linux/SDL_udev.c +++ b/src/core/linux/SDL_udev.c @@ -34,6 +34,7 @@ #include "SDL_assert.h" #include "SDL_loadso.h" #include "SDL_timer.h" +#include "SDL_hints.h" #include "../unix/SDL_poll.h" static const char *SDL_UDEV_LIBS[] = { "libudev.so.1", "libudev.so.0" }; @@ -420,6 +421,12 @@ device_event(SDL_UDEV_deviceevent type, struct udev_device *dev) if (val != NULL && SDL_strcmp(val, "1") == 0 ) { devclass |= SDL_UDEV_DEVICE_JOYSTICK; } + + val = _this->syms.udev_device_get_property_value(dev, "ID_INPUT_ACCELEROMETER"); + if (SDL_GetHintBoolean(SDL_HINT_ACCELEROMETER_AS_JOYSTICK, SDL_TRUE) && + val != NULL && SDL_strcmp(val, "1") == 0 ) { + devclass |= SDL_UDEV_DEVICE_JOYSTICK; + } val = _this->syms.udev_device_get_property_value(dev, "ID_INPUT_MOUSE"); if (val != NULL && SDL_strcmp(val, "1") == 0 ) {