Skip to content

Instantly share code, notes, and snippets.

@ianliu
Created February 3, 2021 16:38
Show Gist options
  • Save ianliu/cd06d58ff2ebdbdfea35d269c2961961 to your computer and use it in GitHub Desktop.
Save ianliu/cd06d58ff2ebdbdfea35d269c2961961 to your computer and use it in GitHub Desktop.
A simple patch that lists all matches when querying devices with xorg-xinput.
diff -u --recursive --text xinput-1.6.3.orig/src/list.c xinput-1.6.3/src/list.c
--- xinput-1.6.3.orig/src/list.c 2021-02-03 11:40:47.405550058 -0300
+++ xinput-1.6.3/src/list.c 2021-02-03 13:05:48.896505807 -0300
@@ -374,13 +374,16 @@
#if HAVE_XI2
if (xinput_version(display) == XI_2_Major)
{
- XIDeviceInfo *info = xi2_find_device_info(display, argv[arg_dev]);
+ int ndevs;
+ XIDeviceInfo **infos = xi2_find_all_devices_info(display, argv[arg_dev], &ndevs);
- if (!info) {
+ if (!infos || ndevs == 0) {
fprintf(stderr, "unable to find device %s\n", argv[arg_dev]);
return EXIT_FAILURE;
} else {
- print_info_xi2(display, info, format);
+ for (int i = 0; i < ndevs; i++) {
+ print_info_xi2(display, infos[i], format);
+ }
return EXIT_SUCCESS;
}
} else
diff -u --recursive --text xinput-1.6.3.orig/src/xinput.c xinput-1.6.3/src/xinput.c
--- xinput-1.6.3.orig/src/xinput.c 2021-02-03 11:40:47.405550058 -0300
+++ xinput-1.6.3/src/xinput.c 2021-02-03 13:05:30.642984343 -0300
@@ -24,6 +24,7 @@
#include "xinput.h"
#include <ctype.h>
#include <string.h>
+#include <stdlib.h>
int xi_opcode;
@@ -345,6 +346,44 @@
return found;
}
+
+XIDeviceInfo**
+xi2_find_all_devices_info(Display *display, char *name, int *ndevs)
+{
+ XIDeviceInfo *info;
+ XIDeviceInfo **found;
+ int ndevices;
+ int nfound = 0;
+ Bool is_id = True;
+ int i, id = -1;
+
+ for(i = 0; i < strlen(name); i++) {
+ if (!isdigit(name[i])) {
+ is_id = False;
+ break;
+ }
+ }
+
+ if (is_id) {
+ id = atoi(name);
+ }
+
+ info = XIQueryDevice(display, XIAllDevices, &ndevices);
+ found = malloc(ndevices * sizeof(XIDeviceInfo*));
+ if (!found) {
+ return NULL;
+ }
+ for(i = 0; i < ndevices; i++)
+ {
+ if (is_id ? info[i].deviceid == id : device_matches (&info[i], name)) {
+ found[nfound] = &info[i];
+ nfound += 1;
+ }
+ }
+ *ndevs = nfound;
+
+ return found;
+}
#endif
static void
diff -u --recursive --text xinput-1.6.3.orig/src/xinput.h xinput-1.6.3/src/xinput.h
--- xinput-1.6.3.orig/src/xinput.h 2021-02-03 11:40:47.405550058 -0300
+++ xinput-1.6.3/src/xinput.h 2021-02-03 12:00:45.091738578 -0300
@@ -45,6 +45,7 @@
XDeviceInfo* find_device_info( Display *display, char *name, Bool only_extended);
#if HAVE_XI2
XIDeviceInfo* xi2_find_device_info(Display *display, char *name);
+XIDeviceInfo** xi2_find_all_devices_info(Display *display, char *name, int *ndevs);
int xinput_version(Display* display);
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment