1 /* -*- Mode: C; tab-width: 4 -*- */
2 /* slip --- lots of slipping blits */
5 static const char sccsid[] = "@(#)slip.c 5.00 2000/11/01 xlockmore";
9 * Copyright (c) 1992 by Scott Draves <spot@cs.cmu.edu>
11 * Permission to use, copy, modify, and distribute this software and its
12 * documentation for any purpose and without fee is hereby granted,
13 * provided that the above copyright notice appear in all copies and that
14 * both that copyright notice and this permission notice appear in
15 * supporting documentation.
17 * This file is provided AS IS with no warranties of any kind. The author
18 * shall have no liability with respect to the infringement of copyrights,
19 * trade secrets or any patents by this file or any part thereof. In no
20 * event will the author be liable for any lost revenue or profits or
21 * other special, indirect and consequential damages.
23 * 01-Nov-2000: Allocation checks
24 * 10-May-1997: Jamie Zawinski <jwz@jwz.org> compatible with xscreensaver
25 * 01-Dec-1995: Patched for VMS <joukj@hrem.stm.tudelft.nl>
30 # define DEFAULTS "*delay: 50000 \n" \
35 # define refresh_slip 0
36 # define slip_handle_event 0
37 # include "xlockmore.h" /* in xscreensaver distribution */
38 #else /* STANDALONE */
39 # include "xlock.h" /* in xlockmore distribution */
40 #endif /* STANDALONE */
44 ENTRYPOINT ModeSpecOpt slip_opts =
45 {0, (XrmOptionDescRec *) NULL, 0, (argtype *) NULL, (OptionStruct *) NULL};
48 ModStruct slip_description =
49 {"slip", "init_slip", "draw_slip", "release_slip",
50 "init_slip", "init_slip", (char *) NULL, &slip_opts,
51 50000, 35, 50, 1, 64, 1.0, "",
52 "Shows slipping blits", 0, NULL};
59 int blit_width, blit_height;
68 static slipstruct *slips = (slipstruct *) NULL;
71 halfrandom(slipstruct *sp, int mv)
80 sp->lasthalf = (short) (r >> 16);
86 erandom(slipstruct *sp, int mv)
94 res = (int) (sp->r & 0xf);
105 image_loaded_cb (Screen *screen, Window w, Drawable d,
106 const char *name, XRectangle *geom,
109 ModeInfo *mi = (ModeInfo *) closure;
110 slipstruct *sp = &slips[MI_SCREEN(mi)];
111 Display *dpy = DisplayOfScreen (screen);
112 XCopyArea (dpy, d, w, mi->gc, 0, 0,
113 sp->width, sp->height, 0, 0);
114 XFreePixmap (dpy, d);
115 sp->image_loading_p = False;
117 #endif /* STANDALONE */
120 prepare_screen(ModeInfo * mi, slipstruct * sp)
123 Display *display = MI_DISPLAY(mi);
125 int i, n, w = sp->width / 20;
126 int not_solid = halfrandom(sp, 10);
128 sp->backwards = (int) (LRAND() & 1); /* jwz: go the other way sometimes */
130 if (sp->first_time || !halfrandom(sp, 10)) {
134 if (halfrandom(sp, 5))
136 if (halfrandom(sp, 5))
142 if (MI_NPIXELS(mi) > 2)
143 XSetForeground(display, gc, MI_PIXEL(mi, halfrandom(sp, MI_NPIXELS(mi))));
144 else if (halfrandom(sp, 2))
145 XSetForeground(display, gc, MI_WHITE_PIXEL(mi));
147 XSetForeground(display, gc, MI_BLACK_PIXEL(mi));
149 for (i = 0; i < n; i++) {
150 int ww = ((w / 2) + halfrandom(sp, MAX(w, 1)));
153 if (MI_NPIXELS(mi) > 2)
154 XSetForeground(display, gc, MI_PIXEL(mi, halfrandom(sp, MI_NPIXELS(mi))));
155 else if (halfrandom(sp, 2))
156 XSetForeground(display, gc, MI_WHITE_PIXEL(mi));
158 XSetForeground(display, gc, MI_BLACK_PIXEL(mi));
160 XFillRectangle(display, MI_WINDOW(mi), gc,
161 halfrandom(sp, MAX(sp->width - ww, 1)),
162 halfrandom(sp, MAX(sp->height - ww, 1)),
168 #ifdef STANDALONE /* jwz -- sometimes hack the desktop image! */
169 if (!sp->image_loading_p &&
170 (1||halfrandom(sp, 2) == 0)) {
171 /* Load it into a pixmap so that the "Loading" message and checkerboard
172 don't show up on the window -- we keep running while the image is
174 Pixmap p = XCreatePixmap (MI_DISPLAY(mi), MI_WINDOW(mi),
175 sp->width, sp->height, mi->xgwa.depth);
176 sp->image_loading_p = True;
177 load_image_async (ScreenOfDisplay (MI_DISPLAY(mi), 0/*####MI_SCREEN(mi)*/),
178 MI_WINDOW(mi), p, image_loaded_cb, mi);
186 int i = (int) floor(d);
189 if ((LRAND() & 0xff) < f * 0xff)
195 reshape_slip (ModeInfo * mi, int w, int h)
197 slipstruct *sp = &slips[MI_SCREEN(mi)];
200 sp->blit_width = sp->width / 25;
201 sp->blit_height = sp->height / 25;
204 sp->nblits_remaining = 0;
208 init_slip (ModeInfo * mi)
213 if ((slips = (slipstruct *) calloc(MI_NUM_SCREENS(mi),
214 sizeof (slipstruct))) == NULL)
217 sp = &slips[MI_SCREEN(mi)];
219 sp->nblits_remaining = 0;
223 /* no "NoExpose" events from XCopyArea wanted */
224 XSetGraphicsExposures(MI_DISPLAY(mi), MI_GC(mi), False);
226 reshape_slip (mi, MI_WIDTH(mi), MI_HEIGHT(mi));
230 draw_slip (ModeInfo * mi)
232 Display *display = MI_DISPLAY(mi);
233 Window window = MI_WINDOW(mi);
240 sp = &slips[MI_SCREEN(mi)];
242 timer = MI_COUNT(mi) * MI_CYCLES(mi);
244 MI_IS_DRAWN(mi) = True;
247 int xi = halfrandom(sp, MAX(sp->width - sp->blit_width, 1));
248 int yi = halfrandom(sp, MAX(sp->height - sp->blit_height, 1));
249 double x, y, dx = 0, dy = 0, t, s1, s2;
251 if (0 == sp->nblits_remaining--) {
252 static const int lut[] = {0, 0, 0, 1, 1, 1, 2};
254 prepare_screen(mi, sp);
255 sp->nblits_remaining = MI_COUNT(mi) *
256 (2000 + halfrandom(sp, 1000) + halfrandom(sp, 1000));
258 sp->mode = halfrandom(sp, 2);
260 sp->mode = lut[halfrandom(sp, 7)];
262 x = (2 * xi + sp->blit_width) / (double) sp->width - 1;
263 y = (2 * yi + sp->blit_height) / (double) sp->height - 1;
265 /* (x,y) is in biunit square */
281 t = dx * dx + dy * dy + 1e-10;
282 s1 = 2 * dx * dx / t - 1;
283 s2 = 2 * dx * dy / t;
287 if (sp->backwards) { /* jwz: go the other way sometimes */
292 case 1: /* shuffle */
296 case 2: /* explode */
302 int qx = xi + quantize(dx), qy = yi + quantize(dy);
305 if (qx < 0 || qy < 0 ||
306 qx >= sp->width - sp->blit_width ||
307 qy >= sp->height - sp->blit_height)
311 Seems to cause problems using Exceed
313 X Error of failed request: BadGC (invalid GC parameter)
315 X Error of failed request: BadDrawable (invalid Pixmap or Window parameter)
316 Major opcode of failed request: 62 (X_CopyArea)
318 XCopyArea(display, window, window, gc, xi, yi,
319 sp->blit_width, sp->blit_height,
324 wrap = sp->width - (2 * sp->blit_width);
326 XCopyArea(display, window, window, gc, qx, qy,
327 sp->blit_width, sp->blit_height,
330 if (qx < 2 * sp->blit_width) {
331 XCopyArea(display, window, window, gc, qx, qy,
332 sp->blit_width, sp->blit_height,
335 wrap = sp->height - (2 * sp->blit_height);
337 XCopyArea(display, window, window, gc, qx, qy,
338 sp->blit_width, sp->blit_height,
341 if (qy < 2 * sp->blit_height) {
342 XCopyArea(display, window, window, gc, qx, qy,
343 sp->blit_width, sp->blit_height,
356 release_slip (ModeInfo * mi)
359 (void) free((void *) slips);
360 slips = (slipstruct *) NULL;
364 XSCREENSAVER_MODULE ("Slip", slip)
366 #endif /* MODE_slip */