diff options
-rw-r--r-- | include/sway/config.h | 2 | ||||
-rw-r--r-- | sway/config.c | 10 | ||||
-rw-r--r-- | sway/config/input.c | 39 | ||||
-rw-r--r-- | sway/input/input-manager.c | 47 | ||||
-rw-r--r-- | sway/sway-input.5.scd | 17 |
5 files changed, 109 insertions, 6 deletions
diff --git a/include/sway/config.h b/include/sway/config.h index fe06fb9d..86410544 100644 --- a/include/sway/config.h +++ b/include/sway/config.h | |||
@@ -105,6 +105,7 @@ struct input_config_mapped_from_region { | |||
105 | */ | 105 | */ |
106 | struct input_config { | 106 | struct input_config { |
107 | char *identifier; | 107 | char *identifier; |
108 | const char *input_type; | ||
108 | 109 | ||
109 | int accel_profile; | 110 | int accel_profile; |
110 | int click_method; | 111 | int click_method; |
@@ -418,6 +419,7 @@ struct sway_config { | |||
418 | list_t *workspace_configs; | 419 | list_t *workspace_configs; |
419 | list_t *output_configs; | 420 | list_t *output_configs; |
420 | list_t *input_configs; | 421 | list_t *input_configs; |
422 | list_t *input_type_configs; | ||
421 | list_t *seat_configs; | 423 | list_t *seat_configs; |
422 | list_t *criteria; | 424 | list_t *criteria; |
423 | list_t *no_focus; | 425 | list_t *no_focus; |
diff --git a/sway/config.c b/sway/config.c index 4944ec02..e14ea83a 100644 --- a/sway/config.c +++ b/sway/config.c | |||
@@ -113,6 +113,12 @@ void free_config(struct sway_config *config) { | |||
113 | } | 113 | } |
114 | list_free(config->input_configs); | 114 | list_free(config->input_configs); |
115 | } | 115 | } |
116 | if (config->input_type_configs) { | ||
117 | for (int i = 0; i < config->input_type_configs->length; i++) { | ||
118 | free_input_config(config->input_type_configs->items[i]); | ||
119 | } | ||
120 | list_free(config->input_type_configs); | ||
121 | } | ||
116 | if (config->seat_configs) { | 122 | if (config->seat_configs) { |
117 | for (int i = 0; i < config->seat_configs->length; i++) { | 123 | for (int i = 0; i < config->seat_configs->length; i++) { |
118 | free_seat_config(config->seat_configs->items[i]); | 124 | free_seat_config(config->seat_configs->items[i]); |
@@ -189,10 +195,12 @@ static void config_defaults(struct sway_config *config) { | |||
189 | if (!(config->workspace_configs = create_list())) goto cleanup; | 195 | if (!(config->workspace_configs = create_list())) goto cleanup; |
190 | if (!(config->criteria = create_list())) goto cleanup; | 196 | if (!(config->criteria = create_list())) goto cleanup; |
191 | if (!(config->no_focus = create_list())) goto cleanup; | 197 | if (!(config->no_focus = create_list())) goto cleanup; |
192 | if (!(config->input_configs = create_list())) goto cleanup; | ||
193 | if (!(config->seat_configs = create_list())) goto cleanup; | 198 | if (!(config->seat_configs = create_list())) goto cleanup; |
194 | if (!(config->output_configs = create_list())) goto cleanup; | 199 | if (!(config->output_configs = create_list())) goto cleanup; |
195 | 200 | ||
201 | if (!(config->input_type_configs = create_list())) goto cleanup; | ||
202 | if (!(config->input_configs = create_list())) goto cleanup; | ||
203 | |||
196 | if (!(config->cmd_queue = create_list())) goto cleanup; | 204 | if (!(config->cmd_queue = create_list())) goto cleanup; |
197 | 205 | ||
198 | if (!(config->current_mode = malloc(sizeof(struct sway_mode)))) | 206 | if (!(config->current_mode = malloc(sizeof(struct sway_mode)))) |
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 | |||
154 | static 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 | ||
145 | struct input_config *store_input_config(struct input_config *ic) { | 170 | struct 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"); |
diff --git a/sway/input/input-manager.c b/sway/input/input-manager.c index 0c5254bd..a2a1e274 100644 --- a/sway/input/input-manager.c +++ b/sway/input/input-manager.c | |||
@@ -105,6 +105,37 @@ const char *input_device_get_type(struct sway_input_device *device) { | |||
105 | return "unknown"; | 105 | return "unknown"; |
106 | } | 106 | } |
107 | 107 | ||
108 | static void apply_input_type_config(struct sway_input_device *input_device) { | ||
109 | const char *device_type = input_device_get_type(input_device); | ||
110 | struct input_config *type_config = NULL; | ||
111 | for (int i = 0; i < config->input_type_configs->length; i++) { | ||
112 | struct input_config *ic = config->input_type_configs->items[i]; | ||
113 | if (strcmp(ic->identifier + 5, device_type) == 0) { | ||
114 | type_config = ic; | ||
115 | break; | ||
116 | } | ||
117 | } | ||
118 | if (type_config == NULL) { | ||
119 | return; | ||
120 | } | ||
121 | |||
122 | for (int i = 0; i < config->input_configs->length; i++) { | ||
123 | struct input_config *ic = config->input_configs->items[i]; | ||
124 | if (strcmp(input_device->identifier, ic->identifier) == 0) { | ||
125 | struct input_config *current = new_input_config(ic->identifier); | ||
126 | merge_input_config(current, type_config); | ||
127 | merge_input_config(current, ic); | ||
128 | |||
129 | current->input_type = device_type; | ||
130 | config->input_configs->items[i] = current; | ||
131 | free_input_config(ic); | ||
132 | ic = NULL; | ||
133 | |||
134 | break; | ||
135 | } | ||
136 | } | ||
137 | } | ||
138 | |||
108 | static struct sway_input_device *input_sway_device_from_wlr( | 139 | static struct sway_input_device *input_sway_device_from_wlr( |
109 | struct wlr_input_device *device) { | 140 | struct wlr_input_device *device) { |
110 | struct sway_input_device *input_device = NULL; | 141 | struct sway_input_device *input_device = NULL; |
@@ -541,6 +572,8 @@ static void handle_new_input(struct wl_listener *listener, void *data) { | |||
541 | sway_log(SWAY_DEBUG, "adding device: '%s'", | 572 | sway_log(SWAY_DEBUG, "adding device: '%s'", |
542 | input_device->identifier); | 573 | input_device->identifier); |
543 | 574 | ||
575 | apply_input_type_config(input_device); | ||
576 | |||
544 | if (input_device->wlr_device->type == WLR_INPUT_DEVICE_POINTER || | 577 | if (input_device->wlr_device->type == WLR_INPUT_DEVICE_POINTER || |
545 | input_device->wlr_device->type == WLR_INPUT_DEVICE_TABLET_TOOL) { | 578 | input_device->wlr_device->type == WLR_INPUT_DEVICE_TABLET_TOOL) { |
546 | input_manager_libinput_config_pointer(input_device); | 579 | input_manager_libinput_config_pointer(input_device); |
@@ -693,9 +726,13 @@ void input_manager_set_focus(struct sway_node *node) { | |||
693 | void input_manager_apply_input_config(struct input_config *input_config) { | 726 | void input_manager_apply_input_config(struct input_config *input_config) { |
694 | struct sway_input_device *input_device = NULL; | 727 | struct sway_input_device *input_device = NULL; |
695 | bool wildcard = strcmp(input_config->identifier, "*") == 0; | 728 | bool wildcard = strcmp(input_config->identifier, "*") == 0; |
729 | bool type_wildcard = strncmp(input_config->identifier, "type:", 5) == 0; | ||
696 | wl_list_for_each(input_device, &server.input->devices, link) { | 730 | wl_list_for_each(input_device, &server.input->devices, link) { |
731 | bool type_matches = type_wildcard && | ||
732 | strcmp(input_device_get_type(input_device), input_config->identifier + 5) == 0; | ||
697 | if (strcmp(input_device->identifier, input_config->identifier) == 0 | 733 | if (strcmp(input_device->identifier, input_config->identifier) == 0 |
698 | || wildcard) { | 734 | || wildcard |
735 | || type_matches) { | ||
699 | if (input_device->wlr_device->type == WLR_INPUT_DEVICE_POINTER || | 736 | if (input_device->wlr_device->type == WLR_INPUT_DEVICE_POINTER || |
700 | input_device->wlr_device->type == WLR_INPUT_DEVICE_TABLET_TOOL) { | 737 | input_device->wlr_device->type == WLR_INPUT_DEVICE_TABLET_TOOL) { |
701 | input_manager_libinput_config_pointer(input_device); | 738 | input_manager_libinput_config_pointer(input_device); |
@@ -829,5 +866,13 @@ struct input_config *input_device_get_config(struct sway_input_device *device) { | |||
829 | } | 866 | } |
830 | } | 867 | } |
831 | 868 | ||
869 | const char *device_type = input_device_get_type(device); | ||
870 | for (int i = 0; i < config->input_type_configs->length; ++i) { | ||
871 | input_config = config->input_type_configs->items[i]; | ||
872 | if (strcmp(input_config->identifier + 5, device_type) == 0) { | ||
873 | return input_config; | ||
874 | } | ||
875 | } | ||
876 | |||
832 | return wildcard_config; | 877 | return wildcard_config; |
833 | } | 878 | } |
diff --git a/sway/sway-input.5.scd b/sway/sway-input.5.scd index 1a8062fb..efd3d1af 100644 --- a/sway/sway-input.5.scd +++ b/sway/sway-input.5.scd | |||
@@ -9,13 +9,28 @@ sway-input - input configuration file and commands | |||
9 | Sway allows for configuration of devices within the sway configuration file. | 9 | Sway allows for configuration of devices within the sway configuration file. |
10 | To obtain a list of available device identifiers, run *swaymsg -t get_inputs*. | 10 | To obtain a list of available device identifiers, run *swaymsg -t get_inputs*. |
11 | Settings can also be applied to all input devices by using the wildcard, _\*_, | 11 | Settings can also be applied to all input devices by using the wildcard, _\*_, |
12 | in place of _\<identifier\>_ in the commands below. | 12 | in place of _\<identifier\>_ in the commands below. In addition, the settings |
13 | can be applied to a type of device, by using _type:\<input_type\>_ in place | ||
14 | of _\<identifier\>_. | ||
13 | 15 | ||
14 | Tip: If the configuration settings do not appear to be taking effect, you could | 16 | Tip: If the configuration settings do not appear to be taking effect, you could |
15 | try using _\*_ instead of _\<identifier\>_. If it works with the wildcard, try | 17 | try using _\*_ instead of _\<identifier\>_. If it works with the wildcard, try |
16 | using a different identifier from *swaymsg -t get_inputs* until you find the | 18 | using a different identifier from *swaymsg -t get_inputs* until you find the |
17 | correct input device. | 19 | correct input device. |
18 | 20 | ||
21 | Current available input types are: | ||
22 | |||
23 | - touchpad | ||
24 | - pointer | ||
25 | - keyboard | ||
26 | - touch | ||
27 | - tablet_tool | ||
28 | - tablet_pad | ||
29 | - switch | ||
30 | |||
31 | Note: The type configurations are applied as the devices appear and get applied | ||
32 | on top of the existing device configurations. | ||
33 | |||
19 | # INPUT COMMANDS | 34 | # INPUT COMMANDS |
20 | 35 | ||
21 | ## KEYBOARD CONFIGURATION | 36 | ## KEYBOARD CONFIGURATION |