diff options
-rw-r--r-- | tools/libinput-record.c | 71 | ||||
-rw-r--r-- | tools/libinput-record.man | 8 |
2 files changed, 77 insertions, 2 deletions
diff --git a/tools/libinput-record.c b/tools/libinput-record.c index 15d20a57..73336957 100644 --- a/tools/libinput-record.c +++ b/tools/libinput-record.c @@ -613,6 +613,39 @@ select_device(void) return device_path; } +static inline char ** +all_devices(void) +{ + struct dirent **namelist; + int ndev; + int rc; + char **devices = NULL; + + ndev = scandir("/dev/input", &namelist, is_event_node, versionsort); + if (ndev <= 0) + return NULL; + + devices = zalloc((ndev + 1)* sizeof *devices); /* NULL-terminated */ + for (int i = 0; i < ndev; i++) { + char *device_path; + + rc = xasprintf(&device_path, + "/dev/input/%s", + namelist[i]->d_name); + if (rc == -1) + goto error; + + devices[i] = device_path; + } + + return devices; + +error: + if (devices) + strv_free(devices); + return NULL; +} + static char * init_output_file(const char *file, bool is_prefix) { @@ -843,7 +876,7 @@ init_device(struct record_context *ctx, char *path) static inline void usage(void) { - printf("Usage: %s [--help] [--multiple] [--autorestart] [--output-file filename] [/dev/input/event0] [...]\n" + printf("Usage: %s [--help] [--multiple|--all] [--autorestart] [--output-file filename] [/dev/input/event0] [...]\n" "Common use-cases:\n" "\n" " sudo %s -o recording.yml\n" @@ -871,6 +904,7 @@ enum options { OPT_OUTFILE, OPT_KEYCODES, OPT_MULTIPLE, + OPT_ALL, }; int @@ -885,12 +919,13 @@ main(int argc, char **argv) { "output-file", required_argument, 0, OPT_OUTFILE }, { "show-keycodes", no_argument, 0, OPT_KEYCODES }, { "multiple", no_argument, 0, OPT_MULTIPLE }, + { "all", no_argument, 0, OPT_ALL }, { "help", no_argument, 0, OPT_HELP }, { 0, 0, 0, 0 }, }; struct record_device *d, *tmp; const char *output_arg = NULL; - bool multiple = false; + bool multiple = false, all = false; int ndevices; int rc = 1; @@ -928,9 +963,18 @@ main(int argc, char **argv) case OPT_MULTIPLE: multiple = true; break; + case OPT_ALL: + all = true; + break; } } + if (all && multiple) { + fprintf(stderr, + "Only one of --multiple and --all allowed.\n"); + goto out; + } + if (ctx.timeout > 0 && output_arg == NULL) { fprintf(stderr, "Option --autorestart requires --output-file\n"); @@ -960,6 +1004,29 @@ main(int argc, char **argv) if (!init_device(&ctx, devnode)) goto out; } + } else if (all) { + char **devices; /* NULL-terminated */ + char **d; + + if (output_arg == NULL) { + fprintf(stderr, + "Option --all requires --output-file\n"); + goto out; + } + + + devices = all_devices(); + d = devices; + + while (*d) { + if (!init_device(&ctx, safe_strdup(*d))) { + strv_free(devices); + goto out; + } + d++; + } + + strv_free(devices); } else { char *path; diff --git a/tools/libinput-record.man b/tools/libinput-record.man index 4a926919..8f9787f4 100644 --- a/tools/libinput-record.man +++ b/tools/libinput-record.man @@ -22,6 +22,14 @@ If unsure, run without any arguments. .B \-\-help Print help .TP 8 +.B \-\-all +Record all \fI/dev/input/event*\fR devices available on the system. This +option should be used in exceptional cases only, the output file is almost +always too noisy and replaying the recording may not be possible. Use +\fB\-\-multiple\fR instead. +This option requires that a \fB\-\-output-file\fR is specified and may not +be used together with \fB\-\-multiple\fR. +.TP 8 .B \-\-autorestart=s Terminate the current recording after .I s |