mirror of
https://gitlab.freedesktop.org/libinput/libinput.git
synced 2025-12-30 02:30:07 +01:00
tools/record: add --grab option
Useful to record devices like power buttons, lid switches, etc. Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
This commit is contained in:
parent
7dee616621
commit
2d641e6b7b
2 changed files with 25 additions and 5 deletions
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue