summaryrefslogtreecommitdiff
path: root/src/context.c
diff options
context:
space:
mode:
authorPeter Hutterer <peter.hutterer@who-t.net>2019-10-25 14:36:16 +1000
committerRan Benita <ran234@gmail.com>2019-10-31 19:29:30 +0200
commite23f1061b2b9c8d40ba7797a5ffbd6d474d604e0 (patch)
tree07c02243ce45a5f4d0f3a960d40803fa27160707 /src/context.c
parent6d83838cc2e89a61d081e6f7f53aa9bccd0ddb34 (diff)
downloadxorg-lib-libxkbcommon-e23f1061b2b9c8d40ba7797a5ffbd6d474d604e0.tar.gz
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>
Diffstat (limited to 'src/context.c')
-rw-r--r--src/context.c19
1 files changed, 18 insertions, 1 deletions
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) {