It just so happens that I was trying unicode-screensaver
today and decided that I would much prefer white text on a
black background as opposed to the opposite, though more
from an aesthetic point of view than particularly worrying
about screen burn-in.

I decided to try my hand at hacking up a solution myself.
Please find the attached output of git format-patch, which
can be applied to the current unicode-screensaver trunk via
git am. It changes the default colours to a black background
with a white foreground, but still allows those who prefer
other colorschemes to specify them via the -background and
-foreground options. This is my first time working with xlib
or xscreensaver, so I hope the patch isn't too bad.

One thing I didn't do was hack the xscreensaver config file
that would allow the user to configure the colours via the
xscreensaver-demo gui, but I doubt that doing so would be
too hard.

cheers,
Christine
>From 027be0e24f4b2769e564332e896f775518ebc5ab Mon Sep 17 00:00:00 2001
From: Christine Spang <sp...@mit.edu>
Date: Tue, 15 Dec 2009 19:50:36 -0500
Subject: [PATCH] customisable colorscheme via -background and -foreground

This commit also changes the default colorscheme from black
text on a white background to white text on a black background,
which is more canonical for a screensaver and potentially better
at avoiding screen burn-in.

The old behaviour can be gotten back by changing the screen hack
command to: unicode -root -background white -foreground black
in the xscreensaver or gnome-screensaver configuration.
---
 unicode.1.in |    9 +++++++++
 unicode.c    |   21 +++++++++++++++++++--
 2 files changed, 28 insertions(+), 2 deletions(-)

diff --git a/unicode.1.in b/unicode.1.in
index d72e9cc..860b691 100644
--- a/unicode.1.in
+++ b/unicode.1.in
@@ -8,6 +8,8 @@ unicode - displays unicode characters
 [\-window]
 [\-root]
 [\-fps]
+[\-foreground \fIcolor\fP]
+[\-background \fIcolor\fP]
 .SH DESCRIPTION
 unicode-screensaver is a simple screensaver application that repeatedly
 randomly picks an unicode character and displays it in a very large font
@@ -26,6 +28,13 @@ Draw on the root window.
 .TP 8
 .B \-fps
 Display the current frame rate and CPU load.
+.TP 8
+.B \-background
+Set the background color (e.g. black, white, green, red). The default is
+black.
+.TP 8
+.B \-foreground
+Set the font color (e.g. black, white, green, red). The default is white.
 .SH ENVIRONMENT
 .PP
 .TP 8
diff --git a/unicode.c b/unicode.c
index 2623392..288ea25 100644
--- a/unicode.c
+++ b/unicode.c
@@ -27,6 +27,7 @@ struct unicode_state {
        FcChar32        font_count[NUM_FONTS];
        XftDraw*        draw;
        XftColor        font_color;
+       XColor          bg_color;
 };
 
 static void *
@@ -63,7 +64,22 @@ unicode_init (Display *dpy, Window window)
        }
 
        state->draw = XftDrawCreate(dpy, window, xgwa.visual, cmap); 
-       XftColorAllocName(dpy, xgwa.visual ,cmap,"black",&state->font_color);
+       state->bg_color.pixel = get_pixel_resource(dpy, cmap, "background", 
"Background");
+       XQueryColor(dpy, cmap, &state->bg_color);
+
+       XColor color;
+       color.pixel = get_pixel_resource(dpy, cmap, "foreground", "Foreground");
+       XQueryColor(dpy, cmap, &color);
+
+       XRenderColor font_color;
+       font_color.red = color.red;
+       font_color.green = color.green;
+       font_color.blue = color.blue;
+       font_color.alpha = 0xFFFF;
+
+       XftColorAllocValue(dpy, xgwa.visual, cmap, &font_color, 
&state->font_color);
+       XSetWindowBackground(dpy, window, state->bg_color.pixel);
+       XClearWindow (dpy, window);
 
        return state;
 }
@@ -176,7 +192,8 @@ unicode_free (Display *dpy, Window window, void *state) {
 char *progclass = "Unicode";
 
 static char *unicode_defaults [] = {
-  ".background: white",
+  ".background: black",
+  ".foreground: white",
   "*delay:     7",
   0
 };
-- 
1.6.5.3

Reply via email to