[hackers] [wmii] Fix some repetative code in wmii9menu.

From: Kris Maglione <jg_AT_suckless.org>
Date: Fri Apr 06 07:48:51 2007

changeset: 2059:98e795bf82f1
tag: tip
user: Kris Maglione <jg_AT_suckless.org>
date: Fri Apr 06 01:44:50 2007 -0400
summary: Fix some repetative code in wmii9menu.

diff -r 88218dc22b4f -r 98e795bf82f1 cmd/wmii9menu.c
--- a/cmd/wmii9menu.c Fri Apr 06 01:36:17 2007 -0400
+++ b/cmd/wmii9menu.c Fri Apr 06 01:44:50 2007 -0400
@@ -148,6 +148,16 @@ args(int argc, char **argv)
                         break;
         }
         return i;
+}
+
+unsigned long
+getcolor(char *name, unsigned long def) {
+ if ((name != nil)
+ && (XParseColor(dpy, defcmap, name, &color) != 0)
+ && (XAllocColor(dpy, defcmap, &color) != 0))
+ return color.pixel;
+ else
+ return def;
 }
 
 /* main --- crack arguments, set up X stuff, run the main menu loop */
@@ -286,40 +296,12 @@ main(int argc, char **argv)
          * white = WhitePixel(dpy, screen);
          */
         defcmap = DefaultColormap(dpy, screen);
- if (sbgname == nil
- || XParseColor(dpy, defcmap, sbgname, &color) == 0
- || XAllocColor(dpy, defcmap, &color) == 0)
- selbg = BlackPixel(dpy, screen);
- else
- selbg = color.pixel;
-
- if (sfgname == nil
- || XParseColor(dpy, defcmap, sfgname, &color) == 0
- || XAllocColor(dpy, defcmap, &color) == 0)
- selfg = WhitePixel(dpy, screen);
- else
- selfg = color.pixel;
-
- if (nbgname == nil
- || XParseColor(dpy, defcmap, nbgname, &color) == 0
- || XAllocColor(dpy, defcmap, &color) == 0)
- normbg = selfg;
- else
- normbg = color.pixel;
-
- if (nfgname == nil
- || XParseColor(dpy, defcmap, nfgname, &color) == 0
- || XAllocColor(dpy, defcmap, &color) == 0)
- normfg = selbg;
- else
- normfg = color.pixel;
-
- if (brcname == nil
- || XParseColor(dpy, defcmap, brcname, &color) == 0
- || XAllocColor(dpy, defcmap, &color) == 0)
- border = selbg;
- else
- border = color.pixel;
+
+ selbg = getcolor(sbgname, BlackPixel(dpy, screen));
+ selfg = getcolor(sfgname, WhitePixel(dpy, screen));
+ normbg = getcolor(nbgname, selfg);
+ normfg = getcolor(nfgname, selbg);
+ border = getcolor(brcname, selbg);
 
         /* try user's font first */
         if (fontname != nil) {
Received on Fri Apr 06 2007 - 07:48:51 UTC

This archive was generated by hypermail 2.2.0 : Sun Jul 13 2008 - 15:56:33 UTC