Load hierarchy of rc.xml files from directories

This commit is contained in:
Simon Long 2024-01-05 12:00:59 +00:00
parent 785a34e8ad
commit d2e891ab2e
3 changed files with 51 additions and 30 deletions

View file

@ -74,12 +74,12 @@ build_theme_path(struct ctx *ctx, char *prefix, const char *path)
}
static char *
find_dir(struct ctx *ctx)
find_dir(struct ctx *ctx, int n)
{
char *debug = getenv("LABWC_DEBUG_DIR_CONFIG_AND_THEME");
for (int i = 0; ctx->dirs[i].path; i++) {
struct dir d = ctx->dirs[i];
struct dir d = ctx->dirs[n != -1 ? n : i];
if (!d.prefix) {
/* handle /etc/xdg... */
ctx->build_path_fn(ctx, NULL, d.path);
@ -109,6 +109,9 @@ find_dir(struct ctx *ctx)
}
g_strfreev(prefixes);
}
if (n != -1) {
break;
}
}
/* no directory was found */
ctx->buf[0] = '\0';
@ -128,7 +131,20 @@ config_dir(void)
.len = sizeof(buf),
.dirs = config_dirs
};
return find_dir(&ctx);
return find_dir(&ctx, -1);
}
char *
config_dir_n(int n)
{
char buf[4096] = { 0 };
struct ctx ctx = {
.build_path_fn = build_config_path,
.buf = buf,
.len = sizeof(buf),
.dirs = config_dirs
};
return find_dir(&ctx, n);
}
char *
@ -142,5 +158,5 @@ theme_dir(const char *theme_name)
.dirs = theme_dirs,
.theme_name = theme_name
};
return find_dir(&ctx);
return find_dir(&ctx, -1);
}