]> code.delx.au - spectrwm/commitdiff
Unscrew colors on machines that use 16 bit color. I am talking to you
authorMarco Peereboom <marco@conformal.com>
Sun, 18 Jan 2009 23:53:03 +0000 (23:53 +0000)
committerMarco Peereboom <marco@conformal.com>
Sun, 18 Jan 2009 23:53:03 +0000 (23:53 +0000)
zaurus and sparc!

from dwc

scrotwm.c
scrotwm.conf

index 29f4694ccd279cf59fa98d23bd6ce66be453c41a..6ee2f9e0e9c8f09cfcdfd8782db217f59010d90e 100644 (file)
--- a/scrotwm.c
+++ b/scrotwm.c
@@ -210,6 +210,30 @@ union arg {
        char                    **argv;
 };
 
+unsigned long
+name_to_color(char *colorname)
+{
+       Colormap                cmap;
+       Status                  r;
+       XColor                  screen_def, exact_def;
+       unsigned long           result = 0;
+       char                    cname[32] = "#";
+
+       cmap = DefaultColormap(display, screen);
+       r = XAllocNamedColor(display, cmap, colorname, &screen_def, &exact_def);
+       if (!r) {
+               strlcat(cname, colorname + 2, sizeof cname - 1);
+               r = XAllocNamedColor(display, cmap, cname, &screen_def,
+                   &exact_def);
+       }
+       if (r)
+               result = screen_def.pixel;
+       else
+               fprintf(stderr, "color '%s' not found.\n", colorname);
+
+       return (result);
+}
+
 /* conf file stuff */
 #define        SWM_CONF_WS     "\n= \t"
 #define SWM_CONF_FILE  "scrotwm.conf"
@@ -252,13 +276,13 @@ conf_load(char *filename)
                                bar_enabled = atoi(val);
                        else if (!strncmp(var, "bar_border",
                            strlen("bar_border")))
-                               bar_border = strtol(val, NULL, 16);
+                               bar_border = name_to_color(val);
                        else if (!strncmp(var, "bar_color",
                            strlen("bar_color")))
-                               bar_color = strtol(val, NULL, 16);
+                               bar_color = name_to_color(val);
                        else if (!strncmp(var, "bar_font_color",
                            strlen("bar_font_color")))
-                               bar_font_color = strtol(val, NULL, 16);
+                               bar_font_color = name_to_color(val);
                        else if (!strncmp(var, "bar_font", strlen("bar_font")))
                                asprintf(&bar_fonts[0], "%s", val);
                        else
@@ -267,10 +291,10 @@ conf_load(char *filename)
 
                case 'c':
                        if (!strncmp(var, "color_focus", strlen("color_focus")))
-                               color_focus = strtol(val, NULL, 16);
+                               color_focus = name_to_color(val);
                        else if (!strncmp(var, "color_unfocus",
                            strlen("color_unfocus")))
-                               color_unfocus = strtol(val, NULL, 16);
+                               color_unfocus = name_to_color(val);
                        else
                                goto bad;
                        break;
@@ -1458,6 +1482,13 @@ main(int argc, char *argv[])
        root = RootWindow(display, screen);
        astate = XInternAtom(display, "WM_STATE", False);
 
+       /* set default colors */
+       color_focus = name_to_color("red");
+       color_unfocus = name_to_color("rgb:88/88/88");
+       bar_border = name_to_color("rgb:00/80/80");
+       bar_color = name_to_color("black");
+       bar_font_color = name_to_color("rgb:a0/a0/a0");
+
        /* look for local and global conf file */
        pwd = getpwuid(getuid());
        if (pwd == NULL)
index 8b11ae02796812e1c63414e496b1764557004a0f..83f0bd5bbd59323410bbec320ab0616e5b59c129 100644 (file)
@@ -1,12 +1,12 @@
 # colors for focussed and unfocussed window borders
-color_focus    = 0xff0000
-color_unfocus  = 0x888888
+color_focus    = red
+color_unfocus  = rgb:88/88/88
 
 # bar settings
 bar_enabled    = 1
-bar_border     = 0x008080
-bar_color      = 0x000000
-bar_font_color = 0xa0a0a0
+bar_border     = rgb:00/80/80
+bar_color      = black
+bar_font_color = rgb:a0/a0/a0
 bar_font       = -*-terminus-*-*-*-*-*-*-*-*-*-*-*-*
 
 # spawn app