Use XDG_CONFIG_HOME as first XKB search path
authorPeter Hutterer <peter.hutterer@who-t.net>
Fri, 25 Oct 2019 04:36:16 +0000 (14:36 +1000)
committerRan Benita <ran234@gmail.com>
Thu, 31 Oct 2019 17:29:30 +0000 (19:29 +0200)
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>
src/context.c

index f426751..ff9bcb5 100644 (file)
@@ -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) {