Merge pull request #1866 from fewtarius/dev

Fix ES -> RetroArch input ordering bug.
This commit is contained in:
fewtarius 2023-08-03 13:37:47 -04:00 committed by GitHub
commit 925ef12188
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,49 +0,0 @@
diff --git a/input/drivers_joypad/udev_joypad.c b/input/drivers_joypad/udev_joypad.c
index e60a8b2..03ba777 100644
--- a/input/drivers_joypad/udev_joypad.c
+++ b/input/drivers_joypad/udev_joypad.c
@@ -538,6 +538,14 @@
}
}
+/* Used for sorting devnodes to appear in the correct order */
+static int sort_devnodes(const void *a, const void *b)
+{
+ const struct joypad_udev_entry *aa = (const struct joypad_udev_entry*)a;
+ const struct joypad_udev_entry *bb = (const struct joypad_udev_entry*)b;
+ return strcmp(aa->devnode, bb->devnode);
+}
+
static void *udev_joypad_init(void *data)
{
unsigned i;
@@ -570,9 +578,29 @@
udev_enumerate_scan_devices(enumerate);
devs = udev_enumerate_get_list_entry(enumerate);
- udev_list_entry_foreach(item, devs)
+ for (item = devs; item; item = udev_list_entry_get_next(item))
{
const char *name = udev_list_entry_get_name(item);
+ struct udev_device *dev = udev_device_new_from_syspath(udev_joypad_fd, name);
+ const char *devnode = udev_device_get_devnode(dev);
+
+ if (devnode != NULL) {
+ sorted[sorted_count].devnode = devnode;
+ sorted[sorted_count].item = item;
+ sorted_count++;
+ } else {
+ udev_device_unref(dev);
+ }
+ }
+
+ /* Sort the udev entries by devnode name so that they are
+ * created in the proper order */
+ qsort(sorted, sorted_count,
+ sizeof(struct joypad_udev_entry), sort_devnodes);
+
+ for (i = 0; i < sorted_count; i++)
+ {
+ const char *name = udev_list_entry_get_name(sorted[i].item);
struct udev_device *dev = udev_device_new_from_syspath(udev_joypad_fd, name);
const char *devnode = udev_device_get_devnode(dev);