]> diplodocus.org Git - xorg-xinput/commitdiff
Add --name-only flag for 'xinput list'.
authorPeter Hutterer <peter.hutterer@who-t.net>
Tue, 18 Jan 2011 02:55:46 +0000 (12:55 +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
--name-only option to print the device name 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 65b05e365e275c8900e3b0449a6e1c5abde758cb..035becc9b2166788296ca021e3070de7d2aca9cf 100644 (file)
@@ -17,12 +17,15 @@ of the program and the version supported by the server. This option does not
 require a device name.
 .PP
 .TP 8
 require a device name.
 .PP
 .TP 8
-.B --list [--short || --long] [\fIdevice\fP]
+.B --list [--short || --long || --name-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
 capabilities of each devices. Otherwise, or if --short is provided, only the
 device names and some minimal information is listed.
 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
 capabilities of each devices. Otherwise, or if --short is provided, only the
 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.
 .PP
 .TP 8
 .B --get-feedbacks \fIdevice\fP
 .PP
 .TP 8
 .B --get-feedbacks \fIdevice\fP
index 9538a0a8d171aece8e93fe2bc82424342674e9ff..0e6f9bea01246afcf1d5f7dee46e136855b8fb84 100644 (file)
@@ -26,7 +26,8 @@
 
 enum print_format {
     FORMAT_SHORT,
 
 enum print_format {
     FORMAT_SHORT,
-    FORMAT_LONG
+    FORMAT_LONG,
+    FORMAT_NAME
 };
 
 
 };
 
 
@@ -40,6 +41,12 @@ print_info(Display* dpy, XDeviceInfo *info, enum print_format format)
     XValuatorInfoPtr   v;
     XAxisInfoPtr       a;
 
     XValuatorInfoPtr   v;
     XAxisInfoPtr       a;
 
+    if (format == FORMAT_NAME)
+    {
+        printf("%s\n", info->name);
+        return;
+    }
+
     printf("\"%s\"\tid=%ld\t[", info->name, info->id);
 
     switch (info->use) {
     printf("\"%s\"\tid=%ld\t[", info->name, info->id);
 
     switch (info->use) {
@@ -192,6 +199,12 @@ print_classes_xi2(Display* display, XIAnyClassInfo **classes,
 static void
 print_info_xi2(Display* display, XIDeviceInfo *dev, enum print_format format)
 {
 static void
 print_info_xi2(Display* display, XIDeviceInfo *dev, enum print_format format)
 {
+    if (format == FORMAT_NAME)
+    {
+        printf("%s\n", dev->name);
+        return;
+    }
+
     printf("%-40s\tid=%d\t[", dev->name, dev->deviceid);
     switch(dev->use)
     {
     printf("%-40s\tid=%d\t[", dev->name, dev->deviceid);
     switch(dev->use)
     {
@@ -246,10 +259,13 @@ list_xi2(Display *display,
         dev = &info[i];
         if (dev->use == XIMasterPointer || dev->use == XIMasterKeyboard)
         {
         dev = &info[i];
         if (dev->use == XIMasterPointer || dev->use == XIMasterKeyboard)
         {
-            if (dev->use == XIMasterPointer)
-                printf("⎡ ");
-            else
-                printf("⎣ ");
+            if (format == FORMAT_SHORT || format == FORMAT_LONG)
+            {
+                if (dev->use == XIMasterPointer)
+                    printf("⎡ ");
+                else
+                    printf("⎣ ");
+            }
 
             print_info_xi2(display, dev, format);
             for (j = 0; j < ndevices; j++)
 
             print_info_xi2(display, dev, format);
             for (j = 0; j < ndevices; j++)
@@ -259,7 +275,8 @@ list_xi2(Display *display,
                 if ((sd->use == XISlavePointer || sd->use == XISlaveKeyboard) &&
                      (sd->attachment == dev->deviceid))
                 {
                 if ((sd->use == XISlavePointer || sd->use == XISlaveKeyboard) &&
                      (sd->attachment == dev->deviceid))
                 {
-                    printf("%s   ↳ ", dev->use == XIMasterPointer ? "⎜" : " ");
+                    if (format == FORMAT_SHORT || format == FORMAT_LONG)
+                        printf("%s   ↳ ", dev->use == XIMasterPointer ? "⎜" : " ");
                     print_info_xi2(display, sd, format);
                 }
             }
                     print_info_xi2(display, sd, format);
                 }
             }
@@ -298,6 +315,8 @@ list(Display        *display,
             format = FORMAT_SHORT;
         else if (strcmp(argv[0], "--long") == 0)
             format = FORMAT_LONG;
             format = FORMAT_SHORT;
         else if (strcmp(argv[0], "--long") == 0)
             format = FORMAT_LONG;
+        else if (strcmp(argv[0], "--name-only") == 0)
+            format = FORMAT_NAME;
         arg_dev++;
     }
 
         arg_dev++;
     }
 
index 9ca3832a4ce1993154b95632dab18d6cb3f88beb..86c163e952785ac78be5695d39a552a1b54a2294 100644 (file)
@@ -68,7 +68,7 @@ static entry drivers[] =
      set_mode
     },
     {"list",
      set_mode
     },
     {"list",
-     "[--short || --long] [<device name>...]",
+     "[--short || --long || --name-only] [<device name>...]",
      list
     },
     {"query-state",
      list
     },
     {"query-state",