config/input: set type for new identifier configs

When an input becomes available, the input type config for that device
type will be merged underneath the input identifier config, provided
they both exist. If an input type config gets added or modified at a
later point, then those changes get merged onto the input identifier
configs for that type. However there was a missing case of the input
identifier config being added after the device is already available and
the input type config existing. This makes it so that the first time an
input identifier config gets stored, there will be a check to see if it
matched any of the available devices. If it does, then there will be a
search for the associated input type config, which will be merged
underneath the input identifier config if found.
This commit is contained in:
Brian Ashworth 2019-12-14 01:57:51 -05:00 committed by Drew DeVault
parent f9ce8749dc
commit 218b5b9dc0
1 changed files with 24 additions and 0 deletions

View File

@ -249,6 +249,17 @@ static void merge_type_on_existing(struct input_config *type_wildcard) {
}
}
static const char *set_input_type(struct input_config *ic) {
struct sway_input_device *input_device;
wl_list_for_each(input_device, &server.input->devices, link) {
if (strcmp(input_device->identifier, ic->identifier) == 0) {
ic->input_type = input_device_get_type(input_device);
break;
}
}
return ic->input_type;
}
struct input_config *store_input_config(struct input_config *ic,
char **error) {
bool wildcard = strcmp(ic->identifier, "*") == 0;
@ -272,6 +283,19 @@ struct input_config *store_input_config(struct input_config *ic,
current = config_list->items[i];
}
if (!current && !wildcard && !type && set_input_type(ic)) {
for (i = 0; i < config->input_type_configs->length; i++) {
struct input_config *tc = config->input_type_configs->items[i];
if (strcmp(ic->input_type, tc->identifier + 5) == 0) {
current = new_input_config(ic->identifier);
current->input_type = ic->input_type;
merge_input_config(current, tc);
new_current = true;
break;
}
}
}
i = list_seq_find(config->input_configs, input_identifier_cmp, "*");
if (!current && i >= 0) {
current = new_input_config(ic->identifier);