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 # define refresh_slip 0
35 # define slip_handle_event 0
36 # include "xlockmore.h" /* in xscreensaver distribution */
37 #else /* STANDALONE */
38 # include "xlock.h" /* in xlockmore distribution */
39 #endif /* STANDALONE */
43 ENTRYPOINT ModeSpecOpt slip_opts =
44 {0, (XrmOptionDescRec *) NULL, 0, (argtype *) NULL, (OptionStruct *) NULL};
47 ModStruct slip_description =
48 {"slip", "init_slip", "draw_slip", "release_slip",
49 "init_slip", "init_slip", (char *) NULL, &slip_opts,
50 50000, 35, 50, 1, 64, 1.0, "",
51 "Shows slipping blits", 0, NULL};
58 int blit_width, blit_height;
67 static slipstruct *slips = (slipstruct *) NULL;
70 halfrandom(slipstruct *sp, int mv)
79 sp->lasthalf = (short) (r >> 16);
85 erandom(slipstruct *sp, int mv)
93 res = (int) (sp->r & 0xf);
104 image_loaded_cb (Screen *screen, Window w, Drawable d,
105 const char *name, XRectangle *geom,
108 ModeInfo *mi = (ModeInfo *) closure;
109 slipstruct *sp = &slips[MI_SCREEN(mi)];
110 Display *dpy = DisplayOfScreen (screen);
111 XCopyArea (dpy, d, w, mi->gc, 0, 0,
112 sp->width, sp->height, 0, 0);
113 XFreePixmap (dpy, d);
114 sp->image_loading_p = False;
116 #endif /* STANDALONE */
119 prepare_screen(ModeInfo * mi, slipstruct * sp)
122 Display *display = MI_DISPLAY(mi);
124 int i, n, w = sp->width / 20;
125 int not_solid = halfrandom(sp, 10);
127 sp->backwards = (int) (LRAND() & 1); /* jwz: go the other way sometimes */
129 if (sp->first_time || !halfrandom(sp, 10)) {
133 if (halfrandom(sp, 5))
135 if (halfrandom(sp, 5))
141 if (MI_NPIXELS(mi) > 2)
142 XSetForeground(display, gc, MI_PIXEL(mi, halfrandom(sp, MI_NPIXELS(mi))));
143 else if (halfrandom(sp, 2))
144 XSetForeground(display, gc, MI_WHITE_PIXEL(mi));
146 XSetForeground(display, gc, MI_BLACK_PIXEL(mi));
148 for (i = 0; i < n; i++) {
149 int ww = ((w / 2) + halfrandom(sp, MAX(w, 1)));
152 if (MI_NPIXELS(mi) > 2)
153 XSetForeground(display, gc, MI_PIXEL(mi, halfrandom(sp, MI_NPIXELS(mi))));
154 else if (halfrandom(sp, 2))
155 XSetForeground(display, gc, MI_WHITE_PIXEL(mi));
157 XSetForeground(display, gc, MI_BLACK_PIXEL(mi));
159 XFillRectangle(display, MI_WINDOW(mi), gc,
160 halfrandom(sp, MAX(sp->width - ww, 1)),
161 halfrandom(sp, MAX(sp->height - ww, 1)),
167 #ifdef STANDALONE /* jwz -- sometimes hack the desktop image! */
168 if (!sp->image_loading_p &&
169 (1||halfrandom(sp, 2) == 0)) {
170 /* Load it into a pixmap so that the "Loading" message and checkerboard
171 don't show up on the window -- we keep running while the image is
173 Pixmap p = XCreatePixmap (MI_DISPLAY(mi), MI_WINDOW(mi),
174 sp->width, sp->height, mi->xgwa.depth);
175 sp->image_loading_p = True;
176 load_image_async (ScreenOfDisplay (MI_DISPLAY(mi), 0/*####MI_SCREEN(mi)*/),
177 MI_WINDOW(mi), p, image_loaded_cb, mi);
185 int i = (int) floor(d);
188 if ((LRAND() & 0xff) < f * 0xff)
194 reshape_slip (ModeInfo * mi, int w, int h)
196 slipstruct *sp = &slips[MI_SCREEN(mi)];
199 sp->blit_width = sp->width / 25;
200 sp->blit_height = sp->height / 25;
203 sp->nblits_remaining = 0;
207 init_slip (ModeInfo * mi)
212 if ((slips = (slipstruct *) calloc(MI_NUM_SCREENS(mi),
213 sizeof (slipstruct))) == NULL)
216 sp = &slips[MI_SCREEN(mi)];
218 sp->nblits_remaining = 0;
222 /* no "NoExpose" events from XCopyArea wanted */
223 XSetGraphicsExposures(MI_DISPLAY(mi), MI_GC(mi), False);
225 reshape_slip (mi, MI_WIDTH(mi), MI_HEIGHT(mi));
229 draw_slip (ModeInfo * mi)
231 Display *display = MI_DISPLAY(mi);
232 Window window = MI_WINDOW(mi);
239 sp = &slips[MI_SCREEN(mi)];
241 timer = MI_COUNT(mi) * MI_CYCLES(mi);
243 MI_IS_DRAWN(mi) = True;
246 int xi = halfrandom(sp, MAX(sp->width - sp->blit_width, 1));
247 int yi = halfrandom(sp, MAX(sp->height - sp->blit_height, 1));
248 double x, y, dx = 0, dy = 0, t, s1, s2;
250 if (0 == sp->nblits_remaining--) {
251 static const int lut[] = {0, 0, 0, 1, 1, 1, 2};
253 prepare_screen(mi, sp);
254 sp->nblits_remaining = MI_COUNT(mi) *
255 (2000 + halfrandom(sp, 1000) + halfrandom(sp, 1000));
257 sp->mode = halfrandom(sp, 2);
259 sp->mode = lut[halfrandom(sp, 7)];
261 x = (2 * xi + sp->blit_width) / (double) sp->width - 1;
262 y = (2 * yi + sp->blit_height) / (double) sp->height - 1;
264 /* (x,y) is in biunit square */
280 t = dx * dx + dy * dy + 1e-10;
281 s1 = 2 * dx * dx / t - 1;
282 s2 = 2 * dx * dy / t;
286 if (sp->backwards) { /* jwz: go the other way sometimes */
291 case 1: /* shuffle */
295 case 2: /* explode */
301 int qx = xi + quantize(dx), qy = yi + quantize(dy);
304 if (qx < 0 || qy < 0 ||
305 qx >= sp->width - sp->blit_width ||
306 qy >= sp->height - sp->blit_height)
310 Seems to cause problems using Exceed
312 X Error of failed request: BadGC (invalid GC parameter)
314 X Error of failed request: BadDrawable (invalid Pixmap or Window parameter)
315 Major opcode of failed request: 62 (X_CopyArea)
317 XCopyArea(display, window, window, gc, xi, yi,
318 sp->blit_width, sp->blit_height,
323 wrap = sp->width - (2 * sp->blit_width);
325 XCopyArea(display, window, window, gc, qx, qy,
326 sp->blit_width, sp->blit_height,
329 if (qx < 2 * sp->blit_width) {
330 XCopyArea(display, window, window, gc, qx, qy,
331 sp->blit_width, sp->blit_height,
334 wrap = sp->height - (2 * sp->blit_height);
336 XCopyArea(display, window, window, gc, qx, qy,
337 sp->blit_width, sp->blit_height,
340 if (qy < 2 * sp->blit_height) {
341 XCopyArea(display, window, window, gc, qx, qy,
342 sp->blit_width, sp->blit_height,
355 release_slip (ModeInfo * mi)
358 (void) free((void *) slips);
359 slips = (slipstruct *) NULL;
363 XSCREENSAVER_MODULE ("Slip", slip)
365 #endif /* MODE_slip */