mirror of
https://github.com/swaywm/sway.git
synced 2024-12-28 16:06:37 +01:00
Allowed for execd commands to be spawned after abort
This commit is contained in:
parent
d785cbd54c
commit
ea9efc884d
5 changed files with 43 additions and 20 deletions
|
@ -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) {
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue