diff options
Diffstat (limited to 'sway/commands/reload.c')
-rw-r--r-- | sway/commands/reload.c | 36 |
1 files changed, 25 insertions, 11 deletions
diff --git a/sway/commands/reload.c b/sway/commands/reload.c index 36fb9092..9e136d48 100644 --- a/sway/commands/reload.c +++ b/sway/commands/reload.c @@ -3,15 +3,12 @@ #include "sway/commands.h" #include "sway/config.h" #include "sway/ipc-server.h" +#include "sway/server.h" #include "sway/tree/arrange.h" #include "list.h" +#include "log.h" -struct cmd_results *cmd_reload(int argc, char **argv) { - struct cmd_results *error = NULL; - if ((error = checkarg(argc, "reload", EXPECTED_EQUAL_TO, 0))) { - return error; - } - +static void do_reload(void *data) { // store bar ids to check against new bars for barconfig_update events list_t *bar_ids = create_list(); for (int i = 0; i < config->bars->length; ++i) { @@ -20,9 +17,12 @@ struct cmd_results *cmd_reload(int argc, char **argv) { } if (!load_main_config(config->current_config_path, true, false)) { - return cmd_results_new(CMD_FAILURE, "reload", - "Error(s) reloading config."); + wlr_log(WLR_ERROR, "Error(s) reloading config"); + list_foreach(bar_ids, free); + list_free(bar_ids); + return; } + ipc_event_workspace(NULL, NULL, "reload"); load_swaybars(); @@ -37,12 +37,26 @@ struct cmd_results *cmd_reload(int argc, char **argv) { } } - for (int i = 0; i < bar_ids->length; ++i) { - free(bar_ids->items[i]); - } + list_foreach(bar_ids, free); list_free(bar_ids); arrange_root(); +} + +struct cmd_results *cmd_reload(int argc, char **argv) { + struct cmd_results *error = NULL; + if ((error = checkarg(argc, "reload", EXPECTED_EQUAL_TO, 0))) { + return error; + } + + if (!load_main_config(config->current_config_path, true, true)) { + return cmd_results_new(CMD_FAILURE, "reload", + "Error(s) reloading config."); + } + + // The reload command frees a lot of stuff, so to avoid use-after-frees + // we schedule the reload to happen using an idle event. + wl_event_loop_add_idle(server.wl_event_loop, do_reload, NULL); return cmd_results_new(CMD_SUCCESS, NULL, NULL); } |