diff --git a/src/config.c b/src/config.c index 64ff641..138fa87 100644 --- a/src/config.c +++ b/src/config.c @@ -525,18 +525,16 @@ init_conf(void) { int ret; - sprintf(final_path, "%s/%s", _strdup(getenv("HOME")), _strdup(FILE_NAME)); - cfg = cfg_init(opts, CFGF_NONE); - ret = cfg_parse(cfg, final_path); + ret = cfg_parse(cfg, conf.confpath); if(ret == CFG_FILE_ERROR || ret == CFG_PARSE_ERROR) { - fprintf(stderr, "WMFS: parsing configuration file (%s) failed\n", final_path); - sprintf(final_path, "%s/wmfs/wmfsrc", XDG_CONFIG_DIR); - fprintf(stderr, "Use the default configuration (%s).\n", final_path); + fprintf(stderr, "WMFS: parsing configuration file (%s) failed\n", conf.confpath); + sprintf(conf.confpath, "%s/wmfs/wmfsrc", XDG_CONFIG_DIR); + fprintf(stderr, "Use the default configuration (%s).\n", conf.confpath); cfg = cfg_init(opts, CFGF_NONE); - ret = cfg_parse(cfg, final_path); + ret = cfg_parse(cfg, conf.confpath); } conf_init_func_list(); diff --git a/src/config_struct.h b/src/config_struct.h index 78d23ee..0bb9fa7 100644 --- a/src/config_struct.h +++ b/src/config_struct.h @@ -32,10 +32,7 @@ #include "wmfs.h" -#define FILE_NAME ".config/wmfs/wmfsrc" - cfg_t *cfg, *cfgtmp; -char final_path[128]; cfg_opt_t misc_opts[] = { diff --git a/src/structs.h b/src/structs.h index 830412b..d2206f1 100644 --- a/src/structs.h +++ b/src/structs.h @@ -278,6 +278,9 @@ typedef struct /* Configuration structure */ typedef struct { + /* Configuration file path */ + char confpath[512]; + /* Misc option */ char *font; Bool raisefocus; diff --git a/src/wmfs.c b/src/wmfs.c index f322ea6..c5aec81 100644 --- a/src/wmfs.c +++ b/src/wmfs.c @@ -345,9 +345,10 @@ main(int argc, char **argv) { int i; - argv_global = _strdup(argv[0]); + argv_global = _strdup(argv[0]); + sprintf(conf.confpath, "%s/"DEF_CONF, getenv("HOME")); - while ((i = getopt(argc, argv, "hvic:s:g:")) != -1) + while((i = getopt(argc, argv, "hvic:s:g:C:")) != -1) { /* For options who need WMFS running */ @@ -362,7 +363,8 @@ main(int argc, char **argv) { case 'h': default: - printf("usage: %s [-ihv] [-c ] [-g ] [-s ]\n" + printf("usage: %s [-ihv] [-C ] [-c ] [-g ] [-s ]\n" + " -C Load a configuration file\n" " -c Execute an uicb function to control WMFS\n" " -g Show information about wmfs status\n" " -s Set the bar(s) statustext\n" @@ -386,6 +388,10 @@ main(int argc, char **argv) exit(EXIT_SUCCESS); break; + case 'C': + strcpy(conf.confpath, optarg); + break; + case 'c': exec_uicb_function(argv[2], ((argv[3]) ? argv[3] : NULL)); XCloseDisplay(dpy); diff --git a/src/wmfs.h b/src/wmfs.h index 553c4e6..cf74310 100644 --- a/src/wmfs.h +++ b/src/wmfs.h @@ -97,6 +97,7 @@ #define IFREE(x) if(x) free(x) #define LEN(x) (sizeof(x) / sizeof((x)[0])) #define deb(p) fprintf(stderr, "debug: %d\n", (p)) +#define DEF_CONF ".config/wmfs/wmfsrc" #define PAD conf.pad /* barwin.c */ diff --git a/wmfs.1 b/wmfs.1 index 14d7507..9dac1e8 100644 --- a/wmfs.1 +++ b/wmfs.1 @@ -13,13 +13,18 @@ .SH "NAME" wmfs \- Window Manager From Scratch .SH "SYNOPSIS" -\fBwmfs\fR [\fB\-v\fR] [\fB\-h\fR] [\fB\-i\fR] [\fB\-c \fR] [\fB\-g \fR] [\fB\-s \fR] +\fBwmfs\fR [\fB\-ihv\fR] [\fB\-C \fR] [\fB\-c \fR] [\fB\-g \fR] [\fB\-s \fR] .sp .SH "DESCRIPTION" \fBWMFS\fR is a basic, lightweight and dynamic tiling windows manager for X\&. .sp .SH "OPTIONS" .PP +\fB\-C \fR +.RS 4 +Load a configuration file\&. +.RE +.PP \fB\-c \fR .RS 4 Execute an uicb function to control WMFS\&.