diff options
author | Tony Crisci <tony@dubstepdish.com> | 2017-12-12 09:02:30 -0500 |
---|---|---|
committer | Tony Crisci <tony@dubstepdish.com> | 2017-12-12 09:03:58 -0500 |
commit | 538903bc5ace56c1dab0f5287fb4d0bab78a0165 (patch) | |
tree | d45d08f64e98a76c730145cf3ea75dd199d9f6c8 /sway/config.c | |
parent | sway input device (diff) | |
download | sway-538903bc5ace56c1dab0f5287fb4d0bab78a0165.tar.gz sway-538903bc5ace56c1dab0f5287fb4d0bab78a0165.tar.zst sway-538903bc5ace56c1dab0f5287fb4d0bab78a0165.zip |
config cleanup
Diffstat (limited to 'sway/config.c')
-rw-r--r-- | sway/config.c | 37 |
1 files changed, 24 insertions, 13 deletions
diff --git a/sway/config.c b/sway/config.c index 7ae3c2a4..4bc74ee0 100644 --- a/sway/config.c +++ b/sway/config.c | |||
@@ -21,6 +21,7 @@ | |||
21 | #include <dev/evdev/input-event-codes.h> | 21 | #include <dev/evdev/input-event-codes.h> |
22 | #endif | 22 | #endif |
23 | #include <wlr/types/wlr_output.h> | 23 | #include <wlr/types/wlr_output.h> |
24 | #include "sway/input/input-manager.h" | ||
24 | #include "sway/commands.h" | 25 | #include "sway/commands.h" |
25 | #include "sway/config.h" | 26 | #include "sway/config.h" |
26 | #include "sway/layout.h" | 27 | #include "sway/layout.h" |
@@ -48,7 +49,8 @@ static void config_defaults(struct sway_config *config) { | |||
48 | 49 | ||
49 | if (!(config->cmd_queue = create_list())) goto cleanup; | 50 | if (!(config->cmd_queue = create_list())) goto cleanup; |
50 | 51 | ||
51 | if (!(config->current_mode = malloc(sizeof(struct sway_mode)))) goto cleanup; | 52 | if (!(config->current_mode = malloc(sizeof(struct sway_mode)))) |
53 | goto cleanup; | ||
52 | if (!(config->current_mode->name = malloc(sizeof("default")))) goto cleanup; | 54 | if (!(config->current_mode->name = malloc(sizeof("default")))) goto cleanup; |
53 | strcpy(config->current_mode->name, "default"); | 55 | strcpy(config->current_mode->name, "default"); |
54 | if (!(config->current_mode->bindings = create_list())) goto cleanup; | 56 | if (!(config->current_mode->bindings = create_list())) goto cleanup; |
@@ -337,8 +339,9 @@ bool load_main_config(const char *file, bool is_active) { | |||
337 | bool success = true; | 339 | bool success = true; |
338 | DIR *dir = opendir(SYSCONFDIR "/sway/security.d"); | 340 | DIR *dir = opendir(SYSCONFDIR "/sway/security.d"); |
339 | if (!dir) { | 341 | if (!dir) { |
340 | sway_log(L_ERROR, "%s does not exist, sway will have no security configuration" | 342 | sway_log(L_ERROR, |
341 | " and will probably be broken", SYSCONFDIR "/sway/security.d"); | 343 | "%s does not exist, sway will have no security configuration" |
344 | " and will probably be broken", SYSCONFDIR "/sway/security.d"); | ||
342 | } else { | 345 | } else { |
343 | list_t *secconfigs = create_list(); | 346 | list_t *secconfigs = create_list(); |
344 | char *base = SYSCONFDIR "/sway/security.d/"; | 347 | char *base = SYSCONFDIR "/sway/security.d/"; |
@@ -362,8 +365,12 @@ bool load_main_config(const char *file, bool is_active) { | |||
362 | list_qsort(secconfigs, qstrcmp); | 365 | list_qsort(secconfigs, qstrcmp); |
363 | for (int i = 0; i < secconfigs->length; ++i) { | 366 | for (int i = 0; i < secconfigs->length; ++i) { |
364 | char *_path = secconfigs->items[i]; | 367 | char *_path = secconfigs->items[i]; |
365 | if (stat(_path, &s) || s.st_uid != 0 || s.st_gid != 0 || (((s.st_mode & 0777) != 0644) && (s.st_mode & 0777) != 0444)) { | 368 | if (stat(_path, &s) || s.st_uid != 0 || s.st_gid != 0 || |
366 | sway_log(L_ERROR, "Refusing to load %s - it must be owned by root and mode 644 or 444", _path); | 369 | (((s.st_mode & 0777) != 0644) && |
370 | (s.st_mode & 0777) != 0444)) { | ||
371 | sway_log(L_ERROR, | ||
372 | "Refusing to load %s - it must be owned by root " | ||
373 | "and mode 644 or 444", _path); | ||
367 | success = false; | 374 | success = false; |
368 | } else { | 375 | } else { |
369 | success = success && load_config(_path, config); | 376 | success = success && load_config(_path, config); |
@@ -392,7 +399,8 @@ bool load_main_config(const char *file, bool is_active) { | |||
392 | return success; | 399 | return success; |
393 | } | 400 | } |
394 | 401 | ||
395 | static bool load_include_config(const char *path, const char *parent_dir, struct sway_config *config) { | 402 | static bool load_include_config(const char *path, const char *parent_dir, |
403 | struct sway_config *config) { | ||
396 | // save parent config | 404 | // save parent config |
397 | const char *parent_config = config->current_config; | 405 | const char *parent_config = config->current_config; |
398 | 406 | ||
@@ -402,7 +410,8 @@ static bool load_include_config(const char *path, const char *parent_dir, struct | |||
402 | len = len + strlen(parent_dir) + 2; | 410 | len = len + strlen(parent_dir) + 2; |
403 | full_path = malloc(len * sizeof(char)); | 411 | full_path = malloc(len * sizeof(char)); |
404 | if (!full_path) { | 412 | if (!full_path) { |
405 | sway_log(L_ERROR, "Unable to allocate full path to included config"); | 413 | sway_log(L_ERROR, |
414 | "Unable to allocate full path to included config"); | ||
406 | return false; | 415 | return false; |
407 | } | 416 | } |
408 | snprintf(full_path, len, "%s/%s", parent_dir, path); | 417 | snprintf(full_path, len, "%s/%s", parent_dir, path); |
@@ -421,7 +430,9 @@ static bool load_include_config(const char *path, const char *parent_dir, struct | |||
421 | for (j = 0; j < config->config_chain->length; ++j) { | 430 | for (j = 0; j < config->config_chain->length; ++j) { |
422 | char *old_path = config->config_chain->items[j]; | 431 | char *old_path = config->config_chain->items[j]; |
423 | if (strcmp(real_path, old_path) == 0) { | 432 | if (strcmp(real_path, old_path) == 0) { |
424 | sway_log(L_DEBUG, "%s already included once, won't be included again.", real_path); | 433 | sway_log(L_DEBUG, |
434 | "%s already included once, won't be included again.", | ||
435 | real_path); | ||
425 | free(real_path); | 436 | free(real_path); |
426 | return false; | 437 | return false; |
427 | } | 438 | } |
@@ -509,8 +520,8 @@ bool read_config(FILE *file, struct sway_config *config) { | |||
509 | switch(res->status) { | 520 | switch(res->status) { |
510 | case CMD_FAILURE: | 521 | case CMD_FAILURE: |
511 | case CMD_INVALID: | 522 | case CMD_INVALID: |
512 | sway_log(L_ERROR, "Error on line %i '%s': %s (%s)", line_number, line, | 523 | sway_log(L_ERROR, "Error on line %i '%s': %s (%s)", line_number, |
513 | res->error, config->current_config); | 524 | line, res->error, config->current_config); |
514 | success = false; | 525 | success = false; |
515 | break; | 526 | break; |
516 | 527 | ||
@@ -585,8 +596,7 @@ bool read_config(FILE *file, struct sway_config *config) { | |||
585 | 596 | ||
586 | case CMD_BLOCK_INPUT: | 597 | case CMD_BLOCK_INPUT: |
587 | sway_log(L_DEBUG, "End of input block"); | 598 | sway_log(L_DEBUG, "End of input block"); |
588 | // TODO: input | 599 | current_input_config = NULL; |
589 | //current_input_config = NULL; | ||
590 | block = CMD_BLOCK_END; | 600 | block = CMD_BLOCK_END; |
591 | break; | 601 | break; |
592 | 602 | ||
@@ -651,7 +661,8 @@ char *do_var_replacement(char *str) { | |||
651 | char *newstr = malloc(strlen(str) - vnlen + vvlen + 1); | 661 | char *newstr = malloc(strlen(str) - vnlen + vvlen + 1); |
652 | if (!newstr) { | 662 | if (!newstr) { |
653 | sway_log(L_ERROR, | 663 | sway_log(L_ERROR, |
654 | "Unable to allocate replacement during variable expansion"); | 664 | "Unable to allocate replacement " |
665 | "during variable expansion"); | ||
655 | break; | 666 | break; |
656 | } | 667 | } |
657 | char *newptr = newstr; | 668 | char *newptr = newstr; |