small update to man page (backported)
[dmenu.git] / draw.c
diff --git a/draw.c b/draw.c
index ba1fafd..68b8cb7 100644 (file)
--- a/draw.c
+++ b/draw.c
@@ -10,8 +10,7 @@
 /* static */
 
 static unsigned int
-textnw(const char *text, unsigned int len)
-{
+textnw(const char *text, unsigned int len) {
        XRectangle r;
 
        if(dc.font.set) {
@@ -24,36 +23,20 @@ textnw(const char *text, unsigned int len)
 /* extern */
 
 void
-drawtext(const char *text, unsigned int colidx, Bool border)
-{
+drawtext(const char *text, unsigned long col[ColLast]) {
        int x, y, w, h;
        static char buf[256];
        unsigned int len, olen;
-       XPoint points[5];
+       XGCValues gcv;
        XRectangle r = { dc.x, dc.y, dc.w, dc.h };
 
-       XSetForeground(dpy, dc.gc, dc.bg[colidx]);
+       XSetForeground(dpy, dc.gc, col[ColBG]);
        XFillRectangles(dpy, dc.drawable, dc.gc, &r, 1);
 
-       w = 0;
-       XSetForeground(dpy, dc.gc, dc.fg[colidx]);
-       if(border) {
-               points[0].x = dc.x;
-               points[0].y = dc.y;
-               points[1].x = dc.w - 1;
-               points[1].y = 0;
-               points[2].x = 0;
-               points[2].y = dc.h - 1;
-               points[3].x = -(dc.w - 1);
-               points[3].y = 0;
-               points[4].x = 0;
-               points[4].y = -(dc.h - 1);
-               XDrawLines(dpy, dc.drawable, dc.gc, points, 5, CoordModePrevious);
-       }
-
        if(!text)
                return;
 
+       w = 0;
        olen = len = strlen(text);
        if(len >= sizeof(buf))
                len = sizeof(buf) - 1;
@@ -79,27 +62,31 @@ drawtext(const char *text, unsigned int colidx, Bool border)
        if(w > dc.w)
                return; /* too long */
 
-       if(dc.font.set)
-               XmbDrawString(dpy, dc.drawable, dc.font.set, dc.gc, x, y, buf, len);
+       gcv.foreground = col[ColFG];
+       if(dc.font.set) {
+               XChangeGC(dpy, dc.gc, GCForeground, &gcv);
+               XmbDrawString(dpy, dc.drawable, dc.font.set, dc.gc,
+                               x, y, buf, len);
+       }
        else {
-               XSetFont(dpy, dc.gc, dc.font.xfont->fid);
+               gcv.font = dc.font.xfont->fid;
+               XChangeGC(dpy, dc.gc, GCForeground | GCFont, &gcv);
                XDrawString(dpy, dc.drawable, dc.gc, x, y, buf, len);
        }
 }
 
 unsigned long
-getcolor(const char *colstr)
-{
+getcolor(const char *colstr) {
        Colormap cmap = DefaultColormap(dpy, screen);
        XColor color;
 
-       XAllocNamedColor(dpy, cmap, colstr, &color, &color);
+       if(!XAllocNamedColor(dpy, cmap, colstr, &color, &color))
+               eprint("error, cannot allocate color '%s'\n", colstr);
        return color.pixel;
 }
 
 void
-setfont(const char *fontstr)
-{
+setfont(const char *fontstr) {
        char **missing, *def;
        int i, n;
 
@@ -147,7 +134,6 @@ setfont(const char *fontstr)
 }
 
 unsigned int
-textw(const char *text)
-{
+textw(const char *text) {
        return textnw(text, strlen(text)) + dc.font.height;
 }