aboutsummaryrefslogtreecommitdiffstats
path: root/sway/config
diff options
context:
space:
mode:
authorLibravatar Benjamin Cheng <ben@bcheng.me>2019-03-25 22:05:49 -0400
committerLibravatar Brian Ashworth <bosrsf04@gmail.com>2019-04-14 19:31:36 -0400
commitbd3720585e91ae0dfcc4be30149ae4f8f5218174 (patch)
tree3a44b51a2c5a78bfbde227180c3853875a2258a4 /sway/config
parentAdd heuristics to differentiate touchpads (diff)
downloadsway-bd3720585e91ae0dfcc4be30149ae4f8f5218174.tar.gz
sway-bd3720585e91ae0dfcc4be30149ae4f8f5218174.tar.zst
sway-bd3720585e91ae0dfcc4be30149ae4f8f5218174.zip
Implement input type configs (#3784)
Add support for configurations that apply to a type of inputs (i.e. natural scrolling on all touchpads). A type config is differentiated by a `type:` prefix followed by the type it corresponds to. When new devices appear, the device config is merged on top of its type config (if it exists). New type configs are applied on top of existing configs.
Diffstat (limited to 'sway/config')
-rw-r--r--sway/config/input.c39
1 files changed, 36 insertions, 3 deletions
diff --git a/sway/config/input.c b/sway/config/input.c
index 63c28635..aa581431 100644
--- a/sway/config/input.c
+++ b/sway/config/input.c
@@ -18,6 +18,7 @@ struct input_config *new_input_config(const char* identifier) {
18 return NULL; 18 return NULL;
19 } 19 }
20 20
21 input->input_type = NULL;
21 input->tap = INT_MIN; 22 input->tap = INT_MIN;
22 input->tap_button_map = INT_MIN; 23 input->tap_button_map = INT_MIN;
23 input->drag = INT_MIN; 24 input->drag = INT_MIN;
@@ -140,6 +141,30 @@ static void merge_wildcard_on_all(struct input_config *wildcard) {
140 merge_input_config(ic, wildcard); 141 merge_input_config(ic, wildcard);
141 } 142 }
142 } 143 }
144
145 for (int i = 0; i < config->input_type_configs->length; i++) {
146 struct input_config *ic = config->input_type_configs->items[i];
147 if (strcmp(wildcard->identifier, ic->identifier) != 0) {
148 sway_log(SWAY_DEBUG, "Merging input * config on %s", ic->identifier);
149 merge_input_config(ic, wildcard);
150 }
151 }
152}
153
154static void merge_type_on_existing(struct input_config *type_wildcard) {
155 for (int i = 0; i < config->input_configs->length; i++) {
156 struct input_config *ic = config->input_configs->items[i];
157 if (ic->input_type == NULL) {
158 continue;
159 }
160
161 if (strcmp(ic->input_type, type_wildcard->identifier + 5) == 0) {
162 sway_log(SWAY_DEBUG, "Merging %s top of %s",
163 type_wildcard->identifier,
164 ic->identifier);
165 merge_input_config(ic, type_wildcard);
166 }
167 }
143} 168}
144 169
145struct input_config *store_input_config(struct input_config *ic) { 170struct input_config *store_input_config(struct input_config *ic) {
@@ -148,11 +173,19 @@ struct input_config *store_input_config(struct input_config *ic) {
148 merge_wildcard_on_all(ic); 173 merge_wildcard_on_all(ic);
149 } 174 }
150 175
151 int i = list_seq_find(config->input_configs, input_identifier_cmp, 176 list_t *config_list = NULL;
177 if (strncmp(ic->identifier, "type:", 5) == 0) {
178 config_list = config->input_type_configs;
179 merge_type_on_existing(ic);
180 } else {
181 config_list = config->input_configs;
182 }
183
184 int i = list_seq_find(config_list, input_identifier_cmp,
152 ic->identifier); 185 ic->identifier);
153 if (i >= 0) { 186 if (i >= 0) {
154 sway_log(SWAY_DEBUG, "Merging on top of existing input config"); 187 sway_log(SWAY_DEBUG, "Merging on top of existing input config");
155 struct input_config *current = config->input_configs->items[i]; 188 struct input_config *current = config_list->items[i];
156 merge_input_config(current, ic); 189 merge_input_config(current, ic);
157 free_input_config(ic); 190 free_input_config(ic);
158 ic = current; 191 ic = current;
@@ -167,7 +200,7 @@ struct input_config *store_input_config(struct input_config *ic) {
167 free_input_config(ic); 200 free_input_config(ic);
168 ic = current; 201 ic = current;
169 } 202 }
170 list_add(config->input_configs, ic); 203 list_add(config_list, ic);
171 } else { 204 } else {
172 // New wildcard config. Just add it 205 // New wildcard config. Just add it
173 sway_log(SWAY_DEBUG, "Adding input * config"); 206 sway_log(SWAY_DEBUG, "Adding input * config");