diff options
Diffstat (limited to 'uisimulator')
30 files changed, 3167 insertions, 0 deletions
diff --git a/uisimulator/.depends b/uisimulator/.depends new file mode 100644 index 0000000000..412d5508d2 --- /dev/null +++ b/uisimulator/.depends | |||
@@ -0,0 +1,11 @@ | |||
1 | alpha.o: alpha.c utils.h alpha.h visual.h hsv.h yarandom.h resources.h | ||
2 | hsv.o: hsv.c utils.h hsv.h | ||
3 | screenhack.o: screenhack.c xmu.h screenhack.h config.h yarandom.h \ | ||
4 | usleep.h resources.h hsv.h colors.h grabscreen.h visual.h version.h \ | ||
5 | vroot.h | ||
6 | yarandom.o: yarandom.c yarandom.h | ||
7 | uibasic.o: uibasic.c screenhack.h config.h yarandom.h usleep.h \ | ||
8 | resources.h hsv.h colors.h grabscreen.h visual.h alpha.h version.h | ||
9 | resources.o: resources.c utils.h resources.h | ||
10 | visual.o: visual.c utils.h resources.h visual.h | ||
11 | usleep.o: usleep.c | ||
diff --git a/uisimulator/FILES b/uisimulator/FILES new file mode 100644 index 0000000000..6baec58f84 --- /dev/null +++ b/uisimulator/FILES | |||
@@ -0,0 +1,8 @@ | |||
1 | *.c | ||
2 | *.cpp | ||
3 | *.h | ||
4 | Makefile | ||
5 | README | ||
6 | FILES | ||
7 | maketgz | ||
8 | CHANGES | ||
diff --git a/uisimulator/Makefile b/uisimulator/Makefile new file mode 100644 index 0000000000..eb478a6d6b --- /dev/null +++ b/uisimulator/Makefile | |||
@@ -0,0 +1,40 @@ | |||
1 | ############################################################################## | ||
2 | # Rockbox UI simulator | ||
3 | ############################################################################# | ||
4 | |||
5 | TARGET = rockboxui | ||
6 | |||
7 | CC = gcc | ||
8 | RM = rm | ||
9 | |||
10 | CFLAGS = -g -O2 | ||
11 | CPPFLAGS = -DHAVE_CONFIG_H -DGETTIMEOFDAY_TWO_ARGS | ||
12 | LDFLAGS = -lX11 -lm -lXt -lXmu -lsocket -lnsl | ||
13 | |||
14 | DEPEND = .depends | ||
15 | |||
16 | OBJS= alpha.o hsv.o screenhack.o yarandom.o uibasic.o resources.o visual.o\ | ||
17 | usleep.o | ||
18 | |||
19 | SRCS = $(OBJS:%.o=%.c) | ||
20 | HDRS = $(OBJS:%.o=%.h) | ||
21 | |||
22 | all: $(DEPEND) $(TARGET) | ||
23 | |||
24 | clean: | ||
25 | $(RM) -f $(OBJS) *~ core $(TARGET) $(CLIENTS) $(DEPEND) | ||
26 | |||
27 | distclean: clean | ||
28 | $(RM) config.cache | ||
29 | |||
30 | .c.o: | ||
31 | $(CC) $(CPPFLAGS) $(CCFLAGS) -c $< | ||
32 | |||
33 | $(DEPEND): | ||
34 | $(CC) -MM $(CFLAGS) $(SRCS) > $(DEPEND) | ||
35 | |||
36 | $(TARGET): $(OBJS) | ||
37 | $(CC) -o $(TARGET) $(LDFLAGS) $(OBJS) | ||
38 | |||
39 | # Dependencies | ||
40 | include $(DEPEND) | ||
diff --git a/uisimulator/alpha.c b/uisimulator/alpha.c new file mode 100644 index 0000000000..22504fcd93 --- /dev/null +++ b/uisimulator/alpha.c | |||
@@ -0,0 +1,215 @@ | |||
1 | /* xscreensaver, Copyright (c) 1992, 1995, 1996, 1997 | ||
2 | * Jamie Zawinski <jwz@jwz.org> | ||
3 | * | ||
4 | * Permission to use, copy, modify, distribute, and sell this software and its | ||
5 | * documentation for any purpose is hereby granted without fee, provided that | ||
6 | * the above copyright notice appear in all copies and that both that | ||
7 | * copyright notice and this permission notice appear in supporting | ||
8 | * documentation. No representations are made about the suitability of this | ||
9 | * software for any purpose. It is provided "as is" without express or | ||
10 | * implied warranty. | ||
11 | */ | ||
12 | |||
13 | /* Beauty is only skin deep, unless you've got an alpha channel. */ | ||
14 | |||
15 | |||
16 | #include "utils.h" | ||
17 | #include "alpha.h" | ||
18 | #include "visual.h" | ||
19 | #include "hsv.h" | ||
20 | #include "yarandom.h" | ||
21 | #include "resources.h" | ||
22 | |||
23 | #include <X11/Xutil.h> | ||
24 | |||
25 | #ifndef countof | ||
26 | # define countof(x) (sizeof(*(x))/sizeof((x))) | ||
27 | #endif | ||
28 | |||
29 | |||
30 | /* I don't believe this fucking language doesn't have builtin exponentiation. | ||
31 | I further can't believe that the fucking ^ character means fucking XOR!! */ | ||
32 | static int | ||
33 | i_exp (int i, int j) | ||
34 | { | ||
35 | int k = 1; | ||
36 | while (j--) k *= i; | ||
37 | return k; | ||
38 | } | ||
39 | |||
40 | |||
41 | static void | ||
42 | merge_colors (int argc, XColor **argv, XColor *into_color, int mask, | ||
43 | Bool additive_p) | ||
44 | { | ||
45 | int j; | ||
46 | *into_color = *argv [0]; | ||
47 | into_color->pixel |= mask; | ||
48 | |||
49 | for (j = 1; j < argc; j++) | ||
50 | { | ||
51 | # define SHORT_INC(x,y) (x = ((((x)+(y)) > 0xFFFF) ? 0xFFFF : ((x)+(y)))) | ||
52 | # define SHORT_DEC(x,y) (x = ((((x)-(y)) < 0) ? 0 : ((x)-(y)))) | ||
53 | if (additive_p) | ||
54 | { | ||
55 | SHORT_INC (into_color->red, argv[j]->red); | ||
56 | SHORT_INC (into_color->green, argv[j]->green); | ||
57 | SHORT_INC (into_color->blue, argv[j]->blue); | ||
58 | } | ||
59 | else | ||
60 | { | ||
61 | SHORT_DEC (into_color->red, argv[j]->red); | ||
62 | SHORT_DEC (into_color->green, argv[j]->green); | ||
63 | SHORT_DEC (into_color->blue, argv[j]->blue); | ||
64 | } | ||
65 | # undef SHORT_INC | ||
66 | # undef SHORT_DEC | ||
67 | } | ||
68 | } | ||
69 | |||
70 | static void | ||
71 | permute_colors (XColor *pcolors, XColor *colors, | ||
72 | int count, | ||
73 | unsigned long *plane_masks, | ||
74 | Bool additive_p) | ||
75 | { | ||
76 | int out = 0; | ||
77 | int max = i_exp (2, count); | ||
78 | if (count > 31) abort (); | ||
79 | for (out = 1; out < max; out++) | ||
80 | { | ||
81 | XColor *argv [32]; | ||
82 | int this_mask = 0; | ||
83 | int argc = 0; | ||
84 | int bit; | ||
85 | for (bit = 0; bit < 32; bit++) | ||
86 | if (out & (1<<bit)) | ||
87 | { | ||
88 | argv [argc++] = &pcolors [bit]; | ||
89 | this_mask |= plane_masks [bit]; | ||
90 | } | ||
91 | merge_colors (argc, argv, &colors [out-1], this_mask, additive_p); | ||
92 | } | ||
93 | } | ||
94 | |||
95 | |||
96 | static int | ||
97 | allocate_color_planes (Display *dpy, Colormap cmap, | ||
98 | int nplanes, unsigned long *plane_masks, | ||
99 | unsigned long *base_pixel_ret) | ||
100 | { | ||
101 | while (nplanes > 1 && | ||
102 | !XAllocColorCells (dpy, cmap, False, plane_masks, nplanes, | ||
103 | base_pixel_ret, 1)) | ||
104 | nplanes--; | ||
105 | |||
106 | return nplanes; | ||
107 | } | ||
108 | |||
109 | |||
110 | static void | ||
111 | initialize_transparency_colormap (Display *dpy, Colormap cmap, | ||
112 | int nplanes, | ||
113 | unsigned long base_pixel, | ||
114 | unsigned long *plane_masks, | ||
115 | XColor *colors, | ||
116 | Bool additive_p) | ||
117 | { | ||
118 | int i; | ||
119 | int total_colors = i_exp (2, nplanes); | ||
120 | XColor *all_colors = (XColor *) calloc (total_colors, sizeof (XColor)); | ||
121 | |||
122 | for (i = 0; i < nplanes; i++) | ||
123 | colors[i].pixel = base_pixel | plane_masks [i]; | ||
124 | permute_colors (colors, all_colors, nplanes, plane_masks, additive_p); | ||
125 | |||
126 | /* clone the default background of the window into our "base" pixel */ | ||
127 | all_colors [total_colors - 1].pixel = | ||
128 | get_pixel_resource ("background", "Background", dpy, cmap); | ||
129 | XQueryColor (dpy, cmap, &all_colors [total_colors - 1]); | ||
130 | all_colors [total_colors - 1].pixel = base_pixel; | ||
131 | |||
132 | for (i = 0; i < total_colors; i++) | ||
133 | all_colors[i].flags = DoRed|DoGreen|DoBlue; | ||
134 | XStoreColors (dpy, cmap, all_colors, total_colors); | ||
135 | XFree ((XPointer) all_colors); | ||
136 | } | ||
137 | |||
138 | |||
139 | Bool | ||
140 | allocate_alpha_colors (Screen *screen, Visual *visual, Colormap cmap, | ||
141 | int *nplanesP, Bool additive_p, | ||
142 | unsigned long **plane_masks, | ||
143 | unsigned long *base_pixelP) | ||
144 | { | ||
145 | Display *dpy = DisplayOfScreen (screen); | ||
146 | XColor *colors; | ||
147 | int nplanes = *nplanesP; | ||
148 | int i; | ||
149 | |||
150 | if (!has_writable_cells (screen, visual)) | ||
151 | cmap = 0; | ||
152 | |||
153 | if (!cmap) /* A TrueColor visual, or similar. */ | ||
154 | { | ||
155 | int depth = visual_depth (screen, visual); | ||
156 | unsigned long masks; | ||
157 | XVisualInfo vi_in, *vi_out; | ||
158 | |||
159 | /* Find out which bits the R, G, and B components actually occupy | ||
160 | on this visual. */ | ||
161 | vi_in.screen = screen_number (screen); | ||
162 | vi_in.visualid = XVisualIDFromVisual (visual); | ||
163 | vi_out = XGetVisualInfo (dpy, VisualScreenMask|VisualIDMask, | ||
164 | &vi_in, &i); | ||
165 | if (! vi_out) abort (); | ||
166 | masks = vi_out[0].red_mask | vi_out[0].green_mask | vi_out[0].blue_mask; | ||
167 | XFree ((char *) vi_out); | ||
168 | |||
169 | if (nplanes > depth) | ||
170 | nplanes = depth; | ||
171 | *nplanesP = nplanes; | ||
172 | *base_pixelP = 0; | ||
173 | *plane_masks = (unsigned long *) calloc(sizeof(unsigned long), nplanes); | ||
174 | |||
175 | /* Pick the planar values randomly, but constrain them to fall within | ||
176 | the bit positions of the R, G, and B fields. */ | ||
177 | for (i = 0; i < nplanes; i++) | ||
178 | (*plane_masks)[i] = random() & masks; | ||
179 | |||
180 | } | ||
181 | else /* A PseudoColor visual, or similar. */ | ||
182 | { | ||
183 | if (nplanes > 31) nplanes = 31; | ||
184 | *plane_masks = (unsigned long *) malloc(sizeof(unsigned long) * nplanes); | ||
185 | |||
186 | nplanes = allocate_color_planes (dpy, cmap, nplanes, *plane_masks, | ||
187 | base_pixelP); | ||
188 | *nplanesP = nplanes; | ||
189 | |||
190 | if (nplanes <= 1) | ||
191 | { | ||
192 | free(*plane_masks); | ||
193 | *plane_masks = 0; | ||
194 | return False; | ||
195 | } | ||
196 | |||
197 | colors = (XColor *) calloc (nplanes, sizeof (XColor)); | ||
198 | for (i = 0; i < nplanes; i++) | ||
199 | { | ||
200 | /* pick the base colors. If we are in subtractive mode, pick higher | ||
201 | intensities. */ | ||
202 | hsv_to_rgb (random () % 360, | ||
203 | frand (1.0), | ||
204 | frand (0.5) + (additive_p ? 0.2 : 0.5), | ||
205 | &colors[i].red, | ||
206 | &colors[i].green, | ||
207 | &colors[i].blue); | ||
208 | } | ||
209 | initialize_transparency_colormap (dpy, cmap, nplanes, | ||
210 | *base_pixelP, *plane_masks, colors, | ||
211 | additive_p); | ||
212 | XFree ((XPointer) colors); | ||
213 | } | ||
214 | return True; | ||
215 | } | ||
diff --git a/uisimulator/alpha.h b/uisimulator/alpha.h new file mode 100644 index 0000000000..4ff99037b3 --- /dev/null +++ b/uisimulator/alpha.h | |||
@@ -0,0 +1,22 @@ | |||
1 | /* xscreensaver, Copyright (c) 1992, 1995, 1996, 1997 | ||
2 | * Jamie Zawinski <jwz@jwz.org> | ||
3 | * | ||
4 | * Permission to use, copy, modify, distribute, and sell this software and its | ||
5 | * documentation for any purpose is hereby granted without fee, provided that | ||
6 | * the above copyright notice appear in all copies and that both that | ||
7 | * copyright notice and this permission notice appear in supporting | ||
8 | * documentation. No representations are made about the suitability of this | ||
9 | * software for any purpose. It is provided "as is" without express or | ||
10 | * implied warranty. | ||
11 | */ | ||
12 | |||
13 | #ifndef __XSCREENSAVER_ALPHA_H__ | ||
14 | #define __XSCREENSAVER_ALPHA_H__ | ||
15 | |||
16 | extern Bool allocate_alpha_colors (Screen *screen, Visual *visual, | ||
17 | Colormap cmap, | ||
18 | int *nplanesP, Bool additive_p, | ||
19 | unsigned long **plane_masks, | ||
20 | unsigned long *base_pixelP); | ||
21 | |||
22 | #endif /* __XSCREENSAVER_ALPHA_H__ */ | ||
diff --git a/uisimulator/colors.h b/uisimulator/colors.h new file mode 100644 index 0000000000..61421cf5c3 --- /dev/null +++ b/uisimulator/colors.h | |||
@@ -0,0 +1,140 @@ | |||
1 | /* xscreensaver, Copyright (c) 1992, 1997 Jamie Zawinski <jwz@jwz.org> | ||
2 | * | ||
3 | * Permission to use, copy, modify, distribute, and sell this software and its | ||
4 | * documentation for any purpose is hereby granted without fee, provided that | ||
5 | * the above copyright notice appear in all copies and that both that | ||
6 | * copyright notice and this permission notice appear in supporting | ||
7 | * documentation. No representations are made about the suitability of this | ||
8 | * software for any purpose. It is provided "as is" without express or | ||
9 | * implied warranty. | ||
10 | */ | ||
11 | |||
12 | #ifndef __COLORS_H__ | ||
13 | #define __COLORS_H__ | ||
14 | |||
15 | /* Like XFreeColors, but works on `XColor *' instead of `unsigned long *' | ||
16 | */ | ||
17 | extern void free_colors (Display *, Colormap, XColor *, int ncolors); | ||
18 | |||
19 | |||
20 | /* Allocates writable, non-contiguous color cells. The number requested is | ||
21 | passed in *ncolorsP, and the number actually allocated is returned there. | ||
22 | (Unlike XAllocColorCells(), this will allocate as many as it can, instead | ||
23 | of failing if they can't all be allocated.) | ||
24 | */ | ||
25 | extern void allocate_writable_colors (Display *dpy, Colormap cmap, | ||
26 | unsigned long *pixels, int *ncolorsP); | ||
27 | |||
28 | |||
29 | /* Generates a sequence of colors evenly spaced between the given pair | ||
30 | of HSV coordinates. | ||
31 | |||
32 | If closed_p is true, the colors will go from the first point to the | ||
33 | second then back to the first. | ||
34 | |||
35 | If allocate_p is true, the colors will be allocated from the map; | ||
36 | if enough colors can't be allocated, we will try for less, and the | ||
37 | result will be returned to ncolorsP. | ||
38 | |||
39 | If writable_p is true, writable color cells will be allocated; | ||
40 | otherwise, read-only cells will be allocated. | ||
41 | */ | ||
42 | extern void make_color_ramp (Display *dpy, Colormap cmap, | ||
43 | int h1, double s1, double v1, | ||
44 | int h2, double s2, double v2, | ||
45 | XColor *colors, int *ncolorsP, | ||
46 | Bool closed_p, | ||
47 | Bool allocate_p, | ||
48 | Bool writable_p); | ||
49 | |||
50 | /* Generates a sequence of colors evenly spaced around the triangle | ||
51 | indicated by the thee HSV coordinates. | ||
52 | |||
53 | If allocate_p is true, the colors will be allocated from the map; | ||
54 | if enough colors can't be allocated, we will try for less, and the | ||
55 | result will be returned to ncolorsP. | ||
56 | |||
57 | If writable_p is true, writable color cells will be allocated; | ||
58 | otherwise, read-only cells will be allocated. | ||
59 | */ | ||
60 | extern void make_color_loop (Display *, Colormap, | ||
61 | int h1, double s1, double v1, | ||
62 | int h2, double s2, double v2, | ||
63 | int h3, double s3, double v3, | ||
64 | XColor *colors, int *ncolorsP, | ||
65 | Bool allocate_p, | ||
66 | Bool writable_p); | ||
67 | |||
68 | |||
69 | /* Allocates a hopefully-interesting colormap, which will be a closed loop | ||
70 | without any sudden transitions. | ||
71 | |||
72 | If allocate_p is true, the colors will be allocated from the map; | ||
73 | if enough colors can't be allocated, we will try for less, and the | ||
74 | result will be returned to ncolorsP. An error message will be | ||
75 | printed on stderr (if verbose_p). | ||
76 | |||
77 | If *writable_pP is true, writable color cells will be allocated; | ||
78 | otherwise, read-only cells will be allocated. If no writable cells | ||
79 | cannot be allocated, we will try to allocate unwritable cells | ||
80 | instead, and print a message on stderr to that effect (if verbose_p). | ||
81 | */ | ||
82 | extern void make_smooth_colormap (Display *dpy, Visual *visual, | ||
83 | Colormap cmap, | ||
84 | XColor *colors, int *ncolorsP, | ||
85 | Bool allocate_p, | ||
86 | Bool *writable_pP, | ||
87 | Bool verbose_p); | ||
88 | |||
89 | /* Allocates a uniform colormap which touches each hue of the spectrum, | ||
90 | evenly spaced. The saturation and intensity are chosen randomly, but | ||
91 | will be high enough to be visible. | ||
92 | |||
93 | If allocate_p is true, the colors will be allocated from the map; | ||
94 | if enough colors can't be allocated, we will try for less, and the | ||
95 | result will be returned to ncolorsP. An error message will be | ||
96 | printed on stderr (if verbose_p). | ||
97 | |||
98 | If *writable_pP is true, writable color cells will be allocated; | ||
99 | otherwise, read-only cells will be allocated. If no writable cells | ||
100 | cannot be allocated, we will try to allocate unwritable cells | ||
101 | instead, and print a message on stderr to that effect (if verbose_p). | ||
102 | */ | ||
103 | extern void make_uniform_colormap (Display *dpy, Visual *visual, | ||
104 | Colormap cmap, | ||
105 | XColor *colors, int *ncolorsP, | ||
106 | Bool allocate_p, | ||
107 | Bool *writable_pP, | ||
108 | Bool verbose_p); | ||
109 | |||
110 | /* Allocates a random colormap (the colors are unrelated to one another.) | ||
111 | If `bright_p' is false, the colors will be completely random; if it is | ||
112 | true, all of the colors will be bright enough to see on a black background. | ||
113 | |||
114 | If allocate_p is true, the colors will be allocated from the map; | ||
115 | if enough colors can't be allocated, we will try for less, and the | ||
116 | result will be returned to ncolorsP. An error message will be | ||
117 | printed on stderr (if verbose_p). | ||
118 | |||
119 | If *writable_pP is true, writable color cells will be allocated; | ||
120 | otherwise, read-only cells will be allocated. If no writable cells | ||
121 | cannot be allocated, we will try to allocate unwritable cells | ||
122 | instead, and print a message on stderr to that effect (if verbose_p). | ||
123 | */ | ||
124 | extern void make_random_colormap (Display *dpy, Visual *visual, | ||
125 | Colormap cmap, | ||
126 | XColor *colors, int *ncolorsP, | ||
127 | Bool bright_p, | ||
128 | Bool allocate_p, | ||
129 | Bool *writable_pP, | ||
130 | Bool verbose_p); | ||
131 | |||
132 | |||
133 | /* Assuming that the array of colors indicates the current state of a set | ||
134 | of writable color cells, this rotates the contents of the array by | ||
135 | `distance' steps, moving the colors of cell N to cell (N - distance). | ||
136 | */ | ||
137 | extern void rotate_colors (Display *, Colormap, | ||
138 | XColor *, int ncolors, int distance); | ||
139 | |||
140 | #endif /* __COLORS_H__ */ | ||
diff --git a/uisimulator/config.h b/uisimulator/config.h new file mode 100644 index 0000000000..1c520cfbac --- /dev/null +++ b/uisimulator/config.h | |||
@@ -0,0 +1,362 @@ | |||
1 | /* config.h. Generated automatically by configure. */ | ||
2 | /* config.h.in --- xscreensaver, Copyright (c) 1998 Jamie Zawinski. | ||
3 | * | ||
4 | * The best way to set these parameters is by running the included `configure' | ||
5 | * script. That examines your system, and generates `config.h' from | ||
6 | * `config.h.in'. | ||
7 | * | ||
8 | * If something goes very wrong, you can edit `config.h' directly, but beware | ||
9 | * that your changes will be lost if you ever run `configure' again. | ||
10 | */ | ||
11 | |||
12 | |||
13 | /* ************************************************************************* | ||
14 | CONFIGURING SERVER EXTENSIONS | ||
15 | ************************************************************************* */ | ||
16 | |||
17 | /* Define this if you have the XReadDisplay extension (I think this is an | ||
18 | SGI-only thing; it's in <X11/extensions/readdisplay.h>.) A few of the | ||
19 | screenhacks will take advantage of this if it's available. | ||
20 | */ | ||
21 | /* #undef HAVE_READ_DISPLAY_EXTENSION */ | ||
22 | |||
23 | /* Define this if you have the Iris Video Library (dmedia/vl.h on SGI.) | ||
24 | A few of the screenhacks will take advantage of this if it's available. | ||
25 | */ | ||
26 | /* #undef HAVE_SGI_VIDEO */ | ||
27 | |||
28 | /* Define this if you have the XHPDisableReset function (an HP only thing.) | ||
29 | */ | ||
30 | /* #undef HAVE_XHPDISABLERESET */ | ||
31 | |||
32 | /* First, some background: there are three distinct server extensions which | ||
33 | * are useful to a screen saver program: they are XIDLE, MIT-SCREEN-SAVER, | ||
34 | * and SCREEN_SAVER. | ||
35 | * | ||
36 | * The XIDLE extension resides in .../contrib/extensions/xidle/ on the X11R5 | ||
37 | * contrib tape. This extension lets the client get accurate idle-time | ||
38 | * information from the X server in a potentially more reliable way than by | ||
39 | * simply watching for keyboard and mouse activity. However, the XIDLE | ||
40 | * extension has apparently not been ported to X11R6. | ||
41 | * | ||
42 | * The SCREEN_SAVER extension is found (as far as I know) only in the SGI | ||
43 | * X server, and it exists in all releases since (at least) Irix 5. The | ||
44 | * relevant header file is /usr/include/X11/extensions/XScreenSaver.h. | ||
45 | * | ||
46 | * The similarly-named MIT-SCREEN-SAVER extension came into existence long | ||
47 | * after the SGI SCREEN_SAVER extension was already in use, and resides in | ||
48 | * .../contrib/extensions/screensaver/ on the X11R6 contrib tape. It is | ||
49 | * also found in certain recent X servers built in to NCD X terminals. | ||
50 | * | ||
51 | * The MIT extension does basically the same thing that the XIDLE extension | ||
52 | * does, but there are two things wrong with it: first, because of the way | ||
53 | * the extension was designed, the `fade' option to XScreenSaver will be | ||
54 | * uglier: just before the screen fades out, there will be an unattractive | ||
55 | * flicker to black, because this extension blanks the screen *before* | ||
56 | * telling us that it is time to do so. Second, this extension is known to | ||
57 | * be buggy; on the systems I use, it works, but some people have reported | ||
58 | * X server crashes as a result of using it. XScreenSaver uses this | ||
59 | * extension rather conservatively, because when I tried to use any of its | ||
60 | * more complicated features, I could get it to crash the server at the | ||
61 | * drop of a hat. | ||
62 | * | ||
63 | * In short, the MIT-SCREEN-SAVER extension is a piece of junk. The older | ||
64 | * SGI SCREEN_SAVER extension works great, as does XIDLE. It would be nice | ||
65 | * If those two existed on more systems, that is, would be adopted by the | ||
66 | * X Consortium in favor of their inferior "not-invented-here" entry. | ||
67 | */ | ||
68 | |||
69 | /* Define this if you have the XIDLE extension installed. If you have the | ||
70 | * XIDLE extension, this is recommended. (You have this extension if the | ||
71 | * file /usr/include/X11/extensions/xidle.h exists.) Turning on this flag | ||
72 | * lets XScreenSaver work better with servers which support this extension; | ||
73 | * but it will still work with servers which do not suport it, so it's a good | ||
74 | * idea to compile in support for it if you can. | ||
75 | */ | ||
76 | /* #undef HAVE_XIDLE_EXTENSION */ | ||
77 | |||
78 | /* Define this if you have the MIT-SCREEN-SAVER extension installed. See the | ||
79 | * caveats about this extension, above. (It's available if the file | ||
80 | * /usr/include/X11/extensions/scrnsaver.h exists.) | ||
81 | */ | ||
82 | #define HAVE_MIT_SAVER_EXTENSION 1 | ||
83 | |||
84 | /* Define this if you have the SGI SCREEN_SAVER extension. This is standard | ||
85 | * on Irix systems, and not available elsewhere. | ||
86 | */ | ||
87 | /* #undef HAVE_SGI_SAVER_EXTENSION */ | ||
88 | |||
89 | /* Define this if you have the SGI-VIDEO-CONTROL extension. This is standard | ||
90 | * on Irix systems, and not available elsewhere. | ||
91 | */ | ||
92 | /* #undef HAVE_SGI_VC_EXTENSION */ | ||
93 | |||
94 | /* Define this if you have the XDPMS extension. This is standard on | ||
95 | * sufficiently-recent XFree86 systems, and possibly elsewhere. (It's | ||
96 | * available if the file /usr/include/X11/extensions/dpms.h exists.) | ||
97 | */ | ||
98 | /* #undef HAVE_DPMS_EXTENSION */ | ||
99 | |||
100 | /* Define this if you have the functions XF86VidModeGetModeLine() and | ||
101 | * XF86VidModeGetViewPort(), in support of virtual desktops where the | ||
102 | * X server's root window is bigger than the actual screen. This is | ||
103 | * an XFree86 thing, and probably doesn't exist elsewhere. (It's | ||
104 | * available if the file /usr/include/X11/extensions/xf86vmode.h exists.) | ||
105 | */ | ||
106 | /* #undef HAVE_XF86VMODE */ | ||
107 | |||
108 | /* Define this if you have a Linux-like /proc/interrupts file which can be | ||
109 | * examined to determine when keyboard activity has occurred. | ||
110 | */ | ||
111 | /* #undef HAVE_PROC_INTERRUPTS */ | ||
112 | |||
113 | |||
114 | |||
115 | /* ************************************************************************* | ||
116 | CONFIGURING GRAPHICS TOOLKITS | ||
117 | ************************************************************************* */ | ||
118 | |||
119 | /* Define this if you have Motif. | ||
120 | */ | ||
121 | #define HAVE_MOTIF 1 | ||
122 | |||
123 | /* Define this if you have Gtk. | ||
124 | */ | ||
125 | /* #undef HAVE_GTK */ | ||
126 | |||
127 | /* Define this if you have Athena (-Xaw). | ||
128 | */ | ||
129 | #define HAVE_ATHENA 1 | ||
130 | |||
131 | /* Define this if you have Athena, and the version you have includes the | ||
132 | * XawViewportSetCoordinates function in Viewport.h (some old versions of | ||
133 | * the library didn't have this function.) | ||
134 | */ | ||
135 | #define HAVE_XawViewportSetCoordinates 1 | ||
136 | |||
137 | /* Define this if you have the XPM library installed. Some of the demos can | ||
138 | * make use of this if it is available. | ||
139 | */ | ||
140 | #define HAVE_XPM 1 | ||
141 | |||
142 | /* Define this if you have the Xmu library. This is standard part of X, and | ||
143 | * if your vendor doesn't ship it, you should report that as a bug. | ||
144 | */ | ||
145 | #define HAVE_XMU 1 | ||
146 | |||
147 | /* Define this if you have OpenGL. Some of the demos require it, so if you | ||
148 | * don't have it, then those particular demos won't be built. (This won't | ||
149 | * affect the screen saver as a whole.) | ||
150 | */ | ||
151 | /* #undef HAVE_GL */ | ||
152 | |||
153 | /* Define this if you have OpenGL, but it's the MesaGL variant. (The | ||
154 | libraries have different names.) (HAVE_GL should be defined too.) | ||
155 | */ | ||
156 | /* #undef HAVE_MESA_GL */ | ||
157 | |||
158 | /* Define this if your version of OpenGL has the glBindTexture() routine. | ||
159 | This is the case for OpenGL 1.1, but not for OpenGL 1.0. | ||
160 | */ | ||
161 | /* #undef HAVE_GLBINDTEXTURE */ | ||
162 | |||
163 | /* Define this if you have the -lgle and -lmatrix libraries (GL extrusion.) | ||
164 | */ | ||
165 | /* #undef HAVE_GLE */ | ||
166 | |||
167 | /* Define this if the `xscreensaver' process itself (the driver process) | ||
168 | should be linked against GL. Most systems won't want this (in particular, | ||
169 | if you're using Linux and/or Mesa, you don't want this) but SGI systems | ||
170 | do want this. It may also be useful on other systems that have serious | ||
171 | GL support -- you only need this if you have a lot of different visuals, | ||
172 | not all of which work with GL programs. | ||
173 | */ | ||
174 | /* #undef DAEMON_USE_GL */ | ||
175 | |||
176 | /* Define this if you have the X Shared Memory Extension. | ||
177 | */ | ||
178 | #define HAVE_XSHM_EXTENSION 1 | ||
179 | |||
180 | /* Define this if you have the X Double Buffer Extension. | ||
181 | */ | ||
182 | #define HAVE_DOUBLE_BUFFER_EXTENSION 1 | ||
183 | |||
184 | /* Some screenhacks like to run an external program to generate random pieces | ||
185 | of text; set this to the one you like ("yow" and "fortune" are the most | ||
186 | likely prospects.) Note that this is just the default; X resources can | ||
187 | be used to override it. | ||
188 | */ | ||
189 | #define ZIPPY_PROGRAM "/usr/local/libexec/emacs/20.4/sparc-sun-solaris2.6/yow" | ||
190 | |||
191 | |||
192 | |||
193 | /* ************************************************************************* | ||
194 | CONFIGURING PASSWORD AUTHENTICATION | ||
195 | ************************************************************************* */ | ||
196 | |||
197 | /* Define this to remove the option of locking the screen at all. | ||
198 | */ | ||
199 | /* #undef NO_LOCKING */ | ||
200 | |||
201 | /* Define this if you want to use Kerberos authentication to lock/unlock the | ||
202 | * screen instead of your local password. This currently uses Kerberos V4, | ||
203 | * but a V5 server with V4 compatibility will work. WARNING: DO NOT USE AFS | ||
204 | * string-to-key passwords with this option. This option currently *only* | ||
205 | * works with standard Kerberos des_string_to_key. If your password is an | ||
206 | * AFS password and not a kerberos password, it will not authenticate | ||
207 | * properly. See the comments in driver/kpasswd.c for more information if you | ||
208 | * need it. | ||
209 | */ | ||
210 | /* #undef HAVE_KERBEROS */ | ||
211 | |||
212 | /* Define this if you want to use PAM (Pluggable Authentication Modules) | ||
213 | * to lock/unlock the screen, instead of standard /etc/passwd authentication. | ||
214 | */ | ||
215 | /* #undef HAVE_PAM */ | ||
216 | |||
217 | /* If PAM is being used, this is the name of the PAM service that xscreensaver | ||
218 | * will authenticate as. The default is "xscreensaver", which means that the | ||
219 | * PAM library will look for an "xscreensaver" line in /etc/pam.conf, or (on | ||
220 | * recent Linux systems) will look for a file called /etc/pam.d/xscreensaver. | ||
221 | * Some systems might already have a PAM installation that is configured for | ||
222 | * xlock, so setting this to "xlock" would also work in that case. | ||
223 | */ | ||
224 | #define PAM_SERVICE_NAME "xscreensaver" | ||
225 | |||
226 | /* Define if you have PAM and pam_strerror() requires two arguments. */ | ||
227 | /* #undef PAM_STRERROR_TWO_ARGS */ | ||
228 | |||
229 | /* Define this if your system uses `shadow' passwords, that is, the passwords | ||
230 | * live in /etc/shadow instead of /etc/passwd, and one reads them with | ||
231 | * getspnam() instead of getpwnam(). (Note that SCO systems do some random | ||
232 | * other thing; others might as well. See the ifdefs in driver/passwd-pwent.c | ||
233 | * if you're having trouble related to reading passwords.) | ||
234 | */ | ||
235 | #define HAVE_SHADOW_PASSWD 1 | ||
236 | |||
237 | /* Define this if your system is Digital or SCO Unix with so-called ``Enhanced | ||
238 | Security'', that is, the passwords live in /tcb/files/auth/<x>/<xyz> | ||
239 | instead of in /etc/passwd, and one reads them with getprpwnam() instead | ||
240 | of getpwnam(). | ||
241 | */ | ||
242 | /* #undef HAVE_ENHANCED_PASSWD */ | ||
243 | |||
244 | /* Define this if your system is Solaris with ``adjunct'' passwords (this is | ||
245 | the version where one gets at the passwords with getpwanam() instead of | ||
246 | getpwnam().) I haven't tested this one, let me know if it works. | ||
247 | */ | ||
248 | /* #undef HAVE_ADJUNCT_PASSWD */ | ||
249 | |||
250 | /* Define this if you are running HPUX with so-called ``Secure Passwords'' | ||
251 | (if you have /usr/include/hpsecurity.h, you probably have this.) I | ||
252 | haven't tested this one, let me know if it works. | ||
253 | */ | ||
254 | /* #undef HAVE_HPUX_PASSWD */ | ||
255 | |||
256 | /* Define this if you are on a system that supports the VT_LOCKSWITCH and | ||
257 | VT_UNLOCKSWITCH ioctls. If this is defined, then when the screen is | ||
258 | locked, switching to another virtual terminal will also be prevented. | ||
259 | That is, the whole console will be locked, rather than just the VT on | ||
260 | which X is running. (Well, that's the theory anyway -- in practice, | ||
261 | I haven't yet figured out how to make that work.) | ||
262 | */ | ||
263 | /* #undef HAVE_VT_LOCKSWITCH */ | ||
264 | |||
265 | |||
266 | /* Define this if you the openlog(), syslog(), and closelog() functions. | ||
267 | This is used for logging failed login attempts. | ||
268 | */ | ||
269 | #define HAVE_SYSLOG 1 | ||
270 | |||
271 | |||
272 | /* ************************************************************************* | ||
273 | OTHER C ENVIRONMENT JUNK | ||
274 | ************************************************************************* */ | ||
275 | |||
276 | /* Define this to void* if you're using X11R4 or earlier. */ | ||
277 | /* #undef XPointer */ | ||
278 | |||
279 | /* Define if you have the nice function. */ | ||
280 | #define HAVE_NICE 1 | ||
281 | |||
282 | /* Define if you have the setpriority function. */ | ||
283 | #define HAVE_SETPRIORITY 1 | ||
284 | |||
285 | /* Define to empty if the keyword does not work. */ | ||
286 | /* #undef const */ | ||
287 | |||
288 | /* Define if you have <sys/wait.h> that is POSIX.1 compatible. */ | ||
289 | #define HAVE_SYS_WAIT_H 1 | ||
290 | |||
291 | /* Define as __inline if that's what the C compiler calls it. */ | ||
292 | /* #undef inline */ | ||
293 | |||
294 | /* Define to `int' if <sys/types.h> doesn't define. */ | ||
295 | /* #undef mode_t */ | ||
296 | |||
297 | /* Define to `int' if <sys/types.h> doesn't define. */ | ||
298 | /* #undef pid_t */ | ||
299 | |||
300 | /* Define as the return type of signal handlers (int or void). */ | ||
301 | #define RETSIGTYPE void | ||
302 | |||
303 | /* Define to `unsigned' if <sys/types.h> doesn't define. */ | ||
304 | /* #undef size_t */ | ||
305 | |||
306 | /* Define if you have the ANSI C header files. */ | ||
307 | #define STDC_HEADERS 1 | ||
308 | |||
309 | /* Define if you can safely include both <sys/time.h> and <time.h>. */ | ||
310 | #define TIME_WITH_SYS_TIME 1 | ||
311 | |||
312 | /* Define if you have the gettimeofday function. */ | ||
313 | #define HAVE_GETTIMEOFDAY 1 | ||
314 | |||
315 | /* Define if gettimeofday requires two arguments. */ | ||
316 | #define GETTIMEOFDAY_TWO_ARGS 1 | ||
317 | |||
318 | /* Define if you have the putenv function. */ | ||
319 | #define HAVE_PUTENV 1 | ||
320 | |||
321 | /* Define if you have the select function. */ | ||
322 | #define HAVE_SELECT 1 | ||
323 | |||
324 | /* Define if you have the getcwd function. */ | ||
325 | #define HAVE_GETCWD 1 | ||
326 | |||
327 | /* Define if you have the getcwd function. */ | ||
328 | #define HAVE_GETWD 1 | ||
329 | |||
330 | /* Define if you have the realpath function. */ | ||
331 | #define HAVE_REALPATH 1 | ||
332 | |||
333 | /* Define if you have the uname function. */ | ||
334 | #define HAVE_UNAME 1 | ||
335 | |||
336 | /* Define if you have the fcntl function. */ | ||
337 | #define HAVE_FCNTL 1 | ||
338 | |||
339 | /* Define if you have the sigaction function. */ | ||
340 | #define HAVE_SIGACTION 1 | ||
341 | |||
342 | /* Define if you have the <unistd.h> header file. */ | ||
343 | #define HAVE_UNISTD_H 1 | ||
344 | |||
345 | /* Define if you have the <crypt.h> header file. */ | ||
346 | #define HAVE_CRYPT_H 1 | ||
347 | |||
348 | /* Define if you have <sys/select.h> that defines fd_set and FD_SET. */ | ||
349 | #define HAVE_SYS_SELECT_H 1 | ||
350 | |||
351 | /* Define to use sigaction() instead of signal() for SIGCHLD-related activity. | ||
352 | This is necessary at least on SCO OpenServer 5, due to a Unix kernel bug. | ||
353 | */ | ||
354 | /* #undef USE_SIGACTION */ | ||
355 | |||
356 | /* Define this if you do pings with a `struct icmp' and a `icmp_id' slot. | ||
357 | */ | ||
358 | #define HAVE_ICMP 1 | ||
359 | |||
360 | /* Define this if you do pings with a `struct icmphdr' and a `un.echo.id' slot. | ||
361 | */ | ||
362 | /* #undef HAVE_ICMPHDR */ | ||
diff --git a/uisimulator/grabscreen.h b/uisimulator/grabscreen.h new file mode 100644 index 0000000000..6d2503a1fc --- /dev/null +++ b/uisimulator/grabscreen.h | |||
@@ -0,0 +1,27 @@ | |||
1 | /* xscreensaver, Copyright (c) 1992, 1993, 1994, 1997 | ||
2 | * Jamie Zawinski <jwz@jwz.org> | ||
3 | * | ||
4 | * Permission to use, copy, modify, distribute, and sell this software and its | ||
5 | * documentation for any purpose is hereby granted without fee, provided that | ||
6 | * the above copyright notice appear in all copies and that both that | ||
7 | * copyright notice and this permission notice appear in supporting | ||
8 | * documentation. No representations are made about the suitability of this | ||
9 | * software for any purpose. It is provided "as is" without express or | ||
10 | * implied warranty. | ||
11 | */ | ||
12 | |||
13 | #ifndef __GRABSCREEN_H__ | ||
14 | #define __GRABSCREEN_H__ | ||
15 | |||
16 | /* This will write a snapshot of the screen image into the given window. | ||
17 | Beware that the colormap of the window may also be changed (to match | ||
18 | the bits that were drawn.) | ||
19 | */ | ||
20 | extern void grab_screen_image (Screen *, Window); | ||
21 | |||
22 | /* Whether one should use GCSubwindowMode when drawing on this window | ||
23 | (assuming a screen image has been grabbed onto it.) Yes, this is a | ||
24 | total kludge. */ | ||
25 | extern Bool use_subwindow_mode_p(Screen *screen, Window window); | ||
26 | |||
27 | #endif /* __GRABSCREEN_H__ */ | ||
diff --git a/uisimulator/guiclient.h b/uisimulator/guiclient.h new file mode 100644 index 0000000000..472e7fa3be --- /dev/null +++ b/uisimulator/guiclient.h | |||
@@ -0,0 +1,6 @@ | |||
1 | #ifndef GUICLIENT_H | ||
2 | #define GUICLIENT_H | ||
3 | |||
4 | extern void drawline(int color, int x1, int y1, int x2, int y2); | ||
5 | |||
6 | #endif | ||
diff --git a/uisimulator/hsv.c b/uisimulator/hsv.c new file mode 100644 index 0000000000..cf1cc8d18e --- /dev/null +++ b/uisimulator/hsv.c | |||
@@ -0,0 +1,81 @@ | |||
1 | /* xscreensaver, Copyright (c) 1992, 1997 Jamie Zawinski <jwz@jwz.org> | ||
2 | * | ||
3 | * Permission to use, copy, modify, distribute, and sell this software and its | ||
4 | * documentation for any purpose is hereby granted without fee, provided that | ||
5 | * the above copyright notice appear in all copies and that both that | ||
6 | * copyright notice and this permission notice appear in supporting | ||
7 | * documentation. No representations are made about the suitability of this | ||
8 | * software for any purpose. It is provided "as is" without express or | ||
9 | * implied warranty. | ||
10 | */ | ||
11 | |||
12 | /* This file contains some utility routines for randomly picking the colors | ||
13 | to hack the screen with. | ||
14 | */ | ||
15 | |||
16 | #include "utils.h" | ||
17 | #include "hsv.h" | ||
18 | |||
19 | void | ||
20 | hsv_to_rgb (int h, double s, double v, | ||
21 | unsigned short *r, unsigned short *g, unsigned short *b) | ||
22 | { | ||
23 | double H, S, V, R, G, B; | ||
24 | double p1, p2, p3; | ||
25 | double f; | ||
26 | int i; | ||
27 | |||
28 | if (s < 0) s = 0; | ||
29 | if (v < 0) v = 0; | ||
30 | if (s > 1) s = 1; | ||
31 | if (v > 1) v = 1; | ||
32 | |||
33 | S = s; V = v; | ||
34 | H = (h % 360) / 60.0; | ||
35 | i = H; | ||
36 | f = H - i; | ||
37 | p1 = V * (1 - S); | ||
38 | p2 = V * (1 - (S * f)); | ||
39 | p3 = V * (1 - (S * (1 - f))); | ||
40 | if (i == 0) { R = V; G = p3; B = p1; } | ||
41 | else if (i == 1) { R = p2; G = V; B = p1; } | ||
42 | else if (i == 2) { R = p1; G = V; B = p3; } | ||
43 | else if (i == 3) { R = p1; G = p2; B = V; } | ||
44 | else if (i == 4) { R = p3; G = p1; B = V; } | ||
45 | else { R = V; G = p1; B = p2; } | ||
46 | *r = R * 65535; | ||
47 | *g = G * 65535; | ||
48 | *b = B * 65535; | ||
49 | } | ||
50 | |||
51 | void | ||
52 | rgb_to_hsv (unsigned short r, unsigned short g, unsigned short b, | ||
53 | int *h, double *s, double *v) | ||
54 | { | ||
55 | double R, G, B, H, S, V; | ||
56 | double cmax, cmin; | ||
57 | double cmm; | ||
58 | int imax; | ||
59 | R = ((double) r) / 65535.0; | ||
60 | G = ((double) g) / 65535.0; | ||
61 | B = ((double) b) / 65535.0; | ||
62 | cmax = R; cmin = G; imax = 1; | ||
63 | if ( cmax < G ) { cmax = G; cmin = R; imax = 2; } | ||
64 | if ( cmax < B ) { cmax = B; imax = 3; } | ||
65 | if ( cmin > B ) { cmin = B; } | ||
66 | cmm = cmax - cmin; | ||
67 | V = cmax; | ||
68 | if (cmm == 0) | ||
69 | S = H = 0; | ||
70 | else | ||
71 | { | ||
72 | S = cmm / cmax; | ||
73 | if (imax == 1) H = (G - B) / cmm; | ||
74 | else if (imax == 2) H = 2.0 + (B - R) / cmm; | ||
75 | else /*if (imax == 3)*/ H = 4.0 + (R - G) / cmm; | ||
76 | if (H < 0) H += 6.0; | ||
77 | } | ||
78 | *h = (H * 60.0); | ||
79 | *s = S; | ||
80 | *v = V; | ||
81 | } | ||
diff --git a/uisimulator/hsv.h b/uisimulator/hsv.h new file mode 100644 index 0000000000..e0fdfb0fe6 --- /dev/null +++ b/uisimulator/hsv.h | |||
@@ -0,0 +1,27 @@ | |||
1 | /* xscreensaver, Copyright (c) 1992, 1997 Jamie Zawinski <jwz@jwz.org> | ||
2 | * | ||
3 | * Permission to use, copy, modify, distribute, and sell this software and its | ||
4 | * documentation for any purpose is hereby granted without fee, provided that | ||
5 | * the above copyright notice appear in all copies and that both that | ||
6 | * copyright notice and this permission notice appear in supporting | ||
7 | * documentation. No representations are made about the suitability of this | ||
8 | * software for any purpose. It is provided "as is" without express or | ||
9 | * implied warranty. | ||
10 | */ | ||
11 | |||
12 | #ifndef __HSV_H__ | ||
13 | #define __HSV_H__ | ||
14 | |||
15 | /* Converts between RGB and HSV color spaces. | ||
16 | R, G, and B are in the range 0 - 65535; | ||
17 | H is in the range 0 - 360; | ||
18 | S and V are in the range 0.0 - 1.0. | ||
19 | */ | ||
20 | extern void hsv_to_rgb (int h, double s, double v, | ||
21 | unsigned short *r, | ||
22 | unsigned short *g, | ||
23 | unsigned short *b); | ||
24 | extern void rgb_to_hsv (unsigned short r, unsigned short g, unsigned short b, | ||
25 | int *h, double *s, double *v); | ||
26 | |||
27 | #endif /* __HSV_H__ */ | ||
diff --git a/uisimulator/list.h b/uisimulator/list.h new file mode 100644 index 0000000000..91a85869bc --- /dev/null +++ b/uisimulator/list.h | |||
@@ -0,0 +1,38 @@ | |||
1 | #ifndef LIST_H | ||
2 | #define LIST_H | ||
3 | |||
4 | |||
5 | class ListWalk { | ||
6 | public: | ||
7 | ListWalk(class List *list); | ||
8 | void restart(); | ||
9 | |||
10 | void* getNext(); | ||
11 | |||
12 | private: | ||
13 | int index; | ||
14 | class List *list; | ||
15 | }; | ||
16 | |||
17 | class List { | ||
18 | friend ListWalk; | ||
19 | public: | ||
20 | List(); | ||
21 | |||
22 | void* getNext(void *); // next after this | ||
23 | |||
24 | int getSize(); | ||
25 | |||
26 | bool add(void *); | ||
27 | void *remove(void *); | ||
28 | |||
29 | private: | ||
30 | void **data; | ||
31 | int datasize; | ||
32 | |||
33 | int size; | ||
34 | |||
35 | }; | ||
36 | |||
37 | |||
38 | #endif // LIST_H | ||
diff --git a/uisimulator/resources.c b/uisimulator/resources.c new file mode 100644 index 0000000000..e0925d0fc7 --- /dev/null +++ b/uisimulator/resources.c | |||
@@ -0,0 +1,231 @@ | |||
1 | /* xscreensaver, Copyright (c) 1992, 1997, 1998 | ||
2 | * Jamie Zawinski <jwz@jwz.org> | ||
3 | * | ||
4 | * Permission to use, copy, modify, distribute, and sell this software and its | ||
5 | * documentation for any purpose is hereby granted without fee, provided that | ||
6 | * the above copyright notice appear in all copies and that both that | ||
7 | * copyright notice and this permission notice appear in supporting | ||
8 | * documentation. No representations are made about the suitability of this | ||
9 | * software for any purpose. It is provided "as is" without express or | ||
10 | * implied warranty. | ||
11 | */ | ||
12 | |||
13 | #include "utils.h" | ||
14 | #include "resources.h" | ||
15 | #include <X11/Xresource.h> | ||
16 | |||
17 | |||
18 | /* Resource functions. Assumes: */ | ||
19 | |||
20 | extern char *progname; | ||
21 | extern char *progclass; | ||
22 | extern XrmDatabase db; | ||
23 | |||
24 | static unsigned int get_time_resource (char *res_name, char *res_class, | ||
25 | Bool sec_p); | ||
26 | |||
27 | #ifndef isupper | ||
28 | # define isupper(c) ((c) >= 'A' && (c) <= 'Z') | ||
29 | #endif | ||
30 | #ifndef _tolower | ||
31 | # define _tolower(c) ((c) - 'A' + 'a') | ||
32 | #endif | ||
33 | |||
34 | char * | ||
35 | get_string_resource (char *res_name, char *res_class) | ||
36 | { | ||
37 | XrmValue value; | ||
38 | char *type; | ||
39 | char full_name [1024], full_class [1024]; | ||
40 | strcpy (full_name, progname); | ||
41 | strcat (full_name, "."); | ||
42 | strcat (full_name, res_name); | ||
43 | strcpy (full_class, progclass); | ||
44 | strcat (full_class, "."); | ||
45 | strcat (full_class, res_class); | ||
46 | if (XrmGetResource (db, full_name, full_class, &type, &value)) | ||
47 | { | ||
48 | char *str = (char *) malloc (value.size + 1); | ||
49 | strncpy (str, (char *) value.addr, value.size); | ||
50 | str [value.size] = 0; | ||
51 | return str; | ||
52 | } | ||
53 | return 0; | ||
54 | } | ||
55 | |||
56 | Bool | ||
57 | get_boolean_resource (char *res_name, char *res_class) | ||
58 | { | ||
59 | char *tmp, buf [100]; | ||
60 | char *s = get_string_resource (res_name, res_class); | ||
61 | char *os = s; | ||
62 | if (! s) return 0; | ||
63 | for (tmp = buf; *s; s++) | ||
64 | *tmp++ = isupper (*s) ? _tolower (*s) : *s; | ||
65 | *tmp = 0; | ||
66 | free (os); | ||
67 | |||
68 | while (*buf && | ||
69 | (buf[strlen(buf)-1] == ' ' || | ||
70 | buf[strlen(buf)-1] == '\t')) | ||
71 | buf[strlen(buf)-1] = 0; | ||
72 | |||
73 | if (!strcmp (buf, "on") || !strcmp (buf, "true") || !strcmp (buf, "yes")) | ||
74 | return 1; | ||
75 | if (!strcmp (buf,"off") || !strcmp (buf, "false") || !strcmp (buf,"no")) | ||
76 | return 0; | ||
77 | fprintf (stderr, "%s: %s must be boolean, not %s.\n", | ||
78 | progname, res_name, buf); | ||
79 | return 0; | ||
80 | } | ||
81 | |||
82 | int | ||
83 | get_integer_resource (char *res_name, char *res_class) | ||
84 | { | ||
85 | int val; | ||
86 | char c, *s = get_string_resource (res_name, res_class); | ||
87 | char *ss = s; | ||
88 | if (!s) return 0; | ||
89 | |||
90 | while (*ss && *ss <= ' ') ss++; /* skip whitespace */ | ||
91 | |||
92 | if (ss[0] == '0' && (ss[1] == 'x' || ss[1] == 'X')) /* 0x: parse as hex */ | ||
93 | { | ||
94 | if (1 == sscanf (ss+2, "%x %c", &val, &c)) | ||
95 | { | ||
96 | free (s); | ||
97 | return val; | ||
98 | } | ||
99 | } | ||
100 | else /* else parse as dec */ | ||
101 | { | ||
102 | if (1 == sscanf (ss, "%d %c", &val, &c)) | ||
103 | { | ||
104 | free (s); | ||
105 | return val; | ||
106 | } | ||
107 | } | ||
108 | |||
109 | fprintf (stderr, "%s: %s must be an integer, not %s.\n", | ||
110 | progname, res_name, s); | ||
111 | free (s); | ||
112 | return 0; | ||
113 | } | ||
114 | |||
115 | double | ||
116 | get_float_resource (char *res_name, char *res_class) | ||
117 | { | ||
118 | double val; | ||
119 | char c, *s = get_string_resource (res_name, res_class); | ||
120 | if (! s) return 0.0; | ||
121 | if (1 == sscanf (s, " %lf %c", &val, &c)) | ||
122 | { | ||
123 | free (s); | ||
124 | return val; | ||
125 | } | ||
126 | fprintf (stderr, "%s: %s must be a float, not %s.\n", | ||
127 | progname, res_name, s); | ||
128 | free (s); | ||
129 | return 0.0; | ||
130 | } | ||
131 | |||
132 | |||
133 | unsigned int | ||
134 | get_pixel_resource (char *res_name, char *res_class, | ||
135 | Display *dpy, Colormap cmap) | ||
136 | { | ||
137 | XColor color; | ||
138 | char *s = get_string_resource (res_name, res_class); | ||
139 | char *s2; | ||
140 | if (!s) goto DEFAULT; | ||
141 | |||
142 | for (s2 = s + strlen(s) - 1; s2 > s; s2--) | ||
143 | if (*s2 == ' ' || *s2 == '\t') | ||
144 | *s2 = 0; | ||
145 | else | ||
146 | break; | ||
147 | |||
148 | if (! XParseColor (dpy, cmap, s, &color)) | ||
149 | { | ||
150 | fprintf (stderr, "%s: can't parse color %s\n", progname, s); | ||
151 | goto DEFAULT; | ||
152 | } | ||
153 | if (! XAllocColor (dpy, cmap, &color)) | ||
154 | { | ||
155 | fprintf (stderr, "%s: couldn't allocate color %s\n", progname, s); | ||
156 | goto DEFAULT; | ||
157 | } | ||
158 | free (s); | ||
159 | return color.pixel; | ||
160 | DEFAULT: | ||
161 | if (s) free (s); | ||
162 | return ((strlen(res_class) >= 10 && | ||
163 | !strcmp ("Background", res_class + strlen(res_class) - 10)) | ||
164 | ? BlackPixel (dpy, DefaultScreen (dpy)) | ||
165 | : WhitePixel (dpy, DefaultScreen (dpy))); | ||
166 | } | ||
167 | |||
168 | |||
169 | int | ||
170 | parse_time (const char *string, Bool seconds_default_p, Bool silent_p) | ||
171 | { | ||
172 | unsigned int h, m, s; | ||
173 | char c; | ||
174 | if (3 == sscanf (string, " %u : %2u : %2u %c", &h, &m, &s, &c)) | ||
175 | ; | ||
176 | else if (2 == sscanf (string, " : %2u : %2u %c", &m, &s, &c) || | ||
177 | 2 == sscanf (string, " %u : %2u %c", &m, &s, &c)) | ||
178 | h = 0; | ||
179 | else if (1 == sscanf (string, " : %2u %c", &s, &c)) | ||
180 | h = m = 0; | ||
181 | else if (1 == sscanf (string, " %u %c", | ||
182 | (seconds_default_p ? &s : &m), &c)) | ||
183 | { | ||
184 | h = 0; | ||
185 | if (seconds_default_p) m = 0; | ||
186 | else s = 0; | ||
187 | } | ||
188 | else | ||
189 | { | ||
190 | if (! silent_p) | ||
191 | fprintf (stderr, "%s: invalid time interval specification \"%s\".\n", | ||
192 | progname, string); | ||
193 | return -1; | ||
194 | } | ||
195 | if (s >= 60 && (h != 0 || m != 0)) | ||
196 | { | ||
197 | if (! silent_p) | ||
198 | fprintf (stderr, "%s: seconds > 59 in \"%s\".\n", progname, string); | ||
199 | return -1; | ||
200 | } | ||
201 | if (m >= 60 && h > 0) | ||
202 | { | ||
203 | if (! silent_p) | ||
204 | fprintf (stderr, "%s: minutes > 59 in \"%s\".\n", progname, string); | ||
205 | return -1; | ||
206 | } | ||
207 | return ((h * 60 * 60) + (m * 60) + s); | ||
208 | } | ||
209 | |||
210 | static unsigned int | ||
211 | get_time_resource (char *res_name, char *res_class, Bool sec_p) | ||
212 | { | ||
213 | int val; | ||
214 | char *s = get_string_resource (res_name, res_class); | ||
215 | if (!s) return 0; | ||
216 | val = parse_time (s, sec_p, False); | ||
217 | free (s); | ||
218 | return (val < 0 ? 0 : val); | ||
219 | } | ||
220 | |||
221 | unsigned int | ||
222 | get_seconds_resource (char *res_name, char *res_class) | ||
223 | { | ||
224 | return get_time_resource (res_name, res_class, True); | ||
225 | } | ||
226 | |||
227 | unsigned int | ||
228 | get_minutes_resource (char *res_name, char *res_class) | ||
229 | { | ||
230 | return get_time_resource (res_name, res_class, False); | ||
231 | } | ||
diff --git a/uisimulator/resources.h b/uisimulator/resources.h new file mode 100644 index 0000000000..1fbcfa7ce7 --- /dev/null +++ b/uisimulator/resources.h | |||
@@ -0,0 +1,23 @@ | |||
1 | /* xscreensaver, Copyright (c) 1992, 1997 Jamie Zawinski <jwz@jwz.org> | ||
2 | * | ||
3 | * Permission to use, copy, modify, distribute, and sell this software and its | ||
4 | * documentation for any purpose is hereby granted without fee, provided that | ||
5 | * the above copyright notice appear in all copies and that both that | ||
6 | * copyright notice and this permission notice appear in supporting | ||
7 | * documentation. No representations are made about the suitability of this | ||
8 | * software for any purpose. It is provided "as is" without express or | ||
9 | * implied warranty. | ||
10 | */ | ||
11 | |||
12 | #ifndef __XSCREENSAVER_RESOURCES_H__ | ||
13 | #define __XSCREENSAVER_RESOURCES_H__ | ||
14 | extern char *get_string_resource (char*,char*); | ||
15 | extern Bool get_boolean_resource (char*,char*); | ||
16 | extern int get_integer_resource (char*,char*); | ||
17 | extern double get_float_resource (char*,char*); | ||
18 | extern unsigned int get_pixel_resource (char*,char*,Display*,Colormap); | ||
19 | extern unsigned int get_minutes_resource (char*,char*); | ||
20 | extern unsigned int get_seconds_resource (char*,char*); | ||
21 | extern int parse_time (const char *string, Bool seconds_default_p, | ||
22 | Bool silent_p); | ||
23 | #endif /* __XSCREENSAVER_RESOURCES_H__ */ | ||
diff --git a/uisimulator/rockboxui b/uisimulator/rockboxui new file mode 100755 index 0000000000..d0f71b64d6 --- /dev/null +++ b/uisimulator/rockboxui | |||
Binary files differ | |||
diff --git a/uisimulator/screenhack.c b/uisimulator/screenhack.c new file mode 100644 index 0000000000..538400944e --- /dev/null +++ b/uisimulator/screenhack.c | |||
@@ -0,0 +1,581 @@ | |||
1 | /* xscreensaver, Copyright (c) 1992, 1995, 1997, 1998 | ||
2 | * Jamie Zawinski <jwz@jwz.org> | ||
3 | * | ||
4 | * Permission to use, copy, modify, distribute, and sell this software and its | ||
5 | * documentation for any purpose is hereby granted without fee, provided that | ||
6 | * the above copyright notice appear in all copies and that both that | ||
7 | * copyright notice and this permission notice appear in supporting | ||
8 | * documentation. No representations are made about the suitability of this | ||
9 | * software for any purpose. It is provided "as is" without express or | ||
10 | * implied warranty. | ||
11 | * | ||
12 | * And remember: X Windows is to graphics hacking as roman numerals are to | ||
13 | * the square root of pi. | ||
14 | */ | ||
15 | |||
16 | /* This file contains simple code to open a window or draw on the root. | ||
17 | The idea being that, when writing a graphics hack, you can just link | ||
18 | with this .o to get all of the uninteresting junk out of the way. | ||
19 | |||
20 | - create a procedure `screenhack(dpy, window)' | ||
21 | |||
22 | - create a variable `char *progclass' which names this program's | ||
23 | resource class. | ||
24 | |||
25 | - create a variable `char defaults []' for the default resources, and | ||
26 | null-terminate it. | ||
27 | |||
28 | - create a variable `XrmOptionDescRec options[]' for the command-line, | ||
29 | and null-terminate it. | ||
30 | |||
31 | And that's it... | ||
32 | */ | ||
33 | |||
34 | #include <stdio.h> | ||
35 | #include <X11/Intrinsic.h> | ||
36 | #include <X11/IntrinsicP.h> | ||
37 | #include <X11/CoreP.h> | ||
38 | #include <X11/Shell.h> | ||
39 | #include <X11/StringDefs.h> | ||
40 | #include <X11/Xutil.h> | ||
41 | #include <X11/keysym.h> | ||
42 | |||
43 | #ifdef __sgi | ||
44 | # include <X11/SGIScheme.h> /* for SgiUseSchemes() */ | ||
45 | #endif /* __sgi */ | ||
46 | |||
47 | #ifdef HAVE_XMU | ||
48 | # ifndef VMS | ||
49 | # include <X11/Xmu/Error.h> | ||
50 | # else /* VMS */ | ||
51 | # include <Xmu/Error.h> | ||
52 | # endif | ||
53 | #else | ||
54 | # include "xmu.h" | ||
55 | #endif | ||
56 | #include "screenhack.h" | ||
57 | #include "version.h" | ||
58 | #include "vroot.h" | ||
59 | |||
60 | #ifndef isupper | ||
61 | # define isupper(c) ((c) >= 'A' && (c) <= 'Z') | ||
62 | #endif | ||
63 | #ifndef _tolower | ||
64 | # define _tolower(c) ((c) - 'A' + 'a') | ||
65 | #endif | ||
66 | |||
67 | |||
68 | char *progname; | ||
69 | XrmDatabase db; | ||
70 | XtAppContext app; | ||
71 | Bool mono_p; | ||
72 | |||
73 | static XrmOptionDescRec default_options [] = { | ||
74 | { "-root", ".root", XrmoptionNoArg, "True" }, | ||
75 | { "-window", ".root", XrmoptionNoArg, "False" }, | ||
76 | { "-mono", ".mono", XrmoptionNoArg, "True" }, | ||
77 | { "-install", ".installColormap", XrmoptionNoArg, "True" }, | ||
78 | { "-noinstall",".installColormap", XrmoptionNoArg, "False" }, | ||
79 | { "-visual", ".visualID", XrmoptionSepArg, 0 }, | ||
80 | { "-window-id", ".windowID", XrmoptionSepArg, 0 }, | ||
81 | { 0, 0, 0, 0 } | ||
82 | }; | ||
83 | |||
84 | static char *default_defaults[] = { | ||
85 | ".root: false", | ||
86 | "*geometry: 100x200", /* this should be .geometry, but nooooo... */ | ||
87 | "*mono: false", | ||
88 | "*installColormap: false", | ||
89 | "*visualID: default", | ||
90 | "*windowID: ", | ||
91 | 0 | ||
92 | }; | ||
93 | |||
94 | static XrmOptionDescRec *merged_options; | ||
95 | static int merged_options_size; | ||
96 | static char **merged_defaults; | ||
97 | |||
98 | static void | ||
99 | merge_options (void) | ||
100 | { | ||
101 | int def_opts_size, opts_size; | ||
102 | int def_defaults_size, defaults_size; | ||
103 | |||
104 | for (def_opts_size = 0; default_options[def_opts_size].option; | ||
105 | def_opts_size++) | ||
106 | ; | ||
107 | for (opts_size = 0; options[opts_size].option; opts_size++) | ||
108 | ; | ||
109 | |||
110 | merged_options_size = def_opts_size + opts_size; | ||
111 | merged_options = (XrmOptionDescRec *) | ||
112 | malloc ((merged_options_size + 1) * sizeof(*default_options)); | ||
113 | memcpy (merged_options, default_options, | ||
114 | (def_opts_size * sizeof(*default_options))); | ||
115 | memcpy (merged_options + def_opts_size, options, | ||
116 | ((opts_size + 1) * sizeof(*default_options))); | ||
117 | |||
118 | for (def_defaults_size = 0; default_defaults[def_defaults_size]; | ||
119 | def_defaults_size++) | ||
120 | ; | ||
121 | for (defaults_size = 0; defaults[defaults_size]; defaults_size++) | ||
122 | ; | ||
123 | merged_defaults = (char **) | ||
124 | malloc ((def_defaults_size + defaults_size + 1) * sizeof (*defaults));; | ||
125 | memcpy (merged_defaults, default_defaults, | ||
126 | def_defaults_size * sizeof(*defaults)); | ||
127 | memcpy (merged_defaults + def_defaults_size, defaults, | ||
128 | (defaults_size + 1) * sizeof(*defaults)); | ||
129 | |||
130 | /* This totally sucks. Xt should behave like this by default. | ||
131 | If the string in `defaults' looks like ".foo", change that | ||
132 | to "Progclass.foo". | ||
133 | */ | ||
134 | { | ||
135 | char **s; | ||
136 | for (s = merged_defaults; *s; s++) | ||
137 | if (**s == '.') | ||
138 | { | ||
139 | const char *oldr = *s; | ||
140 | char *newr = (char *) malloc(strlen(oldr) + strlen(progclass) + 3); | ||
141 | strcpy (newr, progclass); | ||
142 | strcat (newr, oldr); | ||
143 | *s = newr; | ||
144 | } | ||
145 | } | ||
146 | } | ||
147 | |||
148 | |||
149 | /* Make the X errors print out the name of this program, so we have some | ||
150 | clue which one has a bug when they die under the screensaver. | ||
151 | */ | ||
152 | |||
153 | static int | ||
154 | screenhack_ehandler (Display *dpy, XErrorEvent *error) | ||
155 | { | ||
156 | fprintf (stderr, "\nX error in %s:\n", progname); | ||
157 | if (XmuPrintDefaultErrorMessage (dpy, error, stderr)) | ||
158 | exit (-1); | ||
159 | else | ||
160 | fprintf (stderr, " (nonfatal.)\n"); | ||
161 | return 0; | ||
162 | } | ||
163 | |||
164 | static Bool | ||
165 | MapNotify_event_p (Display *dpy, XEvent *event, XPointer window) | ||
166 | { | ||
167 | return (event->xany.type == MapNotify && | ||
168 | event->xvisibility.window == (Window) window); | ||
169 | } | ||
170 | |||
171 | |||
172 | #ifdef XLOCKMORE | ||
173 | extern void pre_merge_options (void); | ||
174 | #endif | ||
175 | |||
176 | |||
177 | static Atom XA_WM_PROTOCOLS, XA_WM_DELETE_WINDOW; | ||
178 | |||
179 | /* Dead-trivial event handling: exits if "q" or "ESC" are typed. | ||
180 | Exit if the WM_PROTOCOLS WM_DELETE_WINDOW ClientMessage is received. | ||
181 | */ | ||
182 | void | ||
183 | screenhack_handle_event (Display *dpy, XEvent *event) | ||
184 | { | ||
185 | switch (event->xany.type) | ||
186 | { | ||
187 | case KeyPress: | ||
188 | { | ||
189 | KeySym keysym; | ||
190 | unsigned char c = 0; | ||
191 | XLookupString (&event->xkey, &c, 1, &keysym, 0); | ||
192 | if (c == 'q' || | ||
193 | c == 'Q' || | ||
194 | c == 3 || /* ^C */ | ||
195 | c == 27) /* ESC */ | ||
196 | exit (0); | ||
197 | else if (! (keysym >= XK_Shift_L && keysym <= XK_Hyper_R)) | ||
198 | XBell (dpy, 0); /* beep for non-chord keys */ | ||
199 | |||
200 | fprintf(stderr, "KEY PRESSED: %c (%02x)\n", c, c); | ||
201 | } | ||
202 | break; | ||
203 | case ResizeRequest: | ||
204 | screen_resized(event->xresizerequest.width, event->xresizerequest.height); | ||
205 | screen_redraw(); | ||
206 | fprintf(stderr, "WINDOW RESIZED to width %d height %d\n", | ||
207 | event->xresizerequest.width, event->xresizerequest.height); | ||
208 | break; | ||
209 | default: | ||
210 | fprintf(stderr, "EVENT: %d (see /usr/include/X11/X.h)\n", | ||
211 | event->xany.type); | ||
212 | break; | ||
213 | case Expose: | ||
214 | screen_redraw(); | ||
215 | fprintf(stderr, "EXPOSE: x: %d y: %d width: %d height: %d\n", | ||
216 | event->xexpose.x, event->xexpose.y, | ||
217 | event->xexpose.width, event->xexpose.height); | ||
218 | break; | ||
219 | case ButtonPress: | ||
220 | fprintf(stderr, "BUTTON PRESSED\n"); | ||
221 | break; | ||
222 | case ClientMessage: | ||
223 | { | ||
224 | if (event->xclient.message_type != XA_WM_PROTOCOLS) | ||
225 | { | ||
226 | char *s = XGetAtomName(dpy, event->xclient.message_type); | ||
227 | if (!s) s = "(null)"; | ||
228 | fprintf (stderr, "%s: unknown ClientMessage %s received!\n", | ||
229 | progname, s); | ||
230 | } | ||
231 | else if (event->xclient.data.l[0] != XA_WM_DELETE_WINDOW) | ||
232 | { | ||
233 | char *s1 = XGetAtomName(dpy, event->xclient.message_type); | ||
234 | char *s2 = XGetAtomName(dpy, event->xclient.data.l[0]); | ||
235 | if (!s1) s1 = "(null)"; | ||
236 | if (!s2) s2 = "(null)"; | ||
237 | fprintf (stderr, "%s: unknown ClientMessage %s[%s] received!\n", | ||
238 | progname, s1, s2); | ||
239 | } | ||
240 | else | ||
241 | { | ||
242 | exit (0); | ||
243 | } | ||
244 | } | ||
245 | break; | ||
246 | } | ||
247 | } | ||
248 | |||
249 | |||
250 | void | ||
251 | screenhack_handle_events (Display *dpy) | ||
252 | { | ||
253 | while (XPending (dpy)) | ||
254 | { | ||
255 | XEvent event; | ||
256 | XNextEvent (dpy, &event); | ||
257 | screenhack_handle_event (dpy, &event); | ||
258 | } | ||
259 | } | ||
260 | |||
261 | |||
262 | static Visual * | ||
263 | pick_visual (Screen *screen) | ||
264 | { | ||
265 | #ifdef USE_GL | ||
266 | /* If we're linking against GL (that is, this is the version of screenhack.o | ||
267 | that the GL hacks will use, which is different from the one that the | ||
268 | non-GL hacks will use) then try to pick the "best" visual by interrogating | ||
269 | the GL library instead of by asking Xlib. GL knows better. | ||
270 | */ | ||
271 | Visual *v = 0; | ||
272 | char *string = get_string_resource ("visualID", "VisualID"); | ||
273 | char *s; | ||
274 | |||
275 | if (string) | ||
276 | for (s = string; *s; s++) | ||
277 | if (isupper (*s)) *s = _tolower (*s); | ||
278 | |||
279 | if (!string || !*string || | ||
280 | !strcmp (string, "gl") || | ||
281 | !strcmp (string, "best") || | ||
282 | !strcmp (string, "color") || | ||
283 | !strcmp (string, "default")) | ||
284 | v = get_gl_visual (screen); /* from ../utils/visual-gl.c */ | ||
285 | |||
286 | if (string) | ||
287 | free (string); | ||
288 | if (v) | ||
289 | return v; | ||
290 | #endif /* USE_GL */ | ||
291 | |||
292 | return get_visual_resource (screen, "visualID", "VisualID", False); | ||
293 | } | ||
294 | |||
295 | |||
296 | /* Notice when the user has requested a different visual or colormap | ||
297 | on a pre-existing window (e.g., "-root -visual truecolor" or | ||
298 | "-window-id 0x2c00001 -install") and complain, since when drawing | ||
299 | on an existing window, we have no choice about these things. | ||
300 | */ | ||
301 | static void | ||
302 | visual_warning (Screen *screen, Window window, Visual *visual, Colormap cmap, | ||
303 | Bool window_p) | ||
304 | { | ||
305 | char *visual_string = get_string_resource ("visualID", "VisualID"); | ||
306 | Visual *desired_visual = pick_visual (screen); | ||
307 | char win[100]; | ||
308 | char why[100]; | ||
309 | |||
310 | if (window == RootWindowOfScreen (screen)) | ||
311 | strcpy (win, "root window"); | ||
312 | else | ||
313 | sprintf (win, "window 0x%x", (unsigned long) window); | ||
314 | |||
315 | if (window_p) | ||
316 | sprintf (why, "-window-id 0x%x", (unsigned long) window); | ||
317 | else | ||
318 | strcpy (why, "-root"); | ||
319 | |||
320 | if (visual_string && *visual_string) | ||
321 | { | ||
322 | char *s; | ||
323 | for (s = visual_string; *s; s++) | ||
324 | if (isupper (*s)) *s = _tolower (*s); | ||
325 | |||
326 | if (!strcmp (visual_string, "default") || | ||
327 | !strcmp (visual_string, "default") || | ||
328 | !strcmp (visual_string, "best")) | ||
329 | /* don't warn about these, just silently DWIM. */ | ||
330 | ; | ||
331 | else if (visual != desired_visual) | ||
332 | { | ||
333 | fprintf (stderr, "%s: ignoring `-visual %s' because of `%s'.\n", | ||
334 | progname, visual_string, why); | ||
335 | fprintf (stderr, "%s: using %s's visual 0x%x.\n", | ||
336 | progname, win, XVisualIDFromVisual (visual)); | ||
337 | } | ||
338 | free (visual_string); | ||
339 | } | ||
340 | |||
341 | if (visual == DefaultVisualOfScreen (screen) && | ||
342 | has_writable_cells (screen, visual) && | ||
343 | get_boolean_resource ("installColormap", "InstallColormap")) | ||
344 | { | ||
345 | fprintf (stderr, "%s: ignoring `-install' because of `%s'.\n", | ||
346 | progname, why); | ||
347 | fprintf (stderr, "%s: using %s's colormap 0x%x.\n", | ||
348 | progname, win, (unsigned long) cmap); | ||
349 | } | ||
350 | } | ||
351 | |||
352 | |||
353 | int | ||
354 | main (int argc, char **argv) | ||
355 | { | ||
356 | Widget toplevel; | ||
357 | Display *dpy; | ||
358 | Window window; | ||
359 | Screen *screen; | ||
360 | Visual *visual; | ||
361 | Colormap cmap; | ||
362 | Bool root_p; | ||
363 | Window on_window = 0; | ||
364 | XEvent event; | ||
365 | Boolean dont_clear /*, dont_map */; | ||
366 | char version[255]; | ||
367 | |||
368 | #ifdef XLOCKMORE | ||
369 | pre_merge_options (); | ||
370 | #endif | ||
371 | merge_options (); | ||
372 | |||
373 | #ifdef __sgi | ||
374 | /* We have to do this on SGI to prevent the background color from being | ||
375 | overridden by the current desktop color scheme (we'd like our backgrounds | ||
376 | to be black, thanks.) This should be the same as setting the | ||
377 | "*useSchemes: none" resource, but it's not -- if that resource is | ||
378 | present in the `default_defaults' above, it doesn't work, though it | ||
379 | does work when passed as an -xrm arg on the command line. So screw it, | ||
380 | turn them off from C instead. | ||
381 | */ | ||
382 | SgiUseSchemes ("none"); | ||
383 | #endif /* __sgi */ | ||
384 | |||
385 | toplevel = XtAppInitialize (&app, progclass, merged_options, | ||
386 | merged_options_size, &argc, argv, | ||
387 | merged_defaults, 0, 0); | ||
388 | dpy = XtDisplay (toplevel); | ||
389 | screen = XtScreen (toplevel); | ||
390 | db = XtDatabase (dpy); | ||
391 | |||
392 | XtGetApplicationNameAndClass (dpy, &progname, &progclass); | ||
393 | |||
394 | /* half-assed way of avoiding buffer-overrun attacks. */ | ||
395 | if (strlen (progname) >= 100) progname[100] = 0; | ||
396 | |||
397 | XSetErrorHandler (screenhack_ehandler); | ||
398 | |||
399 | XA_WM_PROTOCOLS = XInternAtom (dpy, "WM_PROTOCOLS", False); | ||
400 | XA_WM_DELETE_WINDOW = XInternAtom (dpy, "WM_DELETE_WINDOW", False); | ||
401 | |||
402 | |||
403 | if (argc > 1) | ||
404 | { | ||
405 | const char *s; | ||
406 | int i; | ||
407 | int x = 18; | ||
408 | int end = 78; | ||
409 | Bool help_p = !strcmp(argv[1], "-help"); | ||
410 | fprintf (stderr, "%s\n", version); | ||
411 | for (s = progclass; *s; s++) fprintf(stderr, " "); | ||
412 | fprintf (stderr, " eXcellent GUI\n\n"); | ||
413 | |||
414 | if (!help_p) | ||
415 | fprintf(stderr, "Unrecognised option: %s\n", argv[1]); | ||
416 | fprintf (stderr, "Options include: "); | ||
417 | for (i = 0; i < merged_options_size; i++) | ||
418 | { | ||
419 | char *sw = merged_options [i].option; | ||
420 | Bool argp = (merged_options [i].argKind == XrmoptionSepArg); | ||
421 | int size = strlen (sw) + (argp ? 6 : 0) + 2; | ||
422 | if (x + size >= end) | ||
423 | { | ||
424 | fprintf (stderr, "\n\t\t "); | ||
425 | x = 18; | ||
426 | } | ||
427 | x += size; | ||
428 | fprintf (stderr, "%s", sw); | ||
429 | if (argp) fprintf (stderr, " <arg>"); | ||
430 | if (i != merged_options_size - 1) fprintf (stderr, ", "); | ||
431 | } | ||
432 | fprintf (stderr, ".\n"); | ||
433 | exit (help_p ? 0 : 1); | ||
434 | } | ||
435 | |||
436 | dont_clear = get_boolean_resource ("dontClearRoot", "Boolean"); | ||
437 | /*dont_map = get_boolean_resource ("dontMapWindow", "Boolean"); */ | ||
438 | mono_p = get_boolean_resource ("mono", "Boolean"); | ||
439 | if (CellsOfScreen (DefaultScreenOfDisplay (dpy)) <= 2) | ||
440 | mono_p = True; | ||
441 | |||
442 | root_p = get_boolean_resource ("root", "Boolean"); | ||
443 | |||
444 | { | ||
445 | char *s = get_string_resource ("windowID", "WindowID"); | ||
446 | if (s && *s) | ||
447 | on_window = get_integer_resource ("windowID", "WindowID"); | ||
448 | if (s) free (s); | ||
449 | } | ||
450 | |||
451 | if (on_window) | ||
452 | { | ||
453 | XWindowAttributes xgwa; | ||
454 | window = (Window) on_window; | ||
455 | XtDestroyWidget (toplevel); | ||
456 | XGetWindowAttributes (dpy, window, &xgwa); | ||
457 | cmap = xgwa.colormap; | ||
458 | visual = xgwa.visual; | ||
459 | visual_warning (screen, window, visual, cmap, True); | ||
460 | } | ||
461 | else if (root_p) | ||
462 | { | ||
463 | XWindowAttributes xgwa; | ||
464 | window = RootWindowOfScreen (XtScreen (toplevel)); | ||
465 | XtDestroyWidget (toplevel); | ||
466 | XGetWindowAttributes (dpy, window, &xgwa); | ||
467 | cmap = xgwa.colormap; | ||
468 | visual = xgwa.visual; | ||
469 | visual_warning (screen, window, visual, cmap, False); | ||
470 | } | ||
471 | else | ||
472 | { | ||
473 | Boolean def_visual_p; | ||
474 | visual = pick_visual (screen); | ||
475 | |||
476 | if (toplevel->core.width <= 0) | ||
477 | toplevel->core.width = 600; | ||
478 | if (toplevel->core.height <= 0) | ||
479 | toplevel->core.height = 480; | ||
480 | |||
481 | def_visual_p = (visual == DefaultVisualOfScreen (screen)); | ||
482 | |||
483 | if (!def_visual_p) | ||
484 | { | ||
485 | unsigned int bg, bd; | ||
486 | Widget new; | ||
487 | |||
488 | cmap = XCreateColormap (dpy, RootWindowOfScreen(screen), | ||
489 | visual, AllocNone); | ||
490 | bg = get_pixel_resource ("background", "Background", dpy, cmap); | ||
491 | bd = get_pixel_resource ("borderColor", "Foreground", dpy, cmap); | ||
492 | |||
493 | new = XtVaAppCreateShell (progname, progclass, | ||
494 | topLevelShellWidgetClass, dpy, | ||
495 | XtNmappedWhenManaged, False, | ||
496 | XtNvisual, visual, | ||
497 | XtNdepth, visual_depth (screen, visual), | ||
498 | XtNwidth, toplevel->core.width, | ||
499 | XtNheight, toplevel->core.height, | ||
500 | XtNcolormap, cmap, | ||
501 | XtNbackground, (Pixel) bg, | ||
502 | XtNborderColor, (Pixel) bd, | ||
503 | XtNinput, True, /* for WM_HINTS */ | ||
504 | 0); | ||
505 | XtDestroyWidget (toplevel); | ||
506 | toplevel = new; | ||
507 | XtRealizeWidget (toplevel); | ||
508 | window = XtWindow (toplevel); | ||
509 | } | ||
510 | else | ||
511 | { | ||
512 | XtVaSetValues (toplevel, | ||
513 | XtNmappedWhenManaged, False, | ||
514 | XtNinput, True, /* for WM_HINTS */ | ||
515 | 0); | ||
516 | XtRealizeWidget (toplevel); | ||
517 | window = XtWindow (toplevel); | ||
518 | |||
519 | if (get_boolean_resource ("installColormap", "InstallColormap")) | ||
520 | { | ||
521 | cmap = XCreateColormap (dpy, window, | ||
522 | DefaultVisualOfScreen (XtScreen (toplevel)), | ||
523 | AllocNone); | ||
524 | XSetWindowColormap (dpy, window, cmap); | ||
525 | } | ||
526 | else | ||
527 | { | ||
528 | cmap = DefaultColormap (dpy, DefaultScreen (dpy)); | ||
529 | } | ||
530 | } | ||
531 | |||
532 | /* | ||
533 | if (dont_map) | ||
534 | { | ||
535 | XtVaSetValues (toplevel, XtNmappedWhenManaged, False, 0); | ||
536 | XtRealizeWidget (toplevel); | ||
537 | } | ||
538 | else | ||
539 | */ | ||
540 | { | ||
541 | XtPopup (toplevel, XtGrabNone); | ||
542 | } | ||
543 | |||
544 | XtVaSetValues(toplevel, XtNtitle, version, 0); | ||
545 | |||
546 | /* For screenhack_handle_events(): select KeyPress, and | ||
547 | announce that we accept WM_DELETE_WINDOW. */ | ||
548 | { | ||
549 | XWindowAttributes xgwa; | ||
550 | XGetWindowAttributes (dpy, window, &xgwa); | ||
551 | XSelectInput (dpy, window, | ||
552 | xgwa.your_event_mask | KeyPressMask | ButtonPressMask | ResizeRedirectMask | ExposureMask); | ||
553 | XChangeProperty (dpy, window, XA_WM_PROTOCOLS, XA_ATOM, 32, | ||
554 | PropModeReplace, | ||
555 | (unsigned char *) &XA_WM_DELETE_WINDOW, 1); | ||
556 | } | ||
557 | } | ||
558 | |||
559 | if (!dont_clear) | ||
560 | { | ||
561 | XSetWindowBackground (dpy, window, | ||
562 | get_pixel_resource ("background", "Background", | ||
563 | dpy, cmap)); | ||
564 | XClearWindow (dpy, window); | ||
565 | } | ||
566 | |||
567 | if (!root_p && !on_window) | ||
568 | /* wait for it to be mapped */ | ||
569 | XIfEvent (dpy, &event, MapNotify_event_p, (XPointer) window); | ||
570 | |||
571 | XSync (dpy, False); | ||
572 | |||
573 | /* This is the one and only place that the random-number generator is | ||
574 | seeded in any screenhack. You do not need to seed the RNG again, | ||
575 | it is done for you before your code is invoked. */ | ||
576 | # undef ya_rand_init | ||
577 | ya_rand_init ((int) time ((time_t *) 0)); | ||
578 | |||
579 | screenhack (dpy, window); /* doesn't return */ | ||
580 | return 0; | ||
581 | } | ||
diff --git a/uisimulator/screenhack.h b/uisimulator/screenhack.h new file mode 100644 index 0000000000..761b244bec --- /dev/null +++ b/uisimulator/screenhack.h | |||
@@ -0,0 +1,102 @@ | |||
1 | /* xscreensaver, Copyright (c) 1992-1997 Jamie Zawinski <jwz@jwz.org> | ||
2 | * | ||
3 | * Permission to use, copy, modify, distribute, and sell this software and its | ||
4 | * documentation for any purpose is hereby granted without fee, provided that | ||
5 | * the above copyright notice appear in all copies and that both that | ||
6 | * copyright notice and this permission notice appear in supporting | ||
7 | * documentation. No representations are made about the suitability of this | ||
8 | * software for any purpose. It is provided "as is" without express or | ||
9 | * implied warranty. | ||
10 | */ | ||
11 | |||
12 | /* Found in Don Hopkins' .plan file: | ||
13 | * | ||
14 | * The color situation is a total flying circus. The X approach to | ||
15 | * device independence is to treat everything like a MicroVax framebuffer | ||
16 | * on acid. A truely portable X application is required to act like the | ||
17 | * persistent customer in the Monty Python ``Cheese Shop'' sketch. Even | ||
18 | * the simplest applications must answer many difficult questions, like: | ||
19 | * | ||
20 | * WHAT IS YOUR DISPLAY? | ||
21 | * display = XOpenDisplay("unix:0"); | ||
22 | * WHAT IS YOUR ROOT? | ||
23 | * root = RootWindow(display, DefaultScreen(display)); | ||
24 | * AND WHAT IS YOUR WINDOW? | ||
25 | * win = XCreateSimpleWindow(display, root, 0, 0, 256, 256, 1, | ||
26 | * BlackPixel(display, DefaultScreen(display)), | ||
27 | * WhitePixel(display, DefaultScreen(display))) | ||
28 | * OH ALL RIGHT, YOU CAN GO ON. | ||
29 | * | ||
30 | * WHAT IS YOUR DISPLAY? | ||
31 | * display = XOpenDisplay("unix:0"); | ||
32 | * WHAT IS YOUR COLORMAP? | ||
33 | * cmap = DefaultColormap(display, DefaultScreen(display)); | ||
34 | * AND WHAT IS YOUR FAVORITE COLOR? | ||
35 | * favorite_color = 0; / * Black. * / | ||
36 | * / * Whoops! No, I mean: * / | ||
37 | * favorite_color = BlackPixel(display, DefaultScreen(display)); | ||
38 | * / * AAAYYYYEEEEE!! (client dumps core & falls into the chasm) * / | ||
39 | * | ||
40 | * WHAT IS YOUR DISPLAY? | ||
41 | * display = XOpenDisplay("unix:0"); | ||
42 | * WHAT IS YOUR VISUAL? | ||
43 | * struct XVisualInfo vinfo; | ||
44 | * if (XMatchVisualInfo(display, DefaultScreen(display), | ||
45 | * 8, PseudoColor, &vinfo) != 0) | ||
46 | * visual = vinfo.visual; | ||
47 | * AND WHAT IS THE NET SPEED VELOCITY OF AN XConfigureWindow REQUEST? | ||
48 | * / * Is that a SubStructureRedirectMask or a ResizeRedirectMask? * / | ||
49 | * WHAT?! HOW AM I SUPPOSED TO KNOW THAT? | ||
50 | * AAAAUUUGGGHHH!!!! (server dumps core & falls into the chasm) | ||
51 | */ | ||
52 | |||
53 | #ifndef __SCREENHACK_H__ | ||
54 | #define __SCREENHACK_H__ | ||
55 | |||
56 | #include <stdlib.h> | ||
57 | |||
58 | #include "config.h" | ||
59 | |||
60 | #ifdef __hpux | ||
61 | /* Which of the ten billion standards does values.h belong to? | ||
62 | What systems always have it? */ | ||
63 | # include <values.h> | ||
64 | #endif | ||
65 | |||
66 | #include <stdio.h> | ||
67 | |||
68 | #include <X11/Xlib.h> | ||
69 | #include <X11/Xresource.h> | ||
70 | #include <X11/Xos.h> | ||
71 | |||
72 | /* M_PI ought to have been defined in math.h, but... */ | ||
73 | #ifndef M_PI | ||
74 | # define M_PI 3.1415926535 | ||
75 | #endif | ||
76 | |||
77 | #ifndef M_PI_2 | ||
78 | # define M_PI_2 1.5707963267 | ||
79 | #endif | ||
80 | |||
81 | #include "yarandom.h" | ||
82 | #include "usleep.h" | ||
83 | #include "resources.h" | ||
84 | #include "hsv.h" | ||
85 | #include "colors.h" | ||
86 | #include "grabscreen.h" | ||
87 | #include "visual.h" | ||
88 | |||
89 | extern Bool mono_p; | ||
90 | extern char *progname; | ||
91 | extern char *progclass; | ||
92 | extern XrmDatabase db; | ||
93 | extern XrmOptionDescRec options []; | ||
94 | extern char *defaults []; | ||
95 | |||
96 | extern void screenhack (Display*,Window); | ||
97 | extern void screenhack_handle_event (Display*, XEvent*); | ||
98 | extern void screenhack_handle_events (Display*); | ||
99 | extern void screen_redraw(); | ||
100 | extern void screen_resized(); | ||
101 | |||
102 | #endif /* __SCREENHACK_H__ */ | ||
diff --git a/uisimulator/sourceheader b/uisimulator/sourceheader new file mode 100644 index 0000000000..df255c5ec8 --- /dev/null +++ b/uisimulator/sourceheader | |||
@@ -0,0 +1,18 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $id:$ | ||
9 | * | ||
10 | * Copyright (C) 2002 by Daniel Stenberg <daniel@haxx.se> | ||
11 | * | ||
12 | * All files in this archive are subject to the GNU General Public License. | ||
13 | * See the file COPYING in the source tree root for full license agreement. | ||
14 | * | ||
15 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
16 | * KIND, either express or implied. | ||
17 | * | ||
18 | ****************************************************************************/ | ||
diff --git a/uisimulator/uibasic.c b/uisimulator/uibasic.c new file mode 100644 index 0000000000..df35fac79c --- /dev/null +++ b/uisimulator/uibasic.c | |||
@@ -0,0 +1,220 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $id:$ | ||
9 | * | ||
10 | * Copyright (C) 2002 by Daniel Stenberg <daniel@haxx.se> | ||
11 | * | ||
12 | * All files in this archive are subject to the GNU General Public License. | ||
13 | * See the file COPYING in the source tree root for full license agreement. | ||
14 | * | ||
15 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
16 | * KIND, either express or implied. | ||
17 | * | ||
18 | ****************************************************************************/ | ||
19 | #include <stdio.h> | ||
20 | #include <string.h> | ||
21 | #include <stdarg.h> | ||
22 | #include <stdlib.h> | ||
23 | #include <ctype.h> | ||
24 | #include <sys/types.h> | ||
25 | #include <sys/stat.h> | ||
26 | #include <fcntl.h> | ||
27 | |||
28 | #include <errno.h> | ||
29 | #include <ctype.h> | ||
30 | #include <time.h> | ||
31 | |||
32 | #include "screenhack.h" | ||
33 | #include "alpha.h" | ||
34 | |||
35 | #include "version.h" | ||
36 | |||
37 | #define MAX(x,y) ((x)>(y)?(x):(y)) | ||
38 | #define MIN(x,y) ((x)<(y)?(x):(y)) | ||
39 | |||
40 | #define PROGNAME "rockboxui" | ||
41 | |||
42 | /* -- -- */ | ||
43 | |||
44 | static GC draw_gc, erase_gc; | ||
45 | static Colormap cmap; | ||
46 | static XColor color_track, color_car; | ||
47 | |||
48 | static long maxx, maxy; | ||
49 | static double track_zoom=1; | ||
50 | |||
51 | Display *dpy; | ||
52 | Window window; | ||
53 | |||
54 | XrmOptionDescRec options [] = { | ||
55 | /* { "-subtractive", ".additive", XrmoptionNoArg, "false" }, */ | ||
56 | { "-server", ".server", XrmoptionSepArg, 0 }, | ||
57 | { "-help", ".help", XrmoptionNoArg, "false" }, | ||
58 | { 0, 0, 0, 0 } | ||
59 | }; | ||
60 | char *progclass = "rockboxui"; | ||
61 | |||
62 | char *defaults [] = { | ||
63 | ".background: black", | ||
64 | ".foreground: white", | ||
65 | "*help: false", | ||
66 | 0 | ||
67 | }; | ||
68 | |||
69 | #define LOGFILE "xgui.log" | ||
70 | void Logf(char *fmt, ...) | ||
71 | { | ||
72 | va_list args; | ||
73 | FILE *log; | ||
74 | struct tm *t; | ||
75 | time_t now=time(NULL); | ||
76 | |||
77 | va_start(args, fmt); | ||
78 | |||
79 | t = localtime(&now); | ||
80 | log = fopen(LOGFILE, "a"); | ||
81 | if(log) { | ||
82 | fprintf(log, "%02d.%02d.%02d ", | ||
83 | t->tm_hour, t->tm_min, t->tm_sec); | ||
84 | vfprintf(log, fmt, args); | ||
85 | fprintf(log, "\n"); | ||
86 | |||
87 | fclose(log); | ||
88 | } | ||
89 | |||
90 | fprintf(stderr, "%02d.%02d.%02d ", | ||
91 | t->tm_hour, t->tm_min, t->tm_sec); | ||
92 | vfprintf(stderr, fmt, args); | ||
93 | fprintf(stderr, "\n"); | ||
94 | va_end(args); | ||
95 | } | ||
96 | |||
97 | void init_window () | ||
98 | { | ||
99 | XGCValues gcv; | ||
100 | XWindowAttributes xgwa; | ||
101 | char *test_p; | ||
102 | |||
103 | XGetWindowAttributes (dpy, window, &xgwa); | ||
104 | |||
105 | color_track.red=65535; | ||
106 | color_track.green=65535; | ||
107 | color_track.blue=65535; | ||
108 | |||
109 | color_car.red=65535; | ||
110 | color_car.green=65535; | ||
111 | color_car.blue=0; | ||
112 | |||
113 | cmap = xgwa.colormap; | ||
114 | |||
115 | gcv.function = GXxor; | ||
116 | gcv.foreground = | ||
117 | get_pixel_resource ("foreground", "Foreground", dpy, cmap); | ||
118 | draw_gc = erase_gc = XCreateGC (dpy, window, GCForeground, &gcv); | ||
119 | XAllocColor (dpy, cmap, &color_track); | ||
120 | XAllocColor (dpy, cmap, &color_car); | ||
121 | |||
122 | screen_resized(200, 100); | ||
123 | } | ||
124 | |||
125 | void screen_resized(int width, int height) | ||
126 | { | ||
127 | #if 0 | ||
128 | XWindowAttributes xgwa; | ||
129 | XGetWindowAttributes (dpy, window, &xgwa); | ||
130 | maxx = ((long)(xgwa.width)); | ||
131 | maxy = ((long)(xgwa.height)); | ||
132 | #else | ||
133 | maxx = width-1; | ||
134 | maxy = height-1; | ||
135 | #endif | ||
136 | XSetForeground (dpy, draw_gc, get_pixel_resource ("background", "Background", | ||
137 | dpy, cmap)); | ||
138 | XFillRectangle(dpy, window, draw_gc, 0, 0, width, height); | ||
139 | |||
140 | } | ||
141 | |||
142 | static void help(void) | ||
143 | { | ||
144 | printf(PROGNAME " " ROCKBOXUI_VERSION " " __DATE__ "\n" | ||
145 | "usage: " PROGNAME "\n" | ||
146 | ); | ||
147 | } | ||
148 | |||
149 | void drawline(int color, int x1, int y1, int x2, int y2) | ||
150 | { | ||
151 | if (color==0) { | ||
152 | XSetForeground(dpy, draw_gc, | ||
153 | get_pixel_resource("background", "Background", dpy, cmap)); | ||
154 | } | ||
155 | else | ||
156 | XSetForeground(dpy, draw_gc, | ||
157 | get_pixel_resource("foreground", "Foreground", dpy, cmap)); | ||
158 | |||
159 | XDrawLine(dpy, window, draw_gc, | ||
160 | (int)(x1*track_zoom), | ||
161 | (int)(y1*track_zoom), | ||
162 | (int)(x2*track_zoom), | ||
163 | (int)(y2*track_zoom)); | ||
164 | } | ||
165 | |||
166 | void drawtext(int color, int x, int y, char *text) | ||
167 | { | ||
168 | if (color==0) { | ||
169 | XSetForeground(dpy, draw_gc, | ||
170 | get_pixel_resource("background", "Background", dpy, cmap)); | ||
171 | } | ||
172 | else | ||
173 | XSetForeground(dpy, draw_gc, | ||
174 | get_pixel_resource("foreground", "Foreground", dpy, cmap)); | ||
175 | |||
176 | XDrawString(dpy, window, draw_gc, x, y, text, strlen(text)); | ||
177 | } | ||
178 | |||
179 | |||
180 | void | ||
181 | screenhack (Display *the_dpy, Window the_window) | ||
182 | { | ||
183 | unsigned short porttouse=0; | ||
184 | char *proxy = NULL; | ||
185 | char *url = NULL; | ||
186 | int i; | ||
187 | char *guiname="Rock-the-box"; | ||
188 | Bool helpme; | ||
189 | |||
190 | /* This doesn't work, but I don't know why (Daniel 1999-12-01) */ | ||
191 | helpme = get_boolean_resource ("help", "Boolean"); | ||
192 | if(helpme) { | ||
193 | help(); | ||
194 | } | ||
195 | printf(PROGNAME " " ROCKBOXUI_VERSION " (" __DATE__ ")\n"); | ||
196 | |||
197 | dpy=the_dpy; | ||
198 | window=the_window; | ||
199 | |||
200 | init_window(); | ||
201 | |||
202 | drawtext(1, 20, 20, PROGNAME); | ||
203 | drawline(1, 0, 0, 40, 50); | ||
204 | |||
205 | Logf("Rockbox will kill ya!"); | ||
206 | |||
207 | while (1) { | ||
208 | /* deal with input here */ | ||
209 | |||
210 | XSync (dpy, False); | ||
211 | screenhack_handle_events (dpy); | ||
212 | } | ||
213 | } | ||
214 | |||
215 | void screen_redraw() | ||
216 | { | ||
217 | /* does nothing yet */ | ||
218 | drawtext(1, 20, 20, PROGNAME); | ||
219 | drawline(1, 0, 0, 40, 50); | ||
220 | } | ||
diff --git a/uisimulator/usleep.c b/uisimulator/usleep.c new file mode 100644 index 0000000000..706675910e --- /dev/null +++ b/uisimulator/usleep.c | |||
@@ -0,0 +1,58 @@ | |||
1 | /* xscreensaver, Copyright (c) 1992, 1996, 1997 | ||
2 | * Jamie Zawinski <jwz@jwz.org> | ||
3 | * | ||
4 | * Permission to use, copy, modify, distribute, and sell this software and its | ||
5 | * documentation for any purpose is hereby granted without fee, provided that | ||
6 | * the above copyright notice appear in all copies and that both that | ||
7 | * copyright notice and this permission notice appear in supporting | ||
8 | * documentation. No representations are made about the suitability of this | ||
9 | * software for any purpose. It is provided "as is" without express or | ||
10 | * implied warranty. | ||
11 | */ | ||
12 | |||
13 | #ifdef HAVE_CONFIG_H | ||
14 | # include "config.h" | ||
15 | #else /* !HAVE_CONFIG_H */ | ||
16 | # ifndef NO_SELECT | ||
17 | # define HAVE_SELECT | ||
18 | # endif | ||
19 | #endif /* !HAVE_CONFIG_H */ | ||
20 | |||
21 | #ifdef __STDC__ | ||
22 | # include <stdlib.h> | ||
23 | #endif | ||
24 | |||
25 | #if defined(VMS) | ||
26 | # include <descrip.h> | ||
27 | # include <stdio.h> | ||
28 | # include <lib$routines.h> | ||
29 | #elif defined(HAVE_SELECT) | ||
30 | # include <sys/time.h> /* for struct timeval */ | ||
31 | #endif | ||
32 | |||
33 | |||
34 | #ifdef __SCREENHACK_USLEEP_H__ | ||
35 | ERROR, do not include that here | ||
36 | #endif | ||
37 | |||
38 | void | ||
39 | screenhack_usleep (unsigned long usecs) | ||
40 | { | ||
41 | # if defined(VMS) | ||
42 | float seconds = ((float) usecs)/1000000.0; | ||
43 | unsigned long int statvms = lib$wait(&seconds); | ||
44 | |||
45 | #elif defined(HAVE_SELECT) | ||
46 | /* usleep() doesn't exist everywhere, and select() is faster anyway. */ | ||
47 | struct timeval tv; | ||
48 | tv.tv_sec = usecs / 1000000L; | ||
49 | tv.tv_usec = usecs % 1000000L; | ||
50 | (void) select (0, 0, 0, 0, &tv); | ||
51 | |||
52 | #else /* !VMS && !HAVE_SELECT */ | ||
53 | /* If you don't have select() or usleep(), I guess you lose... | ||
54 | Maybe you have napms() instead? Let me know. */ | ||
55 | usleep (usecs); | ||
56 | |||
57 | #endif /* !VMS && !HAVE_SELECT */ | ||
58 | } | ||
diff --git a/uisimulator/usleep.h b/uisimulator/usleep.h new file mode 100644 index 0000000000..c40363ef4a --- /dev/null +++ b/uisimulator/usleep.h | |||
@@ -0,0 +1,20 @@ | |||
1 | /* xscreensaver, Copyright (c) 1992, 1996 Jamie Zawinski <jwz@jwz.org> | ||
2 | * | ||
3 | * Permission to use, copy, modify, distribute, and sell this software and its | ||
4 | * documentation for any purpose is hereby granted without fee, provided that | ||
5 | * the above copyright notice appear in all copies and that both that | ||
6 | * copyright notice and this permission notice appear in supporting | ||
7 | * documentation. No representations are made about the suitability of this | ||
8 | * software for any purpose. It is provided "as is" without express or | ||
9 | * implied warranty. | ||
10 | */ | ||
11 | |||
12 | #ifndef __SCREENHACK_USLEEP_H__ | ||
13 | #define __SCREENHACK_USLEEP_H__ | ||
14 | |||
15 | extern void screenhack_usleep (unsigned long usecs); | ||
16 | |||
17 | #undef usleep | ||
18 | #define usleep(usecs) screenhack_usleep(usecs) | ||
19 | |||
20 | #endif /* __SCREENHACK_USLEEP_H__ */ | ||
diff --git a/uisimulator/utils.h b/uisimulator/utils.h new file mode 100644 index 0000000000..284bb86dcd --- /dev/null +++ b/uisimulator/utils.h | |||
@@ -0,0 +1,22 @@ | |||
1 | /* xscreensaver, Copyright (c) 1997 Jamie Zawinski <jwz@jwz.org> | ||
2 | * | ||
3 | * Permission to use, copy, modify, distribute, and sell this software and its | ||
4 | * documentation for any purpose is hereby granted without fee, provided that | ||
5 | * the above copyright notice appear in all copies and that both that | ||
6 | * copyright notice and this permission notice appear in supporting | ||
7 | * documentation. No representations are made about the suitability of this | ||
8 | * software for any purpose. It is provided "as is" without express or | ||
9 | * implied warranty. | ||
10 | */ | ||
11 | |||
12 | #ifdef HAVE_CONFIG_H | ||
13 | # include "config.h" | ||
14 | #endif | ||
15 | |||
16 | #include <stdlib.h> | ||
17 | #include <stdio.h> | ||
18 | #include <string.h> | ||
19 | #include <math.h> | ||
20 | |||
21 | #include <X11/Xlib.h> | ||
22 | #include <X11/Xos.h> | ||
diff --git a/uisimulator/version.h b/uisimulator/version.h new file mode 100644 index 0000000000..e9e70b675b --- /dev/null +++ b/uisimulator/version.h | |||
@@ -0,0 +1 @@ | |||
#define ROCKBOXUI_VERSION "0.1" | |||
diff --git a/uisimulator/visual.c b/uisimulator/visual.c new file mode 100644 index 0000000000..57b73151c5 --- /dev/null +++ b/uisimulator/visual.c | |||
@@ -0,0 +1,544 @@ | |||
1 | /* xscreensaver, Copyright (c) 1993, 1994, 1995, 1996, 1997, 1998, 1999 | ||
2 | * by Jamie Zawinski <jwz@jwz.org> | ||
3 | * | ||
4 | * Permission to use, copy, modify, distribute, and sell this software and its | ||
5 | * documentation for any purpose is hereby granted without fee, provided that | ||
6 | * the above copyright notice appear in all copies and that both that | ||
7 | * copyright notice and this permission notice appear in supporting | ||
8 | * documentation. No representations are made about the suitability of this | ||
9 | * software for any purpose. It is provided "as is" without express or | ||
10 | * implied warranty. | ||
11 | */ | ||
12 | |||
13 | /* This file contains some code for intelligently picking the best visual | ||
14 | (where "best" is biased in the direction of either: high color counts; | ||
15 | or: having writable color cells...) | ||
16 | */ | ||
17 | |||
18 | #include "utils.h" | ||
19 | #include "resources.h" /* for get_string_resource() */ | ||
20 | #include "visual.h" | ||
21 | |||
22 | #include <X11/Xutil.h> | ||
23 | |||
24 | extern char *progname; | ||
25 | |||
26 | |||
27 | #ifndef isupper | ||
28 | # define isupper(c) ((c) >= 'A' && (c) <= 'Z') | ||
29 | #endif | ||
30 | #ifndef _tolower | ||
31 | # define _tolower(c) ((c) - 'A' + 'a') | ||
32 | #endif | ||
33 | |||
34 | |||
35 | static Visual *pick_best_visual (Screen *, Bool, Bool); | ||
36 | static Visual *pick_mono_visual (Screen *); | ||
37 | static Visual *pick_best_visual_of_class (Screen *, int); | ||
38 | static Visual *pick_best_gl_visual (Screen *); | ||
39 | static Visual *id_to_visual (Screen *, int); | ||
40 | static Visual *id_to_visual (Screen *screen, int id); | ||
41 | |||
42 | |||
43 | #define DEFAULT_VISUAL -1 | ||
44 | #define BEST_VISUAL -2 | ||
45 | #define MONO_VISUAL -3 | ||
46 | #define GRAY_VISUAL -4 | ||
47 | #define COLOR_VISUAL -5 | ||
48 | #define GL_VISUAL -6 | ||
49 | #define SPECIFIC_VISUAL -7 | ||
50 | |||
51 | Visual * | ||
52 | get_visual (Screen *screen, const char *string, Bool prefer_writable_cells, | ||
53 | Bool verbose_p) | ||
54 | { | ||
55 | char *v = (string ? strdup(string) : 0); | ||
56 | char c, *tmp; | ||
57 | int vclass; | ||
58 | unsigned long id; | ||
59 | Visual *result = 0; | ||
60 | |||
61 | if (v) | ||
62 | for (tmp = v; *tmp; tmp++) | ||
63 | if (isupper (*tmp)) *tmp = _tolower (*tmp); | ||
64 | |||
65 | if (!v || !*v) vclass = BEST_VISUAL; | ||
66 | else if (!strcmp (v, "default")) vclass = DEFAULT_VISUAL; | ||
67 | else if (!strcmp (v, "best")) vclass = BEST_VISUAL; | ||
68 | else if (!strcmp (v, "mono")) vclass = MONO_VISUAL; | ||
69 | else if (!strcmp (v, "monochrome")) vclass = MONO_VISUAL; | ||
70 | else if (!strcmp (v, "gray")) vclass = GRAY_VISUAL; | ||
71 | else if (!strcmp (v, "grey")) vclass = GRAY_VISUAL; | ||
72 | else if (!strcmp (v, "color")) vclass = COLOR_VISUAL; | ||
73 | else if (!strcmp (v, "gl")) vclass = GL_VISUAL; | ||
74 | else if (!strcmp (v, "staticgray")) vclass = StaticGray; | ||
75 | else if (!strcmp (v, "staticcolor")) vclass = StaticColor; | ||
76 | else if (!strcmp (v, "truecolor")) vclass = TrueColor; | ||
77 | else if (!strcmp (v, "grayscale")) vclass = GrayScale; | ||
78 | else if (!strcmp (v, "greyscale")) vclass = GrayScale; | ||
79 | else if (!strcmp (v, "pseudocolor")) vclass = PseudoColor; | ||
80 | else if (!strcmp (v, "directcolor")) vclass = DirectColor; | ||
81 | else if (1 == sscanf (v, " %ld %c", &id, &c)) vclass = SPECIFIC_VISUAL; | ||
82 | else if (1 == sscanf (v, " 0x%lx %c", &id, &c)) vclass = SPECIFIC_VISUAL; | ||
83 | else | ||
84 | { | ||
85 | fprintf (stderr, "%s: unrecognized visual \"%s\".\n", progname, v); | ||
86 | vclass = DEFAULT_VISUAL; | ||
87 | } | ||
88 | |||
89 | if (vclass == DEFAULT_VISUAL) | ||
90 | result = DefaultVisualOfScreen (screen); | ||
91 | else if (vclass == BEST_VISUAL) | ||
92 | result = pick_best_visual (screen, prefer_writable_cells, False); | ||
93 | else if (vclass == MONO_VISUAL) | ||
94 | { | ||
95 | result = pick_mono_visual (screen); | ||
96 | if (!result && verbose_p) | ||
97 | fprintf (stderr, "%s: no monochrome visuals.\n", progname); | ||
98 | } | ||
99 | else if (vclass == GRAY_VISUAL) | ||
100 | { | ||
101 | if (prefer_writable_cells) | ||
102 | result = pick_best_visual_of_class (screen, GrayScale); | ||
103 | if (!result) | ||
104 | result = pick_best_visual_of_class (screen, StaticGray); | ||
105 | if (!result) | ||
106 | result = pick_best_visual_of_class (screen, GrayScale); | ||
107 | if (!result && verbose_p) | ||
108 | fprintf (stderr, "%s: no GrayScale or StaticGray visuals.\n", | ||
109 | progname); | ||
110 | } | ||
111 | else if (vclass == COLOR_VISUAL) | ||
112 | { | ||
113 | int class; | ||
114 | /* First see if the default visual will do. */ | ||
115 | result = DefaultVisualOfScreen (screen); | ||
116 | class = visual_class(screen, result); | ||
117 | if (class != TrueColor && | ||
118 | class != PseudoColor && | ||
119 | class != DirectColor && | ||
120 | class != StaticColor) | ||
121 | result = 0; | ||
122 | if (result && visual_depth(screen, result) <= 1) | ||
123 | result = 0; | ||
124 | |||
125 | /* Else, find the best non-default color visual */ | ||
126 | if (!result) | ||
127 | result = pick_best_visual (screen, prefer_writable_cells, True); | ||
128 | |||
129 | if (!result && verbose_p) | ||
130 | fprintf (stderr, "%s: no color visuals.\n", progname); | ||
131 | } | ||
132 | else if (vclass == GL_VISUAL) | ||
133 | { | ||
134 | Visual *visual = pick_best_gl_visual (screen); | ||
135 | if (visual) | ||
136 | result = visual; | ||
137 | else if (verbose_p) | ||
138 | fprintf (stderr, "%s: no visual suitable for GL.\n", progname); | ||
139 | } | ||
140 | else if (vclass == SPECIFIC_VISUAL) | ||
141 | { | ||
142 | result = id_to_visual (screen, id); | ||
143 | if (!result && verbose_p) | ||
144 | fprintf (stderr, "%s: no visual with id 0x%x.\n", progname, | ||
145 | (unsigned int) id); | ||
146 | } | ||
147 | else | ||
148 | { | ||
149 | Visual *visual = pick_best_visual_of_class (screen, vclass); | ||
150 | if (visual) | ||
151 | result = visual; | ||
152 | else if (verbose_p) | ||
153 | fprintf (stderr, "%s: no visual of class %s.\n", progname, v); | ||
154 | } | ||
155 | |||
156 | if (v) free (v); | ||
157 | return result; | ||
158 | } | ||
159 | |||
160 | Visual * | ||
161 | get_visual_resource (Screen *screen, char *name, char *class, | ||
162 | Bool prefer_writable_cells) | ||
163 | { | ||
164 | char *string = get_string_resource (name, class); | ||
165 | Visual *v = get_visual (screen, string, prefer_writable_cells, True); | ||
166 | if (string) | ||
167 | free(string); | ||
168 | if (v) | ||
169 | return v; | ||
170 | else | ||
171 | return DefaultVisualOfScreen (screen); | ||
172 | } | ||
173 | |||
174 | |||
175 | static Visual * | ||
176 | pick_best_visual (Screen *screen, Bool prefer_writable_cells, Bool color_only) | ||
177 | { | ||
178 | Visual *visual; | ||
179 | |||
180 | if (!prefer_writable_cells) | ||
181 | { | ||
182 | /* If we don't prefer writable cells, then the "best" visual is the one | ||
183 | on which we can allocate the largest range and number of colors. | ||
184 | |||
185 | Therefore, a TrueColor visual which is at least 16 bits deep is best. | ||
186 | (The assumption here being that a TrueColor of less than 16 bits is | ||
187 | really just a PseudoColor visual with a pre-allocated color cube.) | ||
188 | |||
189 | The next best thing is a PseudoColor visual of any type. After that | ||
190 | come the non-colormappable visuals, and non-color visuals. | ||
191 | */ | ||
192 | if ((visual = pick_best_visual_of_class (screen, TrueColor)) && | ||
193 | visual_depth (screen, visual) >= 16) | ||
194 | return visual; | ||
195 | } | ||
196 | |||
197 | #define TRY_CLASS(CLASS) \ | ||
198 | if ((visual = pick_best_visual_of_class (screen, CLASS)) && \ | ||
199 | (!color_only || visual_depth(screen, visual) > 1)) \ | ||
200 | return visual | ||
201 | TRY_CLASS(PseudoColor); | ||
202 | TRY_CLASS(TrueColor); | ||
203 | TRY_CLASS(DirectColor); | ||
204 | TRY_CLASS(StaticColor); | ||
205 | if (!color_only) | ||
206 | { | ||
207 | TRY_CLASS(GrayScale); | ||
208 | TRY_CLASS(StaticGray); | ||
209 | } | ||
210 | #undef TRY_CLASS | ||
211 | |||
212 | visual = DefaultVisualOfScreen (screen); | ||
213 | if (!color_only || visual_depth(screen, visual) > 1) | ||
214 | return visual; | ||
215 | else | ||
216 | return 0; | ||
217 | } | ||
218 | |||
219 | static Visual * | ||
220 | pick_mono_visual (Screen *screen) | ||
221 | { | ||
222 | Display *dpy = DisplayOfScreen (screen); | ||
223 | XVisualInfo vi_in, *vi_out; | ||
224 | int out_count; | ||
225 | |||
226 | vi_in.depth = 1; | ||
227 | vi_in.screen = screen_number (screen); | ||
228 | vi_out = XGetVisualInfo (dpy, (VisualDepthMask | VisualScreenMask), | ||
229 | &vi_in, &out_count); | ||
230 | if (vi_out) | ||
231 | { | ||
232 | Visual *v = (out_count > 0 ? vi_out [0].visual : 0); | ||
233 | if (v && vi_out[0].depth != 1) | ||
234 | v = 0; | ||
235 | XFree ((char *) vi_out); | ||
236 | return v; | ||
237 | } | ||
238 | else | ||
239 | return 0; | ||
240 | } | ||
241 | |||
242 | |||
243 | static Visual * | ||
244 | pick_best_visual_of_class (Screen *screen, int visual_class) | ||
245 | { | ||
246 | /* The best visual of a class is the one which on which we can allocate | ||
247 | the largest range and number of colors, which means the one with the | ||
248 | greatest depth and number of cells. | ||
249 | |||
250 | (But actually, for XDaliClock, all visuals of the same class are | ||
251 | probably equivalent - either we have writable cells or we don't.) | ||
252 | */ | ||
253 | Display *dpy = DisplayOfScreen (screen); | ||
254 | XVisualInfo vi_in, *vi_out; | ||
255 | int out_count; | ||
256 | |||
257 | vi_in.class = visual_class; | ||
258 | vi_in.screen = screen_number (screen); | ||
259 | vi_out = XGetVisualInfo (dpy, (VisualClassMask | VisualScreenMask), | ||
260 | &vi_in, &out_count); | ||
261 | if (vi_out) | ||
262 | { | ||
263 | /* choose the 'best' one, if multiple */ | ||
264 | int i, best; | ||
265 | Visual *visual; | ||
266 | /* for (i = 0, best = 0; i < out_count; i++) */ | ||
267 | for (i = out_count-1, best = i; i >= 0; i--) /* go backwards */ | ||
268 | /* It's better if it's deeper, or if it's the same depth with | ||
269 | more cells (does that ever happen? Well, it could...) */ | ||
270 | if ((vi_out [i].depth > vi_out [best].depth) || | ||
271 | ((vi_out [i].depth == vi_out [best].depth) && | ||
272 | (vi_out [i].colormap_size > vi_out [best].colormap_size))) | ||
273 | best = i; | ||
274 | visual = (best < out_count ? vi_out [best].visual : 0); | ||
275 | XFree ((char *) vi_out); | ||
276 | return visual; | ||
277 | } | ||
278 | else | ||
279 | return 0; | ||
280 | } | ||
281 | |||
282 | static Visual * | ||
283 | pick_best_gl_visual (Screen *screen) | ||
284 | { | ||
285 | /* The best visual for GL is a TrueColor visual that is half as deep as | ||
286 | the screen. If such a thing doesn't exist, then TrueColor is best. | ||
287 | Failing that, the deepest available color visual is best. | ||
288 | |||
289 | Compare this function to get_gl_visual() in visual-gl.c. | ||
290 | This function tries to find the best GL visual using Xlib calls, | ||
291 | whereas that function does the same thing using GLX calls. | ||
292 | */ | ||
293 | Display *dpy = DisplayOfScreen (screen); | ||
294 | XVisualInfo vi_in, *vi_out; | ||
295 | int out_count; | ||
296 | Visual *result = 0; | ||
297 | |||
298 | int ndepths = 0; | ||
299 | int *depths = XListDepths (dpy, screen_number (screen), &ndepths); | ||
300 | int screen_depth = depths[ndepths]; | ||
301 | XFree (depths); | ||
302 | |||
303 | vi_in.class = TrueColor; | ||
304 | vi_in.screen = screen_number (screen); | ||
305 | vi_in.depth = screen_depth / 2; | ||
306 | vi_out = XGetVisualInfo (dpy, (VisualClassMask | VisualScreenMask | | ||
307 | VisualDepthMask), | ||
308 | &vi_in, &out_count); | ||
309 | if (out_count > 0) | ||
310 | result = vi_out[0].visual; | ||
311 | |||
312 | if (vi_out) | ||
313 | XFree ((char *) vi_out); | ||
314 | |||
315 | if (!result && screen_depth > 24) | ||
316 | { | ||
317 | /* If it's a 32-deep screen and we didn't find a depth-16 visual, | ||
318 | see if there's a depth-12 visual. */ | ||
319 | vi_in.class = TrueColor; | ||
320 | vi_in.screen = screen_number (screen); | ||
321 | vi_in.depth = 12; | ||
322 | vi_out = XGetVisualInfo (dpy, (VisualClassMask | VisualScreenMask | | ||
323 | VisualDepthMask), | ||
324 | &vi_in, &out_count); | ||
325 | if (out_count > 0) | ||
326 | result = vi_out[0].visual; | ||
327 | } | ||
328 | |||
329 | if (!result) | ||
330 | /* No half-depth TrueColor? Ok, try for any TrueColor (the deepest.) */ | ||
331 | result = pick_best_visual_of_class (screen, TrueColor); | ||
332 | |||
333 | if (!result) | ||
334 | /* No TrueColor? Ok, try for anything. */ | ||
335 | result = pick_best_visual (screen, False, False); | ||
336 | |||
337 | return result; | ||
338 | } | ||
339 | |||
340 | |||
341 | static Visual * | ||
342 | id_to_visual (Screen *screen, int id) | ||
343 | { | ||
344 | Display *dpy = DisplayOfScreen (screen); | ||
345 | XVisualInfo vi_in, *vi_out; | ||
346 | int out_count; | ||
347 | vi_in.screen = screen_number (screen); | ||
348 | vi_in.visualid = id; | ||
349 | vi_out = XGetVisualInfo (dpy, (VisualScreenMask | VisualIDMask), | ||
350 | &vi_in, &out_count); | ||
351 | if (vi_out) | ||
352 | { | ||
353 | Visual *v = vi_out[0].visual; | ||
354 | XFree ((char *) vi_out); | ||
355 | return v; | ||
356 | } | ||
357 | return 0; | ||
358 | } | ||
359 | |||
360 | int | ||
361 | visual_depth (Screen *screen, Visual *visual) | ||
362 | { | ||
363 | Display *dpy = DisplayOfScreen (screen); | ||
364 | XVisualInfo vi_in, *vi_out; | ||
365 | int out_count, d; | ||
366 | vi_in.screen = screen_number (screen); | ||
367 | vi_in.visualid = XVisualIDFromVisual (visual); | ||
368 | vi_out = XGetVisualInfo (dpy, VisualScreenMask|VisualIDMask, | ||
369 | &vi_in, &out_count); | ||
370 | if (! vi_out) abort (); | ||
371 | d = vi_out [0].depth; | ||
372 | XFree ((char *) vi_out); | ||
373 | return d; | ||
374 | } | ||
375 | |||
376 | |||
377 | #if 0 | ||
378 | /* You very probably don't want to be using this. | ||
379 | Pixmap depth doesn't refer to the depths of pixmaps, but rather, to | ||
380 | the depth of protocol-level on-the-wire pixmap data, that is, XImages. | ||
381 | To get this info, you should be looking at XImage->bits_per_pixel | ||
382 | instead. (And allocating the data for your XImage structures by | ||
383 | multiplying ximage->bytes_per_line by ximage->height.) | ||
384 | */ | ||
385 | int | ||
386 | visual_pixmap_depth (Screen *screen, Visual *visual) | ||
387 | { | ||
388 | Display *dpy = DisplayOfScreen (screen); | ||
389 | int vdepth = visual_depth (screen, visual); | ||
390 | int pdepth = vdepth; | ||
391 | int i, pfvc = 0; | ||
392 | XPixmapFormatValues *pfv = XListPixmapFormats (dpy, &pfvc); | ||
393 | |||
394 | /* Return the first matching depth in the pixmap formats. If there are no | ||
395 | matching pixmap formats (which shouldn't be able to happen at all) then | ||
396 | return the visual depth instead. */ | ||
397 | for (i = 0; i < pfvc; i++) | ||
398 | if (pfv[i].depth == vdepth) | ||
399 | { | ||
400 | pdepth = pfv[i].bits_per_pixel; | ||
401 | break; | ||
402 | } | ||
403 | if (pfv) | ||
404 | XFree (pfv); | ||
405 | return pdepth; | ||
406 | } | ||
407 | #endif /* 0 */ | ||
408 | |||
409 | |||
410 | int | ||
411 | visual_class (Screen *screen, Visual *visual) | ||
412 | { | ||
413 | Display *dpy = DisplayOfScreen (screen); | ||
414 | XVisualInfo vi_in, *vi_out; | ||
415 | int out_count, c; | ||
416 | vi_in.screen = screen_number (screen); | ||
417 | vi_in.visualid = XVisualIDFromVisual (visual); | ||
418 | vi_out = XGetVisualInfo (dpy, VisualScreenMask|VisualIDMask, | ||
419 | &vi_in, &out_count); | ||
420 | if (! vi_out) abort (); | ||
421 | c = vi_out [0].class; | ||
422 | XFree ((char *) vi_out); | ||
423 | return c; | ||
424 | } | ||
425 | |||
426 | Bool | ||
427 | has_writable_cells (Screen *screen, Visual *visual) | ||
428 | { | ||
429 | switch (visual_class (screen, visual)) | ||
430 | { | ||
431 | case GrayScale: /* Mappable grays. */ | ||
432 | case PseudoColor: /* Mappable colors. */ | ||
433 | return True; | ||
434 | case StaticGray: /* Fixed grays. */ | ||
435 | case TrueColor: /* Fixed colors. */ | ||
436 | case StaticColor: /* (What's the difference again?) */ | ||
437 | case DirectColor: /* DirectColor visuals are like TrueColor, but have | ||
438 | three colormaps - one for each component of RGB. | ||
439 | Screw it. */ | ||
440 | return False; | ||
441 | default: | ||
442 | abort(); | ||
443 | return False; | ||
444 | } | ||
445 | } | ||
446 | |||
447 | void | ||
448 | describe_visual (FILE *f, Screen *screen, Visual *visual, Bool private_cmap_p) | ||
449 | { | ||
450 | char n[10]; | ||
451 | Display *dpy = DisplayOfScreen (screen); | ||
452 | XVisualInfo vi_in, *vi_out; | ||
453 | int out_count; | ||
454 | vi_in.screen = screen_number (screen); | ||
455 | vi_in.visualid = XVisualIDFromVisual (visual); | ||
456 | vi_out = XGetVisualInfo (dpy, (VisualScreenMask | VisualIDMask), | ||
457 | &vi_in, &out_count); | ||
458 | if (! vi_out) abort (); | ||
459 | if (private_cmap_p) | ||
460 | sprintf(n, "%3d", vi_out->colormap_size); | ||
461 | else | ||
462 | strcpy(n, "default"); | ||
463 | |||
464 | fprintf (f, "0x%02x (%s depth: %2d, cmap: %s)\n", | ||
465 | (unsigned int) vi_out->visualid, | ||
466 | (vi_out->class == StaticGray ? "StaticGray, " : | ||
467 | vi_out->class == StaticColor ? "StaticColor," : | ||
468 | vi_out->class == TrueColor ? "TrueColor, " : | ||
469 | vi_out->class == GrayScale ? "GrayScale, " : | ||
470 | vi_out->class == PseudoColor ? "PseudoColor," : | ||
471 | vi_out->class == DirectColor ? "DirectColor," : | ||
472 | "UNKNOWN: "), | ||
473 | vi_out->depth, n); | ||
474 | XFree ((char *) vi_out); | ||
475 | } | ||
476 | |||
477 | int | ||
478 | screen_number (Screen *screen) | ||
479 | { | ||
480 | Display *dpy = DisplayOfScreen (screen); | ||
481 | int i; | ||
482 | for (i = 0; i < ScreenCount (dpy); i++) | ||
483 | if (ScreenOfDisplay (dpy, i) == screen) | ||
484 | return i; | ||
485 | abort (); | ||
486 | return 0; | ||
487 | } | ||
488 | |||
489 | int | ||
490 | visual_cells (Screen *screen, Visual *visual) | ||
491 | { | ||
492 | Display *dpy = DisplayOfScreen (screen); | ||
493 | XVisualInfo vi_in, *vi_out; | ||
494 | int out_count, c; | ||
495 | vi_in.screen = screen_number (screen); | ||
496 | vi_in.visualid = XVisualIDFromVisual (visual); | ||
497 | vi_out = XGetVisualInfo (dpy, VisualScreenMask|VisualIDMask, | ||
498 | &vi_in, &out_count); | ||
499 | if (! vi_out) abort (); | ||
500 | c = vi_out [0].colormap_size; | ||
501 | XFree ((char *) vi_out); | ||
502 | return c; | ||
503 | } | ||
504 | |||
505 | Visual * | ||
506 | find_similar_visual(Screen *screen, Visual *old_visual) | ||
507 | { | ||
508 | Display *dpy = DisplayOfScreen (screen); | ||
509 | XVisualInfo vi_in, *vi_out; | ||
510 | Visual *result = 0; | ||
511 | int out_count; | ||
512 | |||
513 | vi_in.screen = screen_number (screen); | ||
514 | vi_in.class = visual_class (screen, old_visual); | ||
515 | vi_in.depth = visual_depth (screen, old_visual); | ||
516 | |||
517 | /* Look for a visual of the same class and depth. | ||
518 | */ | ||
519 | vi_out = XGetVisualInfo (dpy, (VisualScreenMask | VisualClassMask | | ||
520 | VisualDepthMask), | ||
521 | &vi_in, &out_count); | ||
522 | if (vi_out && out_count > 0) | ||
523 | result = vi_out[0].visual; | ||
524 | if (vi_out) XFree (vi_out); | ||
525 | vi_out = 0; | ||
526 | |||
527 | /* Failing that, look for a visual of the same class. | ||
528 | */ | ||
529 | if (!result) | ||
530 | { | ||
531 | vi_out = XGetVisualInfo (dpy, (VisualScreenMask | VisualClassMask), | ||
532 | &vi_in, &out_count); | ||
533 | if (vi_out && out_count > 0) | ||
534 | result = vi_out[0].visual; | ||
535 | if (vi_out) XFree (vi_out); | ||
536 | vi_out = 0; | ||
537 | } | ||
538 | |||
539 | /* Failing that, return the default visual. */ | ||
540 | if (!result) | ||
541 | result = DefaultVisualOfScreen (screen); | ||
542 | |||
543 | return result; | ||
544 | } | ||
diff --git a/uisimulator/visual.h b/uisimulator/visual.h new file mode 100644 index 0000000000..dd45708ea0 --- /dev/null +++ b/uisimulator/visual.h | |||
@@ -0,0 +1,29 @@ | |||
1 | /* xscreensaver, Copyright (c) 1993-1999 by Jamie Zawinski <jwz@jwz.org> | ||
2 | * | ||
3 | * Permission to use, copy, modify, distribute, and sell this software and its | ||
4 | * documentation for any purpose is hereby granted without fee, provided that | ||
5 | * the above copyright notice appear in all copies and that both that | ||
6 | * copyright notice and this permission notice appear in supporting | ||
7 | * documentation. No representations are made about the suitability of this | ||
8 | * software for any purpose. It is provided "as is" without express or | ||
9 | * implied warranty. | ||
10 | */ | ||
11 | |||
12 | #ifndef __VISUAL_H__ | ||
13 | #define __VISUAL_H__ | ||
14 | |||
15 | extern Visual *get_visual (Screen *, const char *name, Bool, Bool); | ||
16 | extern Visual *get_visual_resource (Screen *, char *, char *, Bool); | ||
17 | extern int visual_depth (Screen *, Visual *); | ||
18 | /* extern int visual_pixmap_depth (Screen *, Visual *); */ | ||
19 | extern int visual_class (Screen *, Visual *); | ||
20 | extern int visual_cells (Screen *, Visual *); | ||
21 | extern int screen_number (Screen *); | ||
22 | extern Visual *find_similar_visual (Screen *, Visual *old); | ||
23 | extern void describe_visual (FILE *f, Screen *, Visual *, Bool private_cmap_p); | ||
24 | extern Visual *get_overlay_visual (Screen *, unsigned long *pixel_return); | ||
25 | extern Bool has_writable_cells (Screen *screen, Visual *visual); | ||
26 | |||
27 | Visual *get_gl_visual (Screen *screen); | ||
28 | |||
29 | #endif /* __VISUAL_H__ */ | ||
diff --git a/uisimulator/vroot.h b/uisimulator/vroot.h new file mode 100644 index 0000000000..ba3e5d29fa --- /dev/null +++ b/uisimulator/vroot.h | |||
@@ -0,0 +1,126 @@ | |||
1 | /*****************************************************************************/ | ||
2 | /** Copyright 1991 by Andreas Stolcke **/ | ||
3 | /** Copyright 1990 by Solbourne Computer Inc. **/ | ||
4 | /** Longmont, Colorado **/ | ||
5 | /** **/ | ||
6 | /** All Rights Reserved **/ | ||
7 | /** **/ | ||
8 | /** Permission to use, copy, modify, and distribute this software and **/ | ||
9 | /** its documentation for any purpose and without fee is hereby **/ | ||
10 | /** granted, provided that the above copyright notice appear in all **/ | ||
11 | /** copies and that both that copyright notice and this permis- **/ | ||
12 | /** sion notice appear in supporting documentation, and that the **/ | ||
13 | /** name of Solbourne not be used in advertising **/ | ||
14 | /** in publicity pertaining to distribution of the software without **/ | ||
15 | /** specific, written prior permission. **/ | ||
16 | /** **/ | ||
17 | /** ANDREAS STOLCKE AND SOLBOURNE COMPUTER INC. DISCLAIMS ALL WARRANTIES **/ | ||
18 | /** WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF **/ | ||
19 | /** MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL ANDREAS STOLCKE **/ | ||
20 | /** OR SOLBOURNE BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL **/ | ||
21 | /** DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA **/ | ||
22 | /** OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER **/ | ||
23 | /** TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE **/ | ||
24 | /** OR PERFORMANCE OF THIS SOFTWARE. **/ | ||
25 | /*****************************************************************************/ | ||
26 | /* | ||
27 | * vroot.h -- Virtual Root Window handling header file | ||
28 | * | ||
29 | * This header file redefines the X11 macros RootWindow and DefaultRootWindow, | ||
30 | * making them look for a virtual root window as provided by certain `virtual' | ||
31 | * window managers like swm and tvtwm. If none is found, the ordinary root | ||
32 | * window is returned, thus retaining backward compatibility with standard | ||
33 | * window managers. | ||
34 | * The function implementing the virtual root lookup remembers the result of | ||
35 | * its last invocation to avoid overhead in the case of repeated calls | ||
36 | * on the same display and screen arguments. | ||
37 | * The lookup code itself is taken from Tom LaStrange's ssetroot program. | ||
38 | * | ||
39 | * Most simple root window changing X programs can be converted to using | ||
40 | * virtual roots by just including | ||
41 | * | ||
42 | * #include <X11/vroot.h> | ||
43 | * | ||
44 | * after all the X11 header files. It has been tested on such popular | ||
45 | * X clients as xphoon, xfroot, xloadimage, and xaqua. | ||
46 | * It also works with the core clients xprop, xwininfo, xwd, and editres | ||
47 | * (and is necessary to get those clients working under tvtwm). | ||
48 | * It does NOT work with xsetroot; get the xsetroot replacement included in | ||
49 | * the tvtwm distribution instead. | ||
50 | * | ||
51 | * Andreas Stolcke <stolcke@ICSI.Berkeley.EDU>, 9/7/90 | ||
52 | * - replaced all NULL's with properly cast 0's, 5/6/91 | ||
53 | * - free children list (suggested by Mark Martin <mmm@cetia.fr>), 5/16/91 | ||
54 | * - include X11/Xlib.h and support RootWindowOfScreen, too 9/17/91 | ||
55 | */ | ||
56 | |||
57 | #ifndef _VROOT_H_ | ||
58 | #define _VROOT_H_ | ||
59 | |||
60 | #if !defined(lint) && !defined(SABER) | ||
61 | static const char vroot_rcsid[] = "#Id: vroot.h,v 1.4 1991/09/30 19:23:16 stolcke Exp stolcke #"; | ||
62 | #endif | ||
63 | |||
64 | #include <X11/X.h> | ||
65 | #include <X11/Xatom.h> | ||
66 | #include <X11/Xlib.h> | ||
67 | |||
68 | static Window | ||
69 | #ifdef __STDC__ /* ANSIfication added by jwz, to avoid superfluous warnings. */ | ||
70 | VirtualRootWindowOfScreen(Screen *screen) | ||
71 | #else /* !__STDC__ */ | ||
72 | VirtualRootWindowOfScreen(screen) Screen *screen; | ||
73 | #endif /* !__STDC__ */ | ||
74 | { | ||
75 | static Screen *save_screen = (Screen *)0; | ||
76 | static Window root = (Window)0; | ||
77 | |||
78 | if (screen != save_screen) { | ||
79 | Display *dpy = DisplayOfScreen(screen); | ||
80 | Atom __SWM_VROOT = None; | ||
81 | int i; | ||
82 | Window rootReturn, parentReturn, *children; | ||
83 | unsigned int numChildren; | ||
84 | |||
85 | root = RootWindowOfScreen(screen); | ||
86 | |||
87 | /* go look for a virtual root */ | ||
88 | __SWM_VROOT = XInternAtom(dpy, "__SWM_VROOT", False); | ||
89 | if (XQueryTree(dpy, root, &rootReturn, &parentReturn, | ||
90 | &children, &numChildren)) { | ||
91 | for (i = 0; i < numChildren; i++) { | ||
92 | Atom actual_type; | ||
93 | int actual_format; | ||
94 | unsigned long nitems, bytesafter; | ||
95 | Window *newRoot = (Window *)0; | ||
96 | |||
97 | if (XGetWindowProperty(dpy, children[i], | ||
98 | __SWM_VROOT, 0, 1, False, XA_WINDOW, | ||
99 | &actual_type, &actual_format, | ||
100 | &nitems, &bytesafter, | ||
101 | (unsigned char **) &newRoot) == Success | ||
102 | && newRoot) { | ||
103 | root = *newRoot; | ||
104 | break; | ||
105 | } | ||
106 | } | ||
107 | if (children) | ||
108 | XFree((char *)children); | ||
109 | } | ||
110 | |||
111 | save_screen = screen; | ||
112 | } | ||
113 | |||
114 | return root; | ||
115 | } | ||
116 | |||
117 | #undef RootWindowOfScreen | ||
118 | #define RootWindowOfScreen(s) VirtualRootWindowOfScreen(s) | ||
119 | |||
120 | #undef RootWindow | ||
121 | #define RootWindow(dpy,screen) VirtualRootWindowOfScreen(ScreenOfDisplay(dpy,screen)) | ||
122 | |||
123 | #undef DefaultRootWindow | ||
124 | #define DefaultRootWindow(dpy) VirtualRootWindowOfScreen(DefaultScreenOfDisplay(dpy)) | ||
125 | |||
126 | #endif /* _VROOT_H_ */ | ||
diff --git a/uisimulator/xgui.log b/uisimulator/xgui.log new file mode 100644 index 0000000000..aac53fb382 --- /dev/null +++ b/uisimulator/xgui.log | |||
@@ -0,0 +1,22 @@ | |||
1 | 13.07.21 Rockbox will kill ya! | ||
2 | 13.08.13 Rockbox will kill ya! | ||
3 | 13.09.12 Rockbox will kill ya! | ||
4 | 13.09.42 Rockbox will kill ya! | ||
5 | 13.12.26 Rockbox will kill ya! | ||
6 | 13.14.27 Rockbox will kill ya! | ||
7 | 13.15.48 Rockbox will kill ya! | ||
8 | 13.16.32 Rockbox will kill ya! | ||
9 | 13.22.54 Rockbox will kill ya! | ||
10 | 13.25.02 Rockbox will kill ya! | ||
11 | 13.37.39 Rockbox will kill ya! | ||
12 | 13.38.14 Rockbox will kill ya! | ||
13 | 13.38.31 Rockbox will kill ya! | ||
14 | 13.38.49 Rockbox will kill ya! | ||
15 | 13.39.39 Rockbox will kill ya! | ||
16 | 13.40.07 Rockbox will kill ya! | ||
17 | 13.50.51 Rockbox will kill ya! | ||
18 | 13.52.27 Rockbox will kill ya! | ||
19 | 13.53.16 Rockbox will kill ya! | ||
20 | 13.53.31 Rockbox will kill ya! | ||
21 | 13.53.46 Rockbox will kill ya! | ||
22 | 13.55.39 Rockbox will kill ya! | ||
diff --git a/uisimulator/xmu.h b/uisimulator/xmu.h new file mode 100644 index 0000000000..48084f747e --- /dev/null +++ b/uisimulator/xmu.h | |||
@@ -0,0 +1,14 @@ | |||
1 | /* This file contains compatibility routines for systems without Xmu. | ||
2 | * You would be better served by installing Xmu on your machine or | ||
3 | * yelling at your vendor to ship it. | ||
4 | */ | ||
5 | |||
6 | #ifndef __XMU_H__ | ||
7 | #define __XMU_H__ | ||
8 | |||
9 | #include <X11/Xlib.h> | ||
10 | #include <stdio.h> | ||
11 | |||
12 | int XmuPrintDefaultErrorMessage (Display *dpy, XErrorEvent *event, FILE *fp); | ||
13 | |||
14 | #endif /* __XMU_H__ */ | ||
diff --git a/uisimulator/yarandom.c b/uisimulator/yarandom.c new file mode 100644 index 0000000000..3d24943e0e --- /dev/null +++ b/uisimulator/yarandom.c | |||
@@ -0,0 +1,115 @@ | |||
1 | /* yarandom.c -- Yet Another Random Number Generator. | ||
2 | |||
3 | The unportable mess that is rand(), random(), drand48() and friends led me | ||
4 | to ask Phil Karlton <karlton@netscape.com> what the Right Thing to Do was. | ||
5 | He responded with this. It is non-cryptographically secure, reasonably | ||
6 | random (more so than anything that is in any C library), and very fast. | ||
7 | |||
8 | I don't understand how it works at all, but he says "look at Knuth, | ||
9 | Vol. 2 (original edition), page 26, Algorithm A. In this case n=55, | ||
10 | k=20 and m=2^32." | ||
11 | |||
12 | So there you have it. | ||
13 | |||
14 | --------------------------- | ||
15 | Note: xlockmore 4.03a10 uses this very simple RNG: | ||
16 | |||
17 | if ((seed = seed % 44488 * 48271 - seed / 44488 * 3399) < 0) | ||
18 | seed += 2147483647; | ||
19 | return seed-1; | ||
20 | |||
21 | of which it says | ||
22 | |||
23 | ``Dr. Park's algorithm published in the Oct. '88 ACM "Random Number | ||
24 | Generators: Good Ones Are Hard To Find" His version available at | ||
25 | ftp://cs.wm.edu/pub/rngs.tar Present form by many authors.'' | ||
26 | |||
27 | Karlton says: ``the usual problem with that kind of RNG turns out to | ||
28 | be unexepected short cycles for some word lengths.'' | ||
29 | |||
30 | Karlton's RNG is faster, since it does three adds and two stores, while the | ||
31 | xlockmore RNG does two multiplies, two divides, three adds, and one store. | ||
32 | |||
33 | Compiler optimizations make a big difference here: | ||
34 | gcc -O: difference is 1.2x. | ||
35 | gcc -O2: difference is 1.4x. | ||
36 | gcc -O3: difference is 1.5x. | ||
37 | SGI cc -O: difference is 2.4x. | ||
38 | SGI cc -O2: difference is 2.4x. | ||
39 | SGI cc -O3: difference is 5.1x. | ||
40 | Irix 6.2; Indy r5k; SGI cc version 6; gcc version 2.7.2.1. | ||
41 | */ | ||
42 | |||
43 | |||
44 | #ifdef HAVE_CONFIG_H | ||
45 | # include "config.h" | ||
46 | #endif | ||
47 | |||
48 | #ifdef HAVE_UNISTD_H | ||
49 | # include <unistd.h> /* for getpid() */ | ||
50 | #endif | ||
51 | #include <sys/time.h> /* for gettimeofday() */ | ||
52 | |||
53 | #include "yarandom.h" | ||
54 | # undef ya_rand_init | ||
55 | |||
56 | |||
57 | /* The following 'random' numbers are taken from CRC, 18th Edition, page 622. | ||
58 | Each array element was taken from the corresponding line in the table, | ||
59 | except that a[0] was from line 100. 8s and 9s in the table were simply | ||
60 | skipped. The high order digit was taken mod 4. | ||
61 | */ | ||
62 | #define VectorSize 55 | ||
63 | static unsigned int a[VectorSize] = { | ||
64 | 035340171546, 010401501101, 022364657325, 024130436022, 002167303062, /* 5 */ | ||
65 | 037570375137, 037210607110, 016272055420, 023011770546, 017143426366, /* 10 */ | ||
66 | 014753657433, 021657231332, 023553406142, 004236526362, 010365611275, /* 14 */ | ||
67 | 007117336710, 011051276551, 002362132524, 001011540233, 012162531646, /* 20 */ | ||
68 | 007056762337, 006631245521, 014164542224, 032633236305, 023342700176, /* 25 */ | ||
69 | 002433062234, 015257225043, 026762051606, 000742573230, 005366042132, /* 30 */ | ||
70 | 012126416411, 000520471171, 000725646277, 020116577576, 025765742604, /* 35 */ | ||
71 | 007633473735, 015674255275, 017555634041, 006503154145, 021576344247, /* 40 */ | ||
72 | 014577627653, 002707523333, 034146376720, 030060227734, 013765414060, /* 45 */ | ||
73 | 036072251540, 007255221037, 024364674123, 006200353166, 010126373326, /* 50 */ | ||
74 | 015664104320, 016401041535, 016215305520, 033115351014, 017411670323 /* 55 */ | ||
75 | }; | ||
76 | |||
77 | static int i1, i2; | ||
78 | |||
79 | unsigned int | ||
80 | ya_random (void) | ||
81 | { | ||
82 | register int ret = a[i1] + a[i2]; | ||
83 | a[i1] = ret; | ||
84 | if (++i1 >= VectorSize) i1 = 0; | ||
85 | if (++i2 >= VectorSize) i2 = 0; | ||
86 | return ret; | ||
87 | } | ||
88 | |||
89 | void | ||
90 | ya_rand_init(unsigned int seed) | ||
91 | { | ||
92 | int i; | ||
93 | if (seed == 0) | ||
94 | { | ||
95 | struct timeval tp; | ||
96 | #ifdef GETTIMEOFDAY_TWO_ARGS | ||
97 | struct timezone tzp; | ||
98 | gettimeofday(&tp, &tzp); | ||
99 | #else | ||
100 | gettimeofday(&tp); | ||
101 | #endif | ||
102 | /* ignore overflow */ | ||
103 | seed = (999*tp.tv_sec) + (1001*tp.tv_usec) + (1003 * getpid()); | ||
104 | } | ||
105 | |||
106 | a[0] += seed; | ||
107 | for (i = 1; i < VectorSize; i++) | ||
108 | { | ||
109 | seed = a[i-1]*1001 + seed*999; | ||
110 | a[i] += seed; | ||
111 | } | ||
112 | |||
113 | i1 = a[0] % VectorSize; | ||
114 | i2 = (i1 + 024) % VectorSize; | ||
115 | } | ||
diff --git a/uisimulator/yarandom.h b/uisimulator/yarandom.h new file mode 100644 index 0000000000..0e1dfcfb76 --- /dev/null +++ b/uisimulator/yarandom.h | |||
@@ -0,0 +1,64 @@ | |||
1 | /* xscreensaver, Copyright (c) 1997, 1998 by Jamie Zawinski <jwz@jwz.org> | ||
2 | * | ||
3 | * Permission to use, copy, modify, distribute, and sell this software and its | ||
4 | * documentation for any purpose is hereby granted without fee, provided that | ||
5 | * the above copyright notice appear in all copies and that both that | ||
6 | * copyright notice and this permission notice appear in supporting | ||
7 | * documentation. No representations are made about the suitability of this | ||
8 | * software for any purpose. It is provided "as is" without express or | ||
9 | * implied warranty. | ||
10 | */ | ||
11 | |||
12 | #ifndef __YARANDOM_H__ | ||
13 | #define __YARANDOM_H__ | ||
14 | |||
15 | #undef random | ||
16 | #undef rand | ||
17 | #undef drand48 | ||
18 | #undef srandom | ||
19 | #undef srand | ||
20 | #undef srand48 | ||
21 | #undef frand | ||
22 | #undef RAND_MAX | ||
23 | |||
24 | #ifdef VMS | ||
25 | # include "vms-gtod.h" | ||
26 | #endif | ||
27 | |||
28 | extern unsigned int ya_random (void); | ||
29 | extern void ya_rand_init (unsigned int); | ||
30 | |||
31 | #define random() ya_random() | ||
32 | #define RAND_MAX 0x7FFFFFFF | ||
33 | |||
34 | /*#define srandom(i) ya_rand_init(0)*/ | ||
35 | |||
36 | /* Define these away to keep people from using the wrong APIs in xscreensaver. | ||
37 | */ | ||
38 | #define rand __ERROR_use_random_not_rand_in_xscreensaver__ | ||
39 | #define drand48 __ERROR_use_random_not_drand48_in_xscreensaver__ | ||
40 | #define srandom __ERROR_do_not_call_srandom_in_xscreensaver__ | ||
41 | #define srand __ERROR_do_not_call_srand_in_xscreensaver__ | ||
42 | #define srand48 __ERROR_do_not_call_srand48_in_xscreensaver__ | ||
43 | #define ya_rand_init __ERROR_do_not_call_ya_rand_init_in_xscreensaver__ | ||
44 | |||
45 | |||
46 | #if defined (__GNUC__) && (__GNUC__ >= 2) | ||
47 | /* Implement frand using GCC's statement-expression extension. */ | ||
48 | |||
49 | # define frand(f) \ | ||
50 | ({ double tmp = (((double) random()) / \ | ||
51 | (((double) ((unsigned int)~0)) / ((double) (f)))); \ | ||
52 | tmp < 0 ? (-tmp) : tmp; }) | ||
53 | |||
54 | #else /* not GCC2 - implement frand using a global variable.*/ | ||
55 | |||
56 | static double _frand_tmp_; | ||
57 | # define frand(f) \ | ||
58 | (_frand_tmp_ = (((double) random()) / \ | ||
59 | (((double) ((unsigned int)~0)) / ((double) (f)))), \ | ||
60 | _frand_tmp_ < 0 ? (-_frand_tmp_) : _frand_tmp_) | ||
61 | |||
62 | #endif /* not GCC2 */ | ||
63 | |||
64 | #endif /* __YARANDOM_H__ */ | ||