From 4e469291b15e00a6faa77b809799b22d6c44ad40 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Wed, 31 Oct 2018 15:52:25 +1000 Subject: [PATCH] tools: let debug-events take a device path 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 --- tools/libinput-debug-events.c | 12 +++++++++--- tools/libinput-debug-events.man | 9 +++++++-- tools/libinput-debug-gui.c | 14 ++++++++++---- tools/libinput-debug-gui.man | 9 +++++++-- tools/shared.h | 1 + tools/test-tool-option-parsing.py | 1 + 6 files changed, 35 insertions(+), 11 deletions(-) diff --git a/tools/libinput-debug-events.c b/tools/libinput-debug-events.c index 42dadefa..8ca2c542 100644 --- a/tools/libinput-debug-events.c +++ b/tools/libinput-debug-events.c @@ -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)); diff --git a/tools/libinput-debug-events.man b/tools/libinput-debug-events.man index 8a63821e..582f3375 100644 --- a/tools/libinput-debug-events.man +++ b/tools/libinput-debug-events.man @@ -2,7 +2,11 @@ .SH NAME libinput\-debug\-events \- debug helper for libinput .SH SYNOPSIS -.B libinput debug\-events [\-\-help] [\-\-show\-keycodes] [\-\-udev \fI\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\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 diff --git a/tools/libinput-debug-gui.c b/tools/libinput-debug-gui.c index afe0a325..cda5be00 100644 --- a/tools/libinput-debug-gui.c +++ b/tools/libinput-debug-gui.c @@ -916,7 +916,7 @@ sockets_init(struct libinput *li) static void usage(void) { - printf("Usage: libinput debug-gui [options] [--udev |--device /dev/input/event0]\n"); + printf("Usage: libinput debug-gui [options] [--udev |[--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); diff --git a/tools/libinput-debug-gui.man b/tools/libinput-debug-gui.man index f2053779..c02aaeba 100644 --- a/tools/libinput-debug-gui.man +++ b/tools/libinput-debug-gui.man @@ -2,7 +2,11 @@ .SH NAME libinput\-debug\-gui \- visual debug helper for libinput .SH SYNOPSIS -.B libinput debug\-gui [\-\-help] [\-\-udev \fI\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\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 diff --git a/tools/shared.h b/tools/shared.h index 4e363e22..7370d735 100644 --- a/tools/shared.h +++ b/tools/shared.h @@ -80,6 +80,7 @@ enum configuration_options { { "set-speed", required_argument, 0, OPT_SPEED } enum tools_backend { + BACKEND_NONE, BACKEND_DEVICE, BACKEND_UDEV }; diff --git a/tools/test-tool-option-parsing.py b/tools/test-tool-option-parsing.py index b6f845e8..c1c7b988 100755 --- a/tools/test-tool-option-parsing.py +++ b/tools/test-tool-option-parsing.py @@ -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']: