Преглед на файлове

Allow opening joysticks that are read-only on Linux

Fixes https://github.com/libsdl-org/SDL/issues/4713
Sam Lantinga преди 3 години
родител
ревизия
b8c00bf914
променени са 1 файла, в които са добавени 6 реда и са изтрити 1 реда
  1. 6 1
      src/joystick/linux/SDL_sysjoystick.c

+ 6 - 1
src/joystick/linux/SDL_sysjoystick.c

@@ -963,7 +963,12 @@ PrepareJoystickHwdata(SDL_Joystick *joystick, SDL_joylist_item *item)
                                      &joystick->naxes,
                                      &joystick->nhats);
     } else {
-        const int fd = open(item->path, O_RDWR | O_CLOEXEC, 0);
+        /* Try read-write first, so we can do rumble */
+        int fd = open(item->path, O_RDWR | O_CLOEXEC, 0);
+        if (fd < 0) {
+            /* Try read-only again, at least we'll get events in this case */
+            fd = open(item->path, O_RDONLY | O_CLOEXEC, 0);
+        }
         if (fd < 0) {
             return SDL_SetError("Unable to open %s", item->path);
         }