Abstracted load_config

This commit is contained in:
Luminarys 2015-08-10 14:22:22 -05:00
parent 7c02a1967b
commit 508980e3ab
4 changed files with 26 additions and 19 deletions

View File

@ -195,6 +195,9 @@ int cmd_reload(struct sway_config *config, int argc, char **argv) {
free(temp); free(temp);
config = read_config(f, true); config = read_config(f, true);
fclose(f); fclose(f);
if (load_config()) {
}
return 0; return 0;
} }

View File

@ -8,6 +8,25 @@
#include "commands.h" #include "commands.h"
#include "config.h" #include "config.h"
bool load_config() {
// TODO: Allow use of more config file locations
const char *name = "/.sway/config";
const char *home = getenv("HOME");
char *temp = malloc(strlen(home) + strlen(name) + 1);
strcpy(temp, home);
strcat(temp, name);
FILE *f = fopen(temp, "r");
if (!f) {
fprintf(stderr, "Unable to open %s for reading", temp);
free(temp);
return false;
}
free(temp);
config = read_config(f, false);
fclose(f);
return true;
}
void config_defaults(struct sway_config *config) { void config_defaults(struct sway_config *config) {
config->symbols = create_list(); config->symbols = create_list();
config->modes = create_list(); config->modes = create_list();

View File

@ -33,6 +33,7 @@ struct sway_config {
bool reloading; bool reloading;
}; };
bool load_config();
struct sway_config *read_config(FILE *file, bool is_active); struct sway_config *read_config(FILE *file, bool is_active);
char *do_var_replacement(struct sway_config *config, char *str); char *do_var_replacement(struct sway_config *config, char *str);

View File

@ -9,24 +9,6 @@
struct sway_config *config; struct sway_config *config;
void load_config() {
// TODO: Allow use of more config file locations
const char *name = "/.sway/config";
const char *home = getenv("HOME");
char *temp = malloc(strlen(home) + strlen(name) + 1);
strcpy(temp, home);
strcat(temp, name);
FILE *f = fopen(temp, "r");
if (!f) {
fprintf(stderr, "Unable to open %s for reading", temp);
free(temp);
exit(1);
}
free(temp);
config = read_config(f, false);
fclose(f);
}
int main(int argc, char **argv) { int main(int argc, char **argv) {
init_log(L_DEBUG); // TODO: Control this with command line arg init_log(L_DEBUG); // TODO: Control this with command line arg
init_layout(); init_layout();
@ -61,7 +43,9 @@ int main(int argc, char **argv) {
} }
setenv("DISPLAY", ":1", 1); setenv("DISPLAY", ":1", 1);
load_config(); if (load_config()) {
exit(1);
}
wlc_run(); wlc_run();
return 0; return 0;