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.
master
Brian Ashworth 5 years ago committed by Simon Ser
parent 0c23525d47
commit ec7d3f181d

@ -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]); ic->send_events = mode_for_name(argv[index % argc]);
} }
static void toggle_send_events(struct input_config *ic, int argc, char **argv) { static void toggle_send_events(int argc, char **argv) {
struct sway_input_device *input_device = NULL; struct input_config *ic = config->handler_context.input_config;
wl_list_for_each(input_device, &server.input->devices, link) { bool wildcard = strcmp(ic->identifier, "*") == 0;
if (strcmp(input_device->identifier, ic->identifier) == 0) { const char *type = strncmp(ic->identifier, "type:", strlen("type:")) == 0
if (argc) { ? ic->identifier + strlen("type:") : NULL;
toggle_select_send_events_for_device(ic, input_device, struct sway_input_device *device = NULL;
argc, argv); wl_list_for_each(device, &server.input->devices, link) {
} else { if (wildcard || type) {
toggle_supported_send_events_for_device(ic, input_device); ic = new_input_config(device->identifier);
} if (!ic) {
return; continue;
} }
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) { if (argc) {
toggle_select_send_events_for_device(ic, input_device, argc, argv); toggle_select_send_events_for_device(ic, device, argc, argv);
} else { } 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); store_input_config(ic, NULL);
} else {
return;
}
} }
} }
@ -132,15 +134,16 @@ struct cmd_results *input_cmd_events(int argc, char **argv) {
"Invalid toggle mode %s", argv[i]); "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 // config send events mode so that is does not override the device
// ones. The device ones will be applied when attempting to apply // ones. The device ones will be applied when attempting to apply
// the wildcard config // the type/wildcard config
toggle_wildcard_send_events(argc - 1, argv + 1);
ic->send_events = INT_MIN; ic->send_events = INT_MIN;
} else {
toggle_send_events(ic, argc - 1, argv + 1);
} }
} else { } else {
return cmd_results_new(CMD_INVALID, return cmd_results_new(CMD_INVALID,

Loading…
Cancel
Save