- root = secure_getenv("XKB_CONFIG_ROOT");
- if (root != NULL)
- ret |= xkb_context_include_path_append(ctx, root);
- else
- ret |= xkb_context_include_path_append(ctx, DFLT_XKB_CONFIG_ROOT);
-
- home = secure_getenv("HOME");
- if (!home)
- return ret;
- err = asprintf(&user_path, "%s/.xkb", home);
- if (err <= 0)
- return ret;
- ret |= xkb_context_include_path_append(ctx, user_path);
- free(user_path);
+ home = xkb_context_getenv(ctx, "HOME");
+
+ xdg = xkb_context_getenv(ctx, "XDG_CONFIG_HOME");
+ if (xdg != NULL) {
+ user_path = asprintf_safe("%s/xkb", xdg);
+ if (user_path) {
+ ret |= xkb_context_include_path_append(ctx, user_path);
+ free(user_path);
+ }
+ } else if (home != NULL) {
+ /* XDG_CONFIG_HOME fallback is $HOME/.config/ */
+ user_path = asprintf_safe("%s/.config/xkb", home);
+ if (user_path) {
+ ret |= xkb_context_include_path_append(ctx, user_path);
+ free(user_path);
+ }
+ }
+
+ if (home != NULL) {
+ user_path = asprintf_safe("%s/.xkb", home);
+ if (user_path) {
+ ret |= xkb_context_include_path_append(ctx, user_path);
+ free(user_path);
+ }
+ }
+
+ extra = xkb_context_include_path_get_extra_path(ctx);
+ ret |= xkb_context_include_path_append(ctx, extra);
+ root = xkb_context_include_path_get_system_path(ctx);
+ ret |= xkb_context_include_path_append(ctx, root);