allow overriding path to theme file and binds file in the regular config

file, and allow overriding config file path in options.h
This commit is contained in:
speedie 2023-06-06 17:59:03 +02:00
parent a9ee831159
commit fd92de24ff
6 changed files with 35 additions and 25 deletions

View file

@ -203,6 +203,8 @@ spmenu = {
global = 1; // Read global .Xresources colors, programs like Pywal use this. (*.color0, *.color1, etc.) (0/1)
theme = 1; // Load theme (~/.config/spmenu/theme.conf) on runtime
binds = 1; // Load binds (~/.config/spmenu/binds.conf) on runtime
themefile = "NULL"; // Path to theme file to load on runtime. NULL means default.
bindsfile = "NULL"; // Path to binds file to load on runtime. NULL means default.
} );
/* Input options */

View file

@ -28,19 +28,19 @@ void readargs(int argc, char *argv[]) {
#if USECONFIG
} else if (!strcmp(argv[j], "-cf") || (!strcmp(argv[j], "--config-file"))) { // specify a config file
if (argv[j+1]) {
argconf = argv[++j];
configfile = argv[++j];
} else {
die("This argument requires a second argument.");
}
} else if (!strcmp(argv[j], "-bf") || (!strcmp(argv[j], "--bind-file"))) { // specify a bind file
if (argv[j+1]) {
argbinds = argv[++j];
bindsfile = argv[++j];
} else {
die("This argument requires a second argument.");
}
} else if (!strcmp(argv[j], "-tm") || (!strcmp(argv[j], "--theme"))) { // specify a theme
if (argv[j+1]) {
argtheme = argv[++j];
themefile = argv[++j];
} else {
die("This argument requires a second argument.");
}
@ -251,13 +251,13 @@ void readargs(int argc, char *argv[]) {
#if USECONFIG
|| !strcmp(argv[i], "-cf")
|| !strcmp(argv[i], "--config-file")
|| (argconf && !strcmp(argv[i], argconf))
|| (configfile && !strcmp(argv[i], configfile))
|| !strcmp(argv[i], "-tm")
|| !strcmp(argv[i], "--theme")
|| (argtheme && !strcmp(argv[i], argtheme))
|| (themefile && !strcmp(argv[i], themefile))
|| !strcmp(argv[i], "-bf")
|| !strcmp(argv[i], "--bind-file")
|| (argbinds && !strcmp(argv[i], argbinds))
|| (bindsfile && !strcmp(argv[i], bindsfile))
#endif
))
continue;
@ -485,13 +485,13 @@ void readargs(int argc, char *argv[]) {
#if USECONFIG
|| !strcmp(argv[i], "-cf")
|| !strcmp(argv[i], "--config-file")
|| (argconf && !strcmp(argv[i], argconf))
|| (configfile && !strcmp(argv[i], configfile))
|| !strcmp(argv[i], "-tm")
|| !strcmp(argv[i], "--theme")
|| (argtheme && !strcmp(argv[i], argtheme))
|| (themefile && !strcmp(argv[i], themefile))
|| !strcmp(argv[i], "-bf")
|| !strcmp(argv[i], "--bind-file")
|| (argbinds && !strcmp(argv[i], argbinds))
|| (bindsfile && !strcmp(argv[i], bindsfile))
#endif
))
continue;

View file

