summaryrefslogtreecommitdiffstats
path: root/sway/config.c
diff options
context:
space:
mode:
Diffstat (limited to 'sway/config.c')
-rw-r--r--sway/config.c52
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 @@
25#include "sway/commands.h" 25#include "sway/commands.h"
26#include "sway/config.h" 26#include "sway/config.h"
27#include "sway/criteria.h" 27#include "sway/criteria.h"
28#include "sway/swaynag.h"
28#include "sway/tree/arrange.h" 29#include "sway/tree/arrange.h"
29#include "sway/tree/layout.h" 30#include "sway/tree/layout.h"
30#include "sway/tree/workspace.h" 31#include "sway/tree/workspace.h"
@@ -72,6 +73,8 @@ void free_config(struct sway_config *config) {
72 73
73 memset(&config->handler_context, 0, sizeof(config->handler_context)); 74 memset(&config->handler_context, 0, sizeof(config->handler_context));
74 75
76 free(config->swaynag_command);
77
75 // TODO: handle all currently unhandled lists as we add implementations 78 // TODO: handle all currently unhandled lists as we add implementations
76 if (config->symbols) { 79 if (config->symbols) {
77 for (int i = 0; i < config->symbols->length; ++i) { 80 for (int i = 0; i < config->symbols->length; ++i) {
@@ -158,6 +161,17 @@ static void set_color(float dest[static 4], uint32_t color) {
158} 161}
159 162
160static void config_defaults(struct sway_config *config) { 163static void config_defaults(struct sway_config *config) {
164 config->swaynag_command = strdup("swaynag");
165 config->swaynag_config_errors = (struct swaynag_instance){
166 .args = "--type error "
167 "--message 'There are errors in your config file' "
168 "--detailed-message "
169 "--button 'Exit sway' 'swaymsg exit' "
170 "--button 'Reload sway' 'swaymsg reload'",
171 .pid = -1,
172 .detailed = true,
173 };
174
161 if (!(config->symbols = create_list())) goto cleanup; 175 if (!(config->symbols = create_list())) goto cleanup;
162 if (!(config->modes = create_list())) goto cleanup; 176 if (!(config->modes = create_list())) goto cleanup;
163 if (!(config->bars = create_list())) goto cleanup; 177 if (!(config->bars = create_list())) goto cleanup;
@@ -204,6 +218,7 @@ static void config_defaults(struct sway_config *config) {
204 config->focus_follows_mouse = true; 218 config->focus_follows_mouse = true;
205 config->mouse_warping = true; 219 config->mouse_warping = true;
206 config->focus_wrapping = WRAP_YES; 220 config->focus_wrapping = WRAP_YES;
221 config->validating = false;
207 config->reloading = false; 222 config->reloading = false;
208 config->active = false; 223 config->active = false;
209 config->failed = false; 224 config->failed = false;
@@ -319,7 +334,8 @@ static char *get_config_path(void) {
319 return NULL; // Not reached 334 return NULL; // Not reached
320} 335}
321 336
322static bool load_config(const char *path, struct sway_config *config) { 337static bool load_config(const char *path, struct sway_config *config,
338 struct swaynag_instance *swaynag) {
323 if (path == NULL) { 339 if (path == NULL) {
324 wlr_log(WLR_ERROR, "Unable to find a config file!"); 340 wlr_log(WLR_ERROR, "Unable to find a config file!");
325 return false; 341 return false;
@@ -338,7 +354,7 @@ static bool load_config(const char *path, struct sway_config *config) {
338 return false; 354 return false;
339 } 355 }
340 356
341 bool config_load_success = read_config(f, config); 357 bool config_load_success = read_config(f, config, swaynag);
342 fclose(f); 358 fclose(f);
343 359
344 if (!config_load_success) { 360 if (!config_load_success) {
@@ -348,7 +364,7 @@ static bool load_config(const char *path, struct sway_config *config) {
348 return true; 364 return true;
349} 365}
350 366
351bool load_main_config(const char *file, bool is_active) { 367bool load_main_config(const char *file, bool is_active, bool validating) {
352 char *path; 368 char *path;
353 if (file != NULL) { 369 if (file != NULL) {
354 path = strdup(file); 370 path = strdup(file);
@@ -363,10 +379,17 @@ bool load_main_config(const char *file, bool is_active) {
363 } 379 }
364 380
365 config_defaults(config); 381 config_defaults(config);
382 config->validating = validating;
366 if (is_active) { 383 if (is_active) {
367 wlr_log(WLR_DEBUG, "Performing configuration file reload"); 384 wlr_log(WLR_DEBUG, "Performing configuration file reload");
368 config->reloading = true; 385 config->reloading = true;
369 config->active = true; 386 config->active = true;
387
388 swaynag_kill(&old_config->swaynag_config_errors);
389 memcpy(&config->swaynag_config_errors,
390 &old_config->swaynag_config_errors,
391 sizeof(struct swaynag_instance));
392
370 create_default_output_configs(); 393 create_default_output_configs();
371 } 394 }
372 395
@@ -423,13 +446,17 @@ bool load_main_config(const char *file, bool is_active) {
423 } 446 }
424 */ 447 */
425 448
426 success = success && load_config(path, config); 449 success = success && load_config(path, config,
450 &config->swaynag_config_errors);
427 451
428 if (is_active) { 452 if (is_active) {
429 for (int i = 0; i < config->output_configs->length; i++) { 453 for (int i = 0; i < config->output_configs->length; i++) {
430 apply_output_config_to_outputs(config->output_configs->items[i]); 454 apply_output_config_to_outputs(config->output_configs->items[i]);
431 } 455 }
432 config->reloading = false; 456 config->reloading = false;
457 if (config->swaynag_config_errors.pid > 0) {
458 swaynag_show(&config->swaynag_config_errors);
459 }
433 } 460 }
434 461
435 if (old_config) { 462 if (old_config) {
@@ -441,7 +468,7 @@ bool load_main_config(const char *file, bool is_active) {
441} 468}
442 469
443static bool load_include_config(const char *path, const char *parent_dir, 470static bool load_include_config(const char *path, const char *parent_dir,
444 struct sway_config *config) { 471 struct sway_config *config, struct swaynag_instance *swaynag) {
445 // save parent config 472 // save parent config
446 const char *parent_config = config->current_config_path; 473 const char *parent_config = config->current_config_path;
447 474
@@ -485,7 +512,7 @@ static bool load_include_config(const char *path, const char *parent_dir,
485 list_add(config->config_chain, real_path); 512 list_add(config->config_chain, real_path);
486 int index = config->config_chain->length - 1; 513 int index = config->config_chain->length - 1;
487 514
488 if (!load_config(real_path, config)) { 515 if (!load_config(real_path, config, swaynag)) {
489 free(real_path); 516 free(real_path);
490 config->current_config_path = parent_config; 517 config->current_config_path = parent_config;
491 list_del(config->config_chain, index); 518 list_del(config->config_chain, index);
@@ -497,7 +524,8 @@ static bool load_include_config(const char *path, const char *parent_dir,
497 return true; 524 return true;
498} 525}
499 526
500bool load_include_configs(const char *path, struct sway_config *config) { 527bool load_include_configs(const char *path, struct sway_config *config,
528 struct swaynag_instance *swaynag) {
501 char *wd = getcwd(NULL, 0); 529 char *wd = getcwd(NULL, 0);
502 char *parent_path = strdup(config->current_config_path); 530 char *parent_path = strdup(config->current_config_path);
503 const char *parent_dir = dirname(parent_path); 531 const char *parent_dir = dirname(parent_path);
@@ -519,7 +547,7 @@ bool load_include_configs(const char *path, struct sway_config *config) {
519 char **w = p.we_wordv; 547 char **w = p.we_wordv;
520 size_t i; 548 size_t i;
521 for (i = 0; i < p.we_wordc; ++i) { 549 for (i = 0; i < p.we_wordc; ++i) {
522 load_include_config(w[i], parent_dir, config); 550 load_include_config(w[i], parent_dir, config, swaynag);
523 } 551 }
524 free(parent_path); 552 free(parent_path);
525 wordfree(&p); 553 wordfree(&p);
@@ -575,7 +603,8 @@ static char *expand_line(const char *block, const char *line, bool add_brace) {
575 return expanded; 603 return expanded;
576} 604}
577 605
578bool read_config(FILE *file, struct sway_config *config) { 606bool read_config(FILE *file, struct sway_config *config,
607 struct swaynag_instance *swaynag) {
579 bool reading_main_config = false; 608 bool reading_main_config = false;
580 char *this_config = NULL; 609 char *this_config = NULL;
581 size_t config_size = 0; 610 size_t config_size = 0;
@@ -665,6 +694,11 @@ bool read_config(FILE *file, struct sway_config *config) {
665 case CMD_INVALID: 694 case CMD_INVALID:
666 wlr_log(WLR_ERROR, "Error on line %i '%s': %s (%s)", line_number, 695 wlr_log(WLR_ERROR, "Error on line %i '%s': %s (%s)", line_number,
667 line, res->error, config->current_config_path); 696 line, res->error, config->current_config_path);
697 if (!config->validating) {
698 swaynag_log(config->swaynag_command, swaynag,
699 "Error on line %i (%s) '%s': %s", line_number,
700 config->current_config_path, line, res->error);
701 }
668 success = false; 702 success = false;
669 break; 703 break;
670 704