aboutsummaryrefslogtreecommitdiff
path: root/sway/config
diff options
context:
space:
mode:
authorBrian Ashworth <bosrsf04@gmail.com>2018-09-23 19:56:52 -0400
committerBrian Ashworth <bosrsf04@gmail.com>2018-09-23 19:56:52 -0400
commitbaeb28ea6230ef9aa409ee52abe208720120e45c (patch)
treed5a6fffc3470b3fbbb18a6ae01851451bea1dbb2 /sway/config
parent4a4f07ac25d18dfeffc6a1ff55e175ba01abc290 (diff)
Implement support for input wildcard
Diffstat (limited to 'sway/config')
-rw-r--r--sway/config/input.c55
1 files changed, 44 insertions, 11 deletions
diff --git a/sway/config/input.c b/sway/config/input.c
index ad5b96c8..fffc8518 100644
--- a/sway/config/input.c
+++ b/sway/config/input.c
@@ -40,10 +40,6 @@ struct input_config *new_input_config(const char* identifier) {
}
void merge_input_config(struct input_config *dst, struct input_config *src) {
- if (src->identifier) {
- free(dst->identifier);
- dst->identifier = strdup(src->identifier);
- }
if (src->accel_profile != INT_MIN) {
dst->accel_profile = src->accel_profile;
}
@@ -125,14 +121,51 @@ void merge_input_config(struct input_config *dst, struct input_config *src) {
}
}
-struct input_config *copy_input_config(struct input_config *ic) {
- struct input_config *copy = calloc(1, sizeof(struct input_config));
- if (copy == NULL) {
- wlr_log(WLR_ERROR, "could not allocate input config");
- return NULL;
+static void merge_wildcard_on_all(struct input_config *wildcard) {
+ for (int i = 0; i < config->input_configs->length; i++) {
+ struct input_config *ic = config->input_configs->items[i];
+ if (strcmp(wildcard->identifier, ic->identifier) != 0) {
+ wlr_log(WLR_DEBUG, "Merging input * config on %s", ic->identifier);
+ merge_input_config(ic, wildcard);
+ }
+ }
+}
+
+struct input_config *store_input_config(struct input_config *ic) {
+ bool wildcard = strcmp(ic->identifier, "*") == 0;
+ if (wildcard) {
+ merge_wildcard_on_all(ic);
}
- merge_input_config(copy, ic);
- return copy;
+
+ int i = list_seq_find(config->input_configs, input_identifier_cmp,
+ ic->identifier);
+ if (i >= 0) {
+ wlr_log(WLR_DEBUG, "Merging on top of existing input config");
+ struct input_config *current = config->input_configs->items[i];
+ merge_input_config(current, ic);
+ free_input_config(ic);
+ ic = current;
+ } else if (!wildcard) {
+ wlr_log(WLR_DEBUG, "Adding non-wildcard input config");
+ i = list_seq_find(config->input_configs, input_identifier_cmp, "*");
+ if (i >= 0) {
+ wlr_log(WLR_DEBUG, "Merging on top of input * config");
+ struct input_config *current = new_input_config(ic->identifier);
+ merge_input_config(current, config->input_configs->items[i]);
+ merge_input_config(current, ic);
+ free_input_config(ic);
+ ic = current;
+ }
+ list_add(config->input_configs, ic);
+ } else {
+ // New wildcard config. Just add it
+ wlr_log(WLR_DEBUG, "Adding input * config");
+ list_add(config->input_configs, ic);
+ }
+
+ wlr_log(WLR_DEBUG, "Config stored for input %s", ic->identifier);
+
+ return ic;
}
void free_input_config(struct input_config *ic) {