diff options
Diffstat (limited to 'sway/config.c')
-rw-r--r-- | sway/config.c | 52 |
1 files changed, 43 insertions, 9 deletions
diff --git a/sway/config.c b/sway/config.c index 2afffab1..c1ec77f9 100644 --- a/sway/config.c +++ b/sway/config.c @@ -25,6 +25,7 @@ #include "sway/commands.h" #include "sway/config.h" #include "sway/criteria.h" +#include "sway/swaynag.h" #include "sway/tree/arrange.h" #include "sway/tree/layout.h" #include "sway/tree/workspace.h" @@ -72,6 +73,8 @@ void free_config(struct sway_config *config) { memset(&config->handler_context, 0, sizeof(config->handler_context)); + free(config->swaynag_command); + // TODO: handle all currently unhandled lists as we add implementations if (config->symbols) { for (int i = 0; i < config->symbols->length; ++i) { @@ -158,6 +161,17 @@ static void set_color(float dest[static 4], uint32_t color) { } static void config_defaults(struct sway_config *config) { + config->swaynag_command = strdup("swaynag"); + config->swaynag_config_errors = (struct swaynag_instance){ + .args = "--type error " + "--message 'There are errors in your config file' " + "--detailed-message " + "--button 'Exit sway' 'swaymsg exit' " + "--button 'Reload sway' 'swaymsg reload'", + .pid = -1, + .detailed = true, + }; + if (!(config->symbols = create_list())) goto cleanup; if (!(config->modes = create_list())) goto cleanup; if (!(config->bars = create_list())) goto cleanup; @@ -204,6 +218,7 @@ static void config_defaults(struct sway_config *config) { config->focus_follows_mouse = true; config->mouse_warping = true; config->focus_wrapping = WRAP_YES; + config->validating = false; config->reloading = false; config->active = false; config->failed = false; @@ -319,7 +334,8 @@ static char *get_config_path(void) { return NULL; // Not reached } -static bool load_config(const char *path, struct sway_config *config) { +static bool load_config(const char *path, struct sway_config *config, + struct swaynag_instance *swaynag) { if (path == NULL) { wlr_log(WLR_ERROR, "Unable to find a config file!"); return false; @@ -338,7 +354,7 @@ static bool load_config(const char *path, struct sway_config *config) { return false; } - bool config_load_success = read_config(f, config); + bool config_load_success = read_config(f, config, swaynag); fclose(f); if (!config_load_success) { @@ -348,7 +364,7 @@ static bool load_config(const char *path, struct sway_config *config) { return true; } -bool load_main_config(const char *file, bool is_active) { +bool load_main_config(const char *file, bool is_active, bool validating) { char *path; if (file != NULL) { path = strdup(file); @@ -363,10 +379,17 @@ bool load_main_config(const char *file, bool is_active) { } config_defaults(config); + config->validating = validating; if (is_active) { wlr_log(WLR_DEBUG, "Performing configuration file reload"); config->reloading = true; config->active = true; + + swaynag_kill(&old_config->swaynag_config_errors); + memcpy(&config->swaynag_config_errors, + &old_config->swaynag_config_errors, + sizeof(struct swaynag_instance)); + create_default_output_configs(); } @@ -423,13 +446,17 @@ bool load_main_config(const char *file, bool is_active) { } */ - success = success && load_config(path, config); + success = success && load_config(path, config, + &config->swaynag_config_errors); if (is_active) { for (int i = 0; i < config->output_configs->length; i++) { apply_output_config_to_outputs(config->output_configs->items[i]); } config->reloading = false; + if (config->swaynag_config_errors.pid > 0) { + swaynag_show(&config->swaynag_config_errors); + } } if (old_config) { @@ -441,7 +468,7 @@ bool load_main_config(const char *file, bool is_active) { } static bool load_include_config(const char *path, const char *parent_dir, - struct sway_config *config) { + struct sway_config *config, struct swaynag_instance *swaynag) { // save parent config const char *parent_config = config->current_config_path; @@ -485,7 +512,7 @@ static bool load_include_config(const char *path, const char *parent_dir, list_add(config->config_chain, real_path); int index = config->config_chain->length - 1; - if (!load_config(real_path, config)) { + if (!load_config(real_path, config, swaynag)) { free(real_path); config->current_config_path = parent_config; list_del(config->config_chain, index); @@ -497,7 +524,8 @@ static bool load_include_config(const char *path, const char *parent_dir, return true; } -bool load_include_configs(const char *path, struct sway_config *config) { +bool load_include_configs(const char *path, struct sway_config *config, + struct swaynag_instance *swaynag) { char *wd = getcwd(NULL, 0); char *parent_path = strdup(config->current_config_path); const char *parent_dir = dirname(parent_path); @@ -519,7 +547,7 @@ bool load_include_configs(const char *path, struct sway_config *config) { char **w = p.we_wordv; size_t i; for (i = 0; i < p.we_wordc; ++i) { - load_include_config(w[i], parent_dir, config); + load_include_config(w[i], parent_dir, config, swaynag); } free(parent_path); wordfree(&p); @@ -575,7 +603,8 @@ static char *expand_line(const char *block, const char *line, bool add_brace) { return expanded; } -bool read_config(FILE *file, struct sway_config *config) { +bool read_config(FILE *file, struct sway_config *config, + struct swaynag_instance *swaynag) { bool reading_main_config = false; char *this_config = NULL; size_t config_size = 0; @@ -665,6 +694,11 @@ bool read_config(FILE *file, struct sway_config *config) { case CMD_INVALID: wlr_log(WLR_ERROR, "Error on line %i '%s': %s (%s)", line_number, line, res->error, config->current_config_path); + if (!config->validating) { + swaynag_log(config->swaynag_command, swaynag, + "Error on line %i (%s) '%s': %s", line_number, + config->current_config_path, line, res->error); + } success = false; break; |