mirror of
https://github.com/labwc/labwc.git
synced 2026-04-12 08:21:13 -04:00
Load hierarchy of rc.xml files from directories
This commit is contained in:
parent
785a34e8ad
commit
d2e891ab2e
3 changed files with 51 additions and 30 deletions
|
|
@ -3,6 +3,7 @@
|
|||
#define LABWC_DIR_H
|
||||
|
||||
char *config_dir(void);
|
||||
char *config_dir_n(int n);
|
||||
|
||||
/**
|
||||
* theme_dir - find theme directory containing theme @theme_name
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@
|
|||
#include <wlr/util/box.h>
|
||||
#include <wlr/util/log.h>
|
||||
#include "action.h"
|
||||
#include "common/dir.h"
|
||||
#include "common/list.h"
|
||||
#include "common/macros.h"
|
||||
#include "common/mem.h"
|
||||
|
|
@ -1487,20 +1488,22 @@ rcxml_read(const char *filename)
|
|||
* the first time. The specified 'filename' is only respected the first
|
||||
* time.
|
||||
*/
|
||||
if (rcxml[0] == '\0') {
|
||||
find_config_file(rcxml, sizeof(rcxml), filename);
|
||||
for (int i = 3; i >= 0; i--) {
|
||||
line = NULL;
|
||||
len = 0;
|
||||
if (filename) {
|
||||
sprintf(rcxml, "%s", filename);
|
||||
i = 0;
|
||||
} else {
|
||||
sprintf(rcxml, "%s/rc.xml", config_dir_n(i));
|
||||
}
|
||||
if (rcxml[0] == '\0') {
|
||||
wlr_log(WLR_INFO, "cannot find rc.xml config file");
|
||||
goto no_config;
|
||||
}
|
||||
|
||||
/* Reading file into buffer before parsing - better for unit tests */
|
||||
stream = fopen(rcxml, "r");
|
||||
if (!stream) {
|
||||
wlr_log(WLR_ERROR, "cannot read (%s)", rcxml);
|
||||
goto no_config;
|
||||
}
|
||||
else
|
||||
{
|
||||
wlr_log(WLR_INFO, "read config file %s", rcxml);
|
||||
buf_init(&b);
|
||||
while (getline(&line, &len, stream) != -1) {
|
||||
|
|
@ -1514,7 +1517,8 @@ rcxml_read(const char *filename)
|
|||
fclose(stream);
|
||||
rcxml_parse_xml(&b);
|
||||
free(b.buf);
|
||||
no_config:
|
||||
}
|
||||
}
|
||||
post_processing();
|
||||
validate();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue