diff --git a/tools/libinput-debug-events.man b/tools/libinput-debug-events.man index 582f3375..e5a39e2e 100644 --- a/tools/libinput-debug-events.man +++ b/tools/libinput-debug-events.man @@ -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 diff --git a/tools/shared.c b/tools/shared.c index ee8e6ae0..10dda8ce 100644 --- a/tools/shared.c +++ b/tools/shared.c @@ -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* diff --git a/tools/shared.h b/tools/shared.h index df7d6f15..e2a6d662 100644 --- a/tools/shared.h +++ b/tools/shared.h @@ -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; diff --git a/tools/test-tool-option-parsing.py b/tools/test-tool-option-parsing.py index 169bef8f..64a9ce0b 100755 --- a/tools/test-tool-option-parsing.py +++ b/tools/test-tool-option-parsing.py @@ -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'