aboutsummaryrefslogtreecommitdiffstats
path: root/sway/input/input-manager.c
diff options
context:
space:
mode:
authorLibravatar Tony Crisci <tony@dubstepdish.com>2017-12-17 10:39:22 -0500
committerLibravatar Tony Crisci <tony@dubstepdish.com>2017-12-17 10:39:22 -0500
commit88bcd43ebf59cfa03a9e9a158c6f7a258c1f7db2 (patch)
tree4c2b9321ab9d5f7a9aeed35c7d6826c5da4e496f /sway/input/input-manager.c
parentsend keyboard enter on keyboard configuration (diff)
downloadsway-88bcd43ebf59cfa03a9e9a158c6f7a258c1f7db2.tar.gz
sway-88bcd43ebf59cfa03a9e9a158c6f7a258c1f7db2.tar.zst
sway-88bcd43ebf59cfa03a9e9a158c6f7a258c1f7db2.zip
seat fallback config
Diffstat (limited to 'sway/input/input-manager.c')
-rw-r--r--sway/input/input-manager.c83
1 files changed, 59 insertions, 24 deletions
diff --git a/sway/input/input-manager.c b/sway/input/input-manager.c
index fa8e4b49..16301489 100644
--- a/sway/input/input-manager.c
+++ b/sway/input/input-manager.c
@@ -56,9 +56,9 @@ static char *get_device_identifier(struct wlr_input_device *device) {
56 56
57 int len = 57 int len =
58 (strlen(name) + 58 (strlen(name) +
59 strlen_num(device->vendor) + 59 strlen_num(device->vendor) +
60 strlen_num(device->product) + 60 strlen_num(device->product) +
61 3) * sizeof(char); 61 3) * sizeof(char);
62 62
63 char *identifier = malloc(len); 63 char *identifier = malloc(len);
64 if (!identifier) { 64 if (!identifier) {
@@ -151,13 +151,30 @@ static void input_add_notify(struct wl_listener *listener, void *data) {
151 return; 151 return;
152 } 152 }
153 153
154 bool added = false;
154 wl_list_for_each(seat, &input->seats, link) { 155 wl_list_for_each(seat, &input->seats, link) {
155 if (seat->config && 156 if (seat->config &&
156 (seat_config_get_attachment(seat->config, input_device->identifier) || 157 (seat_config_get_attachment(seat->config, input_device->identifier) ||
157 seat_config_get_attachment(seat->config, "*"))) { 158 seat_config_get_attachment(seat->config, "*"))) {
158 sway_seat_add_device(seat, input_device); 159 sway_seat_add_device(seat, input_device);
160 added = true;
159 } 161 }
160 } 162 }
163
164 if (!added) {
165 wl_list_for_each(seat, &input->seats, link) {
166 if (seat->config && seat->config->fallback == 1) {
167 sway_seat_add_device(seat, input_device);
168 added = true;
169 }
170 }
171 }
172
173 if (!added) {
174 sway_log(L_DEBUG,
175 "device '%s' is not configured on any seats",
176 input_device->identifier);
177 }
161} 178}
162 179
163static void input_remove_notify(struct wl_listener *listener, void *data) { 180static void input_remove_notify(struct wl_listener *listener, void *data) {
@@ -248,35 +265,53 @@ void sway_input_manager_apply_seat_config(struct sway_input_manager *input,
248 struct seat_config *seat_config) { 265 struct seat_config *seat_config) {
249 sway_log(L_DEBUG, "applying new seat config for seat %s", seat_config->name); 266 sway_log(L_DEBUG, "applying new seat config for seat %s", seat_config->name);
250 struct sway_seat *seat = input_manager_get_seat(input, seat_config->name); 267 struct sway_seat *seat = input_manager_get_seat(input, seat_config->name);
251 // the old config is invalid so clear it 268 if (!seat) {
252 sway_seat_set_config(seat, NULL); 269 return;
270 }
271
272 sway_seat_set_config(seat, seat_config);
253 273
254 // clear devices 274 // for every device, try to add it to a seat and if no seat has it
275 // attached, add it to the fallback seats.
255 struct sway_input_device *input_device = NULL; 276 struct sway_input_device *input_device = NULL;
256 wl_list_for_each(input_device, &input->devices, link) { 277 wl_list_for_each(input_device, &input->devices, link) {
257 sway_seat_remove_device(seat, input_device); 278 list_t *seat_list = create_list();
258 } 279 struct sway_seat *seat = NULL;
259 280 wl_list_for_each(seat, &input->seats, link) {
260 if (seat_config_get_attachment(seat_config, "*")) { 281 if (!seat->config) {
261 wl_list_for_each(input_device, &input->devices, link) { 282 continue;
262 sway_seat_add_device(seat, input_device); 283 }
284 if (seat_config_get_attachment(seat->config, "*") ||
285 seat_config_get_attachment(seat->config, input_device->identifier)) {
286 list_add(seat_list, seat);
287 }
263 } 288 }
264 } else {
265 for (int i = 0; i < seat_config->attachments->length; ++i) {
266 struct seat_attachment_config *attachment =
267 seat_config->attachments->items[i];
268
269 struct sway_input_device *device =
270 input_sway_device_from_identifier(input,
271 attachment->identifier);
272 289
273 if (device) { 290 if (seat_list->length) {
274 sway_seat_add_device(seat, device); 291 wl_list_for_each(seat, &input->seats, link) {
292 bool attached = false;
293 for (int i = 0; i < seat_list->length; ++i) {
294 if (seat == seat_list->items[i]) {
295 attached = true;
296 break;
297 }
298 }
299 if (attached) {
300 sway_seat_add_device(seat, input_device);
301 } else {
302 sway_seat_remove_device(seat, input_device);
303 }
304 }
305 } else {
306 wl_list_for_each(seat, &input->seats, link) {
307 if (seat->config && seat->config->fallback == 1) {
308 sway_seat_add_device(seat, input_device);
309 } else {
310 sway_seat_remove_device(seat, input_device);
311 }
275 } 312 }
276 } 313 }
277 } 314 }
278
279 sway_seat_set_config(seat, seat_config);
280} 315}
281 316
282void sway_input_manager_configure_xcursor(struct sway_input_manager *input) { 317void sway_input_manager_configure_xcursor(struct sway_input_manager *input) {