@ -10,7 +10,7 @@ void conf_init(void) {
const char *dest;
// get path for configuration file
if (!argconf) {
if (!configfile) {
if (!(xdg_conf = getenv("XDG_CONFIG_HOME"))) {
// ~/.config/spmenu/spmenu.conf
home = getenv("HOME");
@ -31,11 +31,11 @@ void conf_init(void) {
sprintf(cfgfile, "%s/%s", xdg_conf, "spmenu/spmenu.conf");
}
} else { // custom config path
if (!(cfgfile = malloc(snprintf(NULL, 0, "%s", argconf) + 1))) {
if (!(cfgfile = malloc(snprintf(NULL, 0, "%s", configfile) + 1))) {
die("spmenu: failed to malloc cfgfile");
}
sprintf(cfgfile, "%s", argconf);
sprintf(cfgfile, "%s", configfile);
}
// don't bother trying to load if it doesn't exist.
@ -424,6 +424,14 @@ void conf_init(void) {
config_setting_lookup_int(conf, "binds", &loadbinds); // spmenu.file.binds
config_setting_lookup_int(conf, "global", &globalcolors); // spmenu.file.global
config_setting_lookup_int(conf, "xresources", &xresources); // spmenu.file.xresources
if (config_setting_lookup_string(conf, "themefile", &dest)) {
themefile = strdup(dest);
}
if (config_setting_lookup_string(conf, "bindsfile", &dest)) {
bindsfile = strdup(dest);
}
}
}
@ -716,7 +724,7 @@ void conf_init(void) {
theme_load();
}
if (!argbinds) {
if (!bindsfile || !strcmp(bindsfile, "NULL")) {
if (!(xdg_conf = getenv("XDG_CONFIG_HOME"))) {
home = getenv("HOME");
@ -733,11 +741,11 @@ void conf_init(void) {
sprintf(bindfile, "%s/%s", xdg_conf, "spmenu/binds.conf");
}
} else { // custom keys path
if (!(bindfile = malloc(snprintf(NULL, 0, "%s", argbinds) + 1))) {
if (!(bindfile = malloc(snprintf(NULL, 0, "%s", bindsfile) + 1))) {
die("spmenu: failed to malloc bindfile");
}
sprintf(bindfile, "%s", argbinds);
sprintf(bindfile, "%s", bindsfile);
}
// don't bother trying to load if it doesn't exist.

View file

@ -10,7 +10,7 @@ void theme_load(void) {
if (!loadtheme) return;
// get path for configuration file
if (!argtheme) {
if (!themefile || !strcmp(themefile, "NULL")) {
if (!(xdg_conf = getenv("XDG_CONFIG_HOME"))) {
// ~/.config/spmenu/theme.conf
home = getenv("HOME");
@ -31,11 +31,11 @@ void theme_load(void) {
sprintf(theme, "%s/%s", xdg_conf, "spmenu/theme.conf");
}
} else { // custom config path
if (!(theme = malloc(snprintf(NULL, 0, "%s", argtheme) + 1))) {
if (!(theme = malloc(snprintf(NULL, 0, "%s", themefile) + 1))) {
die("spmenu: failed to malloc theme");
}
sprintf(theme, "%s", argtheme);
sprintf(theme, "%s", themefile);
}
// don't bother trying to load if it doesn't exist.

View file

@ -15,6 +15,13 @@ static int loadtheme = 1; /* Load theme (~/.config/spmenu/them
static int loadbinds = 1; /* Load keybind file (~/.config/spmenu/binds.conf) on runtime */
static int mon = -1; /* Monitor to run spmenu on */
/* Config file options */
#if USECONFIG
static char *configfile = NULL; /* Config file path. Default is ~/.config/spmenu/spmenu.conf */
static char *themefile = NULL; /* Theme file path. Default is ~/.config/spmenu/theme.conf */
static char *bindsfile = NULL; /* Keybind file path. Default is ~/.config/spmenu/binds.conf */
#endif
/* Window options */
static int alpha = 1; /* Enable alpha */
static int menuposition = 2; /* Position of the menu (0: Bottom, 1: Top, 2: Center */

View file

@ -164,13 +164,6 @@ static int oh = 0;
#endif
static int fullscreen = 0;
// config file
#if USECONFIG
static char *argconf = NULL; // arg config path
static char *argtheme = NULL; // arg theme path
static char *argbinds = NULL; // arg binds path
#endif
// set an integer to 1 if we have rtl enabled, this saves a lot of lines and duplicate code
#if USERTL
static int isrtl = 1;