]> diplodocus.org Git - xorg-xinput/commitdiff
Add --id-only flag for 'xinput list'.
authorPeter Hutterer <peter.hutterer@who-t.net>
Tue, 18 Jan 2011 03:02:20 +0000 (13:02 +1000)
committerPeter Hutterer <peter.hutterer@who-t.net>
Wed, 19 Jan 2011 21:41:58 +0000 (07:41 +1000)
The default output of xinput list is hard to parse by scripts. Provide a
--id-only option to print the device ID only, without any other
information.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Dirk Wallenstein <halsmit@t-online.de>
Tested-by: Dirk Wallenstein <halsmit@t-online.de>
man/xinput.man
src/list.c
src/xinput.c

index 035becc9b2166788296ca021e3070de7d2aca9cf..9d7e9a724cd7d457fb8bf76745eaa653ae446c0b 100644 (file)
@@ -17,7 +17,7 @@ of the program and the version supported by the server. This option does not
 require a device name.
 .PP
 .TP 8
-.B --list [--short || --long || --name-only] [\fIdevice\fP]
+.B --list [--short || --long || --name-only || --id-only] [\fIdevice\fP]
 If no argument is given list all the input devices. If an argument is given,
 show all the features of \fIdevice\fP.
 If --long is provided, the output includes detailed information about the
@@ -26,6 +26,9 @@ device names and some minimal information is listed.
 If --name-only is provided, the output is limited to the device names. One
 device name is listed per line. Note that the order the devices are listed
 is undefined.
+If --id-only is provided, the output is limited to the device IDs. One
+device ID is listed per line. Note that the order the devices are listed is
+undefined.
 .PP
 .TP 8
 .B --get-feedbacks \fIdevice\fP
index 0e6f9bea01246afcf1d5f7dee46e136855b8fb84..ca3c6bfaa3364f94ed3864efcaa864cb183ae1b4 100644 (file)
@@ -27,7 +27,8 @@
 enum print_format {
     FORMAT_SHORT,
     FORMAT_LONG,
-    FORMAT_NAME
+    FORMAT_NAME,
+    FORMAT_ID,
 };
 
 
@@ -45,6 +46,10 @@ print_info(Display* dpy, XDeviceInfo *info, enum print_format format)
     {
         printf("%s\n", info->name);
         return;
+    } else if (format == FORMAT_ID)
+    {
+        printf("%ld\n", info->id);
+        return;
     }
 
     printf("\"%s\"\tid=%ld\t[", info->name, info->id);
@@ -203,6 +208,10 @@ print_info_xi2(Display* display, XIDeviceInfo *dev, enum print_format format)
     {
         printf("%s\n", dev->name);
         return;
+    } else if (format == FORMAT_ID)
+    {
+        printf("%d\n", dev->deviceid);
+        return;
     }
 
     printf("%-40s\tid=%d\t[", dev->name, dev->deviceid);
@@ -317,6 +326,8 @@ list(Display        *display,
             format = FORMAT_LONG;
         else if (strcmp(argv[0], "--name-only") == 0)
             format = FORMAT_NAME;
+        else if (strcmp(argv[0], "--id-only") == 0)
+            format = FORMAT_ID;
         arg_dev++;
     }
 
index 86c163e952785ac78be5695d39a552a1b54a2294..a20f8560bad57f1813ab000822eec54e9e73d35f 100644 (file)
@@ -68,7 +68,7 @@ static entry drivers[] =
      set_mode
     },
     {"list",
-     "[--short || --long || --name-only] [<device name>...]",
+     "[--short || --long || --name-only || --id-only] [<device name>...]",
      list
     },
     {"query-state",