tools: let debug-events take a device path
authorPeter Hutterer <peter.hutterer@who-t.net>
Wed, 31 Oct 2018 05:52:25 +0000 (15:52 +1000)
committerPeter Hutterer <peter.hutterer@who-t.net>
Wed, 7 Nov 2018 05:03:52 +0000 (05:03 +0000)
This is the most common use-case other than "all from udev", so let's just
parse a device path correctly without requiring --device.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
tools/libinput-debug-events.c
tools/libinput-debug-events.man
tools/libinput-debug-gui.c
tools/libinput-debug-gui.man
tools/shared.h
tools/test-tool-option-parsing.py

index 42dadef..8ca2c54 100644 (file)
@@ -904,7 +904,7 @@ main(int argc, char **argv)
 {
        struct libinput *li;
        struct timespec tp;
-       enum tools_backend backend = BACKEND_UDEV;
+       enum tools_backend backend = BACKEND_NONE;
        const char *seat_or_device = "seat0";
        bool grab = false;
        bool verbose = false;
@@ -981,8 +981,14 @@ main(int argc, char **argv)
        }
 
        if (optind < argc) {
-               usage();
-               return EXIT_INVALID_USAGE;
+               if (optind < argc - 1 || backend != BACKEND_NONE) {
+                       usage();
+                       return EXIT_INVALID_USAGE;
+               }
+               backend = BACKEND_DEVICE;
+               seat_or_device = argv[optind];
+       } else if (backend == BACKEND_NONE) {
+               backend = BACKEND_UDEV;
        }
 
        memset(&act, 0, sizeof(act));
index 8a63821..582f337 100644 (file)
@@ -2,7 +2,11 @@
 .SH NAME
 libinput\-debug\-events \- debug helper for libinput
 .SH SYNOPSIS
-.B libinput debug\-events [\-\-help] [\-\-show\-keycodes] [\-\-udev \fI<seat>\fB|\-\-device \fI/dev/input/event0\fB] \fI[configuration options]\fB
+.B libinput debug\-events \fI[options]\fB
+.PP
+.B libinput debug\-events \fI[options]\fB \-\-udev \fI<seat>\fB
+.PP
+.B libinput debug\-events \fI[options]\fB [\-\-device] \fI/dev/input/event0\fB
 .SH DESCRIPTION
 .PP
 The
@@ -17,7 +21,8 @@ This tool usually needs to be run as root to have access to the
 .SH OPTIONS
 .TP 8
 .B \-\-device \fI/dev/input/event0\fR
-Use the given device with the path backend
+Use the given device with the path backend. The \fB\-\-device\fR argument may be
+omitted.
 .TP 8
 .B \-\-grab
 Exclusively grab all opened devices. This will prevent events from being
index afe0a32..cda5be0 100644 (file)
@@ -916,7 +916,7 @@ sockets_init(struct libinput *li)
 
 static void
 usage(void) {
-       printf("Usage: libinput debug-gui [options] [--udev <seat>|--device /dev/input/event0]\n");
+       printf("Usage: libinput debug-gui [options] [--udev <seat>|[--device] /dev/input/event0]\n");
 }
 
 static gboolean
@@ -933,7 +933,7 @@ main(int argc, char **argv)
        struct window w = {0};
        struct tools_options options;
        struct libinput *li;
-       enum tools_backend backend = BACKEND_UDEV;
+       enum tools_backend backend = BACKEND_NONE;
        const char *seat_or_device = "seat0";
        bool verbose = false;
 
@@ -999,8 +999,14 @@ main(int argc, char **argv)
        }
 
        if (optind < argc) {
-               usage();
-               return EXIT_INVALID_USAGE;
+               if (optind < argc - 1 || backend != BACKEND_NONE) {
+                       usage();
+                       return EXIT_INVALID_USAGE;
+               }
+               backend = BACKEND_DEVICE;
+               seat_or_device = argv[optind];
+       } else if (backend == BACKEND_NONE) {
+               backend = BACKEND_UDEV;
        }
 
        li = tools_open_backend(backend, seat_or_device, verbose, &w.grab);
index f205377..c02aaeb 100644 (file)
@@ -2,7 +2,11 @@
 .SH NAME
 libinput\-debug\-gui \- visual debug helper for libinput
 .SH SYNOPSIS
-.B libinput debug\-gui [\-\-help] [\-\-udev \fI<seat>\fB|\-\-device \fI/dev/input/event0\fB] \fI[configuration options]\fB
+.B libinput debug\-gui \fI[options]\fB
+.PP
+.B libinput debug\-gui \fI[options]\fB \-\-udev \fI<seat>\fB
+.PP
+.B libinput debug\-gui \fI[options]\fB [\-\-device] \fI/dev/input/event0\fB
 .SH DESCRIPTION
 .PP
 The
@@ -21,7 +25,8 @@ This tool usually needs to be run as root to have access to the
 .SH OPTIONS
 .TP 8
 .B \-\-device \fI/dev/input/event0\fR
-Use the given device with the path backend.
+Use the given device with the path backend. The \fB\-\-device\fR argument may be
+omitted.
 .TP 8
 .B \-\-grab
 Exclusively grab all opened devices. This will prevent events from being
index 4e363e2..7370d73 100644 (file)
@@ -80,6 +80,7 @@ enum configuration_options {
        { "set-speed",                 required_argument, 0, OPT_SPEED }
 
 enum tools_backend {
+       BACKEND_NONE,
        BACKEND_DEVICE,
        BACKEND_UDEV
 };
index b6f845e..c1c7b98 100755 (executable)
@@ -135,6 +135,7 @@ class TestToolWithOptions(object):
         self.run_command_missing_arg(['--device'])
         self.run_command_success(['--device', '/dev/input/event0'])
         self.run_command_success(['--device', '/dev/input/event1'])
+        self.run_command_success(['/dev/input/event0'])
 
     def test_options_pattern(self):
         for option in self.options['pattern']: