diff options
author | Brian Ashworth <bosrsf04@gmail.com> | 2018-11-28 11:08:54 -0500 |
---|---|---|
committer | Brian Ashworth <bosrsf04@gmail.com> | 2018-11-28 11:09:01 -0500 |
commit | e5f90f25d755b19151dfcfd98790c1bad3eb8068 (patch) | |
tree | c6af192b469e6cf86ee00cb5d0ab4e03a98bacae /sway | |
parent | Merge pull request #3211 from emersion/child-view-unmapped-segfault (diff) | |
download | sway-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')
-rw-r--r-- | sway/commands/bind.c | 8 | ||||
-rw-r--r-- | sway/commands/output/background.c | 7 | ||||
-rw-r--r-- | sway/config.c | 28 |
3 files changed, 36 insertions, 7 deletions
diff --git a/sway/commands/bind.c b/sway/commands/bind.c index 34881b0f..9112815f 100644 --- a/sway/commands/bind.c +++ b/sway/commands/bind.c | |||
@@ -255,8 +255,12 @@ static struct cmd_results *cmd_bindsym_or_bindcode(int argc, char **argv, | |||
255 | for (int i = 0; i < mode_bindings->length; ++i) { | 255 | for (int i = 0; i < mode_bindings->length; ++i) { |
256 | struct sway_binding *config_binding = mode_bindings->items[i]; | 256 | struct sway_binding *config_binding = mode_bindings->items[i]; |
257 | if (binding_key_compare(binding, config_binding)) { | 257 | if (binding_key_compare(binding, config_binding)) { |
258 | wlr_log(WLR_DEBUG, "overwriting old binding with command '%s'", | 258 | wlr_log(WLR_INFO, "Overwriting binding '%s' for device '%s' " |
259 | config_binding->command); | 259 | "from `%s` to `%s`", argv[0], binding->input, |
260 | binding->command, config_binding->command); | ||
261 | config_add_swaynag_warning("Overwriting binding '%s' for device " | ||
262 | "'%s' to `%s` from `%s`", argv[0], binding->input, | ||
263 | binding->command, config_binding->command); | ||
260 | free_sway_binding(config_binding); | 264 | free_sway_binding(config_binding); |
261 | mode_bindings->items[i] = binding; | 265 | mode_bindings->items[i] = binding; |
262 | overwritten = true; | 266 | overwritten = true; |
diff --git a/sway/commands/output/background.c b/sway/commands/output/background.c index 30fb47c4..2cd1b76a 100644 --- a/sway/commands/output/background.c +++ b/sway/commands/output/background.c | |||
@@ -116,11 +116,8 @@ struct cmd_results *output_cmd_background(int argc, char **argv) { | |||
116 | if (!can_access) { | 116 | if (!can_access) { |
117 | wlr_log(WLR_ERROR, "Unable to access background file '%s': %s", | 117 | wlr_log(WLR_ERROR, "Unable to access background file '%s': %s", |
118 | src, strerror(errno)); | 118 | src, strerror(errno)); |
119 | if (config->reading && !config->validating) { | 119 | config_add_swaynag_warning("Unable to access background file '%s'", |
120 | swaynag_log(config->swaynag_command, | 120 | src); |
121 | &config->swaynag_config_errors, | ||
122 | "Unable to access background file '%s'", src); | ||
123 | } | ||
124 | free(src); | 121 | free(src); |
125 | } else { | 122 | } else { |
126 | // Escape double quotes in the final path for swaybg | 123 | // Escape double quotes in the final path for swaybg |
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 | ||
772 | void 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 | |||
768 | char *do_var_replacement(char *str) { | 796 | char *do_var_replacement(char *str) { |
769 | int i; | 797 | int i; |
770 | char *find = str; | 798 | char *find = str; |