2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
6 * These libraries and programs are free software; you can
7 * redistribute them and/or modify them under the terms of the GNU
8 * Lesser General Public License as published by the Free Software
9 * Foundation; either version 2 of the License, or (at your option)
12 * These libraries and programs are distributed in the hope that
13 * they will be useful, but WITHOUT ANY WARRANTY; without even the
14 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU Lesser General Public License for more
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with these librararies and programs; if not, write
20 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21 * Floor, Boston, MA 02110-1301 USA
23 /* $XConsortium: qix.c /main/3 1995/11/02 16:08:11 rswiston $ */
27 * (c) Copyright 1993, 1994 Hewlett-Packard Company *
28 * (c) Copyright 1993, 1994 International Business Machines Corp. *
29 * (c) Copyright 1993, 1994 Sun Microsystems, Inc. *
30 * (c) Copyright 1993, 1994 Novell, Inc. *
33 * qix.c - Vector swirl for dtscreen, the X Window System lockscreen.
35 * Copyright (c) 1991 by Patrick J. Naughton.
37 * See dtscreen.c for copying information.
40 * 29-Jul-90: support for multiple screens.
41 * made check_bounds_?() a macro.
42 * fixed initial parameter setup.
43 * 15-Dec-89: Fix for proper skipping of {White,Black}Pixel() in colors.
44 * 08-Oct-89: Fixed bug in memory allocation in initqix().
45 * Moved seconds() to an extern.
46 * 23-Sep-89: Switch to random() and fixed bug w/ less than 4 lines.
83 XWindowAttributes xgwa;
86 if (pwin->data) free(pwin->data);
87 pwin->data = (void *)malloc(sizeof(qixstruct));
88 memset(pwin->data, '\0', sizeof(qixstruct));
89 qp = (qixstruct *)pwin->data;
90 qp->startTime = seconds();
91 qp->nlines = (batchcount + 1) * 2;
93 qp->lineq = (point *) malloc(qp->nlines * sizeof(point));
94 memset(qp->lineq, '\0', qp->nlines * sizeof(point));
96 XGetWindowAttributes(dsp, pwin->w, &xgwa);
97 qp->width = xgwa.width;
98 qp->height = xgwa.height;
101 if (qp->width < 100) { /* icon window */
105 qp->offset = qp->delta / 3;
108 qp->dx1 = random() % qp->delta + qp->offset;
109 qp->dy1 = random() % qp->delta + qp->offset;
110 qp->dx2 = random() % qp->delta + qp->offset;
111 qp->dy2 = random() % qp->delta + qp->offset;
112 qp->x1 = random() % qp->width;
113 qp->y1 = random() % qp->height;
114 qp->x2 = random() % qp->width;
115 qp->y2 = random() % qp->height;
116 XSetForeground(dsp, pwin->gc, BlackPixelOfScreen(pwin->perscreen->screen));
117 XFillRectangle(dsp, pwin->w, pwin->gc, 0, 0, qp->width, qp->height);
120 #define check_bounds(qp, val, del, max) \
123 *(del) = (random() % (qp)->delta) + (qp)->offset; \
124 } else if ((val) > (max)) { \
125 *(del) = -(random() % (qp)->delta) - (qp)->offset; \
133 qixstruct *qp = (qixstruct *)pwin->data;
135 qp->first = (qp->last + 2) % qp->nlines;
141 check_bounds(qp, qp->x1, &qp->dx1, qp->width);
142 check_bounds(qp, qp->y1, &qp->dy1, qp->height);
143 check_bounds(qp, qp->x2, &qp->dx2, qp->width);
144 check_bounds(qp, qp->y2, &qp->dy2, qp->height);
145 XSetForeground(dsp, pwin->gc, BlackPixelOfScreen(pwin->perscreen->screen));
146 XDrawLine(dsp, pwin->w, pwin->gc,
147 qp->lineq[qp->first].x, qp->lineq[qp->first].y,
148 qp->lineq[qp->first + 1].x, qp->lineq[qp->first + 1].y);
149 if (!mono && pwin->perscreen->npixels > 2) {
150 XSetForeground(dsp, pwin->gc, pwin->perscreen->pixels[qp->pix]);
151 if (++qp->pix >= pwin->perscreen->npixels)
154 XSetForeground(dsp, pwin->gc, WhitePixelOfScreen(pwin->perscreen->screen));
156 XDrawLine(dsp, pwin->w, pwin->gc, qp->x1, qp->y1, qp->x2, qp->y2);
158 qp->lineq[qp->last].x = qp->x1;
159 qp->lineq[qp->last].y = qp->y1;
161 if (qp->last >= qp->nlines)
164 qp->lineq[qp->last].x = qp->x2;
165 qp->lineq[qp->last].y = qp->y2;
167 if (qp->last >= qp->nlines)