From c0ee2a64065f3a9953e977e517a466361444c144 Mon Sep 17 00:00:00 2001 From: Luminarys Date: Mon, 10 Aug 2015 13:53:43 -0500 Subject: Added in reload and exec_always handling --- sway/config.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'sway/config.c') diff --git a/sway/config.c b/sway/config.c index 26dc88cb..ee6c324c 100644 --- a/sway/config.c +++ b/sway/config.c @@ -18,12 +18,17 @@ void config_defaults(struct sway_config *config) { // Flags config->focus_follows_mouse = true; config->mouse_warping = true; + config->reloading = false; } -struct sway_config *read_config(FILE *file) { +struct sway_config *read_config(FILE *file, bool is_active) { struct sway_config *config = malloc(sizeof(struct sway_config)); config_defaults(config); + if (is_active) { + config->reloading = true; + } + bool success = true; int temp_depth = 0; // Temporary: skip all config sections with depth @@ -56,6 +61,8 @@ _continue: exit(1); } + config->reloading = false; + return config; } -- cgit v1.2.3 From 68beabda0382e63d2c0101d78893eb20967dbe43 Mon Sep 17 00:00:00 2001 From: Luminarys Date: Mon, 10 Aug 2015 14:00:10 -0500 Subject: Style fixes and slight reload command alteration --- sway/config.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'sway/config.c') diff --git a/sway/config.c b/sway/config.c index ee6c324c..da4fac84 100644 --- a/sway/config.c +++ b/sway/config.c @@ -18,7 +18,7 @@ void config_defaults(struct sway_config *config) { // Flags config->focus_follows_mouse = true; config->mouse_warping = true; - config->reloading = false; + config->reloading = false; } struct sway_config *read_config(FILE *file, bool is_active) { @@ -26,7 +26,7 @@ struct sway_config *read_config(FILE *file, bool is_active) { config_defaults(config); if (is_active) { - config->reloading = true; + config->reloading = true; } bool success = true; @@ -49,7 +49,7 @@ struct sway_config *read_config(FILE *file, bool is_active) { if (!temp_depth && handle_command(config, line) != 0) { success = false; } - + _continue: if (line && line[strlen(line) - 1] == '{') { temp_depth++; @@ -61,7 +61,9 @@ _continue: exit(1); } - config->reloading = false; + if (is_active) { + config->reloading = true; + } return config; } -- cgit v1.2.3 From 7c02a1967b3d6345754b69a716459534bd2e1620 Mon Sep 17 00:00:00 2001 From: Luminarys Date: Mon, 10 Aug 2015 14:09:51 -0500 Subject: Spaces to Tabs --- sway/config.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'sway/config.c') diff --git a/sway/config.c b/sway/config.c index da4fac84..280900ca 100644 --- a/sway/config.c +++ b/sway/config.c @@ -18,16 +18,16 @@ void config_defaults(struct sway_config *config) { // Flags config->focus_follows_mouse = true; config->mouse_warping = true; - config->reloading = false; + config->reloading = false; } struct sway_config *read_config(FILE *file, bool is_active) { struct sway_config *config = malloc(sizeof(struct sway_config)); config_defaults(config); - if (is_active) { - config->reloading = true; - } + if (is_active) { + config->reloading = true; + } bool success = true; @@ -61,9 +61,9 @@ _continue: exit(1); } - if (is_active) { - config->reloading = true; - } + if (is_active) { + config->reloading = true; + } return config; } -- cgit v1.2.3 From 508980e3ab930fd1ea16cbb769771126110aa329 Mon Sep 17 00:00:00 2001 From: Luminarys Date: Mon, 10 Aug 2015 14:22:22 -0500 Subject: Abstracted load_config --- sway/config.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'sway/config.c') diff --git a/sway/config.c b/sway/config.c index 280900ca..3c7badec 100644 --- a/sway/config.c +++ b/sway/config.c @@ -8,6 +8,25 @@ #include "commands.h" #include "config.h" +bool load_config() { + // TODO: Allow use of more config file locations + const char *name = "/.sway/config"; + const char *home = getenv("HOME"); + char *temp = malloc(strlen(home) + strlen(name) + 1); + strcpy(temp, home); + strcat(temp, name); + FILE *f = fopen(temp, "r"); + if (!f) { + fprintf(stderr, "Unable to open %s for reading", temp); + free(temp); + return false; + } + free(temp); + config = read_config(f, false); + fclose(f); + return true; +} + void config_defaults(struct sway_config *config) { config->symbols = create_list(); config->modes = create_list(); -- cgit v1.2.3