aboutsummaryrefslogtreecommitdiffstats
path: root/draw.c
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2012-02-21 00:59:16 -0600
committerJesse Luehrs <doy@tozt.net>2012-02-21 01:32:59 -0600
commit8e7f8c02a1c6f1a916376f43cbce1271225c2ec7 (patch)
tree6b86ca3e365991327af78054370976c4903488ba /draw.c
parent2077fd91caaa678de78e7b599def61f89306f2b8 (diff)
downloaddzen-8e7f8c02a1c6f1a916376f43cbce1271225c2ec7.tar.gz
dzen-8e7f8c02a1c6f1a916376f43cbce1271225c2ec7.zip
cache return values of XAllocNamedColor
round trip to the server on every color lookup is pretty bad
Diffstat (limited to 'draw.c')
-rw-r--r--draw.c16
1 files changed, 11 insertions, 5 deletions
diff --git a/draw.c b/draw.c
index 6e99586..f20ff45 100644
--- a/draw.c
+++ b/draw.c
@@ -103,13 +103,19 @@ drawtext(const char *text, int reverse, int line, int align) {
long
getcolor(const char *colstr) {
- Colormap cmap = DefaultColormap(dzen.dpy, dzen.screen);
- XColor color;
+ long color;
+ if ((color = colorcache_get(colstr)) != -1)
+ return color;
+ else {
+ Colormap cmap = DefaultColormap(dzen.dpy, dzen.screen);
+ XColor color;
- if(!XAllocNamedColor(dzen.dpy, cmap, colstr, &color, &color))
- return -1;
+ if(!XAllocNamedColor(dzen.dpy, cmap, colstr, &color, &color))
+ return -1;
- return color.pixel;
+ colorcache_set(colstr, color.pixel);
+ return color.pixel;
+ }
}
void