summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRĂ©mi Verschelde <remi@verschelde.fr>2021-01-27 19:43:34 +0100
committerGitHub <noreply@github.com>2021-01-27 19:43:34 +0100
commit69f77e83bf6430f1d76a3551d2787668646f9d76 (patch)
treea1e3329c2bbabbb8b32e549a09a2c0bd561fd587
parent964c14580c322cdbd529d03896de5cd8be4c8c2f (diff)
parent01c030f9b79ab8bb402b286704d4d58908d6d03c (diff)
Merge pull request #45481 from ronchaine/joypad-detection
POSIX systems: go through all event devices, not just event[0-32]
-rw-r--r--platform/linuxbsd/joypad_linux.cpp19
1 files changed, 15 insertions, 4 deletions
diff --git a/platform/linuxbsd/joypad_linux.cpp b/platform/linuxbsd/joypad_linux.cpp
index 291ca49585..d54d805199 100644
--- a/platform/linuxbsd/joypad_linux.cpp
+++ b/platform/linuxbsd/joypad_linux.cpp
@@ -32,6 +32,7 @@
#include "joypad_linux.h"
+#include <dirent.h>
#include <errno.h>
#include <fcntl.h>
#include <linux/input.h>
@@ -183,13 +184,23 @@ void JoypadLinux::monitor_joypads() {
{
MutexLock lock(joy_mutex);
- for (int i = 0; i < 32; i++) {
+ DIR *input_directory;
+ input_directory = opendir("/dev/input");
+ if (input_directory) {
+ struct dirent *current;
char fname[64];
- sprintf(fname, "/dev/input/event%d", i);
- if (attached_devices.find(fname) == -1) {
- open_joypad(fname);
+
+ while ((current = readdir(input_directory)) != NULL) {
+ if (strncmp(current->d_name, "event", 5) != 0) {
+ continue;
+ }
+ sprintf(fname, "/dev/input/%.*s", 16, current->d_name);
+ if (attached_devices.find(fname) == -1) {
+ open_joypad(fname);
+ }
}
}
+ closedir(input_directory);
}
usleep(1000000); // 1s
}