|
|
@ -232,12 +232,12 @@ static char *get_config_path(void) {
|
|
|
|
char *home = getenv("HOME");
|
|
|
|
char *home = getenv("HOME");
|
|
|
|
char *config_home = malloc(strlen(home) + strlen("/.config") + 1);
|
|
|
|
char *config_home = malloc(strlen(home) + strlen("/.config") + 1);
|
|
|
|
if (!config_home) {
|
|
|
|
if (!config_home) {
|
|
|
|
sway_log(L_ERROR, "Unable to allocate $HOME/.config");
|
|
|
|
wlr_log(L_ERROR, "Unable to allocate $HOME/.config");
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
strcpy(config_home, home);
|
|
|
|
strcpy(config_home, home);
|
|
|
|
strcat(config_home, "/.config");
|
|
|
|
strcat(config_home, "/.config");
|
|
|
|
setenv("XDG_CONFIG_HOME", config_home, 1);
|
|
|
|
setenv("XDG_CONFIG_HOME", config_home, 1);
|
|
|
|
sway_log(L_DEBUG, "Set XDG_CONFIG_HOME to %s", config_home);
|
|
|
|
wlr_log(L_DEBUG, "Set XDG_CONFIG_HOME to %s", config_home);
|
|
|
|
free(config_home);
|
|
|
|
free(config_home);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -263,7 +263,7 @@ static char *get_config_path(void) {
|
|
|
|
const char *current_config_path;
|
|
|
|
const char *current_config_path;
|
|
|
|
|
|
|
|
|
|
|
|
static bool load_config(const char *path, struct sway_config *config) {
|
|
|
|
static bool load_config(const char *path, struct sway_config *config) {
|
|
|
|
sway_log(L_INFO, "Loading config from %s", path);
|
|
|
|
wlr_log(L_INFO, "Loading config from %s", path);
|
|
|
|
current_config_path = path;
|
|
|
|
current_config_path = path;
|
|
|
|
|
|
|
|
|
|
|
|
struct stat sb;
|
|
|
|
struct stat sb;
|
|
|
@ -272,13 +272,13 @@ static bool load_config(const char *path, struct sway_config *config) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (path == NULL) {
|
|
|
|
if (path == NULL) {
|
|
|
|
sway_log(L_ERROR, "Unable to find a config file!");
|
|
|
|
wlr_log(L_ERROR, "Unable to find a config file!");
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
FILE *f = fopen(path, "r");
|
|
|
|
FILE *f = fopen(path, "r");
|
|
|
|
if (!f) {
|
|
|
|
if (!f) {
|
|
|
|
sway_log(L_ERROR, "Unable to open %s for reading", path);
|
|
|
|
wlr_log(L_ERROR, "Unable to open %s for reading", path);
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -286,7 +286,7 @@ static bool load_config(const char *path, struct sway_config *config) {
|
|
|
|
fclose(f);
|
|
|
|
fclose(f);
|
|
|
|
|
|
|
|
|
|
|
|
if (!config_load_success) {
|
|
|
|
if (!config_load_success) {
|
|
|
|
sway_log(L_ERROR, "Error(s) loading config!");
|
|
|
|
wlr_log(L_ERROR, "Error(s) loading config!");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
current_config_path = NULL;
|
|
|
|
current_config_path = NULL;
|
|
|
@ -313,7 +313,7 @@ bool load_main_config(const char *file, bool is_active) {
|
|
|
|
|
|
|
|
|
|
|
|
config_defaults(config);
|
|
|
|
config_defaults(config);
|
|
|
|
if (is_active) {
|
|
|
|
if (is_active) {
|
|
|
|
sway_log(L_DEBUG, "Performing configuration file reload");
|
|
|
|
wlr_log(L_DEBUG, "Performing configuration file reload");
|
|
|
|
config->reloading = true;
|
|
|
|
config->reloading = true;
|
|
|
|
config->active = true;
|
|
|
|
config->active = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -327,7 +327,7 @@ bool load_main_config(const char *file, bool is_active) {
|
|
|
|
bool success = true;
|
|
|
|
bool success = true;
|
|
|
|
DIR *dir = opendir(SYSCONFDIR "/sway/security.d");
|
|
|
|
DIR *dir = opendir(SYSCONFDIR "/sway/security.d");
|
|
|
|
if (!dir) {
|
|
|
|
if (!dir) {
|
|
|
|
sway_log(L_ERROR,
|
|
|
|
wlr_log(L_ERROR,
|
|
|
|
"%s does not exist, sway will have no security configuration"
|
|
|
|
"%s does not exist, sway will have no security configuration"
|
|
|
|
" and will probably be broken", SYSCONFDIR "/sway/security.d");
|
|
|
|
" and will probably be broken", SYSCONFDIR "/sway/security.d");
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
@ -356,7 +356,7 @@ bool load_main_config(const char *file, bool is_active) {
|
|
|
|
if (stat(_path, &s) || s.st_uid != 0 || s.st_gid != 0 ||
|
|
|
|
if (stat(_path, &s) || s.st_uid != 0 || s.st_gid != 0 ||
|
|
|
|
(((s.st_mode & 0777) != 0644) &&
|
|
|
|
(((s.st_mode & 0777) != 0644) &&
|
|
|
|
(s.st_mode & 0777) != 0444)) {
|
|
|
|
(s.st_mode & 0777) != 0444)) {
|
|
|
|
sway_log(L_ERROR,
|
|
|
|
wlr_log(L_ERROR,
|
|
|
|
"Refusing to load %s - it must be owned by root "
|
|
|
|
"Refusing to load %s - it must be owned by root "
|
|
|
|
"and mode 644 or 444", _path);
|
|
|
|
"and mode 644 or 444", _path);
|
|
|
|
success = false;
|
|
|
|
success = false;
|
|
|
@ -398,7 +398,7 @@ static bool load_include_config(const char *path, const char *parent_dir,
|
|
|
|
len = len + strlen(parent_dir) + 2;
|
|
|
|
len = len + strlen(parent_dir) + 2;
|
|
|
|
full_path = malloc(len * sizeof(char));
|
|
|
|
full_path = malloc(len * sizeof(char));
|
|
|
|
if (!full_path) {
|
|
|
|
if (!full_path) {
|
|
|
|
sway_log(L_ERROR,
|
|
|
|
wlr_log(L_ERROR,
|
|
|
|
"Unable to allocate full path to included config");
|
|
|
|
"Unable to allocate full path to included config");
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -409,7 +409,7 @@ static bool load_include_config(const char *path, const char *parent_dir,
|
|
|
|
free(full_path);
|
|
|
|
free(full_path);
|
|
|
|
|
|
|
|
|
|
|
|
if (real_path == NULL) {
|
|
|
|
if (real_path == NULL) {
|
|
|
|
sway_log(L_DEBUG, "%s not found.", path);
|
|
|
|
wlr_log(L_DEBUG, "%s not found.", path);
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -418,7 +418,7 @@ static bool load_include_config(const char *path, const char *parent_dir,
|
|
|
|
for (j = 0; j < config->config_chain->length; ++j) {
|
|
|
|
for (j = 0; j < config->config_chain->length; ++j) {
|
|
|
|
char *old_path = config->config_chain->items[j];
|
|
|
|
char *old_path = config->config_chain->items[j];
|
|
|
|
if (strcmp(real_path, old_path) == 0) {
|
|
|
|
if (strcmp(real_path, old_path) == 0) {
|
|
|
|
sway_log(L_DEBUG,
|
|
|
|
wlr_log(L_DEBUG,
|
|
|
|
"%s already included once, won't be included again.",
|
|
|
|
"%s already included once, won't be included again.",
|
|
|
|
real_path);
|
|
|
|
real_path);
|
|
|
|
free(real_path);
|
|
|
|
free(real_path);
|
|
|
@ -472,7 +472,7 @@ bool load_include_configs(const char *path, struct sway_config *config) {
|
|
|
|
// restore wd
|
|
|
|
// restore wd
|
|
|
|
if (chdir(wd) < 0) {
|
|
|
|
if (chdir(wd) < 0) {
|
|
|
|
free(wd);
|
|
|
|
free(wd);
|
|
|
|
sway_log(L_ERROR, "failed to restore working directory");
|
|
|
|
wlr_log(L_ERROR, "failed to restore working directory");
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -508,13 +508,13 @@ bool read_config(FILE *file, struct sway_config *config) {
|
|
|
|
switch(res->status) {
|
|
|
|
switch(res->status) {
|
|
|
|
case CMD_FAILURE:
|
|
|
|
case CMD_FAILURE:
|
|
|
|
case CMD_INVALID:
|
|
|
|
case CMD_INVALID:
|
|
|
|
sway_log(L_ERROR, "Error on line %i '%s': %s (%s)", line_number,
|
|
|
|
wlr_log(L_ERROR, "Error on line %i '%s': %s (%s)", line_number,
|
|
|
|
line, res->error, config->current_config);
|
|
|
|
line, res->error, config->current_config);
|
|
|
|
success = false;
|
|
|
|
success = false;
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case CMD_DEFER:
|
|
|
|
case CMD_DEFER:
|
|
|
|
sway_log(L_DEBUG, "Deferring command `%s'", line);
|
|
|
|
wlr_log(L_DEBUG, "Deferring command `%s'", line);
|
|
|
|
list_add(config->cmd_queue, strdup(line));
|
|
|
|
list_add(config->cmd_queue, strdup(line));
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
@ -522,7 +522,7 @@ bool read_config(FILE *file, struct sway_config *config) {
|
|
|
|
if (block == CMD_BLOCK_END) {
|
|
|
|
if (block == CMD_BLOCK_END) {
|
|
|
|
block = CMD_BLOCK_MODE;
|
|
|
|
block = CMD_BLOCK_MODE;
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
sway_log(L_ERROR, "Invalid block '%s'", line);
|
|
|
|
wlr_log(L_ERROR, "Invalid block '%s'", line);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
@ -530,7 +530,7 @@ bool read_config(FILE *file, struct sway_config *config) {
|
|
|
|
if (block == CMD_BLOCK_END) {
|
|
|
|
if (block == CMD_BLOCK_END) {
|
|
|
|
block = CMD_BLOCK_INPUT;
|
|
|
|
block = CMD_BLOCK_INPUT;
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
sway_log(L_ERROR, "Invalid block '%s'", line);
|
|
|
|
wlr_log(L_ERROR, "Invalid block '%s'", line);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
@ -538,7 +538,7 @@ bool read_config(FILE *file, struct sway_config *config) {
|
|
|
|
if (block == CMD_BLOCK_END) {
|
|
|
|
if (block == CMD_BLOCK_END) {
|
|
|
|
block = CMD_BLOCK_SEAT;
|
|
|
|
block = CMD_BLOCK_SEAT;
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
sway_log(L_ERROR, "Invalid block '%s'", line);
|
|
|
|
wlr_log(L_ERROR, "Invalid block '%s'", line);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
@ -546,7 +546,7 @@ bool read_config(FILE *file, struct sway_config *config) {
|
|
|
|
if (block == CMD_BLOCK_END) {
|
|
|
|
if (block == CMD_BLOCK_END) {
|
|
|
|
block = CMD_BLOCK_BAR;
|
|
|
|
block = CMD_BLOCK_BAR;
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
sway_log(L_ERROR, "Invalid block '%s'", line);
|
|
|
|
wlr_log(L_ERROR, "Invalid block '%s'", line);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
@ -554,7 +554,7 @@ bool read_config(FILE *file, struct sway_config *config) {
|
|
|
|
if (block == CMD_BLOCK_BAR) {
|
|
|
|
if (block == CMD_BLOCK_BAR) {
|
|
|
|
block = CMD_BLOCK_BAR_COLORS;
|
|
|
|
block = CMD_BLOCK_BAR_COLORS;
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
sway_log(L_ERROR, "Invalid block '%s'", line);
|
|
|
|
wlr_log(L_ERROR, "Invalid block '%s'", line);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
@ -562,7 +562,7 @@ bool read_config(FILE *file, struct sway_config *config) {
|
|
|
|
if (block == CMD_BLOCK_END) {
|
|
|
|
if (block == CMD_BLOCK_END) {
|
|
|
|
block = CMD_BLOCK_COMMANDS;
|
|
|
|
block = CMD_BLOCK_COMMANDS;
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
sway_log(L_ERROR, "Invalid block '%s'", line);
|
|
|
|
wlr_log(L_ERROR, "Invalid block '%s'", line);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
@ -570,7 +570,7 @@ bool read_config(FILE *file, struct sway_config *config) {
|
|
|
|
if (block == CMD_BLOCK_END) {
|
|
|
|
if (block == CMD_BLOCK_END) {
|
|
|
|
block = CMD_BLOCK_IPC;
|
|
|
|
block = CMD_BLOCK_IPC;
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
sway_log(L_ERROR, "Invalid block '%s'", line);
|
|
|
|
wlr_log(L_ERROR, "Invalid block '%s'", line);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
@ -578,59 +578,59 @@ bool read_config(FILE *file, struct sway_config *config) {
|
|
|
|
if (block == CMD_BLOCK_IPC) {
|
|
|
|
if (block == CMD_BLOCK_IPC) {
|
|
|
|
block = CMD_BLOCK_IPC_EVENTS;
|
|
|
|
block = CMD_BLOCK_IPC_EVENTS;
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
sway_log(L_ERROR, "Invalid block '%s'", line);
|
|
|
|
wlr_log(L_ERROR, "Invalid block '%s'", line);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case CMD_BLOCK_END:
|
|
|
|
case CMD_BLOCK_END:
|
|
|
|
switch(block) {
|
|
|
|
switch(block) {
|
|
|
|
case CMD_BLOCK_MODE:
|
|
|
|
case CMD_BLOCK_MODE:
|
|
|
|
sway_log(L_DEBUG, "End of mode block");
|
|
|
|
wlr_log(L_DEBUG, "End of mode block");
|
|
|
|
config->current_mode = config->modes->items[0];
|
|
|
|
config->current_mode = config->modes->items[0];
|
|
|
|
block = CMD_BLOCK_END;
|
|
|
|
block = CMD_BLOCK_END;
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case CMD_BLOCK_INPUT:
|
|
|
|
case CMD_BLOCK_INPUT:
|
|
|
|
sway_log(L_DEBUG, "End of input block");
|
|
|
|
wlr_log(L_DEBUG, "End of input block");
|
|
|
|
free_input_config(current_input_config);
|
|
|
|
free_input_config(current_input_config);
|
|
|
|
current_input_config = NULL;
|
|
|
|
current_input_config = NULL;
|
|
|
|
block = CMD_BLOCK_END;
|
|
|
|
block = CMD_BLOCK_END;
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case CMD_BLOCK_SEAT:
|
|
|
|
case CMD_BLOCK_SEAT:
|
|
|
|
sway_log(L_DEBUG, "End of seat block");
|
|
|
|
wlr_log(L_DEBUG, "End of seat block");
|
|
|
|
current_seat_config = NULL;
|
|
|
|
current_seat_config = NULL;
|
|
|
|
block = CMD_BLOCK_END;
|
|
|
|
block = CMD_BLOCK_END;
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case CMD_BLOCK_BAR:
|
|
|
|
case CMD_BLOCK_BAR:
|
|
|
|
sway_log(L_DEBUG, "End of bar block");
|
|
|
|
wlr_log(L_DEBUG, "End of bar block");
|
|
|
|
config->current_bar = NULL;
|
|
|
|
config->current_bar = NULL;
|
|
|
|
block = CMD_BLOCK_END;
|
|
|
|
block = CMD_BLOCK_END;
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case CMD_BLOCK_BAR_COLORS:
|
|
|
|
case CMD_BLOCK_BAR_COLORS:
|
|
|
|
sway_log(L_DEBUG, "End of bar colors block");
|
|
|
|
wlr_log(L_DEBUG, "End of bar colors block");
|
|
|
|
block = CMD_BLOCK_BAR;
|
|
|
|
block = CMD_BLOCK_BAR;
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case CMD_BLOCK_COMMANDS:
|
|
|
|
case CMD_BLOCK_COMMANDS:
|
|
|
|
sway_log(L_DEBUG, "End of commands block");
|
|
|
|
wlr_log(L_DEBUG, "End of commands block");
|
|
|
|
block = CMD_BLOCK_END;
|
|
|
|
block = CMD_BLOCK_END;
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case CMD_BLOCK_IPC:
|
|
|
|
case CMD_BLOCK_IPC:
|
|
|
|
sway_log(L_DEBUG, "End of IPC block");
|
|
|
|
wlr_log(L_DEBUG, "End of IPC block");
|
|
|
|
block = CMD_BLOCK_END;
|
|
|
|
block = CMD_BLOCK_END;
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case CMD_BLOCK_IPC_EVENTS:
|
|
|
|
case CMD_BLOCK_IPC_EVENTS:
|
|
|
|
sway_log(L_DEBUG, "End of IPC events block");
|
|
|
|
wlr_log(L_DEBUG, "End of IPC events block");
|
|
|
|
block = CMD_BLOCK_IPC;
|
|
|
|
block = CMD_BLOCK_IPC;
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case CMD_BLOCK_END:
|
|
|
|
case CMD_BLOCK_END:
|
|
|
|
sway_log(L_ERROR, "Unmatched }");
|
|
|
|
wlr_log(L_ERROR, "Unmatched }");
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
default:;
|
|
|
|
default:;
|
|
|
@ -663,7 +663,7 @@ char *do_var_replacement(char *str) {
|
|
|
|
int vvlen = strlen(var->value);
|
|
|
|
int vvlen = strlen(var->value);
|
|
|
|
char *newstr = malloc(strlen(str) - vnlen + vvlen + 1);
|
|
|
|
char *newstr = malloc(strlen(str) - vnlen + vvlen + 1);
|
|
|
|
if (!newstr) {
|
|
|
|
if (!newstr) {
|
|
|
|
sway_log(L_ERROR,
|
|
|
|
wlr_log(L_ERROR,
|
|
|
|
"Unable to allocate replacement "
|
|
|
|
"Unable to allocate replacement "
|
|
|
|
"during variable expansion");
|
|
|
|
"during variable expansion");
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|