summaryrefslogtreecommitdiffstats
path: root/kscreensaver/xsavers/xlock.cpp
diff options
context:
space:
mode:
authortoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
committertoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
commit8b2aa1b5301ab60368a03e36df4ff5216726e87d (patch)
tree36163d4ee667c23b5cf232df2f3004cd0a76202a /kscreensaver/xsavers/xlock.cpp
downloadtdeartwork-8b2aa1b5301ab60368a03e36df4ff5216726e87d.tar.gz
tdeartwork-8b2aa1b5301ab60368a03e36df4ff5216726e87d.zip
Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features.
BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdeartwork@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'kscreensaver/xsavers/xlock.cpp')
-rw-r--r--kscreensaver/xsavers/xlock.cpp86
1 files changed, 86 insertions, 0 deletions
diff --git a/kscreensaver/xsavers/xlock.cpp b/kscreensaver/xsavers/xlock.cpp
new file mode 100644
index 00000000..7e7634db
--- /dev/null
+++ b/kscreensaver/xsavers/xlock.cpp
@@ -0,0 +1,86 @@
+//----------------------------------------------------------------------------
+// This module contains code to interface original xlock savers to
+// kscreensave
+//
+
+#include <time.h>
+#include <qapplication.h>
+#include "xlock.h"
+
+
+int screen;
+Display *dsp;
+perscreen Scr[MAXSCREENS];
+int batchcount = 100;
+int cycles = 100;
+Bool mono = 0;
+//Bool allowroot = 0;
+char *ProgramName;
+/*
+Dr. Park's algorithm published in the Oct. '88 ACM
+"Random Number Generators: Good Ones Are Hard To Find"
+His version available at ftp://cs.wm.edu/pub/rngs.tar
+Present form by many authors.
+*/
+
+static int Seed = 1; /* This is required to be 32 bits long */
+
+/*
+ * Given an integer, this routine initializes the RNG seed.
+ */
+void SetRNG(long s)
+{
+ Seed = (int) s;
+}
+
+/*
+ * Returns an integer between 0 and 2147483647, inclusive.
+ */
+long LongRNG()
+{
+ if ((Seed = Seed % 44488 * 48271 - Seed / 44488 * 3399) < 0)
+ Seed += 2147483647;
+ return (long) (Seed - 1);
+}
+
+unsigned long
+allocpixel(Colormap cmap, const char *name, const char *def)
+{
+ XColor col;
+ XColor tmp;
+ XParseColor(dsp, cmap, name, &col);
+ if (!XAllocColor(dsp, cmap, &col))
+ {
+ fprintf(stderr, "couldn't allocate: %s, using %s instead\n", name, def);
+ XAllocNamedColor(dsp, cmap, def, &col, &tmp);
+ }
+
+ return col.pixel;
+}
+
+void initXLock( GC gc )
+{
+ SetRNG( time(NULL) );
+
+ dsp = qt_xdisplay();
+ screen = qt_xscreen();
+
+ Screen *scr = ScreenOfDisplay(dsp, screen);
+
+ Scr[0].gc = gc;
+ Scr[0].npixels = NUMCOLORS;
+ Scr[0].cmap = None;
+
+ Colormap cmap = DefaultColormapOfScreen(scr);
+ Scr[0].bgcol = allocpixel(cmap, "background", "White");
+ Scr[0].bgcol = allocpixel(cmap, "foreground", "Black");
+
+ QColor color;
+
+ for ( int i = 0; i < NUMCOLORS; i++ )
+ {
+ color.setHsv( i * 360 / NUMCOLORS, 255, 255 );
+ Scr[0].pixels[i] = color.alloc();
+ }
+}
+