summaryrefslogtreecommitdiff
path: root/uisimulator/x11
diff options
context:
space:
mode:
Diffstat (limited to 'uisimulator/x11')
-rw-r--r--uisimulator/x11/Makefile82
-rw-r--r--uisimulator/x11/README9
-rw-r--r--uisimulator/x11/button-x11.c108
-rw-r--r--uisimulator/x11/config.h362
-rw-r--r--uisimulator/x11/lcd-x11.c109
-rw-r--r--uisimulator/x11/lcd-x11.h24
-rw-r--r--uisimulator/x11/resources.c231
-rw-r--r--uisimulator/x11/resources.h23
-rw-r--r--uisimulator/x11/screenhack.c576
-rw-r--r--uisimulator/x11/screenhack.h97
-rw-r--r--uisimulator/x11/uibasic.c253
-rw-r--r--uisimulator/x11/utils.h22
-rw-r--r--uisimulator/x11/version.h1
-rw-r--r--uisimulator/x11/visual.c544
-rw-r--r--uisimulator/x11/visual.h29
-rw-r--r--uisimulator/x11/vroot.h126
-rw-r--r--uisimulator/x11/xmu.h14
17 files changed, 2610 insertions, 0 deletions
diff --git a/uisimulator/x11/Makefile b/uisimulator/x11/Makefile
new file mode 100644
index 0000000000..27dad9f178
--- /dev/null
+++ b/uisimulator/x11/Makefile
@@ -0,0 +1,82 @@
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
20TARGET = rockboxui
21
22FIRMWAREDIR = ../firmware
23DRIVERS = $(FIRMWAREDIR)/drivers
24
25CC = gcc
26RM = rm -f
27DEBUG = -g
28DEFINES = -DHAVE_CONFIG_H -DGETTIMEOFDAY_TWO_ARGS -DSIMULATOR -DHAVE_LCD_BITMAP
29LDFLAGS = -lX11 -lm -lXt -lXmu -lnsl
30
31
32UNAME := $(shell uname)
33ifeq ($(UNAME),Linux)
34 INCLUDES = -I/usr/X11R6/include -I$(DRIVERS) -I$(FIRMWAREDIR)
35 LIBDIRS = -L/usr/X11R6/lib
36else
37 INCLUDES = -I$(FIRMWAREDIR)
38 LIBDIRS =
39endif
40
41CFLAGS = $(DEBUG) $(DEFINES) $(INCLUDES)
42
43#SRCS = $(wildcard *.c)
44
45SRCS = screenhack.c uibasic.c resources.c visual.c lcd.c lcd-x11.c \
46 button-x11.c chartables.c tetris.c app.c
47
48OBJS := $(SRCS:c=o)
49
50all: $(TARGET)
51
52clean:
53 $(RM) $(OBJS) *~ core $(TARGET) $(CLIENTS)
54 $(RM) -r $(DEPS)
55
56distclean: clean
57 $(RM) config.cache
58
59lcd.o: $(DRIVERS)/lcd.c
60 $(CC) $(CFLAGS) -c $< -o $@
61
62chartables.o: $(FIRMWAREDIR)/chartables.c
63 $(CC) $(CFLAGS) -c $< -o $@
64
65.c.o:
66 $(CC) $(CFLAGS) -c $<
67
68$(TARGET): $(OBJS)
69 $(CC) -o $(TARGET) $(LIBDIRS) $(LDFLAGS) $(OBJS)
70
71DEPS:=.deps
72
73$(DEPS)/%.d: %.c
74 @$(SHELL) -c 'if [ ! -d $(DEPS) ]; then \
75 echo Creating the dependency directory: $(DEPS); \
76 mkdir $(DEPS); fi'
77 @echo "Updating Dependencies for $<"
78 @$(SHELL) -ec '$(CC) -MM $(CFLAGS) $< \
79 |sed '\''s/\($*\)\.o[ :]*/\1.o $(<:%.c=%.d) : /g'\'' > $@; \
80 [ -s $@ ] || rm -f $@'
81
82-include $(SRCS:%.c=$(DEPS)/%.d)
diff --git a/uisimulator/x11/README b/uisimulator/x11/README
new file mode 100644
index 0000000000..bf1291fbc5
--- /dev/null
+++ b/uisimulator/x11/README
@@ -0,0 +1,9 @@
1Solaris
2
3 $ make
4 $ ./rockboxui
5
6Linux
7
8 $ make LIBDIRS=-L/usr/X11R6/lib
9 $ ./rockboxui
diff --git a/uisimulator/x11/button-x11.c b/uisimulator/x11/button-x11.c
new file mode 100644
index 0000000000..4bc780bed6
--- /dev/null
+++ b/uisimulator/x11/button-x11.c
@@ -0,0 +1,108 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2002 by Björn Stenberg
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#define HAVE_RECORDER_KEYPAD
20#include "types.h"
21#include "button.h"
22
23#include "X11/keysym.h"
24
25/*
26 *Initialize buttons
27 */
28void button_init()
29{
30}
31
32/*
33 * Translate X keys to Recorder keys
34 *
35 * We simulate recorder keys on the numeric keypad:
36 *
37 * 4,6,8,2 = Left, Right, Up, Down
38 * 5 = Play/pause
39 * Div,Mul,Sub = The tree menu keys
40 * +,Enter = On, Off
41 *
42 */
43static int get_raw_button (void)
44{
45 int k = screenhack_handle_events();
46 switch(k)
47 {
48 case XK_KP_Left:
49 case XK_Left:
50 case XK_KP_4:
51 return BUTTON_LEFT;
52
53 case XK_KP_Right:
54 case XK_Right:
55 case XK_KP_6:
56 return BUTTON_RIGHT;
57
58 case XK_KP_Up:
59 case XK_Up:
60 case XK_KP_8:
61 return BUTTON_UP;
62
63 case XK_KP_Down:
64 case XK_Down:
65 case XK_KP_2:
66 return BUTTON_DOWN;
67
68 case XK_KP_Space:
69 case XK_KP_5:
70 return BUTTON_PLAY;
71
72 case XK_KP_Enter:
73 return BUTTON_OFF;
74
75 case XK_KP_Add:
76 return BUTTON_ON;
77
78 case XK_KP_Divide:
79 return BUTTON_F1;
80
81 case XK_KP_Multiply:
82 return BUTTON_F2;
83
84 case XK_KP_Subtract:
85 return BUTTON_F3;
86
87 default:
88 return 0;
89 }
90}
91
92/*
93 * Get the currently pressed button.
94 * Returns one of BUTTON_xxx codes, with possibly a modifier bit set.
95 * No modifier bits are set when the button is first pressed.
96 * BUTTON_HELD bit is while the button is being held.
97 * BUTTON_REL bit is set when button has been released.
98 */
99int button_get(void)
100{
101 return get_raw_button();
102}
103
104/* -----------------------------------------------------------------
105 * local variables:
106 * eval: (load-file "rockbox-mode.el")
107 * end:
108 */
diff --git a/uisimulator/x11/config.h b/uisimulator/x11/config.h
new file mode 100644
index 0000000000..1c520cfbac
--- /dev/null
+++ b/uisimulator/x11/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/x11/lcd-x11.c b/uisimulator/x11/lcd-x11.c
new file mode 100644
index 0000000000..9659426f02
--- /dev/null
+++ b/uisimulator/x11/lcd-x11.c
@@ -0,0 +1,109 @@
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
20#include <stdio.h>
21#include <string.h>
22#include <stdarg.h>
23#include <stdlib.h>
24#include <ctype.h>
25#include <sys/types.h>
26#include <sys/stat.h>
27#include <fcntl.h>
28
29#include <errno.h>
30#include <ctype.h>
31#include <time.h>
32
33#include "screenhack.h"
34
35/*
36 * Specific implementations for X11, using the generic LCD API and data.
37 */
38
39#include "lcd-x11.h"
40
41extern unsigned char display[LCD_WIDTH][LCD_HEIGHT/8];
42extern void screen_resized(int width, int height);
43extern Display *dpy;
44
45unsigned char display_copy[LCD_WIDTH][LCD_HEIGHT/8];
46
47void lcd_update (void)
48{
49 int x, y;
50 int p=0;
51 int bit;
52 XPoint points[LCD_WIDTH * LCD_HEIGHT];
53 int cp=0;
54 XPoint clearpoints[LCD_WIDTH * LCD_HEIGHT];
55
56#if 0
57 screen_resized(LCD_WIDTH, LCD_HEIGHT);
58
59 for(y=0; y<LCD_HEIGHT; y+=8) {
60 for(x=0; x<LCD_WIDTH; x++) {
61 if(display[x][y/8]) {
62 /* one or more bits/pixels are set */
63 for(bit=0; bit<8; bit++) {
64 if(display[x][y/8]&(1<<bit)) {
65 points[p].x = x + MARGIN_X;
66 points[p].y = y+bit + MARGIN_Y;
67 p++; /* increase the point counter */
68 }
69 }
70 }
71 }
72 }
73#else
74 for(y=0; y<LCD_HEIGHT; y+=8) {
75 for(x=0; x<LCD_WIDTH; x++) {
76 if(display[x][y/8] || display_copy[x][y/8]) {
77 /* one or more bits/pixels are changed */
78 unsigned char diff =
79 display[x][y/8] ^ display_copy[x][y/8];
80
81 for(bit=0; bit<8; bit++) {
82 if(display[x][y/8]&(1<<bit)) {
83 /* set a dot */
84 points[p].x = x + MARGIN_X;
85 points[p].y = y+bit + MARGIN_Y;
86 p++; /* increase the point counter */
87 }
88 else if(diff &(1<<bit)) {
89 /* clear a dot */
90 clearpoints[cp].x = x + MARGIN_X;
91 clearpoints[cp].y = y+bit + MARGIN_Y;
92 cp++; /* increase the point counter */
93 }
94 }
95 }
96 }
97 }
98
99 /* copy a huge block */
100 memcpy(display_copy, display, sizeof(display));
101
102#endif
103
104
105 drawdots(1, &points[0], p);
106 drawdots(0, &clearpoints[0], cp);
107 fprintf(stderr, "lcd_update: Draws %d pixels, clears %d pixels\n", p, cp);
108 XSync(dpy,False);
109}
diff --git a/uisimulator/x11/lcd-x11.h b/uisimulator/x11/lcd-x11.h
new file mode 100644
index 0000000000..b95374c13c
--- /dev/null
+++ b/uisimulator/x11/lcd-x11.h
@@ -0,0 +1,24 @@
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
20#define MARGIN_X 3
21#define MARGIN_Y 3
22
23/* include the "real" lcd.h file here */
24#include <lcd.h>
diff --git a/uisimulator/x11/resources.c b/uisimulator/x11/resources.c
new file mode 100644
index 0000000000..e0925d0fc7
--- /dev/null
+++ b/uisimulator/x11/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
20extern char *progname;
21extern char *progclass;
22extern XrmDatabase db;
23
24static 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
34char *
35get_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
56Bool
57get_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
82int
83get_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
115double
116get_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
133unsigned int
134get_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
169int
170parse_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
210static unsigned int
211get_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
221unsigned int
222get_seconds_resource (char *res_name, char *res_class)
223{
224 return get_time_resource (res_name, res_class, True);
225}
226
227unsigned int
228get_minutes_resource (char *res_name, char *res_class)
229{
230 return get_time_resource (res_name, res_class, False);
231}
diff --git a/uisimulator/x11/resources.h b/uisimulator/x11/resources.h
new file mode 100644
index 0000000000..1fbcfa7ce7
--- /dev/null
+++ b/uisimulator/x11/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__
14extern char *get_string_resource (char*,char*);
15extern Bool get_boolean_resource (char*,char*);
16extern int get_integer_resource (char*,char*);
17extern double get_float_resource (char*,char*);
18extern unsigned int get_pixel_resource (char*,char*,Display*,Colormap);
19extern unsigned int get_minutes_resource (char*,char*);
20extern unsigned int get_seconds_resource (char*,char*);
21extern int parse_time (const char *string, Bool seconds_default_p,
22 Bool silent_p);
23#endif /* __XSCREENSAVER_RESOURCES_H__ */
diff --git a/uisimulator/x11/screenhack.c b/uisimulator/x11/screenhack.c
new file mode 100644
index 0000000000..f4f5aaa348
--- /dev/null
+++ b/uisimulator/x11/screenhack.c
@@ -0,0 +1,576 @@
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
68char *progname;
69XrmDatabase db;
70XtAppContext app;
71Bool mono_p;
72
73static 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
84static char *default_defaults[] = {
85 ".root: false",
86 "*geometry: 200x100", /* this should be .geometry, but nooooo... */
87 "*mono: false",
88 "*installColormap: false",
89 "*visualID: default",
90 "*windowID: ",
91 0
92};
93
94extern Display* dpy;
95
96static XrmOptionDescRec *merged_options;
97static int merged_options_size;
98static char **merged_defaults;
99
100static void
101merge_options (void)
102{
103 int def_opts_size, opts_size;
104 int def_defaults_size, defaults_size;
105
106 for (def_opts_size = 0; default_options[def_opts_size].option;
107 def_opts_size++)
108 ;
109 for (opts_size = 0; options[opts_size].option; opts_size++)
110 ;
111
112 merged_options_size = def_opts_size + opts_size;
113 merged_options = (XrmOptionDescRec *)
114 malloc ((merged_options_size + 1) * sizeof(*default_options));
115 memcpy (merged_options, default_options,
116 (def_opts_size * sizeof(*default_options)));
117 memcpy (merged_options + def_opts_size, options,
118 ((opts_size + 1) * sizeof(*default_options)));
119
120 for (def_defaults_size = 0; default_defaults[def_defaults_size];
121 def_defaults_size++)
122 ;
123 for (defaults_size = 0; defaults[defaults_size]; defaults_size++)
124 ;
125 merged_defaults = (char **)
126 malloc ((def_defaults_size + defaults_size + 1) * sizeof (*defaults));;
127 memcpy (merged_defaults, default_defaults,
128 def_defaults_size * sizeof(*defaults));
129 memcpy (merged_defaults + def_defaults_size, defaults,
130 (defaults_size + 1) * sizeof(*defaults));
131
132 /* This totally sucks. Xt should behave like this by default.
133 If the string in `defaults' looks like ".foo", change that
134 to "Progclass.foo".
135 */
136 {
137 char **s;
138 for (s = merged_defaults; *s; s++)
139 if (**s == '.')
140 {
141 const char *oldr = *s;
142 char *newr = (char *) malloc(strlen(oldr) + strlen(progclass) + 3);
143 strcpy (newr, progclass);
144 strcat (newr, oldr);
145 *s = newr;
146 }
147 }
148}
149
150
151/* Make the X errors print out the name of this program, so we have some
152 clue which one has a bug when they die under the screensaver.
153 */
154
155static int
156screenhack_ehandler (Display *dpy, XErrorEvent *error)
157{
158 fprintf (stderr, "\nX error in %s:\n", progname);
159 if (XmuPrintDefaultErrorMessage (dpy, error, stderr))
160 exit (-1);
161 else
162 fprintf (stderr, " (nonfatal.)\n");
163 return 0;
164}
165
166static Bool
167MapNotify_event_p (Display *dpy, XEvent *event, XPointer window)
168{
169 return (event->xany.type == MapNotify &&
170 event->xvisibility.window == (Window) window);
171}
172
173
174#ifdef XLOCKMORE
175extern void pre_merge_options (void);
176#endif
177
178
179static Atom XA_WM_PROTOCOLS, XA_WM_DELETE_WINDOW;
180
181/* Dead-trivial event handling: exits if "q" or "ESC" are typed.
182 Exit if the WM_PROTOCOLS WM_DELETE_WINDOW ClientMessage is received.
183 */
184int
185screenhack_handle_event (Display *dpy, XEvent *event)
186{
187 int key=0;
188 switch (event->xany.type)
189 {
190 case KeyPress:
191 {
192 KeySym keysym;
193 unsigned char c = 0;
194 XLookupString (&event->xkey, &c, 1, &keysym, 0);
195 if (! (keysym >= XK_Shift_L && keysym <= XK_Hyper_R))
196 XBell (dpy, 0); /* beep for non-chord keys */
197 key = keysym;
198 fprintf(stderr, "KEY PRESSED: %c (%02x)\n", c, c);
199 }
200 break;
201 case ResizeRequest:
202 screen_resized(event->xresizerequest.width, event->xresizerequest.height);
203 screen_redraw();
204 fprintf(stderr, "WINDOW RESIZED to width %d height %d\n",
205 event->xresizerequest.width, event->xresizerequest.height);
206 break;
207 default:
208 fprintf(stderr, "EVENT: %d (see /usr/include/X11/X.h)\n",
209 event->xany.type);
210 break;
211 case Expose:
212 screen_redraw();
213 fprintf(stderr, "EXPOSE: x: %d y: %d width: %d height: %d\n",
214 event->xexpose.x, event->xexpose.y,
215 event->xexpose.width, event->xexpose.height);
216 break;
217 case ButtonPress:
218 fprintf(stderr, "BUTTON PRESSED\n");
219 break;
220 case ClientMessage:
221 {
222 if (event->xclient.message_type != XA_WM_PROTOCOLS)
223 {
224 char *s = XGetAtomName(dpy, event->xclient.message_type);
225 if (!s) s = "(null)";
226 fprintf (stderr, "%s: unknown ClientMessage %s received!\n",
227 progname, s);
228 }
229 else if (event->xclient.data.l[0] != XA_WM_DELETE_WINDOW)
230 {
231 char *s1 = XGetAtomName(dpy, event->xclient.message_type);
232 char *s2 = XGetAtomName(dpy, event->xclient.data.l[0]);
233 if (!s1) s1 = "(null)";
234 if (!s2) s2 = "(null)";
235 fprintf (stderr, "%s: unknown ClientMessage %s[%s] received!\n",
236 progname, s1, s2);
237 }
238 else
239 {
240 exit (0);
241 }
242 }
243 break;
244 }
245 return key;
246}
247
248
249int
250screenhack_handle_events (void)
251{
252 int key=0;
253 while (XPending (dpy))
254 {
255 XEvent event;
256 XNextEvent (dpy, &event);
257 key=screenhack_handle_event (dpy, &event);
258 }
259 return key;
260}
261
262
263static Visual *
264pick_visual (Screen *screen)
265{
266#ifdef USE_GL
267 /* If we're linking against GL (that is, this is the version of screenhack.o
268 that the GL hacks will use, which is different from the one that the
269 non-GL hacks will use) then try to pick the "best" visual by interrogating
270 the GL library instead of by asking Xlib. GL knows better.
271 */
272 Visual *v = 0;
273 char *string = get_string_resource ("visualID", "VisualID");
274 char *s;
275
276 if (string)
277 for (s = string; *s; s++)
278 if (isupper (*s)) *s = _tolower (*s);
279
280 if (!string || !*string ||
281 !strcmp (string, "gl") ||
282 !strcmp (string, "best") ||
283 !strcmp (string, "color") ||
284 !strcmp (string, "default"))
285 v = get_gl_visual (screen); /* from ../utils/visual-gl.c */
286
287 if (string)
288 free (string);
289 if (v)
290 return v;
291#endif /* USE_GL */
292
293 return get_visual_resource (screen, "visualID", "VisualID", False);
294}
295
296
297/* Notice when the user has requested a different visual or colormap
298 on a pre-existing window (e.g., "-root -visual truecolor" or
299 "-window-id 0x2c00001 -install") and complain, since when drawing
300 on an existing window, we have no choice about these things.
301 */
302static void
303visual_warning (Screen *screen, Window window, Visual *visual, Colormap cmap,
304 Bool window_p)
305{
306 char *visual_string = get_string_resource ("visualID", "VisualID");
307 Visual *desired_visual = pick_visual (screen);
308 char win[100];
309 char why[100];
310
311 if (window == RootWindowOfScreen (screen))
312 strcpy (win, "root window");
313 else
314 sprintf (win, "window 0x%x", (unsigned long) window);
315
316 if (window_p)
317 sprintf (why, "-window-id 0x%x", (unsigned long) window);
318 else
319 strcpy (why, "-root");
320
321 if (visual_string && *visual_string)
322 {
323 char *s;
324 for (s = visual_string; *s; s++)
325 if (isupper (*s)) *s = _tolower (*s);
326
327 if (!strcmp (visual_string, "default") ||
328 !strcmp (visual_string, "default") ||
329 !strcmp (visual_string, "best"))
330 /* don't warn about these, just silently DWIM. */
331 ;
332 else if (visual != desired_visual)
333 {
334 fprintf (stderr, "%s: ignoring `-visual %s' because of `%s'.\n",
335 progname, visual_string, why);
336 fprintf (stderr, "%s: using %s's visual 0x%x.\n",
337 progname, win, XVisualIDFromVisual (visual));
338 }
339 free (visual_string);
340 }
341
342 if (visual == DefaultVisualOfScreen (screen) &&
343 has_writable_cells (screen, visual) &&
344 get_boolean_resource ("installColormap", "InstallColormap"))
345 {
346 fprintf (stderr, "%s: ignoring `-install' because of `%s'.\n",
347 progname, why);
348 fprintf (stderr, "%s: using %s's colormap 0x%x.\n",
349 progname, win, (unsigned long) cmap);
350 }
351}
352
353
354int
355main (int argc, char **argv)
356{
357 Widget toplevel;
358 Display *dpy;
359 Window window;
360 Screen *screen;
361 Visual *visual;
362 Colormap cmap;
363 Bool root_p;
364 Window on_window = 0;
365 XEvent event;
366 Boolean dont_clear /*, dont_map */;
367 char version[255];
368
369#ifdef XLOCKMORE
370 pre_merge_options ();
371#endif
372 merge_options ();
373
374#ifdef __sgi
375 /* We have to do this on SGI to prevent the background color from being
376 overridden by the current desktop color scheme (we'd like our backgrounds
377 to be black, thanks.) This should be the same as setting the
378 "*useSchemes: none" resource, but it's not -- if that resource is
379 present in the `default_defaults' above, it doesn't work, though it
380 does work when passed as an -xrm arg on the command line. So screw it,
381 turn them off from C instead.
382 */
383 SgiUseSchemes ("none");
384#endif /* __sgi */
385
386 toplevel = XtAppInitialize (&app, progclass, merged_options,
387 merged_options_size, &argc, argv,
388 merged_defaults, 0, 0);
389 dpy = XtDisplay (toplevel);
390 screen = XtScreen (toplevel);
391 db = XtDatabase (dpy);
392
393 XtGetApplicationNameAndClass (dpy, &progname, &progclass);
394
395 /* half-assed way of avoiding buffer-overrun attacks. */
396 if (strlen (progname) >= 100) progname[100] = 0;
397
398 XSetErrorHandler (screenhack_ehandler);
399
400 XA_WM_PROTOCOLS = XInternAtom (dpy, "WM_PROTOCOLS", False);
401 XA_WM_DELETE_WINDOW = XInternAtom (dpy, "WM_DELETE_WINDOW", False);
402
403
404 if (argc > 1)
405 {
406 const char *s;
407 int i;
408 int x = 18;
409 int end = 78;
410 Bool help_p = !strcmp(argv[1], "-help");
411 fprintf (stderr, "%s\n", version);
412 for (s = progclass; *s; s++) fprintf(stderr, " ");
413 fprintf (stderr, " eXcellent GUI\n\n");
414
415 if (!help_p)
416 fprintf(stderr, "Unrecognised option: %s\n", argv[1]);
417 fprintf (stderr, "Options include: ");
418 for (i = 0; i < merged_options_size; i++)
419 {
420 char *sw = merged_options [i].option;
421 Bool argp = (merged_options [i].argKind == XrmoptionSepArg);
422 int size = strlen (sw) + (argp ? 6 : 0) + 2;
423 if (x + size >= end)
424 {
425 fprintf (stderr, "\n\t\t ");
426 x = 18;
427 }
428 x += size;
429 fprintf (stderr, "%s", sw);
430 if (argp) fprintf (stderr, " <arg>");
431 if (i != merged_options_size - 1) fprintf (stderr, ", ");
432 }
433 fprintf (stderr, ".\n");
434 exit (help_p ? 0 : 1);
435 }
436
437 dont_clear = get_boolean_resource ("dontClearRoot", "Boolean");
438/*dont_map = get_boolean_resource ("dontMapWindow", "Boolean"); */
439 mono_p = get_boolean_resource ("mono", "Boolean");
440 if (CellsOfScreen (DefaultScreenOfDisplay (dpy)) <= 2)
441 mono_p = True;
442
443 root_p = get_boolean_resource ("root", "Boolean");
444
445 {
446 char *s = get_string_resource ("windowID", "WindowID");
447 if (s && *s)
448 on_window = get_integer_resource ("windowID", "WindowID");
449 if (s) free (s);
450 }
451
452 if (on_window)
453 {
454 XWindowAttributes xgwa;
455 window = (Window) on_window;
456 XtDestroyWidget (toplevel);
457 XGetWindowAttributes (dpy, window, &xgwa);
458 cmap = xgwa.colormap;
459 visual = xgwa.visual;
460 visual_warning (screen, window, visual, cmap, True);
461 }
462 else if (root_p)
463 {
464 XWindowAttributes xgwa;
465 window = RootWindowOfScreen (XtScreen (toplevel));
466 XtDestroyWidget (toplevel);
467 XGetWindowAttributes (dpy, window, &xgwa);
468 cmap = xgwa.colormap;
469 visual = xgwa.visual;
470 visual_warning (screen, window, visual, cmap, False);
471 }
472 else
473 {
474 Boolean def_visual_p;
475 visual = pick_visual (screen);
476
477 if (toplevel->core.width <= 0)
478 toplevel->core.width = 600;
479 if (toplevel->core.height <= 0)
480 toplevel->core.height = 480;
481
482 def_visual_p = (visual == DefaultVisualOfScreen (screen));
483
484 if (!def_visual_p)
485 {
486 unsigned int bg, bd;
487 Widget new;
488
489 cmap = XCreateColormap (dpy, RootWindowOfScreen(screen),
490 visual, AllocNone);
491 bg = get_pixel_resource ("background", "Background", dpy, cmap);
492 bd = get_pixel_resource ("borderColor", "Foreground", dpy, cmap);
493
494 new = XtVaAppCreateShell (progname, progclass,
495 topLevelShellWidgetClass, dpy,
496 XtNmappedWhenManaged, False,
497 XtNvisual, visual,
498 XtNdepth, visual_depth (screen, visual),
499 XtNwidth, toplevel->core.width,
500 XtNheight, toplevel->core.height,
501 XtNcolormap, cmap,
502 XtNbackground, (Pixel) bg,
503 XtNborderColor, (Pixel) bd,
504 XtNinput, True, /* for WM_HINTS */
505 0);
506 XtDestroyWidget (toplevel);
507 toplevel = new;
508 XtRealizeWidget (toplevel);
509 window = XtWindow (toplevel);
510 }
511 else
512 {
513 XtVaSetValues (toplevel,
514 XtNmappedWhenManaged, False,
515 XtNinput, True, /* for WM_HINTS */
516 0);
517 XtRealizeWidget (toplevel);
518 window = XtWindow (toplevel);
519
520 if (get_boolean_resource ("installColormap", "InstallColormap"))
521 {
522 cmap = XCreateColormap (dpy, window,
523 DefaultVisualOfScreen (XtScreen (toplevel)),
524 AllocNone);
525 XSetWindowColormap (dpy, window, cmap);
526 }
527 else
528 {
529 cmap = DefaultColormap (dpy, DefaultScreen (dpy));
530 }
531 }
532
533/*
534 if (dont_map)
535 {
536 XtVaSetValues (toplevel, XtNmappedWhenManaged, False, 0);
537 XtRealizeWidget (toplevel);
538 }
539 else
540*/
541 {
542 XtPopup (toplevel, XtGrabNone);
543 }
544
545 XtVaSetValues(toplevel, XtNtitle, version, 0);
546
547 /* For screenhack_handle_events(): select KeyPress, and
548 announce that we accept WM_DELETE_WINDOW. */
549 {
550 XWindowAttributes xgwa;
551 XGetWindowAttributes (dpy, window, &xgwa);
552 XSelectInput (dpy, window,
553 xgwa.your_event_mask | KeyPressMask | ButtonPressMask | ResizeRedirectMask | ExposureMask);
554 XChangeProperty (dpy, window, XA_WM_PROTOCOLS, XA_ATOM, 32,
555 PropModeReplace,
556 (unsigned char *) &XA_WM_DELETE_WINDOW, 1);
557 }
558 }
559
560 if (!dont_clear)
561 {
562 XSetWindowBackground (dpy, window,
563 get_pixel_resource ("background", "Background",
564 dpy, cmap));
565 XClearWindow (dpy, window);
566 }
567
568 if (!root_p && !on_window)
569 /* wait for it to be mapped */
570 XIfEvent (dpy, &event, MapNotify_event_p, (XPointer) window);
571
572 XSync (dpy, False);
573
574 screenhack (dpy, window); /* doesn't return */
575 return 0;
576}
diff --git a/uisimulator/x11/screenhack.h b/uisimulator/x11/screenhack.h
new file mode 100644
index 0000000000..12cd873e22
--- /dev/null
+++ b/uisimulator/x11/screenhack.h
@@ -0,0 +1,97 @@
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 "resources.h"
82#include "visual.h"
83
84extern Bool mono_p;
85extern char *progname;
86extern char *progclass;
87extern XrmDatabase db;
88extern XrmOptionDescRec options [];
89extern char *defaults [];
90
91extern void screenhack (Display*,Window);
92extern int screenhack_handle_event (Display*, XEvent*);
93extern int screenhack_handle_events (void);
94extern void screen_redraw();
95extern void screen_resized();
96
97#endif /* __SCREENHACK_H__ */
diff --git a/uisimulator/x11/uibasic.c b/uisimulator/x11/uibasic.c
new file mode 100644
index 0000000000..85cfb7d911
--- /dev/null
+++ b/uisimulator/x11/uibasic.c
@@ -0,0 +1,253 @@
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
34#include "version.h"
35
36#include "lcd-x11.h"
37
38#define MAX(x,y) ((x)>(y)?(x):(y))
39#define MIN(x,y) ((x)<(y)?(x):(y))
40
41#define PROGNAME "rockboxui"
42
43/* -- -- */
44
45GC draw_gc, erase_gc;
46static Colormap cmap;
47static XColor color_track, color_car;
48
49static long maxx, maxy;
50static double track_zoom=1;
51
52Display *dpy;
53Window window;
54
55XrmOptionDescRec options [] = {
56 /* { "-subtractive", ".additive", XrmoptionNoArg, "false" }, */
57 { "-server", ".server", XrmoptionSepArg, 0 },
58 { "-help", ".help", XrmoptionNoArg, "false" },
59 { 0, 0, 0, 0 }
60};
61char *progclass = "rockboxui";
62
63char *defaults [] = {
64 ".background: black",
65 ".foreground: white",
66 "*help: false",
67 0
68};
69
70#define LOGFILE "xgui.log"
71void Logf(char *fmt, ...)
72{
73 va_list args;
74 FILE *log;
75 struct tm *t;
76 time_t now=time(NULL);
77
78 va_start(args, fmt);
79
80 t = localtime(&now);
81 log = fopen(LOGFILE, "a");
82 if(log) {
83 fprintf(log, "%02d:%02d:%02d ",
84 t->tm_hour, t->tm_min, t->tm_sec);
85 vfprintf(log, fmt, args);
86 fprintf(log, "\n");
87
88 fclose(log);
89 }
90
91 fprintf(stderr, "%02d:%02d:%02d ",
92 t->tm_hour, t->tm_min, t->tm_sec);
93 vfprintf(stderr, fmt, args);
94 fprintf(stderr, "\n");
95 va_end(args);
96}
97
98void init_window ()
99{
100 XGCValues gcv;
101 XWindowAttributes xgwa;
102 char *test_p;
103
104 XGetWindowAttributes (dpy, window, &xgwa);
105
106 color_track.red=65535;
107 color_track.green=65535;
108 color_track.blue=65535;
109
110 color_car.red=65535;
111 color_car.green=65535;
112 color_car.blue=0;
113
114 cmap = xgwa.colormap;
115
116 gcv.function = GXxor;
117 gcv.foreground =
118 get_pixel_resource ("foreground", "Foreground", dpy, cmap);
119 draw_gc = erase_gc = XCreateGC (dpy, window, GCForeground, &gcv);
120 XAllocColor (dpy, cmap, &color_track);
121 XAllocColor (dpy, cmap, &color_car);
122
123 screen_resized(200, 100);
124}
125
126void screen_resized(int width, int height)
127{
128#if 0
129 XWindowAttributes xgwa;
130 XGetWindowAttributes (dpy, window, &xgwa);
131 maxx = ((long)(xgwa.width));
132 maxy = ((long)(xgwa.height));
133#else
134 maxx = width-1;
135 maxy = height-1;
136#endif
137 XSetForeground (dpy, draw_gc, get_pixel_resource ("background", "Background",
138 dpy, cmap));
139 XFillRectangle(dpy, window, draw_gc, 0, 0, width, height);
140
141}
142
143static void help(void)
144{
145 printf(PROGNAME " " ROCKBOXUI_VERSION " " __DATE__ "\n"
146 "usage: " PROGNAME "\n"
147 );
148}
149
150void drawline(int color, int x1, int y1, int x2, int y2)
151{
152 if (color==0) {
153 XSetForeground(dpy, draw_gc,
154 get_pixel_resource("background", "Background", dpy, cmap));
155 }
156 else
157 XSetForeground(dpy, draw_gc,
158 get_pixel_resource("foreground", "Foreground", dpy, cmap));
159
160 XDrawLine(dpy, window, draw_gc,
161 (int)(x1*track_zoom),
162 (int)(y1*track_zoom),
163 (int)(x2*track_zoom),
164 (int)(y2*track_zoom));
165}
166
167void drawdot(int color, int x, int y)
168{
169 if (color==0) {
170 XSetForeground(dpy, draw_gc,
171 get_pixel_resource("background", "Background", dpy, cmap));
172 }
173 else
174 XSetForeground(dpy, draw_gc,
175 get_pixel_resource("foreground", "Foreground", dpy, cmap));
176
177 XDrawPoint(dpy, window, draw_gc, x, y);
178}
179
180void drawdots(int color, XPoint *points, int count)
181{
182 if (color==0) {
183 XSetForeground(dpy, draw_gc,
184 get_pixel_resource("background", "Background", dpy, cmap));
185 }
186 else
187 XSetForeground(dpy, draw_gc,
188 get_pixel_resource("foreground", "Foreground", dpy, cmap));
189
190
191 XDrawPoints(dpy, window, draw_gc, points, count, CoordModeOrigin);
192}
193
194void drawtext(int color, int x, int y, char *text)
195{
196 if (color==0) {
197 XSetForeground(dpy, draw_gc,
198 get_pixel_resource("background", "Background", dpy, cmap));
199 }
200 else
201 XSetForeground(dpy, draw_gc,
202 get_pixel_resource("foreground", "Foreground", dpy, cmap));
203
204 XDrawString(dpy, window, draw_gc, x, y, text, strlen(text));
205}
206
207
208void
209screenhack (Display *the_dpy, Window the_window)
210{
211 unsigned short porttouse=0;
212 char *proxy = NULL;
213 char *url = NULL;
214 int i;
215 char *guiname="Rock-the-box";
216 Bool helpme;
217
218 /* This doesn't work, but I don't know why (Daniel 1999-12-01) */
219 helpme = get_boolean_resource ("help", "Boolean");
220 if(helpme) {
221 help();
222 }
223 printf(PROGNAME " " ROCKBOXUI_VERSION " (" __DATE__ ")\n");
224
225 dpy=the_dpy;
226 window=the_window;
227
228 init_window();
229
230 Logf("Rockbox will kill ya!");
231
232 app_main();
233}
234
235void screen_redraw()
236{
237 int y, x;
238
239 lcd_update();
240
241 /* draw a border around the "Recorder" screen */
242
243#define X1 0
244#define Y1 0
245#define X2 (LCD_WIDTH + MARGIN_X*2)
246#define Y2 (LCD_HEIGHT + MARGIN_Y*2)
247
248 drawline(1, X1, Y1, X2, Y1);
249 drawline(1, X2, Y1, X2, Y2);
250 drawline(1, X1, Y2, X2, Y2);
251 drawline(1, X1, Y1, X1, Y2);
252
253}
diff --git a/uisimulator/x11/utils.h b/uisimulator/x11/utils.h
new file mode 100644
index 0000000000..284bb86dcd
--- /dev/null
+++ b/uisimulator/x11/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/x11/version.h b/uisimulator/x11/version.h
new file mode 100644
index 0000000000..e9e70b675b
--- /dev/null
+++ b/uisimulator/x11/version.h
@@ -0,0 +1 @@
#define ROCKBOXUI_VERSION "0.1"
diff --git a/uisimulator/x11/visual.c b/uisimulator/x11/visual.c
new file mode 100644
index 0000000000..57b73151c5
--- /dev/null
+++ b/uisimulator/x11/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
24extern 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
35static Visual *pick_best_visual (Screen *, Bool, Bool);
36static Visual *pick_mono_visual (Screen *);
37static Visual *pick_best_visual_of_class (Screen *, int);
38static Visual *pick_best_gl_visual (Screen *);
39static Visual *id_to_visual (Screen *, int);
40static 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
51Visual *
52get_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
160Visual *
161get_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
175static Visual *
176pick_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
219static Visual *
220pick_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
243static Visual *
244pick_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
282static Visual *
283pick_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
341static Visual *
342id_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
360int
361visual_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 */
385int
386visual_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
410int
411visual_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
426Bool
427has_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
447void
448describe_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
477int
478screen_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
489int
490visual_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
505Visual *
506find_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/x11/visual.h b/uisimulator/x11/visual.h
new file mode 100644
index 0000000000..dd45708ea0
--- /dev/null
+++ b/uisimulator/x11/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
15extern Visual *get_visual (Screen *, const char *name, Bool, Bool);
16extern Visual *get_visual_resource (Screen *, char *, char *, Bool);
17extern int visual_depth (Screen *, Visual *);
18/* extern int visual_pixmap_depth (Screen *, Visual *); */
19extern int visual_class (Screen *, Visual *);
20extern int visual_cells (Screen *, Visual *);
21extern int screen_number (Screen *);
22extern Visual *find_similar_visual (Screen *, Visual *old);
23extern void describe_visual (FILE *f, Screen *, Visual *, Bool private_cmap_p);
24extern Visual *get_overlay_visual (Screen *, unsigned long *pixel_return);
25extern Bool has_writable_cells (Screen *screen, Visual *visual);
26
27Visual *get_gl_visual (Screen *screen);
28
29#endif /* __VISUAL_H__ */
diff --git a/uisimulator/x11/vroot.h b/uisimulator/x11/vroot.h
new file mode 100644
index 0000000000..ba3e5d29fa
--- /dev/null
+++ b/uisimulator/x11/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)
61static 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
68static Window
69#ifdef __STDC__ /* ANSIfication added by jwz, to avoid superfluous warnings. */
70VirtualRootWindowOfScreen(Screen *screen)
71#else /* !__STDC__ */
72VirtualRootWindowOfScreen(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/x11/xmu.h b/uisimulator/x11/xmu.h
new file mode 100644
index 0000000000..48084f747e
--- /dev/null
+++ b/uisimulator/x11/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
12int XmuPrintDefaultErrorMessage (Display *dpy, XErrorEvent *event, FILE *fp);
13
14#endif /* __XMU_H__ */