diff options
Diffstat (limited to 'sway/config/input.c')
-rw-r--r-- | sway/config/input.c | 55 |
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) { | |||
40 | } | 40 | } |
41 | 41 | ||
42 | void merge_input_config(struct input_config *dst, struct input_config *src) { | 42 | void merge_input_config(struct input_config *dst, struct input_config *src) { |
43 | if (src->identifier) { | ||
44 | free(dst->identifier); | ||
45 | dst->identifier = strdup(src->identifier); | ||
46 | } | ||
47 | if (src->accel_profile != INT_MIN) { | 43 | if (src->accel_profile != INT_MIN) { |
48 | dst->accel_profile = src->accel_profile; | 44 | dst->accel_profile = src->accel_profile; |
49 | } | 45 | } |
@@ -125,14 +121,51 @@ void merge_input_config(struct input_config *dst, struct input_config *src) { | |||
125 | } | 121 | } |
126 | } | 122 | } |
127 | 123 | ||
128 | struct input_config *copy_input_config(struct input_config *ic) { | 124 | static void merge_wildcard_on_all(struct input_config *wildcard) { |
129 | struct input_config *copy = calloc(1, sizeof(struct input_config)); | 125 | for (int i = 0; i < config->input_configs->length; i++) { |
130 | if (copy == NULL) { | 126 | struct input_config *ic = config->input_configs->items[i]; |
131 | wlr_log(WLR_ERROR, "could not allocate input config"); | 127 | if (strcmp(wildcard->identifier, ic->identifier) != 0) { |
132 | return NULL; | 128 | wlr_log(WLR_DEBUG, "Merging input * config on %s", ic->identifier); |
129 | merge_input_config(ic, wildcard); | ||
130 | } | ||
131 | } | ||
132 | } | ||
133 | |||
134 | struct input_config *store_input_config(struct input_config *ic) { | ||
135 | bool wildcard = strcmp(ic->identifier, "*") == 0; | ||
136 | if (wildcard) { | ||
137 | merge_wildcard_on_all(ic); | ||
133 | } | 138 | } |
134 | merge_input_config(copy, ic); | 139 | |
135 | return copy; | 140 | int i = list_seq_find(config->input_configs, input_identifier_cmp, |
141 | ic->identifier); | ||
142 | if (i >= 0) { | ||
143 | wlr_log(WLR_DEBUG, "Merging on top of existing input config"); | ||
144 | struct input_config *current = config->input_configs->items[i]; | ||
145 | merge_input_config(current, ic); | ||
146 | free_input_config(ic); | ||
147 | ic = current; | ||
148 | } else if (!wildcard) { | ||
149 | wlr_log(WLR_DEBUG, "Adding non-wildcard input config"); | ||
150 | i = list_seq_find(config->input_configs, input_identifier_cmp, "*"); | ||
151 | if (i >= 0) { | ||
152 | wlr_log(WLR_DEBUG, "Merging on top of input * config"); | ||
153 | struct input_config *current = new_input_config(ic->identifier); | ||
154 | merge_input_config(current, config->input_configs->items[i]); | ||
155 | merge_input_config(current, ic); | ||
156 | free_input_config(ic); | ||
157 | ic = current; | ||
158 | } | ||
159 | list_add(config->input_configs, ic); | ||
160 | } else { | ||
161 | // New wildcard config. Just add it | ||
162 | wlr_log(WLR_DEBUG, "Adding input * config"); | ||
163 | list_add(config->input_configs, ic); | ||
164 | } | ||
165 | |||
166 | wlr_log(WLR_DEBUG, "Config stored for input %s", ic->identifier); | ||
167 | |||
168 | return ic; | ||
136 | } | 169 | } |
137 | 170 | ||
138 | void free_input_config(struct input_config *ic) { | 171 | void free_input_config(struct input_config *ic) { |