dmenu

my fork of dmenu
Index Commits Files Refs README LICENSE
commit 3b590beda2fb23400f74394badd7a5231d4d7920
parent 5c0d28e4ff9909059ac1247aa71f9b1e906fea3a
Author: arg@mmvi <unknown>
Date:   Tue, 26 Sep 2006 13:37:36 +0200

added fallback to color initialization
Diffstat:
Mdmenu.h | 3++-
Mdraw.c | 5+++--
Mmain.c | 8++++----
3 files changed, 9 insertions(+), 7 deletions(-)
diff --git a/dmenu.h b/dmenu.h
@@ -43,7 +43,8 @@ extern DC dc;			/* global drawing context */
 /* draw.c */
 extern void drawtext(const char *text,
             unsigned long col[ColLast]);    /* draws text with the defined color tuple */
-extern unsigned long getcolor(const char *colstr);    /* returns color of colstr */
+extern unsigned long getcolor(
+    const char *colstr, const char *alternate);    /* returns color of colstr */
 extern void setfont(const char *fontstr);        /* sets global font */
 extern unsigned int textw(const char *text);        /* returns width of text in px */
 
diff --git a/draw.c b/draw.c
@@ -76,11 +76,12 @@ drawtext(const char *text, unsigned long col[ColLast]) {
 }
 
 unsigned long
-getcolor(const char *colstr) {
+getcolor(const char *colstr, const char *alternate) {
     Colormap cmap = DefaultColormap(dpy, screen);
     XColor color;
 
-    XAllocNamedColor(dpy, cmap, colstr, &color, &color);
+    if(XAllocNamedColor(dpy, cmap, colstr, &color, &color) != Success)
+        XAllocNamedColor(dpy, cmap, alternate, &color, &color);
     return color.pixel;
 }
 
diff --git a/main.c b/main.c
@@ -341,10 +341,10 @@ main(int argc, char *argv[]) {
     maxname = readstdin();
 
     /* style */
-    dc.sel[ColBG] = getcolor(selbg);
-    dc.sel[ColFG] = getcolor(selfg);
-    dc.norm[ColBG] = getcolor(normbg);
-    dc.norm[ColFG] = getcolor(normfg);
+    dc.norm[ColBG] = getcolor(normbg, NORMBGCOLOR);
+    dc.norm[ColFG] = getcolor(normfg, NORMFGCOLOR);
+    dc.sel[ColBG] = getcolor(selbg, SELBGCOLOR);
+    dc.sel[ColFG] = getcolor(selfg, SELFGCOLOR);
     setfont(font);
 
     wa.override_redirect = 1;