summaryrefslogtreecommitdiffstats
path: root/tdescreensaver/xsavers/xlock.cpp
blob: 7b8261589fc7b1899539c238b32ef4cb84bdda99 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
//----------------------------------------------------------------------------
// This module contains code to interface original xlock savers to
// kscreensave
//

#include <time.h>
#include <tqapplication.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 = tqt_xdisplay();
	screen = tqt_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");

	TQColor color;

	for ( int i = 0; i < NUMCOLORS; i++ )
	{
		color.setHsv( i * 360 / NUMCOLORS, 255, 255 );
		Scr[0].pixels[i] = color.alloc();
	}
}