}
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;
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)
OPT_MULTIPLE,
OPT_ALL,
OPT_LIBINPUT,
+ OPT_GRAB,
};
int
{ "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;
case OPT_LIBINPUT:
with_libinput = true;
break;
+ case OPT_GRAB:
+ grab = true;
+ break;
default:
usage();
rc = EXIT_INVALID_USAGE;
d = devices;
while (*d) {
- if (!init_device(&ctx, safe_strdup(*d))) {
+ if (!init_device(&ctx, safe_strdup(*d), grab)) {
strv_free(devices);
goto out;
}
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 {
goto out;
}
- if (!init_device(&ctx, path))
+ if (!init_device(&ctx, path, grab))
goto out;
}