aboutsummaryrefslogtreecommitdiffstats
path: root/sway/config.c
diff options
context:
space:
mode:
authorLibravatar Brian Ashworth <bosrsf04@gmail.com>2018-11-28 11:08:54 -0500
committerLibravatar Brian Ashworth <bosrsf04@gmail.com>2018-11-28 11:09:01 -0500
commite5f90f25d755b19151dfcfd98790c1bad3eb8068 (patch)
treec6af192b469e6cf86ee00cb5d0ab4e03a98bacae /sway/config.c
parentMerge pull request #3211 from emersion/child-view-unmapped-segfault (diff)
downloadsway-e5f90f25d755b19151dfcfd98790c1bad3eb8068.tar.gz
sway-e5f90f25d755b19151dfcfd98790c1bad3eb8068.tar.zst
sway-e5f90f25d755b19151dfcfd98790c1bad3eb8068.zip
Introduce a way to show config warnings in swaynag
Adds the function `config_add_swaynag_warning(char *fmt, ...)` so that handlers can add warnings to the swaynag config log in a uniform way. The formatting is identical to errors and include the line number, line, and config path. This also alters the background file access warning to use the function and introduces a warning for duplicate bindings.
Diffstat (limited to 'sway/config.c')
-rw-r--r--sway/config.c28
1 files changed, 28 insertions, 0 deletions
diff --git a/sway/config.c b/sway/config.c
index ed288060..46322374 100644
--- a/sway/config.c
+++ b/sway/config.c
@@ -700,6 +700,8 @@ bool read_config(FILE *file, struct sway_config *config,
700 free(line); 700 free(line);
701 return false; 701 return false;
702 } 702 }
703 config->current_config_line_number = line_number;
704 config->current_config_line = line;
703 struct cmd_results *res; 705 struct cmd_results *res;
704 if (block && strcmp(block, "<commands>") == 0) { 706 if (block && strcmp(block, "<commands>") == 0) {
705 // Special case 707 // Special case
@@ -761,10 +763,36 @@ bool read_config(FILE *file, struct sway_config *config,
761 } 763 }
762 list_foreach(stack, free); 764 list_foreach(stack, free);
763 list_free(stack); 765 list_free(stack);
766 config->current_config_line_number = 0;
767 config->current_config_line = NULL;
764 768
765 return success; 769 return success;
766} 770}
767 771
772void config_add_swaynag_warning(char *fmt, ...) {
773 if (config->reading && !config->validating) {
774 va_list args;
775 va_start(args, fmt);
776 size_t length = vsnprintf(NULL, 0, fmt, args) + 1;
777 va_end(args);
778
779 char *temp = malloc(length + 1);
780 if (!temp) {
781 wlr_log(WLR_ERROR, "Failed to allocate buffer for warning.");
782 return;
783 }
784
785 va_start(args, fmt);
786 vsnprintf(temp, length, fmt, args);
787 va_end(args);
788
789 swaynag_log(config->swaynag_command, &config->swaynag_config_errors,
790 "Warning on line %i (%s) '%s': %s",
791 config->current_config_line_number, config->current_config_path,
792 config->current_config_line, temp);
793 }
794}
795
768char *do_var_replacement(char *str) { 796char *do_var_replacement(char *str) {
769 int i; 797 int i;
770 char *find = str; 798 char *find = str;