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.
84 XWindowAttributes xgwa;
87 if (pwin->data) free(pwin->data);
88 pwin->data = (void *)malloc(sizeof(qixstruct));
89 memset(pwin->data, '\0', sizeof(qixstruct));
90 qp = (qixstruct *)pwin->data;
91 qp->startTime = seconds();
92 qp->nlines = (batchcount + 1) * 2;
94 qp->lineq = (point *) malloc(qp->nlines * sizeof(point));
95 memset(qp->lineq, '\0', qp->nlines * sizeof(point));
97 XGetWindowAttributes(dsp, pwin->w, &xgwa);
98 qp->width = xgwa.width;
99 qp->height = xgwa.height;
102 if (qp->width < 100) { /* icon window */
106 qp->offset = qp->delta / 3;
109 qp->dx1 = random() % qp->delta + qp->offset;
110 qp->dy1 = random() % qp->delta + qp->offset;
111 qp->dx2 = random() % qp->delta + qp->offset;
112 qp->dy2 = random() % qp->delta + qp->offset;
113 qp->x1 = random() % qp->width;
114 qp->y1 = random() % qp->height;
115 qp->x2 = random() % qp->width;
116 qp->y2 = random() % qp->height;
117 XSetForeground(dsp, pwin->gc, BlackPixelOfScreen(pwin->perscreen->screen));
118 XFillRectangle(dsp, pwin->w, pwin->gc, 0, 0, qp->width, qp->height);
121 #define check_bounds(qp, val, del, max) \
124 *(del) = (random() % (qp)->delta) + (qp)->offset; \
125 } else if ((val) > (max)) { \
126 *(del) = -(random() % (qp)->delta) - (qp)->offset; \
134 qixstruct *qp = (qixstruct *)pwin->data;
136 qp->first = (qp->last + 2) % qp->nlines;
142 check_bounds(qp, qp->x1, &qp->dx1, qp->width);
143 check_bounds(qp, qp->y1, &qp->dy1, qp->height);
144 check_bounds(qp, qp->x2, &qp->dx2, qp->width);
145 check_bounds(qp, qp->y2, &qp->dy2, qp->height);
146 XSetForeground(dsp, pwin->gc, BlackPixelOfScreen(pwin->perscreen->screen));
147 XDrawLine(dsp, pwin->w, pwin->gc,
148 qp->lineq[qp->first].x, qp->lineq[qp->first].y,
149 qp->lineq[qp->first + 1].x, qp->lineq[qp->first + 1].y);
150 if (!mono && pwin->perscreen->npixels > 2) {
151 XSetForeground(dsp, pwin->gc, pwin->perscreen->pixels[qp->pix]);
152 if (++qp->pix >= pwin->perscreen->npixels)
155 XSetForeground(dsp, pwin->gc, WhitePixelOfScreen(pwin->perscreen->screen));
157 XDrawLine(dsp, pwin->w, pwin->gc, qp->x1, qp->y1, qp->x2, qp->y2);
159 qp->lineq[qp->last].x = qp->x1;
160 qp->lineq[qp->last].y = qp->y1;
162 if (qp->last >= qp->nlines)
165 qp->lineq[qp->last].x = qp->x2;
166 qp->lineq[qp->last].y = qp->y2;
168 if (qp->last >= qp->nlines)