*** empty log message ***
authorpcg <pcg>
Mon, 24 Nov 2003 17:28:07 +0000 (17:28 +0000)
committerpcg <pcg>
Mon, 24 Nov 2003 17:28:07 +0000 (17:28 +0000)
200 files changed:
.cvsignore [new file with mode: 0644]
.prebuild [new file with mode: 0644]
INSTALL [new file with mode: 0644]
Makefile.in
README.configure [new file with mode: 0644]
README.unicode [new file with mode: 0644]
W11/Makefile.in [new file with mode: 0644]
W11/Makefile.xpm [new file with mode: 0644]
W11/X11/Intrinsic.h [new file with mode: 0644]
W11/X11/Xatom.h [new file with mode: 0644]
W11/X11/Xlib.h [new file with mode: 0644]
W11/X11/Xlocale.h [new file with mode: 0644]
W11/X11/Xmd.h [new file with mode: 0644]
W11/X11/Xutil.h [new file with mode: 0644]
W11/X11/cursorfont.h [new file with mode: 0644]
W11/X11/keysym.h [new file with mode: 0644]
W11/X11/keysymdef.h [new file with mode: 0644]
W11/w32/Makefile [new file with mode: 0644]
W11/w32/event.c [new file with mode: 0644]
W11/w32/ntdef.h [new file with mode: 0644]
W11/w32/ntutil.c [new file with mode: 0644]
W11/w32/xlib.c [new file with mode: 0644]
W11/wrap/Makefile [new file with mode: 0644]
W11/wrap/mkproxy.pl [new file with mode: 0644]
W11/wrap/rxtv.ico [new file with mode: 0644]
W11/wrap/rxvt.ico [new file with mode: 0644]
W11/wrap/rxvt.rc [new file with mode: 0644]
W11/wrap/wrap.c [new file with mode: 0644]
W11/wrap/wrap.h [new file with mode: 0644]
W11/wrap/xwrappers.gen [new file with mode: 0644]
autoconf/.cvsignore [new file with mode: 0644]
autoconf/Make.common.in [new file with mode: 0644]
autoconf/aclocal.m4
autoconf/config.guess [new file with mode: 0644]
autoconf/config.h.in [new file with mode: 0644]
autoconf/config.sub [new file with mode: 0644]
autoconf/configure.in
autoconf/install-sh [new file with mode: 0644]
autoconf/libtool.m4 [new file with mode: 0644]
autoconf/ltmain.sh [new file with mode: 0644]
autoconf/mkinstalldirs [new file with mode: 0644]
autoconf/xpm.m4
configure [new file with mode: 0755]
doc/.cvsignore [new file with mode: 0644]
doc/BUGS [new file with mode: 0644]
doc/FAQ [new file with mode: 0644]
doc/LSM.in [new file with mode: 0644]
doc/Makefile.in
doc/README.greek [new file with mode: 0644]
doc/README.menu [new file with mode: 0644]
doc/README.xvt [new file with mode: 0644]
doc/TODO [new file with mode: 0644]
doc/changes.txt [new file with mode: 0644]
doc/etc/XTerm.ad [new file with mode: 0644]
doc/etc/rclock [new file with mode: 0644]
doc/etc/rxvt.termcap [new file with mode: 0644]
doc/etc/rxvt.terminfo [new file with mode: 0644]
doc/menu/example.menu [new file with mode: 0644]
doc/menu/jedmenu.sl [new file with mode: 0644]
doc/menu/menu [new file with mode: 0644]
doc/menu/rxvt.menu [new file with mode: 0644]
doc/menu/rxvt.zh-menu [new file with mode: 0644]
doc/menu/terminal.menu [new file with mode: 0644]
doc/rxvt.1 [new file with mode: 0644]
doc/rxvt.tbl [new file with mode: 0644]
doc/rxvtRef-frame.html [new file with mode: 0644]
doc/rxvtRef-toc.html [new file with mode: 0644]
doc/xterm.seq [new file with mode: 0644]
doc/yodl/.cvsignore [new file with mode: 0644]
doc/yodl/masonyodl.yo
doc/yodl/rxvt-colours.yo
doc/yodl/rxvt-environment.yo
doc/yodl/rxvt-files.yo
doc/yodl/rxvt-fonts.yo
doc/yodl/rxvt-login.yo
doc/yodl/rxvt-mousereporting.yo
doc/yodl/rxvt-options.yo
doc/yodl/rxvt-resources.yo
doc/yodl/rxvt-scrollbar.yo
doc/yodl/rxvt-textselection.yo
doc/yodl/rxvt.yo
doc/yodl/rxvtRef-csi.yo
doc/yodl/rxvtRef-definitions.yo
doc/yodl/rxvtRef-graphics.yo
doc/yodl/rxvtRef-keycodes.yo
doc/yodl/rxvtRef-menubar.yo
doc/yodl/rxvtRef-mouse.yo
doc/yodl/rxvtRef-privatemodes.yo
doc/yodl/rxvtRef-sequences.yo
doc/yodl/rxvtRef-values.yo
doc/yodl/rxvtRef-xpm.yo
doc/yodl/rxvtRef-xterm.yo
doc/yodl/rxvtRef.yo
doc/yodl/versioninfo.yo [new file with mode: 0644]
doc/yodl/versioninfo.yo.in
doc/yodl/versionyodl.yo [new file with mode: 0644]
reconf [new file with mode: 0755]
src/.cvsignore [new file with mode: 0644]
src/.indent.pro [new file with mode: 0644]
src/Makefile.in
src/callback.h [new file with mode: 0644]
src/command.C
src/command.h
src/defaultfont.C [new file with mode: 0644]
src/defaultfont.h
src/dist [new file with mode: 0644]
src/encoding.C [new file with mode: 0644]
src/encoding.h [new file with mode: 0644]
src/feature.h
src/gcc-Wall [new file with mode: 0644]
src/gentables [new file with mode: 0755]
src/graphics.C
src/graphics/.cvsignore [new file with mode: 0644]
src/graphics/Makefile.in
src/graphics/README [new file with mode: 0644]
src/graphics/data [new file with mode: 0644]
src/graphics/grxlib.c
src/graphics/grxlib.h
src/graphics/qplot.c
src/grkelot.C
src/grkelot.h
src/init.C
src/init.h
src/iom.C [new file with mode: 0644]
src/iom.h [new file with mode: 0644]
src/logging.C
src/logging.h
src/main.C
src/makeextprotos-awk [new file with mode: 0644]
src/makeextprotos-sed
src/makeintprotos-awk [new file with mode: 0644]
src/makeintprotos-sed
src/menubar.C
src/menubar.h
src/misc.C
src/netdisp.C
src/netdisp.h [new file with mode: 0644]
src/protos.h
src/ptytty.C
src/rxvt.C [new file with mode: 0644]
src/rxvt.h
src/rxvtc.C [new file with mode: 0644]
src/rxvtcolor.C [new file with mode: 0644]
src/rxvtcolor.h [new file with mode: 0644]
src/rxvtd.C [new file with mode: 0644]
src/rxvtdaemon.C [new file with mode: 0644]
src/rxvtdaemon.h [new file with mode: 0644]
src/rxvtgrx.h
src/rxvtlib.h.in
src/rxvtvec.C [new file with mode: 0644]
src/rxvtvec.h [new file with mode: 0644]
src/screen.C
src/scrollbar-next.C
src/scrollbar-rxvt.C
src/scrollbar-xterm.C
src/scrollbar.C
src/simplevec.h [new file with mode: 0644]
src/strings.C
src/table/big5_ext.h [new file with mode: 0644]
src/table/big5_plus.h [new file with mode: 0644]
src/table/cns11643_1992_1.h [new file with mode: 0644]
src/table/cns11643_1992_2.h [new file with mode: 0644]
src/table/cns11643_1992_3.h [new file with mode: 0644]
src/table/cns11643_1992_4.h [new file with mode: 0644]
src/table/cns11643_1992_5.h [new file with mode: 0644]
src/table/cns11643_1992_6.h [new file with mode: 0644]
src/table/cns11643_1992_7.h [new file with mode: 0644]
src/table/cns11643_1992_f.h [new file with mode: 0644]
src/table/gb2312_1980_0.h [new file with mode: 0644]
src/table/iso8859_1.h [new file with mode: 0644]
src/table/iso8859_10.h [new file with mode: 0644]
src/table/iso8859_11.h [new file with mode: 0644]
src/table/iso8859_13.h [new file with mode: 0644]
src/table/iso8859_14.h [new file with mode: 0644]
src/table/iso8859_15.h [new file with mode: 0644]
src/table/iso8859_16.h [new file with mode: 0644]
src/table/iso8859_2.h [new file with mode: 0644]
src/table/iso8859_3.h [new file with mode: 0644]
src/table/iso8859_4.h [new file with mode: 0644]
src/table/iso8859_5.h [new file with mode: 0644]
src/table/iso8859_6.h [new file with mode: 0644]
src/table/iso8859_7.h [new file with mode: 0644]
src/table/iso8859_8.h [new file with mode: 0644]
src/table/iso8859_9.h [new file with mode: 0644]
src/table/jis0201_1976_0.h [new file with mode: 0644]
src/table/jis0208_1983_0.h [new file with mode: 0644]
src/table/jis0212_1990_0.h [new file with mode: 0644]
src/table/jis0213_1.h [new file with mode: 0644]
src/table/jis0213_2.h [new file with mode: 0644]
src/table/koi8_r.h [new file with mode: 0644]
src/table/koi8_u.h [new file with mode: 0644]
src/table/ksc5601_1987_0.h [new file with mode: 0644]
src/table/viscii.h [new file with mode: 0644]
src/test/.cvsignore [new file with mode: 0644]
src/test/Makefile.in [new file with mode: 0644]
src/test/gettty.c [new file with mode: 0644]
src/test/strings-memmove.c [new file with mode: 0644]
src/version.h [new file with mode: 0644]
src/xdefaults.C
src/xpm.C

