From ec7d3f181d9e188adc5ce0288885a8b120f6c34a Mon Sep 17 00:00:00 2001 From: Brian Ashworth Date: Mon, 17 Feb 2020 17:17:20 -0500 Subject: input_cmd_events: add support for input types This adds support for input type configs to input_cmd_events. This works similar to the wildcard handling that existed where configs for the devices are stored and the type config is reset to INT_MIN so that it does not override. This also condenses the toggle_send_events and toggle_wildcard_send_events functions into a single function to reduce code duplication. --- sway/commands/input/events.c | 59 +++++++++++++++++++++++--------------------- 1 file changed, 31 insertions(+), 28 deletions(-) (limited to 'sway/commands') diff --git a/sway/commands/input/events.c b/sway/commands/input/events.c index cd2985ee..9405181a 100644 --- a/sway/commands/input/events.c +++ b/sway/commands/input/events.c @@ -74,34 +74,36 @@ static void toggle_select_send_events_for_device(struct input_config *ic, ic->send_events = mode_for_name(argv[index % argc]); } -static void toggle_send_events(struct input_config *ic, int argc, char **argv) { - struct sway_input_device *input_device = NULL; - wl_list_for_each(input_device, &server.input->devices, link) { - if (strcmp(input_device->identifier, ic->identifier) == 0) { - if (argc) { - toggle_select_send_events_for_device(ic, input_device, - argc, argv); - } else { - toggle_supported_send_events_for_device(ic, input_device); +static void toggle_send_events(int argc, char **argv) { + struct input_config *ic = config->handler_context.input_config; + bool wildcard = strcmp(ic->identifier, "*") == 0; + const char *type = strncmp(ic->identifier, "type:", strlen("type:")) == 0 + ? ic->identifier + strlen("type:") : NULL; + struct sway_input_device *device = NULL; + wl_list_for_each(device, &server.input->devices, link) { + if (wildcard || type) { + ic = new_input_config(device->identifier); + if (!ic) { + continue; } - return; + if (type && strcmp(input_device_get_type(device), type) != 0) { + continue; + } + } else if (strcmp(ic->identifier, device->identifier) != 0) { + continue; } - } -} -static void toggle_wildcard_send_events(int argc, char **argv) { - struct sway_input_device *input_device = NULL; - wl_list_for_each(input_device, &server.input->devices, link) { - struct input_config *ic = new_input_config(input_device->identifier); - if (!ic) { - break; - } if (argc) { - toggle_select_send_events_for_device(ic, input_device, argc, argv); + toggle_select_send_events_for_device(ic, device, argc, argv); } else { - toggle_supported_send_events_for_device(ic, input_device); + toggle_supported_send_events_for_device(ic, device); + } + + if (wildcard || type) { + store_input_config(ic, NULL); + } else { + return; } - store_input_config(ic, NULL); } } @@ -132,15 +134,16 @@ struct cmd_results *input_cmd_events(int argc, char **argv) { "Invalid toggle mode %s", argv[i]); } } - if (strcmp(ic->identifier, "*") == 0) { - // Update the device input configs and then reset the wildcard + + toggle_send_events(argc - 1, argv + 1); + + if (strcmp(ic->identifier, "*") == 0 || + strncmp(ic->identifier, "type:", strlen("type:")) == 0) { + // Update the device input configs and then reset the type/wildcard // config send events mode so that is does not override the device // ones. The device ones will be applied when attempting to apply - // the wildcard config - toggle_wildcard_send_events(argc - 1, argv + 1); + // the type/wildcard config ic->send_events = INT_MIN; - } else { - toggle_send_events(ic, argc - 1, argv + 1); } } else { return cmd_results_new(CMD_INVALID, -- cgit v1.2.3-54-g00ecf