diff --git a/tools/libinput-debug-events.c b/tools/libinput-debug-events.c index aa8dfee1..bce219cb 100644 --- a/tools/libinput-debug-events.c +++ b/tools/libinput-debug-events.c @@ -179,8 +179,11 @@ mainloop(struct libinput *li) } static void -usage(void) { +usage(struct option *opts) { printf("Usage: libinput debug-events [options] [--udev |--device /dev/input/event0 ...]\n"); + + if (opts) + tools_print_usage_option_list(opts); } int @@ -232,7 +235,7 @@ main(int argc, char **argv) exit(EXIT_INVALID_USAGE); break; case 'h': - usage(); + usage(opts); exit(EXIT_SUCCESS); break; case OPT_SHOW_KEYCODES: @@ -244,7 +247,7 @@ main(int argc, char **argv) case OPT_DEVICE: if (backend == BACKEND_UDEV || ndevices >= ARRAY_LENGTH(seat_or_devices)) { - usage(); + usage(NULL); return EXIT_INVALID_USAGE; } @@ -254,7 +257,7 @@ main(int argc, char **argv) case OPT_UDEV: if (backend == BACKEND_DEVICE || ndevices >= ARRAY_LENGTH(seat_or_devices)) { - usage(); + usage(NULL); return EXIT_INVALID_USAGE; } @@ -274,7 +277,7 @@ main(int argc, char **argv) break; default: if (tools_parse_option(c, optarg, &options) != 0) { - usage(); + usage(NULL); return EXIT_INVALID_USAGE; } break; @@ -284,13 +287,13 @@ main(int argc, char **argv) if (optind < argc) { if (backend == BACKEND_UDEV) { - usage(); + usage(NULL); return EXIT_INVALID_USAGE; } backend = BACKEND_DEVICE; do { if (ndevices >= ARRAY_LENGTH(seat_or_devices)) { - usage(); + usage(NULL); return EXIT_INVALID_USAGE; } seat_or_devices[ndevices++] = argv[optind]; diff --git a/tools/libinput-debug-gui.c b/tools/libinput-debug-gui.c index 858093ba..579f59d6 100644 --- a/tools/libinput-debug-gui.c +++ b/tools/libinput-debug-gui.c @@ -1883,8 +1883,11 @@ sockets_init(struct libinput *li) } static void -usage(void) { +usage(struct option *opts) { printf("Usage: libinput debug-gui [options] [--udev |[--device] /dev/input/event0]\n"); + + if (opts) + tools_print_usage_option_list(opts); } static gboolean @@ -1948,7 +1951,7 @@ main(int argc, char **argv) exit(EXIT_INVALID_USAGE); break; case 'h': - usage(); + usage(opts); exit(0); break; case OPT_DEVICE: @@ -1967,7 +1970,7 @@ main(int argc, char **argv) break; default: if (tools_parse_option(c, optarg, &options) != 0) { - usage(); + usage(NULL); return EXIT_INVALID_USAGE; } break; @@ -1977,7 +1980,7 @@ main(int argc, char **argv) if (optind < argc) { if (optind < argc - 1 || backend != BACKEND_NONE) { - usage(); + usage(NULL); return EXIT_INVALID_USAGE; } backend = BACKEND_DEVICE; diff --git a/tools/shared.h b/tools/shared.h index 35e2808f..97d5abab 100644 --- a/tools/shared.h +++ b/tools/shared.h @@ -30,6 +30,8 @@ #include #include +#include "util-strings.h" + #define EXIT_INVALID_USAGE 2 extern uint32_t log_serial; @@ -111,6 +113,24 @@ enum configuration_options { { "set-calibration", required_argument, 0, OPT_CALIBRATION }, \ { "set-area", required_argument, 0, OPT_AREA } +static inline void +tools_print_usage_option_list(struct option *opts) +{ + printf("Options:\n"); + + struct option *o = opts; + while (o && o->name) { + if (strstartswith(o->name, "enable-") && + strstartswith((o+1)->name, "disable-")) { + printf(" --%s/--%s\n", o->name, (o+1)->name); + o++; + } else { + printf(" --%s\n", o->name); + } + o++; + } +} + enum tools_backend { BACKEND_NONE, BACKEND_DEVICE,