summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWill Thompson <will.thompson@collabora.co.uk>2010-04-06 11:26:39 +0100
committerPeter Hutterer <peter.hutterer@who-t.net>2010-05-14 11:33:55 +1000
commit79eada1b0a221c10a3300fa0c988879fd9062d99 (patch)
tree3351c11ff79304df94a408d2dbad26643d6d70cf
parent26c8ad96bed67087f89439ec595e928e7f5c8a9c (diff)
Support pointer: and keyboard: prefices for XI2 device names
I have a keyboard which is also a mouse, and shows up as two devices with the same name. This patch allows me to reliably refer to the pointer device. Signed-off-by: Will Thompson <will.thompson@collabora.co.uk> Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
-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 {