189
197
return(numpoints);
193
init_pedal (Display *dpy, Window window)
201
pedal_init (Display *dpy, Window window)
203
struct state *st = (struct state *) calloc (1, sizeof(*st));
196
205
XWindowAttributes xgwa;
200
delay = get_integer_resource ("delay", "Integer");
201
if (delay < 0) delay = 0;
203
fadedelay = get_integer_resource ("fadedelay", "Integer");
204
if (fadedelay < 0) fadedelay = 0;
206
maxlines = get_integer_resource ("maxlines", "Integer");
207
if (maxlines < MINLINES) maxlines = MINLINES;
208
else if (maxlines > MAXLINES) maxlines = MAXLINES;
210
points = (XPoint *)malloc(sizeof(XPoint) * maxlines);
212
XGetWindowAttributes (dpy, window, &xgwa);
216
if ((xgwa.visual->class != GrayScale) && (xgwa.visual->class != PseudoColor))
219
cmap = xgwa.colormap;
210
st->delay = get_integer_resource (st->dpy, "delay", "Integer");
211
if (st->delay < 0) st->delay = 0;
213
st->maxlines = get_integer_resource (st->dpy, "maxlines", "Integer");
214
if (st->maxlines < MINLINES) st->maxlines = MINLINES;
215
else if (st->maxlines > MAXLINES) st->maxlines = MAXLINES;
217
st->points = (XPoint *)malloc(sizeof(XPoint) * st->maxlines);
219
XGetWindowAttributes (st->dpy, st->window, &xgwa);
220
st->sizex = xgwa.width;
221
st->sizey = xgwa.height;
223
st->cmap = xgwa.colormap;
221
225
gcv.function = GXcopy;
222
gcv.foreground = get_pixel_resource ("foreground", "Foreground", dpy, cmap);
223
gcv.background = get_pixel_resource ("background", "Background", dpy, cmap);
224
gc = XCreateGC (dpy, window, GCForeground | GCBackground |GCFunction, &gcv);
229
foreground.pixel = gcv.foreground;
230
XQueryColor (dpy, cmap, &foreground);
232
status = XAllocColorCells (
242
XStoreColor ( dpy, cmap, &foreground);
243
XSetForeground (dpy, gc, foreground.pixel);
245
background.pixel = gcv.background;
246
XQueryColor (dpy, cmap, &background);
250
/* If we cant allocate a color cell, then just forget the
251
* whole fade business.
259
fade_foreground (Display *dpy, Colormap cmap,
260
XColor from, XColor to, int steps)
262
* This routine assumes that we have a writeable colormap.
263
* That means that the default colormap is not full, and that
264
* the visual class is PseudoColor or GrayScale.
269
int udelay = fadedelay / (steps + 1);
271
inbetween = foreground;
272
for (i = 0; i <= steps; i++ )
274
inbetween.red = from.red + (to.red - from.red) * i / steps ;
275
inbetween.green = from.green + (to.green - from.green) * i / steps ;
276
inbetween.blue = from.blue + (to.blue - from.blue) * i / steps ;
277
XStoreColor (dpy, cmap, &inbetween);
278
/* If we don't sync, these can bunch up */
280
screenhack_handle_events (dpy);
286
pedal (Display *dpy, Window window)
226
gcv.foreground = get_pixel_resource (st->dpy, st->cmap, "foreground", "Foreground");
227
gcv.background = get_pixel_resource (st->dpy, st->cmap, "background", "Background");
228
st->gc = XCreateGC (st->dpy, st->window, GCForeground | GCBackground |GCFunction, &gcv);
288
234
* Since the XFillPolygon doesn't require that the last
289
235
* point == first point, the number of points is the same
291
237
* the line from the last point to the first point.
297
numpoints = compute_pedal(points, maxlines);
299
/* Fade out, make foreground the same as background */
301
fade_foreground (dpy, cmap, foreground, background, 32);
303
/* Clear the window of previous garbage */
304
XClearWindow (dpy, window);
315
/* Pick a new foreground color (added by jwz) */
319
hsv_to_rgb (random()%360, 1.0, 1.0,
320
&color.red, &color.green, &color.blue);
324
foreground.red = color.red;
325
foreground.green = color.green;
326
foreground.blue = color.blue;
327
/* don't do this here -- let fade_foreground() bring it up! */
328
/* XStoreColor (dpy, cmap, &foreground); */
330
else if (XAllocColor (dpy, cmap, &color))
332
XSetForeground (dpy, gc, color.pixel);
333
XFreeColors (dpy, cmap, &foreground.pixel, 1, 0);
334
foreground.red = color.red;
335
foreground.green = color.green;
336
foreground.blue = color.blue;
337
foreground.pixel = color.pixel;
342
/* Fade in by bringing the foreground back from background */
344
fade_foreground (dpy, cmap, background, foreground, 32);
241
pedal_draw (Display *dpy, Window window, void *closure)
243
struct state *st = (struct state *) closure;
245
int erase_delay = 10000;
246
int long_delay = 1000000 * st->delay;
248
if (st->erase_p || st->eraser) {
249
st->eraser = erase_window (dpy, window, st->eraser);
251
return (st->eraser ? erase_delay : 1000000);
254
numpoints = compute_pedal(st, st->points, st->maxlines);
256
/* Pick a new foreground color (added by jwz) */
260
hsv_to_rgb (random()%360, 1.0, 1.0,
261
&color.red, &color.green, &color.blue);
262
if (XAllocColor (st->dpy, st->cmap, &color))
264
XSetForeground (st->dpy, st->gc, color.pixel);
265
XFreeColors (st->dpy, st->cmap, &st->foreground.pixel, 1, 0);
266
st->foreground.red = color.red;
267
st->foreground.green = color.green;
268
st->foreground.blue = color.blue;
269
st->foreground.pixel = color.pixel;
273
XFillPolygon (st->dpy, st->window, st->gc, st->points, numpoints,
274
Complex, CoordModeOrigin);
281
pedal_reshape (Display *dpy, Window window, void *closure,
282
unsigned int w, unsigned int h)
284
struct state *st = (struct state *) closure;
290
pedal_event (Display *dpy, Window window, void *closure, XEvent *event)
296
pedal_free (Display *dpy, Window window, void *closure)
298
struct state *st = (struct state *) closure;
348
char *progclass = "Pedal";
351
306
* If we are trying to save the screen, the background
352
307
* should be dark.
354
char *defaults [] = {
309
static const char *pedal_defaults [] = {
355
310
".background: black",
356
311
".foreground: white",
358
"*fadedelay: 200000",
359
313
"*maxlines: 1000",
363
XrmOptionDescRec options [] = {
317
static XrmOptionDescRec pedal_options [] = {
364
318
{ "-delay", ".delay", XrmoptionSepArg, 0 },
365
{ "-fadedelay", ".fadedelay", XrmoptionSepArg, 0 },
366
319
{ "-maxlines", ".maxlines", XrmoptionSepArg, 0 },
367
320
{ "-foreground", ".foreground", XrmoptionSepArg, 0 },
368
321
{ "-background", ".background", XrmoptionSepArg, 0 },
373
screenhack (Display *dpy, Window window)
375
init_pedal (dpy, window);
379
screenhack_handle_events (dpy);
380
if (delay) sleep (delay);
325
XSCREENSAVER_MODULE ("Pedal", pedal)