summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/xinput.c40
1 files changed, 35 insertions, 5 deletions
diff --git a/src/xinput.c b/src/xinput.c
index 6989ef3..9ca3832 100644
--- a/src/xinput.c
+++ b/src/xinput.c
@@ -232,6 +232,37 @@ find_device_info(Display *display,
}
#ifdef HAVE_XI2
+Bool is_pointer(int use)
+{
+ return use == XIMasterPointer || use == XISlavePointer;
+}
+
+Bool is_keyboard(int use)
+{
+ return use == XIMasterKeyboard || use == XISlaveKeyboard;
+}
+
+Bool device_matches(XIDeviceInfo *info, char *name)
+{
+ if (strcmp(info->name, name) == 0) {
+ return True;
+ }
+
+ if (strncmp(name, "pointer:", strlen("pointer:")) == 0 &&
+ strcmp(info->name, name + strlen("pointer:")) == 0 &&
+ is_pointer(info->use)) {
+ return True;
+ }
+
+ if (strncmp(name, "keyboard:", strlen("keyboard:")) == 0 &&
+ strcmp(info->name, name + strlen("keyboard:")) == 0 &&
+ is_keyboard(info->use)) {
+ return True;
+ }
+
+ return False;
+}
+
XIDeviceInfo*
xi2_find_device_info(Display *display, char *name)
{
@@ -255,14 +286,13 @@ xi2_find_device_info(Display *display, char *name)
info = XIQueryDevice(display, XIAllDevices, &ndevices);
for(i = 0; i < ndevices; i++)
{
- if ((is_id && info[i].deviceid == id) ||
- (!is_id && strcmp(info[i].name, name) == 0))
- {
+ if (is_id ? info[i].deviceid == id : device_matches (&info[i], name)) {
if (found) {
fprintf(stderr,
- "Warning: There are multiple devices named '%s'.\n"
+ "Warning: There are multiple devices matching '%s'.\n"
"To ensure the correct one is selected, please use "
- "the device ID instead.\n\n", name);
+ "the device ID, or prefix the\ndevice name with "
+ "'pointer:' or 'keyboard:' as appropriate.\n\n", name);
XIFreeDeviceInfo(info);
return NULL;
} else {