Skip to content

Commit

Permalink
tools: let debug-events take a device path
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
whot committed Nov 7, 2018
1 parent 5cd27b0 commit 4e46929
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 11 deletions.
12 changes: 9 additions & 3 deletions tools/libinput-debug-events.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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));
Expand Down
9 changes: 7 additions & 2 deletions tools/libinput-debug-events.man
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
14 changes: 10 additions & 4 deletions tools/libinput-debug-gui.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;

Expand Down Expand Up @@ -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);
Expand Down
9 changes: 7 additions & 2 deletions tools/libinput-debug-gui.man
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions tools/shared.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ enum configuration_options {
{ "set-speed", required_argument, 0, OPT_SPEED }

enum tools_backend {
BACKEND_NONE,
BACKEND_DEVICE,
BACKEND_UDEV
};
Expand Down
1 change: 1 addition & 0 deletions tools/test-tool-option-parsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ def test_device(self):
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']:
Expand Down

0 comments on commit 4e46929

Please sign in to comment.