]> git.mdlowis.com Git - proto/labwc.git/commitdiff
src/theme/theme-dir.c: support colon separated XDG_* env vars
authorJohan Malm <jgm323@gmail.com>
Fri, 7 Aug 2020 19:40:46 +0000 (20:40 +0100)
committerJohan Malm <jgm323@gmail.com>
Fri, 7 Aug 2020 19:40:46 +0000 (20:40 +0100)
src/theme/theme-dir.c

index a78c569913061747c82a1c2a87cd3501cdf22dee..ee8b58429cc4a77053d57b93e34aa8cb615b793f 100644 (file)
@@ -7,6 +7,8 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <sys/stat.h>
+#include <stdbool.h>
+#include <glib.h>
 
 struct dir {
        const char *prefix;
@@ -26,29 +28,41 @@ static struct dir theme_dirs[] = {
 };
 /* clang-format on */
 
+static bool isdir(const char *path)
+{
+       struct stat st;
+       return (!stat(path, &st) && S_ISDIR(st.st_mode));
+}
+
 char *theme_dir(const char *theme_name)
 {
        static char buf[4096] = { 0 };
        if (buf[0] != '\0')
                return buf;
 
-       struct stat st;
        for (int i = 0; theme_dirs[i].path; i++) {
-               char *prefix = NULL;
                struct dir d = theme_dirs[i];
-               if (d.prefix) {
-                       prefix = getenv(d.prefix);
-                       if (!prefix)
-                               continue;
-                       snprintf(buf, sizeof(buf), "%s/%s/%s/openbox-3", prefix,
-                                d.path, theme_name);
-               } else {
+               if (!d.prefix) {
                        snprintf(buf, sizeof(buf), "%s/%s/openbox-3", d.path,
                                 theme_name);
+                       if (isdir(buf))
+                               return buf;
+               } else {
+                       char *prefix = getenv(d.prefix);
+                       if (!prefix)
+                               continue;
+                       gchar **prefixes = g_strsplit(prefix, ":", -1);
+                       for (gchar **p = prefixes; *p; p++) {
+                               snprintf(buf, sizeof(buf),
+                                        "%s/%s/%s/openbox-3", *p, d.path,
+                                        theme_name);
+                               if (isdir(buf))
+                                       return buf;
+                       }
                }
-               if (!stat(buf, &st) && S_ISDIR(st.st_mode))
-                       return buf;
        }
-       buf[0] = '\0';
+       /* no config directory was found */
+       buf[0] = '.';
+       buf[1] = '\0';
        return buf;
 }