1
/* -*- Mode: C; tab-width: 4 -*-
2
* slip --- lots of blits.
4
#if !defined( lint ) && !defined( SABER )
5
static const char sccsid[] = "@(#)slip.c 4.00 97/01/01 xlockmore";
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";
8
/* Copyright (c) 1992 by Scott Draves (spot@cs.cmu.edu)
9
* Copyright (c) 1992 by Scott Draves <spot@cs.cmu.edu>
10
11
* Permission to use, copy, modify, and distribute this software and its
11
12
* documentation for any purpose and without fee is hereby granted,
19
20
* event will the author be liable for any lost revenue or profits or
20
21
* other special, indirect and consequential damages.
23
* 12-May-97: jwz@jwz.org: turned into a standalone program.
24
* 01-Dec-95: Patched for VMS <joukj@alpha.chem.uva.nl>.
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>
28
# define PROGCLASS "Slip"
29
# define HACK_INIT init_slip
30
# define HACK_DRAW draw_slip
31
# define slip_opts xlockmore_opts
32
# define DEFAULTS "*count: 35 \n" \
36
# include "xlockmore.h" /* from the xscreensaver distribution */
37
#else /* !STANDALONE */
38
# include "xlock.h" /* from the xlockmore distribution */
39
#endif /* !STANDALONE */
41
ModeSpecOpt slip_opts = {
42
0, NULL, 0, NULL, NULL };
30
#define PROGCLASS "Slip"
31
#define HACK_INIT init_slip
32
#define HACK_DRAW draw_slip
33
#define slip_opts xlockmore_opts
34
#define DEFAULTS "*delay: 50000 \n" \
38
#include "xlockmore.h" /* in xscreensaver distribution */
39
#else /* STANDALONE */
40
#include "xlock.h" /* in xlockmore distribution */
41
#endif /* STANDALONE */
45
ModeSpecOpt slip_opts =
46
{0, (XrmOptionDescRec *) NULL, 0, (argtype *) NULL, (OptionStruct *) NULL};
49
ModStruct slip_description =
50
{"slip", "init_slip", "draw_slip", "release_slip",
51
"init_slip", "init_slip", (char *) NULL, &slip_opts,
52
50000, 35, 50, 1, 64, 1.0, "",
53
"Shows slipping blits", 0, NULL};
91
prepare_screen(ModeInfo * mi, slipstruct * s)
104
prepare_screen(ModeInfo * mi, slipstruct * sp)
94
107
Display *display = MI_DISPLAY(mi);
95
108
GC gc = MI_GC(mi);
96
int i, n, w = s->width / 20;
97
int not_solid = halfrandom(10);
109
int i, n, w = sp->width / 20;
110
int not_solid = halfrandom(sp, 10);
99
112
#ifdef STANDALONE /* jwz -- sometimes hack the desktop image! */
100
if (halfrandom(2) == 0)
102
grab_screen_image(DefaultScreenOfDisplay (MI_DISPLAY(mi)),
113
if (halfrandom(sp, 2) == 0) {
114
load_random_image (DefaultScreenOfDisplay(display),
115
MI_WINDOW(mi), MI_WINDOW(mi), NULL, NULL);
108
s->backwards = LRAND() & 1; /* jwz: go the other way sometimes */
119
sp->backwards = (int) (LRAND() & 1); /* jwz: go the other way sometimes */
110
if (s->first_time || (0 == halfrandom(10))) {
111
XClearWindow(display, MI_WINDOW(mi));
121
if (sp->first_time || !halfrandom(sp, 10)) {
125
if (halfrandom(sp, 5))
127
if (halfrandom(sp, 5))
122
133
if (MI_NPIXELS(mi) > 2)
123
XSetForeground(display, gc, MI_PIXEL(mi, halfrandom(MI_NPIXELS(mi))));
124
else if (halfrandom(2))
125
XSetForeground(display, gc, MI_WIN_WHITE_PIXEL(mi));
134
XSetForeground(display, gc, MI_PIXEL(mi, halfrandom(sp, MI_NPIXELS(mi))));
135
else if (halfrandom(sp, 2))
136
XSetForeground(display, gc, MI_WHITE_PIXEL(mi));
127
XSetForeground(display, gc, MI_WIN_BLACK_PIXEL(mi));
138
XSetForeground(display, gc, MI_BLACK_PIXEL(mi));
129
140
for (i = 0; i < n; i++) {
130
int ww = ((w/2) + halfrandom(w));
141
int ww = ((w / 2) + halfrandom(sp, MAX(w, 1)));
132
144
if (MI_NPIXELS(mi) > 2)
133
XSetForeground(display, gc, MI_PIXEL(mi, halfrandom(MI_NPIXELS(mi))));
134
else if (halfrandom(2))
135
XSetForeground(display, gc, MI_WIN_WHITE_PIXEL(mi));
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));
137
XSetForeground(display, gc, MI_WIN_BLACK_PIXEL(mi));
149
XSetForeground(display, gc, MI_BLACK_PIXEL(mi));
139
151
XFillRectangle(display, MI_WINDOW(mi), gc,
140
halfrandom(s->width - ww),
141
halfrandom(s->height - ww),
152
halfrandom(sp, MAX(sp->width - ww, 1)),
153
halfrandom(sp, MAX(sp->height - ww, 1)),
186
198
Display *display = MI_DISPLAY(mi);
187
199
Window window = MI_WINDOW(mi);
188
200
GC gc = MI_GC(mi);
189
slipstruct *s = &slips[MI_SCREEN(mi)];
192
timer = MI_BATCHCOUNT(mi) * MI_CYCLES(mi);
206
sp = &slips[MI_SCREEN(mi)];
208
timer = MI_COUNT(mi) * MI_CYCLES(mi);
210
MI_IS_DRAWN(mi) = True;
194
212
while (timer--) {
195
int xi = halfrandom(s->width - s->blit_width);
196
int yi = halfrandom(s->height - s->blit_height);
213
int xi = halfrandom(sp, MAX(sp->width - sp->blit_width, 1));
214
int yi = halfrandom(sp, MAX(sp->height - sp->blit_height, 1));
197
215
double x, y, dx = 0, dy = 0, t, s1, s2;
199
if (0 == s->nblits_remaining--) {
217
if (0 == sp->nblits_remaining--) {
201
219
{0, 0, 0, 1, 1, 1, 2};
203
prepare_screen(mi, s);
204
s->nblits_remaining = MI_BATCHCOUNT(mi) *
205
(2000 + halfrandom(1000) + halfrandom(1000));
207
s->mode = halfrandom(2);
221
prepare_screen(mi, sp);
222
sp->nblits_remaining = MI_COUNT(mi) *
223
(2000 + halfrandom(sp, 1000) + halfrandom(sp, 1000));
225
sp->mode = halfrandom(sp, 2);
209
s->mode = lut[halfrandom(7)];
227
sp->mode = lut[halfrandom(sp, 7)];
211
x = (2 * xi + s->blit_width) / (double) s->width - 1;
212
y = (2 * yi + s->blit_height) / (double) s->height - 1;
229
x = (2 * xi + sp->blit_width) / (double) sp->width - 1;
230
y = (2 * yi + sp->blit_height) / (double) sp->height - 1;
214
232
/* (x,y) is in biunit square */
253
272
if (qx < 0 || qy < 0 ||
254
qx >= s->width - s->blit_width ||
255
qy >= s->height - s->blit_height)
273
qx >= sp->width - sp->blit_width ||
274
qy >= sp->height - sp->blit_height)
278
Seems to cause problems using Exceed
280
X Error of failed request: BadGC (invalid GC parameter)
282
X Error of failed request: BadDrawable (invalid Pixmap or Window parameter)
283
Major opcode of failed request: 62 (X_CopyArea)
258
285
XCopyArea(display, window, window, gc, xi, yi,
259
s->blit_width, s->blit_height,
286
sp->blit_width, sp->blit_height,
265
wrap = s->width - (2 * s->blit_width);
291
wrap = sp->width - (2 * sp->blit_width);
267
293
XCopyArea(display, window, window, gc, qx, qy,
268
s->blit_width, s->blit_height,
294
sp->blit_width, sp->blit_height,
271
if (qx < 2 * s->blit_width)
297
if (qx < 2 * sp->blit_width) {
272
298
XCopyArea(display, window, window, gc, qx, qy,
273
s->blit_width, s->blit_height,
299
sp->blit_width, sp->blit_height,
276
wrap = s->height - (2 * s->blit_height);
302
wrap = sp->height - (2 * sp->blit_height);
278
304
XCopyArea(display, window, window, gc, qx, qy,
279
s->blit_width, s->blit_height,
305
sp->blit_width, sp->blit_height,
282
if (qy < 2 * s->blit_height)
308
if (qy < 2 * sp->blit_height) {
283
309
XCopyArea(display, window, window, gc, qx, qy,
284
s->blit_width, s->blit_height,
310
sp->blit_width, sp->blit_height,