2018-07-14 08:22:34 +10:00
|
|
|
#define _XOPEN_SOURCE 500
|
|
|
|
#include <string.h>
|
2018-01-06 08:05:48 +11:00
|
|
|
#include "sway/commands.h"
|
|
|
|
#include "sway/config.h"
|
2018-07-14 08:22:34 +10:00
|
|
|
#include "sway/ipc-server.h"
|
2018-04-28 11:26:14 +10:00
|
|
|
#include "sway/tree/arrange.h"
|
2018-07-14 08:22:34 +10:00
|
|
|
#include "list.h"
|
2018-01-06 08:05:48 +11:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
2018-07-14 08:22:34 +10:00
|
|
|
|
|
|
|
// 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) {
|
|
|
|
struct bar_config *bar = config->bars->items[i];
|
|
|
|
list_add(bar_ids, strdup(bar->id));
|
|
|
|
}
|
|
|
|
|
2018-08-03 11:37:29 +10:00
|
|
|
if (!load_main_config(config->current_config_path, true, false)) {
|
2018-08-02 13:54:40 +10:00
|
|
|
return cmd_results_new(CMD_FAILURE, "reload",
|
|
|
|
"Error(s) reloading config.");
|
2018-01-06 08:05:48 +11:00
|
|
|
}
|
2018-07-18 20:38:06 +10:00
|
|
|
ipc_event_workspace(NULL, NULL, "reload");
|
2018-01-06 08:05:48 +11:00
|
|
|
|
2018-03-30 09:09:42 +11:00
|
|
|
load_swaybars();
|
2018-07-14 08:22:34 +10:00
|
|
|
|
|
|
|
for (int i = 0; i < config->bars->length; ++i) {
|
|
|
|
struct bar_config *bar = config->bars->items[i];
|
|
|
|
for (int j = 0; j < bar_ids->length; ++j) {
|
|
|
|
if (strcmp(bar->id, bar_ids->items[j]) == 0) {
|
|
|
|
ipc_event_barconfig_update(bar);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = 0; i < bar_ids->length; ++i) {
|
|
|
|
free(bar_ids->items[i]);
|
|
|
|
}
|
|
|
|
list_free(bar_ids);
|
|
|
|
|
2018-07-14 23:14:55 +10:00
|
|
|
arrange_windows(&root_container);
|
2018-08-02 13:54:40 +10:00
|
|
|
|
2018-01-06 08:05:48 +11:00
|
|
|
return cmd_results_new(CMD_SUCCESS, NULL, NULL);
|
|
|
|
}
|