Merge pull request #45481 from ronchaine/joypad-detection

POSIX systems: go through all event devices, not just event[0-32]
This commit is contained in:
Rémi Verschelde 2021-01-27 19:43:34 +01:00 committed by GitHub
commit 69f77e83bf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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
}