From: Will Thompson Date: Thu, 1 Apr 2010 14:35:34 +0000 (+0100) Subject: Warn and fail if a device name is ambiguous. X-Git-Url: https://diplodocus.org/git/xorg-xinput/commitdiff_plain/26c8ad96bed67087f89439ec595e928e7f5c8a9c?ds=inline;hp=--cc 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 --- 26c8ad96bed67087f89439ec595e928e7f5c8a9c 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