diff options
author | Peter Hutterer <peter.hutterer@who-t.net> | 2017-05-23 13:37:06 +1000 |
---|---|---|
committer | Peter Hutterer <peter.hutterer@who-t.net> | 2017-05-23 13:37:06 +1000 |
commit | a2a8db261aa65dae1d657a37533b4a99d711b668 (patch) | |
tree | 198aa748cbcea8e9b49f991e7f1cbf9dfd1eed77 /tools | |
parent | 1daaa07fc34f10628675ab95a681caa5bf128c66 (diff) | |
parent | f3107a78e04e279a544bf870098adf51899d43e4 (diff) |
Merge branch 'wip/libinput-tool-v2'
Diffstat (limited to 'tools')
-rw-r--r-- | tools/Makefile.am | 47 | ||||
-rw-r--r-- | tools/libinput-debug-events.c (renamed from tools/event-debug.c) | 15 | ||||
-rw-r--r-- | tools/libinput-list-devices.c | 56 | ||||
-rw-r--r-- | tools/libinput-tool.c | 161 | ||||
-rw-r--r-- | tools/libinput-tool.h | 40 | ||||
-rw-r--r-- | tools/libinput.1 | 134 | ||||
-rw-r--r-- | tools/shared.c | 36 | ||||
-rw-r--r-- | tools/shared.h | 5 |
8 files changed, 447 insertions, 47 deletions
diff --git a/tools/Makefile.am b/tools/Makefile.am index 4fc1046..77b4e74 100644 --- a/tools/Makefile.am +++ b/tools/Makefile.am @@ -1,6 +1,5 @@ noinst_PROGRAMS = event-debug ptraccel-debug -bin_PROGRAMS = libinput-list-devices libinput-debug-events -noinst_LTLIBRARIES = libshared.la +bin_PROGRAMS = libinput-list-devices libinput-debug-events libinput AM_CPPFLAGS = -I$(top_srcdir)/include \ -I$(top_srcdir)/src \ @@ -8,37 +7,51 @@ AM_CPPFLAGS = -I$(top_srcdir)/include \ AM_CFLAGS = $(GCC_CFLAGS) AM_CXXFLAGS = $(GCC_CXXFLAGS) -libshared_la_SOURCES = \ - shared.c \ - shared.h -libshared_la_CFLAGS = $(AM_CFLAGS) $(LIBEVDEV_CFLAGS) -libshared_la_LIBADD = $(LIBEVDEV_LIBS) +shared_sources = \ + shared.c \ + shared.h -event_debug_SOURCES = event-debug.c -event_debug_LDADD = ../src/libinput.la libshared.la $(LIBUDEV_LIBS) $(LIBEVDEV_LIBS) +event_debug_sources = libinput-debug-events.c $(shared_sources) +event_debug_SOURCES = libinput-debug-events.c $(shared_sources) +event_debug_LDADD = ../src/libinput.la $(LIBUDEV_LIBS) $(LIBEVDEV_LIBS) event_debug_LDFLAGS = -no-install -event_debug_CFLAGS = $(AM_CFLAGS) $(LIBUDEV_CFLAGS) $(LIBEVDEV_CFLAGS) +event_debug_CFLAGS = $(AM_CFLAGS) $(LIBUDEV_CFLAGS) $(LIBEVDEV_CFLAGS) \ + -DTOOLS_BUILD_STANDALONE=1 ptraccel_debug_SOURCES = ptraccel-debug.c ptraccel_debug_LDADD = ../src/libfilter.la ../src/libinput.la ptraccel_debug_LDFLAGS = -no-install -libinput_list_devices_SOURCES = libinput-list-devices.c -libinput_list_devices_LDADD = ../src/libinput.la libshared.la $(LIBUDEV_LIBS) -libinput_list_devices_CFLAGS = $(AM_CFLAGS) $(LIBUDEV_CFLAGS) +libinput_list_devices_SOURCES = libinput-list-devices.c $(shared_sources) +libinput_list_devices_LDADD = ../src/libinput.la $(LIBUDEV_LIBS) $(LIBEVDEV_LIBS) +libinput_list_devices_CFLAGS = $(AM_CFLAGS) $(LIBUDEV_CFLAGS) $(LIBEVDEV_CFLAGS) \ + -DTOOLS_BUILD_STANDALONE=1 dist_man1_MANS = libinput-list-devices.1 libinput_debug_events_SOURCES = $(event_debug_SOURCES) libinput_debug_events_LDADD = $(event_debug_LDADD) -libinput_debug_events_CFLAGS = $(AM_CFLAGS) $(event_debug_CFLAGS) +libinput_debug_events_CFLAGS = $(AM_CFLAGS) $(event_debug_CFLAGS) \ + -DTOOLS_BUILD_STANDALONE=1 dist_man1_MANS += libinput-debug-events.1 +libinput_SOURCES = \ + libinput-tool.c \ + libinput-tool.h \ + libinput-debug-events.c \ + libinput-list-devices.c \ + $(shared_sources) +libinput_LDADD = ../src/libinput.la $(LIBUDEV_LIBS) $(LIBEVDEV_LIBS) +libinput_CFLAGS = $(AM_CFLAGS) $(LIBUDEV_CFLAGS) $(LIBEVDEV_CFLAGS) +dist_man1_MANS += libinput.1 + if BUILD_EVENTGUI noinst_PROGRAMS += event-gui -event_gui_SOURCES = event-gui.c -event_gui_LDADD = ../src/libinput.la libshared.la $(CAIRO_LIBS) $(GTK_LIBS) $(LIBUDEV_LIBS) -event_gui_CFLAGS = $(CAIRO_CFLAGS) $(GTK_CFLAGS) $(LIBUDEV_CFLAGS) $(AM_CFLAGS) +event_gui_SOURCES = event-gui.c $(shared_sources) +event_gui_LDADD = ../src/libinput.la $(CAIRO_LIBS) $(GTK_LIBS) \ + $(LIBUDEV_LIBS) $(LIBEVDEV_LIBS) +event_gui_CFLAGS = $(CAIRO_CFLAGS) $(GTK_CFLAGS) \ + $(LIBUDEV_CFLAGS) $(LIBEVDEV_CFLAGS) $(AM_CFLAGS) event_gui_LDFLAGS = -no-install endif diff --git a/tools/event-debug.c b/tools/libinput-debug-events.c index 574fa9e..f64708d 100644 --- a/tools/event-debug.c +++ b/tools/libinput-debug-events.c @@ -39,6 +39,7 @@ #include <libinput.h> #include <libevdev/libevdev.h> +#include "libinput-tool.h" #include "shared.h" uint32_t start_time; @@ -896,7 +897,7 @@ mainloop(struct libinput *li) } int -main(int argc, char **argv) +libinput_debug_events(struct global_options *opts, int argc, char **argv) { struct libinput *li; struct timespec tp; @@ -909,7 +910,7 @@ main(int argc, char **argv) if (tools_parse_args(argc, argv, &context)) return 1; - be_quiet = context.options.quiet; + be_quiet = context.options.global_options.quiet; li = tools_open_backend(&context); if (!li) @@ -921,3 +922,13 @@ main(int argc, char **argv) return 0; } + +#if TOOLS_BUILD_STANDALONE +int +main(int argc, char **argv) +{ + struct global_options opts = {0}; + + return libinput_debug_events(&opts, argc, argv); +} +#endif diff --git a/tools/libinput-list-devices.c b/tools/libinput-list-devices.c index aad605a..a0154d3 100644 --- a/tools/libinput-list-devices.c +++ b/tools/libinput-list-devices.c @@ -34,6 +34,7 @@ #include <libinput-util.h> #include <libinput-version.h> +#include "libinput-tool.h" #include "shared.h" static const char * @@ -354,39 +355,38 @@ print_device_notify(struct libinput_event *ev) static inline void usage(void) { - printf("Usage: %s [--help|--version]\n" - "\n" +#if TOOLS_BUILD_STANDALONE + printf("Usage: %s [--help|--version]\n", program_invocation_short_name); +#else + printf("Usage: libinput list-devices [--help]\n"); +#endif + printf("\n" "This tool creates a libinput context on the default seat \"seat0\"\n" "and lists all devices recognized by libinput and the configuration options.\n" "Where multiple options are possible, the default is prefixed with \"*\".\n" "\n" "Options:\n" "--help ...... show this help\n" +#if TOOLS_BUILD_STANDALONE "--version ... show version information\n" +#endif "\n" - "This tool requires access to the /dev/input/eventX nodes.\n", - program_invocation_short_name); + "This tool requires access to the /dev/input/eventX nodes.\n"); } int -main(int argc, char **argv) +libinput_list_devices(struct global_options *opts, int argc, char **argv) { struct libinput *li; struct tools_context context; struct libinput_event *ev; +#if !TOOLS_BUILD_STANDALONE if (argc > 1) { - if (streq(argv[1], "--help")) { - usage(); - return 0; - } else if (streq(argv[1], "--version")) { - printf("%s\n", LIBINPUT_VERSION); - return 0; - } else { - usage(); - return 1; - } + usage(); + return streq(argv[1], "--help") ? EXIT_SUCCESS : EXIT_FAILURE; } +#endif tools_init_context(&context); @@ -406,5 +406,29 @@ main(int argc, char **argv) libinput_unref(li); - return 0; + return EXIT_SUCCESS; +} + +#if TOOLS_BUILD_STANDALONE +int +main(int argc, char **argv) +{ + struct global_options options = {0}; + + if (argc > 1) { + if (streq(argv[1], "--help")) { + usage(); + return 0; + } else if (streq(argv[1], "--version")) { + printf("%s\n", LIBINPUT_VERSION); + return 0; + } else { + usage(); + return 1; + } + } + + return libinput_list_devices(&options, argc - optind, &argv[optind]); } + +#endif /* TOOLS_BUILD_STANDALONE */ diff --git a/tools/libinput-tool.c b/tools/libinput-tool.c new file mode 100644 index 0000000..12204ab --- /dev/null +++ b/tools/libinput-tool.c @@ -0,0 +1,161 @@ +/* + * Copyright © 2017 Red Hat, Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +#include "config.h" + +#include <errno.h> +#include <getopt.h> +#include <stdbool.h> +#include <stdio.h> +#include <string.h> +#include <unistd.h> +#include <libudev.h> + +#include <libinput.h> +#include <libinput-util.h> +#include <libinput-version.h> + +#include "libinput-tool.h" + +void +libinput_tool_usage(void) +{ + printf("Usage: libinput [GLOBAL OPTIONS] [COMMAND] [ARGS]\n" + "\n" + "This tool creates a libinput context and interacts with that context.\n" + "For detailed information about the options below, see the" + "libinput(1) man page.\n" + "\n" + "This tool usually requires access to the /dev/input/eventX nodes.\n" + "\n" + "Global options:\n" + " --help ...... show this help\n" + " --version ... show version information\n" + " --verbose ... enable verbose output for debugging\n" + " --quiet ..... reduce output (may be used with --verbose)\n" + "\n" + "Commands:\n" + " list-devices\n" + " List all devices with their default configuration options\n" + "\n" + " debug-events\n" + " Print events to stdout\n" + "\n"); +} + +enum command { + COMMAND_NONE, + COMMAND_LIST_DEVICES, + COMMAND_DEBUG_EVENTS, +}; + +enum global_opts { + GOPT_HELP = 1, + GOPT_VERSION, + GOPT_QUIET, + GOPT_VERBOSE, +}; + +static bool +parse_args_cmd(enum command cmd, + struct global_options *global_options, + int argc, char *argv[]) +{ + optind = 0; + + switch (cmd) { + case COMMAND_NONE: + break; + case COMMAND_LIST_DEVICES: + return libinput_list_devices(global_options, argc, argv); + case COMMAND_DEBUG_EVENTS: + return libinput_debug_events(global_options, argc, argv); + } + return true; +} + +int +main(int argc, char **argv) +{ + enum command cmd = COMMAND_NONE; + const char *command; + int option_index = 0; + struct global_options global_options = {0}; + + if (argc == 1) { + libinput_tool_usage(); + return false; + } + + while (1) { + int c; + static struct option opts[] = { + { "help", no_argument, 0, GOPT_HELP }, + { "version", no_argument, 0, GOPT_VERSION }, + { "quiet", no_argument, 0, GOPT_QUIET }, + { "verbose", no_argument, 0, GOPT_VERBOSE }, + { 0, 0, 0, 0} + }; + + c = getopt_long(argc, argv, "+h", opts, &option_index); + if (c == -1) + break; + + switch(c) { + case 'h': + case GOPT_HELP: + libinput_tool_usage(); + exit(0); + case GOPT_VERSION: + printf("%s\n", LIBINPUT_VERSION); + exit(0); + case GOPT_VERBOSE: + global_options.verbose = true; + break; + case GOPT_QUIET: + global_options.quiet = true; + break; + default: + libinput_tool_usage(); + return false; + } + } + + if (optind > argc) { + libinput_tool_usage(); + return false; + } + + command = argv[optind]; + + if (streq(command, "list-devices")) { + cmd = COMMAND_LIST_DEVICES; + } else if (streq(command, "debug-events")) { + cmd = COMMAND_DEBUG_EVENTS; + } else { + fprintf(stderr, "Invalid command '%s'\n", command); + return EXIT_FAILURE; + } + + return parse_args_cmd(cmd, &global_options, argc - optind, &argv[optind]); +} diff --git a/tools/libinput-tool.h b/tools/libinput-tool.h new file mode 100644 index 0000000..c451857 --- /dev/null +++ b/tools/libinput-tool.h @@ -0,0 +1,40 @@ +/* + * Copyright © 2017 Red Hat, Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +#ifndef LIBINPUT_TOOL_H +#define LIBINPUT_TOOL_H 1 + +#include "config.h" + +#include <stdbool.h> + +struct global_options { + bool verbose; + bool quiet; +}; + +void libinput_tool_usage(void); +int libinput_list_devices(struct global_options *opts, int argc, char **argv); +int libinput_debug_events(struct global_options *opts, int argc, char **argv); + +#endif diff --git a/tools/libinput.1 b/tools/libinput.1 new file mode 100644 index 0000000..0dd596e --- /dev/null +++ b/tools/libinput.1 @@ -0,0 +1,134 @@ +.TH LIBINPUT "1" +.SH NAME +libinput \- tool to interface with libinput +.SH SYNOPSIS +.B libinput [GLOBAL OPTIONS] [COMMAND] [ARGS] +.SH DESCRIPTION +.PP +The +.I libinput +tool creates a libinput context on the default seat "seat0" and interacts +with that libinput context. +.PP +This tool usually needs to be run as root to have access to the +/dev/input/eventX nodes. +.PP +The context created by this tool is a new libinput context and independent +of that created by the X.Org libinput driver, the Wayland compositor or any +other process that utilizes libinput (henceforth called "the caller"). +Configuration options set in this context do not affect any other libinput +contexts. +.SH GLOBAL OPTIONS +These options are independent of any +.B COMMAND +.TP 8 +.B --help +Print help and exit +.TP 8 +.B --version +Print the version and exit +.TP 8 +.B --verbose +Enable verbose mode. In verbose mode, libinput will print a number of +debug messages to stdout. The exact behavior of verbose mode depends on the +.B COMMAND. +.TP 8 +.B --quiet +Enable quiet mode. In quiet mode, most messages normally printed to stdout +will be omitted. The exact behavior of quiet mode depends on the +.B COMMAND. + +.SH COMMANDS +All commands support a +.B --help +argument that prints command-specific usage +information (e.g. +.B libinput debug-events --help) +.TP 8 +.B debug-events [ARGS] +Print all events as seen by libinput. See section +.B debug-events +.TP 8 +.B list-devices +List all devices recognized by libinput. See section +.B list-devices + +.SS debug-events [...] +Print all events from these devices. +.PP +This is a debugging tool only, its output may change at any time. Do not +rely on the output. +.PP +.B --device /path/to/device +.IP +Use a path backend for the device for the given path. This option is +mutually exclusive with the +.B --udev +option. +.PP +.B --grab +.IP +Exclusively grab all devices. This will prevent events from being sent to +any other caller. It is recommended this option is only used together with +the +.B --device +option, otherwise a user may not be able to terminate this tool. +.PP +.B --udev <name> +.IP +Use a udev backend for this context with the given seat name. This option is +mutually exclusive with the +.B --device +option. +.PP +.B --show-keycodes +.IP +Print all keycodes as-is. Without this argument, most key events shown by +this tool are obfuscated to avoid passwords and other sensitive +information showing up in the output. +.PP +.B --enable-<feature> +or +.B --disable-<feature> +.IP +Enable or disable the given feature. For a full list of features, see the +.B --help +output. Requests to enable or disable a feature on a device that does +not provide that feature, or where that feature is already enabled or +disabled will be silently ignored. +.PP +.B --set-<feature>=<value> +.IP +Set the given feature to the given value. For a full list of features, see +the +.B --help +output. Requests to set a feature on a device that does not provide that +feature, or where that feature is already set to that value, or where the +value is not available on that device will be silently ignored + +.SS list-devices +List all devices recognized by libinput. Each device shows available +configurations the respective +.B default +configuration setting. +.PP +For configuration options that allow multiple different settings (e.g. +scrolling), all available settings are listed. The default setting is +prefixed by an asterisk (*). +.PP +Note that some specific feature may still be available on a device even when +no configuration is exposed, a lack of a configuration option does not +necessarily mean that this feature does not work. +.PP +Note that this command only lists +.B default +configuration settings, settings modified in other contextx by the caller +are not reflected in this tool. +.SH NOTES +.PP +A device may be recognized by this libinput context but not handled by the +X.Org libinput driver or the Wayland compositor. +.PP +.SH SEE ALSO +.PP +libinput(4) diff --git a/tools/shared.c b/tools/shared.c index 830e0cb..af23415 100644 --- a/tools/shared.c +++ b/tools/shared.c @@ -34,6 +34,7 @@ #include <libevdev/libevdev.h> #include <libinput-util.h> +#include "libinput-tool.h" #include "shared.h" enum options { @@ -94,8 +95,13 @@ log_handler(struct libinput *li, void tools_usage(void) { - printf("Usage: %s [options] [--udev [<seat>]|--device /dev/input/event0]\n" - "--udev <seat>.... Use udev device discovery (default).\n" +#if TOOLS_BUILD_STANDALONE + printf("Usage: %s [options] [--udev [<seat>]|--device /dev/input/event0]\n", + program_invocation_short_name); +#else + printf("Usage: libinput debug-events [options] [--udev [<seat>]|--device /dev/input/event0]\n"); +#endif + printf("--udev <seat>.... Use udev device discovery (default).\n" " Specifying a seat ID is optional.\n" "--device /path/to/device .... open the given device only\n" "\n" @@ -127,10 +133,12 @@ tools_usage(void) "\n" "Other options:\n" "--grab .......... Exclusively grab all openend devices\n" - "--verbose ....... Print debugging output.\n" - "--quiet ......... Only print libinput messages, useful in combination with --verbose.\n" - "--help .......... Print this help.\n", - program_invocation_short_name); + "--help .......... Print this help.\n" + ); +#if TOOLS_BUILD_STANDALONE + printf("--verbose ....... Print debugging output.\n" + "--quiet ......... Only print libinput messages, useful in combination with --verbose.\n"); +#endif } void @@ -172,8 +180,10 @@ tools_parse_args(int argc, char **argv, struct tools_context *context) { "udev", no_argument, 0, OPT_UDEV }, { "grab", no_argument, 0, OPT_GRAB }, { "help", no_argument, 0, OPT_HELP }, +#if TOOLS_BUILD_STANDALONE { "verbose", no_argument, 0, OPT_VERBOSE }, { "quiet", no_argument, 0, OPT_QUIET }, +#endif { "enable-tap", no_argument, 0, OPT_TAP_ENABLE }, { "disable-tap", no_argument, 0, OPT_TAP_DISABLE }, { "enable-drag", no_argument, 0, OPT_DRAG_ENABLE }, @@ -224,7 +234,7 @@ tools_parse_args(int argc, char **argv, struct tools_context *context) options->grab = 1; break; case OPT_VERBOSE: - options->verbose = 1; + options->global_options.verbose = 1; break; case OPT_TAP_ENABLE: options->tapping = 1; @@ -363,7 +373,7 @@ tools_parse_args(int argc, char **argv, struct tools_context *context) options->show_keycodes = true; break; case OPT_QUIET: - options->quiet = true; + options->global_options.quiet = true; break; default: tools_usage(); @@ -482,9 +492,15 @@ tools_open_backend(struct tools_context *context) struct tools_options *options = &context->options; if (options->backend == BACKEND_UDEV) { - li = open_udev(&interface, context, options->seat, options->verbose); + li = open_udev(&interface, + context, + options->seat, + options->global_options.verbose); } else if (options->backend == BACKEND_DEVICE) { - li = open_device(&interface, context, options->device, options->verbose); + li = open_device(&interface, + context, + options->device, + options->global_options.verbose); } else abort(); diff --git a/tools/shared.h b/tools/shared.h index d19d52a..03838e1 100644 --- a/tools/shared.h +++ b/tools/shared.h @@ -28,20 +28,21 @@ #include <libinput.h> +#include "libinput-tool.h" + enum tools_backend { BACKEND_DEVICE, BACKEND_UDEV }; struct tools_options { + struct global_options global_options; enum tools_backend backend; const char *device; /* if backend is BACKEND_DEVICE */ const char *seat; /* if backend is BACKEND_UDEV */ int grab; /* EVIOCGRAB */ bool show_keycodes; /* show keycodes */ - bool quiet; /* only print libinput messages */ - int verbose; int tapping; int drag; int drag_lock; |