tools: add --apply-to to debug-events and debug-gui

All configuration options will only apply to the device with the given match
mattern. This makes it easier to test things like tapping on one device but
not on the other.

Exception is the sendevents pattern which applies independently.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
This commit is contained in:
Peter Hutterer 2019-05-08 11:24:28 +10:00
parent 4f63345b60
commit 829673901c
4 changed files with 39 additions and 10 deletions

View file

@ -49,8 +49,14 @@ The default behavior is equivalent to \-\-udev "seat0".
Use verbose output
.SS libinput configuration options
.TP 8
.B \-\-apply-to="pattern"
Configuration options are only applied where the device name matches the
pattern. This pattern has no effect on the \fB\-\-disable-sendevents\fR
option.
.TP 8
.B \-\-disable-sendevents="pattern"
Set the send-events option to disabled for the devices matching patterns.
This option is not affected by the \fB\-\-apply-to="pattern"\fR option.
.TP 8
.B \-\-enable\-tap|\-\-disable\-tap
Enable or disable tap-to-click

View file

@ -219,6 +219,15 @@ tools_parse_option(int option,
"%s",
optarg);
break;
case OPT_APPLY_TO:
if (!optarg)
return 1;
snprintf(options->match,
sizeof(options->match),
"%s",
optarg);
break;
}
return 0;
@ -349,6 +358,19 @@ void
tools_device_apply_config(struct libinput_device *device,
struct tools_options *options)
{
const char *name = libinput_device_get_name(device);
if (libinput_device_config_send_events_get_modes(device) &
LIBINPUT_CONFIG_SEND_EVENTS_DISABLED &&
fnmatch(options->disable_pattern, name, 0) != FNM_NOMATCH) {
libinput_device_config_send_events_set_mode(device,
LIBINPUT_CONFIG_SEND_EVENTS_DISABLED);
}
if (strlen(options->match) > 0 &&
fnmatch(options->match, name, 0) == FNM_NOMATCH)
return;
if (options->tapping != -1)
libinput_device_config_tap_set_enabled(device, options->tapping);
if (options->tap_map != (enum libinput_config_tap_button_map)-1)
@ -389,15 +411,6 @@ tools_device_apply_config(struct libinput_device *device,
libinput_device_config_accel_set_profile(device,
options->profile);
}
if (libinput_device_config_send_events_get_modes(device) &
LIBINPUT_CONFIG_SEND_EVENTS_DISABLED &&
fnmatch(options->disable_pattern,
libinput_device_get_name(device),
0) != FNM_NOMATCH) {
libinput_device_config_send_events_set_mode(device,
LIBINPUT_CONFIG_SEND_EVENTS_DISABLED);
}
}
static char*

View file

@ -54,6 +54,7 @@ enum configuration_options {
OPT_SPEED,
OPT_PROFILE,
OPT_DISABLE_SENDEVENTS,
OPT_APPLY_TO,
};
#define CONFIGURATION_OPTIONS \
@ -77,7 +78,8 @@ enum configuration_options {
{ "set-scroll-button", required_argument, 0, OPT_SCROLL_BUTTON }, \
{ "set-profile", required_argument, 0, OPT_PROFILE }, \
{ "set-tap-map", required_argument, 0, OPT_TAP_MAP }, \
{ "set-speed", required_argument, 0, OPT_SPEED }
{ "set-speed", required_argument, 0, OPT_SPEED },\
{ "apply-to", required_argument, 0, OPT_APPLY_TO }
enum tools_backend {
BACKEND_NONE,
@ -86,6 +88,8 @@ enum tools_backend {
};
struct tools_options {
char match[256];
int tapping;
int drag;
int drag_lock;

View file

@ -175,6 +175,12 @@ class TestToolWithOptions(object):
self.run_command_success(['--{}'.format(option), str(maximum)])
self.run_command_success(['--{}={}'.format(option, maximum)])
def test_apply_to(self):
self.run_command_missing_arg(['--apply-to'])
self.run_command_success(['--apply-to', '*foo*'])
self.run_command_success(['--apply-to', 'foobar'])
self.run_command_success(['--apply-to', 'any'])
class TestDebugEvents(TestToolWithOptions, TestLibinputTool):
subtool = 'debug-events'