From ab130fb56b5c450d3821cfdfc18fc7a37487c70a Mon Sep 17 00:00:00 2001 From: Luminarys Date: Thu, 13 Aug 2015 12:32:43 -0500 Subject: Added in command queue --- sway/config.h | 1 + 1 file changed, 1 insertion(+) (limited to 'sway/config.h') diff --git a/sway/config.h b/sway/config.h index 62b65723..f55453a3 100644 --- a/sway/config.h +++ b/sway/config.h @@ -24,6 +24,7 @@ struct sway_mode { struct sway_config { list_t *symbols; list_t *modes; + list_t *cmd_queue; struct sway_mode *current_mode; // Flags -- cgit v1.2.3 From ea9efc884d92d32863287b8d8e5a5f8bd631f9f5 Mon Sep 17 00:00:00 2001 From: Luminarys Date: Thu, 13 Aug 2015 14:41:29 -0500 Subject: Allowed for execd commands to be spawned after abort --- sway/commands.c | 2 +- sway/config.c | 44 ++++++++++++++++++++++++++++---------------- sway/config.h | 5 +++-- sway/handlers.c | 9 +++++++++ sway/main.c | 3 ++- 5 files changed, 43 insertions(+), 20 deletions(-) (limited to 'sway/config.h') diff --git a/sway/commands.c b/sway/commands.c index cae35237..c95b9858 100644 --- a/sway/commands.c +++ b/sway/commands.c @@ -229,7 +229,7 @@ static bool cmd_set(struct sway_config *config, int argc, char **argv) { static bool _do_split(struct sway_config *config, int argc, char **argv, int layout) { char *name = layout == L_VERT ? "splitv": - layout == L_HORIZ ? "splith":"split"; + layout == L_HORIZ ? "splith":"split"; if (!checkarg(argc, name, EXPECTED_EQUAL_TO, 0)) { return false; } diff --git a/sway/config.c b/sway/config.c index 869fa077..d96d23fc 100644 --- a/sway/config.c +++ b/sway/config.c @@ -25,9 +25,16 @@ bool load_config() { return false; } free(temp); - config = read_config(f, false); + + bool config_load_success; + if (config) { + config_load_success = read_config(f, true); + } else { + config_load_success = read_config(f, false); + } fclose(f); - return true; + + return config_load_success; } void config_defaults(struct sway_config *config) { @@ -42,14 +49,17 @@ void config_defaults(struct sway_config *config) { config->focus_follows_mouse = true; config->mouse_warping = true; config->reloading = false; + config->active = false; + config->failed = false; } -struct sway_config *read_config(FILE *file, bool is_active) { - struct sway_config *config = malloc(sizeof(struct sway_config)); - config_defaults(config); - +bool read_config(FILE *file, bool is_active) { + struct sway_config *temp_config = malloc(sizeof(struct sway_config)); + config_defaults(temp_config); if (is_active) { - config->reloading = true; + sway_log(L_DEBUG, "Performing configuration file reload"); + temp_config->reloading = true; + temp_config->active = true; } bool success = true; @@ -72,14 +82,19 @@ struct sway_config *read_config(FILE *file, bool is_active) { // Any command which would require wlc to be initialized // should be queued for later execution list_t *args = split_string(line, " "); - if (strcmp("workspace", args->items[0]) == 0) { + if (!is_active && ( + strcmp("workspace", args->items[0]) == 0 || + strcmp("exec", args->items[0]) == 0 || + strcmp("exec_always", args->items[0]) == 0 )) { sway_log(L_DEBUG, "Deferring command %s", line); + char *cmd = malloc(strlen(line) + 1); strcpy(cmd, line); - list_add(config->cmd_queue, cmd); - } else if (!temp_depth && !handle_command(config, line)) { + list_add(temp_config->cmd_queue, cmd); + } else if (!temp_depth && !handle_command(temp_config, line)) { sway_log(L_DEBUG, "Config load failed for line %s", line); success = false; + temp_config->failed = true; } list_free(args); @@ -90,15 +105,12 @@ _continue: free(line); } - if (success == false) { - exit(1); - } - if (is_active) { - config->reloading = false; + temp_config->reloading = false; } + config = temp_config; - return config; + return success; } char *do_var_replacement(struct sway_config *config, char *str) { diff --git a/sway/config.h b/sway/config.h index f55453a3..c9fd374c 100644 --- a/sway/config.h +++ b/sway/config.h @@ -30,12 +30,13 @@ struct sway_config { // Flags bool focus_follows_mouse; bool mouse_warping; - + bool active; + bool failed; bool reloading; }; bool load_config(); -struct sway_config *read_config(FILE *file, bool is_active); +bool read_config(FILE *file, bool is_active); char *do_var_replacement(struct sway_config *config, char *str); extern struct sway_config *config; diff --git a/sway/handlers.c b/sway/handlers.c index 4411b947..48c6cbf7 100644 --- a/sway/handlers.c +++ b/sway/handlers.c @@ -8,6 +8,7 @@ #include "config.h" #include "commands.h" #include "handlers.h" +#include "stringop.h" static bool handle_output_created(wlc_handle output) { add_output(output); @@ -165,11 +166,19 @@ static bool handle_pointer_button(wlc_handle view, uint32_t time, const struct w static void handle_wlc_ready(void) { sway_log(L_DEBUG, "Compositor is ready, executing cmds in queue"); + int i; for (i = 0; i < config->cmd_queue->length; ++i) { handle_command(config, config->cmd_queue->items[i]); } free_flat_list(config->cmd_queue); + + if (config->failed) { + sway_log(L_ERROR, "Programs have been execd, aborting!"); + sway_abort("Unable to load config"); + } + + config->active = true; } diff --git a/sway/main.c b/sway/main.c index b48d4b19..061564e2 100644 --- a/sway/main.c +++ b/sway/main.c @@ -19,7 +19,7 @@ int main(int argc, char **argv) { signal(SIGCHLD, sigchld_handle); if (!load_config()) { - sway_abort("Unable to load config"); + sway_log(L_ERROR, "Config load failed, aborting sway post init!"); } setenv("WLC_DIM", "0", 0); @@ -29,6 +29,7 @@ int main(int argc, char **argv) { setenv("DISPLAY", ":1", 1); wlc_run(); + return 0; } -- cgit v1.2.3