aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--draw.c14
-rw-r--r--dzen.h4
-rw-r--r--util.c35
3 files changed, 49 insertions, 4 deletions
diff --git a/draw.c b/draw.c
index f20ff45..7af1eb6 100644
--- a/draw.c
+++ b/draw.c
@@ -806,11 +806,17 @@ parse_line(const char *line, int lnr, int align, int reverse, int nodraw) {
XDrawString(dzen.dpy, pm, dzen.tgc, px, py+dzen.font.ascent, lbuf, strlen(lbuf));
#else
if(reverse) {
- XftColorAllocName(dzen.dpy, DefaultVisual(dzen.dpy, dzen.screen),
- DefaultColormap(dzen.dpy, dzen.screen), xftcs_bg, &xftc);
+ if (!xftcolorcache_get(xftcs_bg, &xftc)) {
+ XftColorAllocName(dzen.dpy, DefaultVisual(dzen.dpy, dzen.screen),
+ DefaultColormap(dzen.dpy, dzen.screen), xftcs_bg, &xftc);
+ xftcolorcache_set(xftcs_bg, &xftc);
+ }
} else {
- XftColorAllocName(dzen.dpy, DefaultVisual(dzen.dpy, dzen.screen),
- DefaultColormap(dzen.dpy, dzen.screen), xftcs, &xftc);
+ if (!xftcolorcache_get(xftcs, &xftc)) {
+ XftColorAllocName(dzen.dpy, DefaultVisual(dzen.dpy, dzen.screen),
+ DefaultColormap(dzen.dpy, dzen.screen), xftcs, &xftc);
+ xftcolorcache_set(xftcs, &xftc);
+ }
}
XftDrawStringUtf8(xftd, &xftc,
diff --git a/dzen.h b/dzen.h
index fa764f9..4a4bf52 100644
--- a/dzen.h
+++ b/dzen.h
@@ -181,3 +181,7 @@ extern void spawn(const char *arg); /* execute arg */
extern long colorcache_get(const char *name); /* gets a cached color */
extern void colorcache_set(const char *name, long value); /* sets a cached color */
+#ifdef DZEN_XFT
+extern int xftcolorcache_get(const char *name, XftColor *color); /* gets a cached color */
+extern void xftcolorcache_set(const char *name, XftColor *color); /* sets a cached color */
+#endif
diff --git a/util.c b/util.c
index e276aaf..ef9a954 100644
--- a/util.c
+++ b/util.c
@@ -17,6 +17,10 @@
static char *colorcache_names[COLORCACHE_MAX];
static long colorcache_values[COLORCACHE_MAX];
+#ifdef DZEN_XFT
+static char *xftcolorcache_names[COLORCACHE_MAX];
+static XftColor xftcolorcache_values[COLORCACHE_MAX];
+#endif
#define ONEMASK ((size_t)(-1) / 0xFF)
@@ -95,3 +99,34 @@ void colorcache_set(const char *name, long value) {
colorcache_names[i] = strdup(name);
colorcache_values[i] = value;
}
+
+#ifdef DZEN_XFT
+int xftcolorcache_get(const char *name, XftColor *color) {
+ int i;
+
+ for (i = 0; i < COLORCACHE_MAX; ++i) {
+ if (!xftcolorcache_names[i])
+ break;
+ if (!strcmp(xftcolorcache_names[i], name)) {
+ memcpy(color, &xftcolorcache_values[i], sizeof(XftColor));
+ return 1;
+ }
+ }
+
+ return 0;
+}
+
+void xftcolorcache_set(const char *name, XftColor *color) {
+ int i;
+
+ for (i = 0; i < COLORCACHE_MAX; ++i)
+ if (!xftcolorcache_names[i])
+ break;
+
+ if (i >= COLORCACHE_MAX)
+ return;
+
+ xftcolorcache_names[i] = strdup(name);
+ memcpy(&xftcolorcache_values[i], color, sizeof(XftColor));
+}
+#endif