From: Peter Hutterer Date: Sun, 13 Sep 2020 21:58:04 +0000 (+1000) Subject: tools/record: add --grab option X-Git-Tag: 1.16.901~83 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=2d641e6b7bcd4f35b111d739b15d00ae407cc1d5;p=platform%2Fupstream%2Flibinput.git tools/record: add --grab option Useful to record devices like power buttons, lid switches, etc. Signed-off-by: Peter Hutterer --- diff --git a/tools/libinput-record.c b/tools/libinput-record.c index 6572858c..7ea5a011 100644 --- a/tools/libinput-record.c +++ b/tools/libinput-record.c @@ -2295,7 +2295,7 @@ mainloop(struct record_context *ctx) } static inline bool -init_device(struct record_context *ctx, char *path) +init_device(struct record_context *ctx, char *path, bool grab) { struct record_device *d; int fd, rc; @@ -2325,6 +2325,17 @@ init_device(struct record_context *ctx, char *path) goto error; } + if (grab) { + rc = libevdev_grab(d->evdev, LIBEVDEV_GRAB); + if (rc != 0) { + fprintf(stderr, + "Grab failed on %s: %s\n", + path, + strerror(-rc)); + goto error; + } + } + libevdev_set_clock_id(d->evdev, CLOCK_MONOTONIC); if (libevdev_get_num_slots(d->evdev) > 0) @@ -2446,6 +2457,7 @@ enum options { OPT_MULTIPLE, OPT_ALL, OPT_LIBINPUT, + OPT_GRAB, }; int @@ -2463,11 +2475,12 @@ main(int argc, char **argv) { "all", no_argument, 0, OPT_ALL }, { "help", no_argument, 0, OPT_HELP }, { "with-libinput", no_argument, 0, OPT_LIBINPUT }, + { "grab", no_argument, 0, OPT_GRAB }, { 0, 0, 0, 0 }, }; struct record_device *d, *tmp; const char *output_arg = NULL; - bool all = false, with_libinput = false; + bool all = false, with_libinput = false, grab = false; int ndevices; int rc = EXIT_FAILURE; @@ -2511,6 +2524,9 @@ main(int argc, char **argv) case OPT_LIBINPUT: with_libinput = true; break; + case OPT_GRAB: + grab = true; + break; default: usage(); rc = EXIT_INVALID_USAGE; @@ -2608,7 +2624,7 @@ main(int argc, char **argv) d = devices; while (*d) { - if (!init_device(&ctx, safe_strdup(*d))) { + if (!init_device(&ctx, safe_strdup(*d), grab)) { strv_free(devices); goto out; } @@ -2627,7 +2643,7 @@ main(int argc, char **argv) for (int i = ndevices; i > 0; i -= 1) { char *devnode = safe_strdup(argv[optind + i - 1]); - if (!init_device(&ctx, devnode)) + if (!init_device(&ctx, devnode, grab)) goto out; } } else { @@ -2638,7 +2654,7 @@ main(int argc, char **argv) goto out; } - if (!init_device(&ctx, path)) + if (!init_device(&ctx, path, grab)) goto out; } diff --git a/tools/libinput-record.man b/tools/libinput-record.man index e85eb10d..196ad0f3 100644 --- a/tools/libinput-record.man +++ b/tools/libinput-record.man @@ -58,6 +58,10 @@ Where \-\-output-file is not given and the first \fBor\fR last argument is not an input device, the first \fBor\fR last argument will be the output file. .TP 8 +.B \-\-grab +Exclusively grab all opened devices. This will prevent events from being +delivered to the host system. +.TP 8 .B \-\-show\-keycodes Show keycodes as-is in the recording. By default, common keys are obfuscated and printed as \fBKEY_A\fR to avoid information leaks.