]> diplodocus.org Git - xorg-xinput/commitdiff
Warn and fail if a device name is ambiguous.
authorWill Thompson <will.thompson@collabora.co.uk>
Thu, 1 Apr 2010 14:35:34 +0000 (15:35 +0100)
committerPeter Hutterer <peter.hutterer@who-t.net>
Fri, 14 May 2010 01:33:51 +0000 (11:33 +1000)
The XI1 path bails out if the user specifies a device by name and there
is more than one device, but the XI2 path previously just silently chose
the first one. This patch makes it fail outright.

Signed-off-by: Will Thompson <will.thompson@collabora.co.uk>
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
src/xinput.c

index 149662d2068c4fb8878e91fa565aa65962afc0a0..6989ef3bd3578f61e91ca64c4c11f2a290a99568 100644 (file)
@@ -236,6 +236,7 @@ XIDeviceInfo*
 xi2_find_device_info(Display *display, char *name)
 {
     XIDeviceInfo *info;
+    XIDeviceInfo *found = NULL;
     int ndevices;
     Bool is_id = True;
     int i, id = -1;
@@ -257,12 +258,20 @@ xi2_find_device_info(Display *display, char *name)
         if ((is_id && info[i].deviceid == id) ||
                 (!is_id && strcmp(info[i].name, name) == 0))
         {
-            return &info[i];
+            if (found) {
+                fprintf(stderr,
+                        "Warning: There are multiple devices named '%s'.\n"
+                        "To ensure the correct one is selected, please use "
+                        "the device ID instead.\n\n", name);
+                XIFreeDeviceInfo(info);
+                return NULL;
+            } else {
+                found = &info[i];
+            }
         }
     }
 
-    XIFreeDeviceInfo(info);
-    return NULL;
+    return found;
 }
 #endif