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,
36 lcdscrub_init (Display *dpy, Window window)
38 struct state *st = (struct state *) calloc (1, sizeof(*st));
42 st->delay = get_integer_resource (st->dpy, "delay", "Integer");
43 st->spread = get_integer_resource (st->dpy, "spread", "Integer");
44 st->cycles = get_integer_resource (st->dpy, "cycles", "Integer");
46 XGetWindowAttributes (st->dpy, st->window, &st->xgwa);
47 gcv.foreground = BlackPixelOfScreen (st->xgwa.screen);
48 gcv.background = WhitePixelOfScreen (st->xgwa.screen);
49 st->bg = XCreateGC (st->dpy, st->window, GCForeground, &gcv);
50 gcv.foreground = WhitePixelOfScreen (st->xgwa.screen);
51 gcv.background = BlackPixelOfScreen (st->xgwa.screen);
52 st->fg = XCreateGC (st->dpy, st->window, GCForeground, &gcv);
55 jwxyz_XSetAntiAliasing (st->dpy, st->fg, False);
56 jwxyz_XSetAntiAliasing (st->dpy, st->bg, False);
63 lcdscrub_draw (Display *dpy, Window window, void *closure)
65 struct state *st = (struct state *) closure;
66 int count = st->count % st->spread;
68 GC fg = (st->mode & 1 ? st->fg : st->bg);
69 GC bg = (st->mode & 1 ? st->bg : st->fg);
74 XFillRectangle (st->dpy, st->window, bg, 0, 0,
75 st->xgwa.width, st->xgwa.height);
76 for (i = count; i < st->xgwa.height; i += st->spread)
77 XDrawLine (st->dpy, st->window, fg, 0, i, st->xgwa.width, i);
81 XFillRectangle (st->dpy, st->window, bg, 0, 0,
82 st->xgwa.width, st->xgwa.height);
83 for (i = count; i < st->xgwa.width; i += st->spread)
84 XDrawLine (st->dpy, st->window, fg, i, 0, i, st->xgwa.height);
88 XFillRectangle (st->dpy, st->window, bg, 0, 0,
89 st->xgwa.width, st->xgwa.height);
90 for (i = count; i < st->xgwa.width; i += st->spread)
91 XDrawLine (st->dpy, st->window, fg, i, 0,
92 i + st->xgwa.width, st->xgwa.width);
93 for (i = -count; i < st->xgwa.height; i += st->spread)
94 XDrawLine (st->dpy, st->window, fg, 0, i,
95 st->xgwa.height, i + st->xgwa.height);
99 XFillRectangle (st->dpy, st->window, fg, 0, 0,
100 st->xgwa.width, st->xgwa.height);
109 if (st->count > st->spread * st->cycles)
112 if (++st->mode == END)
120 lcdscrub_reshape (Display *dpy, Window window, void *closure,
121 unsigned int w, unsigned int h)
126 lcdscrub_event (Display *dpy, Window window, void *closure, XEvent *event)
132 lcdscrub_free (Display *dpy, Window window, void *closure)
134 struct state *st = (struct state *) closure;
135 XFreeGC (dpy, st->fg);
136 XFreeGC (dpy, st->bg);
141 static const char *lcdscrub_defaults [] = {
142 ".background: black",
143 ".foreground: white",
150 static XrmOptionDescRec lcdscrub_options [] = {
151 { "-delay", ".delay", XrmoptionSepArg, 0 },
152 { "-spread", ".spread", XrmoptionSepArg, 0 },
153 { "-cycles", ".cycles", XrmoptionSepArg, 0 },
158 XSCREENSAVER_MODULE ("LCDscrub", lcdscrub)