1 /* xscreensaver, Copyright (c) 2008 Jamie Zawinski <jwz@jwz.org>
3 * Permission to use, copy, modify, distribute, and sell this software and its
4 * documentation for any purpose is hereby granted without fee, provided that
5 * the above copyright notice appear in all copies and that both that
6 * copyright notice and this permission notice appear in supporting
7 * documentation. No representations are made about the suitability of this
8 * software for any purpose. It is provided "as is" without express or
11 * Draws repetitive patterns that should undo burned in LCD screens.
12 * Concept shamelessly cloned from
13 * http://toastycode.com/blog/2008/02/05/lcd-scrub/
16 #include "screenhack.h"
21 XWindowAttributes xgwa;
22 enum { HORIZ_W, HORIZ_B,
27 unsigned int enabled_mask;
37 pick_mode (struct state *st)
42 if (++st->mode == END)
44 if (st->enabled_mask & (1 << st->mode))
50 lcdscrub_init (Display *dpy, Window window)
52 struct state *st = (struct state *) calloc (1, sizeof(*st));
56 st->delay = get_integer_resource (st->dpy, "delay", "Integer");
57 st->spread = get_integer_resource (st->dpy, "spread", "Integer");
58 st->cycles = get_integer_resource (st->dpy, "cycles", "Integer");
60 XGetWindowAttributes (st->dpy, st->window, &st->xgwa);
61 gcv.foreground = BlackPixelOfScreen (st->xgwa.screen);
62 gcv.background = WhitePixelOfScreen (st->xgwa.screen);
63 st->bg = XCreateGC (st->dpy, st->window, GCForeground, &gcv);
64 gcv.foreground = WhitePixelOfScreen (st->xgwa.screen);
65 gcv.background = BlackPixelOfScreen (st->xgwa.screen);
66 st->fg = XCreateGC (st->dpy, st->window, GCForeground, &gcv);
69 jwxyz_XSetAntiAliasing (st->dpy, st->fg, False);
70 jwxyz_XSetAntiAliasing (st->dpy, st->bg, False);
75 if (get_boolean_resource (st->dpy, R, "Mode")) st->enabled_mask |= (1 << F)
76 PREF("modeHW", HORIZ_W);
77 PREF("modeHB", HORIZ_B);
78 PREF("modeVW", VERT_W);
79 PREF("modeVB", VERT_B);
80 PREF("modeDW", DIAG_W);
81 PREF("modeDB", DIAG_B);
85 if (! st->enabled_mask)
87 fprintf (stderr, "%s: no modes enabled\n", progname);
97 lcdscrub_draw (Display *dpy, Window window, void *closure)
99 struct state *st = (struct state *) closure;
100 int count = st->count % st->spread;
102 GC fg = (st->mode & 1 ? st->fg : st->bg);
103 GC bg = (st->mode & 1 ? st->bg : st->fg);
108 XFillRectangle (st->dpy, st->window, bg, 0, 0,
109 st->xgwa.width, st->xgwa.height);
110 for (i = count; i < st->xgwa.height; i += st->spread)
111 XDrawLine (st->dpy, st->window, fg, 0, i, st->xgwa.width, i);
115 XFillRectangle (st->dpy, st->window, bg, 0, 0,
116 st->xgwa.width, st->xgwa.height);
117 for (i = count; i < st->xgwa.width; i += st->spread)
118 XDrawLine (st->dpy, st->window, fg, i, 0, i, st->xgwa.height);
122 XFillRectangle (st->dpy, st->window, bg, 0, 0,
123 st->xgwa.width, st->xgwa.height);
124 for (i = count; i < st->xgwa.width; i += st->spread)
125 XDrawLine (st->dpy, st->window, fg, i, 0,
126 i + st->xgwa.width, st->xgwa.width);
127 for (i = -count; i < st->xgwa.height; i += st->spread)
128 XDrawLine (st->dpy, st->window, fg, 0, i,
129 st->xgwa.height, i + st->xgwa.height);
133 XFillRectangle (st->dpy, st->window, bg, 0, 0,
134 st->xgwa.width, st->xgwa.height);
143 if (st->count > st->spread * st->cycles)
150 lcdscrub_reshape (Display *dpy, Window window, void *closure,
151 unsigned int w, unsigned int h)
156 lcdscrub_event (Display *dpy, Window window, void *closure, XEvent *event)
162 lcdscrub_free (Display *dpy, Window window, void *closure)
164 struct state *st = (struct state *) closure;
165 XFreeGC (dpy, st->fg);
166 XFreeGC (dpy, st->bg);
171 static const char *lcdscrub_defaults [] = {
172 ".background: black",
173 ".foreground: white",
188 static XrmOptionDescRec lcdscrub_options [] = {
189 { "-delay", ".delay", XrmoptionSepArg, 0 },
190 { "-spread", ".spread", XrmoptionSepArg, 0 },
191 { "-cycles", ".cycles", XrmoptionSepArg, 0 },
192 { "-no-hw", ".modeHW", XrmoptionNoArg, "False" },
193 { "-no-hb", ".modeHB", XrmoptionNoArg, "False" },
194 { "-no-vw", ".modeVW", XrmoptionNoArg, "False" },
195 { "-no-vb", ".modeVB", XrmoptionNoArg, "False" },
196 { "-no-dw", ".modeDW", XrmoptionNoArg, "False" },
197 { "-no-db", ".modeDB", XrmoptionNoArg, "False" },
198 { "-no-w", ".modeW", XrmoptionNoArg, "False" },
199 { "-no-b", ".modeB", XrmoptionNoArg, "False" },
204 XSCREENSAVER_MODULE ("LCDscrub", lcdscrub)