[PATCH app/setxkbmap 1/2] Add ~/.xkb to search path

Mihail Konev k.mvc at ya.ru
Thu Nov 17 17:42:38 UTC 2016


Also look in $XDG_CONFIG_HOME/xkb, falling back to ~/.config/xkb

Signed-off-by: Mihail Konev <k.mvc at ya.ru>
---
 configure.ac |  3 +++
 setxkbmap.c  | 23 +++++++++++++++++++++++
 2 files changed, 26 insertions(+)

diff --git a/configure.ac b/configure.ac
index 65a4ab6ea9b7..1cbded5e0af7 100644
--- a/configure.ac
+++ b/configure.ac
@@ -33,6 +33,9 @@ AC_CONFIG_HEADERS([config.h])
 # Initialize Automake
 AM_INIT_AUTOMAKE([foreign dist-bzip2])
 
+# Get _GNU_SOURCE and alike
+AC_USE_SYSTEM_EXTENSIONS
+
 # Require X.Org macros 1.8 or later for MAN_SUBSTS set by XORG_MANPAGE_SECTIONS
 m4_ifndef([XORG_MACROS_VERSION],
 	  [m4_fatal([must install xorg-macros 1.8 or later before running autoconf/autogen])])
diff --git a/setxkbmap.c b/setxkbmap.c
index cf0f02d6e704..7cac2ce5207c 100644
--- a/setxkbmap.c
+++ b/setxkbmap.c
@@ -394,6 +394,29 @@ parseArgs(int argc, char **argv)
 
     ok = True;
     addToList(&inclPath, ".");
+    {
+        const char *home = getenv("HOME");
+        const char *xdg = getenv("XDG_CONFIG_HOME");
+        char *home_path, *xdg_path;
+        int rc;
+
+        rc = asprintf(&home_path, "%s/.xkb", home);
+        if (rc >= 0) {
+            addToList(&inclPath, home_path);
+            free(home_path);
+        }
+
+        rc = 0;
+        if (xdg != NULL) {
+            rc = asprintf(&xdg_path, "%s/xkb", xdg);
+        } else {
+            rc = asprintf(&xdg_path, "%s/.config/xkb", home);
+        }
+        if (rc >= 0) {
+            addToList(&inclPath, xdg_path);
+            free(xdg_path);
+        }
+    }
     addToList(&inclPath, DFLT_XKB_CONFIG_ROOT);
     for (i = 1; (i < argc) && ok; i++)
     {
-- 
2.9.2



More information about the xorg-devel mailing list