Use XDG_CONFIG_HOME as first XKB search path Use $XDG_CONFIG_HOME/xkb as the primary lookup path for XKB rules. Same motivation as in 3a91788d9254b, however the XDG directories are more standard and recommended these days than application-specific dotfiles. The XDG spec says to fall back to $HOME/.config where XDG_CONFIG_HOME is not set so we implement that behavior as well. Fixes #112 Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
diff --git a/src/context.c b/src/context.c
index f426751..ff9bcb5 100644
--- a/src/context.c
+++ b/src/context.c
@@ -75,12 +75,29 @@ err:
XKB_EXPORT int
xkb_context_include_path_append_default(struct xkb_context *ctx)
{
- const char *home, *root;
+ const char *home, *xdg, *root;
char *user_path;
int err;
int ret = 0;
home = secure_getenv("HOME");
+
+ xdg = secure_getenv("XDG_CONFIG_HOME");
+ if (xdg != NULL) {
+ err = asprintf(&user_path, "%s/xkb", xdg);
+ if (err >= 0) {
+ ret |= xkb_context_include_path_append(ctx, user_path);
+ free(user_path);
+ }
+ } else if (home != NULL) {
+ /* XDG_CONFIG_HOME fallback is $HOME/.config/ */
+ err = asprintf(&user_path, "%s/.config/xkb", home);
+ if (err >= 0) {
+ ret |= xkb_context_include_path_append(ctx, user_path);
+ free(user_path);
+ }
+ }
+
if (home != NULL) {
err = asprintf(&user_path, "%s/.xkb", home);
if (err >= 0) {