Commit 328bc99d authored by Peter Hutterer's avatar Peter Hutterer

tools: add "libinput measure touchpad-tap"

This is the first tool of many more to come to enable users to gather
information aobut their devices and/or usage of these devices. Previously,
these required the users to record events, submit them to a bugzilla, have me
run various scripts over it and then decree that the scripts have spoken.
Push some of this into the hands of the users so they can query the numbers
locally and start investigating (or at least get an idea of what's happening).

This tool measures the time deltas between touch up and touch down and prints
a basic summary, together with the ability to print a dat file with the data
for visualization by e.g. gnuplot. Eventually, more of the current analysis
scripts will be moved into this or other helpers.
Signed-off-by: Peter Hutterer's avatarPeter Hutterer <peter.hutterer@who-t.net>
parent 1332d883
......@@ -373,6 +373,26 @@ executable('libinput-list-devices',
)
install_man('tools/libinput-list-devices.1')
libinput_measure_sources = [ 'tools/libinput-measure.c' ]
executable('libinput-measure',
libinput_measure_sources,
dependencies : deps_tools,
include_directories : include_directories('src'),
install_dir : libinput_tool_path,
install : true,
)
install_man('tools/libinput-measure.1')
libinput_measure_touchpad_tap_sources = [ 'tools/libinput-measure-touchpad-tap.c' ]
executable('libinput-measure-touchpad-tap',
libinput_measure_touchpad_tap_sources,
dependencies : deps_tools,
include_directories : include_directories('src'),
install_dir : libinput_tool_path,
install : true,
)
install_man('tools/libinput-measure-touchpad-tap.1')
if get_option('debug-gui')
dep_gtk = dependency('gtk+-3.0')
dep_cairo = dependency('cairo')
......
......@@ -14,7 +14,8 @@ AM_CXXFLAGS = $(GCC_CXXFLAGS)
libshared_la_SOURCES = \
shared.c \
shared.h
libshared_la_CFLAGS = $(AM_CFLAGS) $(LIBEVDEV_CFLAGS)
libshared_la_CFLAGS = $(AM_CFLAGS) $(LIBEVDEV_CFLAGS) \
-DLIBINPUT_TOOL_PATH="\"@libexecdir@/libinput\""
libshared_la_LIBADD = $(LIBEVDEV_LIBS)
ptraccel_debug_SOURCES = ptraccel-debug.c
......@@ -23,8 +24,7 @@ ptraccel_debug_LDFLAGS = -no-install
libinput_SOURCES = libinput-tool.c
libinput_LDADD = ../src/libinput.la libshared.la $(LIBUDEV_LIBS) $(LIBEVDEV_LIBS)
libinput_CFLAGS = $(AM_CFLAGS) $(LIBUDEV_CFLAGS) $(LIBEVDEV_CFLAGS) \
-DLIBINPUT_TOOL_PATH="\"@libexecdir@/libinput\""
libinput_CFLAGS = $(AM_CFLAGS) $(LIBUDEV_CFLAGS) $(LIBEVDEV_CFLAGS)
dist_man1_MANS = libinput.1
tools_PROGRAMS += libinput-list-devices
......@@ -39,6 +39,20 @@ libinput_debug_events_LDADD = ../src/libinput.la libshared.la $(LIBUDEV_LIBS) $(
libinput_debug_events_CFLAGS = $(AM_CFLAGS) $(LIBUDEV_CFLAGS) $(LIBEVDEV_CFLAGS)
dist_man1_MANS += libinput-debug-events.1
tools_PROGRAMS += libinput-measure
libinput_measure_SOURCES = libinput-measure.c $(shared_sources)
libinput_measure_LDADD = ../src/libinput.la libshared.la $(LIBUDEV_LIBS) $(LIBEVDEV_LIBS)
libinput_measure_CFLAGS = $(AM_CFLAGS) $(LIBUDEV_CFLAGS) $(LIBEVDEV_CFLAGS) \
-DLIBINPUT_TOOL_PATH="\"@libexecdir@/libinput\""
dist_man1_MANS += libinput-measure.1
tools_PROGRAMS += libinput-measure-touchpad-tap
libinput_measure_touchpad_tap_SOURCES = \
libinput-measure-touchpad-tap.c
libinput_measure_touchpad_tap_LDADD = ../src/libinput.la libshared.la $(LIBUDEV_LIBS) $(LIBEVDEV_LIBS)
libinput_measure_touchpad_tap_CFLAGS = $(AM_CFLAGS) $(LIBUDEV_CFLAGS) $(LIBEVDEV_CFLAGS)
dist_man1_MANS += libinput-measure-touchpad-tap.1
if BUILD_DEBUG_GUI
tools_PROGRAMS += libinput-debug-gui
libinput_debug_gui_SOURCES = libinput-debug-gui.c
......
.TH LIBINPUT-MEASURE-TOUCHPAD-TAP "1"
.SH NAME
libinput-measure-touchpad-tap \- measure tap-to-click properities of devices
.SH SYNOPSIS
.B libinput measure touchpad-tap [--help] [--format=<format>] [/dev/input/event0]
.SH DESCRIPTION
.PP
The
.B "libinput measure touchpad-tap"
tool measures properties of the tap-to-click behavior of the user. This is
an interactive tool. When executed, the tool will prompt the user to
interact with the touchpad. On termination, the tool prints a summary of the
tap interactions seen. This data should be attached to any tap-related bug
report.
.PP
For a full description on how libinput's tap-to-click behavior works, see
the online documentation here:
.I https://wayland.freedesktop.org/libinput/doc/latest/tapping.html
.PP
This is a debugging tool only, its output may change at any time. Do not
rely on the output.
.PP
This tool usually needs to be run as root to have access to the
/dev/input/eventX nodes.
.SH OPTIONS
.TP 8
.B --help
Print help
.TP 8
.B --format=summary|dat
Specify the data format to be printed. The default (or if
.B --format
is omitted) is "summary". See section
.B DATA FORMATS
.SH DATA FORMATS
This section describes the data formats printed with the
.B --format
commandline argument. Note that any of the output may change at any time.
.RE
.PP
summary
.RS 4
The
.I summary
format prints a summary of the data collected. This format is useful to
get a quick overview of a user's tapping behavior and why some taps may or
may not be detected.
.RE
.PP
dat
.RS 4
The
.I dat
format prints the touch sequence data (raw and processed) in column-style
format, suitable for processing by other tools such as
.B gnuplot(1).
The data is aligned in one row per touch with each column containing a
separate data entry.
.B libinput-measure-touchpad-tap
prints comments at the top of the file to describe each column.
.PP
.B WARNING:
The data contained in the output is grouped by different sort orders. For
example, the first few columns may list tap information in the 'natural'
sort order (i.e. as they occured), the data in the next few columns may list
tap information sorted by the delta time between touch down and touch up.
Comparing columns across these group boundaries will compare data of two
different touch points and result in invalid analysis.
.SH LIBINPUT
Part of the
.B libinput(1)
suite
This diff is collapsed.
.TH LIBINPUT-MEASURE "1"
.SH NAME
libinput-measure \- measure properties of devices
.SH SYNOPSIS
.B libinput measure [--help] <feature> [<args>]
.SH DESCRIPTION
.PP
The
.B "libinput measure"
tool measures properties of one (or more) devices. Depending on what is to
be measured, this too may not create a libinput context.
.PP
This is a debugging tool only, its output may change at any time. Do not
rely on the output.
.PP
This tool usually needs to be run as root to have access to the
/dev/input/eventX nodes.
.SH OPTIONS
.TP 8
.B --help
Print help
.SH FEATURES
Features that can be measured include
.TP 8
.B libinput-measure-touchpad-tap-time(1)
Measure tap-to-click time.
.SH LIBINPUT
Part of the
.B libinput(1)
suite
/*
* 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-util.h>
#include "shared.h"
static inline void
usage(void)
{
printf("Usage: libinput measure [--help] FEATURE [/dev/input/event0]\n");
printf("\n"
"Collect measurements related to FEATURE on the given device.\n"
"\n"
"Options:\n"
"--help ...... show this help\n"
"\n"
"Available features are:\n"
" touchpad-tap-time\n"
" Measures the time for tap-to-click interactions\n"
" "
"For information about each feature, see the --help output for that feature.\n"
"\n"
"This tool requires access to the /dev/input/eventX nodes.\n");
}
int
main(int argc, char **argv)
{
int option_index = 0;
while (1) {
int c;
static struct option opts[] = {
{ "help", no_argument, 0, 'h' },
{ 0, 0, 0, 0}
};
c = getopt_long(argc, argv, "h", opts, &option_index);
if (c == -1)
break;
switch(c) {
case 'h':
usage();
return EXIT_SUCCESS;
default:
usage();
return EXIT_FAILURE;
}
}
if (optind >= argc) {
usage();
return EXIT_FAILURE;
}
argc--;
argv++;
return tools_exec_command("libinput-measure", argc, argv);
}
......@@ -35,6 +35,7 @@
#include <libinput-util.h>
#include <libinput-version.h>
#include "shared.h"
static void
usage(void)
{
......@@ -61,6 +62,9 @@ usage(void)
"\n"
" debug-gui\n"
" Display a simple GUI to visualize libinput's events.\n"
"\n"
" measure\n"
" Measure various device properties. See the --help output for more info\n"
"\n");
}
......@@ -69,52 +73,6 @@ enum global_opts {
GOPT_VERSION,
};
static inline void
setup_path(void)
{
const char *path = getenv("PATH");
char new_path[PATH_MAX];
snprintf(new_path,
sizeof(new_path),
"%s:%s",
LIBINPUT_TOOL_PATH,
path ? path : "");
setenv("PATH", new_path, 1);
}
static int
exec_command(int real_argc, char **real_argv)
{
char *argv[64] = {NULL};
char executable[128];
const char *command;
int rc;
assert((size_t)real_argc < ARRAY_LENGTH(argv));
command = real_argv[0];
rc = snprintf(executable, sizeof(executable), "libinput-%s", command);
if (rc >= (int)sizeof(executable)) {
usage();
return EXIT_FAILURE;
}
argv[0] = executable;
for (int i = 1; i < real_argc; i++)
argv[i] = real_argv[i];
setup_path();
rc = execvp(executable, argv);
fprintf(stderr,
"Failed to execute '%s' (%s)\n",
command,
strerror(errno));
return EXIT_FAILURE;
}
int
main(int argc, char **argv)
{
......@@ -154,5 +112,5 @@ main(int argc, char **argv)
argv += optind;
argc -= optind;
return exec_command(argc, argv);
return tools_exec_command("libinput-", argc, argv);
}
......@@ -44,6 +44,12 @@ Show a GUI to visualize libinput's events.
.TP 8
.B libinput-list-devices(1)
List all devices recognized by libinput.
.TP 8
.B libinput-measure(1)
Measure various properties of devices.
.TP 8
.B libinput-measure-touchpad-tap(1)
Measure tap-to-click time.
.SH LIBINPUT
Part of the
.B libinput(1)
......
......@@ -29,6 +29,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include <libudev.h>
#include <libevdev/libevdev.h>
......@@ -546,3 +547,133 @@ tools_device_apply_config(struct libinput_device *device,
options->profile);
}
}
static char*
find_device(const char *udev_tag)
{
struct udev *udev;
struct udev_enumerate *e;
struct udev_list_entry *entry;
struct udev_device *device;
const char *path, *sysname;
char *device_node = NULL;
udev = udev_new();
e = udev_enumerate_new(udev);
udev_enumerate_add_match_subsystem(e, "input");
udev_enumerate_scan_devices(e);
udev_list_entry_foreach(entry, udev_enumerate_get_list_entry(e)) {
path = udev_list_entry_get_name(entry);
device = udev_device_new_from_syspath(udev, path);
if (!device)
continue;
sysname = udev_device_get_sysname(device);
if (strncmp("event", sysname, 5) != 0) {
udev_device_unref(device);
continue;
}
if (udev_device_get_property_value(device, udev_tag))
device_node = strdup(udev_device_get_devnode(device));
udev_device_unref(device);
if (device_node)
break;
}
udev_enumerate_unref(e);
udev_unref(udev);
return device_node;
}
bool
find_touchpad_device(char *path, size_t path_len)
{
char *devnode = find_device("ID_INPUT_TOUCHPAD");
if (devnode) {
snprintf(path, path_len, "%s", devnode);
free(devnode);
}
return devnode != NULL;
}
bool
is_touchpad_device(const char *devnode)
{
struct udev *udev;
struct udev_device *dev = NULL;
struct stat st;
bool is_touchpad = false;
if (stat(devnode, &st) < 0)
return false;
udev = udev_new();
dev = udev_device_new_from_devnum(udev, 'c', st.st_rdev);
if (!dev)
goto out;
is_touchpad = udev_device_get_property_value(dev, "ID_INPUT_TOUCHPAD");
out:
if (dev)
udev_device_unref(dev);
udev_unref(udev);
return is_touchpad;
}
static inline void
setup_path(void)
{
const char *path = getenv("PATH");
char new_path[PATH_MAX];
snprintf(new_path,
sizeof(new_path),
"%s:%s",
LIBINPUT_TOOL_PATH,
path ? path : "");
setenv("PATH", new_path, 1);
}
int
tools_exec_command(const char *prefix, int real_argc, char **real_argv)
{
char *argv[64] = {NULL};
char executable[128];
const char *command;
int rc;
assert((size_t)real_argc < ARRAY_LENGTH(argv));
command = real_argv[0];
rc = snprintf(executable,
sizeof(executable),
"%s-%s",
prefix,
command);
if (rc >= (int)sizeof(executable)) {
fprintf(stderr, "Failed to assemble command.\n");
return EXIT_FAILURE;
}
argv[0] = executable;
for (int i = 1; i < real_argc; i++)
argv[i] = real_argv[i];
setup_path();
rc = execvp(executable, argv);
fprintf(stderr,
"Failed to execute '%s' (%s)\n",
command,
strerror(errno));
return EXIT_FAILURE;
}
......@@ -71,5 +71,9 @@ struct libinput* tools_open_backend(struct tools_context *context);
void tools_device_apply_config(struct libinput_device *device,
struct tools_options *options);
void tools_usage(const char *command);
int tools_exec_command(const char *prefix, int argc, char **argv);
bool find_touchpad_device(char *path, size_t path_len);
bool is_touchpad_device(const char *devnode);
#endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment