static void * lcdscrub_init (Display *dpy, Window window) { struct state *st = (struct state *) calloc (1, sizeof(*st)); XGCValues gcv; st->dpy = dpy; st->window = window; //st->delay = get_integer_resource (st->dpy, "delay", "Integer"); //st->spread = get_integer_resource (st->dpy, "spread", "Integer"); //st->cycles = get_integer_resource (st->dpy, "cycles", "Integer"); st->delay = delay; st->spread = spread; st->cycles = cycles; XGetWindowAttributes (st->dpy, st->window, &st->xgwa); gcv.foreground = BlackPixelOfScreen (st->xgwa.screen); gcv.background = WhitePixelOfScreen (st->xgwa.screen); st->bg = XCreateGC (st->dpy, st->window, GCForeground, &gcv); st->bg2 = XCreateGC (st->dpy, st->window, GCForeground, &gcv); gcv.foreground = WhitePixelOfScreen (st->xgwa.screen); gcv.background = BlackPixelOfScreen (st->xgwa.screen); st->fg = XCreateGC (st->dpy, st->window, GCForeground, &gcv); #ifdef HAVE_COCOA jwxyz_XSetAntiAliasing (st->dpy, st->fg, False); jwxyz_XSetAntiAliasing (st->dpy, st->bg, False); jwxyz_XSetAntiAliasing (st->dpy, st->bg2, False); #endif st->enabled_mask = 0; #if 1 # define PREF(R,F) \ if (R) st->enabled_mask |= (1 << F) #else # define PREF(R,F) \ if (get_boolean_resource (st->dpy, R, "Mode")) st->enabled_mask |= (1 << F) #endif PREF("modeHW", HORIZ_W); PREF("modeHB", HORIZ_B); PREF("modeVW", VERT_W); PREF("modeVB", VERT_B); PREF("modeDW", DIAG_W); PREF("modeDB", DIAG_B); PREF("modeW", WHITE); PREF("modeB", BLACK); PREF("modeRGB", RGB); # undef PREF if (! st->enabled_mask) { fprintf (stderr, "%s: no modes enabled\n", progname); exit (1); } pick_mode (st); return st; }
static unsigned long lcdscrub_draw (Display *dpy, Window window, void *closure) { struct state *st = (struct state *) closure; int count = st->count % st->spread; int i; GC fg = (st->mode & 1 ? st->fg : st->bg); GC bg = (st->mode & 1 ? st->bg : st->fg); switch (st->mode) { case HORIZ_W: case HORIZ_B: XFillRectangle (st->dpy, st->window, bg, 0, 0, st->xgwa.width, st->xgwa.height); for (i = count; i < st->xgwa.height; i += st->spread) XDrawLine (st->dpy, st->window, fg, 0, i, st->xgwa.width, i); break; case VERT_W: case VERT_B: XFillRectangle (st->dpy, st->window, bg, 0, 0, st->xgwa.width, st->xgwa.height); for (i = count; i < st->xgwa.width; i += st->spread) XDrawLine (st->dpy, st->window, fg, i, 0, i, st->xgwa.height); break; case DIAG_W: case DIAG_B: XFillRectangle (st->dpy, st->window, bg, 0, 0, st->xgwa.width, st->xgwa.height); for (i = count; i < st->xgwa.width; i += st->spread) XDrawLine (st->dpy, st->window, fg, i, 0, i + st->xgwa.width, st->xgwa.width); for (i = -count; i < st->xgwa.height; i += st->spread) XDrawLine (st->dpy, st->window, fg, 0, i, st->xgwa.height, i + st->xgwa.height); break; case RGB: { int scale = 10 * 8; /* 8 sec */ static const unsigned short colors[][3] = { { 0xFFFF, 0x0000, 0x0000 }, { 0x0000, 0xFFFF, 0x0000 }, { 0x0000, 0x0000, 0xFFFF }, { 0xFFFF, 0xFFFF, 0x0000 }, { 0xFFFF, 0x0000, 0xFFFF }, { 0x0000, 0xFFFF, 0xFFFF }, { 0xFFFF, 0xFFFF, 0xFFFF }, { 0x0000, 0x0000, 0x0000 }, }; static unsigned long last = 0; XColor xc; bg = st->bg2; xc.red = colors[st->color_tick / scale][0]; xc.green = colors[st->color_tick / scale][1]; xc.blue = colors[st->color_tick / scale][2]; if (last) XFreeColors (st->dpy, st->xgwa.colormap, &last, 1, 0); XAllocColor (st->dpy, st->xgwa.colormap, &xc); last = xc.pixel; XSetForeground (st->dpy, bg, xc.pixel); st->color_tick = (st->color_tick + 1) % (countof(colors) * scale); /* fall through */ } case WHITE: case BLACK: XFillRectangle (st->dpy, st->window, bg, 0, 0, st->xgwa.width, st->xgwa.height); break; default: abort(); break; } st->count++; if (st->count > st->spread * st->cycles) pick_mode (st); return st->delay; }