]> git.mdlowis.com Git - proto/labwc.git/commitdiff
Load close.xbm based on rc.xml theme name
authorJohan Malm <jgm323@gmail.com>
Thu, 9 Jul 2020 21:41:54 +0000 (22:41 +0100)
committerJohan Malm <jgm323@gmail.com>
Thu, 9 Jul 2020 21:41:54 +0000 (22:41 +0100)
README.md
data/rc.xml
include/rcxml.h
src/config/rcxml.c
src/theme/xbm/xbm.c

index 69aacd15ce00d3d0cd913ed140079d18a829537e..a6dd01148daea17630fd58b093d82fa7e9d17f99 100644 (file)
--- a/README.md
+++ b/README.md
@@ -40,6 +40,8 @@ libxml2, glib-2.0, cairo and pango.
 - [ ] Implement client-menu
 - [ ] Implement root-menu
 
+For further details see [wiki/Roadmap](https://github.com/johanmalm/labwc/wiki/Roadmap).
+
 ## Inspiration
 
 Labwc has been inspired and inflenced by [openbox](https://github.com/danakj/openbox), [sway](https://github.com/swaywm/sway), [cage](https://www.hjdskes.nl/blog/cage-01/), [wio](https://wio-project.org/) and [rootston](https://github.com/swaywm/rootston)
@@ -67,5 +69,5 @@ Suggested apps:
 
 To enable ASAN and UBSAN, run meson with `-Db_sanitize=address,undefined`
 
-For further details see [wiki/Build](https://github.com/labwc/wiki/Build).
+For further details see [wiki/Build](https://github.com/johanmalm/labwc/wiki/Build).
 
index 19798ef943b23f138cd1b8800d59be079822f99b..e097bd6f35b3d79e15094a0ce478c99017370068 100644 (file)
   </keyboard>
 </lab>
 
+<theme>
+  <name>Clearlooks</name>
+  <titleLayout>NLIMC</titleLayout>
+  <font place="ActiveWindow">
+    <name>sans</name>
+    <size>8</size>
+  </font>
+</theme>
+
 <keyboard>
   <keybind key="A-Escape">
     <action name="Exit"/>
index 55f9388453779cb99722c463c1f21c2425be045d..1b0a099c8c623bf40921f856884a02bcfee53ae1 100644 (file)
@@ -30,6 +30,7 @@ struct keybind *keybind_add(const char *keybind);
 
 struct rcxml {
        bool client_side_decorations;
+       char *theme_name;
        struct wl_list keybinds;
 };
 
index 7196daf815dda77174537f405b03a6a5ae0b23f0..460e9a0c556e27d31cbe92c03ee88aec0a2e0ece 100644 (file)
@@ -78,8 +78,10 @@ static void entry(xmlNode *node, char *nodename, char *content)
                fill_keybind(node, nodename, content);
        if (!strcmp(nodename, "csd.lab"))
                rc.client_side_decorations = get_bool(content);
-       if (!strcmp(nodename, "layout.keyboard.lab"))
+       else if (!strcmp(nodename, "layout.keyboard.lab"))
                setenv("XKB_DEFAULT_LAYOUT", content, 1);
+       else if (!strcmp(nodename, "name.theme"))
+               rc.theme_name = strdup(content);
 }
 
 static char *nodename(xmlNode *node, char *buf, int len)
index 3df66047d9e6d286d517226d1a733797f9563090..5b90167ad6b7a784b11c8d0e7bfc352751ad3f4f 100644 (file)
@@ -6,9 +6,27 @@
 
 #include <stdio.h>
 #include <stdlib.h>
+#include <sys/stat.h>
 
 #include "theme/xbm/xbm.h"
 #include "theme/xbm/parse.h"
+#include "rcxml.h"
+
+struct dir {
+       const char *prefix;
+       const char *path;
+};
+
+static struct dir theme_dirs[] = {
+       { "XDG_DATA_HOME", "themes" },
+       { "HOME", ".local/share/themes" },
+       { "HOME", ".themes" },
+       { "XDG_DATA_HOME", "themes" },
+       { NULL, "/usr/share/themes" },
+       { NULL, "/usr/local/share/themes" },
+       { NULL, "opt/share/themes" },
+       { NULL, NULL }
+};
 
 /* built-in 6x6 buttons */
 char close_button_normal[] = { 0x33, 0x3f, 0x1e, 0x1e, 0x3f, 0x33 };
@@ -16,12 +34,6 @@ char iconify_button_normal[] = { 0x00, 0x00, 0x00, 0x00, 0x3f, 0x3f };
 char max_button_normal[] = { 0x3f, 0x3f, 0x21, 0x21, 0x21, 0x3f };
 char max_button_toggled[] = { 0x3e, 0x22, 0x2f, 0x29, 0x39, 0x0f };
 
-/*
- * TODO: parse rc.xml theme name and look for icons properly.
- *       Just using random icon to prove the point.
- */
-static char filename[] = "/usr/share/themes/Bear2/openbox-3/close.xbm";
-
 static struct wlr_texture *texture_from_pixmap(struct wlr_renderer *renderer,
                                               struct pixmap *pixmap)
 {
@@ -42,11 +54,45 @@ static struct wlr_texture *builtin(struct wlr_renderer *renderer,
        return texture;
 }
 
+static char *theme_dir(void)
+{
+       static char buffer[4096] = { 0 };
+       if (buffer[0] != '\0')
+               return buffer;
+
+       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(buffer, sizeof(buffer), "%s/%s/%s/openbox-3",
+                                prefix, d.path, rc.theme_name);
+               } else {
+                       snprintf(buffer, sizeof(buffer), "%s/%s/openbox-3",
+                                d.path, rc.theme_name);
+               }
+               if (!stat(buffer, &st) && S_ISDIR(st.st_mode))
+                       return buffer;
+       }
+       buffer[0] = '\0';
+       return buffer;
+}
+
+static char *xbm_path(const char *button)
+{
+       static char buffer[4096] = { 0 };
+       snprintf(buffer, sizeof(buffer), "%s/%s", theme_dir(), button);
+       return buffer;
+}
+
 void xbm_load(struct wlr_renderer *renderer)
 {
        struct token *tokens;
 
-       char *buffer = xbm_read_file(filename);
+       char *buffer = xbm_read_file(xbm_path("close.xbm"));
        if (!buffer) {
                fprintf(stderr, "no buffer\n");
                goto out;