X-Git-Url: http://git.hungrycats.org/cgi-bin/gitweb.cgi?p=xscreensaver;a=blobdiff_plain;f=utils%2Fresources.c;h=fc5cea13e7f7e9d25681e0c48452acbf240b2e02;hp=e0925d0fc783792eb1403a835c916d218030ed2d;hb=8eb2873d7054e705c4e83f22d18c40946a9e2529;hpb=a1d41b2aa6e18bf9a49b914a99dda8232c5d7762 diff --git a/utils/resources.c b/utils/resources.c index e0925d0f..fc5cea13 100644 --- a/utils/resources.c +++ b/utils/resources.c @@ -1,4 +1,4 @@ -/* xscreensaver, Copyright (c) 1992, 1997, 1998 +/* xscreensaver, Copyright (c) 1992, 1997, 1998, 2001 * Jamie Zawinski * * Permission to use, copy, modify, distribute, and sell this software and its @@ -137,6 +137,7 @@ get_pixel_resource (char *res_name, char *res_class, XColor color; char *s = get_string_resource (res_name, res_class); char *s2; + Bool ok = True; if (!s) goto DEFAULT; for (s2 = s + strlen(s) - 1; s2 > s; s2--) @@ -147,22 +148,42 @@ get_pixel_resource (char *res_name, char *res_class, if (! XParseColor (dpy, cmap, s, &color)) { - fprintf (stderr, "%s: can't parse color %s\n", progname, s); + fprintf (stderr, "%s: can't parse color %s", progname, s); + ok = False; goto DEFAULT; } if (! XAllocColor (dpy, cmap, &color)) { - fprintf (stderr, "%s: couldn't allocate color %s\n", progname, s); + fprintf (stderr, "%s: couldn't allocate color %s", progname, s); + ok = False; goto DEFAULT; } free (s); return color.pixel; DEFAULT: if (s) free (s); - return ((strlen(res_class) >= 10 && - !strcmp ("Background", res_class + strlen(res_class) - 10)) - ? BlackPixel (dpy, DefaultScreen (dpy)) - : WhitePixel (dpy, DefaultScreen (dpy))); + + { + Bool black_p = (strlen(res_class) >= 10 && + !strcasecmp ("Background", + res_class + strlen(res_class) - 10)); + if (!ok) + fprintf (stderr, ": using %s.\n", (black_p ? "black" : "white")); + color.flags = DoRed|DoGreen|DoBlue; + color.red = color.green = color.blue = (black_p ? 0 : 0xFFFF); + if (XAllocColor (dpy, cmap, &color)) + return color.pixel; + else + { + fprintf (stderr, "%s: couldn't allocate %s either!\n", progname, + (black_p ? "black" : "white")); + /* We can't use BlackPixel/WhitePixel here, because we don't know + what screen we're allocating on (only an issue when running inside + the xscreensaver daemon: for hacks, DefaultScreen is fine.) + */ + return 0; + } + } }