diff options
Diffstat (limited to 'sway/config.c')
-rw-r--r-- | sway/config.c | 144 |
1 files changed, 139 insertions, 5 deletions
diff --git a/sway/config.c b/sway/config.c index b77b8b4b..52633ad8 100644 --- a/sway/config.c +++ b/sway/config.c | |||
@@ -45,6 +45,7 @@ static void config_defaults(struct sway_config *config) { | |||
45 | if (!(config->criteria = create_list())) goto cleanup; | 45 | if (!(config->criteria = create_list())) goto cleanup; |
46 | if (!(config->no_focus = create_list())) goto cleanup; | 46 | if (!(config->no_focus = create_list())) goto cleanup; |
47 | if (!(config->input_configs = create_list())) goto cleanup; | 47 | if (!(config->input_configs = create_list())) goto cleanup; |
48 | if (!(config->seat_configs = create_list())) goto cleanup; | ||
48 | if (!(config->output_configs = create_list())) goto cleanup; | 49 | if (!(config->output_configs = create_list())) goto cleanup; |
49 | 50 | ||
50 | if (!(config->cmd_queue = create_list())) goto cleanup; | 51 | if (!(config->cmd_queue = create_list())) goto cleanup; |
@@ -258,9 +259,7 @@ struct input_config *new_input_config(const char* identifier) { | |||
258 | 259 | ||
259 | void merge_input_config(struct input_config *dst, struct input_config *src) { | 260 | void merge_input_config(struct input_config *dst, struct input_config *src) { |
260 | if (src->identifier) { | 261 | if (src->identifier) { |
261 | if (dst->identifier) { | 262 | free(dst->identifier); |
262 | free(dst->identifier); | ||
263 | } | ||
264 | dst->identifier = strdup(src->identifier); | 263 | dst->identifier = strdup(src->identifier); |
265 | } | 264 | } |
266 | if (src->accel_profile != INT_MIN) { | 265 | if (src->accel_profile != INT_MIN) { |
@@ -300,7 +299,6 @@ void free_input_config(struct input_config *ic) { | |||
300 | return; | 299 | return; |
301 | } | 300 | } |
302 | free(ic->identifier); | 301 | free(ic->identifier); |
303 | free(ic->seat); | ||
304 | free(ic); | 302 | free(ic); |
305 | } | 303 | } |
306 | 304 | ||
@@ -310,6 +308,128 @@ int input_identifier_cmp(const void *item, const void *data) { | |||
310 | return strcmp(ic->identifier, identifier); | 308 | return strcmp(ic->identifier, identifier); |
311 | } | 309 | } |
312 | 310 | ||
311 | struct seat_config *new_seat_config(const char* name) { | ||
312 | struct seat_config *seat = calloc(1, sizeof(struct seat_config)); | ||
313 | if (!seat) { | ||
314 | sway_log(L_DEBUG, "Unable to allocate seat config"); | ||
315 | return NULL; | ||
316 | } | ||
317 | |||
318 | sway_log(L_DEBUG, "new_seat_config(%s)", name); | ||
319 | seat->name = strdup(name); | ||
320 | if (!sway_assert(seat->name, "could not allocate name for seat")) { | ||
321 | return NULL; | ||
322 | } | ||
323 | |||
324 | seat->attachments = create_list(); | ||
325 | if (!sway_assert(seat->attachments, | ||
326 | "could not allocate seat attachments list")) { | ||
327 | return NULL; | ||
328 | } | ||
329 | |||
330 | return seat; | ||
331 | } | ||
332 | |||
333 | struct seat_attachment_config *seat_attachment_config_new() { | ||
334 | struct seat_attachment_config *attachment = | ||
335 | calloc(1, sizeof(struct seat_attachment_config)); | ||
336 | if (!attachment) { | ||
337 | sway_log(L_DEBUG, "cannot allocate attachment config"); | ||
338 | return NULL; | ||
339 | } | ||
340 | return attachment; | ||
341 | } | ||
342 | |||
343 | static void seat_attachment_config_free( | ||
344 | struct seat_attachment_config *attachment) { | ||
345 | free(attachment->identifier); | ||
346 | free(attachment); | ||
347 | return; | ||
348 | } | ||
349 | |||
350 | static struct seat_attachment_config *seat_attachment_config_copy( | ||
351 | struct seat_attachment_config *attachment) { | ||
352 | struct seat_attachment_config *copy = seat_attachment_config_new(); | ||
353 | if (!copy) { | ||
354 | return NULL; | ||
355 | } | ||
356 | |||
357 | copy->identifier = strdup(attachment->identifier); | ||
358 | |||
359 | return copy; | ||
360 | } | ||
361 | |||
362 | static void merge_seat_attachment_config(struct seat_attachment_config *dest, | ||
363 | struct seat_attachment_config *source) { | ||
364 | // nothing to merge yet, but there will be some day | ||
365 | } | ||
366 | |||
367 | void merge_seat_config(struct seat_config *dest, struct seat_config *source) { | ||
368 | if (source->name) { | ||
369 | free(dest->name); | ||
370 | dest->name = strdup(source->name); | ||
371 | } | ||
372 | |||
373 | for (int i = 0; i < source->attachments->length; ++i) { | ||
374 | struct seat_attachment_config *source_attachment = | ||
375 | source->attachments->items[i]; | ||
376 | bool found = false; | ||
377 | for (int j = 0; j < dest->attachments->length; ++j) { | ||
378 | struct seat_attachment_config *dest_attachment = | ||
379 | dest->attachments->items[j]; | ||
380 | if (strcmp(source_attachment->identifier, | ||
381 | dest_attachment->identifier) == 0) { | ||
382 | merge_seat_attachment_config(dest_attachment, | ||
383 | source_attachment); | ||
384 | found = true; | ||
385 | } | ||
386 | } | ||
387 | |||
388 | if (!found) { | ||
389 | struct seat_attachment_config *copy = | ||
390 | seat_attachment_config_copy(source_attachment); | ||
391 | if (copy) { | ||
392 | list_add(dest->attachments, copy); | ||
393 | } | ||
394 | } | ||
395 | } | ||
396 | } | ||
397 | |||
398 | void free_seat_config(struct seat_config *seat) { | ||
399 | if (!seat) { | ||
400 | return; | ||
401 | } | ||
402 | |||
403 | free(seat->name); | ||
404 | for (int i = 0; i < seat->attachments->length; ++i) { | ||
405 | struct seat_attachment_config *attachment = | ||
406 | seat->attachments->items[i]; | ||
407 | seat_attachment_config_free(attachment); | ||
408 | } | ||
409 | |||
410 | list_free(seat->attachments); | ||
411 | free(seat); | ||
412 | } | ||
413 | |||
414 | int seat_name_cmp(const void *item, const void *data) { | ||
415 | const struct seat_config *sc = item; | ||
416 | const char *name = data; | ||
417 | return strcmp(sc->name, name); | ||
418 | } | ||
419 | |||
420 | struct seat_attachment_config *seat_config_get_attachment( | ||
421 | struct seat_config *seat_config, char *identifier) { | ||
422 | for (int i = 0; i < seat_config->attachments->length; ++i) { | ||
423 | struct seat_attachment_config *attachment = | ||
424 | seat_config->attachments->items[i]; | ||
425 | if (strcmp(attachment->identifier, identifier) == 0) { | ||
426 | return attachment; | ||
427 | } | ||
428 | } | ||
429 | |||
430 | return NULL; | ||
431 | } | ||
432 | |||
313 | bool load_main_config(const char *file, bool is_active) { | 433 | bool load_main_config(const char *file, bool is_active) { |
314 | char *path; | 434 | char *path; |
315 | if (file != NULL) { | 435 | if (file != NULL) { |
@@ -368,7 +488,7 @@ bool load_main_config(const char *file, bool is_active) { | |||
368 | char *_path = secconfigs->items[i]; | 488 | char *_path = secconfigs->items[i]; |
369 | if (stat(_path, &s) || s.st_uid != 0 || s.st_gid != 0 || | 489 | if (stat(_path, &s) || s.st_uid != 0 || s.st_gid != 0 || |
370 | (((s.st_mode & 0777) != 0644) && | 490 | (((s.st_mode & 0777) != 0644) && |
371 | (s.st_mode & 0777) != 0444)) { | 491 | (s.st_mode & 0777) != 0444)) { |
372 | sway_log(L_ERROR, | 492 | sway_log(L_ERROR, |
373 | "Refusing to load %s - it must be owned by root " | 493 | "Refusing to load %s - it must be owned by root " |
374 | "and mode 644 or 444", _path); | 494 | "and mode 644 or 444", _path); |
@@ -547,6 +667,14 @@ bool read_config(FILE *file, struct sway_config *config) { | |||
547 | } | 667 | } |
548 | break; | 668 | break; |
549 | 669 | ||
670 | case CMD_BLOCK_SEAT: | ||
671 | if (block == CMD_BLOCK_END) { | ||
672 | block = CMD_BLOCK_SEAT; | ||
673 | } else { | ||
674 | sway_log(L_ERROR, "Invalid block '%s'", line); | ||
675 | } | ||
676 | break; | ||
677 | |||
550 | case CMD_BLOCK_BAR: | 678 | case CMD_BLOCK_BAR: |
551 | if (block == CMD_BLOCK_END) { | 679 | if (block == CMD_BLOCK_END) { |
552 | block = CMD_BLOCK_BAR; | 680 | block = CMD_BLOCK_BAR; |
@@ -601,6 +729,12 @@ bool read_config(FILE *file, struct sway_config *config) { | |||
601 | block = CMD_BLOCK_END; | 729 | block = CMD_BLOCK_END; |
602 | break; | 730 | break; |
603 | 731 | ||
732 | case CMD_BLOCK_SEAT: | ||
733 | sway_log(L_DEBUG, "End of seat block"); | ||
734 | current_seat_config = NULL; | ||
735 | block = CMD_BLOCK_END; | ||
736 | break; | ||
737 | |||
604 | case CMD_BLOCK_BAR: | 738 | case CMD_BLOCK_BAR: |
605 | sway_log(L_DEBUG, "End of bar block"); | 739 | sway_log(L_DEBUG, "End of bar block"); |
606 | config->current_bar = NULL; | 740 | config->current_bar = NULL; |