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" \
34 "*fpsSolid: true \n" \
35 "*ignoreRotation: True \n" \
37 # define refresh_slip 0
38 # define slip_handle_event 0
39 # include "xlockmore.h" /* in xscreensaver distribution */
40 #else /* STANDALONE */
41 # include "xlock.h" /* in xlockmore distribution */
42 #endif /* STANDALONE */
46 ENTRYPOINT ModeSpecOpt slip_opts =
47 {0, (XrmOptionDescRec *) NULL, 0, (argtype *) NULL, (OptionStruct *) NULL};
50 ModStruct slip_description =
51 {"slip", "init_slip", "draw_slip", "release_slip",
52 "init_slip", "init_slip", (char *) NULL, &slip_opts,
53 50000, 35, 50, 1, 64, 1.0, "",
54 "Shows slipping blits", 0, NULL};
61 int blit_width, blit_height;
70 static slipstruct *slips = (slipstruct *) NULL;
73 halfrandom(slipstruct *sp, int mv)
82 sp->lasthalf = (short) (r >> 16);
88 erandom(slipstruct *sp, int mv)
96 res = (int) (sp->r & 0xf);
107 image_loaded_cb (Screen *screen, Window w, Drawable d,
108 const char *name, XRectangle *geom,
111 ModeInfo *mi = (ModeInfo *) closure;
112 slipstruct *sp = &slips[MI_SCREEN(mi)];
113 Display *dpy = DisplayOfScreen (screen);
114 XCopyArea (dpy, d, w, mi->gc, 0, 0,
115 sp->width, sp->height, 0, 0);
116 XFreePixmap (dpy, d);
117 sp->image_loading_p = False;
119 #endif /* STANDALONE */
122 prepare_screen(ModeInfo * mi, slipstruct * sp)
125 Display *display = MI_DISPLAY(mi);
127 int i, n, w = sp->width / 20;
128 int not_solid = halfrandom(sp, 10);
130 sp->backwards = (int) (LRAND() & 1); /* jwz: go the other way sometimes */
132 if (sp->first_time || !halfrandom(sp, 10)) {
136 if (halfrandom(sp, 5))
138 if (halfrandom(sp, 5))
144 if (MI_NPIXELS(mi) > 2)
145 XSetForeground(display, gc, MI_PIXEL(mi, halfrandom(sp, MI_NPIXELS(mi))));
146 else if (halfrandom(sp, 2))
147 XSetForeground(display, gc, MI_WHITE_PIXEL(mi));
149 XSetForeground(display, gc, MI_BLACK_PIXEL(mi));
151 for (i = 0; i < n; i++) {
152 int ww = ((w / 2) + halfrandom(sp, MAX(w, 1)));
155 if (MI_NPIXELS(mi) > 2)
156 XSetForeground(display, gc, MI_PIXEL(mi, halfrandom(sp, MI_NPIXELS(mi))));
157 else if (halfrandom(sp, 2))
158 XSetForeground(display, gc, MI_WHITE_PIXEL(mi));
160 XSetForeground(display, gc, MI_BLACK_PIXEL(mi));
162 XFillRectangle(display, MI_WINDOW(mi), gc,
163 halfrandom(sp, MAX(sp->width - ww, 1)),
164 halfrandom(sp, MAX(sp->height - ww, 1)),
170 #ifdef STANDALONE /* jwz -- sometimes hack the desktop image! */
171 if (!sp->image_loading_p &&
172 (1||halfrandom(sp, 2) == 0)) {
173 /* Load it into a pixmap so that the "Loading" message and checkerboard
174 don't show up on the window -- we keep running while the image is
176 Pixmap p = XCreatePixmap (MI_DISPLAY(mi), MI_WINDOW(mi),
177 sp->width, sp->height, mi->xgwa.depth);
178 sp->image_loading_p = True;
179 load_image_async (ScreenOfDisplay (MI_DISPLAY(mi), 0/*####MI_SCREEN(mi)*/),
180 MI_WINDOW(mi), p, image_loaded_cb, mi);
188 int i = (int) floor(d);
191 if ((LRAND() & 0xff) < f * 0xff)
197 reshape_slip (ModeInfo * mi, int w, int h)
199 slipstruct *sp = &slips[MI_SCREEN(mi)];
202 sp->blit_width = sp->width / 25;
203 sp->blit_height = sp->height / 25;
206 sp->nblits_remaining = 0;
210 init_slip (ModeInfo * mi)
215 if ((slips = (slipstruct *) calloc(MI_NUM_SCREENS(mi),
216 sizeof (slipstruct))) == NULL)
219 sp = &slips[MI_SCREEN(mi)];
221 sp->nblits_remaining = 0;
225 /* no "NoExpose" events from XCopyArea wanted */
226 XSetGraphicsExposures(MI_DISPLAY(mi), MI_GC(mi), False);
228 reshape_slip (mi, MI_WIDTH(mi), MI_HEIGHT(mi));
232 draw_slip (ModeInfo * mi)
234 Display *display = MI_DISPLAY(mi);
235 Window window = MI_WINDOW(mi);
242 sp = &slips[MI_SCREEN(mi)];
244 timer = MI_COUNT(mi) * MI_CYCLES(mi);
246 MI_IS_DRAWN(mi) = True;
249 int xi = halfrandom(sp, MAX(sp->width - sp->blit_width, 1));
250 int yi = halfrandom(sp, MAX(sp->height - sp->blit_height, 1));
251 double x, y, dx = 0, dy = 0, t, s1, s2;
253 if (0 == sp->nblits_remaining--) {
254 static const int lut[] = {0, 0, 0, 1, 1, 1, 2};
256 prepare_screen(mi, sp);
257 sp->nblits_remaining = MI_COUNT(mi) *
258 (2000 + halfrandom(sp, 1000) + halfrandom(sp, 1000));
260 sp->mode = halfrandom(sp, 2);
262 sp->mode = lut[halfrandom(sp, 7)];
264 x = (2 * xi + sp->blit_width) / (double) sp->width - 1;
265 y = (2 * yi + sp->blit_height) / (double) sp->height - 1;
267 /* (x,y) is in biunit square */
283 t = dx * dx + dy * dy + 1e-10;
284 s1 = 2 * dx * dx / t - 1;
285 s2 = 2 * dx * dy / t;
289 if (sp->backwards) { /* jwz: go the other way sometimes */
294 case 1: /* shuffle */
298 case 2: /* explode */
304 int qx = xi + quantize(dx), qy = yi + quantize(dy);
307 if (qx < 0 || qy < 0 ||
308 qx >= sp->width - sp->blit_width ||
309 qy >= sp->height - sp->blit_height)
313 Seems to cause problems using Exceed
315 X Error of failed request: BadGC (invalid GC parameter)
317 X Error of failed request: BadDrawable (invalid Pixmap or Window parameter)
318 Major opcode of failed request: 62 (X_CopyArea)
320 XCopyArea(display, window, window, gc, xi, yi,
321 sp->blit_width, sp->blit_height,
326 wrap = sp->width - (2 * sp->blit_width);
328 XCopyArea(display, window, window, gc, qx, qy,
329 sp->blit_width, sp->blit_height,
332 if (qx < 2 * sp->blit_width) {
333 XCopyArea(display, window, window, gc, qx, qy,
334 sp->blit_width, sp->blit_height,
337 wrap = sp->height - (2 * sp->blit_height);
339 XCopyArea(display, window, window, gc, qx, qy,
340 sp->blit_width, sp->blit_height,
343 if (qy < 2 * sp->blit_height) {
344 XCopyArea(display, window, window, gc, qx, qy,
345 sp->blit_width, sp->blit_height,
358 release_slip (ModeInfo * mi)
361 (void) free((void *) slips);
362 slips = (slipstruct *) NULL;
366 XSCREENSAVER_MODULE ("Slip", slip)
368 #endif /* MODE_slip */