aboutsummaryrefslogtreecommitdiff
path: root/sway/config
diff options
context:
space:
mode:
authorBenjamin Cheng <ben@bcheng.me>2019-03-25 22:05:49 -0400
committerBrian Ashworth <bosrsf04@gmail.com>2019-04-14 19:31:36 -0400
commitbd3720585e91ae0dfcc4be30149ae4f8f5218174 (patch)
tree3a44b51a2c5a78bfbde227180c3853875a2258a4 /sway/config
parent6737b90cb93d0231bbbc6045adf8a2443bc4e21c (diff)
downloadsway-bd3720585e91ae0dfcc4be30149ae4f8f5218174.tar.xz
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) {
return NULL;
}
+ input->input_type = NULL;
input->tap = INT_MIN;
input->tap_button_map = INT_MIN;
input->drag = INT_MIN;
@@ -140,6 +141,30 @@ static void merge_wildcard_on_all(struct input_config *wildcard) {
merge_input_config(ic, wildcard);
}
}
+
+ for (int i = 0; i < config->input_type_configs->length; i++) {
+ struct input_config *ic = config->input_type_configs->items[i];
+ if (strcmp(wildcard->identifier, ic->identifier) != 0) {
+ sway_log(SWAY_DEBUG, "Merging input * config on %s", ic->identifier);
+ merge_input_config(ic, wildcard);
+ }
+ }
+}
+
+static void merge_type_on_existing(struct input_config *type_wildcard) {
+ for (int i = 0; i < config->input_configs->length; i++) {
+ struct input_config *ic = config->input_configs->items[i];
+ if (ic->input_type == NULL) {
+ continue;
+ }
+
+ if (strcmp(ic->input_type, type_wildcard->identifier + 5) == 0) {
+ sway_log(SWAY_DEBUG, "Merging %s top of %s",
+ type_wildcard->identifier,
+ ic->identifier);
+ merge_input_config(ic, type_wildcard);
+ }
+ }
}
struct input_config *store_input_config(struct input_config *ic) {
@@ -148,11 +173,19 @@ struct input_config *store_input_config(struct input_config *ic) {
merge_wildcard_on_all(ic);
}
- int i = list_seq_find(config->input_configs, input_identifier_cmp,
+ list_t *config_list = NULL;
+ if (strncmp(ic->identifier, "type:", 5) == 0) {
+ config_list = config->input_type_configs;
+ merge_type_on_existing(ic);
+ } else {
+ config_list = config->input_configs;
+ }
+
+ int i = list_seq_find(config_list, input_identifier_cmp,
ic->identifier);
if (i >= 0) {
sway_log(SWAY_DEBUG, "Merging on top of existing input config");
- struct input_config *current = config->input_configs->items[i];
+ struct input_config *current = config_list->items[i];
merge_input_config(current, ic);
free_input_config(ic);
ic = current;
@@ -167,7 +200,7 @@ struct input_config *store_input_config(struct input_config *ic) {
free_input_config(ic);
ic = current;
}
- list_add(config->input_configs, ic);
+ list_add(config_list, ic);
} else {
// New wildcard config. Just add it
sway_log(SWAY_DEBUG, "Adding input * config");