diff options
-rw-r--r-- | draw.c | 14 | ||||
-rw-r--r-- | dzen.h | 4 | ||||
-rw-r--r-- | util.c | 35 |
3 files changed, 49 insertions, 4 deletions
@@ -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, @@ -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 @@ -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 |