From 26c8ad96bed67087f89439ec595e928e7f5c8a9c Mon Sep 17 00:00:00 2001 From: Will Thompson Date: Thu, 1 Apr 2010 15:35:34 +0100 Subject: Warn and fail if a device name is ambiguous. 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 Signed-off-by: Peter Hutterer --- src/xinput.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/xinput.c b/src/xinput.c index 149662d..6989ef3 100644 --- a/src/xinput.c +++ b/src/xinput.c @@ -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 -- cgit v1.2.3