[PATCH libinput 4/4] tools: hook libinput-debug-events into the libinput tool

Peter Hutterer peter.hutterer at who-t.net
Tue May 16 23:02:32 UTC 2017


Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
---
 meson.build                   |  7 +++--
 tools/Makefile.am             |  8 ++++--
 tools/libinput-debug-events.c | 15 +++++++++--
 tools/libinput-tool.c         |  8 ++++++
 tools/libinput-tool.h         |  1 +
 tools/libinput.1              | 60 ++++++++++++++++++++++++++++++++++++++++++-
 tools/shared.c                | 36 ++++++++++++++++++--------
 tools/shared.h                |  5 ++--
 8 files changed, 121 insertions(+), 19 deletions(-)

diff --git a/meson.build b/meson.build
index 090536b5..1606401c 100644
--- a/meson.build
+++ b/meson.build
@@ -344,6 +344,7 @@ executable('event-debug',
 	   event_debug_sources,
 	   dependencies : dep_libinput,
 	   include_directories : include_directories('src'),
+	   c_args : [ '-DTOOLS_BUILD_STANDALONE=1' ],
 	   install : false
 	   )
 
@@ -352,6 +353,7 @@ executable('libinput-debug-events',
 	   libinput_debug_events_sources,
 	   dependencies : dep_libinput,
 	   include_directories : include_directories('src'),
+	   c_args : [ '-DTOOLS_BUILD_STANDALONE=1' ],
 	   install : true
 	   )
 
@@ -360,11 +362,12 @@ executable('libinput-list-devices',
 	   libinput_list_devices_sources,
 	   dependencies : [ dep_libinput ],
 	   include_directories : include_directories('src'),
-	   c_args : [ '-DTOOLS_BUILD_STANDALONE=1' ]
+	   c_args : [ '-DTOOLS_BUILD_STANDALONE=1' ],
 	   install : true,
 	   )
 
-libinput_sources = [ 'tools/libinput-tool.c' ] + libinput_list_devices_sources
+libinput_sources = [ 'tools/libinput-tool.c' ] + libinput_list_devices_sources + libinput_debug_events_sources
+
 executable('libinput',
 	   libinput_sources,
 	   dependencies : dep_libinput,
diff --git a/tools/Makefile.am b/tools/Makefile.am
index 94765ced..77b4e74c 100644
--- a/tools/Makefile.am
+++ b/tools/Makefile.am
@@ -11,10 +11,12 @@ shared_sources = \
 		 shared.c \
 		 shared.h
 
+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
@@ -28,12 +30,14 @@ 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)
diff --git a/tools/libinput-debug-events.c b/tools/libinput-debug-events.c
index 574fa9ed..f64708d0 100644
--- a/tools/libinput-debug-events.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-tool.c b/tools/libinput-tool.c
index b20ed0f3..12204abd 100644
--- a/tools/libinput-tool.c
+++ b/tools/libinput-tool.c
@@ -57,12 +57,16 @@ libinput_tool_usage(void)
 	       "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 {
@@ -84,6 +88,8 @@ parse_args_cmd(enum command cmd,
 		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;
 }
@@ -144,6 +150,8 @@ main(int argc, char **argv)
 
 	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;
diff --git a/tools/libinput-tool.h b/tools/libinput-tool.h
index 7b3b8b69..c4518579 100644
--- a/tools/libinput-tool.h
+++ b/tools/libinput-tool.h
@@ -35,5 +35,6 @@ struct global_options {
 
 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
index 2f2476e4..0dd596e6 100644
--- a/tools/libinput.1
+++ b/tools/libinput.1
@@ -42,12 +42,70 @@ will be omitted. The exact behavior of quiet mode depends on the
 All commands support a
 .B --help
 argument that prints command-specific usage
-information
+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
diff --git a/tools/shared.c b/tools/shared.c
index 830e0cb4..af23415f 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 d19d52aa..03838e14 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;
-- 
2.12.2



More information about the wayland-devel mailing list