Back to index

kdeartwork  4.3.2
xlock.cpp
Go to the documentation of this file.
00001 //----------------------------------------------------------------------------
00002 // This module contains code to interface original xlock savers to
00003 // kscreensaver
00004 //
00005 
00006 #include <time.h>
00007 #include <qapplication.h>
00008 #include <QX11Info>
00009 #include <QColor>
00010 #include <QColormap>
00011 #include "xlock.h"
00012 
00013 
00014 int screen;
00015 Display *dsp;
00016 perscreen Scr[MAXSCREENS];
00017 int batchcount = 100;
00018 int cycles = 100;
00019 Bool mono = 0;
00020 //Bool allowroot = 0;
00021 char *ProgramName;
00022 /*
00023 Dr. Park's algorithm published in the Oct. '88 ACM
00024 "Random Number Generators: Good Ones Are Hard To Find"
00025 His version available at ftp://cs.wm.edu/pub/rngs.tar
00026 Present form by many authors.
00027 */
00028 
00029 static int Seed = 1;       /* This is required to be 32 bits long */
00030 
00031 /*
00032  *      Given an integer, this routine initializes the RNG seed.
00033  */
00034 void SetRNG(long s)
00035 {
00036        Seed = (int) s;
00037 }
00038 
00039 /*
00040  *      Returns an integer between 0 and 2147483647, inclusive.
00041  */
00042 long LongRNG()
00043 {
00044        if ((Seed = Seed % 44488 * 48271 - Seed / 44488 * 3399) < 0)
00045               Seed += 2147483647;
00046        return (long) (Seed - 1);
00047 }
00048 
00049 unsigned long
00050 allocpixel(Colormap cmap, const char *name, const char *def)
00051 {
00052        XColor      col;
00053        XColor      tmp;
00054        XParseColor(dsp, cmap, name, &col);
00055        if (!XAllocColor(dsp, cmap, &col))
00056        {
00057               fprintf(stderr, "could not allocate: %s, using %s instead\n", name, def);
00058               XAllocNamedColor(dsp, cmap, def, &col, &tmp);
00059        }
00060 
00061        return col.pixel;
00062 }
00063 
00064 void initXLock( GC gc )
00065 {
00066        SetRNG( time(NULL) );
00067 
00068        dsp = QX11Info::display();
00069        screen = QX11Info::appScreen();
00070 
00071        Screen *scr = ScreenOfDisplay(dsp, screen);
00072 
00073        Scr[0].gc = gc;
00074        Scr[0].npixels = NUMCOLORS;
00075        Scr[0].cmap = None;
00076 
00077        Colormap    cmap = DefaultColormapOfScreen(scr);
00078        Scr[0].bgcol = allocpixel(cmap, "background", "White");
00079        Scr[0].bgcol = allocpixel(cmap, "foreground", "Black");
00080 
00081        QColor color;
00082        QColormap colormap(QColormap::instance());
00083 
00084        for ( int i = 0; i < NUMCOLORS; i++ )
00085        {
00086               color.setHsv( i * 360 / NUMCOLORS, 255, 255 );
00087               Scr[0].pixels[i] = colormap.pixel(color);
00088        }
00089 }
00090