aboutsummaryrefslogtreecommitdiff
path: root/sway/commands/reload.c
diff options
context:
space:
mode:
authorIan Fan <ianfan0@gmail.com>2018-10-08 12:05:18 +0000
committerGitHub <noreply@github.com>2018-10-08 12:05:18 +0000
commitb3b17280de54021657eabf2df4c3dbfd0039bac8 (patch)
treed2602caa071680a898a80f8096ed8f787103329e /sway/commands/reload.c
parent89f4ebef064809c4e3d4cc08f8c7f08f4bc6d420 (diff)
parente168e8f0ffbcd3924570aec63655c6ca0ab384fa (diff)
Merge pull request #2789 from RyanDwyer/reload-idle
Reload config using idle event
Diffstat (limited to 'sway/commands/reload.c')
-rw-r--r--sway/commands/reload.c36
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);
}