mirror of
https://github.com/swaywm/sway.git
synced 2024-11-29 03:11:27 +00:00
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.
This commit is contained in:
parent
0c23525d47
commit
ec7d3f181d
|
@ -74,37 +74,39 @@ 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) {
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
|
if (type && strcmp(input_device_get_type(device), type) != 0) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
} else if (strcmp(ic->identifier, device->identifier) != 0) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (argc) {
|
||||||
|
toggle_select_send_events_for_device(ic, device, argc, argv);
|
||||||
|
} else {
|
||||||
|
toggle_supported_send_events_for_device(ic, device);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (wildcard || type) {
|
||||||
|
store_input_config(ic, NULL);
|
||||||
|
} else {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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);
|
|
||||||
} else {
|
|
||||||
toggle_supported_send_events_for_device(ic, input_device);
|
|
||||||
}
|
|
||||||
store_input_config(ic, NULL);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
struct cmd_results *input_cmd_events(int argc, char **argv) {
|
struct cmd_results *input_cmd_events(int argc, char **argv) {
|
||||||
struct cmd_results *error = NULL;
|
struct cmd_results *error = NULL;
|
||||||
if ((error = checkarg(argc, "events", EXPECTED_AT_LEAST, 1))) {
|
if ((error = checkarg(argc, "events", EXPECTED_AT_LEAST, 1))) {
|
||||||
|
@ -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…
Reference in a new issue