tools/record: add --grab option
authorPeter Hutterer <peter.hutterer@who-t.net>
Sun, 13 Sep 2020 21:58:04 +0000 (07:58 +1000)
committerPeter Hutterer <peter.hutterer@who-t.net>
Wed, 16 Sep 2020 23:59:57 +0000 (23:59 +0000)
Useful to record devices like power buttons, lid switches, etc.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
tools/libinput-record.c
tools/libinput-record.man

index 6572858c2ad0e787ae02ea33b3fedb80d044f1cf..7ea5a01199bf7a508cd1c93d8198f3b3dba41075 100644 (file)
@@ -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;
        }
 
index e85eb10d6b9b6e18586d9571abfe641de51dc0c5..196ad0f3c74b0d6533ac1a1b82de1ec73f547677 100644 (file)
@@ -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.