diff --git a/.cvsignore b/.cvsignore
new file mode 100644 (file)
index 0000000..90d7c69
--- /dev/null
@@ -0,0 +1,9 @@
+ChangeLog
+config.cache
+config.h
+config.log
+config.status
+configure
+libtool
+Makefile
+*.lsm
diff --git a/.prebuild b/.prebuild
new file mode 100644 (file)
index 0000000..1a94765
--- /dev/null
+++ b/.prebuild
@@ -0,0 +1,31 @@
+#!/bin/sh
+
+#
+# run autoheader
+#
+newah=0
+autoheader --version | grep -q autoheader && newah=1
+
+if test $newah = 1; then
+  cmd="autoheader --include=autoconf autoconf/configure.in"
+else
+  cmd="autoheader --localdir=autoconf autoconf/configure.in > autoconf/config.h.in"
+fi
+echo $cmd
+eval $cmd
+chmod 644 autoconf/config.h.in
+
+#
+# run autoconf
+#
+newac=0
+autoconf --version | grep -q autoconf && newac=1
+
+if test $newac = 1; then
+  cmd="autoconf --include=autoconf autoconf/configure.in > configure"
+else
+  cmd="autoconf --localdir=autoconf autoconf/configure.in > configure"
+fi
+echo $cmd
+eval $cmd
+chmod 755 configure
diff --git a/INSTALL b/INSTALL
new file mode 100644 (file)
index 0000000..998a263
--- /dev/null
+++ b/INSTALL
@@ -0,0 +1,91 @@
+--------------------------------------------------------------------------
+Using GNU autoconfig
+--------------------------------------------------------------------------
+  1.   If you retrieved a CVS version of this package, you need the GNU
+       autoconf package to generate the configure script.  This is done
+       by running   ./.prebuild   in this directory which will automatically
+       run autoconf with the appropriate options.
+
+  2.   Run   ./configure   to generate config.h and the various Makefiles.
+       ./configure --help   gives a list of possible options with slightly
+       longer descriptions in README.configure
+
+       Note that configure options have changed since 2.6.x series.
+
+       Some systems require unusual options for compilation or linking that
+       the `configure' script does not know about.  You can give `configure'
+       initial values for variables by setting them in the environment.  Using
+       a Bourne-compatible shell, you can do that on the command line like
+       this:
+               CC=c89 CFLAGS=-O2 LIBS=-lposix ./configure
+       Or on systems that have the `env' program, you can do it like this:
+               env CPPFLAGS=-I/usr/local/include LDFLAGS=-s ./configure
+       Or if you're using a non Bourne-compatible shell, you can do:
+               sh -c 'CFLAGS="-O2 -g" ./configure
+
+       If you are making different versions of rxvt you can configure them
+       to be installed with different names using configure arguments, e.g.
+       ./configure --enable-languages --program-transform-name='s,rxvt,kxvt,;'
+
+  3.   set any other main preferences:
+           Edit "src/feature.h"
+           Edit "config.h"   if you didn't use ./configure options
+           If you're cross-compiling, edit the following in "config.h"
+               NO_XLOCALE
+               SIZEOF_*        # sizeof some types
+
+  4.   Build it (repeat step 2 as desired):
+           make
+
+  5.   build rclock (small xclock with biff & appointments) and
+       optionally edit rclock/feature.h to add/remove features:
+           make clock
+
+  6.   Install both rxvt and rclock:
+           make install
+
+       or install them separately
+           (cd src; make install)
+           (cd rclock; make install)
+
+       you may also want to install doc/etc/rxvt.terminfo and 
+       doc/etc/rxvt.termcap
+
+  7 a. If compiled with UTMP_SUPPORT, you may need to install rxvt setuid
+       root or setuid/setgid to match the file permissions on /etc/utmp
+  7 b.  You may need to install setuid root anyway for some systems so that
+       they can give you ownership of the tty devices.
+
+  8.   On systems which dislike doc/rxvt.1
+           (cd doc; rm rxvt.1; make rxvt.1)
+
+                ===================================
+
+NB:    If you were able to compile OK but running rxvt prints out
+               "rxvt: could not obtain control of tty"
+       running "make tests" from this directory (or from src/test)
+       should give you a breakdown of the failure point which is
+       useful to the developers in fixing the problem
+
+NB:    SunOS (with/without gcc?) gets reported by configure as
+
+               #undef STDC_HEADERS
+               #define HAVE_SYS_IOCTL_H 1
+
+       but the ioctl() defines aren't protected against multiple
+       inclusion, in this case by <termios.h> so use a hack in
+       "feature.h" to avoid the problem.
+
+       Gave up checking for `STDC_HEADERS', since they really should be
+       there and I don't want to deal with the problems when they don't
+       exist.
+
+       SunOS users might complain to the right places and get their
+       system headers fixed so that one day the rest of us won't have
+       to keep compensating :(
+
+       SVR4 users (that aren't using gcc) will have to add -DSVR4 to
+       CPPFLAGS for configure.
+
+--
+EOF
index 55266f5..91d5283 100644 (file)
@@ -1,5 +1,5 @@
 # ./Makefile.in                        -*- Makefile -*-
-# $Id: Makefile.in,v 1.1 2003-11-24 17:28:07 pcg Exp $
+# $Id: Makefile.in,v 1.2 2003-11-24 17:31:26 pcg Exp $
 @MCOMMON@
 
 srcdir =       @srcdir@
diff --git a/README.configure b/README.configure
new file mode 100644 (file)
index 0000000..d60f764
--- /dev/null
@@ -0,0 +1,125 @@
+--enable-everything
+       add support for all enable options marked with an asterisk listed
+       in "./configure --help".  Note that unlike other enable options this
+       is order dependant.  You can specify this and then disable options
+       which this enables by _following_ this with the appropriate
+       commands.
+--enable-languages
+       add support for languages which require multiple character glyphs
+       to display.
+--with-encoding=NAME
+       set the default encoding for multi-char glyph languages to NAME.
+       Options are: "eucj" EUC Japanese encoding; "sjis" Shift JIS encoding;
+       "big5" BIG5 encoding; "gb" GB encoding; "kr" EUC Korean encoding;
+       "noenc" no encoding.  This option requires --enable-languages to
+       also be specified.
+--enable-utmp
+       write user and tty to utmp file (used by programs like ``w'') at
+       start of rxvt execution and delete information when rxvt exits.
+--enable-wtmp
+       write user and tty to wtmp file (used by programs like ``last'') at
+       start of rxvt execution and write logout when rxvt exits.  This
+       option requires --enable-utmp to also be specified.
+--enable-lastlog
+       write user and tty to lastlog file (used by programs like
+       ``lastlogin'') at start of rxvt execution.  This option requires
+       --enable-utmp to also be specified.
+--enable-xpm-background
+       add support for XPM background pixmaps
+--enable-transparency
+       add support for inheriting parent backgrounds thus giving a fake
+       transparency to the term
+--enable-menubar
+       add support for our menu bar system
+--enable-graphics
+       add support for our graphics mode (see src/graphics)
+--enable-rxvt-scroll
+       add support for the original rxvt scrollbar
+--enable-next-scroll
+       add support for a NeXT-like scrollbar
+--enable-xterm-scroll
+       add support for an Xterm-like scrollbar
+--enable-half-shadow
+       make shadows on the scrollbar only half the normal width & height.
+       only applicable to rxvt scrollbars
+--enable-xim
+       add support for XIM (X Input Method) protocol.  This allows using
+       alternative input methods (e.g. kinput2) and will also correctly
+       set up the input for people using dead keys.
+--enable-greek
+       add support for greek keyboard
+--enable-ttygid
+       change tty device setting to group "tty" - only use this if
+        your system uses this type of security
+--disable-backspace-key
+       disable any handling of the backspace key by us - let the X server
+       do it
+--disable-delete-key
+       disable any handling of the delete key by us - let the X server
+       do it
+--disable-resources
+       remove all resources checking
+--enable-xgetdefault
+       make resources checking via XGetDefault() instead of our small
+       version which only checks ~/.Xdefaults, or if that doesn't exist
+       then ~/.Xresources
+--enable-strings
+       add support for our possibly faster memset() function and other
+       various routines, overriding your system's versions which may
+       have been hand-crafted in assembly or may require extra libraries
+       to link in.  (This has header problems on some Linux systems).
+--disable-swapscreen
+       remove support for swap screen
+--enable-frills
+       add support for some lesser used features
+--enable-linespace
+       add support to provide user specified line spacing between text rows
+--enable-keepscrolling
+       add support for continual scrolling of the display when you hold
+       the mouse button down on a scrollbar arrow
+--enable-mousewheel
+       add support for scrolling via mouse wheel or buttons 4 & 5
+-enable-slipwheeling
+       add support for continual scrolling (using the mouse wheel as an
+       accelerator) while the control key is held down.  This option
+       requires --enable-mousewheel to also be specified.
+--enable-old-selection
+       remove support for reverting the mouse selection style to that
+       of v2.20 (and prior)
+--disable-new-selection
+       remove support for mouse selection style like that of xterm
+--enable-dmalloc
+       use Gray Watson's malloc - which is good for debugging
+       See  http://www.letters.com/dmalloc/  for details
+        If you use either this or the next option, you may need to
+       edit src/Makefile after compiling to point DINCLUDE and DLIB to
+       the right places.
+        You can only use either this option and the following (should
+       you use either) 
+--enable-dlmalloc
+       use Doug Lea's malloc - which is good for a production version
+       See  http://g.oswego.edu/dl/html/malloc.html  for details
+--enable-smart-resize
+       add smart growth/shrink behaviour when changing font size
+       via from hot keys.  This should keep in a fixed position the
+       rxvt corner which is closest to a corner of the screen
+--enable-256-color
+       add support for 256 colours rather than the base 16 colours
+--enable-cursor-blink
+       add support for a blinking cursor
+--enable-pointer-blank
+       add support to have the pointer disappear when typing or inactive
+--with-term=NAME
+       change the environmental variable for the terminal to NAME
+       (default "xterm")
+--with-terminfo=PATH
+       change the environmental variable for the path to the terminfo
+       tree to PATH
+--with-x
+       use the X Window System (pretty much default, eh?)
+--with-xpm-includes=DIR
+       look for the XPM includes in DIR
+--with-xpm-library=DIR
+       look for the XPM library in DIR
+--with-xpm
+       not needed - define via --enable-xpm-background
diff --git a/README.unicode b/README.unicode
new file mode 100644 (file)
index 0000000..b2116d1
--- /dev/null
@@ -0,0 +1,40 @@
+Sketchy overview of the details:
+
+- gcc is probably required to compile this release, g++, too, as it has
+  been re-written in C++.
+
+- the options used in the ./reconf script should work. everything else
+  might be broken.
+
+- wchar_t MUST be UNICODE or ISO-10646-1 on your system, or various
+  things will break down.
+
+- rxvt ALWAYS expects utf-8 input, regardless of the locale, currently.
+  so only start it in a utf-8-locale: "LC_CTYPE=en_US.UTF-8 rxvt" etc..
+
+- "-fn" commandline switch and *.font ressource accepts a comma
+  seperated list of fontnames:
+
+  x:9x15bold                   a x11 font
+  9x15bold                     the same
+  xft:Andale Mono              a xft font
+  xft:Andale Mono:pixelsize=20
+
+- the _first_ font in the list selects the cell width/height. All other fonts
+  must be smaller or same sized, or they will be ignored or worse. xft fonts
+  will automatically be rescaled.
+
+- the fonts will be tried in the order given when searching for a font
+  to display a specific character. if you are e.g. mainly interested in
+  japanese you might want to put a japanese font first to get the ascii
+  characters in it. If you are mainly interested in a text terminal and
+  only want to display other characters you should put a ascii/is8859 text
+  font first (e.g. "9x15bold") and let rxvt sort it out.
+
+- xft fonts require gobs of memory and generally are slow
+
+- src/defaultfont.C lists the fallback fonts that are tried when a character cannot
+  be displayed with the current list of fonts.
+
+Marc <rxvt@plan9.de>
+
diff --git a/W11/Makefile.in b/W11/Makefile.in
new file mode 100644 (file)
index 0000000..fae5f40
--- /dev/null
@@ -0,0 +1,59 @@
+
+@MCOMMON@
+
+srcdir =       @srcdir@
+VPATH =                @srcdir@
+.PATH:         @srcdir@
+
+top_builddir = ..
+basedir = ..
+thisdir = W11
+XPMDIR=xpm-3.4k
+MKDIR = @top_srcdir@/autoconf/mkinstalldirs
+
+first_rule: all
+
+all allbin alldoc:
+       -mkdir lib
+       cd wrap; make $@
+       cd w32; make $@
+       if test -d $(XPMDIR); then make -f Makefile.xpm; fi
+
+tags clean:
+       cd wrap; make $@
+       cd w32; make $@
+       if test -d $(XPMDIR); then make -f Makefile.xpm $@; fi
+
+realclean: clean
+
+cleandir: realclean
+
+install:
+       $(INSTALL_PROGRAM) lib/libW11.dll $(bindir)/libW11.dll
+
+#
+# Distribution variables
+#
+
+DIST = Makefile.in Makefile.xpm
+DISTX11 = X11/Intrinsic.h X11/Xatom.h X11/Xlib.h X11/Xlocale.h X11/Xmd.h \
+       X11/Xutil.h X11/cursorfont.h X11/keysym.h X11/keysymdef.h
+DISTw32 = w32/Makefile w32/event.c w32/ntdef.h w32/ntutil.c w32/xlib.c
+DISTwrap = wrap/Makefile wrap/mkproxy.pl wrap/rxtv.ico wrap/rxvt.ico \
+       wrap/rxvt.rc wrap/wrap.c wrap/wrap.h wrap/xwrappers.gen
+
+distclean: realclean
+       if test $(srcdir) = .; then $(MAKE) realclean; fi
+       (cd $(srcdir); $(RMF) Makefile)
+
+distdirs:
+       mkdir $(basedir)/../$(VERNAME)/$(thisdir)
+       mkdir $(basedir)/../$(VERNAME)/$(thisdir)/X11
+       mkdir $(basedir)/../$(VERNAME)/$(thisdir)/w32
+       mkdir $(basedir)/../$(VERNAME)/$(thisdir)/wrap
+
+distcopy:
+       $(CP) -p $(DIST) $(basedir)/../$(VERNAME)/$(thisdir)
+       $(CP) -p $(DISTX11) $(basedir)/../$(VERNAME)/$(thisdir)/X11
+       $(CP) -p $(DISTw32) $(basedir)/../$(VERNAME)/$(thisdir)/w32
+       $(CP) -p $(DISTwrap) $(basedir)/../$(VERNAME)/$(thisdir)/wrap
diff --git a/W11/Makefile.xpm b/W11/Makefile.xpm
new file mode 100644 (file)
index 0000000..4da06a5
--- /dev/null
@@ -0,0 +1,8 @@
+first_rule: all
+
+all allbin alldoc:
+       -mkdir lib
+       cd xpm-3.4k/lib; make -f Makefile.noX CC=gcc INCLUDES=-I../.. DESTLIBDIR=../../lib DESTINCLUDEDIR=../../X11 all install
+
+tags clean:
+       cd xpm-3.4k/lib; make -f Makefile.noX $@
diff --git a/W11/X11/Intrinsic.h b/W11/X11/Intrinsic.h
new file mode 100644 (file)
index 0000000..7d6a67a
--- /dev/null
@@ -0,0 +1,2 @@
+#include <X11/xlib.h>
+
diff --git a/W11/X11/Xatom.h b/W11/X11/Xatom.h
new file mode 100644 (file)
index 0000000..485a423
--- /dev/null
@@ -0,0 +1,79 @@
+#ifndef XATOM_H
+#define XATOM_H 1
+
+/* THIS IS A GENERATED FILE
+ *
+ * Do not change!  Changing this file implies a protocol change!
+ */
+
+#define XA_PRIMARY ((Atom) 1)
+#define XA_SECONDARY ((Atom) 2)
+#define XA_ARC ((Atom) 3)
+#define XA_ATOM ((Atom) 4)
+#define XA_BITMAP ((Atom) 5)
+#define XA_CARDINAL ((Atom) 6)
+#define XA_COLORMAP ((Atom) 7)
+#define XA_CURSOR ((Atom) 8)
+#define XA_CUT_BUFFER0 ((Atom) 9)
+#define XA_CUT_BUFFER1 ((Atom) 10)
+#define XA_CUT_BUFFER2 ((Atom) 11)
+#define XA_CUT_BUFFER3 ((Atom) 12)
+#define XA_CUT_BUFFER4 ((Atom) 13)
+#define XA_CUT_BUFFER5 ((Atom) 14)
+#define XA_CUT_BUFFER6 ((Atom) 15)
+#define XA_CUT_BUFFER7 ((Atom) 16)
+#define XA_DRAWABLE ((Atom) 17)
+#define XA_FONT ((Atom) 18)
+#define XA_INTEGER ((Atom) 19)
+#define XA_PIXMAP ((Atom) 20)
+#define XA_POINT ((Atom) 21)
+#define XA_RECTANGLE ((Atom) 22)
+#define XA_RESOURCE_MANAGER ((Atom) 23)
+#define XA_RGB_COLOR_MAP ((Atom) 24)
+#define XA_RGB_BEST_MAP ((Atom) 25)
+#define XA_RGB_BLUE_MAP ((Atom) 26)
+#define XA_RGB_DEFAULT_MAP ((Atom) 27)
+#define XA_RGB_GRAY_MAP ((Atom) 28)
+#define XA_RGB_GREEN_MAP ((Atom) 29)
+#define XA_RGB_RED_MAP ((Atom) 30)
+#define XA_STRING ((Atom) 31)
+#define XA_VISUALID ((Atom) 32)
+#define XA_WINDOW ((Atom) 33)
+#define XA_WM_COMMAND ((Atom) 34)
+#define XA_WM_HINTS ((Atom) 35)
+#define XA_WM_CLIENT_MACHINE ((Atom) 36)
+#define XA_WM_ICON_NAME ((Atom) 37)
+#define XA_WM_ICON_SIZE ((Atom) 38)
+#define XA_WM_NAME ((Atom) 39)
+#define XA_WM_NORMAL_HINTS ((Atom) 40)
+#define XA_WM_SIZE_HINTS ((Atom) 41)
+#define XA_WM_ZOOM_HINTS ((Atom) 42)
+#define XA_MIN_SPACE ((Atom) 43)
+#define XA_NORM_SPACE ((Atom) 44)
+#define XA_MAX_SPACE ((Atom) 45)
+#define XA_END_SPACE ((Atom) 46)
+#define XA_SUPERSCRIPT_X ((Atom) 47)
+#define XA_SUPERSCRIPT_Y ((Atom) 48)
+#define XA_SUBSCRIPT_X ((Atom) 49)
+#define XA_SUBSCRIPT_Y ((Atom) 50)
+#define XA_UNDERLINE_POSITION ((Atom) 51)
+#define XA_UNDERLINE_THICKNESS ((Atom) 52)
+#define XA_STRIKEOUT_ASCENT ((Atom) 53)
+#define XA_STRIKEOUT_DESCENT ((Atom) 54)
+#define XA_ITALIC_ANGLE ((Atom) 55)
+#define XA_X_HEIGHT ((Atom) 56)
+#define XA_QUAD_WIDTH ((Atom) 57)
+#define XA_WEIGHT ((Atom) 58)
+#define XA_POINT_SIZE ((Atom) 59)
+#define XA_RESOLUTION ((Atom) 60)
+#define XA_COPYRIGHT ((Atom) 61)
+#define XA_NOTICE ((Atom) 62)
+#define XA_FONT_NAME ((Atom) 63)
+#define XA_FAMILY_NAME ((Atom) 64)
+#define XA_FULL_NAME ((Atom) 65)
+#define XA_CAP_HEIGHT ((Atom) 66)
+#define XA_WM_CLASS ((Atom) 67)
+#define XA_WM_TRANSIENT_FOR ((Atom) 68)
+
+#define XA_LAST_PREDEFINED ((Atom) 68)
+#endif /* XATOM_H */
diff --git a/W11/X11/Xlib.h b/W11/X11/Xlib.h
new file mode 100644 (file)
index 0000000..d512816
--- /dev/null
@@ -0,0 +1,2246 @@
+/* 
+
+Copyright 1985, 1986, 1987, 1991, 1998  The Open Group
+
+All Rights Reserved.
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of The Open Group shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from The Open Group.
+
+*/
+
+#ifndef __XLIB_H
+#define __XLIB_H
+
+/* typedef struct _XrmHashBucketRec; */
+typedef unsigned long Atom;
+typedef unsigned long Time;
+typedef unsigned long XID;
+
+#ifndef Bool
+#define Bool int
+#endif
+
+typedef int BoolDef;
+
+typedef XID Window;
+typedef XID Drawable;
+typedef XID Font;
+typedef XID Pixmap;
+typedef XID Cursor;
+typedef XID Colormap;
+typedef XID KeySym;
+typedef XID GContext;
+
+typedef unsigned char KeyCode;
+
+typedef char *XPointer;
+typedef unsigned long VisualID;
+
+#define PIXEL_ALREADY_TYPEDEFED
+typedef unsigned long Pixel;
+
+#define XDestroyImage(ximage) \
+       ((*((ximage)->f.destroy_image))((ximage)))
+#define XPutPixel(ximage, x, y, pixel) \
+       ((*((ximage)->f.put_pixel))((ximage), (x), (y), (pixel)))
+
+#define AllPlanes              ((unsigned long)~0L)
+#define ScreenOfDisplay(dpy, scr)(&((_XPrivDisplay)dpy)->screens[scr])
+#define DefaultVisual(dpy, scr) (ScreenOfDisplay(dpy,scr)->root_visual)
+#define DefaultDepth(dpy, scr)         (ScreenOfDisplay(dpy,scr)->root_depth)
+#define DefaultColormap(dpy, scr)(ScreenOfDisplay(dpy,scr)->cmap)
+#define DefaultScreen(dpy)     (((_XPrivDisplay)dpy)->default_screen)
+#define BlackPixel(dpy, scr)   (ScreenOfDisplay(dpy,scr)->black_pixel)
+#define WhitePixel(dpy, scr)   (ScreenOfDisplay(dpy,scr)->white_pixel)
+#define RootWindow(dpy, scr)   (ScreenOfDisplay(dpy,scr)->root)
+#define DefaultRootWindow(dpy)         (ScreenOfDisplay(dpy,DefaultScreen(dpy))->root)
+#define DisplayWidth(dpy, scr)         (ScreenOfDisplay(dpy,scr)->width)
+#define DisplayHeight(dpy, scr) (ScreenOfDisplay(dpy,scr)->height)
+
+#ifndef None
+#define None                 0L        /* universal null resource or null atom */
+#endif
+
+#define ParentRelative       1L        
+#define CopyFromParent       0L        
+#define PointerWindow        0L        /* destination window in SendEvent */
+#define InputFocus           1L        /* destination window in SendEvent */
+#define PointerRoot          1L        /* focus window in SetInputFocus */
+#define AnyPropertyType      0L        /* special Atom, passed to GetProperty */
+#define AnyKey              0L /* special Key Code, passed to GrabKey */
+#define AnyButton            0L        /* special Button Code, passed to GrabButton */
+#define AllTemporary         0L        /* special Resource ID passed to KillClient */
+#define CurrentTime          0L        /* special Time */
+#define NoSymbol            0L /* special KeySym */
+#define NoEventMask                    0L
+#define KeyPressMask                   (1L<<0)  
+#define KeyReleaseMask                 (1L<<1)  
+#define ButtonPressMask                        (1L<<2)  
+#define ButtonReleaseMask              (1L<<3)  
+#define EnterWindowMask                        (1L<<4)  
+#define LeaveWindowMask                        (1L<<5)  
+#define PointerMotionMask              (1L<<6)  
+#define PointerMotionHintMask          (1L<<7)  
+#define Button1MotionMask              (1L<<8)  
+#define Button2MotionMask              (1L<<9)  
+#define Button3MotionMask              (1L<<10) 
+#define Button4MotionMask              (1L<<11) 
+#define Button5MotionMask              (1L<<12) 
+#define ButtonMotionMask               (1L<<13) 
+#define KeymapStateMask                        (1L<<14)
+#define ExposureMask                   (1L<<15) 
+#define VisibilityChangeMask           (1L<<16) 
+#define StructureNotifyMask            (1L<<17) 
+#define ResizeRedirectMask             (1L<<18) 
+#define SubstructureNotifyMask         (1L<<19) 
+#define SubstructureRedirectMask       (1L<<20) 
+#define FocusChangeMask                        (1L<<21) 
+#define PropertyChangeMask             (1L<<22) 
+#define ColormapChangeMask             (1L<<23) 
+#define OwnerGrabButtonMask            (1L<<24) 
+#define KeyPress               2
+#define KeyRelease             3
+#define ButtonPress            4
+#define ButtonRelease          5
+#define MotionNotify           6
+#define EnterNotify            7
+#define LeaveNotify            8
+#define FocusIn                        9
+#define FocusOut               10
+#define KeymapNotify           11
+#define Expose                 12
+#define GraphicsExpose         13
+#define NoExpose               14
+#define VisibilityNotify       15
+#define CreateNotify           16
+#define DestroyNotify          17
+#define UnmapNotify            18
+#define MapNotify              19
+#define MapRequest             20
+#define ReparentNotify         21
+#define ConfigureNotify                22
+#define ConfigureRequest       23
+#define GravityNotify          24
+#define ResizeRequest          25
+#define CirculateNotify                26
+#define CirculateRequest       27
+#define PropertyNotify         28
+#define SelectionClear         29
+#define SelectionRequest       30
+#define SelectionNotify                31
+#define ColormapNotify         32
+#define ClientMessage          33
+#define MappingNotify          34
+#define LASTEvent              35      /* must be bigger than any event # */
+#define ShiftMask              (1<<0)
+#define LockMask               (1<<1)
+#define ControlMask            (1<<2)
+#define Mod1Mask               (1<<3)
+#define Mod2Mask               (1<<4)
+#define Mod3Mask               (1<<5)
+#define Mod4Mask               (1<<6)
+#define Mod5Mask               (1<<7)
+#define ShiftMapIndex          0
+#define LockMapIndex           1
+#define ControlMapIndex                2
+#define Mod1MapIndex           3
+#define Mod2MapIndex           4
+#define Mod3MapIndex           5
+#define Mod4MapIndex           6
+#define Mod5MapIndex           7
+#define Button1Mask            (1<<8)
+#define Button2Mask            (1<<9)
+#define Button3Mask            (1<<10)
+#define Button4Mask            (1<<11)
+#define Button5Mask            (1<<12)
+#define AnyModifier            (1<<15)  /* used in GrabButton, GrabKey */
+#define Button1                        1
+#define Button2                        2
+#define Button3                        3
+#define Button4                        4
+#define Button5                        5
+#define NotifyNormal           0
+#define NotifyGrab             1
+#define NotifyUngrab           2
+#define NotifyWhileGrabbed     3
+#define NotifyHint             1       /* for MotionNotify events */
+#define NotifyAncestor         0
+#define NotifyVirtual          1
+#define NotifyInferior         2
+#define NotifyNonlinear                3
+#define NotifyNonlinearVirtual 4
+#define NotifyPointer          5
+#define NotifyPointerRoot      6
+#define NotifyDetailNone       7
+#define VisibilityUnobscured           0
+#define VisibilityPartiallyObscured    1
+#define VisibilityFullyObscured                2
+#define PlaceOnTop             0
+#define PlaceOnBottom          1
+#define FamilyInternet         0
+#define FamilyDECnet           1
+#define FamilyChaos            2
+#define PropertyNewValue       0
+#define PropertyDelete         1
+#define ColormapUninstalled    0
+#define ColormapInstalled      1
+#define GrabModeSync           0
+#define GrabModeAsync          1
+#define GrabSuccess            0
+#define AlreadyGrabbed         1
+#define GrabInvalidTime                2
+#define GrabNotViewable                3
+#define GrabFrozen             4
+#define AsyncPointer           0
+#define SyncPointer            1
+#define ReplayPointer          2
+#define AsyncKeyboard          3
+#define SyncKeyboard           4
+#define ReplayKeyboard         5
+#define AsyncBoth              6
+#define SyncBoth               7
+#define RevertToNone           (int)None
+#define RevertToPointerRoot    (int)PointerRoot
+#define RevertToParent         2
+#define Success                   0    /* everything's okay */
+#define BadRequest        1    /* bad request code */
+#define BadValue          2    /* int parameter out of range */
+#define BadWindow         3    /* parameter not a Window */
+#define BadPixmap         4    /* parameter not a Pixmap */
+#define BadAtom                   5    /* parameter not an Atom */
+#define BadCursor         6    /* parameter not a Cursor */
+#define BadFont                   7    /* parameter not a Font */
+#define BadMatch          8    /* parameter mismatch */
+#define BadDrawable       9    /* parameter not a Pixmap or Window */
+#define BadAccess        10   
+#define BadAlloc         11    /* insufficient resources */
+#define BadColor         12    /* no such colormap */
+#define BadGC            13    /* parameter not a GC */
+#define BadIDChoice      14    /* choice not in range or already used */
+#define BadName                  15    /* font or color name doesn't exist */
+#define BadLength        16    /* Request length incorrect */
+#define BadImplementation 17   /* server is defective */
+#define FirstExtensionError    128
+#define LastExtensionError     255
+#define InputOutput            1
+#define InputOnly              2
+#define CWBackPixmap           (1L<<0)
+#define CWBackPixel            (1L<<1)
+#define CWBorderPixmap         (1L<<2)
+#define CWBorderPixel           (1L<<3)
+#define CWBitGravity           (1L<<4)
+#define CWWinGravity           (1L<<5)
+#define CWBackingStore          (1L<<6)
+#define CWBackingPlanes                (1L<<7)
+#define CWBackingPixel         (1L<<8)
+#define CWOverrideRedirect     (1L<<9)
+#define CWSaveUnder            (1L<<10)
+#define CWEventMask            (1L<<11)
+#define CWDontPropagate                (1L<<12)
+#define CWColormap             (1L<<13)
+#define CWCursor               (1L<<14)
+#define CWX                    (1<<0)
+#define CWY                    (1<<1)
+#define CWWidth                        (1<<2)
+#define CWHeight               (1<<3)
+#define CWBorderWidth          (1<<4)
+#define CWSibling              (1<<5)
+#define CWStackMode            (1<<6)
+#define ForgetGravity          0
+#define NorthWestGravity       1
+#define NorthGravity           2
+#define NorthEastGravity       3
+#define WestGravity            4
+#define CenterGravity          5
+#define EastGravity            6
+#define SouthWestGravity       7
+#define SouthGravity           8
+#define SouthEastGravity       9
+#define StaticGravity          10
+#define UnmapGravity           0
+#define NotUseful               0
+#define WhenMapped              1
+#define Always                  2
+#define IsUnmapped             0
+#define IsUnviewable           1
+#define IsViewable             2
+#define SetModeInsert           0
+#define SetModeDelete           1
+#define DestroyAll              0
+#define RetainPermanent         1
+#define RetainTemporary         2
+#define Above                   0
+#define Below                   1
+#define TopIf                   2
+#define BottomIf                3
+#define Opposite                4
+#define RaiseLowest             0
+#define LowerHighest            1
+#define PropModeReplace         0
+#define PropModePrepend         1
+#define PropModeAppend          2
+#define        GXclear                 0x0             /* 0 */
+#define GXand                  0x1             /* src AND dst */
+#define GXandReverse           0x2             /* src AND NOT dst */
+#define GXcopy                 0x3             /* src */
+#define GXandInverted          0x4             /* NOT src AND dst */
+#define        GXnoop                  0x5             /* dst */
+#define GXxor                  0x6             /* src XOR dst */
+#define GXor                   0x7             /* src OR dst */
+#define GXnor                  0x8             /* NOT src AND NOT dst */
+#define GXequiv                        0x9             /* NOT src XOR dst */
+#define GXinvert               0xa             /* NOT dst */
+#define GXorReverse            0xb             /* src OR NOT dst */
+#define GXcopyInverted         0xc             /* NOT src */
+#define GXorInverted           0xd             /* NOT src OR dst */
+#define GXnand                 0xe             /* NOT src OR NOT dst */
+#define GXset                  0xf             /* 1 */
+#define LineSolid              0
+#define LineOnOffDash          1
+#define LineDoubleDash         2
+#define CapNotLast             0
+#define CapButt                        1
+#define CapRound               2
+#define CapProjecting          3
+#define JoinMiter              0
+#define JoinRound              1
+#define JoinBevel              2
+#define FillSolid              0
+#define FillTiled              1
+#define FillStippled           2
+#define FillOpaqueStippled     3
+#define EvenOddRule            0
+#define WindingRule            1
+#define ClipByChildren         0
+#define IncludeInferiors       1
+#define Unsorted               0
+#define YSorted                        1
+#define YXSorted               2
+#define YXBanded               3
+#define CoordModeOrigin                0       /* relative to the origin */
+#define CoordModePrevious       1      /* relative to previous point */
+#define Complex                        0       /* paths may intersect */
+#define Nonconvex              1       /* no paths intersect, but not convex */
+#define Convex                 2       /* wholly convex */
+#define ArcChord               0       /* join endpoints of arc */
+#define ArcPieSlice            1       /* join endpoints to center of arc */
+#define GCFunction              (1L<<0)
+#define GCPlaneMask             (1L<<1)
+#define GCForeground            (1L<<2)
+#define GCBackground            (1L<<3)
+#define GCLineWidth             (1L<<4)
+#define GCLineStyle             (1L<<5)
+#define GCCapStyle              (1L<<6)
+#define GCJoinStyle            (1L<<7)
+#define GCFillStyle            (1L<<8)
+#define GCFillRule             (1L<<9) 
+#define GCTile                 (1L<<10)
+#define GCStipple              (1L<<11)
+#define GCTileStipXOrigin      (1L<<12)
+#define GCTileStipYOrigin      (1L<<13)
+#define GCFont                         (1L<<14)
+#define GCSubwindowMode                (1L<<15)
+#define GCGraphicsExposures     (1L<<16)
+#define GCClipXOrigin          (1L<<17)
+#define GCClipYOrigin          (1L<<18)
+#define GCClipMask             (1L<<19)
+#define GCDashOffset           (1L<<20)
+#define GCDashList             (1L<<21)
+#define GCArcMode              (1L<<22)
+#define GCLastBit              22
+#define FontLeftToRight                0
+#define FontRightToLeft                1
+#define FontChange             255
+#define XYBitmap               0       /* depth 1, XYFormat */
+#define XYPixmap               1       /* depth == drawable depth */
+#define ZPixmap                        2       /* depth == drawable depth */
+#define AllocNone              0       /* create map with no entries */
+#define AllocAll               1       /* allocate entire map writeable */
+#define DoRed                  (1<<0)
+#define DoGreen                        (1<<1)
+#define DoBlue                 (1<<2)
+#define CursorShape            0       /* largest size that can be displayed */
+#define TileShape              1       /* size tiled fastest */
+#define StippleShape           2       /* size stippled fastest */
+#define AutoRepeatModeOff      0
+#define AutoRepeatModeOn       1
+#define AutoRepeatModeDefault  2
+#define LedModeOff             0
+#define LedModeOn              1
+#define KBKeyClickPercent      (1L<<0)
+#define KBBellPercent          (1L<<1)
+#define KBBellPitch            (1L<<2)
+#define KBBellDuration         (1L<<3)
+#define KBLed                  (1L<<4)
+#define KBLedMode              (1L<<5)
+#define KBKey                  (1L<<6)
+#define KBAutoRepeatMode       (1L<<7)
+#define MappingSuccess         0
+#define MappingBusy            1
+#define MappingFailed          2
+#define MappingModifier                0
+#define MappingKeyboard                1
+#define MappingPointer         2
+#define DontPreferBlanking     0
+#define PreferBlanking         1
+#define DefaultBlanking                2
+#define DisableScreenSaver     0
+#define DisableScreenInterval  0
+#define DontAllowExposures     0
+#define AllowExposures         1
+#define DefaultExposures       2
+#define ScreenSaverReset 0
+#define ScreenSaverActive 1
+#define HostInsert             0
+#define HostDelete             1
+#define EnableAccess           1      
+#define DisableAccess          0
+#define StaticGray             0
+#define GrayScale              1
+#define StaticColor            2
+#define PseudoColor            3
+#define TrueColor              4
+#define DirectColor            5
+#define LSBFirst               0
+#define MSBFirst               1
+
+#define True 1
+#define False 0
+
+#define XK_Alt_L               0xFFE9  /* Left alt */
+
+#define XK_BackSpace           0xFF08  /* back space, back char */
+#define XK_Tab                 0xFF09
+#define XK_Linefeed            0xFF0A  /* Linefeed, LF */
+#define XK_Clear               0xFF0B
+#define XK_Return              0xFF0D  /* Return, enter */
+#define XK_Pause               0xFF13  /* Pause, hold */
+#define XK_Scroll_Lock         0xFF14
+#define XK_Sys_Req             0xFF15
+#define XK_Escape              0xFF1B
+#define XK_Delete              0xFFFF  /* Delete, rubout */
+
+#define XK_Home                        0xFF50
+#define XK_Left                        0xFF51  /* Move left, left arrow */
+#define XK_Up                  0xFF52  /* Move up, up arrow */
+#define XK_Right               0xFF53  /* Move right, right arrow */
+#define XK_Down                        0xFF54  /* Move down, down arrow */
+#define XK_Prior               0xFF55  /* Prior, previous */
+#define XK_Page_Up             0xFF55
+#define XK_Next                        0xFF56  /* Next */
+#define XK_Page_Down           0xFF56
+#define XK_End                 0xFF57  /* EOL */
+#define XK_Begin               0xFF58  /* BOL */
+
+#define XK_Select              0xFF60  /* Select, mark */
+#define XK_Print               0xFF61
+#define XK_Execute             0xFF62  /* Execute, run, do */
+#define XK_Insert              0xFF63  /* Insert, insert here */
+#define XK_Undo                        0xFF65  /* Undo, oops */
+#define XK_Redo                        0xFF66  /* redo, again */
+#define XK_Menu                        0xFF67
+#define XK_Find                        0xFF68  /* Find, search */
+#define XK_Cancel              0xFF69  /* Cancel, stop, abort, exit */
+#define XK_Help                        0xFF6A  /* Help */
+#define XK_Break               0xFF6B
+#define XK_Mode_switch         0xFF7E  /* Character set switch */
+#define XK_script_switch        0xFF7E  /* Alias for mode_switch */
+#define XK_Num_Lock            0xFF7F
+
+#define XK_F1                  0xFFBE
+#define XK_F2                  0xFFBF
+#define XK_F3                  0xFFC0
+#define XK_F4                  0xFFC1
+#define XK_F5                  0xFFC2
+#define XK_F6                  0xFFC3
+#define XK_F7                  0xFFC4
+#define XK_F8                  0xFFC5
+#define XK_F9                  0xFFC6
+#define XK_F10                 0xFFC7
+#define XK_F11                 0xFFC8
+#define XK_L1                  0xFFC8
+#define XK_F12                 0xFFC9
+
+#define VisualNoMask           0x0
+#define VisualIDMask           0x1
+#define VisualScreenMask       0x2
+#define VisualDepthMask                0x4
+#define VisualClassMask                0x8
+#define VisualRedMaskMask      0x10
+#define VisualGreenMaskMask    0x20
+#define VisualBlueMaskMask     0x40
+#define VisualColormapSizeMask 0x80
+#define VisualBitsPerRGBMask   0x100
+#define VisualAllMask          0x1FF
+
+#define USPosition     (1L << 0) /* user specified x, y */
+#define USSize         (1L << 1) /* user specified width, height */
+
+#define PPosition      (1L << 2) /* program specified position */
+#define PSize          (1L << 3) /* program specified size */
+#define PMinSize       (1L << 4) /* program specified minimum size */
+#define PMaxSize       (1L << 5) /* program specified maximum size */
+#define PResizeInc     (1L << 6) /* program specified resize increments */
+#define PAspect                (1L << 7) /* program specified min and max aspect ratios */
+#define PBaseSize      (1L << 8) /* program specified base for incrementing */
+#define PWinGravity    (1L << 9) /* program specified window gravity */
+
+#define NoValue                0x0000
+#define XValue         0x0001
+#define YValue         0x0002
+#define WidthValue     0x0004
+#define HeightValue    0x0008
+#define AllValues      0x000F
+#define XNegative      0x0010
+#define YNegative      0x0020
+
+#define XNoMemory -1
+#define XLocaleNotSupported -2
+#define XConverterNotFound -3
+
+#define LC_CTYPE 2
+
+/* used by rxvt/src/main.c */
+#define NormalState 1
+#define IconicState 3
+#define InputHint (1L << 0)
+#define StateHint (1L << 1)
+#define IconWindowHint (1L << 3)
+#define WindowGroupHint (1L << 6)
+#define XC_left_ptr 68
+#define XC_xterm 152
+
+typedef struct _XRegion *Region;
+typedef struct _XOC *XOC, *XFontSet;
+
+typedef struct _XExtData {
+       int number;             /* number returned by XRegisterExtension */
+       struct _XExtData *next; /* next item on list of data for structure */
+       int (*free_private)(    /* called to free private storage */
+       struct _XExtData *extension
+       );
+       XPointer private_data;  /* data private to this extension. */
+} XExtData;
+
+typedef struct {               /* public to extension, cannot be changed */
+       int extension;          /* extension number */
+       int major_opcode;       /* major op-code assigned by server */
+       int first_event;        /* first event number for the extension */
+       int first_error;        /* first error number for the extension */
+} XExtCodes;
+
+typedef struct {
+       XExtData *ext_data;     /* hook for extension to hang data */
+       VisualID visualid;      /* visual id of this visual */
+#if defined(__cplusplus) || defined(c_plusplus)
+       int c_class;            /* C++ class of screen (monochrome, etc.) */
+#else
+       int class;              /* class of screen (monochrome, etc.) */
+#endif
+       unsigned long red_mask, green_mask, blue_mask;  /* mask values */
+       int bits_per_rgb;       /* log base 2 of distinct color values */
+       int map_entries;        /* color map entries */
+} Visual;
+
+typedef struct {
+       int depth;              /* this depth (Z) of the depth */
+       int nvisuals;           /* number of Visual types at this depth */
+       Visual *visuals;        /* list of visuals possible at this depth */
+} Depth;
+
+typedef struct {
+       int function;           /* logical operation */
+       unsigned long plane_mask;/* plane mask */
+       unsigned long foreground;/* foreground pixel */
+       unsigned long background;/* background pixel */
+       int line_width;         /* line width */
+       int line_style;         /* LineSolid, LineOnOffDash, LineDoubleDash */
+       int cap_style;          /* CapNotLast, CapButt, 
+                                  CapRound, CapProjecting */
+       int join_style;         /* JoinMiter, JoinRound, JoinBevel */
+       int fill_style;         /* FillSolid, FillTiled, 
+                                  FillStippled, FillOpaeueStippled */
+       int fill_rule;          /* EvenOddRule, WindingRule */
+       int arc_mode;           /* ArcChord, ArcPieSlice */
+       Pixmap tile;            /* tile pixmap for tiling operations */
+       Pixmap stipple;         /* stipple 1 plane pixmap for stipping */
+       int ts_x_origin;        /* offset for tile or stipple operations */
+       int ts_y_origin;
+        Font font;             /* default text font for text operations */
+       int subwindow_mode;     /* ClipByChildren, IncludeInferiors */
+       BoolDef graphics_exposures;/* boolean, should exposures be generated */
+       int clip_x_origin;      /* origin for clipping */
+       int clip_y_origin;
+       Pixmap clip_mask;       /* bitmap clipping; other calls for rects */
+       int dash_offset;        /* patterned/dashed line information */
+       char dashes;
+} XGCValues;
+
+typedef struct _XGC
+{
+    XExtData *ext_data;        /* hook for extension to hang data */
+    GContext gid;      /* protocol ID for graphics context */
+       int rects;
+       int dashes;
+       XGCValues values;
+       int dirty;
+} *GC;
+
+typedef struct {
+       XExtData *ext_data;     /* hook for extension to hang data */
+       struct _XDisplay *display;/* back pointer to display structure */
+       Window root;            /* Root window id. */
+       int width, height;      /* width and height of screen */
+       int mwidth, mheight;    /* width and height of  in millimeters */
+       int ndepths;            /* number of depths possible */
+       Depth *depths;          /* list of allowable depths on the screen */
+       int root_depth;         /* bits per pixel */
+       Visual *root_visual;    /* root visual */
+       GC default_gc;          /* GC for the root root visual */
+       Colormap cmap;          /* default color map */
+       unsigned long white_pixel;
+       unsigned long black_pixel;      /* White and Black pixel values */
+       int max_maps, min_maps; /* max and min color maps */
+       int backing_store;      /* Never, WhenMapped, Always */
+       BoolDef save_unders;    
+       long root_input_mask;   /* initial root input mask */
+} Screen;
+
+typedef struct {
+       XExtData *ext_data;     /* hook for extension to hang data */
+       int depth;              /* depth of this image format */
+       int bits_per_pixel;     /* bits/pixel at this depth */
+       int scanline_pad;       /* scanline must padded to this multiple */
+} ScreenFormat;
+
+typedef struct _XDisplay
+{
+       XExtData *ext_data;     /* hook for extension to hang data */
+       struct _XPrivate *private1;
+       int fd;                 /* Network socket. */
+       int private2;
+       int proto_major_version;/* major version of server's X protocol */
+       int proto_minor_version;/* minor version of servers X protocol */
+       char *vendor;           /* vendor of the server hardware */
+       XID private3;
+       XID private4;
+       XID private5;
+       int private6;
+       XID (*resource_alloc)(  /* allocator function */
+               struct _XDisplay*
+       );
+       int byte_order;         /* screen byte order, LSBFirst, MSBFirst */
+       int bitmap_unit;        /* padding and data requirements */
+       int bitmap_pad;         /* padding requirements on bitmaps */
+       int bitmap_bit_order;   /* LeastSignificant or MostSignificant */
+       int nformats;           /* number of pixmap formats in list */
+       ScreenFormat *pixmap_format;    /* pixmap format list */
+       int private8;
+       int release;            /* release of the server */
+       struct _XPrivate *private9, *private10;
+       int qlen;               /* Length of input event queue */
+       unsigned long last_request_read; /* seq number of last event read */
+       unsigned long request;  /* sequence number of last request. */
+       XPointer private11;
+       XPointer private12;
+       XPointer private13;
+       XPointer private14;
+       unsigned max_request_size; /* maximum number 32 bit words in request*/
+       struct _XrmHashBucketRec *db;
+       int (*private15)(
+               struct _XDisplay*
+               );
+       char *display_name;     /* "host:display" string used on this connect*/
+       int default_screen;     /* default screen for operations */
+       int nscreens;           /* number of screens on this server*/
+       Screen *screens;        /* pointer to list of screens */
+       unsigned long motion_buffer;    /* size of motion buffer */
+       unsigned long private16;
+       int min_keycode;        /* minimum defined keycode */
+       int max_keycode;        /* maximum defined keycode */
+       XPointer private17;
+       XPointer private18;
+       int private19;
+       char *xdefaults;        /* contents of defaults from server */
+       /* there is more to this structure, but it is private to Xlib */
+}
+Display, *_XPrivDisplay;
+
+typedef int StatusDef;
+
+typedef struct {               /* normal 16 bit characters are two bytes */
+    unsigned char byte1;
+    unsigned char byte2;
+} XChar2b;
+
+typedef struct {
+    short      lbearing;       /* origin to left edge of raster */
+    short      rbearing;       /* origin to right edge of raster */
+    short      width;          /* advance to next char's origin */
+    short      ascent;         /* baseline to top edge of raster */
+    short      descent;        /* baseline to bottom edge of raster */
+    unsigned short attributes; /* per char flags (not predefined) */
+} XCharStruct;
+
+typedef struct {
+       char *res_name;
+       char *res_class;
+} XClassHint;
+
+typedef struct {
+       unsigned long pixel;
+       unsigned short red, green, blue;
+       char flags;  /* do_red, do_green, do_blue */
+       char pad;
+} XColor;
+
+typedef struct _XComposeStatus {
+    XPointer compose_ptr;      /* state table pointer */
+    int chars_matched;         /* match state */
+} XComposeStatus;
+
+/* events --- goes on for a bit */
+typedef struct {
+       int type;               /* of event */
+       unsigned long serial;   /* # of last request processed by server */
+       BoolDef send_event;     /* true if this came from a SendEvent request */
+       Display *display;       /* Display the event was read from */
+       Window window;          /* "event" window it is reported relative to */
+       Window root;            /* root window that the event occurred on */
+       Window subwindow;       /* child window */
+       Time time;              /* milliseconds */
+       int x, y;               /* pointer x, y coordinates in event window */
+       int x_root, y_root;     /* coordinates relative to root */
+       unsigned int state;     /* key or button mask */
+       unsigned int keycode;   /* detail */
+       BoolDef same_screen;    /* same screen flag */
+} XKeyEvent;
+
+typedef XKeyEvent XKeyPressedEvent;
+typedef XKeyEvent XKeyReleasedEvent;
+
+typedef struct {
+       int type;               /* of event */
+       unsigned long serial;   /* # of last request processed by server */
+       BoolDef send_event;     /* true if this came from a SendEvent request */
+       Display *display;       /* Display the event was read from */
+       Window window;          /* "event" window it is reported relative to */
+       Window root;            /* root window that the event occurred on */
+       Window subwindow;       /* child window */
+       Time time;              /* milliseconds */
+       int x, y;               /* pointer x, y coordinates in event window */
+       int x_root, y_root;     /* coordinates relative to root */
+       unsigned int state;     /* key or button mask */
+       unsigned int button;    /* detail */
+       BoolDef same_screen;    /* same screen flag */
+} XButtonEvent;
+typedef XButtonEvent XButtonPressedEvent;
+typedef XButtonEvent XButtonReleasedEvent;
+
+typedef struct {
+       int type;               /* of event */
+       unsigned long serial;   /* # of last request processed by server */
+       BoolDef send_event;     /* true if this came from a SendEvent request */
+       Display *display;       /* Display the event was read from */
+       Window window;          /* "event" window reported relative to */
+       Window root;            /* root window that the event occurred on */
+       Window subwindow;       /* child window */
+       Time time;              /* milliseconds */
+       int x, y;               /* pointer x, y coordinates in event window */
+       int x_root, y_root;     /* coordinates relative to root */
+       unsigned int state;     /* key or button mask */
+       char is_hint;           /* detail */
+       BoolDef same_screen;    /* same screen flag */
+} XMotionEvent;
+typedef XMotionEvent XPointerMovedEvent;
+
+typedef struct {
+       int type;               /* of event */
+       unsigned long serial;   /* # of last request processed by server */
+       BoolDef send_event;     /* true if this came from a SendEvent request */
+       Display *display;       /* Display the event was read from */
+       Window window;          /* "event" window reported relative to */
+       Window root;            /* root window that the event occurred on */
+       Window subwindow;       /* child window */
+       Time time;              /* milliseconds */
+       int x, y;               /* pointer x, y coordinates in event window */
+       int x_root, y_root;     /* coordinates relative to root */
+       int mode;               /* NotifyNormal, NotifyGrab, NotifyUngrab */
+       int detail;
+       /*
+        * NotifyAncestor, NotifyVirtual, NotifyInferior, 
+        * NotifyNonlinear,NotifyNonlinearVirtual
+        */
+       BoolDef same_screen;    /* same screen flag */
+       BoolDef focus;          /* boolean focus */
+       unsigned int state;     /* key or button mask */
+} XCrossingEvent;
+typedef XCrossingEvent XEnterWindowEvent;
+typedef XCrossingEvent XLeaveWindowEvent;
+
+typedef struct {
+       int type;               /* FocusIn or FocusOut */
+       unsigned long serial;   /* # of last request processed by server */
+       BoolDef send_event;     /* true if this came from a SendEvent request */
+       Display *display;       /* Display the event was read from */
+       Window window;          /* window of event */
+       int mode;               /* NotifyNormal, NotifyGrab, NotifyUngrab */
+       int detail;
+       /*
+        * NotifyAncestor, NotifyVirtual, NotifyInferior, 
+        * NotifyNonlinear,NotifyNonlinearVirtual, NotifyPointer,
+        * NotifyPointerRoot, NotifyDetailNone 
+        */
+} XFocusChangeEvent;
+typedef XFocusChangeEvent XFocusInEvent;
+typedef XFocusChangeEvent XFocusOutEvent;
+
+/* generated on EnterWindow and FocusIn  when KeyMapState selected */
+typedef struct {
+       int type;
+       unsigned long serial;   /* # of last request processed by server */
+       BoolDef send_event;     /* true if this came from a SendEvent request */
+       Display *display;       /* Display the event was read from */
+       Window window;
+       char key_vector[32];
+} XKeymapEvent;        
+
+typedef struct {
+       int type;
+       unsigned long serial;   /* # of last request processed by server */
+       BoolDef send_event;     /* true if this came from a SendEvent request */
+       Display *display;       /* Display the event was read from */
+       Window window;
+       int x, y;
+       int width, height;
+       int count;              /* if non-zero, at least this many more */
+} XExposeEvent;
+
+typedef struct {
+       int type;
+       unsigned long serial;   /* # of last request processed by server */
+       BoolDef send_event;     /* true if this came from a SendEvent request */
+       Display *display;       /* Display the event was read from */
+       Drawable drawable;
+       int x, y;
+       int width, height;
+       int count;              /* if non-zero, at least this many more */
+       int major_code;         /* core is CopyArea or CopyPlane */
+       int minor_code;         /* not defined in the core */
+} XGraphicsExposeEvent;
+
+typedef struct {
+       int type;
+       unsigned long serial;   /* # of last request processed by server */
+       BoolDef send_event;     /* true if this came from a SendEvent request */
+       Display *display;       /* Display the event was read from */
+       Drawable drawable;
+       int major_code;         /* core is CopyArea or CopyPlane */
+       int minor_code;         /* not defined in the core */
+} XNoExposeEvent;
+
+typedef struct {
+       int type;
+       unsigned long serial;   /* # of last request processed by server */
+       BoolDef send_event;     /* true if this came from a SendEvent request */
+       Display *display;       /* Display the event was read from */
+       Window window;
+       int state;              /* Visibility state */
+} XVisibilityEvent;
+
+typedef struct {
+       int type;
+       unsigned long serial;   /* # of last request processed by server */
+       BoolDef send_event;     /* true if this came from a SendEvent request */
+       Display *display;       /* Display the event was read from */
+       Window parent;          /* parent of the window */
+       Window window;          /* window id of window created */
+       int x, y;               /* window location */
+       int width, height;      /* size of window */
+       int border_width;       /* border width */
+       BoolDef override_redirect;      /* creation should be overridden */
+} XCreateWindowEvent;
+
+typedef struct {
+       int type;
+       unsigned long serial;   /* # of last request processed by server */
+       BoolDef send_event;     /* true if this came from a SendEvent request */
+       Display *display;       /* Display the event was read from */
+       Window event;
+       Window window;
+} XDestroyWindowEvent;
+
+typedef struct {
+       int type;
+       unsigned long serial;   /* # of last request processed by server */
+       BoolDef send_event;     /* true if this came from a SendEvent request */
+       Display *display;       /* Display the event was read from */
+       Window event;
+       Window window;
+       BoolDef from_configure;
+} XUnmapEvent;
+
+typedef struct {
+       int type;
+       unsigned long serial;   /* # of last request processed by server */
+       BoolDef send_event;     /* true if this came from a SendEvent request */
+       Display *display;       /* Display the event was read from */
+       Window event;
+       Window window;
+       BoolDef override_redirect;      /* boolean, is override set... */
+} XMapEvent;
+
+typedef struct {
+       int type;
+       unsigned long serial;   /* # of last request processed by server */
+       BoolDef send_event;     /* true if this came from a SendEvent request */
+       Display *display;       /* Display the event was read from */
+       Window parent;
+       Window window;
+} XMapRequestEvent;
+
+typedef struct {
+       int type;
+       unsigned long serial;   /* # of last request processed by server */
+       BoolDef send_event;     /* true if this came from a SendEvent request */
+       Display *display;       /* Display the event was read from */
+       Window event;
+       Window window;
+       Window parent;
+       int x, y;
+       BoolDef override_redirect;
+} XReparentEvent;
+
+typedef struct {
+       int type;
+       unsigned long serial;   /* # of last request processed by server */
+       BoolDef send_event;     /* true if this came from a SendEvent request */
+       Display *display;       /* Display the event was read from */
+       Window event;
+       Window window;
+       int x, y;
+       int width, height;
+       int border_width;
+       Window above;
+       BoolDef override_redirect;
+} XConfigureEvent;
+
+typedef struct {
+       int type;
+       unsigned long serial;   /* # of last request processed by server */
+       BoolDef send_event;     /* true if this came from a SendEvent request */
+       Display *display;       /* Display the event was read from */
+       Window event;
+       Window window;
+       int x, y;
+} XGravityEvent;
+
+typedef struct {
+       int type;
+       unsigned long serial;   /* # of last request processed by server */
+       BoolDef send_event;     /* true if this came from a SendEvent request */
+       Display *display;       /* Display the event was read from */
+       Window window;
+       int width, height;
+} XResizeRequestEvent;
+
+typedef struct {
+       int type;
+       unsigned long serial;   /* # of last request processed by server */
+       BoolDef send_event;     /* true if this came from a SendEvent request */
+       Display *display;       /* Display the event was read from */
+       Window parent;
+       Window window;
+       int x, y;
+       int width, height;
+       int border_width;
+       Window above;
+       int detail;             /* Above, Below, TopIf, BottomIf, Opposite */
+       unsigned long value_mask;
+} XConfigureRequestEvent;
+
+typedef struct {
+       int type;
+       unsigned long serial;   /* # of last request processed by server */
+       BoolDef send_event;     /* true if this came from a SendEvent request */
+       Display *display;       /* Display the event was read from */
+       Window event;
+       Window window;
+       int place;              /* PlaceOnTop, PlaceOnBottom */
+} XCirculateEvent;
+
+typedef struct {
+       int type;
+       unsigned long serial;   /* # of last request processed by server */
+       BoolDef send_event;     /* true if this came from a SendEvent request */
+       Display *display;       /* Display the event was read from */
+       Window parent;
+       Window window;
+       int place;              /* PlaceOnTop, PlaceOnBottom */
+} XCirculateRequestEvent;
+
+typedef struct {
+       int type;
+       unsigned long serial;   /* # of last request processed by server */
+       BoolDef send_event;     /* true if this came from a SendEvent request */
+       Display *display;       /* Display the event was read from */
+       Window window;
+       Atom atom;
+       Time time;
+       int state;              /* NewValue, Deleted */
+} XPropertyEvent;
+
+typedef struct {
+       int type;
+       unsigned long serial;   /* # of last request processed by server */
+       BoolDef send_event;     /* true if this came from a SendEvent request */
+       Display *display;       /* Display the event was read from */
+       Window window;
+       Atom selection;
+       Time time;
+} XSelectionClearEvent;
+
+typedef struct {
+       int type;
+       unsigned long serial;   /* # of last request processed by server */
+       BoolDef send_event;     /* true if this came from a SendEvent request */
+       Display *display;       /* Display the event was read from */
+       Window owner;
+       Window requestor;
+       Atom selection;
+       Atom target;
+       Atom property;
+       Time time;
+} XSelectionRequestEvent;
+
+typedef struct {
+       int type;
+       unsigned long serial;   /* # of last request processed by server */
+       BoolDef send_event;     /* true if this came from a SendEvent request */
+       Display *display;       /* Display the event was read from */
+       Window requestor;
+       Atom selection;
+       Atom target;
+       Atom property;          /* ATOM or None */
+       Time time;
+} XSelectionEvent;
+
+typedef struct {
+       int type;
+       unsigned long serial;   /* # of last request processed by server */
+       BoolDef send_event;     /* true if this came from a SendEvent request */
+       Display *display;       /* Display the event was read from */
+       Window window;
+       Colormap colormap;      /* COLORMAP or None */
+#if defined(__cplusplus) || defined(c_plusplus)
+       BoolDef c_new;          /* C++ */
+#else
+       BoolDef new;
+#endif
+       int state;              /* ColormapInstalled, ColormapUninstalled */
+} XColormapEvent;
+
+typedef struct {
+       int type;
+       unsigned long serial;   /* # of last request processed by server */
+       BoolDef send_event;     /* true if this came from a SendEvent request */
+       Display *display;       /* Display the event was read from */
+       Window window;
+       Atom message_type;
+       int format;
+       union {
+               char b[20];
+               short s[10];
+               long l[5];
+               } data;
+} XClientMessageEvent;
+
+typedef struct {
+       int type;
+       unsigned long serial;   /* # of last request processed by server */
+       BoolDef send_event;     /* true if this came from a SendEvent request */
+       Display *display;       /* Display the event was read from */
+       Window window;          /* unused */
+       int request;            /* one of MappingModifier, MappingKeyboard,
+                                  MappingPointer */
+       int first_keycode;      /* first keycode */
+       int count;              /* defines range of change w. first_keycode*/
+} XMappingEvent;
+
+typedef struct {
+       int type;
+       Display *display;       /* Display the event was read from */
+       XID resourceid;         /* resource id */
+       unsigned long serial;   /* serial number of failed request */
+       unsigned char error_code;       /* error code of failed request */
+       unsigned char request_code;     /* Major op-code of failed request */
+       unsigned char minor_code;       /* Minor op-code of failed request */
+} XErrorEvent;
+
+typedef struct {
+       int type;
+       unsigned long serial;   /* # of last request processed by server */
+       BoolDef send_event;     /* true if this came from a SendEvent request */
+       Display *display;/* Display the event was read from */
+       Window window;  /* window on which event was requested in event mask */
+} XAnyEvent;
+
+/*
+ * this union is defined so Xlib can always use the same sized
+ * event structure internally, to avoid memory fragmentation.
+ */
+typedef union _XEvent {
+        int type;              /* must not be changed; first element */
+       XAnyEvent xany;
+       XKeyEvent xkey;
+       XButtonEvent xbutton;
+       XMotionEvent xmotion;
+       XCrossingEvent xcrossing;
+       XFocusChangeEvent xfocus;
+       XExposeEvent xexpose;
+       XGraphicsExposeEvent xgraphicsexpose;
+       XNoExposeEvent xnoexpose;
+       XVisibilityEvent xvisibility;
+       XCreateWindowEvent xcreatewindow;
+       XDestroyWindowEvent xdestroywindow;
+       XUnmapEvent xunmap;
+       XMapEvent xmap;
+       XMapRequestEvent xmaprequest;
+       XReparentEvent xreparent;
+       XConfigureEvent xconfigure;
+       XGravityEvent xgravity;
+       XResizeRequestEvent xresizerequest;
+       XConfigureRequestEvent xconfigurerequest;
+       XCirculateEvent xcirculate;
+       XCirculateRequestEvent xcirculaterequest;
+       XPropertyEvent xproperty;
+       XSelectionClearEvent xselectionclear;
+       XSelectionRequestEvent xselectionrequest;
+       XSelectionEvent xselection;
+       XColormapEvent xcolormap;
+       XClientMessageEvent xclient;
+       XMappingEvent xmapping;
+       XErrorEvent xerror;
+       XKeymapEvent xkeymap;
+       long pad[24];
+} XEvent;
+
+typedef int (*XErrorHandler) (     /* WARNING, this type not in Xlib spec */
+    Display*           /* display */,
+    XErrorEvent*       /* error_event */
+);
+
+
+typedef struct {
+    Atom name;
+    unsigned long card32;
+} XFontProp;
+
+typedef struct {
+    XExtData   *ext_data;      /* hook for extension to hang data */
+    Font        fid;            /* Font id for this font */
+    unsigned   direction;      /* hint about direction the font is painted */
+    unsigned   min_char_or_byte2;/* first character */
+    unsigned   max_char_or_byte2;/* last character */
+    unsigned   min_byte1;      /* first row that exists */
+    unsigned   max_byte1;      /* last row that exists */
+    BoolDef all_chars_exist;/* flag if all characters have non-zero size*/
+    unsigned   default_char;   /* char to print for undefined character */
+    int         n_properties;   /* how many properties there are */
+    XFontProp  *properties;    /* pointer to array of additional properties*/
+    XCharStruct        min_bounds;     /* minimum bounds over all existing char*/
+    XCharStruct        max_bounds;     /* maximum bounds over all existing char*/
+    XCharStruct        *per_char;      /* first_char to last_char information */
+    int                ascent;         /* log. extent above baseline for spacing */
+    int                descent;        /* log. descent below baseline for spacing */
+} XFontStruct;
+
+typedef enum {
+    XStringStyle,              /* STRING */
+    XCompoundTextStyle,                /* COMPOUND_TEXT */
+    XTextStyle,                        /* text in owner's encoding (current locale)*/
+    XStdICCTextStyle,          /* STRING, else COMPOUND_TEXT */
+    XUTF8StringStyle           /* UTF8_STRING */
+} XICCEncodingStyle;
+
+typedef struct _XIM *XIM;
+typedef struct _XIC *XIC;
+
+/*
+ * Data structure for "image" data, used by image manipulation routines.
+ */
+typedef struct _XImage {
+    int width, height;         /* size of image */
+    int xoffset;               /* number of pixels offset in X direction */
+    int format;                        /* XYBitmap, XYPixmap, ZPixmap */
+    char *data;                        /* pointer to image data */
+    int byte_order;            /* data byte order, LSBFirst, MSBFirst */
+    int bitmap_unit;           /* quant. of scanline 8, 16, 32 */
+    int bitmap_bit_order;      /* LSBFirst, MSBFirst */
+    int bitmap_pad;            /* 8, 16, 32 either XY or ZPixmap */
+    int depth;                 /* depth of image */
+    int bytes_per_line;                /* accelarator to next line */
+    int bits_per_pixel;                /* bits per pixel (ZPixmap) */
+    unsigned long red_mask;    /* bits in z arrangment */
+    unsigned long green_mask;
+    unsigned long blue_mask;
+    XPointer obdata;           /* hook for the object routines to hang on */
+    struct funcs {             /* image manipulation routines */
+       struct _XImage *(*create_image)(
+               struct _XDisplay* /* display */,
+               Visual*         /* visual */,
+               unsigned int    /* depth */,
+               int             /* format */,
+               int             /* offset */,
+               char*           /* data */,
+               unsigned int    /* width */,
+               unsigned int    /* height */,
+               int             /* bitmap_pad */,
+               int             /* bytes_per_line */);
+       int (*destroy_image)        (struct _XImage *);
+       unsigned long (*get_pixel)  (struct _XImage *, int, int);
+       int (*put_pixel)            (struct _XImage *, int, int, unsigned long);
+       struct _XImage *(*sub_image)(struct _XImage *, int, int, unsigned int, unsigned int);
+       int (*add_pixel)            (struct _XImage *, long);
+       } f;
+} XImage;
+
+typedef struct {
+       int max_keypermod;      /* The server's max # of keys per modifier */
+       KeyCode *modifiermap;   /* An 8 by max_keypermod array of modifiers */
+} XModifierKeymap;
+
+typedef struct {
+    short x, y;
+} XPoint;
+
+typedef struct {
+    short x, y;
+    unsigned short width, height;
+} XRectangle;
+
+typedef struct {
+    short x1, y1, x2, y2;
+} XSegment;
+
+typedef struct {
+    Pixmap background_pixmap;  /* background or None or ParentRelative */
+    unsigned long background_pixel;    /* background pixel */
+    Pixmap border_pixmap;      /* border of the window */
+    unsigned long border_pixel;        /* border pixel value */
+    int bit_gravity;           /* one of bit gravity values */
+    int win_gravity;           /* one of the window gravity values */
+    int backing_store;         /* NotUseful, WhenMapped, Always */
+    unsigned long backing_planes;/* planes to be preseved if possible */
+    unsigned long backing_pixel;/* value to use in restoring planes */
+    BoolDef save_under;                /* should bits under be saved? (popups) */
+    long event_mask;           /* set of events that should be saved */
+    long do_not_propagate_mask;        /* set of events that should not propagate */
+    BoolDef override_redirect; /* boolean value for override-redirect */
+    Colormap colormap;         /* color map to be associated with window */
+    Cursor cursor;             /* cursor to be displayed (or None) */
+} XSetWindowAttributes;
+
+typedef struct {
+       long flags;     /* marks which fields in this structure are defined */
+       int x, y;               /* obsolete for new window mgrs, but clients */
+       int width, height;      /* should set so old wm's don't mess up */
+       int min_width, min_height;
+       int max_width, max_height;
+       int width_inc, height_inc;
+       struct {
+               int x;  /* numerator */
+               int y;  /* denominator */
+       } min_aspect, max_aspect;
+       int base_width, base_height;            /* added by ICCCM version 1 */
+       int win_gravity;                        /* added by ICCCM version 1 */
+} XSizeHints;
+
+typedef struct {
+       Colormap colormap;
+       unsigned long red_max;
+       unsigned long red_mult;
+       unsigned long green_max;
+       unsigned long green_mult;
+       unsigned long blue_max;
+       unsigned long blue_mult;
+       unsigned long base_pixel;
+       VisualID visualid;              /* added by ICCCM version 1 */
+       XID killid;                     /* added by ICCCM version 1 */
+} XStandardColormap;
+
+typedef struct {
+    unsigned char *value;              /* same as Property routines */
+    Atom encoding;                     /* prop type */
+    int format;                                /* prop data format: 8, 16, or 32 */
+    unsigned long nitems;              /* number of data items in value */
+} XTextProperty;
+
+typedef struct {
+  Visual *visual;
+  VisualID visualid;
+  int screen;
+  int depth;
+#if defined(__cplusplus) || defined(c_plusplus)
+  int c_class;                                 /* C++ */
+#else
+  int class;
+#endif
+  unsigned long red_mask;
+  unsigned long green_mask;
+  unsigned long blue_mask;
+  int colormap_size;
+  int bits_per_rgb;
+} XVisualInfo;
+
+typedef struct {
+       long flags;     /* marks which fields in this structure are defined */
+       BoolDef input;  /* does this application rely on the window manager to
+                       get keyboard input? */
+       int initial_state;      /* see below */
+       Pixmap icon_pixmap;     /* pixmap to be used as icon */
+       Window icon_window;     /* window to be used as icon */
+       int icon_x, icon_y;     /* initial position of icon */
+       Pixmap icon_mask;       /* icon mask bitmap */
+       XID window_group;       /* id of related window group */
+       /* this structure may be extended in the future */
+} XWMHints;
+
+typedef struct {
+    int x, y;                  /* location of window */
+    int width, height;         /* width and height of window */
+    int border_width;          /* border width of window */
+    int depth;                 /* depth of window */
+    Visual *visual;            /* the associated visual structure */
+    Window root;               /* root of screen containing window */
+#if defined(__cplusplus) || defined(c_plusplus)
+    int c_class;               /* C++ InputOutput, InputOnly*/
+#else
+    int class;                 /* InputOutput, InputOnly*/
+#endif
+    int bit_gravity;           /* one of bit gravity values */
+    int win_gravity;           /* one of the window gravity values */
+    int backing_store;         /* NotUseful, WhenMapped, Always */
+    unsigned long backing_planes;/* planes to be preserved if possible */
+    unsigned long backing_pixel;/* value to be used when restoring planes */
+    BoolDef save_under;                /* boolean, should bits under be saved? */
+    Colormap colormap;         /* color map to be associated with window */
+    BoolDef map_installed;             /* boolean, is color map currently installed*/
+    int map_state;             /* IsUnmapped, IsUnviewable, IsViewable */
+    long all_event_masks;      /* set of events all people have interest in*/
+    long your_event_mask;      /* my event mask */
+    long do_not_propagate_mask; /* set of events that should not propagate */
+    BoolDef override_redirect; /* boolean value for override-redirect */
+    Screen *screen;            /* back pointer to correct screen */
+} XWindowAttributes;
+
+struct _XrmHashBucketRec;
+
+/* needed for xdefaults.c */
+typedef struct _XrmHashBucketRec *XrmDatabase;
+typedef enum {XrmBindTightly, XrmBindLoosely} XrmBinding, *XrmBindingList;
+typedef int       XrmQuark, *XrmQuarkList;
+#define NULLQUARK ((XrmQuark) 0)
+typedef XrmQuark     XrmRepresentation;
+typedef struct {
+    unsigned int    size;
+    XPointer       addr;
+} XrmValue, *XrmValuePtr;
+
+/* extend for defining an event callback */
+#define USING_W11LIB
+typedef void (proto_W11EventHandler)(XEvent *ev);
+void W11AddEventHandler(Display *display, proto_W11EventHandler *ev);
+
+/* functions */
+
+Display *XOpenDisplay(const char *name);
+
+int XCloseDisplay(Display *display);
+
+char *XDisplayString(Display *display);
+
+int XSync(Display *display,int discard);
+
+int XFlush(Display *display);
+
+XVisualInfo *XGetVisualInfo(
+                           Display *display,
+                           long vinm,
+                           XVisualInfo *vint,
+                           int *n);
+
+StatusDef XMatchVisualInfo(
+    Display*           display,
+    int                        screen,
+    int                        depth,
+    int                        class,
+    XVisualInfo*       vinfo_return);
+
+int XClearWindow(Display *display, Window w);
+
+Window XCreateSimpleWindow(
+                   Display *display,
+                   Window  parent,
+                   int     x, 
+                   int y,
+                   unsigned int brd,
+                   unsigned int w,
+                   unsigned int h,
+                   unsigned long bg, 
+                   unsigned long brd_col);
+
+Window XCreateWindow(
+             Display *display,
+             Window  parent,
+             int x,
+             int y,
+             unsigned int width,
+             unsigned int height,
+             unsigned int bw,
+             int depth,
+             unsigned int class,
+             Visual *visual,
+             unsigned long valuemask,
+             XSetWindowAttributes *attr);
+
+int XDestroyWindow(
+              Display *display,
+              Window w);
+
+StatusDef XGetGeometry(
+            Display *display,
+            Drawable w,
+            Window *root,
+            int *x,
+            int *y,
+            unsigned int *width,
+            unsigned int *height,
+            unsigned int *bw,
+            unsigned int *depth);
+
+StatusDef XGetWindowAttributes(Display *display,
+                    Window w,
+                    XWindowAttributes *wattr);
+
+int XSelectInput(Display *display,
+            Window  window,
+            long    mask);
+
+int XMapWindow(Display *display,
+          Window window);
+
+int XIconifyWindow(Display *display,
+              Window w,
+              int screen_number);
+GC XCreateGC(
+         Display *display,
+         Drawable window,
+         unsigned long mask,
+         XGCValues *gc_values);
+
+int XFreeGC(
+       Display *display,
+       GC gc);
+
+int XSetForeground(
+              Display *display,
+              GC gc,
+              unsigned long    color);
+int XDrawString(Display *display, 
+           Drawable window,
+           GC gc, 
+           int x, 
+           int y, 
+           const char* str, 
+           int len);
+int XDrawString16(Display *display, 
+             Drawable window,
+             GC gc, int x, int y,
+             const XChar2b* str,
+             int len);
+
+int XDrawImageString(
+       Display* display,
+       Drawable d,
+       GC gc,
+       int x,
+       int y,
+       const char* string,
+       int length);
+
+int XDrawImageString16(Display *display, 
+                  Drawable window,
+                  GC gc, int x, int y,
+                  const XChar2b* str,
+                  int len);
+
+int XFillRectangle(
+              Display *display,
+              Drawable window,
+              GC gc,
+              int x, int y,
+              unsigned int w, unsigned int h);
+int XClearArea(
+          Display *display,
+          Window w,
+          int x, int y,
+          unsigned int width, unsigned int height,
+          BoolDef exposures);
+
+Region XCreateRegion();
+
+int XClipBox(
+        Region hrgn,
+        XRectangle *rect);
+
+int XSetRegion(
+          Display *display,
+          GC gc,
+          Region hrgn);
+
+int XDestroyRegion(Region hrgn);
+
+int XUnionRectWithRegion(XRectangle *rect,
+                    Region hrgnsrc,
+                    Region hrgndest);
+int XDrawArc(
+        Display *display,
+        Drawable w,
+        GC gc,
+        int x, int y,
+        unsigned int width,unsigned int height,
+        int a1, int a2);
+
+int XFillArc(
+        Display *display,
+        Drawable w,
+        GC gc,
+        int x, int y,
+        unsigned int width,unsigned height,
+        int a1, int a2);
+
+int XFillPolygon(
+            Display *display,
+            Drawable w,
+            GC gc,
+            XPoint *points,
+            int nps, int shape, int mode);
+
+int XDrawLine(
+         Display *display,
+         Drawable w,
+         GC gc,
+         int x1,int y1, int x2,int y2);
+
+int XDrawLines(
+          Display *display,
+          Drawable w,
+          GC gc,
+          XPoint *points,
+          int nps,int mode);
+
+int XDrawPoints(
+           Display *display,
+           Drawable w,
+           GC gc,
+           XPoint *points,
+           int nps, int mode);
+
+int XDrawPoint(
+          Display *display,
+          Drawable w,
+          GC gc,
+          int x, int y);
+int XDrawRectangle(
+              Display *display,
+              Drawable w,
+              GC gc,
+              int x, int y,
+              unsigned int width, unsigned int height);
+
+int XDrawSegments(
+             Display *display,
+             Drawable w,
+             GC gc,
+             XSegment *segs,
+             int nsegs);
+
+Pixmap XCreatePixmap(
+             Display *display,
+             Drawable drawable,
+             unsigned int width, unsigned int height,
+             unsigned int depth);
+
+Pixmap XCreateBitmapFromData(Display *display,
+                     Drawable drawable, const char *data,
+                     unsigned int width, unsigned int height);
+int XFreePixmap(
+        Display *display,
+        Pixmap pixmap);
+
+int XCopyArea(
+         Display *display,
+         Drawable src,
+         Drawable dest,
+         GC gc,
+         int src_x, int src_y,
+         unsigned int width, unsigned int height,
+         int dest_x, int dest_y);
+
+XImage *XGetImage(
+                 Display *display,
+                 Drawable drawable,
+                 int x, int y,
+                 unsigned int width, unsigned int height,
+                 unsigned long plane_mask,
+                 int format);
+
+XImage *XCreateImage(
+            Display *display,
+            Visual *visual,
+            unsigned int depth,
+            int format,
+            int offset,
+            char *data,
+            unsigned int width, unsigned int height,
+            int bitmap_pad, int bytes_per_line);
+int XPutImage(
+         Display *display,
+         Drawable w,
+         GC gc,
+         XImage *image,
+         int sx,int sy,int dx,int dy,
+         unsigned int width,unsigned int height);
+
+int XSetWindowBackground(
+                    Display *display,
+                    Window w,
+                    unsigned long bg);
+
+int XSetWindowBackgroundPixmap(
+                          Display *display,
+                          Window w,
+                          Pixmap background_tile);
+
+int XSetFillStyle(
+             Display *display,
+             GC gc,
+             int fs);
+
+int XSetDashes(Display *display,
+          GC gc, int dash_offset,
+          const char * dash_list,
+          int n);
+
+int XChangeWindowAttributes(
+                       Display *display,
+                       Window w,
+                       unsigned long vmask,
+                       XSetWindowAttributes *attr);
+
+int XLowerWindow(Display *display,
+            Window w);
+
+int XMapRaised(
+          Display *display,
+          Window w);
+
+int
+XMapSubwindows(
+              Display *display,
+              Window w);
+
+StatusDef
+XQueryTree(
+          Display *display,
+          Window w,
+          Window* root,
+          Window* parent,
+          Window** ch,
+          unsigned int *n);
+int
+XRaiseWindow(
+            Display *display,
+            Window w);
+
+Window
+XRootWindow(
+           Display *display,
+           int scr);
+Window
+XRootWindowOfScreen(Screen *scr);
+
+BoolDef XTranslateCoordinates(
+                     Display *display,
+                     Window sw, Window dw,
+                     int sx, int sy, int *dx, int *dy,
+                     Window *ch);
+
+int
+XUnmapWindow(Display *display,
+            Window w);
+int
+XCopyGC(
+       Display *display,
+       GC sgc,
+       unsigned long vmask,
+       GC dgc);
+int
+XSetClipMask(
+            Display *display,
+            GC gc,
+            Pixmap cmask);
+
+int
+XSetClipRectangles(
+                  Display *display,
+                  GC gc,
+                  int clx, int cly,
+                  XRectangle *rs,
+                  int n, int order);
+int
+XSetFunction(
+            Display *display,
+            GC gc,
+            int fn);
+int
+XSetLineAttributes(
+                  Display *display,
+                  GC gc,
+                  unsigned int lw,
+                  int ls, int cs, int js);
+int
+XSetPlaneMask(
+             Display *display,
+             GC gc,
+             unsigned long pmask);
+int XSetTile(
+            Display *display,
+            GC gc,
+            Pixmap tile);
+StatusDef
+XAllocColorCells(
+                Display *display,
+                Colormap cmap,
+                BoolDef cont,
+                unsigned long *pmasks,
+                unsigned int np,
+                unsigned long *pixels,
+                unsigned int nc);
+StatusDef
+XAllocColorPlanes(
+                 Display *display,
+                 Colormap cmap,
+                 BoolDef cont,
+                 unsigned long *pixels,
+                 int nc,
+                 int nr,int ng,int nb,
+                 unsigned long *rmask,
+                 unsigned long *gmask,
+                 unsigned long *bmask);
+StatusDef
+XAllocNamedColor(Display *display,
+                Colormap cmap, const char *cname,
+                XColor *cell, XColor *rgb);
+Colormap
+XCreateColormap(
+               Display *display,
+               Window w,
+               Visual *visual,
+               int alloc);
+StatusDef
+XGetStandardColormap(
+                    Display *display,
+                    Window w,
+                    XStandardColormap *cmapinf,
+                    Atom prop);
+StatusDef
+XAllocColor(
+           Display *display,
+           Colormap cmap,
+           XColor *xc);
+int
+XQueryColor(
+           Display *display,
+           Colormap cmap,
+           XColor *cell);
+int
+XQueryColors(
+            Display *display,
+            Colormap cmap,
+            XColor *cells,
+            int nc);
+int
+XStoreColor(
+           Display *display,
+           Colormap cmap,
+           XColor *cell);
+int
+XStoreColors(
+            Display *display,
+            Colormap cmap,
+            XColor *cells,
+            int nc);
+char **
+XGetFontPath(
+            Display *display,
+            int *nps);
+BoolDef XGetFontProperty(
+                XFontStruct *fstruct,
+                Atom atom,
+                unsigned long *val);
+
+XFontStruct *
+XLoadQueryFont(Display *display, const char *name);
+
+XFontStruct *
+XQueryFont(
+          Display *display,
+          XID     font_id);
+
+KeySym
+XKeycodeToKeysym(
+                Display *display,
+                unsigned int keycode,
+                int     index);
+
+KeyCode
+XKeysymToKeycode(
+                Display *display,
+                KeySym keysym);
+
+KeySym
+XStringToKeysym(const char *str);
+
+XModifierKeymap *
+XGetModifierMapping(Display *display);
+
+int
+XFreeModifiermap(XModifierKeymap *modmap);
+
+int
+XSetFont(
+        Display *display,
+        GC gc,
+        Font font);
+int
+XSetFontPath(
+            Display *display,
+            char **dirs,
+            int nd);
+int
+XTextExtents(
+            XFontStruct *fstruct,
+            const char *str,
+            int nc,
+            int *dir,int *ascent,int *descent,
+            XCharStruct *overall);
+int
+XTextExtents16(
+              XFontStruct *fstruct,
+              const XChar2b *str,
+              int nc,
+              int *dir, int *ascent, int *descent,
+              XCharStruct *overall);
+
+int
+XTextWidth(
+          XFontStruct *fstruct,
+          const char *str,
+          int co);
+int
+XTextWidth16(
+            XFontStruct *fstruct,
+            const XChar2b *str,
+            int co);
+int
+XGetErrorDatabaseText(
+                     Display *display,
+                     const char *name, const char *msg,
+                     const char *defstr,
+                     char *buf,
+                     int len);
+
+int
+XGetErrorText(
+             Display *display,
+             int code,
+             char *buf,
+             int len);
+
+XErrorHandler
+XSetErrorHandler(XErrorHandler handler);
+
+int
+XDefaultScreen(Display *display);
+
+Visual *
+XDefaultVisual(
+              Display *display,
+              int screen);
+
+int
+XDefaultDepth(
+             Display *display,
+             int screen);
+
+Colormap
+XDefaultColormap(
+                Display *display,
+                int screen);
+Screen *
+XScreenOfDisplay(
+                Display *display,
+                int scr);
+Cursor
+XCreateFontCursor(
+                 Display *display,
+                 unsigned int shape);
+int
+XRecolorCursor(
+              Display *display,
+              Cursor cursor,
+              XColor *fg,XColor *bg);
+
+int
+XWarpPointer(
+            Display *display,
+            Window sw,Window dw,
+            int sx,int sy,
+            unsigned int swidth,unsigned int sheight,
+            int dx, int dy);
+int
+XBell(
+      Display *display,
+      int pc);
+
+int
+XGetInputFocus(
+              Display *display,
+              Window *focus,
+              int *revto);
+int
+XSetInputFocus(
+              Display *display,
+              Window focus,
+              int revto,
+              Time time);
+int
+XLookupString(
+             XKeyEvent *event,
+             char *buf,
+             int nbytes,
+             KeySym *keysym,
+             XComposeStatus *status);
+
+int
+XRefreshKeyboardMapping(XMappingEvent *event);
+
+int
+XSetClassHint(
+             Display *display,
+             Window w,
+             XClassHint *chints);
+int
+XSetNormalHints(
+               Display *display,
+               Window w,
+               XSizeHints *hints);
+
+int
+XSetWMHints(
+           Display *display,
+           Window w,
+           XWMHints *wmhints);
+StatusDef
+XSetWMProtocols(
+               Display *display,
+               Window w,
+               Atom *prots,
+               int co);
+int
+XStoreName(Display *display,
+          Window w,
+          const char *wname);
+StatusDef
+XFetchName(
+    Display *display,
+    Window w,
+    char **window_name_return);
+
+int
+XDoesBackingStore(Screen *scr);
+
+XExtCodes *
+XInitExtension(Display *display,
+              const char *name);
+int
+XFree(void *data);
+
+char *
+XServerVendor(Display *display);
+
+int
+XSetIconName(Display *display,
+            Window w,
+            const char *iname);
+int
+XGetIconName(
+            Display *display,
+            Window w,
+            char **iname);
+int
+XSetSelectionOwner(
+                  Display* display,
+                  Atom sel,
+                  Window owner,
+                  Time time);
+Window
+XGetSelectionOwner(
+                  Display* display,
+                  Atom selection);
+
+int
+XConvertSelection(
+                 Display *display,
+                 Atom sel, Atom target, Atom prop,
+                 Window req,
+                 Time time);
+BoolDef XCheckTypedEvent(
+                Display *display,
+                int ev,
+                XEvent *rep);
+BoolDef XCheckWindowEvent(
+                 Display *display,
+                 Window w,
+                 long emask,
+                 XEvent *ev);
+int
+XPending(Display *display);
+
+int
+XPutBackEvent(Display *display,
+             XEvent *event);
+
+StatusDef
+XSendEvent(
+          Display *display,
+          Window w,
+          BoolDef prop,
+          long emask,
+          XEvent *event);
+
+BoolDef XCheckTypedWindowEvent(
+       Display* display,
+       Window w,
+       int event_type,
+       XEvent* event_return);
+int
+XWindowEvent(
+            Display *display,
+            Window w,
+            long emask,
+            XEvent *rep);
+
+int
+XNextEvent(
+          Display *display,
+          XEvent  *event);
+
+Atom
+XInternAtom(
+           Display *display,
+           const char *property_name,
+           BoolDef only_if_exists);
+char *
+XGetAtomName(
+            Display *display,
+            Atom atom);
+
+int
+XChangeProperty(
+       Display *display,
+       Window window,
+       Atom property,
+       Atom type,
+       int format,
+       int mode,
+       const unsigned char *data,
+       int nelements);
+
+int
+XGetWindowProperty(
+                  Display *display,
+                  Window window,
+                  Atom property,
+                  long long_offset,
+                  long long_length,
+                  BoolDef delete,
+                  Atom req_type,
+                  Atom *actual_type_return,
+                  int *actual_format_return,
+                  unsigned long *nitems_return,
+                  unsigned long *bytes_after_return,
+                  unsigned char **prop_return);
+
+char **
+XListExtensions(
+               Display *display,
+               int *ret_num);
+
+int XFreeExtensionList(char **list);
+
+int
+XChangeGC(
+       Display* display,
+       GC gc,
+       unsigned long mask,
+       XGCValues* gc_values);
+
+int
+XConnectionNumber(Display* display);
+
+int
+XFreeFont(Display* display,XFontStruct* font_struct);
+
+char *
+XSetLocaleModifiers(const char* modifier_list);
+
+XIM
+XOpenIM(
+       Display* dpy,
+       struct _XrmHashBucketRec* rdb,
+       char* res_name,
+       char* res_class);
+
+char *
+XGetIMValues(XIM im , ...);
+
+XIC XCreateIC(XIM im , ...);
+
+StatusDef
+XCloseIM(XIM im);
+
+BoolDef XFilterEvent(XEvent* event,Window window);
+
+char *
+XrmQuarkToString(void *quark);
+
+int
+XmbLookupString(
+       XIC ic,
+       XKeyPressedEvent* event,
+       char* buffer_return,
+       int bytes_buffer,
+       KeySym* keysym_return,
+       StatusDef* status_return);
+int
+XmbTextPropertyToTextList(
+       Display *display,
+       XTextProperty *text_prop,
+       char ***list_return,
+       int *count_return);
+
+void
+XFreeStringList(char **list);
+
+int XmbTextListToTextProperty(
+        Display *display,
+        char **list,
+        int count,
+        XICCEncodingStyle style,
+        XTextProperty *text_prop_return);
+
+void
+XSetICFocus(XIC ic);
+
+void
+XUnsetICFocus(XIC ic);
+
+BoolDef XQueryPointer(
+       Display* display,
+       Window w,
+       Window* root_return,
+       Window* child_return,
+       int* root_x_return,
+       int* root_y_return,
+       int* win_x_return,
+       int* win_y_return,
+       unsigned int* mask_return);
+
+int XParseGeometry(
+       const char* string,
+       int* x,
+       int* y,
+       unsigned int* width,
+       unsigned int* height);
+
+int XResizeWindow(
+       Display* display,
+       Window w,
+       unsigned int width,
+       unsigned int height);
+
+void XSetWMNormalHints(Display* display,Window w,XSizeHints* hints);
+
+void XSetWMProperties(
+       Display* display,
+       Window w,
+       XTextProperty* window_name,
+       XTextProperty* icon_name,
+       char** argv,
+       int argc,
+       XSizeHints* normal_hints,
+       XWMHints* wm_hints,
+       XClassHint* class_hints);
+
+int XDefineCursor(Display* display,Window w,Cursor cursor);
+
+int XMoveResizeWindow(
+       Display* display,
+       Window w,
+       int x,
+       int y,
+       unsigned int width,
+       unsigned int height);
+
+int XMoveWindow(
+       Display* display,
+       Window w,
+       int x,
+       int y);
+
+StatusDef
+XParseColor(
+    Display *display,
+    Colormap map,
+    const char* spec,
+    XColor *colorPtr);
+
+int
+XFreeColors(Display *display,
+           Colormap cmap,
+           unsigned long pixels[],
+           int npixels,
+           unsigned long planes);
+int
+XGrabServer(Display *display);
+
+int
+XUngrabServer(Display *display);
+
+
+#endif
diff --git a/W11/X11/Xlocale.h b/W11/X11/Xlocale.h
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/W11/X11/Xmd.h b/W11/X11/Xmd.h
new file mode 100644 (file)
index 0000000..b300fe7
--- /dev/null
@@ -0,0 +1,10 @@
+#ifndef XMD_H
+#define XMD_H 1
+
+/*
+ * Machine dependent declarations
+ */
+
+typedef unsigned int CARD32;
+
+#endif /* XMD_H */
diff --git a/W11/X11/Xutil.h b/W11/X11/Xutil.h
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/W11/X11/cursorfont.h b/W11/X11/cursorfont.h
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/W11/X11/keysym.h b/W11/X11/keysym.h
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/W11/X11/keysymdef.h b/W11/X11/keysymdef.h
new file mode 100644 (file)
index 0000000..c005331
--- /dev/null
@@ -0,0 +1,97 @@
+
+#define XK_Meta_L              0xFFE7  /* Left meta */
+#define XK_Meta_R              0xFFE8  /* Right meta */
+#define XK_Alt_R               0xFFEA  /* Right alt */
+#define XK_Super_L             0xFFEB  /* Left super */
+#define XK_Super_R             0xFFEC  /* Right super */
+#define XK_Hyper_L             0xFFED  /* Left hyper */
+#define XK_Hyper_R             0xFFEE  /* Right hyper */
+
+#define XK_KP_Space            0xFF80  /* space */
+#define XK_KP_Tab              0xFF89
+#define XK_KP_Enter            0xFF8D  /* enter */
+#define XK_KP_F1               0xFF91  /* PF1, KP_A, ... */
+#define XK_KP_F2               0xFF92
+#define XK_KP_F3               0xFF93
+#define XK_KP_F4               0xFF94
+#define XK_KP_Home             0xFF95
+#define XK_KP_Left             0xFF96
+#define XK_KP_Up               0xFF97
+#define XK_KP_Right            0xFF98
+#define XK_KP_Down             0xFF99
+#define XK_KP_Prior            0xFF9A
+#define XK_KP_Page_Up          0xFF9A
+#define XK_KP_Next             0xFF9B
+#define XK_KP_Page_Down                0xFF9B
+#define XK_KP_End              0xFF9C
+#define XK_KP_Begin            0xFF9D
+#define XK_KP_Insert           0xFF9E
+#define XK_KP_Delete           0xFF9F
+#define XK_KP_Equal            0xFFBD  /* equals */
+#define XK_KP_Multiply         0xFFAA
+#define XK_KP_Add              0xFFAB
+#define XK_KP_Separator                0xFFAC  /* separator, often comma */
+#define XK_KP_Subtract         0xFFAD
+#define XK_KP_Decimal          0xFFAE
+#define XK_KP_Divide           0xFFAF
+#define XK_minus               0x02d
+
+#define XK_KP_0                        0xFFB0
+#define XK_KP_1                        0xFFB1
+#define XK_KP_2                        0xFFB2
+#define XK_KP_3                        0xFFB3
+#define XK_KP_4                        0xFFB4
+#define XK_KP_5                        0xFFB5
+#define XK_KP_6                        0xFFB6
+#define XK_KP_7                        0xFFB7
+#define XK_KP_8                        0xFFB8
+#define XK_KP_9                        0xFFB9
+
+#define XK_L1                  0xFFC8
+#define XK_L2                  0xFFC9
+#define XK_F13                 0xFFCA
+#define XK_L3                  0xFFCA
+#define XK_F14                 0xFFCB
+#define XK_L4                  0xFFCB
+#define XK_F15                 0xFFCC
+#define XK_L5                  0xFFCC
+#define XK_F16                 0xFFCD
+#define XK_L6                  0xFFCD
+#define XK_F17                 0xFFCE
+#define XK_L7                  0xFFCE
+#define XK_F18                 0xFFCF
+#define XK_L8                  0xFFCF
+#define XK_F19                 0xFFD0
+#define XK_L9                  0xFFD0
+#define XK_F20                 0xFFD1
+#define XK_L10                 0xFFD1
+#define XK_F21                 0xFFD2
+#define XK_R1                  0xFFD2
+#define XK_F22                 0xFFD3
+#define XK_R2                  0xFFD3
+#define XK_F23                 0xFFD4
+#define XK_R3                  0xFFD4
+#define XK_F24                 0xFFD5
+#define XK_R4                  0xFFD5
+#define XK_F25                 0xFFD6
+#define XK_R5                  0xFFD6
+#define XK_F26                 0xFFD7
+#define XK_R6                  0xFFD7
+#define XK_F27                 0xFFD8
+#define XK_R7                  0xFFD8
+#define XK_F28                 0xFFD9
+#define XK_R8                  0xFFD9
+#define XK_F29                 0xFFDA
+#define XK_R9                  0xFFDA
+#define XK_F30                 0xFFDB
+#define XK_R10                 0xFFDB
+#define XK_F31                 0xFFDC
+#define XK_R11                 0xFFDC
+#define XK_F32                 0xFFDD
+#define XK_R12                 0xFFDD
+#define XK_F33                 0xFFDE
+#define XK_R13                 0xFFDE
+#define XK_F34                 0xFFDF
+#define XK_R14                 0xFFDF
+#define XK_F35                 0xFFE0
+#define XK_R15                 0xFFE0
diff --git a/W11/w32/Makefile b/W11/w32/Makefile
new file mode 100644 (file)
index 0000000..1a82bbb
--- /dev/null
@@ -0,0 +1,28 @@
+
+CFLAGS=-O
+
+first_rule: all
+
+all allbin: ../lib/libW11.dll
+
+alldoc tags:
+
+../lib/libW11.dll: xlib.o ntutil.o event.o
+       dllwrap --export-all-symbols -o ../lib/libW11.dll xlib.o ntutil.o event.o -mwindows
+
+xlib.o: xlib.c ntdef.h
+       gcc -c xlib.c ${CFLAGS} -I.. -mwin32
+
+ntutil.o: ntutil.c ntdef.h
+       gcc -c ntutil.c ${CFLAGS} -I.. -mwin32
+
+event.o: event.c ntdef.h
+       gcc -c event.c ${CFLAGS} -I.. -mwin32
+
+debug:
+       gcc -c xlib.c -g -I.. -mwin32
+       gcc -c event.c -g -I.. -mwin32
+       gcc -c ntutil.c -g -I.. -mwin32
+
+clean:
+       -rm ../lib/libW11.dll xlib.o ntutil.o event.o
diff --git a/W11/w32/event.c b/W11/w32/event.c
new file mode 100644 (file)
index 0000000..f8f66e8
--- /dev/null
@@ -0,0 +1,944 @@
+
+#include <X11/Xlib.h>
+#include <X11/Xatom.h>
+#include <X11/keysymdef.h>
+#include "ntdef.h"
+
+/* a crude method to avoid losing the selection when
+   calling EmptyClipboard, which is necessary to do
+   every time the selection content changes, otherwise
+   windows apps use a cached copy of the selection */
+static volatile int destroyClipboardCatcher = 0;
+static NT_window *NT_CWIN = NULL;
+void
+catchNextDestroyClipboard()
+{
+    destroyClipboardCatcher=1;
+}
+
+typedef struct WinEvent_
+{
+    NT_window *window;
+    UINT message;
+    UINT wParam;
+    LONG lParam;
+} WinEvent;
+
+#define W11_QSIZE 100
+typedef struct WinEventQ_
+{
+    int num;
+    int avail;
+    int next;
+    int count;
+    int dispatch;
+    proto_W11EventHandler *handler;
+    WinEvent list[W11_QSIZE];
+} WinEventQ;
+
+static WinEventQ *wineventq = NULL;
+
+void
+initQ() {
+    int i;
+    WinEventQ *q = (WinEventQ *)allocateMemory(sizeof(WinEventQ));
+    q->num=W11_QSIZE-1;
+    q->avail=0;
+    q->next=0;
+    q->count=0;
+    q->dispatch=0;
+    q->handler=NULL;
+    for (i=0; i<W11_QSIZE; i++) {
+       q->list[i].message=0;
+       q->list[i].window = NULL;
+    }
+    wineventq = q;
+}
+
+static int
+getQdEvent(WinEventQ *q, XEvent *ev)
+{
+    WinEvent we;
+    if (q->count<=0) {
+       cjh_printf("Queue is empty\n");
+       return 0;
+    }
+    we = q->list[q->next];
+    WinEventToXEvent(&we,ev);
+    q->next++;
+    q->count--;
+    if (q->next>q->num) q->next=0;     
+    return 1;
+}
+
+static void
+QSendEvent(WinEventQ *q) 
+{
+    XEvent e;
+    if (q->handler != NULL) {
+       if (getQdEvent(q,&e)) (q->handler)(&e);
+    }
+}
+
+static int
+QEvent(WinEventQ *q, NT_window *window,UINT message,UINT wParam,LONG lParam)
+{
+    q->list[q->avail].window=window;
+    q->list[q->avail].message=message;
+    q->list[q->avail].wParam=wParam;
+    q->list[q->avail].lParam=lParam;
+    q->avail++; q->count++;
+    if (q->avail>q->num) q->avail=0;
+    if (q->dispatch) QSendEvent(q);
+    return 1;
+}
+
+
+/* Allow application to install an event handler call back.
+   This will make some actions such as moving the window work
+   better.
+
+   The event handler should look like:
+   void process_xevent(XEvent *ev) { }
+
+   To install it:
+   W11AddEventHandler(display,process_xevent);
+
+   The specific problem is that calling DefWindowProc()
+   in response to a WM_SYSCOMMAND will cause windows to run its
+   own event loop waiting for the mouse up event.  The application
+   therefore cannot rely on it's main event loop to get run for
+   each event.  Without running multiple threads, or setjmp, there
+   is little recourse for alerting the application in the
+   traditional X manner to Expose events while the window is
+   being moved.
+*/
+
+void W11AddEventHandler(Display *d, proto_W11EventHandler *ev) 
+{
+    wineventq->handler = ev;
+}
+
+
+static void
+doTranslateMessage(MSG *m)
+{
+       if ((m->message == WM_KEYDOWN) && 
+           ((m->wParam == VK_BACK) ||
+            (((m->wParam == VK_ADD) || (m->wParam == VK_SUBTRACT)) &&
+             (GetKeyState(VK_SHIFT) & 0x8000)))) return;
+       if ((m->message == WM_SYSKEYDOWN) && (m->wParam == VK_F10))
+       {
+           m->message = WM_KEYDOWN;
+           return;
+       }
+       TranslateMessage(m);
+}
+
+static LONG
+NT_default(HWND hWnd,UINT message,UINT wParam,LONG lParam)
+{
+    return DefWindowProc(hWnd, message, wParam, lParam);
+}
+
+static void
+NT_wakeup(HWND hWnd) 
+{
+    PostMessage(hWnd,USR_WakeUp,0,0L);
+}
+
+/*****************************************************************\
+
+       Function: MainWndProc
+       Inputs:   Window handle, message, message parameters.
+
+       Comments: This is called when messages are sent to the application
+                 but not to the application's message queue.  If an
+                 event can be processed, it is done here.  The equivalent
+                 XEvent is filled out in l_event, which is picked up
+                 in the X event routines.  Some events are not received
+                 from Windows, eg Enter/LeaveNotify, so these are made
+                 up as required.
+
+       Caution:  The application does not see HWND, but Window.
+
+\*****************************************************************/
+
+/* queued messages
+   WM_KEYDOWN
+   WM_KEYUP
+   WM_CHAR
+   WM_MOUSEMOVE
+   WM_BUTTONxx
+   WM_TIMER
+   WM_PAINT
+   WM_QUIT
+   */
+
+LONG NT_handleMsg(
+    HWND hWnd,           /* window handle                   */
+    UINT message,                /* type of message                 */
+    UINT wParam,                 /* additional information          */
+    LONG lParam)                 /* additional information          */
+{
+    RECT rect;
+    WINDOWPOS *posStruct;
+    unsigned long int st=0L;
+    NT_window *window;
+    long mask;
+    PAINTSTRUCT paintStruct;
+
+    /* if (message == WM_CLOSE) exit(0); */
+       
+    window = NT_find_window_from_id(hWnd);
+    if (window == NULL) return  (NT_default(hWnd, message, wParam, lParam));
+
+    mask = window->mask;
+       
+    switch (message) {
+       /* we'll handle these, later */
+       case WM_KILLFOCUS:
+           QEvent(wineventq,window,message,wParam,lParam);
+           NT_wakeup(hWnd);
+           break;
+       case WM_SETFOCUS:
+       case WM_QUIT:
+       case WM_CLOSE:
+       case WM_DESTROY:
+       case WM_SYSCHAR: /* alt-keys go here */
+       case WM_CHAR:
+       case WM_LBUTTONDBLCLK:
+       case WM_MBUTTONDBLCLK:
+       case WM_RBUTTONDBLCLK:
+       case USR_MapNotify:
+       case USR_EnterNotify:
+       case WM_MOVE:
+#if defined(WIN9X)
+       case WM_SIZING:
+#endif                 
+       case WM_SIZE:                   
+           QEvent(wineventq,window,message,wParam,lParam);
+           break;
+       case WM_DESTROYCLIPBOARD:
+           if (destroyClipboardCatcher)
+               destroyClipboardCatcher=0;
+           else {
+               QEvent(wineventq,window,message,wParam,lParam);
+               NT_wakeup(hWnd);
+            }
+           break;
+       case WM_PAINT:
+           BeginPaint(hWnd,&paintStruct);
+           FillRect(paintStruct.hdc, &paintStruct.rcPaint,window->bg);
+           QEvent(wineventq,window,message,
+                  (((paintStruct.rcPaint.right-paintStruct.rcPaint.left)&0xffff) |
+                   (((paintStruct.rcPaint.bottom-paintStruct.rcPaint.top)&0xffff)<<16)),
+                  (((paintStruct.rcPaint.left)&0xffff) | (((paintStruct.rcPaint.top)&0xffff)<<16)));
+
+           EndPaint(hWnd,&paintStruct);
+           break;
+           /* capture the mouse on button down to emulate x */
+       case WM_LBUTTONDOWN:
+       case WM_MBUTTONDOWN:
+       case WM_RBUTTONDOWN:
+           SetCapture(hWnd);
+           QEvent(wineventq,window,message,wParam,lParam);
+           break;
+       case WM_MBUTTONUP:
+       case WM_LBUTTONUP:
+       case WM_RBUTTONUP:
+           ReleaseCapture();
+           QEvent(wineventq,window,message,wParam,lParam);
+           break;
+       case WM_MOUSEMOVE:
+           if ((mask&PointerMotionMask) ||
+               ((mask&Button1MotionMask)&& (wParam&MK_LBUTTON)) ||
+               ((mask&Button2MotionMask)&& (wParam&MK_MBUTTON)) ||
+               ((mask&Button3MotionMask)&& (wParam&MK_RBUTTON)) ||
+               ((mask&ButtonMotionMask)&&((wParam&(MK_LBUTTON|MK_MBUTTON|MK_RBUTTON))))
+               )
+               QEvent(wineventq,window,message,wParam,lParam);
+           else
+               return (NT_default(hWnd, message, wParam, lParam));
+           break;
+       case WM_MOUSEWHEEL:
+           /* this event only seems to go to the top most window.
+              see if child windows accept it. */
+           window = NT_find_child(window,ButtonPressMask|Button2MotionMask|Button3MotionMask,
+                                  ButtonPressMask|Button3MotionMask );
+           if (window && ((window->mask)&ButtonPressMask)) 
+               QEvent(wineventq,window,message,wParam,lParam);
+           else
+               return (NT_default(hWnd, message, wParam, lParam));
+           break;
+       case WM_ERASEBKGND:
+           /* don't erase the background */
+           return 1;
+           break;
+       case WM_SYSCOMMAND:
+           wineventq->dispatch++;
+           NT_default(hWnd, message, wParam, lParam);
+           wineventq->dispatch--;
+           break;
+       case WM_KEYDOWN:
+           switch (wParam)
+           {
+               case VK_CANCEL:
+               case VK_CLEAR:
+               case VK_PAUSE:
+               case VK_PRIOR:
+               case VK_NEXT:
+               case VK_END:
+               case VK_HOME:
+               case VK_LEFT:
+               case VK_UP:
+               case VK_RIGHT:
+               case VK_DOWN:
+               case VK_SELECT:
+               case VK_PRINT:
+               case VK_EXECUTE:
+               case VK_INSERT:
+               case VK_DELETE:
+               case VK_HELP:
+               case VK_NUMLOCK:
+               case VK_SCROLL:
+               case VK_BACK:
+                case VK_F1:
+                case VK_F2:
+                case VK_F3:
+                case VK_F4:
+                case VK_F5:
+                case VK_F6:
+                case VK_F7:
+                case VK_F8:
+                case VK_F9:
+                case VK_F10:
+                case VK_F11:
+               case VK_F12:
+               case VK_ADD:
+               case VK_SUBTRACT:
+                   QEvent(wineventq,window,message,wParam,lParam);
+                   break;
+               default:
+                   return  (NT_default(hWnd, message, wParam, lParam));
+                   break;
+                                       
+           }
+           break;
+       default:                          /* Passes it on if unproccessed    */
+           return (NT_default(hWnd, message, wParam, lParam));
+    }
+    return 0L;
+}
+
+/*****************************************************************\
+
+       Function: NT_get_state
+       Inputs: 
+
+       Comments: Get the keyboard state
+
+\*****************************************************************/
+
+static unsigned int
+NT_get_state()
+{
+       unsigned int state = 0;
+       if (GetKeyState(VK_SHIFT)   & 0x8000) state |= ShiftMask;
+       if (GetKeyState(VK_CONTROL) & 0x8000)
+       {
+               if (!(GetKeyState(VK_MENU) & 0x8000)) 
+                       state |= ControlMask;
+       }
+       else if (GetKeyState(VK_MENU)    & 0x8000)
+               state |= Mod1Mask;
+       if (GetKeyState(VK_CAPITAL) & 0x0001) state |= LockMask;
+       if (GetKeyState(VK_NUMLOCK) & 0x0001) state |= Mod5Mask;
+       if (GetKeyState(VK_SCROLL)  & 0x0001) state |= Mod3Mask;
+       if (GetKeyState(VK_LBUTTON) & 0x8000) state |= Button1Mask;
+       if (GetKeyState(VK_MBUTTON) & 0x8000) state |= Button2Mask;
+       if (GetKeyState(VK_RBUTTON) & 0x8000) state |= Button3Mask;
+       return state;
+}
+
+int
+WinEventToXEvent(
+    WinEvent *we,
+    XEvent *event)
+{
+    POINT pt;
+    RECT rect;
+    unsigned long int st=0L;
+    UINT key;
+    HWND hWnd;
+    UINT wParam;
+    LONG lParam;
+    NT_window *window;
+       
+    do {               
+       if (event==NULL) break;
+       if (we == NULL) break;
+
+       window = we->window;
+       wParam = we->wParam;
+       lParam = we->lParam;
+               
+       event->type=-1;
+       event->xbutton.subwindow = None;
+       hWnd = window->w;
+               
+       switch (we->message) {
+           case WM_SETFOCUS:
+               event->type=FocusIn;
+               event->xfocus.window=(Window)window;
+               break;
+           case WM_KILLFOCUS:
+               event->type=FocusOut;
+               event->xfocus.window=(Window)window;
+               break;  
+                               /*      case WM_ERASEBKGND: */
+           case WM_PAINT:
+               event->type=Expose;
+               event->xexpose.x=LOWORD(lParam); /* right */
+               event->xexpose.y=HIWORD(lParam); /* top */
+               event->xexpose.width=LOWORD(wParam);
+               event->xexpose.height=HIWORD(wParam);
+               event->xexpose.count=0;
+               event->xexpose.window=(Window)window;
+               break;
+           case WM_LBUTTONDOWN:
+           case WM_LBUTTONDBLCLK:
+               event->type = ButtonPress;
+               event->xbutton.x = LOWORD (lParam);
+               event->xbutton.y = HIWORD (lParam);
+               if ( wParam & MK_SHIFT )
+                   event->xbutton.button=Button2;
+               else
+                   event->xbutton.button=Button1;
+               event->xbutton.window = (Window)window;
+               event->xbutton.time=GetTickCount();
+               break;
+           case WM_LBUTTONUP:
+               event->type=ButtonRelease;
+               event->xbutton.x=LOWORD(lParam);
+               event->xbutton.y=HIWORD (lParam);
+               if ( wParam & MK_SHIFT )
+                   event->xbutton.button=Button2;
+               else
+                   event->xbutton.button=Button1;
+               event->xbutton.window=(Window)window;
+               event->xbutton.time=GetTickCount();
+               break;
+           case WM_MBUTTONDOWN:
+           case WM_MBUTTONDBLCLK:
+               event->type=ButtonPress;
+               event->xbutton.x=LOWORD(lParam);
+               event->xbutton.y=HIWORD (lParam);
+               event->xbutton.button=Button2;
+               event->xbutton.window=(Window)window;
+               event->xbutton.time=GetTickCount();
+               break;
+           case WM_MBUTTONUP:
+               event->type=ButtonRelease;
+               event->xbutton.x=LOWORD(lParam);
+               event->xbutton.y=HIWORD (lParam);
+               event->xbutton.button=Button2;
+               event->xbutton.window=(Window)window;
+               event->xbutton.time=GetTickCount();
+               break;
+           case WM_RBUTTONDOWN:
+           case WM_RBUTTONDBLCLK:
+               event->type=ButtonPress;
+               event->xbutton.x=LOWORD(lParam);
+               event->xbutton.y=HIWORD (lParam);
+               event->xbutton.button=Button3;
+               event->xbutton.window=(Window)window;
+               event->xbutton.time=GetTickCount();
+               break;
+           case WM_RBUTTONUP:
+               event->type=ButtonRelease;
+               event->xbutton.x=LOWORD(lParam);
+               event->xbutton.y=HIWORD (lParam);
+               event->xbutton.button=Button3;
+               event->xbutton.window=(Window)window;
+               event->xbutton.time=GetTickCount();
+               break;
+           case WM_MOUSEMOVE:
+               if (hWnd!=(HWND)NT_CWIN)  /* Mouse in different window? */
+               {
+                   if (NT_CWIN==NULL) /* No previous window */
+                   {
+                       event->type = EnterNotify;
+                       event->xcrossing.x = LOWORD(lParam);
+                       event->xcrossing.y = HIWORD(lParam);
+                       event->xcrossing.window = (Window)window;
+                   }
+                   else
+                   {
+                       event->type=LeaveNotify;
+                       event->xcrossing.x=LOWORD(lParam);
+                       event->xcrossing.y=HIWORD(lParam);
+                       event->xcrossing.window = (Window)NT_find_window_from_id(NT_CWIN);
+                   }
+               }
+               else
+               {
+                   event->type=MotionNotify;    /* Fill out mouse event */
+                   event->xmotion.window=(Window)window;
+                   event->xmotion.x=pt.x=LOWORD(lParam);
+                   event->xmotion.y=pt.y=HIWORD(lParam);
+                   event->xmotion.time=GetTickCount();
+                   ClientToScreen(hWnd,&pt);     /* Translate coordinates */
+                   event->xmotion.x_root=pt.x;
+                   event->xmotion.y_root=pt.y;
+                   if (wParam&MK_CONTROL)
+                       st|=ControlMask;
+                   if (wParam&MK_SHIFT)
+                       st|=ShiftMask;
+                   if (wParam&MK_LBUTTON)
+                       st|=Button1Mask;
+                   if (wParam&MK_MBUTTON)
+                       st|=Button2Mask;
+                   if (wParam&MK_RBUTTON)
+                       st|=Button3Mask;
+                   event->xmotion.state=st;
+               }
+               NT_CWIN=(NT_window *)hWnd;
+               break;
+           case WM_MOUSEWHEEL:
+               event->type=ButtonRelease;
+               event->xbutton.x=LOWORD(lParam);
+               event->xbutton.y=HIWORD (lParam);
+               event->xbutton.button=HIWORD(wParam)>32768?Button5:Button4;
+               event->xbutton.window=(Window)window;
+               event->xbutton.time=GetTickCount();
+               if (wParam&MK_CONTROL)
+                   st|=ControlMask;
+               if (wParam&MK_SHIFT)
+                   st|=ShiftMask;
+               if (wParam&MK_LBUTTON)
+                   st|=Button1Mask;
+               if (wParam&MK_MBUTTON)
+                   st|=Button2Mask;
+               if (wParam&MK_RBUTTON)
+                   st|=Button3Mask;
+               event->xbutton.state=st;
+               break;
+           case WM_SYSCHAR:
+           case WM_CHAR:
+               event->type=KeyPress;
+               event->xkey.state=NT_get_state();
+               event->xkey.x=event->xkey.y=0; /* Inside the window */
+               event->xkey.keycode=LOWORD(wParam);
+               if (GetKeyState(VK_CONTROL) & 0x8000) {
+                   if (event->xkey.keycode == 32) { event->xkey.keycode=0; }
+                   if (event->xkey.keycode >255 ) { event->xkey.keycode=0; }
+               }
+               event->xkey.window=(Window)window;
+               break;
+           case WM_KEYDOWN:
+               event->type=KeyPress;
+               switch (wParam)
+               {
+                   case VK_CANCEL:  key=XK_Cancel;      break;
+                   case VK_CLEAR:   key=XK_Clear;       break;
+               /*  causes AltGr to create a keypress */
+               /*  case VK_MENU:    key=XK_Alt_L;       break;*/
+                   case VK_PAUSE:   key=XK_Pause;       break;
+                   case VK_PRIOR:   key=XK_Prior;       break;
+                   case VK_NEXT:    key=XK_Next;        break;
+                   case VK_END:     key=XK_End;         break;
+                   case VK_HOME:    key=XK_Home;        break;
+                   case VK_LEFT:    key=XK_Left;        break;
+                   case VK_UP:      key=XK_Up;          break;
+                   case VK_RIGHT:   key=XK_Right;       break;
+                   case VK_DOWN:    key=XK_Down;        break;
+                   case VK_SELECT:  key=XK_Select;      break;
+                   case VK_PRINT:   key=XK_Print;       break;
+                   case VK_EXECUTE: key=XK_Execute;     break;
+                   case VK_INSERT:  key=XK_Insert;      break;
+                   case VK_DELETE:  key=XK_Delete;      break;
+                   case VK_HELP:    key=XK_Help;        break;
+                   case VK_NUMLOCK: key=XK_Num_Lock;    break;
+                   case VK_SCROLL:  key=XK_Scroll_Lock; break;
+                   case VK_BACK:    key=XK_BackSpace; break;
+                    case VK_F1:      key=XK_F1;          break;
+                    case VK_F2:      key=XK_F2;          break;
+                    case VK_F3:      key=XK_F3;          break;
+                    case VK_F4:      key=XK_F4;          break;
+                    case VK_F5:      key=XK_F5;          break;
+                    case VK_F6:      key=XK_F6;          break;
+                    case VK_F7:      key=XK_F7;          break;
+                    case VK_F8:      key=XK_F8;          break;
+                    case VK_F9:      key=XK_F9;          break;
+                    case VK_F10:     key=XK_F10;         break;
+                    case VK_F11:     key=XK_F11;         break;
+                    case VK_F12:     key=XK_F12;         break;
+                   case VK_ADD:     key=XK_KP_Add;      break;
+                   case VK_SUBTRACT:key=XK_KP_Subtract; break;
+                   default:         key=0;              break;
+               }
+               if (key == 0) {
+                   event->type = -1;
+               }
+               else
+               {
+                   event->xkey.keycode=key;
+                   event->xkey.window=(Window)window;
+                   event->xkey.state=NT_get_state();
+                   event->xkey.x=event->xkey.y=0; /* Inside the window */
+               }
+               break;
+           case WM_DESTROY:
+           case WM_QUIT:
+           case WM_CLOSE:
+               event->type = ClientMessage;
+               event->xclient.format = 32;
+               event->xclient.data.l[0] = XInternAtom(NULL,"WM_DELETE_WINDOW", FALSE);
+               break;
+           case USR_EnterNotify:
+               event->type = EnterNotify;
+               event->xcrossing.x = LOWORD(lParam);
+               event->xcrossing.y = HIWORD(lParam);
+               event->xcrossing.window = (Window)window;
+               break;
+           case WM_MOVE:
+               if (window->min==0)
+               {
+                   window->x =  LOWORD(lParam);
+                   window->y =  HIWORD(lParam);
+                   NT_configureNotify(window,window->x,window->y);
+                   event->type = ConfigureNotify;
+                   event->xconfigure.window = (Window)window;
+                   event->xconfigure.x = 0;  /* client area is always @ 0 */
+                   event->xconfigure.y = 0;
+                   event->xconfigure.width = window->wdth;
+                   event->xconfigure.height = window->hght;
+                   event->xconfigure.above = Above;
+               }
+               break;
+           case WM_SIZING:
+               event->type = ConfigureNotify;
+               window->wdth =  LOWORD(lParam);
+               if (window->wdth<window->minx)
+                   window->wdth = window->minx;
+               window->hght =  HIWORD(lParam);
+               if (window->hght<window->minx)
+                   window->hght = window->miny;
+               NT_configureNotify(window,window->x,window->y);
+               event->xconfigure.window = (Window)window;
+               event->xconfigure.x = 0;
+               event->xconfigure.y = 0;
+               event->xconfigure.width = window->wdth;
+               event->xconfigure.height = window->hght;
+               event->xconfigure.above = Above;
+               break;
+           case WM_SIZE:
+               switch(wParam)
+               {
+                   case SIZE_MINIMIZED:
+                       event->type=UnmapNotify;
+                       window->min=1;
+                       break;
+                   default:
+                       event->type = ConfigureNotify;
+                       window->wdth =  LOWORD(lParam);
+                       if (window->wdth<window->minx)
+                           window->wdth = window->minx;
+                       window->hght =  HIWORD(lParam);
+                       if (window->hght<window->minx)
+                           window->hght = window->miny;
+                       event->xconfigure.window = (Window)window;
+                       event->xconfigure.x = 0;
+                       event->xconfigure.y = 0;
+                       event->xconfigure.width = window->wdth;
+                       event->xconfigure.height = window->hght;
+                       event->xconfigure.above = Above;
+#if !defined(WIN9X)                                            
+                       if (window->min) event->type=MapNotify;
+#endif                                         
+                       window->min=0;
+                       break;
+               }
+               break;
+           case WM_DESTROYCLIPBOARD:
+               event->type = SelectionClear;
+               event->xselectionclear.time = GetTickCount();
+               break;
+           case USR_MapNotify:
+               event->type=MapNotify;
+               break;
+           case USR_ConvertSelection:
+               event->type=SelectionNotify;
+               event->xselection.requestor = (Window)window;
+               event->xselection.property = XA_CUT_BUFFER0;                    
+               break;
+           default:
+               break;
+       }
+    } while(0);
+    return (event==NULL?0: (event->type==-1?0:1));
+}
+/*****************************************************************\
+
+
+       Function: XCheckWindowEvent
+       Inputs:   display, window, event mask.
+       Returned: pointer to filled in event structure, status.
+
+       Comments: This is fudged at the moment to work with the toolkit.
+                 The event system needs rewriting to account properly for
+                 event masks.
+
+\*****************************************************************/
+
+BoolDef
+XCheckTypedEvent(display,ev,rep)
+Display *display;
+int ev;
+XEvent *rep;
+{
+       xtrace("XCheckTypedEvent\n");
+       return (False);
+}
+
+BoolDef
+XCheckWindowEvent(display,w,emask,ev)
+Display *display;
+Window w;
+long emask;
+XEvent *ev;
+{
+       NT_window *ntw=(NT_window *)w;
+       MSG msg;
+       BoolDef status = 0;
+
+       xtrace("XCheckWindowEvent\n");
+       if (emask&0)
+               if (PeekMessage(&msg,ntw->w,USR_MapNotify,
+                                               USR_MapNotify,PM_REMOVE)||
+                   PeekMessage(&msg,ntw->w,WM_PAINT,WM_PAINT,PM_REMOVE))
+               {
+                       cjh_printf("removed message\n");
+                       ev->type=ConfigureNotify;
+                       status = 1;
+               }
+       return(status);
+}
+
+/*
+  XPending checks for x events pending.
+  We don't know if we have x events until we process
+  the win events.
+  */
+int
+XPending (display)
+Display *display;
+{
+       MSG msg;
+       /*      xtrace("XPending\n"); */
+       while(wineventq->count<=0 && PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
+       {
+               doTranslateMessage(&msg);
+               DispatchMessage(&msg);
+       }
+       return wineventq->count;
+}
+
+int
+XPutBackEvent(display,event)
+Display *display;
+XEvent *event;
+{
+       xtrace("XPutBackEvent\n");
+       return 0;
+}
+
+
+StatusDef
+XSendEvent(display,w,prop,emask,event)
+Display *display;
+Window w;
+BoolDef prop;
+long emask;
+XEvent *event;
+{
+       xtrace("XSendEvent\n");
+       return 0;
+}
+
+/* I'm tempted to flush the windows queue
+**   before checking, but I think that would
+**   break the assumtion that most of the WM_PAINT
+**   messges are only going to be dispatched when
+**   the app is directly calling us.
+*/
+
+BoolDef
+XCheckTypedWindowEvent(
+       Display* display,
+       Window w,
+       int event_type,
+       XEvent* event_return)
+{
+       int i,j;
+       xtrace("XCheckTypedWindowEvent\n");
+       if (w==0) return 0;
+       /*
+       i = wineventq->next;
+       while(i != wineventq->avail)
+       {
+               if (wineventq->list[i].window==(NT_window*)w)
+               {
+                       WinEventToXEvent(&wineventq->list[i],event_return);
+                       if (event_return->type == event_type)
+                       {
+                               break;
+                       }
+               }
+               i++;
+               if (i>wineventq->num) i=0;
+       }
+       if (i != wineventq->avail)
+       {
+               while(i != wineventq->next)
+               {
+                       j =i-1;
+                       if (j<0) j= wineventq->num;
+                       copyWinEvent(&wineventq->list[i],&wineventq->list[j]);
+                       i = j;
+               }
+               wineventq->next++;
+               wineventq->count--;
+               cjh_printf("removed an event\n");
+               return 1;
+       }
+       */
+       return 0;
+}
+
+/*****************************************************************\
+
+
+       Function: XWindowEvent
+       Inputs:   display, window, event mask.
+       Returned: pointer to filled in event structure.
+
+       Comments: This is fudged at the moment to work with the toolkit.
+                 The event system needs rewriting to account properly for
+                 event masks.
+
+\*****************************************************************/
+
+int
+XWindowEvent(display,w,emask,rep)
+Display *display;
+Window w;
+long emask;
+XEvent *rep;
+{
+       NT_window *ntw=(NT_window *)w;
+       MSG msg;
+
+       xtrace("XWindowEvent\n");
+       if (emask&ExposureMask)
+       {
+               GetMessage(&msg,ntw->w,USR_MapNotify,USR_MapNotify);
+               rep->type=ConfigureNotify;
+       }
+       return 0;
+}
+
+
+
+/*****************************************************************\
+
+       Function: XNextEvent
+       Inputs:   display, event structure pointer.
+
+       Comments: Windows routines receive messages (events) in two ways:
+                 firstly by GetMessage, which takes messages from the
+                 calling thread's message queue, and secondly by the
+                 window function being called with events as arguments.
+                 To simulate the X system, we get messages from the queue
+                 and pass them to the window function anyway, which
+                 processes them and fills out the local XEvent structure.
+                 DispatchMessage calls the window procedure and waits until
+                 it returns. Translate message turns WM_KEYUP/DOWN messages
+                 into WM_CHAR.
+
+\*****************************************************************/
+
+int
+XNextEvent(Display *display,XEvent  *event)
+{
+    MSG msg;
+       
+    xtrace("XNextEvent\n");
+
+    /* if there isn't already an event in the pipe, this will block */
+    while(wineventq->count <= 0 && GetMessage(&msg, NULL, 0, 0)>0)
+    {          
+       doTranslateMessage(&msg);
+       DispatchMessage(&msg);
+    }
+    if (wineventq->count>0)
+    {
+       getQdEvent(wineventq,event);
+    }
+    else
+    {
+       /* hmm, GetMessage failed, maybe we're supposed to quit */
+       event->type=ClientMessage;
+       event->xclient.format = 32;
+       event->xclient.data.l[0] = XInternAtom(NULL,"WM_DELETE_WINDOW", FALSE);
+       return 1;
+    }
+    return 1;
+}
+
+BoolDef
+XFilterEvent(XEvent* event,Window window)
+{
+       xtrace("XFilterEvent\n");
+       return 0;
+}
+
+BoolDef
+XQueryPointer(
+       Display* display,
+       Window w,
+       Window* root_return,
+       Window* child_return,
+       int* root_x_return,
+       int* root_y_return,
+       int* win_x_return,
+       int* win_y_return,
+       unsigned int* mask_return)
+{
+    POINT point;
+       RECT rect;
+       xtrace("XQueryPointer\n");
+    GetCursorPos(&point);
+    *root_x_return = point.x;
+    *root_y_return = point.y;
+       GetWindowRect(((NT_window*)w)->w,&rect);
+       *win_x_return= point.x - rect.left;
+       *win_y_return= point.y - rect.top;
+       *mask_return = NT_get_state();
+    return True;
+}
+
+int
+XConvertSelection(
+    Display *display,
+    Atom sel, Atom target, Atom prop,
+    Window req,        
+    Time time)
+{
+    xtrace("XConvertSelection\n");
+    QEvent(wineventq,(NT_window*)req,USR_ConvertSelection,0,0L);
+    NT_wakeup(((NT_window*)req)->w);
+    return 0;
+}
+
diff --git a/W11/w32/ntdef.h b/W11/w32/ntdef.h
new file mode 100644 (file)
index 0000000..cfe94fe
--- /dev/null
@@ -0,0 +1,73 @@
+
+
+#ifndef __NTDEF
+#define __NTDEF
+#include <windows.h>
+
+#define INVALID_HANDLE ((HANDLE) -2)
+#define NONMAPPED_HANDLE  ((HANDLE) -3)
+#define VALID_WINDOW(x) (x && (((NT_window *)x)->w != INVALID_HANDLE))
+#define xtrace
+#define cjh_printf
+
+#define CNUMTORGB(x) x
+        /* #define printf(x)   *//* x */ 
+        /* #define SetSystemPaletteUse(x) *//* x */
+
+/*     Windows NT Special event aliases        */
+
+#define USR_MapNotify       0x0401
+#define USR_EnterNotify     0x0402
+#define USR_LeaveNotify     0x0403
+#define USR_Expose          0x0404
+#define USR_ResizeRequest   0x0405
+#define USR_WakeUp          0x0406
+#define USR_ConvertSelection 0x0407
+
+struct NT_child
+{
+       struct NT_window *w;
+       struct NT_child *next;
+} NT_child;
+
+typedef struct NT_window
+{
+       HWND w;
+       HBRUSH bg;
+       int parentRelative;
+       struct NT_window *parent;      /* parent of this window */
+       struct NT_window *next;        /* next window in list */
+       struct NT_child *child;        /* points to list of children */
+       int    x, y;                   /* Position */
+       unsigned int wdth, hght;       /* Dimensions */
+       char *title_text;
+       struct NT_prop_list *props;    /* linked list of properties.*/
+       HDC    hDC;
+       HBITMAP hBitmap;
+       int min;
+       int minx, miny;  /* minimum window size */
+       int top_flag;
+       long mask;   /* selectInputMask */
+} NT_window;
+
+/* Routine declarations */
+
+struct NT_window      *NT_find_window_from_id();
+int                    NT_delete_window();
+
+struct NT_window      *NT_new_window();
+int NT_add_child(NT_window *parent,NT_window *child);
+struct NT_window *NT_find_child(NT_window *w,unsigned long mask,
+                                                                  unsigned long val);
+int NT_del_child(NT_window *parent,NT_window *child);
+void freeMemory(void *p);
+void *allocateMemory(int s);
+void initQ();
+void catchNextDestroyClipboard();
+
+void NT_SetAtom(ATOM class);
+HWND NT_create_window(char *title,DWORD style,int x,int y,int w, int h,HWND parent);
+LONG NT_handleMsg(HWND hWnd,UINT message,UINT wParam,LONG lParam);
+HBITMAP NT_getWallpaper();
+void NT_moveWindow(NT_window *ntw, BOOL repaint);
+#endif
diff --git a/W11/w32/ntutil.c b/W11/w32/ntutil.c
new file mode 100644 (file)
index 0000000..613312b
--- /dev/null
@@ -0,0 +1,379 @@
+#include "ntdef.h"
+
+static struct NT_window *window_list=NULL;
+
+void
+freeMemory(void *p) {
+       if (p!=NULL) free(p);
+}
+void *
+allocateMemory(int s) {
+       void *p=NULL;
+       if (s)
+       {
+               p=(void *)malloc(s);
+               if (p) memset(p,0,s);
+       }
+       return p;
+}
+
+
+/*---------------------------------------------------*\
+| Function: NT_new_window                             |
+| Purpose:  Add a new window id to the Window table   |
+| Return:   Pointer to the new Window structure.      |
+\*---------------------------------------------------*/
+struct NT_window *
+NT_new_window()
+{
+       struct NT_window *new;
+       xtrace("NT_new_window\n");
+       new = (struct NT_window *) allocateMemory (sizeof(struct NT_window));
+       new->next = window_list;
+       new->child=NULL;
+       new->min = 1;
+       new->minx =0;
+       new->miny =0;
+       new->w = INVALID_HANDLE;
+       new->parent= NULL;
+       new->hBitmap = INVALID_HANDLE;
+       new->hDC = INVALID_HANDLE;
+       window_list = new;
+       cjh_printf("NEW window %x\n",window_list);
+       return(window_list);
+}
+       
+/*---------------------------------------------------*\
+| Function: NT_delete_window                          |
+| Purpose:  Remove a window from the window list      |
+| Input:    w - pointer to window data                |
+| Return:   TRUE if deleted                           |
+\*---------------------------------------------------*/
+int
+NT_delete_window(struct NT_window *w)
+{
+       NT_window *f;
+       xtrace("NT_delete_window\n");
+       
+       if (w->w != INVALID_HANDLE)
+       {
+               /* ShowWindow(w->w,SW_HIDE);*/
+               DestroyWindow(w->w);
+               w->w=INVALID_HANDLE;
+       }
+       if (w->hBitmap != INVALID_HANDLE)
+       {
+               DeleteObject(w->hBitmap);
+               w->hBitmap = INVALID_HANDLE;
+       }
+       if (w->hDC != INVALID_HANDLE)
+       {
+               DeleteDC(w->hDC);
+               w->hDC=INVALID_HANDLE;
+       }
+       
+       if (window_list == w)
+               window_list=w->next;
+       else
+       {
+               for (f=window_list; f!=NULL && f->next!=w; f=f->next);
+               if (f!=NULL)
+                       f->next = w->next;
+       }
+       freeMemory(w);
+       return TRUE;
+}
+
+/*------------------------------------------------*\
+| Function: NT_find_window_from_id                 |
+| Purpose:  Find the window in the window list     |
+|           from the HWND id of the window.        |
+| Input:    w - Window id (Windows HWND)           |
+| Return:   pointer to NT_window structure for w.  |
+\*------------------------------------------------*/
+struct NT_window *
+NT_find_window_from_id(HWND w)
+{
+       struct NT_window *current = window_list;
+       /* xtrace("NT_find_window_from_id\n"); */
+       
+       while ( current != NULL &&
+                       current->w != w )
+               current = current->next;
+       if(current)
+               return(current);
+       current=window_list;
+       return NULL;
+}
+
+/*****************************************************************\
+
+       Function: NT_add_child
+       Inputs:   parent and child window IDs.
+       Returned: 1
+
+       Comments: When a child window is created (eg. client canvas) we
+                 update our internal list of windows and their children.
+                 New children are added to the front of the list.
+
+\*****************************************************************/
+
+int
+NT_add_child(parent,child)
+NT_window *parent,*child;
+{
+       struct NT_child *new;
+
+       new=(struct NT_child *) allocateMemory (sizeof(struct NT_child));
+       new->w=child;
+       new->next = parent->child;
+       parent->child=new;
+       return(1);
+}
+
+struct NT_window *
+NT_find_child(NT_window *w,unsigned long mask,
+                                                               unsigned long val)
+{
+       struct NT_window *ret = NULL;
+       struct NT_child *child = NULL;
+       if (w)
+       {
+               if ((w->mask&mask)==val) ret=w;
+               child = w->child;
+               while(!ret && child) {
+                       ret = NT_find_child(child->w, mask, val);
+                       child=child->next;
+               }
+       }
+       return ret;
+}
+
+
+
+/*****************************************************************\
+
+       Function: NT_del_child
+       Inputs:   parent and child window IDs.
+       Returned: TRUE if window is removed, FALSE otherwise.
+
+       Comments: Finds child window if it exits, and it so removes it from
+                 the window list.
+
+\*****************************************************************/
+
+int
+NT_del_child(parent,child)
+struct NT_window *parent;
+struct NT_window *child;
+{
+       struct NT_child *current,*last;
+       int status=FALSE;
+
+       if (parent->child==NULL)
+       {
+       }
+       else if (parent->child->w==child)
+       {
+               current = parent->child;
+               parent->child=parent->child->next;
+               freeMemory(current);
+               status=TRUE;
+       }
+       else
+       {
+               last=parent->child;
+               current=parent->child->next;
+               while (current->w!=child && current!=NULL)
+               {
+                       last=current;
+                       current=current->next;
+               }
+               if (current!=NULL)
+               {
+                       last->next=current->next;
+                       freeMemory(current);
+                       status=TRUE;
+               }
+       }
+       return(status);
+}
+
+/*****************************************************************\
+
+       Function: WinMain
+       Inputs:   instance, previous instance, command line arguments,
+                 default start up.
+
+       Comments: Called instead of main() as the execution entry point.
+
+\*****************************************************************/
+#ifdef NOTCYGWIN
+#define MAX_COMMAND_ARGS 20
+static HANDLE hInstance,hPrevInstance;
+int APIENTRY
+WinMain(HINSTANCE hInst,HINSTANCE hPrevInst,LPSTR lpCmdLine,int nCmdShow)
+{
+        static char *command_args[MAX_COMMAND_ARGS];
+        static int num_command_args;
+        static char proEng[] = "proe";
+        char *wordPtr,*tempPtr;
+        int i,quote;
+       hInstance=hInst;
+       hPrevInstance=hPrevInst;
+
+        for (i=0;i<MAX_COMMAND_ARGS;i++)
+          command_args[i] = NULL;
+
+        wordPtr = lpCmdLine;
+        quote = 0;
+        num_command_args = 1;
+        command_args[0] = proEng;
+        while  (*wordPtr && (*wordPtr == ' ' || *wordPtr == '\t'))
+           wordPtr++;
+        if (*wordPtr == '\"')
+        {
+          quote = 1;
+          wordPtr++;
+        }
+        if (!*wordPtr)
+          main(0,NULL);
+        else
+        {
+          while (*wordPtr && num_command_args < MAX_COMMAND_ARGS)
+          {
+            tempPtr = wordPtr;
+            if (quote)
+            {
+              while (*tempPtr && *tempPtr != '\"')
+                tempPtr++;
+              quote = 0;
+            }
+            else
+              while (*tempPtr && *tempPtr != ' ')
+                tempPtr++;
+            if (*tempPtr)
+              *(tempPtr++) = '\0';
+            command_args[num_command_args++] = wordPtr;
+            wordPtr = tempPtr;
+            while (*wordPtr && (*wordPtr == ' ' || *wordPtr == '\t'))
+              wordPtr++;
+            if (*wordPtr == '\"')
+            {
+              quote = 1;
+              wordPtr++;
+            }
+          }
+          main(num_command_args,command_args);
+        }
+
+}
+#endif
+
+static ATOM atom=0;
+void
+NT_SetAtom(ATOM class)
+{
+       atom = class;
+}
+
+HWND
+NT_create_window(char *title,DWORD style,int x,int y,int w, int h,HWND parent)
+{
+       HMODULE hInst = NULL; /* GetModuleHandleA(NULL); */
+       return CreateWindow((LPCTSTR)MAKELONG(atom,0),title,style,x,y,w,h,
+                                                                parent,NULL,hInst,NULL);
+}
+HBITMAP
+NT_getWallpaper()
+{
+       HBITMAP hb = NULL;
+       do {
+               HKEY hKey;
+               TCHAR wallpaper[MAX_PATH];
+               DWORD dwBufLen = MAX_PATH;
+               LONG lRet;
+
+               lRet = RegOpenKeyEx(HKEY_CURRENT_USER, TEXT("Control Panel\\Desktop"), 0, KEY_QUERY_VALUE, &hKey);
+               if (lRet != ERROR_SUCCESS) break;
+
+               lRet = RegQueryValueEx(hKey, TEXT("Wallpaper"), NULL, NULL, (LPBYTE)wallpaper, &dwBufLen);
+               if (lRet != ERROR_SUCCESS) break;
+
+               RegCloseKey(hKey);
+               hb = LoadImage(NULL, wallpaper, IMAGE_BITMAP, 0, 0,
+               LR_CREATEDIBSECTION | LR_DEFAULTSIZE | LR_LOADFROMFILE );
+       } while(0);
+       return hb;
+}
+
+void
+NT_moveWindow(NT_window *ntw, BOOL repaint)
+{
+       MoveWindow(ntw->w, ntw->x,ntw->y,ntw->wdth,ntw->hght,repaint);
+       NT_configureNotify(ntw,ntw->x,ntw->y);
+}
+
+NT_set_origin(NT_window *ntw,int x, int y)
+{
+       HDC hdc;
+       hdc = GetDC(ntw->w);
+       SetBrushOrgEx(hdc,-x,-y,NULL);
+       ReleaseDC(ntw->w,hdc);
+}
+
+
+NT_confChild(NT_window *ntw,int x, int y)
+{
+       HDC hdc;
+       struct NT_child *child = NULL;
+       if (ntw)
+       {
+               if (ntw->parentRelative) NT_set_origin(ntw,x,y);
+               child = ntw->child;
+               while(child && child->w) {
+                       NT_confChild(child->w, child->w->x+x, child->w->y+y);
+                       child=child->next;
+               }
+       }
+}
+
+NT_configureNotify(NT_window *ntw,int x, int y)
+{
+       while(ntw && ntw->parent) {
+               ntw=ntw->parent;
+       }
+       NT_confChild(ntw,ntw->x,ntw->y);
+}
+
+
+
+/*
+HBITMAP
+NT_getWallpaper() 
+{
+       WCHAR wszWallpaper [MAX_PATH];
+       CHAR szWallpaper[MAX_PATH];
+       HRESULT hr;
+       HBITMAP hb = NULL;
+       IActiveDesktop* pIAD = NULL;
+       do {
+               CoInitialize ( NULL );
+               hr = CoCreateInstance ( CLSID_ActiveDesktop,
+                            NULL,
+                            CLSCTX_INPROC_SERVER,
+                            IID_IActiveDesktop,
+                            (void**) &pIAD );
+               if (! SUCCEEDED(hr) ) break;
+        hr = pIAD->GetWallpaper ( wszWallpaper, MAX_PATH, 0 );
+
+        if (! SUCCEEDED(hr) ) break;
+               wsprintf(szWallpaper,"%ls",wszWallpaper);
+               hb = LoadImage(NULL, szWallpaper, IMAGE_BITMAP, 0, 0,
+               LR_CREATEDIBSECTION | LR_DEFAULTSIZE | LR_LOADFROMFILE );
+       } while(0);
+       if (pIAD) pIAD->Release();
+       CoUninitialize();
+       return hb;
+}
+*/
diff --git a/W11/w32/xlib.c b/W11/w32/xlib.c
new file mode 100644 (file)
index 0000000..c51ca00
--- /dev/null
@@ -0,0 +1,5213 @@
+/*****************************************************************\
+
+
+       Library of X window functions which call Windows 32
+       equivalent functions.
+
+       Some data structures are maintained by this code,
+       simulating the operation of an X server and window manager.
+
+       Aug/Sep-92      xyz     $$1 Created.
+        Oct-92  abc $$2 Added color stuff.
+
+\******************************************************************/
+
+#ifndef __XNT
+#define __XNT
+
+#include <X11/Xlib.h>
+#include <X11/Xatom.h>
+
+#include <stdio.h>
+#include <math.h>
+#include <string.h>
+#include <fcntl.h>
+#include "ntdef.h"
+
+/* Local Data */
+
+static void                   NT_set_GC_pen();
+static void                   NT_set_GC_brush();
+static HPEN                   NT_get_GC_pen();
+static HBRUSH                 NT_get_GC_brush();
+static HBRUSH                 NT_get_GC_bgbrush();
+
+void NT_set_rop();
+double NT_deg64_to_rad(int a);
+
+/*----------------------------------------------------------------*\
+| FUNCTIONS TO MAINTAIN AN INTERNAL LIST OF WINDOWS AND THEIR      |
+| ATTRIBUTES - AS WOULD BE MAINTAINED IN THE X SERVER.             |
+\*----------------------------------------------------------------*/
+
+/* Structure to hold pen and brush info in GC ext_data field */
+
+typedef struct NTGC_
+{
+       HPEN    pen;
+       HBRUSH  brush;
+       HBRUSH  bgbrush;
+} NTGC;
+
+HDC
+cjh_get_dc(NT_window *window)
+{
+       /* pixmaps have to do SelectObject() on their dc's */
+       if (window->hDC == INVALID_HANDLE)
+               if (window->w == INVALID_HANDLE)
+               {
+                       window->hDC= CreateDC("DISPLAY", NULL, NULL, NULL);
+               }
+       else
+               window->hDC=GetDC(window->w);
+    return window->hDC;
+}
+
+int
+cjh_rel_dc(NT_window *window,HDC dc)
+{
+       return TRUE;
+       /*      return ReleaseDC(window, dc); */
+}
+
+HDC
+drawableGetDC(Drawable drawable)
+{
+       cjh_get_dc((NT_window *)drawable);
+}
+
+int
+drawableRelDC(Drawable drawable, HDC hDC)
+{
+       cjh_rel_dc((NT_window *)drawable, hDC);
+}
+
+
+
+/*****************************************************************\
+
+       Function: XOpenDisplay
+       Inputs:   Display name
+
+       Comments: Fills out a Display structure and a Visual and Screen.
+                 Hopefully all the X macros should work with this
+                 structure.  Note that the default visual is for a
+                 True colour screen (24bits).
+\*****************************************************************/
+Display *
+XOpenDisplay (name)
+const char *name;
+{
+       static char vstring[]="NT Xlibemu",
+               *vs,*dn;
+
+       Display *d = NULL;
+       Screen *scrd;
+       static Depth dlist[1];
+       static Visual vlist[1];
+       Colormap cmap;
+       RECT rect;
+       int depth;
+       HDC rootDC = CreateDC("DISPLAY",NULL,NULL,NULL);
+
+       depth = GetDeviceCaps(rootDC, BITSPIXEL);
+       
+       xtrace("XOpenDisplay\n");
+
+       initQ();
+       
+       dlist[0].depth=depth;
+       dlist[0].nvisuals=1;
+       dlist[0].visuals=vlist;
+       vlist[0].ext_data=NULL;
+       vlist[0].visualid=0;
+       vlist[0].class=PseudoColor;
+       vlist[0].bits_per_rgb=8;
+       vlist[0].map_entries=256;
+       vlist[0].red_mask=255;
+       vlist[0].green_mask=255<<8;
+       vlist[0].blue_mask=255<<16;
+       scrd=(Screen *) allocateMemory (sizeof (Screen));
+       (NT_window*)(scrd->root)= NT_new_window();
+       ((NT_window*)(scrd->root))->w=GetDesktopWindow();
+       ((NT_window*)(scrd->root))->parent=0;
+       GetWindowRect(GetDesktopWindow(),&rect);
+       scrd->width=rect.right-rect.left;
+       scrd->height=rect.bottom-rect.top;
+       scrd->mwidth=260;
+       scrd->mheight=190;
+       scrd->ndepths=1;
+       scrd->depths=dlist;
+       scrd->root_depth=depth;
+       scrd->root_visual=vlist;
+       scrd->default_gc=NULL;
+       scrd->cmap=cmap;
+       scrd->white_pixel=0xffffff;
+       scrd->black_pixel=0;
+
+       d=(Display *) allocateMemory (sizeof (Display));
+       scrd->display=d;
+       vs=(char *) allocateMemory (sizeof (char)*strlen (vstring)+1);
+       dn=(char *) allocateMemory (sizeof (char)*strlen (name)+1);
+       strcpy (vs,vstring);
+       strcpy (dn,name);
+       d->ext_data=NULL;
+       d->fd=0;
+       d->proto_major_version=11;
+       d->proto_minor_version=4;
+       d->vendor=vs;
+       d->release=4;
+       d->display_name=dn;
+       d->nscreens=1;
+       d->screens=scrd;
+       d->max_keycode=255;
+
+       return (d);
+}
+
+
+int
+XCloseDisplay(Display *display)
+{
+  NT_window *wanderer;
+
+  xtrace("XCloseDisplay\n");
+/* Do something ? */
+/* Must GlobalDelete all atoms/properties leftover */
+  return 0;
+}
+
+char *
+XDisplayString(Display *display)
+{
+       return (display->display_name);
+}
+
+
+int
+XFlush(Display *display)
+{
+       xtrace("XFlush\n");
+       return 0;
+}
+
+
+int
+XSync(display,discard)
+Display *display;
+int discard;
+{
+       /* Do nothing here either */
+       return 0;
+}
+
+/*****************************************************************\
+
+       Function: XGetVisualInfo
+       Inputs:   display, info mask, template, number of matches.
+       Returned: List of XVisualInfo structures, one for each matching
+                 Visual.
+
+       Comments: Behaves like X routine, but there is only ever one
+                 Visual, so the returned list is never longer than one.
+
+\*****************************************************************/
+XVisualInfo *
+XGetVisualInfo(display,vinm,vint,n)
+Display *display;
+long vinm;
+XVisualInfo *vint;
+int *n;
+{
+       static XVisualInfo xvi;
+       int status=1;
+       xtrace("XGetVisualInfo\n");
+
+       if ((vinm&VisualIDMask|vinm==VisualAllMask)&&
+            vint->visualid!=display->screens->root_visual->visualid)
+               status=0;
+       if ((vinm&VisualScreenMask|vinm==VisualAllMask)&&
+           vint->screen!=0)
+               status=0;
+       if ((vinm&VisualDepthMask|vinm==VisualAllMask)&&
+           vint->depth!=24)
+               status=0;
+       if ((vinm&VisualClassMask|vinm==VisualAllMask)&&
+           vint->class!=display->screens->root_visual->class)
+               status=0;
+       if ((vinm&VisualRedMaskMask|vinm==VisualAllMask)&&
+           vint->red_mask!=display->screens->root_visual->red_mask)
+               status=0;
+       if ((vinm&VisualGreenMaskMask|vinm==VisualAllMask)&&
+           vint->green_mask!=display->screens->root_visual->green_mask)
+               status=0;
+       if ((vinm&VisualBlueMaskMask|vinm==VisualAllMask)&&
+           vint->blue_mask!=display->screens->root_visual->blue_mask)
+               status=0;
+       if ((vinm&VisualColormapSizeMask|vinm==VisualAllMask)&&
+           vint->colormap_size!=display->screens->root_visual->map_entries)
+               status=0;
+       if ((vinm&VisualBitsPerRGBMask|vinm==VisualAllMask)&&
+           vint->bits_per_rgb!=display->screens->root_visual->bits_per_rgb)
+               status=0;
+       if (status==1)
+       {
+               xvi.visualid=display->screens->root_visual->visualid;
+               xvi.screen=0;
+               xvi.depth=display->screens->root_visual->bits_per_rgb;
+               xvi.class=display->screens->root_visual->class;
+               xvi.red_mask=display->screens->root_visual->red_mask;
+               xvi.green_mask=display->screens->root_visual->green_mask;
+               xvi.blue_mask=display->screens->root_visual->blue_mask;
+               xvi.colormap_size=display->screens->root_visual->map_entries;
+               xvi.bits_per_rgb=display->screens->root_visual->bits_per_rgb;
+               xvi.visual=display->screens->root_visual;
+               *n=1;
+               return (&xvi);
+       }
+       *n=0;
+       return (&xvi);
+}
+
+StatusDef XMatchVisualInfo(
+    Display*           display,
+    int                        screen,
+    int                        depth,
+    int                        class,
+    XVisualInfo*       vinfo_return)
+{
+       int status=0;
+       xtrace("XMatchVisualInfo\n");
+       return status;
+}
+
+/*****************************************************************\
+
+       Function: XClearWindow
+       Inputs:   display, window
+
+       Comments: As mentioned, the Window structure is not the one windows
+                 recognises.  The background colour for the window is
+                 stored in this structure.
+
+                 The sequence of GetDC, CreateBrush/Pen, SelectObject,
+                 <draw stuff>, DeleteObject, ReleaseDC occurs in all the
+                 drawing functions.
+
+\*****************************************************************/
+int
+XClearWindow(display, w)
+Display *display;
+Window w;
+{
+       RECT  rRect;
+       HBRUSH hbrush;
+       HDC hDC;
+       HANDLE oldObj;
+       int oldROP;
+       NT_window *window = (NT_window *)w;
+       xtrace("XClearWindow\n");
+
+       if (VALID_WINDOW(window)) {
+               rRect.left= rRect.right=rRect.bottom=rRect.top =0;
+       
+               hDC = cjh_get_dc(window);
+               oldROP = SetROP2(hDC,R2_COPYPEN);
+               hbrush = window->bg;
+               oldObj = SelectObject(hDC, hbrush);
+               GetClientRect(window->w, &rRect);
+               FillRect(hDC, &rRect, hbrush);
+               SelectObject(hDC, oldObj);
+               //      DeleteObject(hbrush);
+               SetROP2(hDC,oldROP);
+               cjh_rel_dc(window,hDC);
+       }
+       
+       return 0;
+}
+
+/*****************************************************************\
+
+       Function: XCreateSimpleWindow
+       Inputs:   display, parent window, geometry, border width,
+                 border colour, background colour.
+       Returned: Window ID
+
+       Comments: The first time a window is made by the application, it
+                 has to be registered.
+                 To simulate the action of a window manager, the toplevel
+                 client window is reparented and a frame window is created.
+                 A MapNotify event is sent to the new client.
+                 Note that child windows are created in the manner of the
+                 default X behaviour, ie. each is clipped individually.
+
+
+        NOTE:     This routine has now changed. As part of our role as
+                  Window manager, we now defer creation of the windows until
+                  they are mapped. The fact that a window has been created
+                  and not mapped is flagged to other routines by setting the
+                  w element of the structure to -1.
+                  WE STILL CREATE THE Window STRUCTURES.
+                  (SEE XMapWindow)
+
+\*****************************************************************/
+
+Window
+XCreateSimpleWindow(display, parent,x, y, w, h, brd, brd_col, bg)
+Display *display;
+Window  parent;
+int     x, y;
+unsigned int brd,w,h;
+unsigned long bg, brd_col;
+{
+       NT_window  *canvas;
+       xtrace("XCreateSimpleWindow\n");
+
+       canvas = NT_new_window();
+       
+       canvas->x = x;
+       canvas->y = y;
+       canvas->wdth = w;
+       canvas->hght = h;
+       NT_add_child((NT_window *)parent,canvas);
+       canvas->bg=CreateSolidBrush (CNUMTORGB(bg));
+       canvas->parent=(NT_window *)parent;
+       canvas->title_text = NULL;
+       if (canvas->parent->w == GetDesktopWindow())
+       {
+               if (x==0 && y==0)
+               {
+                       canvas->x = -1;
+                       canvas->y = -1;
+               }
+               canvas->top_flag = TRUE;
+       }
+       else
+               canvas->top_flag = 0;
+       return ((Window)canvas);
+}
+
+
+/*****************************************************************\
+
+       Function: XCreateWindow
+       Inputs:   display, parent window, geometry, border width, depth,
+                 class, visual, attributes mask, attributes structure
+       Returned: Window ID
+
+       Comments: Simply calls XCreateSimpleWindow.  Some of the arguments
+                 are ignored :-).
+
+\*****************************************************************/
+
+Window
+XCreateWindow(display,parent,x,y,width,height,bw,depth,class,visual,
+                       valuemask,attr)
+Display *display;
+Window  parent;
+int x,y;
+unsigned int width,height,bw;
+int depth;
+unsigned int class;
+Visual *visual;
+unsigned long valuemask;
+XSetWindowAttributes *attr;
+{
+       xtrace("XCreateWindow\n");
+       return (XCreateSimpleWindow(display,parent,x,y,width,height,bw,
+               attr->border_pixel,attr->background_pixel));
+}
+
+
+/*****************************************************************\
+
+       Function: XDestroyWindow
+       Inputs:   Display, window to be destroyed.
+
+       Comments: Removes a window from the server.  
+
+\*****************************************************************/
+int
+XDestroyWindow(display,w)
+Display *display;
+Window w;
+{
+       NT_window *ntw = (NT_window *)w;
+       xtrace("XDestroyWindow\n");
+        if (ntw->hDC != INVALID_HANDLE)
+               {
+          ReleaseDC(ntw->w,ntw->hDC);
+                 ntw->hDC =  INVALID_HANDLE;
+               }
+               
+       /*DestroyWindow(w->w);*/
+       NT_delete_window(ntw);   /* Remove window from data structure */
+       return 0;
+}
+
+
+/*****************************************************************\
+
+       Function: XGetGeometry
+       Inputs:   display, window
+       Returned: root window, screen depth, geometry, border width
+
+       Comments: fetches information from the windows kernel and our
+                 display structure.
+
+\*****************************************************************/
+
+StatusDef
+XGetGeometry(display,w,root,x,y,width,height,bw,depth)
+Display *display;
+Drawable w;
+Window *root;
+int *x,*y;
+unsigned int *width,*height;
+unsigned int *bw,*depth;
+{
+       NT_window *ntw = (NT_window *)w;
+       RECT r;
+       xtrace("XGetGeometry\n");
+
+       *root=display->screens[0].root;
+       *depth=24;
+
+       GetWindowRect(ntw->w,&r);
+       *x=r.left;
+       *y=r.top;
+       GetClientRect(ntw->w,&r);
+       *width=r.right-r.left;
+       if (*width<ntw->minx)
+               *width=ntw->minx;
+       *height=r.bottom-r.top;
+       if (*height<ntw->miny)
+               *height=ntw->miny;
+       *bw=(*width-(r.right-r.left))/2;
+       
+       return 0;
+}
+
+
+/*****************************************************************\
+
+       Function: XGetWindowAttributes
+       Inputs:   display, window, attributes
+       Returned: 1 = ok.
+
+       Comments: Fills out attributes structure.
+
+\*****************************************************************/
+
+StatusDef
+XGetWindowAttributes(display,w,wattr)
+Display *display;
+Window w;
+XWindowAttributes *wattr;
+{
+       xtrace("XGetWindowAttributes\n");
+       XGetGeometry(display,w,&wattr->root,&wattr->x,&wattr->y,&wattr->width,
+               &wattr->height,&wattr->border_width,&wattr->depth);
+       wattr->class=InputOutput;
+       wattr->bit_gravity=StaticGravity;
+       wattr->win_gravity=CenterGravity;
+       wattr->backing_store=NotUseful;
+       wattr->backing_planes=0;
+       wattr->backing_pixel=0;
+       wattr->save_under=0;
+       wattr->colormap=None;
+       wattr->map_installed=TRUE;
+       wattr->map_state=IsViewable;
+       wattr->override_redirect=FALSE;
+       wattr->screen=display->screens;
+       return (1);
+}
+
+
+
+int
+XSelectInput(display, window, mask)
+Display *display;
+Window  window;
+long    mask;
+{
+       NT_window *ntw = (NT_window *)window;
+       xtrace("XSelectInput\n");
+       ntw->mask=mask;
+       return 0;
+}
+
+void NT_dispError(char *msg)
+{
+       LPVOID lpMsgBuf=NULL;
+       FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM,NULL,
+                                 GetLastError(),
+                                 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
+                                 (LPTSTR) &lpMsgBuf,
+                                 0,
+                                 NULL);
+       MessageBox( NULL, lpMsgBuf, msg, MB_OK|MB_ICONINFORMATION );
+       LocalFree( lpMsgBuf );
+}
+
+
+/*****************************************************************\
+
+       Function: XMapWindow
+       Inputs:   display, window to be mapped
+
+       Comments: If the specified window is not already mapped, this
+                 routine calls the Windows function which displays it.
+                 Again, frames have to be mapped as well as clients.
+
+\*****************************************************************/
+int
+XMapWindow(display, window)
+Display *display;
+Window window;
+{
+       NT_window *ntw = (NT_window *)window;
+       RECT rect;
+       unsigned char *hints;
+       Atom property;
+       Atom ret_type;
+       int ret_format;
+       DWORD frame_style;
+       long ret_nitems;
+       long ret_after;
+       HDC hDC;
+       char *title = "";
+       xtrace("XMapWindow\n");
+       
+       if (ntw->w == INVALID_HANDLE)
+       {
+               frame_style = WS_CHILD|WS_CLIPCHILDREN|WS_CLIPSIBLINGS;
+               if (ntw->top_flag)
+               {
+                       /* frame_style = WS_CLIPCHILDREN;
+                          frame_style |=  WS_BORDER;
+                          frame_style |= WS_THICKFRAME;
+                          frame_style |= WS_CAPTION;
+                          frame_style |= WS_POPUP;
+                          frame_style |= WS_SYSMENU;
+                          frame_style |= WS_MINIMIZEBOX;
+                          frame_style |= WS_MAXIMIZEBOX;
+                       */
+                       frame_style = WS_OVERLAPPEDWINDOW|WS_CLIPCHILDREN;
+                       ntw->hght +=  GetSystemMetrics(SM_CYSIZE)+(GetSystemMetrics(SM_CYBORDER)+GetSystemMetrics(SM_CYFRAME))*2;
+                       ntw->wdth += (GetSystemMetrics(SM_CXBORDER) + GetSystemMetrics(SM_CXFRAME))*2;
+                       title = ntw->title_text;
+                       if (ntw->x == -1 && ntw->y == -1)
+                       {
+                               ntw->x = CW_USEDEFAULT;
+                               ntw->y = CW_USEDEFAULT;
+                       }
+               }
+               else if (ntw->x == -1 && ntw->y == -1)
+               {
+                       GetClientRect(ntw->parent->w,&rect);
+                       ntw->x = rect.left;
+                       ntw->y = rect.top;
+                       ntw->wdth = rect.right-rect.left;
+                       ntw->hght = rect.bottom - rect.top;
+               }
+
+               ntw->hDC = INVALID_HANDLE;
+               
+               if (ntw->parent->w == INVALID_HANDLE)
+               {
+                       XMapWindow(display, (Window)ntw->parent);
+               }
+               ntw->w = NT_create_window(title,frame_style,
+                                                                ntw->x,ntw->y,ntw->wdth,ntw->hght,
+                                                                ntw->parent->w);
+               if (ntw->w==NULL) NT_dispError("create window1");
+               hDC = cjh_get_dc(ntw);
+               PostMessage(ntw->w,USR_MapNotify,0,0);
+       }
+       if (IsWindowVisible(ntw->w)==0)
+       {
+               ShowWindow(ntw->w, SW_SHOW);
+               PostMessage(ntw->w,USR_MapNotify,0,0);
+       }
+       UpdateWindow(ntw->w);
+       return 0;
+}
+
+int
+XIconifyWindow(Display *display,
+    Window w,
+    int screen_number)
+{
+       xtrace("XIconifyWindow\n");
+       return 0;
+}
+
+
+/*****************************************************************\
+
+       Function: XCreateGC
+       Inputs:   display, window, mask of setup values, setup values.
+       Returned: GC pointer.
+
+       Comments: Fills out a GC structure with the X defaults unless
+                 the caller specifies otherwise.
+
+\*****************************************************************/
+
+GC
+XCreateGC(display, window, mask, gc_values)
+Display *display;
+Drawable window;
+unsigned long mask;
+XGCValues *gc_values;
+{
+       GC      local_gc;
+       int     size;
+       char    *ptr;
+       xtrace("XCreateGC\n");
+
+       size = sizeof(GC);
+
+       ptr = (char *)allocateMemory((size_t)1000);
+       local_gc = (GC)ptr;
+       local_gc->ext_data = NULL;
+       local_gc->gid=(GContext) window;
+       local_gc->rects=FALSE;
+       local_gc->dashes=FALSE;
+
+       if (mask&GCArcMode)
+               local_gc->values.arc_mode=gc_values->arc_mode;
+       else
+               local_gc->values.arc_mode=ArcPieSlice;
+       if (mask&GCBackground)
+               local_gc->values.background=gc_values->background;
+       else
+               local_gc->values.background=display->screens->white_pixel;
+       if (mask&GCCapStyle)
+               local_gc->values.cap_style=gc_values->cap_style;
+       else
+               local_gc->values.cap_style=CapButt;
+       if (mask&GCClipMask)
+               local_gc->values.clip_mask=gc_values->clip_mask;
+       else
+               local_gc->values.clip_mask=None;
+       if (mask&GCClipXOrigin)
+               local_gc->values.clip_x_origin=gc_values->clip_x_origin;
+       else
+               local_gc->values.clip_x_origin=0;
+       if (mask&GCClipYOrigin)
+               local_gc->values.clip_y_origin=gc_values->clip_y_origin;
+       else
+               local_gc->values.clip_y_origin=0;
+       if (mask&GCDashList)
+               local_gc->values.dashes=gc_values->dashes;
+       else
+               local_gc->values.dashes=4;
+       if (mask&GCDashOffset)
+               local_gc->values.dash_offset=gc_values->dash_offset;
+       else
+               local_gc->values.dash_offset=0;
+       if (mask&GCFillRule)
+               local_gc->values.fill_rule=gc_values->fill_rule;
+       else
+               local_gc->values.fill_rule=EvenOddRule;
+       if (mask&GCFillStyle)
+               local_gc->values.fill_style=gc_values->fill_style;
+       else
+               local_gc->values.fill_style=FillSolid;
+       if (mask&GCFont)
+               local_gc->values.font=gc_values->font;
+       else
+               local_gc->values.font= 999;/*"fixed";*/
+       if (mask&GCForeground)
+               local_gc->values.foreground=gc_values->foreground;
+       else
+               local_gc->values.foreground=display->screens->black_pixel;
+       if (mask&GCFunction)
+               local_gc->values.function=gc_values->function;
+       else
+               local_gc->values.function=GXcopy;
+       if (mask&GCGraphicsExposures)
+               local_gc->values.graphics_exposures=gc_values->graphics_exposures;
+       else
+               local_gc->values.graphics_exposures=True;
+       if (mask&GCJoinStyle)
+               local_gc->values.join_style=gc_values->join_style;
+       else
+               local_gc->values.join_style=JoinMiter;
+       if (mask&GCLineStyle)
+               local_gc->values.line_style=gc_values->line_style;
+       else
+               local_gc->values.line_style=LineSolid;
+       if (mask&GCLineWidth)
+               local_gc->values.line_width=gc_values->line_width;
+       else
+               local_gc->values.line_width=0;
+       if (mask&GCPlaneMask)
+               local_gc->values.plane_mask=gc_values->plane_mask;
+       else
+               local_gc->values.plane_mask=255;
+       if (mask&GCStipple)
+               local_gc->values.stipple=gc_values->stipple;
+       else
+               local_gc->values.stipple=0;
+       if (mask&GCSubwindowMode)
+               local_gc->values.subwindow_mode=gc_values->subwindow_mode;
+       else
+               local_gc->values.subwindow_mode=ClipByChildren;
+       if (mask&GCTile)
+               local_gc->values.tile=gc_values->tile;
+       else
+               local_gc->values.tile=0;
+       if (mask&GCTileStipXOrigin)
+               local_gc->values.ts_x_origin=gc_values->ts_x_origin;
+       else
+               local_gc->values.ts_x_origin=0;
+       if (mask&GCTileStipYOrigin)
+               local_gc->values.ts_y_origin=gc_values->ts_y_origin;
+       else
+               local_gc->values.ts_y_origin=0;
+
+       local_gc->dirty = ~0;
+
+       return (local_gc);
+}
+
+int
+XFreeGC(display, gc)
+Display *display;
+GC gc;
+{
+       freeMemory(gc);
+}
+
+/*****************************************************************\
+
+       Function: XSetForeground
+       Inputs:   display, gc, colour.
+
+       Comments: Colour is an RGB triple (24bits).
+\*****************************************************************/
+int
+XSetForeground(display, gc, color)
+Display *display;
+GC gc;
+unsigned long    color;
+{
+       xtrace("XSetForegrond\n");
+       gc->values.foreground=color;
+       gc->dirty |= GCForeground;
+       return 0;
+}
+
+
+/*****************************************************************\
+
+       Function: XDrawString
+       Inputs:   display, window, gc, position, string, length of string.
+
+       Comments: Writes text to the screen in the manner of X windows.
+                 Note that the y origin is on the text baseline, ie.
+                 the lowest part of a letter o rests on the baseline and
+                 descenders fall below it.
+                 The text is transparent.
+
+\*****************************************************************/
+
+int
+XDrawString(Display *display, Drawable window,
+    GC gc, int x, int y, const char* str, int len)
+{
+       HDC          hDC;
+       TEXTMETRIC   tmet;
+       HFONT old;
+       xtrace("XDrawString\n");
+
+       if (VALID_WINDOW(window))
+       {
+               hDC = drawableGetDC(window);
+               SetBkMode(hDC,TRANSPARENT);
+               SetTextColor(hDC,CNUMTORGB(gc->values.foreground));
+               old=SelectObject(hDC,(HFONT)gc->values.font);
+               GetTextMetrics(hDC,&tmet);
+               TextOut(hDC,x,y-tmet.tmAscent,str,len);
+               SelectObject(hDC,old);
+               drawableRelDC(window,hDC);
+       }
+       return 0;
+}
+
+
+
+int
+XDrawString16(Display *display, Drawable window,
+    GC gc, int x, int y,
+    const XChar2b* str,
+    int len)
+{
+       xtrace("XDrawString16\n");
+       XDrawString(display, window, gc, x, y, (const char*)str, len*2);
+       return 0;
+}
+XDrawImageString(
+       Display* display,
+       Drawable d,
+       GC gc,
+       int x,
+       int y,
+       const char* string,
+       int length)
+{
+       HDC hDC = NULL;
+       TEXTMETRIC   tmet;
+       HFONT old;
+       xtrace("XDrawImageString\n");
+       if (VALID_WINDOW(d))
+       {
+           hDC = drawableGetDC(d);
+           SetBkMode(hDC,TRANSPARENT);
+           SetBkColor(hDC, CNUMTORGB(gc->values.background));  
+           SetTextColor(hDC,CNUMTORGB(gc->values.foreground));
+           old=SelectObject(hDC,(HFONT)gc->values.font);
+           if (GetTextMetrics(hDC,&tmet) && length>0) {
+               RECT fill;
+               fill.top = y-tmet.tmAscent;
+               fill.bottom = y+tmet.tmDescent;
+               fill.left = x;
+               fill.right = x + (tmet.tmAveCharWidth * length);
+               FillRect( hDC, &fill, NT_get_GC_bgbrush(hDC,gc));
+           }
+           TextOut( hDC, x, y-tmet.tmAscent, string, length ); 
+           SelectObject(hDC,old);
+           drawableRelDC(d,hDC);
+       }       
+       return 0;
+}
+
+int
+XDrawImageString16(Display *display, Drawable window,
+    GC gc, int x, int y,
+    const XChar2b* str,
+    int len)
+{
+       xtrace("XDrawImageString16\n");
+       XDrawImageString(display, window, gc, x, y, (const char*)str, len*2);
+       return 0;
+}
+
+
+/*****************************************************************\
+
+       Function: XFillRectangle
+       Inputs:   display, window, gc, geometry.
+
+       Comments: fills rectangles in uniform colours.  No tiles/Pixmaps
+                 are implemented yet.
+
+\*****************************************************************/
+
+int
+XFillRectangle (display,window,gc,x,y,w,h)
+Display *display;
+Drawable window;
+GC gc;
+int x,y;
+unsigned int w,h;
+{
+       RECT rct;
+       HBRUSH hbrush;
+       HDC hDC;
+       HANDLE oldObj;
+       int ret;
+       xtrace("XFillRectangle\n");
+
+       if (VALID_WINDOW(window))
+       {
+               hDC = drawableGetDC(window);
+               NT_set_rop(hDC,gc);
+               hbrush = NT_get_GC_brush(hDC,gc);
+               oldObj = SelectObject(hDC, hbrush);
+               rct.left=(LONG) x;
+               rct.right=(LONG) (x+w);
+               rct.top=(LONG) y;
+               rct.bottom=(LONG) (y+h);
+               ret=FillRect(hDC, &rct, hbrush);
+               SelectObject(hDC, oldObj);
+               drawableRelDC(window,hDC);
+       }
+       return (ret);
+}
+
+
+/*****************************************************************\
+
+       Function: XClearArea
+       Inputs:   display, geometry, exposure events allowed.
+
+       Comments: Straightforward.
+
+\*****************************************************************/
+int
+XClearArea(display,w,x,y,width,height,exposures)
+Display *display;
+Window w;
+int x,y;
+unsigned int width,height;
+BoolDef exposures;
+{
+       NT_window *ntw = (NT_window *)w;
+       RECT rct;
+       HBRUSH hbrush;
+       HDC hDC;
+       HANDLE oldObj;
+       int oldROP;
+       xtrace("XClearArea\n");
+
+       if (VALID_WINDOW(ntw))
+       {
+               hDC = cjh_get_dc(ntw);
+               oldROP = SetROP2(hDC,R2_COPYPEN);
+               hbrush=ntw->bg;
+               oldObj = SelectObject(hDC,hbrush);
+               GetClientRect(ntw->w,&rct);
+
+               if ((width != 0) && (height != 0))
+               {
+                       rct.left=(LONG)x;
+                       rct.right=(LONG)(x+width);
+                       rct.top=(LONG)y;
+                       rct.bottom=(LONG)(y+height);
+                       FillRect(hDC,&rct,hbrush);
+               }
+
+               SelectObject(hDC, oldObj);
+               // DeleteObject(hbrush);
+               SetROP2(hDC,oldROP);
+               cjh_rel_dc(ntw,hDC);
+       }
+       return 0;
+}
+
+
+Region
+XCreateRegion()
+{
+       HRGN hrgn;
+       xtrace("XCreateRegion\n");
+
+       hrgn=CreateRectRgn(0,0,1,1);
+       return ((Region)hrgn);
+}
+
+
+/* Untested.  The Region stuff needs thinking about. */
+
+int
+XClipBox(hrgn,rect)
+Region hrgn;
+XRectangle *rect;
+{
+       RECT rct;
+       xtrace("XClipBox\n");
+
+       GetRgnBox((HRGN)hrgn,&rct);
+       rect->x=(short)rct.left;
+       rect->y=(short)rct.top;
+       rect->width=(unsigned short)(rct.right-rct.left);
+       rect->height=(unsigned short)(rct.bottom-rct.top);
+       return TRUE;/*(rect);*/
+}
+
+
+int
+XSetRegion(display,gc,hrgn)
+Display *display;
+GC gc;
+Region hrgn;
+{
+       /* What to do here ? */
+       xtrace("XSetRegion\n");
+       return 0;
+}
+
+
+int
+XDestroyRegion(hrgn)
+Region hrgn;
+{
+       xtrace("XDestroyRegion\n");
+       DeleteObject(hrgn);
+       return 0;
+}
+
+
+int
+XUnionRectWithRegion(rect,hrgnsrc,hrgndest)
+XRectangle *rect;
+Region hrgnsrc,hrgndest;
+{
+       HRGN temp;
+       xtrace("XUnionRectWithRegion\n");
+       temp=CreateRectRgn(rect->x,rect->y,rect->x+rect->width,
+                               rect->y+rect->height);
+       CombineRgn((HRGN)hrgndest,(HRGN)hrgnsrc,temp,RGN_OR);
+       return 0;
+}
+
+
+/*****************************************************************\
+
+       Function: XDrawArc
+       Inputs:   display, window, gc, bounding box geometry, arc angles.
+
+       Comments: Works fine.
+
+\*****************************************************************/
+
+int
+XDrawArc(display,w,gc,x,y,width,height,a1,a2)
+Display *display;
+Drawable w;
+GC gc;
+int x,y;
+unsigned int width,height;
+int a1,a2;
+{
+       HDC hDC;
+       HPEN hpen;
+       int tmp;
+       double NT_deg64_to_rad();
+       HANDLE oldObj;
+       xtrace("XDrawArc\n");
+       if (a2>=0)
+               a2+=a1;
+       else
+       {
+               tmp=a1;
+               a1-=a2;
+               a2=tmp;
+       }
+
+       if (VALID_WINDOW(w))
+       {
+               hDC = drawableGetDC(w);
+               hpen = NT_get_GC_pen(hDC,gc);
+               oldObj = SelectObject(hDC,hpen);
+               Arc(hDC,x,y,x+width-1,y+height-1,
+                       (int) (x+width/2+width*cos(NT_deg64_to_rad(a1))),
+                       (int) (y+height/2-height*sin(NT_deg64_to_rad(a1))),
+                       (int) (x+width/2+width*cos(NT_deg64_to_rad(a2))),
+                       (int) (y+height/2-height*sin(NT_deg64_to_rad(a2))));
+               SelectObject(hDC, oldObj);
+               drawableRelDC(w,hDC);
+       }
+       return 0;
+}
+
+
+/*****************************************************************\
+
+       Function: XFillArc
+       Inputs:   display, window, gc, geometry as above.
+
+       Comments: Not tested at all, but should work.
+
+\*****************************************************************/
+
+int
+XFillArc(display,w,gc,x,y,width,height,a1,a2)
+Display *display;
+Drawable w;
+GC gc;
+int x,y;
+unsigned int width,height;
+int a1,a2;
+{
+       HDC hDC;
+       HBRUSH hbrush;
+       int tmp;
+        HANDLE oldObj;
+               xtrace("XFillArc\n");
+       if (a2>=0)
+               a2+=a1;
+       else
+       {
+               tmp=a1;
+               a1-=a2;
+               a2=tmp;
+       }
+       if (VALID_WINDOW(w))
+       {
+               hDC = drawableGetDC(w);
+               hbrush = NT_get_GC_brush(hDC,gc);
+               oldObj = SelectObject(hDC,hbrush);
+               if (gc->values.arc_mode==ArcChord)
+               {
+                       Chord(hDC,x,y,x+width,y+height,
+                                 (int) (x+width/2+width*cos(NT_deg64_to_rad(a1))),
+                                 (int) (y+height/2+height*sin(NT_deg64_to_rad(a1))),
+                                 (int) (x+width/2+width*cos(NT_deg64_to_rad(a2))),
+                                 (int) (y+height/2+height*sin(NT_deg64_to_rad(a2))));
+               }
+               else
+               {
+                       Pie(hDC,x,y,x+width,y+height,
+                               (int) (x+width/2+width*cos(NT_deg64_to_rad(a1))),
+                               (int) (y+height/2+height*sin(NT_deg64_to_rad(a1))),
+                               (int) (x+width/2+width*cos(NT_deg64_to_rad(a2))),
+                               (int) (y+height/2+height*sin(NT_deg64_to_rad(a2))));
+               }
+               SelectObject(hDC, oldObj);
+               drawableRelDC(w,hDC);
+       }
+       return 0;
+}
+
+
+/*****************************************************************\
+
+       Function: XFillPolygon
+       Inputs:   display, window, gc, points list, number of points,
+                 shape hint, relative drawing mode.
+
+       Comments: Works for convex polygons.  Untested on otherwise.
+                 Optimisation hints are unused, as is the mode.
+
+\*****************************************************************/
+
+int
+XFillPolygon(display,w,gc,points,nps,shape,mode)
+Display *display;
+Drawable w;
+GC gc;
+XPoint *points;
+int nps,shape,mode;
+{
+       HBRUSH hbrush;
+       int n;
+       POINT ntps[1000];
+       HDC hDC;
+       HANDLE oldObj;
+       xtrace("XFillPolygon\n");
+       /*ntps=allocateMemory(sizeof(POINT)*nps);*/
+       if (VALID_WINDOW(w))
+       {
+               hDC = drawableGetDC(w);
+               hbrush = NT_get_GC_brush(hDC,gc);
+               oldObj = SelectObject(hDC,hbrush);
+               for (n=0;n<nps;++n)
+               {
+                       (ntps+n)->x=(LONG)points->x;
+                       (ntps+n)->y=(LONG)(points++)->y;
+               }
+               Polygon(hDC,ntps,nps);
+               SelectObject(hDC, oldObj);
+               drawableRelDC(w,hDC);
+       }
+       
+       /*free(ntps);*/
+       return 0;
+}
+
+
+/*****************************************************************\
+
+       Function: XDrawLine
+       Inputs:   display, window, geometry.
+
+       Comments: Seems to work ok.
+
+\*****************************************************************/
+
+int
+XDrawLine(display,w,gc,x1,y1,x2,y2)
+Display *display;
+Drawable w;
+GC gc;
+int x1,y1,x2,y2;
+{
+       HDC hDC;
+       HPEN hpen;
+       RECT da;
+       HANDLE oldObj;
+       xtrace("XDrawLine\n");
+
+       if (VALID_WINDOW(w))
+       {
+               hDC = drawableGetDC(w);
+               hpen = NT_get_GC_pen(hDC,gc);
+               oldObj = SelectObject(hDC,hpen);
+               MoveToEx(hDC,x1,y1,NULL);
+               LineTo(hDC,x2,y2);
+               SelectObject(hDC, oldObj);
+               drawableRelDC(w,hDC);
+       }
+       return 0;
+}
+
+
+/*****************************************************************\
+
+       Function: XDrawLines
+       Inputs:   display, window, gc, points list, number of points, mode.
+
+       Comments: Untested.
+
+\*****************************************************************/
+
+int
+XDrawLines(display,w,gc,points,nps,mode)
+Display *display;
+Drawable w;
+GC gc;
+XPoint *points;
+int nps,mode;
+{
+       HPEN hpen;
+       int n;
+       POINT pts[1000];
+       HDC hDC;
+       HANDLE oldObj;
+       xtrace("XDrawLines\n");
+
+       pts->x=(LONG)points->x;
+       pts->y=(LONG)points->y;
+
+       for(n=1;n<nps;++n)
+               if (mode==CoordModeOrigin)
+               {
+                       (pts+n)->x=(LONG)(points+n)->x;
+                       (pts+n)->y=(LONG)(points+n)->y;
+               }
+               else
+               {
+                       (pts+n)->x=(LONG)(points+n)->x+(pts+n-1)->x;
+                       (pts+n)->y=(LONG)(points+n)->y+(pts+n-1)->y;
+               }
+
+       if (VALID_WINDOW(w))
+       {
+               hDC = drawableGetDC(w);
+               hpen = NT_get_GC_pen(hDC,gc);
+               oldObj = SelectObject(hDC,hpen);
+               Polyline(hDC,pts,nps);
+               SelectObject(hDC, oldObj);
+               drawableRelDC(w,hDC);
+       }
+       return 0;
+}
+
+
+/*****************************************************************\
+
+       Function: XDrawPoints
+       Inputs:   display, window, gc, points list, number of points, mode.
+
+       Comments: Untested.
+
+\*****************************************************************/
+
+int
+XDrawPoints(display,w,gc,points,nps,mode)
+Display *display;
+Drawable w;
+GC gc;
+XPoint *points;
+int nps,mode;
+{
+       HDC hDC;
+       int n;
+       xtrace("XDrawPoints\n");
+       if (VALID_WINDOW(w))
+       {
+               hDC = drawableGetDC(w);
+               SetPixelV(hDC,points->x,points->y,CNUMTORGB(gc->values.foreground));
+               for (n=1;n<nps;++n)
+               {
+                       if (mode==CoordModeOrigin)
+                               SetPixelV(hDC,(points+n)->x,(points+n)->y,
+                                                 CNUMTORGB(gc->values.foreground));
+                       else
+                               SetPixelV(hDC,(points+n-1)->x+(points+n)->x,
+                                         (points+n-1)->y+(points+n)->y,
+                                         CNUMTORGB(gc->values.foreground));
+               }
+               drawableRelDC(w,hDC);
+       }
+       return 0;
+}
+int
+XDrawPoint(display,w,gc,x,y)
+Display *display;
+Drawable w;
+GC gc;
+int x,y;
+{
+       HDC hDC;
+       xtrace("XDrawPoint\n");
+       if (VALID_WINDOW(w))
+       {
+               hDC = drawableGetDC(w);
+               SetPixelV(hDC,x,y,CNUMTORGB(gc->values.foreground));
+               drawableRelDC(w,hDC);
+       }
+       return 0;
+}
+
+
+/*****************************************************************\
+
+       Function: XDrawRectangle
+       Inputs:   display, window, gc, geometry
+
+       Comments: Seems to work.
+
+\*****************************************************************/
+
+int
+XDrawRectangle(display,w,gc,x,y,width,height)
+Display *display;
+Drawable w;
+GC gc;
+int x,y;
+unsigned int width,height;
+{
+       HDC hDC;
+       RECT rect;
+       HBRUSH hbrush;
+       HPEN hpen;
+       HANDLE oldbrush, oldpen;
+       xtrace("XDrawRectangle\n");
+       if (VALID_WINDOW(w))
+       {
+               hDC = drawableGetDC(w);
+               hbrush = NT_get_GC_brush(hDC,gc);
+               rect.left=(LONG)x;
+               rect.right=(LONG)(x+width);
+               rect.top=(LONG)y;
+               rect.bottom=(LONG)(y+height);
+               oldbrush = SelectObject(hDC,GetStockObject(NULL_BRUSH));
+               hpen = NT_get_GC_pen(hDC,gc);
+               oldpen = SelectObject(hDC,hpen);
+
+               Rectangle(hDC,(int)rect.left,(int)rect.top,(int)rect.right,(int)rect.bottom);
+               /*
+                 FrameRect(hDC,&rect,hbrush);
+               */
+               SelectObject(hDC, oldbrush);
+               SelectObject(hDC, oldpen);
+               drawableRelDC(w,hDC);
+       }
+       return 0;
+}
+
+
+/*****************************************************************\
+
+       Function: XDrawSegments
+       Inputs: display, window, gc, segment list, number of segments.
+
+       Comments: Untested.
+
+\*****************************************************************/
+
+int
+XDrawSegments(display,w,gc,segs,nsegs)
+Display *display;
+Drawable w;
+GC gc;
+XSegment *segs;
+int nsegs;
+{
+       HDC hDC;
+       HPEN hpen;
+       int n;
+       HANDLE oldObj;
+       xtrace("XDrawSegments\n");
+       if (VALID_WINDOW(w))
+       {
+               hDC = drawableGetDC(w);
+               hpen = NT_get_GC_pen(hDC,gc);
+               oldObj = SelectObject(hDC,hpen);
+               SetBkMode(hDC,TRANSPARENT);
+               for (n=0;n<nsegs;n++)
+               {
+                       MoveToEx(hDC,(segs+n)->x1,(segs+n)->y1,NULL);
+                       LineTo(hDC,(segs+n)->x2,(segs+n)->y2);
+               }
+               SelectObject(hDC, oldObj);
+               drawableRelDC(w,hDC);
+       }
+       return 0;
+}
+
+Pixmap
+XCreatePixmap(display,drawable,width,height,depth)
+Display *display;
+Drawable drawable;
+unsigned int width, height;
+unsigned int depth;
+{
+       RECT rct;
+       NT_window *w = (NT_window *)NT_new_window();
+       HDC parenthDC = drawableGetDC(drawable);
+       w->hDC = CreateCompatibleDC(parenthDC);
+       w->hBitmap = CreateCompatibleBitmap(parenthDC,width,height);
+       SelectObject(w->hDC, w->hBitmap);
+
+       rct.left=(LONG) 0;
+       rct.right=(LONG) width;
+       rct.top=(LONG) 0;
+       rct.bottom=(LONG) height;
+       FillRect(w->hDC, &rct, GetStockObject(WHITE_BRUSH));
+
+       drawableRelDC(drawable,parenthDC);
+
+       w->w = NONMAPPED_HANDLE;
+       w->x=0;
+       w->y=0;
+       w->wdth = width;
+       w->hght = height;
+       w->min = depth;
+       return (Pixmap)w;
+}
+
+const char revBytes[]={
+       0x00, 0x80, 0x40, 0xc0, 0x20, 0xa0, 0x60, 0xe0, 0x10, 0x90, 0x50,
+       0xd0, 0x30, 0xb0, 0x70, 0xf0, 0x08, 0x88, 0x48, 0xc8, 0x28, 0xa8,
+       0x68, 0xe8, 0x18, 0x98, 0x58, 0xd8, 0x38, 0xb8, 0x78, 0xf8, 0x04,
+       0x84, 0x44, 0xc4, 0x24, 0xa4, 0x64, 0xe4, 0x14, 0x94, 0x54, 0xd4,
+       0x34, 0xb4, 0x74, 0xf4, 0x0c, 0x8c, 0x4c, 0xcc, 0x2c, 0xac, 0x6c,
+       0xec, 0x1c, 0x9c, 0x5c, 0xdc, 0x3c, 0xbc, 0x7c, 0xfc, 0x02, 0x82,
+       0x42, 0xc2, 0x22, 0xa2, 0x62, 0xe2, 0x12, 0x92, 0x52, 0xd2, 0x32,
+       0xb2, 0x72, 0xf2, 0x0a, 0x8a, 0x4a, 0xca, 0x2a, 0xaa, 0x6a, 0xea,
+       0x1a, 0x9a, 0x5a, 0xda, 0x3a, 0xba, 0x7a, 0xfa, 0x06, 0x86, 0x46,
+       0xc6, 0x26, 0xa6, 0x66, 0xe6, 0x16, 0x96, 0x56, 0xd6, 0x36, 0xb6,
+       0x76, 0xf6, 0x0e, 0x8e, 0x4e, 0xce, 0x2e, 0xae, 0x6e, 0xee, 0x1e,
+       0x9e, 0x5e, 0xde, 0x3e, 0xbe, 0x7e, 0xfe, 0x01, 0x81, 0x41, 0xc1,
+       0x21, 0xa1, 0x61, 0xe1, 0x11, 0x91, 0x51, 0xd1, 0x31, 0xb1, 0x71,
+       0xf1, 0x09, 0x89, 0x49, 0xc9, 0x29, 0xa9, 0x69, 0xe9, 0x19, 0x99,
+       0x59, 0xd9, 0x39, 0xb9, 0x79, 0xf9, 0x05, 0x85, 0x45, 0xc5, 0x25,
+       0xa5, 0x65, 0xe5, 0x15, 0x95, 0x55, 0xd5, 0x35, 0xb5, 0x75, 0xf5,
+       0x0d, 0x8d, 0x4d, 0xcd, 0x2d, 0xad, 0x6d, 0xed, 0x1d, 0x9d, 0x5d,
+       0xdd, 0x3d, 0xbd, 0x7d, 0xfd, 0x03, 0x83, 0x43, 0xc3, 0x23, 0xa3,
+       0x63, 0xe3, 0x13, 0x93, 0x53, 0xd3, 0x33, 0xb3, 0x73, 0xf3, 0x0b,
+       0x8b, 0x4b, 0xcb, 0x2b, 0xab, 0x6b, 0xeb, 0x1b, 0x9b, 0x5b, 0xdb,
+       0x3b, 0xbb, 0x7b, 0xfb, 0x07, 0x87, 0x47, 0xc7, 0x27, 0xa7, 0x67,
+       0xe7, 0x17, 0x97, 0x57, 0xd7, 0x37, 0xb7, 0x77, 0xf7, 0x0f, 0x8f,
+       0x4f, 0xcf, 0x2f, 0xaf, 0x6f, 0xef, 0x1f, 0x9f, 0x5f, 0xdf, 0x3f,
+       0xbf, 0x7f, 0xff
+};
+
+
+Pixmap
+XCreateBitmapFromData(Display *display,
+    Drawable drawable, const char *data,
+    unsigned int width, unsigned int height)
+{
+       NT_window *w = (NT_window *)NT_new_window();
+       HDC parenthDC = drawableGetDC(drawable);
+       w->hDC = CreateCompatibleDC(parenthDC);
+
+       {
+               int i,j;
+               char *newdata;
+               int bytes = (width+7)>>3;
+               int newbytes = (bytes&1)?bytes+1:bytes;
+               newdata = allocateMemory(newbytes*height);
+               for (i=0;i<height;i++)
+               {
+                       for (j=0;j<bytes;j++)
+                       {
+                               newdata[(i*newbytes)+j]=revBytes[(unsigned char)data[(i*bytes)+j]];             
+                       }
+               }
+               w->hBitmap = CreateBitmap(width,height,1,1,newdata);
+               freeMemory(newdata);
+       }
+       
+       SelectObject(w->hDC, w->hBitmap);       
+       drawableRelDC(drawable,parenthDC);
+       w->x=0;
+       w->y=0;
+       w->wdth = width;
+       w->hght = height;
+       w->min = 1;
+       return (Pixmap)w;
+}
+
+int
+XFreePixmap(display, pixmap)
+        Display *display;
+        Pixmap pixmap;
+{
+       NT_window *w = (NT_window *)pixmap;
+       NT_delete_window(w);
+       return 0;
+}
+
+int
+XCopyArea(display, src, dest, gc, src_x, src_y, width, height, dest_x, dest_y)
+Display *display;
+Drawable src, dest;
+GC gc;
+int src_x, src_y;
+unsigned int width, height;
+int dest_x, dest_y;
+{
+       HDC hsrc, hdst;
+       hsrc = drawableGetDC(src);
+       if (VALID_WINDOW(dest))
+       {
+               hdst = drawableGetDC(dest);
+               (void)BitBlt(hdst,dest_x,dest_y,width,height,hsrc,src_x,src_y,SRCCOPY);
+               drawableRelDC(src,hsrc);
+       }
+       drawableRelDC(dest,hdst);
+       return 0;
+}
+
+XImage *
+NT_XCreateImage()
+{
+       return NULL;
+}
+
+int NT_XDestroyImage(ximage)
+XImage *ximage;
+{
+       /* freeMemory(ximage->data); */
+  freeMemory(ximage);
+  return 1;
+}
+
+unsigned long
+NT_XGetPixel(ximage,x,y)
+XImage *ximage;
+int x,y;
+{
+       return 0;
+}
+int
+NT_XPutPixel(ximage,x,y,pixel)
+XImage *ximage;
+int x,y;
+unsigned long pixel;
+{
+       return 0;
+}
+XImage *
+NT_XSubImage(ximage,x,y,w,h)
+XImage *ximage;
+int x,y;
+unsigned int w,h;
+{
+       return NULL;
+}
+int
+NT_XAddPixel(ximage,value)
+XImage *ximage;
+unsigned long value;
+{
+       return 0;
+}
+
+XImage *
+XGetImage(display,drawable,x,y,width,height,plane_mask,format)
+Display *display;
+Drawable drawable;
+int x,y;
+unsigned int width, height;
+unsigned long plane_mask;
+int format;
+{
+       return NULL;
+}
+
+XImage *
+XCreateImage(display,visual,depth,format,offset,data,width,height, bitmap_pad, bytes_per_line)
+Display *display;
+Visual *visual;
+unsigned int depth;
+int format;
+int offset;
+char *data;
+unsigned int width, height;
+int bitmap_pad, bytes_per_line;
+{
+    XImage *img = (XImage *) allocateMemory(sizeof(XImage));
+
+    if (img) {
+               img->depth = 24; /* depth; */
+               img->format = format;
+               img->xoffset = offset;
+               img->data = data;
+               img->width = width;
+               img->height = height;
+               img->bitmap_pad = 32;
+               img->bytes_per_line=width*((24)>>3);
+               img->bits_per_pixel = 24; /* depth; */
+               img->bitmap_bit_order = LSBFirst;
+               img->byte_order = MSBFirst;
+               img->blue_mask = 0x0ff00000;
+               img->green_mask=0x00ff0000;
+               img->red_mask= 0x0000ff00;
+               
+               img->f.create_image = NT_XCreateImage;
+               img->f.destroy_image = NT_XDestroyImage;
+               img->f.get_pixel = NT_XGetPixel;
+               img->f.put_pixel = NT_XPutPixel;
+               img->f.sub_image = NT_XSubImage;
+               img->f.add_pixel = NT_XAddPixel;
+               
+    }
+       
+       return img;
+}
+void
+DrawBitmap(HDC hdc, HBITMAP hBitmap, int xStart, int yStart)
+{
+       BITMAP bm;
+       HDC hdcMem;
+       DWORD dwSize;
+       POINT ptSize, ptOrg;
+       hdcMem = CreateCompatibleDC(hdc);
+       SelectObject(hdcMem, hBitmap);
+       SetMapMode(hdcMem,GetMapMode(hdc));
+       GetObject(hBitmap, sizeof(BITMAP), (LPVOID)&bm);
+       ptSize.x = bm.bmWidth;
+       ptSize.y = bm.bmHeight;
+       DPtoLP(hdc, &ptSize,1);
+       ptOrg.x=0;
+       ptOrg.y=0;
+       DPtoLP(hdcMem,&ptOrg,1);
+       BitBlt(hdc,xStart,yStart,ptSize.x,ptSize.y,hdcMem,ptOrg.x,ptOrg.y,SRCCOPY);
+       DeleteDC(hdcMem);
+}
+/*
+static unsigned char wBrickBits[]={
+       0xff,0x0c,0x0c,0x0c, 0xff,0xc0,0xc0,0xc0,
+       0xff,0x0c,0xff,0xff, 0xff,0xff,0xc0,0xc0,
+       0xff,0x0c,0xff,0xff, 0xff,0xff,0xc0,0xc0,
+       0xff,0x0c,0x0c,0x0c, 0xff,0xc0,0xc0,0xc0
+};
+*/
+int
+XPutImage(display,w,gc,image,sx,sy,dx,dy,width,height)
+Display *display;
+Drawable w;
+XImage *image;
+GC gc;
+int sx,sy,dx,dy;
+unsigned int width,height;
+{
+       BITMAPINFO bmInfo;
+       NT_window *pix = (NT_window *)w;
+       int res;
+       if (VALID_WINDOW(w))
+       {
+               HDC hDC = drawableGetDC(w);
+               bmInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
+               bmInfo.bmiHeader.biWidth = width;
+               bmInfo.bmiHeader.biHeight = height;
+               bmInfo.bmiHeader.biPlanes = 1;
+               bmInfo.bmiHeader.biBitCount = 24; /*image->depth; */
+               bmInfo.bmiHeader.biCompression = BI_RGB;
+               bmInfo.bmiHeader.biSizeImage = 0;
+               bmInfo.bmiHeader.biXPelsPerMeter = 3600;
+               bmInfo.bmiHeader.biYPelsPerMeter = 3600;
+               bmInfo.bmiHeader.biClrUsed = 0;
+               bmInfo.bmiHeader.biClrImportant = 0;
+               res = SetDIBitsToDevice(hDC,0,0,width,height,0,0,0,height,image->data,&bmInfo,DIB_RGB_COLORS);
+               /*      BitBlt(CreateDC("DISPLAY",NULL,NULL,NULL),10,0,width,height,hDC,0,0,SRCCOPY); */
+               if (res==0)
+                       printf("SetDIBitsfailed %d\n",res,GetLastError());
+               drawableRelDC(w,hDC);
+       }
+       return 0;
+}
+
+int
+XSetWindowBackground(display, w, bg)
+        Display *display;
+        Window w;
+        unsigned long bg;
+{
+       NT_window *window = (NT_window *)w;
+       xtrace("XSetWindowBackground\n");
+       DeleteObject(window->bg);
+       window->bg=CreateSolidBrush(CNUMTORGB(bg));
+       return 0;
+}
+
+int
+XSetWindowBackgroundPixmap(display, w, background_tile)
+Display *display;
+Window w;
+Pixmap background_tile;
+{
+       NT_window *window = (NT_window *)w;
+       NT_window *wpix = (NT_window *)background_tile;
+       BITMAPINFO *bmInfo;
+       BITMAP bm;
+       int res;
+       
+       xtrace("XSetWindowBackgroundPixmap\n");
+       if (background_tile==ParentRelative)
+       {
+               if (!window->parentRelative)
+               {
+                       HBITMAP hb = NT_getWallpaper();
+                       if (hb!=NULL) {
+                               DeleteObject(window->bg);
+                               window->bg = CreatePatternBrush(hb);
+                               window->parentRelative=1;
+                               NT_configureNotify(window,window->x,window->y);
+                       }
+               }
+       }
+       else
+       {
+               GetObject(wpix->hBitmap, sizeof(BITMAP), &bm);
+       
+               bmInfo = allocateMemory(sizeof(BITMAPINFO) + ( (bm.bmBitsPixel>>3)* bm.bmWidth*bm.bmHeight));
+               bmInfo->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
+               bmInfo->bmiHeader.biWidth = bm.bmWidth;
+               bmInfo->bmiHeader.biHeight = bm.bmHeight;
+               bmInfo->bmiHeader.biPlanes = 1;
+               bmInfo->bmiHeader.biBitCount = bm.bmBitsPixel;
+               bmInfo->bmiHeader.biCompression = BI_RGB;
+               bmInfo->bmiHeader.biSizeImage =  0;
+               bmInfo->bmiHeader.biClrImportant = 0; 
+               bmInfo->bmiHeader.biClrUsed = 0;
+       
+               res =GetDIBits(wpix->hDC,wpix->hBitmap,0,bm.bmHeight,bmInfo->bmiColors,bmInfo,DIB_RGB_COLORS);
+               if (res==0)
+                       printf("getDIBits failed %d\n",res,GetLastError());
+       
+               DeleteObject(window->bg);
+               window->bg = CreateDIBPatternBrushPt(bmInfo, DIB_RGB_COLORS);
+               freeMemory(bmInfo);
+       }
+}
+
+
+/*****************************************************************\
+
+       Function: XSetFillStyle
+       Inputs:   display, gc, fill style.
+
+       Comments: ZZzzz...
+
+\*****************************************************************/
+
+int
+XSetFillStyle(display,gc,fs)
+Display *display;
+GC gc;
+int fs;
+{
+       xtrace("XSetFillStyle\n");
+       gc->values.fill_style=fs;
+       gc->dirty |= GCFillStyle;
+       return 0;
+}
+
+
+int
+XSetDashes(Display *display,
+    GC gc, int dash_offset,
+    const char * dash_list,
+    int n)
+{
+       xtrace("XSetDashes\n");
+       return 0;
+}
+
+
+int
+XChangeWindowAttributes(display,w,vmask,attr)
+Display *display;
+Window w;
+unsigned long vmask;
+XSetWindowAttributes *attr;
+{
+       xtrace("XChangeWindowAttributes\n");
+       return 0;
+}
+
+
+/*****************************************************************\
+
+       Function: XLowerWindow
+       Inputs:   display, window to be lowered.
+
+       Comments: Make sure if the window has a frame that that gets lowered
+                 too.
+
+\*****************************************************************/
+
+int
+XLowerWindow(display,w)
+Display *display;
+Window w;
+{
+       NT_window *ntw=(NT_window *)w;
+       xtrace("XLowerWindow\n");
+       SetWindowPos((HWND)ntw->w,HWND_BOTTOM,0,0,0,0,SWP_NOMOVE|SWP_NOSIZE);
+       return 0;
+}
+
+
+/*****************************************************************\
+
+       Function: XMapRaised
+       Inputs:   display, window.
+
+       Comments: Frames get raised first.
+
+\*****************************************************************/
+
+int
+XMapRaised(display,w)
+Display *display;
+Window w;
+{
+       NT_window *ntw=(NT_window *)w;
+       xtrace("XMapRaised\n");
+       XMapWindow(display,w);
+       SetWindowPos(ntw->w,HWND_TOP,0,0,0,0,SWP_NOMOVE|SWP_NOSIZE);
+       return 0;
+}
+
+
+/*****************************************************************\
+
+       Function: XMapSubwindows
+       Inputs:   display, window.
+
+       Comments: Unfortunately, the optimisations normally made by
+                 the X server are not made here.
+
+\*****************************************************************/
+
+int
+XMapSubwindows(display,w)
+Display *display;
+Window w;
+{
+       NT_window *ntw=(NT_window *)w;
+       struct NT_child *tmp;
+
+       xtrace("XMapSubWindows\n");
+       tmp=ntw->child;
+       while (tmp!=NULL)
+       {
+               XMapWindow(display,(Window)tmp->w);
+               tmp=tmp->next;
+        }
+       return 0;
+}
+
+
+/*****************************************************************\
+
+       Function: XQueryTree
+       Inputs:   display, window.
+       Returned: root window, parent window, list of children, status.
+
+       Comments: Not fully implemented.  The child field is wrong.
+
+\*****************************************************************/
+
+StatusDef
+XQueryTree(display,w,root,parent,ch,n)
+Display *display;
+Window w;
+Window* root;
+Window* parent;
+Window** ch;
+unsigned int *n;
+{
+       NT_window *ntw=(NT_window *)w;
+       StatusDef status=1;
+
+       xtrace("XQueryTree\n");
+       *parent=(Window)ntw->parent;
+       if (ntw->parent==NULL)
+               status=0;
+       *root=display->screens[0].root;
+       *ch=NULL;
+       *n=0;
+       return (status);
+}
+
+
+/*****************************************************************\
+
+       Function: XRaiseWindow
+       Inputs:   display, window.
+
+       Comments: Recursive raising of window and its children.
+
+\*****************************************************************/
+
+int
+XRaiseWindow(display,w)
+Display *display;
+Window w;
+{
+       NT_window *ntw=(NT_window *)w;
+       struct NT_child *tmp;
+       xtrace("XRaiseWindows\n");
+
+       BringWindowToTop(ntw->w);
+       tmp=ntw->child;
+       while (tmp!=NULL)
+       {
+               XRaiseWindow(display,(Window)tmp->w);
+               tmp=tmp->next;
+       }
+       return 0;
+}
+
+
+/*****************************************************************\
+
+       Function: XRootWindow
+       Inputs:   display, screen number
+       Returned: root window ID.
+
+       Comments: Info taken from display structure.
+
+\*****************************************************************/
+
+Window
+XRootWindow(display,scr)
+Display *display;
+int scr;
+{
+       xtrace("XRootWindow\n");
+       return(display->screens[0].root);
+}
+
+
+/*****************************************************************\
+
+       Function: XRootWindowOfScreen
+       Inputs:   screen pointer
+       Returned: root window ID.
+
+       Comments: ZZzzz...
+
+\*****************************************************************/
+
+Window
+XRootWindowOfScreen(scr)
+Screen *scr;
+{
+       xtrace("XRootWindowOfScreen\n");
+       return(scr->root);
+}
+
+
+/*****************************************************************\
+
+       Function: XTranslateCoordinates
+       Inputs:   display, source window, destination window, source x, y.
+       Returned: destination x, y, child window if any.
+
+       Comments: Seems to work properly.
+
+\*****************************************************************/
+
+BoolDef
+XTranslateCoordinates(display,sw,dw,sx,sy,dx,dy,ch)
+Display *display;
+Window sw,dw;
+int sx,sy,*dx,*dy;
+Window *ch;
+{
+       xtrace("XTranslateCoordinates\n");
+       return (True);
+}
+
+
+/*****************************************************************\
+
+       Function: XUnmapWindow
+       Inputs:   display, window.
+
+       Comments: Removes a window and its frame, if it has one, from the
+                 screen.
+
+\*****************************************************************/
+
+int
+XUnmapWindow(display,w)
+Display *display;
+Window w;
+{
+       NT_window *ntw=(NT_window *)w;
+       xtrace("XUnmapWindow\n");
+       ShowWindow(ntw->w,SW_HIDE);
+       return 0;
+}
+
+
+/*****************************************************************\
+
+       Function: XCopyGC
+       Inputs:   display, source gc, values mask, destination gc.
+
+       Comments: Copies masked elements from source to destination.
+
+\*****************************************************************/
+
+int
+XCopyGC(display,sgc,vmask,dgc)
+Display *display;
+GC sgc,dgc;
+unsigned long vmask;
+{
+       xtrace("XCopyGC\n");
+       if (vmask&GCFunction)
+               dgc->values.function=sgc->values.function;
+       if (vmask&GCPlaneMask)
+               dgc->values.plane_mask=sgc->values.plane_mask;
+       if (vmask&GCForeground)
+               dgc->values.foreground=sgc->values.foreground;
+       if (vmask&GCBackground)
+               dgc->values.background=sgc->values.background;
+       if (vmask&GCLineWidth)
+               dgc->values.line_width=sgc->values.line_width;
+       if (vmask&GCLineStyle)
+               dgc->values.line_style=sgc->values.line_style;
+       if (vmask&GCCapStyle)
+               dgc->values.cap_style=sgc->values.cap_style;
+       if (vmask&GCJoinStyle)
+               dgc->values.join_style=sgc->values.join_style;
+       if (vmask&GCFillStyle)
+               dgc->values.fill_style=sgc->values.fill_style;
+       if (vmask&GCFillRule)
+               dgc->values.fill_rule=sgc->values.fill_rule;
+       if (vmask&GCTile)
+               dgc->values.tile=sgc->values.tile;
+       if (vmask&GCStipple)
+               dgc->values.stipple=sgc->values.stipple;
+       if (vmask&GCTileStipXOrigin)
+               dgc->values.ts_x_origin=sgc->values.ts_x_origin;
+       if (vmask&GCTileStipYOrigin)
+               dgc->values.ts_y_origin=sgc->values.ts_y_origin;
+       if (vmask&GCFont)
+               dgc->values.font=sgc->values.font;
+       if (vmask&GCSubwindowMode)
+               dgc->values.subwindow_mode=sgc->values.subwindow_mode;
+       if (vmask&GCGraphicsExposures)
+               dgc->values.graphics_exposures=sgc->values.graphics_exposures;
+       if (vmask&GCClipXOrigin)
+               dgc->values.clip_x_origin=sgc->values.clip_x_origin;
+       if (vmask&GCClipYOrigin)
+               dgc->values.clip_y_origin=sgc->values.clip_y_origin;
+       if (vmask&GCClipMask)
+               dgc->values.clip_mask=sgc->values.clip_mask;
+       if (vmask&GCDashList)
+               dgc->values.dashes=sgc->values.dashes;
+       if (vmask&GCArcMode)
+               dgc->values.arc_mode=sgc->values.arc_mode;
+
+       dgc->dirty = 0xFFFF;
+       return 0;
+}
+
+
+int
+XSetClipMask(display,gc,cmask)
+Display *display;
+GC gc;
+Pixmap cmask;
+{
+       xtrace("XSetClipMask\n");
+       return 0;
+}
+
+
+int
+XSetClipRectangles(display,gc,clx,cly,rs,n,order)
+Display *display;
+GC gc;
+int clx,cly;
+XRectangle *rs;
+int n,order;
+{
+       xtrace("XSetClipRectangles\n");
+       return 0;
+}
+
+
+/*****************************************************************\
+
+       Function: XSetFunction
+       Inputs:   display, gc, graphics operation.
+
+       Comments: ZZzzz...
+
+\*****************************************************************/
+
+int
+XSetFunction(display,gc,fn)
+Display *display;
+GC gc;
+int fn;
+{
+       xtrace("XSetFunction\n");
+       gc->values.function=fn;
+       gc->dirty |= GCFunction;
+       return 0;
+}
+
+
+/*****************************************************************\
+
+       Function: XSetLineAttributes
+       Inputs:   display, gc, line width, line style, cap style, join style.
+
+       Comments: These all have windows equivalents.
+
+\*****************************************************************/
+
+int
+XSetLineAttributes(display,gc,lw,ls,cs,js)
+Display *display;
+GC gc;
+unsigned int lw;
+int ls,cs,js;
+{
+       xtrace("XSetLineAttributes\n");
+       gc->values.line_width=lw;
+       gc->values.line_style=ls;
+       gc->values.cap_style=cs;
+       gc->values.join_style=js;
+       gc->dirty |= GCLineWidth | GCLineStyle | GCCapStyle | GCJoinStyle;
+       return 0;
+}
+
+
+/*****************************************************************\
+
+       Function: XSetPlaneMask
+       Inputs:   display, gc, plane mask.
+
+       Comments: What's a plane mask?
+
+\*****************************************************************/
+
+int
+XSetPlaneMask(display,gc,pmask)
+Display *display;
+GC gc;
+unsigned long pmask;
+{
+       xtrace("XSetPlaneMask\n");
+       gc->values.plane_mask=pmask;
+       return 0;
+}
+
+
+int
+XSetTile(display,gc,tile)
+Display *display;
+GC gc;
+Pixmap tile;
+{
+       xtrace("XSetTile\n");
+       return 0;
+}
+
+
+StatusDef
+XAllocColorCells(display,cmap,cont,pmasks,np,pixels,nc)
+Display *display;
+Colormap cmap;
+BoolDef cont;
+unsigned long *pmasks;
+unsigned int np;
+unsigned long *pixels;
+unsigned int nc;
+{
+       unsigned int i;
+       xtrace("XAllocColorCells\n");
+       for (i = 0;i<nc;i++)
+               pixels[i] = i;
+       if(np==1)
+       {
+               *pmasks = nc;
+       }
+       return 1;
+}
+
+
+/*****************************************************************\
+
+       Function: XAllocColorPlanes
+       Inputs:   display, colour map, contiguous flag, pixel value list,
+                 number of colours, number of reds, greens, blues.
+       Returned: red mask, green mask, blue mask, status.
+
+       Comments: Works for True Colour only.
+
+\*****************************************************************/
+
+StatusDef
+XAllocColorPlanes(display,cmap,cont,pixels,nc,nr,ng,nb,rmask,gmask,bmask)
+Display *display;
+Colormap cmap;
+BoolDef cont;
+unsigned long *pixels;
+int nc;
+int nr,ng,nb;
+unsigned long *rmask,*gmask,*bmask;
+{
+       xtrace("XAllocColorPlanes\n");
+       *rmask=255;
+       *gmask=255<<8;
+       *bmask=255<<16;
+       return (1);
+}
+
+
+StatusDef
+XAllocNamedColor(Display *display,
+    Colormap cmap, const char *cname,
+    XColor *cell, XColor *rgb)
+{
+       xtrace("XAllocNamedColor\n");
+       return 0;
+}
+
+
+Colormap
+XCreateColormap(display,w,visual,alloc)
+Display *display;
+Window w;
+Visual *visual;
+int alloc;
+{
+       xtrace("XCreateColormap\n");
+       return 0;
+}
+
+
+StatusDef
+XGetStandardColormap(display,w,cmapinf,prop)
+Display *display;
+Window w;
+XStandardColormap *cmapinf;
+Atom prop;
+{
+       xtrace("XGetStandardColormap\n");
+       return 0;
+}
+
+StatusDef
+XAllocColor(display,cmap,xc)
+Display *display;
+Colormap cmap;
+XColor *xc;
+{
+       xtrace("XAllocColor\n");
+       xc->pixel = RGB((BYTE) (xc->red>>8)&0xff, (BYTE) (xc->green>>8)&0xff, (BYTE) (xc->blue>>8)&0xff);
+       return 1;
+}
+
+int
+XQueryColor(display,cmap,cell)
+Display *display;
+Colormap cmap;
+XColor *cell;
+{
+       xtrace("XQueryColor\n");
+       cell->red = (cell->pixel>>8)&0x0ff00;
+       cell->green = (cell->pixel)&0x0ff00;
+       cell->blue = (cell->pixel<<8)&0x0ff00;
+  return 1;
+}
+
+
+int
+XQueryColors(display,cmap,cells,nc)
+Display *display;
+Colormap cmap;
+XColor *cells;
+int nc;
+{
+       int i;
+
+       xtrace("XQueryColors\n");
+       for (i=0;i<nc;i++)
+       {
+               cells[i].red=(cells[i].pixel>>8)&0xff00;
+               cells[i].green=(cells[i].pixel)&0xff00;
+               cells[i].blue=(cells[i].pixel<<8)&0xff00;
+       }
+       return 0;
+}
+
+
+int
+XStoreColor(display,cmap,cell)
+Display *display;
+Colormap cmap;
+XColor *cell;
+{
+       xtrace("XStoreColor\n");
+       return 0;
+}
+
+
+
+int
+XStoreColors(display,cmap,cells,nc)
+Display *display;
+Colormap cmap;
+XColor *cells;
+int nc;
+{
+       int i;
+       xtrace("XStoreColors\n");
+       return 0;
+}
+
+char **
+XGetFontPath(display,nps)
+Display *display;
+int *nps;
+{
+       xtrace("XGetFontPath\n");
+       return (NULL);
+}
+
+
+BoolDef
+XGetFontProperty(fstruct,atom,val)
+XFontStruct *fstruct;
+Atom atom;
+unsigned long *val;
+{
+       xtrace("XGetFontProperty\n");
+       return (0);
+}
+
+static BYTE
+getCharSetFromName(const char *name,char **lang)
+{
+    static struct {
+       char *label;
+       BYTE id;
+    } charset[] = {
+       "-gb2312", GB2312_CHARSET,
+       "-big5", CHINESEBIG5_CHARSET,
+       "-jis", SHIFTJIS_CHARSET,
+       NULL, DEFAULT_CHARSET
+    };
+    int i;
+    char *p;
+    if (!name)
+    {
+       if (lang) *lang=NULL;
+       return DEFAULT_CHARSET;
+    }
+    else if (lang) *lang=(char *)name+strlen((char *)name);
+    for (i=0; charset[i].label; i++)
+       if (NULL!=(p=strstr(name, charset[i].label)))
+       {
+           if (lang) *lang=p;
+           break;
+       }
+    return charset[i].id;
+}
+
+/* attempts to translate the font name into
+** something win32 understands.
+** 
+*/
+Font
+NT_loadfont(name)
+char *name;
+{
+    LOGFONT lf;
+    HFONT hfont;
+    char *p,*q,*lang;
+    int size = 0;
+    char buff[33];
+       
+    memset(&lf,0,sizeof(lf));
+    lf.lfHeight = -13;
+       
+    lf.lfWeight = FW_NORMAL;
+    lf.lfFaceName[0]='\0';
+       
+    lf.lfCharSet = getCharSetFromName(name,&lang);
+    
+    if (name && strstr(name,"-bold"))
+    {
+       lf.lfWeight = FW_BOLD;
+    }
+    for(p=name, q=buff; p&&p<=lang; p++)
+    {
+       if (((!*p || *p=='-') && q!=buff) || (q-buff>31))
+       {
+           *q++='\0';
+           if (lf.lfFaceName[0]=='\0')
+           {
+               if (isalpha(buff[0]) || IsDBCSLeadByte(buff[0]))
+                   strcpy(lf.lfFaceName, buff);
+               else if (isdigit(buff[0]) && ((q=strchr(buff,'x')) || (q=strchr(buff,'X'))))
+               {
+                   strcpy(lf.lfFaceName, "Courier New");
+                   size = -atoi(q+1);
+               }
+               else if (size == 0 && isdigit(buff[0]))
+                   size = -atoi(buff);
+           }
+           else if (size == 0 && isdigit(buff[0]))
+           {                           
+               size = -atoi(buff);
+           }
+           q = buff;
+       }
+       else
+           *q++ = *p;
+       if (!*p) break;
+    }
+       
+    if (size > 99)
+       lf.lfHeight = - (size/10);
+    else if (size)
+       lf.lfHeight = - size;
+    
+    if (!strcmp(lf.lfFaceName,"lucidatypewriter"))
+       strcpy(lf.lfFaceName,"Lucida Console");
+    else if (lf.lfFaceName[0]=='\0'&&lf.lfCharSet==DEFAULT_CHARSET)
+       strcpy(lf.lfFaceName,"Courier New");
+    hfont = CreateFontIndirect(&lf);
+    return (Font)hfont;
+}
+
+XFontStruct *
+XLoadQueryFont(Display *display, const char *name)
+{
+    XFontStruct *fs;
+    TEXTMETRIC tm;
+    HDC hdc;
+    HWND root;
+    HFONT old;
+    int i;
+       
+    xtrace("XLoadQueryFont\n");
+    fs = allocateMemory(sizeof(XFontStruct));
+    fs->fid = NT_loadfont(name);
+
+    root=GetDesktopWindow();
+    hdc=GetDC(root);
+    old = SelectObject(hdc, (HFONT)fs->fid);
+    GetTextMetrics(hdc, &tm);
+    fs->min_bounds.width = tm.tmAveCharWidth;
+    fs->max_bounds.width = tm.tmMaxCharWidth;
+    fs->n_properties = 0;
+    fs->properties = NULL;
+    fs->min_char_or_byte2 =tm.tmFirstChar;
+    fs->max_char_or_byte2 =tm.tmLastChar;
+    fs->per_char = (XCharStruct*)allocateMemory(sizeof(XCharStruct)*(tm.tmLastChar+1));
+    ZeroMemory(fs->per_char, sizeof(XCharStruct)*(tm.tmLastChar+1));
+
+    if (!(tm.tmPitchAndFamily & TMPF_FIXED_PITCH)) {
+       for (i=tm.tmFirstChar; i<=tm.tmLastChar; i++) {
+           fs->per_char[i].width = tm.tmAveCharWidth;
+           fs->per_char[i].rbearing = tm.tmAveCharWidth;
+       }
+    } else if (tm.tmPitchAndFamily & TMPF_TRUETYPE) {
+       for (i=tm.tmFirstChar; i<=tm.tmLastChar; i++)
+       {
+           ABC abc;
+           if (!GetCharABCWidths(hdc,i,i,&abc))
+           {
+               abc.abcA = 0;
+               abc.abcB = tm.tmAveCharWidth;
+               abc.abcC = 0;
+           }
+           fs->per_char[i].lbearing = abc.abcA;
+           fs->per_char[i].width = abc.abcB;
+           fs->per_char[i].rbearing = abc.abcB+abc.abcC;                   
+       }
+    } else {
+       for (i=tm.tmFirstChar; i<=tm.tmLastChar; i++)
+       {
+           INT fw;
+           if (!GetCharWidth(hdc,i,i,&fw))
+           {
+               fw = tm.tmAveCharWidth;
+           }
+           fs->per_char[i].lbearing = 0;
+           fs->per_char[i].width = fw;
+           fs->per_char[i].rbearing = fw;
+       }
+    }
+    if (getCharSetFromName(name,NULL) == DEFAULT_CHARSET)
+    {
+       int last = tm.tmLastChar;
+
+       switch(tm.tmCharSet) {
+           case CHINESEBIG5_CHARSET:
+           case GB2312_CHARSET:
+           case SHIFTJIS_CHARSET:
+               if (tm.tmLastChar > 127) last = 127;
+               break;
+       }
+
+       if (last >= tm.tmFirstChar)
+       {
+           fs->max_bounds = fs->per_char[last];
+           fs->min_bounds = fs->per_char[last];
+           for (i=tm.tmFirstChar; i<last; i++)
+           {
+               if (fs->per_char[i].lbearing > fs->max_bounds.lbearing)
+                   fs->max_bounds.lbearing = fs->per_char[i].lbearing;
+               else if(fs->per_char[i].lbearing < fs->min_bounds.lbearing)
+                   fs->min_bounds.lbearing = fs->per_char[i].lbearing;
+
+               if (fs->per_char[i].width > fs->max_bounds.width)
+                   fs->max_bounds.width = fs->per_char[i].width;
+               else if(fs->per_char[i].width < fs->min_bounds.width)
+                   fs->min_bounds.width = fs->per_char[i].width;
+
+               if (fs->per_char[i].rbearing > fs->max_bounds.rbearing)
+                   fs->max_bounds.rbearing = fs->per_char[i].rbearing;
+               else if(fs->per_char[i].rbearing < fs->min_bounds.rbearing)
+                   fs->min_bounds.rbearing = fs->per_char[i].rbearing;
+           }
+       }
+    }
+    fs->ascent = tm.tmAscent;
+    fs->descent= tm.tmDescent;
+    SelectObject(hdc,old);
+    ReleaseDC(root,hdc);
+    return(fs);
+}
+
+XFontStruct *
+XQueryFont(display, font_id)
+Display *display;
+XID     font_id;
+{
+       static XFontStruct fs;
+
+       xtrace("XQueryFont\n");
+       return(&fs);
+}
+
+KeySym
+XKeycodeToKeysym(display, keycode, index)
+Display *display;
+unsigned int keycode;
+int     index;
+{
+       xtrace("XKeycodeToKeysym\n");
+       if (keycode == 254) return XK_Alt_L;
+       else if (keycode == 255) return XK_Num_Lock;
+       return(NoSymbol);
+}
+KeyCode
+XKeysymToKeycode(display, keysym)
+Display *display;
+KeySym keysym;
+{
+       xtrace("XKeycodeToKeysym\n");
+       if (keysym == XK_Alt_L) return 254;
+       else if (keysym == XK_Num_Lock) return 255;
+       return(0);
+}
+KeySym
+XStringToKeysym(const char *str)
+{
+       xtrace("XStringToKeysym\n");
+       return(NoSymbol);
+}
+
+XModifierKeymap *
+XGetModifierMapping(display)
+Display *display;
+{
+       XModifierKeymap *map = NULL;
+       xtrace("XGetModifierMapping\n");
+       map = (XModifierKeymap *)allocateMemory(sizeof(XModifierKeymap));
+       map->max_keypermod = 1;
+       map->modifiermap = (KeyCode *)allocateMemory(sizeof(KeyCode)*8);
+       map->modifiermap[0]=0;
+       map->modifiermap[1]=0;
+       map->modifiermap[2]=0;
+       map->modifiermap[3]=XKeysymToKeycode(display,XK_Alt_L);
+       map->modifiermap[4]=0;
+       map->modifiermap[5]=0;
+       map->modifiermap[6]=0;
+       map->modifiermap[7]=XKeysymToKeycode(display,XK_Num_Lock);
+       return(map);
+}
+int
+XFreeModifiermap(XModifierKeymap *modmap)
+{
+       xtrace("XFreeModifiermap\n");
+       freeMemory(modmap->modifiermap);
+       freeMemory(modmap);
+       return 0;
+}
+
+
+int
+XSetFont(display,gc,font)
+Display *display;
+GC gc;
+Font font;
+{
+       xtrace("XSetFont\n");
+       gc->values.font = font;
+       return 0;
+}
+
+
+int
+XSetFontPath(display,dirs,nd)
+Display *display;
+char **dirs;
+int nd;
+{
+       xtrace("XSetFontPath\n");
+       return 0;
+}
+
+
+/*****************************************************************\
+
+       Function: XTextExtents
+       Inputs:   font structure, string, string length.
+       Returned: writing direction, max ascent, max descent, font overall
+                 characteristics.
+
+       Comments: The design of windows fonts is similar to X, as far as
+                 ascent and descent are concerned.  However, they are
+                 positioned differently on the screen (see XDrawText).
+
+\*****************************************************************/
+
+static HDC desktopHDC;
+static int firstTE = TRUE;
+int
+XTextExtents(fstruct,str,nc,dir,ascent,descent,overall)
+XFontStruct *fstruct;
+const char *str;
+int nc;
+int *dir,*ascent,*descent;
+XCharStruct *overall;
+{
+       TEXTMETRIC tmet;
+       HDC hdc;
+       SIZE tsize;
+       HWND desktop;
+       HFONT old;
+       
+       xtrace("XTextExtents\n");
+       if (firstTE)
+       {
+               firstTE = FALSE;
+               desktop=GetDesktopWindow();
+               desktopHDC=GetDC(desktop);
+       }
+       hdc = desktopHDC;
+       old = SelectObject(hdc, (HFONT)fstruct->fid);
+       GetTextMetrics(hdc,&tmet);
+       GetTextExtentPoint(hdc,str,nc,&tsize);
+       *dir=FontLeftToRight;
+       *ascent=tmet.tmAscent + 1;
+       *descent=tmet.tmDescent;
+       overall->ascent=(short)(tmet.tmAscent + 1);
+       overall->descent=(short)tmet.tmDescent;
+       overall->width=(short)tsize.cx;
+       overall->lbearing=0;
+       overall->rbearing=(short)tsize.cx;
+       /* cjh_rel_dc(desktop,hdc);*/
+       SelectObject(hdc,old);
+       return 0;
+}
+
+
+int
+XTextExtents16(fstruct,str,nc,dir,ascent,descent,overall)
+XFontStruct *fstruct;
+const XChar2b *str;
+int nc;
+int *dir,*ascent,*descent;
+XCharStruct *overall;
+{
+       xtrace("XTextExtents16\n");
+       return 0;
+}
+
+
+/*****************************************************************\
+
+
+       Function: XTextWidth
+       Inputs:   font structure, string, length of string.
+       Returned: String width in pixels.
+
+       Comments:
+
+\*****************************************************************/
+
+int
+XTextWidth(fstruct,str,co)
+XFontStruct *fstruct;
+const char *str;
+int co;
+{
+       HDC hdc;
+       SIZE tsize;
+       HWND root;
+       HFONT old;
+       xtrace("XTextWidth\n");
+
+       if(firstTE)
+       {
+               firstTE = FALSE;
+               root=GetDesktopWindow();
+               hdc=GetDC(root);
+       }
+       old = SelectObject(hdc, (HFONT)fstruct->fid);
+       GetTextExtentPoint(hdc,str,co,&tsize);
+       SelectObject(hdc,old);
+       /*cjh_rel_dc(root,hdc);*/
+       return (tsize.cx);
+}
+
+
+int
+XTextWidth16(fstruct,str,co)
+XFontStruct *fstruct;
+const XChar2b *str;
+int co;
+{
+       xtrace("XTextWidth16\n");
+       return 0;
+}
+
+
+int
+XGetErrorDatabaseText(display,name,msg,defstr,buf,len)
+Display *display;
+const char *name,*msg;
+const char *defstr;
+char *buf;
+int len;
+{
+       static char def_err[]="Errors not implemented";
+       int n;
+
+       xtrace("XGetErrorDatabaseText\n");
+       while (n<len && def_err[n] != 0)
+               *(buf+n)=def_err[n++];
+       *(buf+n)=0;
+       return 0;
+}
+
+
+int
+XGetErrorText(display,code,buf,len)
+Display *display;
+int code;
+char *buf;
+int len;
+{
+       xtrace("XGetErrorText\n");
+       return 0;
+}
+
+
+XErrorHandler
+XSetErrorHandler(handler)
+XErrorHandler handler;
+{
+       xtrace("XSetErrorHandler\n");
+       return 0;
+}
+
+
+/*****************************************************************\
+
+
+       Function: XDefaultScreen
+       Inputs:   display
+       Returned: default screen number
+
+       Comments:
+
+\*****************************************************************/
+
+int
+XDefaultScreen(display)
+Display *display;
+{
+       xtrace("XDefaultScreen\n");
+       return (display->default_screen);
+}
+
+Visual *
+XDefaultVisual(display, screen)
+Display *display;
+int screen;
+{
+       xtrace("XDefaultVisual\n");
+       return DefaultVisual(display, screen);
+}
+int
+XDefaultDepth(display, screen)
+Display *display;
+int screen;
+{
+       xtrace("XDefaultDepth\n");
+       return DefaultDepth(display, screen);
+}
+Colormap
+XDefaultColormap(display, screen)
+Display *display;
+int screen;
+{
+       xtrace("XDefaultColormap\n");
+       return DefaultColormap(display, screen);
+}
+
+
+/*****************************************************************\
+
+
+       Function: XScreenOfDisplay
+       Inputs:   display,screen number
+       Returned: screen list.
+
+       Comments:
+
+\*****************************************************************/
+
+Screen *
+XScreenOfDisplay(display,scr)
+Display *display;
+int scr;
+{
+       xtrace("XScreenOfDisplay\n");
+       return (display->screens);
+}
+
+
+Cursor
+XCreateFontCursor(display,shape)
+Display *display;
+unsigned int shape;
+{
+       xtrace("XCreateFontCursor\n");
+       return 0;
+}
+
+
+int
+XRecolorCursor(display,cursor,fg,bg)
+Display *display;
+Cursor cursor;
+XColor *fg,*bg;
+{
+       xtrace("XRecolorCursor\n");
+       return 0;
+}
+
+
+/*****************************************************************\
+
+
+       Function: XWarpPointer
+       Inputs:   display, source window, destination window, source window
+                 geometry, destination x, y.
+
+       Comments: Not knowingly tested.
+
+\*****************************************************************/
+
+int
+XWarpPointer(display,sw,dw,sx,sy,swidth,sheight,dx,dy)
+Display *display;
+Window sw,dw;
+int sx,sy;
+unsigned int swidth,sheight;
+int dx,dy;
+{
+       NT_window *ntsw=(NT_window *)sw;
+       NT_window *ntdw=(NT_window *)dw;
+
+       POINT cpt,tmp;
+       RECT srct;
+       HDC hDC;
+
+       xtrace("XWarpPointer\n");
+       GetCursorPos(&cpt);
+       if (ntsw==None)
+       {
+               if (ntdw==None)
+                       SetCursorPos(dx,dy);
+               else
+               {
+                       tmp.x=dx;
+                       tmp.y=dy;
+                       ClientToScreen(ntdw->w,&tmp);
+                       SetCursorPos(tmp.x,tmp.y);
+               }
+       }
+       else
+       {
+               GetWindowRect(ntsw->w,&srct);
+               tmp.x=sx;
+               tmp.y=sy;
+               ClientToScreen(ntsw->w,&tmp);
+               if (swidth==0)
+                       swidth=srct.right-sx;
+               if (sheight==0)
+                       sheight=srct.bottom-sy;
+               hDC = cjh_get_dc(ntdw);
+               if (cpt.x>=tmp.x && cpt.x<tmp.x+(int)swidth &&
+                   cpt.y>=tmp.y && cpt.y<tmp.y+(int)sheight &&
+                   PtVisible(hDC,cpt.x,cpt.y))
+               {
+                       if (ntdw==None)
+                               SetCursorPos(cpt.x+dx,cpt.y+dy);
+                       else
+                       {
+                               tmp.x=dx;
+                               tmp.y=dy;
+                               ClientToScreen(ntdw->w,&tmp);
+                               SetCursorPos(tmp.x,tmp.y);
+                       }
+               }
+               cjh_rel_dc(ntdw,hDC);
+       }
+       return 0;
+}
+
+
+/*****************************************************************\
+
+
+       Function: XBell
+       Inputs:   display, percent loudness.
+
+       Comments: Don't throw away your CD just yet.
+
+\*****************************************************************/
+
+int
+XBell(display,pc)
+Display *display;
+int pc;
+{
+       xtrace("XBell\n");
+       MessageBeep(MB_OK);
+       return 0;
+}
+
+
+/*****************************************************************\
+
+
+       Function: XGetInputFocus
+       Inputs:   display, focus window, revert to window.
+
+       Comments: We don't have the data in place for the revert to field
+                 to work.
+
+\*****************************************************************/
+
+int
+XGetInputFocus(display,focus,revto)
+Display *display;
+Window *focus;
+int *revto;
+{
+       xtrace("XGetInputFocus\n");
+       *focus=(Window)GetFocus();  /* Note: returns NULL if the focus window */
+       revto=RevertToNone; /*       belongs to another thread.       */
+       return 0;
+}
+
+
+/*****************************************************************\
+
+
+       Function: XSetInputFocus
+       Inputs:   display, focus window, revert to window, time.
+
+       Comments: Set focus to requested client window.
+
+\*****************************************************************/
+
+int
+XSetInputFocus(display,focus,revto,time)
+Display *display;
+Window focus;
+int revto;
+Time time;
+{
+       NT_window *ntw=(NT_window *)focus;
+       xtrace("XSetInputFocus\n");
+       SetFocus(ntw->w);
+       return 0;
+}
+
+
+int
+XLookupString(event,buf,nbytes,keysym,status)
+XKeyEvent *event;
+char *buf;
+int nbytes;
+KeySym *keysym;
+XComposeStatus *status;
+{
+       xtrace("XLookupString\n");
+       *buf=event->keycode;
+       *keysym=event->keycode;
+       return 1;
+}
+
+
+int
+XRefreshKeyboardMapping(event)
+XMappingEvent *event;
+{
+       xtrace("XRefreshKeyboardMapping\n");
+       return 0;
+}
+
+
+int
+XSetClassHint(display,w,chints)
+Display *display;
+Window w;
+XClassHint *chints;
+{
+       xtrace("XSetClassHint\n");
+       return 0;
+}
+
+
+/*****************************************************************\
+
+
+       Function: XSetNormalHints
+       Inputs:   display, window, size hints.
+
+       Comments: Assuming the role of the window manager, we alter the
+                 window geometry as requested.
+
+\*****************************************************************/
+
+int
+XSetNormalHints(display,w,hints)
+Display *display;
+Window w;
+XSizeHints *hints;
+{
+       NT_window *ntw=(NT_window *)w;
+       UINT ff;
+
+       xtrace("XSetNormalHints\n");
+
+       if (!hints->flags&PPosition)
+               ff=SWP_NOMOVE;
+       else
+               ff=0;
+       
+       if (!hints->flags&PSize)
+               ff=ff|SWP_NOSIZE;
+
+       if (hints->flags &USPosition)
+       {
+               ntw->x = hints->x;
+               ntw->y = hints->y;
+       }
+       if (hints->flags & USSize)
+       {
+               ntw->wdth = hints->width;
+               ntw->hght = hints->height;
+       }
+       
+       if (hints->flags&PMinSize)
+       {
+               ntw->minx = hints->min_width;
+               ntw->miny = hints->min_height;
+       }
+       
+       if (VALID_WINDOW(ntw) && (hints->flags & USSize || hints->flags &USPosition))
+       {
+               SetWindowPos(ntw->w,HWND_TOPMOST,hints->x,hints->y,
+                                        hints->width,hints->height,ff|SWP_SHOWWINDOW);
+       }
+       return 0;
+}
+
+
+int
+XSetWMHints(display,w,wmhints)
+Display *display;
+Window w;
+XWMHints *wmhints;
+{
+       xtrace("XSetWMHints\n");
+       return 0;
+}
+
+
+StatusDef
+XSetWMProtocols(display,w,prots,co)
+Display *display;
+Window w;
+Atom *prots;
+int co;
+{
+       xtrace("XSetWMProtocols\n");
+       return 0;
+}
+
+
+/*****************************************************************\
+
+
+       Function: XStoreName
+       Inputs:   display, window, window name.
+
+       Comments: Only set names to the frame windows, otherwise captions
+                 appear in the client areas.
+
+\*****************************************************************/
+
+int
+XStoreName(display,w,wname)
+Display *display;
+Window w;
+const char *wname;
+{
+       NT_window *ntw=(NT_window *)w;
+       int status = 0;
+
+       xtrace("XStoreName\n");
+       if (ntw->top_flag)
+       {
+               ntw->title_text = strdup(wname);
+               if (VALID_WINDOW(ntw))
+                       status = SetWindowText (ntw->w , wname);
+       }
+       return(status);
+}
+
+StatusDef
+XFetchName(
+    Display *display,
+    Window w,
+    char **window_name_return)
+{
+       NT_window *ntw=(NT_window *)w;
+       int status = 1;
+       xtrace("XFetchName\n");
+       *window_name_return = NULL;
+       if (ntw->title_text!=NULL)
+       {
+               *window_name_return = strdup(ntw->title_text);
+               status =0;
+       }
+       return(status);
+}
+
+
+
+/*****************************************************************\
+
+
+       Function: XDoesBackingStore
+       Inputs:   screen
+
+       Comments: No backing store at the moment.  Windows doesn't seem
+                 to support it, unless we do it ourselves with compatible
+                 bitmaps.
+
+\*****************************************************************/
+
+int
+XDoesBackingStore(scr)
+Screen *scr;
+{
+       xtrace("XDoesBackingStore\n");
+       return(0);
+}
+
+
+XExtCodes *
+XInitExtension(display,name)
+Display *display;
+const char *name;
+{
+       xtrace("XInitExtension\n");
+       return 0;
+}
+
+
+/*****************************************************************\
+
+
+       Function: XFree
+       Inputs:   data to be freed.
+
+       Comments: This might need changing sometime.  No crashes so far.
+
+\*****************************************************************/
+
+int
+XFree(data)
+void *data;
+{
+       xtrace("XFree\n");
+       freeMemory(data);
+       return 0;
+}
+
+/*****************************************************************\
+
+
+       Function: XServerVendor
+       Inputs:   display.
+       Returned: string of vendor's name.
+
+       Comments: Copied from the display structure.
+
+\*****************************************************************/
+
+char *
+XServerVendor(display)
+Display *display;
+{
+       xtrace("XServerVendor\n");
+       return (display->vendor);
+}
+
+
+int
+XSetIconName(display,w,iname)
+Display *display;
+Window w;
+const char *iname;
+{
+       xtrace("XSetIconName\n");
+       return 0;
+}
+int
+XGetIconName(display,w,iname)
+Display *display;
+Window w;
+char **iname;
+{
+       xtrace("XGetIconName\n");
+       *iname = NULL;
+       return 0;
+}
+
+
+int
+XSetSelectionOwner(display, sel, owner, time)
+Display* display;
+Atom sel;
+Window owner;
+Time time;
+{
+    HWND hwnd = owner ? ((NT_window*)owner)->w : NULL;
+       HWND cowner = GetClipboardOwner();
+       OpenClipboard(hwnd);
+       if (cowner==hwnd)
+               catchNextDestroyClipboard();
+       EmptyClipboard();
+       CloseClipboard();
+       return 0;
+}
+
+Window
+XGetSelectionOwner(display,selection)
+Display* display;
+Atom selection;
+{
+       HWND hwnd = NULL;
+       Window w;
+       xtrace("XGetSelectionOwner\n");
+       hwnd = GetClipboardOwner();
+       w = (Window)NT_find_window_from_id(hwnd);
+       if (!w) w=None;
+       return w;
+}
+
+/*****************************************************************\
+
+       Function: NT_set_rop
+       Inputs:   window device context, X graphics context
+
+       Comments: Sets the graphics drawing operation.
+
+\*****************************************************************/
+
+void
+NT_set_rop(hdc,gc)
+HDC hdc;
+GC gc;
+{
+       switch (gc->values.function)
+       {
+               case GXclear:
+                       SetROP2(hdc,R2_BLACK);
+                       break;
+
+               case GXand:
+                       SetROP2(hdc,R2_MASKPEN);
+                       break;
+
+               case GXandReverse:
+                       SetROP2(hdc,R2_MASKPENNOT);
+                       break;
+
+               case GXcopy:
+                       SetROP2(hdc,R2_COPYPEN);
+                       break;
+
+               case GXnoop:
+                       SetROP2(hdc,R2_NOP);
+                       break;
+
+               case GXxor:
+                       SetROP2(hdc,R2_XORPEN);/*XORPEN);*/
+                       break;
+
+               case GXor:
+                       SetROP2(hdc,R2_MERGEPEN);
+                       break;
+
+               case GXnor:
+                       SetROP2(hdc,R2_NOTMERGEPEN);
+                       break;
+
+               case GXequiv:
+                       SetROP2(hdc,R2_NOTXORPEN);
+                       break;
+
+               case GXinvert:
+                       SetROP2(hdc,R2_NOT);
+                       break;
+
+               case GXorReverse:
+                       SetROP2(hdc,R2_MERGEPENNOT);
+                       break;
+
+               case GXcopyInverted:
+                       SetROP2(hdc,R2_NOTCOPYPEN);
+                       break;
+
+               case GXorInverted:
+                       SetROP2(hdc,R2_MERGENOTPEN);
+                       break;
+
+               case GXnand:
+                       SetROP2(hdc,R2_NOTMASKPEN);
+                       break;
+
+               case GXset:
+                       SetROP2(hdc,R2_WHITE);
+                       break;
+       }
+}
+
+/*****************************************************************\
+
+       Function: NT_check_update_GC
+       Inputs:   gc - Graphics Context
+
+       Comments: Check what has changed in the GC and modify the
+                 pen and brush accordingly.
+
+\*****************************************************************/
+static int
+NT_check_update_GC(gc)
+GC gc;
+{
+       DWORD style=PS_GEOMETRIC;
+       LOGBRUSH lbr;
+       int      width;
+       NTGC    *lntgc;
+
+       if ( gc->ext_data == NULL )
+       {
+               gc->ext_data = (XExtData *)allocateMemory(sizeof(XExtData));
+               lntgc = (NTGC *)allocateMemory(sizeof(NTGC));
+               gc->ext_data->private_data = (char *)lntgc;
+               lntgc->pen = INVALID_HANDLE;
+               lntgc->brush = INVALID_HANDLE;
+               lntgc->bgbrush = INVALID_HANDLE;
+               gc->dirty=~0;
+       }
+
+       if ((gc->dirty & GCForeground) ||
+                (gc->dirty & GCLineStyle)  ||
+            (gc->dirty & GCCapStyle)   ||
+            (gc->dirty & GCJoinStyle)  ||
+            (gc->dirty & GCLineWidth) )
+       {
+               lbr.lbStyle=BS_SOLID;
+               lbr.lbColor=CNUMTORGB(gc->values.foreground);
+               lbr.lbHatch=0;
+
+               if (gc->values.line_style==LineDoubleDash)
+                       style|=PS_DASHDOT;
+               else if (gc->values.line_style==LineOnOffDash)
+                       style|=PS_DASH;
+               else
+                       style|=PS_SOLID;
+
+               if (gc->values.cap_style==CapProjecting)
+                       style|=PS_ENDCAP_SQUARE;
+               else if (gc->values.cap_style==CapRound)
+                       style|=PS_ENDCAP_ROUND;
+               else
+                       style|=PS_ENDCAP_FLAT;
+
+               if (gc->values.join_style==JoinRound)
+                       style|=PS_JOIN_ROUND;
+               else if (gc->values.join_style==JoinMiter)
+                       style|=PS_JOIN_MITER;
+               else
+                       style|=PS_JOIN_BEVEL;
+               width=gc->values.line_width;
+               if (width==0)
+                       width=1;
+
+               lntgc = (NTGC *)gc->ext_data->private_data;
+               if ( lntgc->pen != INVALID_HANDLE )
+                       DeleteObject(lntgc->pen);
+
+               lntgc->pen = ExtCreatePen(style,width,&lbr,0,NULL);
+       }
+       if (gc->values.fill_style != FillSolid)
+       {
+               if ((gc->dirty & GCStipple))
+               {
+                       NT_window *pixmap = (NT_window *)gc->values.stipple;
+                       lntgc->brush = CreatePatternBrush(pixmap->hBitmap);
+               }
+       }
+       else if ((gc->dirty & GCForeground) )
+       {
+               lntgc = (NTGC *)gc->ext_data->private_data;
+               if ( lntgc->brush != INVALID_HANDLE )
+                       DeleteObject(lntgc->brush);
+               lntgc->brush = CreateSolidBrush(CNUMTORGB(gc->values.foreground));
+
+       }
+
+       if ((gc->dirty & GCBackground) )
+       {
+               lntgc = (NTGC *)gc->ext_data->private_data;
+               if ( lntgc->bgbrush != INVALID_HANDLE )
+                       DeleteObject(lntgc->bgbrush);
+               lntgc->bgbrush = CreateSolidBrush(CNUMTORGB(gc->values.background));
+
+       }
+
+       gc->dirty = 0;
+
+       return(1);
+}
+
+
+/*****************************************************************\
+
+       Function: NT_get_GC_pen
+       Inputs:   device context, graphics context
+
+       Comments: Sets the device context and pen according to the
+                 graphics context.
+
+\*****************************************************************/
+static HPEN
+NT_get_GC_pen(hdc,gc)
+HDC hdc;
+GC gc;
+{
+       NTGC *lntgc;
+
+       NT_check_update_GC(gc);
+       NT_set_rop(hdc,gc);
+
+       lntgc = (NTGC *)gc->ext_data->private_data;
+
+       return(lntgc->pen);
+}
+
+
+/*****************************************************************\
+
+       Function: NT_get_GC_brush
+       Inputs:   device context, graphics context
+       Returns:  handle for brush.
+
+       Comments: Same as above for painting operations.
+
+\*****************************************************************/
+static HBRUSH
+NT_get_GC_brush(hdc,gc)
+HDC hdc;
+GC gc;
+{
+       NTGC *lntgc;
+
+        NT_check_update_GC(gc);
+
+       if (gc->values.fill_rule==EvenOddRule)
+               SetPolyFillMode(hdc,ALTERNATE);
+       else
+               SetPolyFillMode(hdc,WINDING);
+       
+       if (gc->values.fill_style == FillSolid || 
+           gc->values.fill_style == FillOpaqueStippled)
+       {
+               SetTextColor(hdc, CNUMTORGB(gc->values.foreground));
+               SetBkColor(hdc, CNUMTORGB(gc->values.background));
+       }
+
+       NT_set_rop(hdc,gc);
+
+       lntgc = (NTGC *)gc->ext_data->private_data;
+
+       return(lntgc->brush);
+}
+
+static HBRUSH
+NT_get_GC_bgbrush(hdc,gc)
+HDC hdc;
+GC gc;
+{
+       NTGC *lntgc;
+        NT_check_update_GC(gc);
+       lntgc = (NTGC *)gc->ext_data->private_data;
+       return(lntgc->bgbrush);
+}
+
+
+
+/*****************************************************************\
+
+       Function: NT_deg64_to_rad
+       Inputs:   angle (in 64ths of a degree)
+
+       Comments: Converts int angle to double in radians.
+
+\*****************************************************************/
+
+double
+NT_deg64_to_rad(a)
+int a;
+{
+       return ((double)a/64.0*0.017453);
+}
+
+
+/******************************************************************/
+/*                                                                */
+/*               Atoms and properties code.                       */
+/*                                                                */
+/******************************************************************/
+
+static char **nt_atoms;
+static int num_nt_atoms = 0;
+static int max_num_nt_atoms = 0;
+#define ATOMS_BLOCK_SIZE 40
+
+/******************************************************************\
+
+         Function:  XInternAtom
+         Inputs:    Display, property name, creation flag.
+
+         Comments:  Could be made much more efficient.
+
+\******************************************************************/
+
+Atom
+XInternAtom(display, property_name, only_if_exists)
+Display *display;
+const char *property_name;
+BoolDef only_if_exists;
+{
+       int i;
+       char **new_nt_atoms;
+
+       xtrace("XInternAtom\n");
+       if (strcmp(property_name,"VT_SELECTION")==0)
+       {
+               return XA_LAST_PREDEFINED + 667;
+       }
+       
+       for (i=0;i< num_nt_atoms ;i++)
+               if (strcmp(nt_atoms[i],property_name) == 0)
+                       return XA_LAST_PREDEFINED + i;
+       
+       if (only_if_exists)
+               return None;
+
+       if (num_nt_atoms >= max_num_nt_atoms)
+       {
+               new_nt_atoms = (char **)realloc(nt_atoms,(max_num_nt_atoms + ATOMS_BLOCK_SIZE)*sizeof(char *));
+               if (!new_nt_atoms)
+                       return None;
+               nt_atoms = new_nt_atoms;
+               max_num_nt_atoms+= ATOMS_BLOCK_SIZE;
+               nt_atoms[num_nt_atoms] = allocateMemory(strlen(property_name)+1);
+               if (!nt_atoms[num_nt_atoms])
+                       return None;
+               strcpy(nt_atoms[num_nt_atoms],property_name);
+               return (XA_LAST_PREDEFINED +  num_nt_atoms++);
+       }
+}
+
+/******************************************************************\
+
+         Function:  XGetAtomName
+         Inputs:    Display,Atom
+
+         Comments:  None.
+
+\******************************************************************/
+char *
+XGetAtomName(display,atom)
+Display *display;
+Atom atom;
+{
+       char *ret_string;
+       xtrace("XGetAtomName\n");
+       if (atom > num_nt_atoms + XA_LAST_PREDEFINED)
+               return NULL;
+
+       if (! (ret_string = allocateMemory(strlen(nt_atoms[atom - XA_LAST_PREDEFINED])+1)))
+               return FALSE;
+
+       strcpy(ret_string,nt_atoms[atom]);
+
+       return ret_string;
+}
+
+/******************************************************************\
+
+         Function:  XChangeProperty
+         Inputs:    Display,Window,Property,type,format,mode,data,
+                    nelements.
+
+         Comments:  None.
+
+\******************************************************************/
+int
+XChangeProperty(
+       Display *display,
+       Window window,
+       Atom property,
+       Atom type,
+       int format,
+       int mode,
+       const unsigned char *data,
+       int nelements)
+{
+       NT_window *ntw=(NT_window *)window;
+       struct NT_prop_list *wanderer, *new;
+       xtrace("XChangeProperty\n");
+
+       if (property == XA_CUT_BUFFER0 && type==XA_STRING)
+       {
+               HGLOBAL handle=NULL;
+               char *buffer=NULL;
+               int i,j,cr=0;
+               for (i=0; i<nelements; i++)
+                       if (data[i]=='\n' && (i==0 || data[i-1]!='\r')) cr++;
+               
+               handle = GlobalAlloc(GMEM_MOVEABLE|GMEM_DDESHARE, nelements+cr+1);
+               if (!handle) return;
+               OpenClipboard(ntw->w);
+               buffer = GlobalLock(handle);
+               for (i=j=0; i<nelements; buffer[j++]=data[i++])
+                       if (data[i]=='\n' && (i==0 || data[i-1]!='\r')) buffer[j++]='\r';
+               buffer[j++]='\0';
+               GlobalUnlock(handle);
+               SetClipboardData(CF_TEXT, handle);
+               handle = GlobalAlloc(GMEM_MOVEABLE|GMEM_DDESHARE, sizeof(LCID));
+               if (handle) {
+                       *(LCID*)GlobalLock(handle) = GetThreadLocale();
+                       GlobalUnlock(handle);
+                       SetClipboardData(CF_LOCALE, handle);
+               }
+               CloseClipboard();
+               return;
+       }
+}
+
+int
+XDeleteProperty(
+      Display *display,
+      Window w,
+      Atom property)
+{
+       return 0;
+}
+
+static char *
+NT_getClipboard() 
+{
+    char *ret = NULL;
+    char *s,*t;
+    int size, format=0;
+    HGLOBAL handle;
+    LPVOID data;
+    OpenClipboard(NULL);
+    for (format = EnumClipboardFormats(format); format; format = EnumClipboardFormats(format)) {
+       if (format != CF_TEXT && format != CF_UNICODETEXT) continue;
+       handle = GetClipboardData(format);
+       if (handle==NULL) break;
+       data = GlobalLock(handle);
+       if (format == CF_UNICODETEXT) {
+           int conv = CP_THREAD_ACP;
+           size = WideCharToMultiByte(conv,0,data,-1,NULL,0,NULL,NULL);
+           if (size == 0) /* NT doesn't support CF_THREAD_ACP */
+               size = WideCharToMultiByte( (conv = CP_UTF8),0,data,-1,NULL,0,NULL,NULL);
+           if (size==0) continue; /* let windows convert it */
+           ret = allocateMemory(size);
+           WideCharToMultiByte(conv, 0, data, -1, ret, size, NULL, NULL);
+       } else {
+           size = strlen(data)+1;
+           ret = allocateMemory(size);
+           strcpy(ret,data);
+       }    
+       GlobalUnlock(handle);
+       break;
+    }
+    CloseClipboard();
+    for (s=t=ret;s && (*t=*s++);) if (*t!='\r') t++;
+    return ret;
+}
+
+int
+XGetWindowProperty(display,window,property,long_offset,long_length,delete,
+                   req_type,actual_type_return,actual_format_return,
+                   nitems_return,bytes_after_return,prop_return)
+Display *display;
+Window window;
+Atom property;
+long long_offset;
+long long_length;
+BoolDef delete;
+Atom req_type;
+Atom *actual_type_return;
+int *actual_format_return;
+unsigned long *nitems_return;
+unsigned long *bytes_after_return;
+unsigned char **prop_return;
+{
+    xtrace("XGetWindowProperty\n");
+    if (property == XA_CUT_BUFFER0 && prop_return && (*prop_return = NT_getClipboard())) {
+       *nitems_return=strlen(*prop_return);
+       *actual_type_return = XA_STRING;
+       *bytes_after_return = 0;
+    }    
+    else {
+       *prop_return = NULL;
+       *actual_type_return = None;
+       *actual_format_return = 0;
+       *bytes_after_return = 0;
+    }
+    return 0;
+}
+
+
+
+char **
+XListExtensions(display,ret_num)
+Display *display;
+int *ret_num;
+{
+       *ret_num = 0;
+       xtrace("XListExtensions\n");
+       return NULL;
+}
+
+XFreeExtensionList(list)
+char **list;
+{
+       xtrace("XFreeExtensionList\n");
+       return 0;
+}
+
+XChangeGC(
+       Display* display,
+       GC gc,
+       unsigned long mask,
+       XGCValues* gc_values)
+{
+       xtrace("XChangeGC\n");
+       if (mask&GCArcMode)
+               gc->values.arc_mode=gc_values->arc_mode;
+       if (mask&GCBackground)
+               gc->values.background=gc_values->background;
+       if (mask&GCCapStyle)
+               gc->values.cap_style=gc_values->cap_style;
+       if (mask&GCClipMask)
+               gc->values.clip_mask=gc_values->clip_mask;
+       if (mask&GCClipXOrigin)
+               gc->values.clip_x_origin=gc_values->clip_x_origin;
+       if (mask&GCClipYOrigin)
+               gc->values.clip_y_origin=gc_values->clip_y_origin;
+       if (mask&GCDashList)
+               gc->values.dashes=gc_values->dashes;
+       if (mask&GCDashOffset)
+               gc->values.dash_offset=gc_values->dash_offset;
+       if (mask&GCFillRule)
+               gc->values.fill_rule=gc_values->fill_rule;
+       if (mask&GCFillStyle)
+               gc->values.fill_style=gc_values->fill_style;
+       if (mask&GCFont)
+               gc->values.font=gc_values->font;
+       if (mask&GCForeground)
+               gc->values.foreground=gc_values->foreground;
+       if (mask&GCFunction)
+               gc->values.function=gc_values->function;
+       if (mask&GCGraphicsExposures)
+               gc->values.graphics_exposures=gc_values->graphics_exposures;
+       if (mask&GCJoinStyle)
+               gc->values.join_style=gc_values->join_style;
+       if (mask&GCLineStyle)
+               gc->values.line_style=gc_values->line_style;
+       if (mask&GCLineWidth)
+               gc->values.line_width=gc_values->line_width;
+       if (mask&GCPlaneMask)
+               gc->values.plane_mask=gc_values->plane_mask;
+       if (mask&GCStipple)
+               gc->values.stipple=gc_values->stipple;
+       if (mask&GCSubwindowMode)
+               gc->values.subwindow_mode=gc_values->subwindow_mode;
+       if (mask&GCTile)
+               gc->values.tile=gc_values->tile;
+       if (mask&GCTileStipXOrigin)
+               gc->values.ts_x_origin=gc_values->ts_x_origin;
+       if (mask&GCTileStipYOrigin)
+               gc->values.ts_y_origin=gc_values->ts_y_origin;
+       gc->dirty |= mask;
+       return 0;
+}
+
+int
+XConnectionNumber(Display* display)
+{
+    int fd;
+    xtrace("XConnectionNumber\n");
+    fd = open ("/dev/windows", O_NONBLOCK, 0);
+    return fd;
+}
+
+XFreeFont(Display* display,XFontStruct* font_struct)
+{
+       xtrace("XFreeFont\n");
+       return 0;
+}
+
+char *
+_Xsetlocale(int category, const char *name)
+{
+       xtrace("Xsetlocale\n");
+       return (char *)name;
+}
+
+char *
+XSetLocaleModifiers(const char* modifier_list)
+{
+       xtrace("XSetLocaleModifiers\n");
+       return NULL;
+}
+XIM
+XOpenIM(
+       Display* dpy,
+       struct _XrmHashBucketRec* rdb,
+       char* res_name,
+       char* res_class)
+{
+       xtrace("XOpenIM\n");
+       return 0;
+}
+char *
+XGetIMValues(XIM im , ...)
+{
+       xtrace("XGetIMValues\n");
+       return NULL;
+}
+XIC
+XCreateIC(XIM im , ...)
+{
+       xtrace("XCreateIC\n");
+       return 0;
+}
+StatusDef
+XCloseIM(XIM im)
+{
+       xtrace("XCloseIM\n");
+       return 0;
+}
+
+char *
+XrmQuarkToString(void *quark)
+{
+       xtrace("XrmQuarkToString\n");
+       return NULL;
+}
+
+int
+XmbLookupString(
+       XIC ic,
+       XKeyPressedEvent* event,
+       char* buffer_return,
+       int bytes_buffer,
+       KeySym* keysym_return,
+       StatusDef* status_return)
+{
+       xtrace("XmbLookupString\n");
+       return 0;
+}
+int
+XmbTextPropertyToTextList(
+       Display *display,
+       XTextProperty *text_prop,
+       char ***list_return,
+       int *count_return)
+{
+       xtrace("XmbTextPropertyToTextList\n");
+       /* in the future copy this, for 2.7.1 rxvt leaks this, so don't yet */
+       *list_return = (char **)allocateMemory(sizeof(char *));
+       *list_return[0] = text_prop->value;
+       *count_return = 1;
+       return 0;       
+}
+
+void
+XFreeStringList(char **list)
+{
+       freeMemory(list);
+}
+
+int
+XmbTextListToTextProperty(
+        Display *display,
+        char **list,
+        int count,
+        XICCEncodingStyle style,
+        XTextProperty *text_prop_return)
+{
+       int ret = 0;
+       if (count!=1) ret = XNoMemory;
+       text_prop_return->value = strdup(list[0]);
+       switch (style)
+       {
+               case XStringStyle: text_prop_return->encoding = XA_STRING; break;
+               /* case XCompoundTextStyle: text_prop_return->encoding = XA_COMPOUND; break; */
+               default: ret = XLocaleNotSupported;
+       }
+       text_prop_return->format = 8;
+       text_prop_return->nitems = count;
+       return ret;
+}
+void XmbDrawString(
+       Display *display,
+       Drawable d,
+       XFontSet font_set,
+       GC gc,
+       int x, int y,
+       char *string,
+       int num_bytes) 
+{
+       xtrace("XmbDrawString\n");
+}
+
+
+void
+XSetICFocus(XIC ic)
+{
+       xtrace("XSetICFocus\n");
+}
+void
+XUnsetICFocus(XIC ic)
+{
+       xtrace("XUnsetICFocus\n");
+}
+
+
+
+/* lifted from emacs */
+/*
+ *    XParseGeometry parses strings of the form
+ *   "=<width>x<height>{+-}<xoffset>{+-}<yoffset>", where
+ *   width, height, xoffset, and yoffset are unsigned integers.
+ *   Example:  "=80x24+300-49"
+ *   The equal sign is optional.
+ *   It returns a bitmask that indicates which of the four values
+ *   were actually found in the string.  For each value found,
+ *   the corresponding argument is updated;  for each value
+ *   not found, the corresponding argument is left unchanged. 
+ */
+
+static int
+read_integer (string, NextString)
+     register char *string;
+     char **NextString;
+{
+       register int Result = 0;
+       int Sign = 1;
+  
+       if (*string == '+')
+               string++;
+       else if (*string == '-')
+    {
+               string++;
+               Sign = -1;
+    }
+       for (; (*string >= '0') && (*string <= '9'); string++)
+    {
+               Result = (Result * 10) + (*string - '0');
+    }
+       *NextString = string;
+       if (Sign >= 0)
+               return (Result);
+       else
+               return (-Result);
+}
+
+/* lifted from emacs */
+int
+XParseGeometry(
+       const char* string,
+       int* x,
+       int* y,
+       unsigned int* width,
+       unsigned int* height)
+{
+       int mask = NoValue;
+       register char *strind;
+       unsigned int tempWidth, tempHeight;
+       int tempX, tempY;
+       char *nextCharacter;
+  
+       if ((string == NULL) || (*string == '\0')) return (mask);
+       if (*string == '=')
+               string++;  /* ignore possible '=' at beg of geometry spec */
+  
+       strind = (char *)string;
+       if (*strind != '+' && *strind != '-' && *strind != 'x') 
+    {
+               tempWidth = read_integer (strind, &nextCharacter);
+               if (strind == nextCharacter) 
+                       return (0);
+               strind = nextCharacter;
+               mask |= WidthValue;
+    }
+  
+       if (*strind == 'x' || *strind == 'X') 
+    {  
+               strind++;
+               tempHeight = read_integer (strind, &nextCharacter);
+               if (strind == nextCharacter)
+                       return (0);
+               strind = nextCharacter;
+               mask |= HeightValue;
+    }
+  
+       if ((*strind == '+') || (*strind == '-')) 
+    {
+               if (*strind == '-') 
+               {
+                       strind++;
+                       tempX = -read_integer (strind, &nextCharacter);
+                       if (strind == nextCharacter)
+                               return (0);
+                       strind = nextCharacter;
+                       mask |= XNegative;
+
+               }
+               else
+               {       
+                       strind++;
+                       tempX = read_integer (strind, &nextCharacter);
+                       if (strind == nextCharacter)
+                               return (0);
+                       strind = nextCharacter;
+               }
+               mask |= XValue;
+               if ((*strind == '+') || (*strind == '-')) 
+               {
+                       if (*strind == '-') 
+                       {
+                               strind++;
+                               tempY = -read_integer (strind, &nextCharacter);
+                               if (strind == nextCharacter)
+                                       return (0);
+                               strind = nextCharacter;
+                               mask |= YNegative;
+
+                       }
+                       else
+                       {
+                               strind++;
+                               tempY = read_integer (strind, &nextCharacter);
+                               if (strind == nextCharacter)
+                                       return (0);
+                               strind = nextCharacter;
+                       }
+                       mask |= YValue;
+               }
+    }
+  
+       /* If strind isn't at the end of the string the it's an invalid
+          geometry specification. */
+  
+       if (*strind != '\0') return (0);
+  
+       if (mask & XValue)
+               *x = tempX;
+       if (mask & YValue)
+               *y = tempY;
+       if (mask & WidthValue)
+               *width = tempWidth;
+       if (mask & HeightValue)
+               *height = tempHeight;
+       return (mask);
+}
+
+XResizeWindow(
+       Display* display,
+       Window w,
+       unsigned int width,
+       unsigned int height)
+{
+       RECT r; 
+       NT_window *ntw=(NT_window *)w;
+       xtrace("XResizeWindow\n");
+       r.left = ntw->x;
+       r.top = ntw->y;
+       r.right = r.left + width;
+       r.bottom = r.top + height;
+       if (ntw->top_flag)
+         AdjustWindowRect(&r, WS_OVERLAPPEDWINDOW, FALSE);
+       if (VALID_WINDOW(ntw))
+         MoveWindow(ntw->w, r.left, r.top, 
+                    r.right-r.left, r.bottom-r.top,TRUE);
+       return 0;
+}
+
+void
+XSetWMNormalHints(Display* display,Window w,XSizeHints* hints)
+{
+       xtrace("XSetWMNormalHints\n");
+       XSetNormalHints(display,w,hints);
+}
+
+void
+XSetWMProperties(
+       Display* display,
+       Window w,
+       XTextProperty* window_name,
+       XTextProperty* icon_name,
+       char** argv,
+       int argc,
+       XSizeHints* normal_hints,
+       XWMHints* wm_hints,
+       XClassHint* class_hints)
+{
+       xtrace("XSetWMProperties\n");
+       XSetNormalHints(display,w,normal_hints);
+}
+XDefineCursor(Display* display,Window w,Cursor cursor)
+{
+       xtrace("XDefineCursor\n");
+       return 0;
+}
+
+XMoveResizeWindow(
+       Display* display,
+       Window w,
+       int x,
+       int y,
+       unsigned int width,
+       unsigned int height)
+{
+       NT_window *ntw=(NT_window *)w;
+       xtrace("XMoveResizeWindow\n");
+       ntw->x = x;
+       ntw->y = y;
+       ntw->wdth = width;
+       ntw->hght = height;
+       if (VALID_WINDOW(ntw)) {
+               NT_moveWindow(ntw,TRUE);
+       }
+       
+}
+
+XMoveWindow(
+       Display* display,
+       Window w,
+       int x,
+       int y)
+{
+       NT_window *ntw=(NT_window *)w;
+       xtrace("XMoveWindow\n");
+       ntw->x = x;
+       ntw->y = y;
+       if (VALID_WINDOW(ntw)) {
+               NT_moveWindow(ntw,TRUE);
+       }
+       return 0;
+}
+
+/* 
+ * xcolors.c --
+ *
+ *     This file contains the routines used to map from X color
+ *     names to RGB and pixel values.
+ *
+ * Copyright (c) 1996 by Sun Microsystems, Inc.
+ *
+ * See the file "license.terms" for information on usage and redistribution
+ * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
+ *
+ * SCCS: @(#) xcolors.c 1.3 96/12/17 13:07:02
+ */
+
+/*
+ * Define an array that defines the mapping from color names to RGB values.
+ * Note that this array must be kept sorted alphabetically so that the
+ * binary search used in XParseColor will succeed.
+ */
+typedef struct {
+    char *name;
+    unsigned char red;
+    unsigned char green;
+    unsigned char blue;
+} XColorEntry;
+
+static XColorEntry xColors[] = {
+    "alice blue", 240, 248, 255,
+    "AliceBlue", 240, 248, 255,
+    "antique white", 250, 235, 215,
+    "AntiqueWhite", 250, 235, 215,
+    "AntiqueWhite1", 255, 239, 219,
+    "AntiqueWhite2", 238, 223, 204,
+    "AntiqueWhite3", 205, 192, 176,
+    "AntiqueWhite4", 139, 131, 120,
+    "aquamarine", 127, 255, 212,
+    "aquamarine1", 127, 255, 212,
+    "aquamarine2", 118, 238, 198,
+    "aquamarine3", 102, 205, 170,
+    "aquamarine4", 69, 139, 116,
+    "azure", 240, 255, 255,
+    "azure1", 240, 255, 255,
+    "azure2", 224, 238, 238,
+    "azure3", 193, 205, 205,
+    "azure4", 131, 139, 139,
+    "beige", 245, 245, 220,
+    "bisque", 255, 228, 196,
+    "bisque1", 255, 228, 196,
+    "bisque2", 238, 213, 183,
+    "bisque3", 205, 183, 158,
+    "bisque4", 139, 125, 107,
+    "black", 0, 0, 0,
+    "blanched almond", 255, 235, 205,
+    "BlanchedAlmond", 255, 235, 205,
+    "blue", 0, 0, 255,
+    "blue violet", 138, 43, 226,
+    "blue1", 0, 0, 255,
+    "blue2", 0, 0, 238,
+    "blue3", 0, 0, 205,
+    "blue4", 0, 0, 139,
+    "BlueViolet", 138, 43, 226,
+    "brown", 165, 42, 42,
+    "brown1", 255, 64, 64,
+    "brown2", 238, 59, 59,
+    "brown3", 205, 51, 51,
+    "brown4", 139, 35, 35,
+    "burlywood", 222, 184, 135,
+    "burlywood1", 255, 211, 155,
+    "burlywood2", 238, 197, 145,
+    "burlywood3", 205, 170, 125,
+    "burlywood4", 139, 115, 85,
+    "cadet blue", 95, 158, 160,
+    "CadetBlue", 95, 158, 160,
+    "CadetBlue1", 152, 245, 255,
+    "CadetBlue2", 142, 229, 238,
+    "CadetBlue3", 122, 197, 205,
+    "CadetBlue4", 83, 134, 139,
+    "chartreuse", 127, 255, 0,
+    "chartreuse1", 127, 255, 0,
+    "chartreuse2", 118, 238, 0,
+    "chartreuse3", 102, 205, 0,
+    "chartreuse4", 69, 139, 0,
+    "chocolate", 210, 105, 30,
+    "chocolate1", 255, 127, 36,
+    "chocolate2", 238, 118, 33,
+    "chocolate3", 205, 102, 29,
+    "chocolate4", 139, 69, 19,
+    "coral", 255, 127, 80,
+    "coral1", 255, 114, 86,
+    "coral2", 238, 106, 80,
+    "coral3", 205, 91, 69,
+    "coral4", 139, 62, 47,
+    "cornflower blue", 100, 149, 237,
+    "CornflowerBlue", 100, 149, 237,
+    "cornsilk", 255, 248, 220,
+    "cornsilk1", 255, 248, 220,
+    "cornsilk2", 238, 232, 205,
+    "cornsilk3", 205, 200, 177,
+    "cornsilk4", 139, 136, 120,
+    "cyan", 0, 255, 255,
+    "cyan1", 0, 255, 255,
+    "cyan2", 0, 238, 238,
+    "cyan3", 0, 205, 205,
+    "cyan4", 0, 139, 139,
+    "dark goldenrod", 184, 134, 11,
+    "dark green", 0, 100, 0,
+    "dark khaki", 189, 183, 107,
+    "dark olive green", 85, 107, 47,
+    "dark orange", 255, 140, 0,
+    "dark orchid", 153, 50, 204,
+    "dark salmon", 233, 150, 122,
+    "dark sea green", 143, 188, 143,
+    "dark slate blue", 72, 61, 139,
+    "dark slate gray", 47, 79, 79,
+    "dark slate grey", 47, 79, 79,
+    "dark turquoise", 0, 206, 209,
+    "dark violet", 148, 0, 211,
+    "DarkGoldenrod", 184, 134, 11,
+    "DarkGoldenrod1", 255, 185, 15,
+    "DarkGoldenrod2", 238, 173, 14,
+    "DarkGoldenrod3", 205, 149, 12,
+    "DarkGoldenrod4", 139, 101, 8,
+    "DarkGreen", 0, 100, 0,
+    "DarkKhaki", 189, 183, 107,
+    "DarkOliveGreen", 85, 107, 47,
+    "DarkOliveGreen1", 202, 255, 112,
+    "DarkOliveGreen2", 188, 238, 104,
+    "DarkOliveGreen3", 162, 205, 90,
+    "DarkOliveGreen4", 110, 139, 61,
+    "DarkOrange", 255, 140, 0,
+    "DarkOrange1", 255, 127, 0,
+    "DarkOrange2", 238, 118, 0,
+    "DarkOrange3", 205, 102, 0,
+    "DarkOrange4", 139, 69, 0,
+    "DarkOrchid", 153, 50, 204,
+    "DarkOrchid1", 191, 62, 255,
+    "DarkOrchid2", 178, 58, 238,
+    "DarkOrchid3", 154, 50, 205,
+    "DarkOrchid4", 104, 34, 139,
+    "DarkSalmon", 233, 150, 122,
+    "DarkSeaGreen", 143, 188, 143,
+    "DarkSeaGreen1", 193, 255, 193,
+    "DarkSeaGreen2", 180, 238, 180,
+    "DarkSeaGreen3", 155, 205, 155,
+    "DarkSeaGreen4", 105, 139, 105,
+    "DarkSlateBlue", 72, 61, 139,
+    "DarkSlateGray", 47, 79, 79,
+    "DarkSlateGray1", 151, 255, 255,
+    "DarkSlateGray2", 141, 238, 238,
+    "DarkSlateGray3", 121, 205, 205,
+    "DarkSlateGray4", 82, 139, 139,
+    "DarkSlateGrey", 47, 79, 79,
+    "DarkTurquoise", 0, 206, 209,
+    "DarkViolet", 148, 0, 211,
+    "deep pink", 255, 20, 147,
+    "deep sky blue", 0, 191, 255,
+    "DeepPink", 255, 20, 147,
+    "DeepPink1", 255, 20, 147,
+    "DeepPink2", 238, 18, 137,
+    "DeepPink3", 205, 16, 118,
+    "DeepPink4", 139, 10, 80,
+    "DeepSkyBlue", 0, 191, 255,
+    "DeepSkyBlue1", 0, 191, 255,
+    "DeepSkyBlue2", 0, 178, 238,
+    "DeepSkyBlue3", 0, 154, 205,
+    "DeepSkyBlue4", 0, 104, 139,
+    "dim gray", 105, 105, 105,
+    "dim grey", 105, 105, 105,
+    "DimGray", 105, 105, 105,
+    "DimGrey", 105, 105, 105,
+    "dodger blue", 30, 144, 255,
+    "DodgerBlue", 30, 144, 255,
+    "DodgerBlue1", 30, 144, 255,
+    "DodgerBlue2", 28, 134, 238,
+    "DodgerBlue3", 24, 116, 205,
+    "DodgerBlue4", 16, 78, 139,
+    "firebrick", 178, 34, 34,
+    "firebrick1", 255, 48, 48,
+    "firebrick2", 238, 44, 44,
+    "firebrick3", 205, 38, 38,
+    "firebrick4", 139, 26, 26,
+    "floral white", 255, 250, 240,
+    "FloralWhite", 255, 250, 240,
+    "forest green", 34, 139, 34,
+    "ForestGreen", 34, 139, 34,
+    "gainsboro", 220, 220, 220,
+    "ghost white", 248, 248, 255,
+    "GhostWhite", 248, 248, 255,
+    "gold", 255, 215, 0,
+    "gold1", 255, 215, 0,
+    "gold2", 238, 201, 0,
+    "gold3", 205, 173, 0,
+    "gold4", 139, 117, 0,
+    "goldenrod", 218, 165, 32,
+    "goldenrod1", 255, 193, 37,
+    "goldenrod2", 238, 180, 34,
+    "goldenrod3", 205, 155, 29,
+    "goldenrod4", 139, 105, 20,
+    "gray", 190, 190, 190,
+    "gray0", 0, 0, 0,
+    "gray1", 3, 3, 3,
+    "gray10", 26, 26, 26,
+    "gray100", 255, 255, 255,
+    "gray11", 28, 28, 28,
+    "gray12", 31, 31, 31,
+    "gray13", 33, 33, 33,
+    "gray14", 36, 36, 36,
+    "gray15", 38, 38, 38,
+    "gray16", 41, 41, 41,
+    "gray17", 43, 43, 43,
+    "gray18", 46, 46, 46,
+    "gray19", 48, 48, 48,
+    "gray2", 5, 5, 5,
+    "gray20", 51, 51, 51,
+    "gray21", 54, 54, 54,
+    "gray22", 56, 56, 56,
+    "gray23", 59, 59, 59,
+    "gray24", 61, 61, 61,
+    "gray25", 64, 64, 64,
+    "gray26", 66, 66, 66,
+    "gray27", 69, 69, 69,
+    "gray28", 71, 71, 71,
+    "gray29&q