Fix some error
[kdeartwork.git] / kscreensaver / xsavers / xlock.cpp
blob7576dc47ad50ef477c039714e04189aac6a466a6
1 //----------------------------------------------------------------------------
2 // This module contains code to interface original xlock savers to
3 // kscreensave
4 //
6 #include <time.h>
7 #include <qapplication.h>
8 #include <QX11Info>
9 #include "xlock.h"
12 int screen;
13 Display *dsp;
14 perscreen Scr[MAXSCREENS];
15 int batchcount = 100;
16 int cycles = 100;
17 Bool mono = 0;
18 //Bool allowroot = 0;
19 char *ProgramName;
21 Dr. Park's algorithm published in the Oct. '88 ACM
22 "Random Number Generators: Good Ones Are Hard To Find"
23 His version available at ftp://cs.wm.edu/pub/rngs.tar
24 Present form by many authors.
27 static int Seed = 1; /* This is required to be 32 bits long */
30 * Given an integer, this routine initializes the RNG seed.
32 void SetRNG(long s)
34 Seed = (int) s;
38 * Returns an integer between 0 and 2147483647, inclusive.
40 long LongRNG()
42 if ((Seed = Seed % 44488 * 48271 - Seed / 44488 * 3399) < 0)
43 Seed += 2147483647;
44 return (long) (Seed - 1);
47 unsigned long
48 allocpixel(Colormap cmap, const char *name, const char *def)
50 XColor col;
51 XColor tmp;
52 XParseColor(dsp, cmap, name, &col);
53 if (!XAllocColor(dsp, cmap, &col))
55 fprintf(stderr, "couldn't allocate: %s, using %s instead\n", name, def);
56 XAllocNamedColor(dsp, cmap, def, &col, &tmp);
59 return col.pixel;
62 void initXLock( GC gc )
64 SetRNG( time(NULL) );
66 dsp = QX11Info::display();
67 screen = qt_xscreen();
69 Screen *scr = ScreenOfDisplay(dsp, screen);
71 Scr[0].gc = gc;
72 Scr[0].npixels = NUMCOLORS;
73 Scr[0].cmap = None;
75 Colormap cmap = DefaultColormapOfScreen(scr);
76 Scr[0].bgcol = allocpixel(cmap, "background", "White");
77 Scr[0].bgcol = allocpixel(cmap, "foreground", "Black");
79 QColor color;
81 for ( int i = 0; i < NUMCOLORS; i++ )
83 color.setHsv( i * 360 / NUMCOLORS, 255, 255 );
84 Scr[0].pixels[i] = color.alloc();