diff --git a/Make.rules.in b/Make.rules.in
index 8d0358cd5cc3842815770afd10ad36710970e7cd..45bfde9484e704469f4b1bf7bb463db95b141664 100644
--- a/Make.rules.in
+++ b/Make.rules.in
@@ -22,8 +22,7 @@ CFLAGS    = @CFLAGS@
 OPTIONS   = @OPTIONS@ -D_REENTRANT
 X_CFLAGS  = @X_CFLAGS@
 X_LIBS    = @X_LIBS@
-XPM_LIB   = -lXpm
-XLIB      = @X_PRE_LIBS@ -lXext -lX11 @X_EXTRA_LIBS@
+XLIB      = @X_PRE_LIBS@ @XLIB@ @X_EXTRA_LIBS@
 WINELIB   = $(WINESTUB) $(TOPOBJDIR)/@LIB_TARGET@
 LIBS      = @LIBS@
 YACC      = @YACC@
diff --git a/Makefile.in b/Makefile.in
index 5c487d5408816f21dd074841775e1841f010dae5..47a2dd95fabd6f16e33e1f6dcebccb22306dd50b 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -39,7 +39,6 @@ LIBSUBDIRS = \
 	files \
 	graphics \
 	graphics/metafiledrv \
-	graphics/x11drv \
 	ipc \
 	library \
 	loader \
@@ -55,10 +54,14 @@ LIBSUBDIRS = \
 	resources \
 	scheduler \
 	server \
-	tsx11 \
 	win32 \
 	windows
 
+X11SUBDIRS = \
+	graphics/x11drv \
+	tsx11 \
+	windows/x11drv
+
 EMUSUBDIRS = \
 	debugger \
 	graphics/psdrv \
@@ -73,12 +76,13 @@ DOCSUBDIRS = documentation
 # All sub-directories
 ALLSUBDIRS = \
 	$(LIBSUBDIRS) \
+	$(X11SUBDIRS) \
 	$(EMUSUBDIRS) \
 	$(PROGSUBDIRS) \
 	$(DOCSUBDIRS)
 
 # Sub-directories to run make depend into
-DEPENDSUBDIRS = $(LIBSUBDIRS) $(EMUSUBDIRS) $(DOCSUBDIRS)
+DEPENDSUBDIRS = $(LIBSUBDIRS) $(X11SUBDIRS) $(EMUSUBDIRS) $(DOCSUBDIRS)
 
 # Sub-directories to run make install into
 INSTALLSUBDIRS = $(DOCSUBDIRS)
@@ -97,7 +101,6 @@ LIBOBJS = \
 	files/files.o \
 	graphics/graphics.o \
 	graphics/metafiledrv/metafiledrv.o \
-	graphics/x11drv/x11drv.o \
 	ipc/ipc.o \
 	loader/loader.o \
 	loader/ne/ne.o \
@@ -112,10 +115,14 @@ LIBOBJS = \
 	resources/resources.o \
 	scheduler/scheduler.o \
 	server/server.o \
-	tsx11/tsx11.o \
 	win32/win32.o \
 	windows/windows.o
 
+X11OBJS = \
+	graphics/x11drv/x11drv.o \
+	tsx11/tsx11.o \
+	windows/x11drv/x11drv.o
+
 EMUOBJS = \
 	debugger/debugger.o \
 	graphics/psdrv/psdrv.o \
@@ -137,21 +144,21 @@ uninstall:: uninstall_$(MAIN_TARGET)
 
 emu: wine
 
-lib: $(LIBSUBDIRS) $(LIB_TARGET)
+lib: $(LIBSUBDIRS) $(X11SUBDIRS) $(LIB_TARGET)
 
-wine wine.sym: $(LIBSUBDIRS) $(LIB_TARGET) $(EMUSUBDIRS) dummy
-	$(CC) -o wine $(EMUOBJS) $(LIB_TARGET) $(ALT_LINK) $(LDOPTIONS) $(X_LIBS) $(XPM_LIB) $(XLIB) $(LIBS)
+wine wine.sym: $(LIBSUBDIRS) $(X11SUBDIRS) $(LIB_TARGET) $(EMUSUBDIRS) dummy
+	$(CC) -o wine $(EMUOBJS) $(LIB_TARGET) $(ALT_LINK) $(LDOPTIONS) $(X_LIBS) $(XLIB) $(LIBS)
 	@echo "Please ignore the 'gets' warning message, it only applies to Windows programs which use 'gets'"
 	nm -n wine | grep -v _compiled >wine.sym
 	@echo "Wine build complete."
 
-libwine.a: $(LIBOBJS)
+libwine.a: $(LIBOBJS) $(X11OBJS)
 	$(RM) $@
-	$(AR) $@ $(LIBOBJS)
+	$(AR) $@ $(LIBOBJS) $(X11OBJS)
 	$(RANLIB) $@
 
-libwine.so.1.0: $(LIBOBJS)
-	$(CC) -shared -Wl,-soname,libwine.so -o$@ $(LIBOBJS) $(LDOPTIONS) $(X_LIBS) $(XPM_LIB) $(XLIB) $(LIBS)
+libwine.so.1.0: $(LIBOBJS) $(X11OBJS)
+	$(CC) -shared -Wl,-soname,libwine.so -o$@ $(LIBOBJS) $(X11OBJS) $(LDOPTIONS) $(X_LIBS) $(XLIB) $(LIBS)
 
 install_emu: install_lib
 	[ -d $(bindir) ] || $(MKDIR) $(bindir)
diff --git a/configure b/configure
index d90282ac596e86cf4db05ff183057c0a3ffb4c73..959d92c662b5b7241e12e735bb612c60e37f2e8a 100755
--- a/configure
+++ b/configure
@@ -2072,8 +2072,113 @@ else
   echo "$ac_t""no" 1>&6
 fi
 
+for ac_func in gethostbyname
+do
+echo $ac_n "checking for $ac_func""... $ac_c" 1>&6
+echo "configure:2079: checking for $ac_func" >&5
+if eval "test \"`echo '$''{'ac_cv_func_$ac_func'+set}'`\" = set"; then
+  echo $ac_n "(cached) $ac_c" 1>&6
+else
+  cat > conftest.$ac_ext <<EOF
+#line 2084 "configure"
+#include "confdefs.h"
+/* System header to define __stub macros and hopefully few prototypes,
+    which can conflict with char $ac_func(); below.  */
+#include <assert.h>
+/* Override any gcc2 internal prototype to avoid an error.  */
+/* We use char because int might match the return type of a gcc2
+    builtin and then its argument prototype would still apply.  */
+char $ac_func();
+
+int main() {
+
+/* The GNU C library defines this for functions which it implements
+    to always fail with ENOSYS.  Some functions are actually named
+    something starting with __ and the normal name is an alias.  */
+#if defined (__stub_$ac_func) || defined (__stub___$ac_func)
+choke me
+#else
+$ac_func();
+#endif
+
+; return 0; }
+EOF
+if { (eval echo configure:2107: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then
+  rm -rf conftest*
+  eval "ac_cv_func_$ac_func=yes"
+else
+  echo "configure: failed program was:" >&5
+  cat conftest.$ac_ext >&5
+  rm -rf conftest*
+  eval "ac_cv_func_$ac_func=no"
+fi
+rm -f conftest*
+fi
+
+if eval "test \"`echo '$ac_cv_func_'$ac_func`\" = yes"; then
+  echo "$ac_t""yes" 1>&6
+    ac_tr_func=HAVE_`echo $ac_func | tr 'abcdefghijklmnopqrstuvwxyz' 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'`
+  cat >> confdefs.h <<EOF
+#define $ac_tr_func 1
+EOF
+ 
+else
+  echo "$ac_t""no" 1>&6
+fi
+done
+
+if test "$ac_cv_func_gethostbyname" = "no"
+then
+    echo $ac_n "checking for gethostbyname in -lnsl""... $ac_c" 1>&6
+echo "configure:2134: checking for gethostbyname in -lnsl" >&5
+ac_lib_var=`echo nsl'_'gethostbyname | sed 'y%./+-%__p_%'`
+if eval "test \"`echo '$''{'ac_cv_lib_$ac_lib_var'+set}'`\" = set"; then
+  echo $ac_n "(cached) $ac_c" 1>&6
+else
+  ac_save_LIBS="$LIBS"
+LIBS="-lnsl  $LIBS"
+cat > conftest.$ac_ext <<EOF
+#line 2142 "configure"
+#include "confdefs.h"
+/* Override any gcc2 internal prototype to avoid an error.  */
+/* We use char because int might match the return type of a gcc2
+    builtin and then its argument prototype would still apply.  */
+char gethostbyname();
+
+int main() {
+gethostbyname()
+; return 0; }
+EOF
+if { (eval echo configure:2153: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then
+  rm -rf conftest*
+  eval "ac_cv_lib_$ac_lib_var=yes"
+else
+  echo "configure: failed program was:" >&5
+  cat conftest.$ac_ext >&5
+  rm -rf conftest*
+  eval "ac_cv_lib_$ac_lib_var=no"
+fi
+rm -f conftest*
+LIBS="$ac_save_LIBS"
+
+fi
+if eval "test \"`echo '$ac_cv_lib_'$ac_lib_var`\" = yes"; then
+  echo "$ac_t""yes" 1>&6
+    ac_tr_lib=HAVE_LIB`echo nsl | sed -e 's/[^a-zA-Z0-9_]/_/g' \
+    -e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'`
+  cat >> confdefs.h <<EOF
+#define $ac_tr_lib 1
+EOF
+
+  LIBS="-lnsl $LIBS"
+
+else
+  echo "$ac_t""no" 1>&6
+fi
+
+fi
 echo $ac_n "checking for setrunelocale in -lxpg4""... $ac_c" 1>&6
-echo "configure:2077: checking for setrunelocale in -lxpg4" >&5
+echo "configure:2182: checking for setrunelocale in -lxpg4" >&5
 ac_lib_var=`echo xpg4'_'setrunelocale | sed 'y%./+-%__p_%'`
 if eval "test \"`echo '$''{'ac_cv_lib_$ac_lib_var'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
@@ -2081,7 +2186,7 @@ else
   ac_save_LIBS="$LIBS"
 LIBS="-lxpg4  $LIBS"
 cat > conftest.$ac_ext <<EOF
-#line 2085 "configure"
+#line 2190 "configure"
 #include "confdefs.h"
 /* Override any gcc2 internal prototype to avoid an error.  */
 /* We use char because int might match the return type of a gcc2
@@ -2092,7 +2197,7 @@ int main() {
 setrunelocale()
 ; return 0; }
 EOF
-if { (eval echo configure:2096: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then
+if { (eval echo configure:2201: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then
   rm -rf conftest*
   eval "ac_cv_lib_$ac_lib_var=yes"
 else
@@ -2120,7 +2225,7 @@ else
 fi
 
 echo $ac_n "checking for dlopen in -ldl""... $ac_c" 1>&6
-echo "configure:2124: checking for dlopen in -ldl" >&5
+echo "configure:2229: checking for dlopen in -ldl" >&5
 ac_lib_var=`echo dl'_'dlopen | sed 'y%./+-%__p_%'`
 if eval "test \"`echo '$''{'ac_cv_lib_$ac_lib_var'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
@@ -2128,7 +2233,7 @@ else
   ac_save_LIBS="$LIBS"
 LIBS="-ldl  $LIBS"
 cat > conftest.$ac_ext <<EOF
-#line 2132 "configure"
+#line 2237 "configure"
 #include "confdefs.h"
 /* Override any gcc2 internal prototype to avoid an error.  */
 /* We use char because int might match the return type of a gcc2
@@ -2139,7 +2244,7 @@ int main() {
 dlopen()
 ; return 0; }
 EOF
-if { (eval echo configure:2143: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then
+if { (eval echo configure:2248: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then
   rm -rf conftest*
   eval "ac_cv_lib_$ac_lib_var=yes"
 else
@@ -2166,8 +2271,55 @@ else
   echo "$ac_t""no" 1>&6
 fi
 
-echo $ac_n "checking for XF86DGAQueryExtension in -lXxf86dga""... $ac_c" 1>&6
-echo "configure:2171: checking for XF86DGAQueryExtension in -lXxf86dga" >&5
+
+if test "$have_x" = "yes"
+then
+    XLIB="-lXpm -lXext -lX11"
+                    echo $ac_n "checking for XShmQueryExtension in -lXext""... $ac_c" 1>&6
+echo "configure:2280: checking for XShmQueryExtension in -lXext" >&5
+ac_lib_var=`echo Xext'_'XShmQueryExtension | sed 'y%./+-%__p_%'`
+if eval "test \"`echo '$''{'ac_cv_lib_$ac_lib_var'+set}'`\" = set"; then
+  echo $ac_n "(cached) $ac_c" 1>&6
+else
+  ac_save_LIBS="$LIBS"
+LIBS="-lXext $X_LIBS -lXext -lX11 $LIBS"
+cat > conftest.$ac_ext <<EOF
+#line 2288 "configure"
+#include "confdefs.h"
+/* Override any gcc2 internal prototype to avoid an error.  */
+/* We use char because int might match the return type of a gcc2
+    builtin and then its argument prototype would still apply.  */
+char XShmQueryExtension();
+
+int main() {
+XShmQueryExtension()
+; return 0; }
+EOF
+if { (eval echo configure:2299: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then
+  rm -rf conftest*
+  eval "ac_cv_lib_$ac_lib_var=yes"
+else
+  echo "configure: failed program was:" >&5
+  cat conftest.$ac_ext >&5
+  rm -rf conftest*
+  eval "ac_cv_lib_$ac_lib_var=no"
+fi
+rm -f conftest*
+LIBS="$ac_save_LIBS"
+
+fi
+if eval "test \"`echo '$ac_cv_lib_'$ac_lib_var`\" = yes"; then
+  echo "$ac_t""yes" 1>&6
+  cat >> confdefs.h <<\EOF
+#define HAVE_LIBXXSHM 1
+EOF
+
+else
+  echo "$ac_t""no" 1>&6
+fi
+
+        echo $ac_n "checking for XF86DGAQueryExtension in -lXxf86dga""... $ac_c" 1>&6
+echo "configure:2323: checking for XF86DGAQueryExtension in -lXxf86dga" >&5
 ac_lib_var=`echo Xxf86dga'_'XF86DGAQueryExtension | sed 'y%./+-%__p_%'`
 if eval "test \"`echo '$''{'ac_cv_lib_$ac_lib_var'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
@@ -2175,7 +2327,7 @@ else
   ac_save_LIBS="$LIBS"
 LIBS="-lXxf86dga $X_LIBS -lXext -lX11 $LIBS"
 cat > conftest.$ac_ext <<EOF
-#line 2179 "configure"
+#line 2331 "configure"
 #include "confdefs.h"
 /* Override any gcc2 internal prototype to avoid an error.  */
 /* We use char because int might match the return type of a gcc2
@@ -2186,7 +2338,7 @@ int main() {
 XF86DGAQueryExtension()
 ; return 0; }
 EOF
-if { (eval echo configure:2190: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then
+if { (eval echo configure:2342: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then
   rm -rf conftest*
   eval "ac_cv_lib_$ac_lib_var=yes"
 else
@@ -2209,22 +2361,27 @@ else
   echo "$ac_t""no" 1>&6
 fi
 
+else
+    XLIB=""
+    X_CFLAGS=""
+    X_LIBS=""
+fi
 
 for ac_hdr in sys/soundcard.h machine/soundcard.h
 do
 ac_safe=`echo "$ac_hdr" | sed 'y%./+-%__p_%'`
 echo $ac_n "checking for $ac_hdr""... $ac_c" 1>&6
-echo "configure:2218: checking for $ac_hdr" >&5
+echo "configure:2375: checking for $ac_hdr" >&5
 if eval "test \"`echo '$''{'ac_cv_header_$ac_safe'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   cat > conftest.$ac_ext <<EOF
-#line 2223 "configure"
+#line 2380 "configure"
 #include "confdefs.h"
 #include <$ac_hdr>
 EOF
 ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out"
-{ (eval echo configure:2228: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
+{ (eval echo configure:2385: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
 ac_err=`grep -v '^ *+' conftest.out`
 if test -z "$ac_err"; then
   rm -rf conftest*
@@ -2252,12 +2409,12 @@ done
 
 
 echo $ac_n "checking "for Open Sound System"""... $ac_c" 1>&6
-echo "configure:2256: checking "for Open Sound System"" >&5
+echo "configure:2413: checking "for Open Sound System"" >&5
 if eval "test \"`echo '$''{'ac_cv_c_opensoundsystem'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   cat > conftest.$ac_ext <<EOF
-#line 2261 "configure"
+#line 2418 "configure"
 #include "confdefs.h"
 
 	#ifdef HAVE_SYS_SOUNDCARD_H
@@ -2277,7 +2434,7 @@ int main() {
 
 ; return 0; }
 EOF
-if { (eval echo configure:2281: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
+if { (eval echo configure:2438: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
   rm -rf conftest*
   ac_cv_c_opensoundsystem="yes"
 else
@@ -2301,12 +2458,12 @@ fi
 
 
 echo $ac_n "checking "for union semun"""... $ac_c" 1>&6
-echo "configure:2305: checking "for union semun"" >&5
+echo "configure:2462: checking "for union semun"" >&5
 if eval "test \"`echo '$''{'ac_cv_c_union_semun'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   cat > conftest.$ac_ext <<EOF
-#line 2310 "configure"
+#line 2467 "configure"
 #include "confdefs.h"
 #include <sys/types.h>
 #include <sys/sem.h>
@@ -2314,7 +2471,7 @@ int main() {
 union semun foo
 ; return 0; }
 EOF
-if { (eval echo configure:2318: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
+if { (eval echo configure:2475: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
   rm -rf conftest*
   ac_cv_c_union_semun="yes"
 else
@@ -2342,7 +2499,7 @@ if test "x${GCC}" = "xyes"
 then
   CFLAGS="$CFLAGS -Wall"
   echo $ac_n "checking "for gcc strength-reduce bug"""... $ac_c" 1>&6
-echo "configure:2346: checking "for gcc strength-reduce bug"" >&5
+echo "configure:2503: checking "for gcc strength-reduce bug"" >&5
 if eval "test \"`echo '$''{'ac_cv_c_gcc_strength_bug'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
@@ -2350,7 +2507,7 @@ else
   ac_cv_c_gcc_strength_bug="yes"
 else
   cat > conftest.$ac_ext <<EOF
-#line 2354 "configure"
+#line 2511 "configure"
 #include "confdefs.h"
 
 int main(void) {
@@ -2361,7 +2518,7 @@ int main(void) {
   exit( Array[1] != -2 );
 }
 EOF
-if { (eval echo configure:2365: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest && (./conftest; exit) 2>/dev/null
+if { (eval echo configure:2522: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest && (./conftest; exit) 2>/dev/null
 then
   ac_cv_c_gcc_strength_bug="no"
 else
@@ -2384,7 +2541,7 @@ fi
 
 
 echo $ac_n "checking "whether external symbols need an underscore prefix"""... $ac_c" 1>&6
-echo "configure:2388: checking "whether external symbols need an underscore prefix"" >&5
+echo "configure:2545: checking "whether external symbols need an underscore prefix"" >&5
 if eval "test \"`echo '$''{'ac_cv_c_extern_prefix'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
@@ -2396,14 +2553,14 @@ _ac_test:
 	.long 0
 EOF
 cat > conftest.$ac_ext <<EOF
-#line 2400 "configure"
+#line 2557 "configure"
 #include "confdefs.h"
 extern int ac_test;
 int main() {
 if (ac_test) return 1
 ; return 0; }
 EOF
-if { (eval echo configure:2407: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then
+if { (eval echo configure:2564: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then
   rm -rf conftest*
   ac_cv_c_extern_prefix="yes"
 else
@@ -2427,7 +2584,7 @@ fi
 
 
 echo $ac_n "checking "whether assembler accepts .string"""... $ac_c" 1>&6
-echo "configure:2431: checking "whether assembler accepts .string"" >&5
+echo "configure:2588: checking "whether assembler accepts .string"" >&5
 if eval "test \"`echo '$''{'ac_cv_c_asm_string'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
@@ -2437,14 +2594,14 @@ cat > conftest_asm.s <<EOF
 	.string "test"
 EOF
 cat > conftest.$ac_ext <<EOF
-#line 2441 "configure"
+#line 2598 "configure"
 #include "confdefs.h"
 
 int main() {
 
 ; return 0; }
 EOF
-if { (eval echo configure:2448: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then
+if { (eval echo configure:2605: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then
   rm -rf conftest*
   ac_cv_c_asm_string="yes"
 else
@@ -2471,21 +2628,21 @@ DLLFLAGS=""
 if test "$LIB_TARGET" = "libwine.so.1.0"
 then
   echo $ac_n "checking "whether we can build a dll"""... $ac_c" 1>&6
-echo "configure:2475: checking "whether we can build a dll"" >&5
+echo "configure:2632: checking "whether we can build a dll"" >&5
 if eval "test \"`echo '$''{'ac_cv_c_dll'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   saved_cflags=$CFLAGS
   CFLAGS="$CFLAGS -fPIC -shared -Wl,-soname,conftest.so.1.0"
   cat > conftest.$ac_ext <<EOF
-#line 2482 "configure"
+#line 2639 "configure"
 #include "confdefs.h"
 
 int main() {
 return 1
 ; return 0; }
 EOF
-if { (eval echo configure:2489: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then
+if { (eval echo configure:2646: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then
   rm -rf conftest*
   ac_cv_c_dll="yes"
 else
@@ -2511,7 +2668,7 @@ fi
 
 
 echo $ac_n "checking "for reentrant libc"""... $ac_c" 1>&6
-echo "configure:2515: checking "for reentrant libc"" >&5
+echo "configure:2672: checking "for reentrant libc"" >&5
 if eval "test \"`echo '$''{'wine_cv_libc_reentrant'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
@@ -2519,14 +2676,14 @@ else
   wine_cv_libc_reentrant=yes 
 else
   cat > conftest.$ac_ext <<EOF
-#line 2523 "configure"
+#line 2680 "configure"
 #include "confdefs.h"
 int myerrno = 0;
 char buf[256];
 int *__errno_location(){return &myerrno;}
 main(){connect(0,buf,255); exit(!myerrno);}
 EOF
-if { (eval echo configure:2530: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest && (./conftest; exit) 2>/dev/null
+if { (eval echo configure:2687: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest && (./conftest; exit) 2>/dev/null
 then
   wine_cv_libc_reentrant=yes
 else
@@ -2551,7 +2708,7 @@ fi
 
 
 echo $ac_n "checking "for reentrant X libraries"""... $ac_c" 1>&6
-echo "configure:2555: checking "for reentrant X libraries"" >&5
+echo "configure:2712: checking "for reentrant X libraries"" >&5
 if eval "test \"`echo '$''{'wine_cv_x_reentrant'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
@@ -2596,12 +2753,12 @@ fi
 for ac_func in clone getpagesize memmove sendmsg sigaltstack strerror stricmp tcgetattr timegm usleep wait4 waitpid vfscanf
 do
 echo $ac_n "checking for $ac_func""... $ac_c" 1>&6
-echo "configure:2600: checking for $ac_func" >&5
+echo "configure:2757: checking for $ac_func" >&5
 if eval "test \"`echo '$''{'ac_cv_func_$ac_func'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   cat > conftest.$ac_ext <<EOF
-#line 2605 "configure"
+#line 2762 "configure"
 #include "confdefs.h"
 /* System header to define __stub macros and hopefully few prototypes,
     which can conflict with char $ac_func(); below.  */
@@ -2624,7 +2781,7 @@ $ac_func();
 
 ; return 0; }
 EOF
-if { (eval echo configure:2628: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then
+if { (eval echo configure:2785: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then
   rm -rf conftest*
   eval "ac_cv_func_$ac_func=yes"
 else
@@ -2652,17 +2809,17 @@ for ac_hdr in wctype.h sys/syscall.h syscall.h sys/param.h sys/vfs.h sys/mount.h
 do
 ac_safe=`echo "$ac_hdr" | sed 'y%./+-%__p_%'`
 echo $ac_n "checking for $ac_hdr""... $ac_c" 1>&6
-echo "configure:2656: checking for $ac_hdr" >&5
+echo "configure:2813: checking for $ac_hdr" >&5
 if eval "test \"`echo '$''{'ac_cv_header_$ac_safe'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   cat > conftest.$ac_ext <<EOF
-#line 2661 "configure"
+#line 2818 "configure"
 #include "confdefs.h"
 #include <$ac_hdr>
 EOF
 ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out"
-{ (eval echo configure:2666: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
+{ (eval echo configure:2823: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
 ac_err=`grep -v '^ *+' conftest.out`
 if test -z "$ac_err"; then
   rm -rf conftest*
@@ -2689,12 +2846,12 @@ fi
 done
 
 echo $ac_n "checking whether stat file-mode macros are broken""... $ac_c" 1>&6
-echo "configure:2693: checking whether stat file-mode macros are broken" >&5
+echo "configure:2850: checking whether stat file-mode macros are broken" >&5
 if eval "test \"`echo '$''{'ac_cv_header_stat_broken'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   cat > conftest.$ac_ext <<EOF
-#line 2698 "configure"
+#line 2855 "configure"
 #include "confdefs.h"
 #include <sys/types.h>
 #include <sys/stat.h>
@@ -2745,12 +2902,12 @@ EOF
 fi
 
 echo $ac_n "checking for working const""... $ac_c" 1>&6
-echo "configure:2749: checking for working const" >&5
+echo "configure:2906: checking for working const" >&5
 if eval "test \"`echo '$''{'ac_cv_c_const'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   cat > conftest.$ac_ext <<EOF
-#line 2754 "configure"
+#line 2911 "configure"
 #include "confdefs.h"
 
 int main() {
@@ -2799,7 +2956,7 @@ ccp = (char const *const *) p;
 
 ; return 0; }
 EOF
-if { (eval echo configure:2803: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
+if { (eval echo configure:2960: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
   rm -rf conftest*
   ac_cv_c_const=yes
 else
@@ -2820,12 +2977,12 @@ EOF
 fi
 
 echo $ac_n "checking for ANSI C header files""... $ac_c" 1>&6
-echo "configure:2824: checking for ANSI C header files" >&5
+echo "configure:2981: checking for ANSI C header files" >&5
 if eval "test \"`echo '$''{'ac_cv_header_stdc'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   cat > conftest.$ac_ext <<EOF
-#line 2829 "configure"
+#line 2986 "configure"
 #include "confdefs.h"
 #include <stdlib.h>
 #include <stdarg.h>
@@ -2833,7 +2990,7 @@ else
 #include <float.h>
 EOF
 ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out"
-{ (eval echo configure:2837: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
+{ (eval echo configure:2994: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
 ac_err=`grep -v '^ *+' conftest.out`
 if test -z "$ac_err"; then
   rm -rf conftest*
@@ -2850,7 +3007,7 @@ rm -f conftest*
 if test $ac_cv_header_stdc = yes; then
   # SunOS 4.x string.h does not declare mem*, contrary to ANSI.
 cat > conftest.$ac_ext <<EOF
-#line 2854 "configure"
+#line 3011 "configure"
 #include "confdefs.h"
 #include <string.h>
 EOF
@@ -2868,7 +3025,7 @@ fi
 if test $ac_cv_header_stdc = yes; then
   # ISC 2.0.2 stdlib.h does not declare free, contrary to ANSI.
 cat > conftest.$ac_ext <<EOF
-#line 2872 "configure"
+#line 3029 "configure"
 #include "confdefs.h"
 #include <stdlib.h>
 EOF
@@ -2889,7 +3046,7 @@ if test "$cross_compiling" = yes; then
   :
 else
   cat > conftest.$ac_ext <<EOF
-#line 2893 "configure"
+#line 3050 "configure"
 #include "confdefs.h"
 #include <ctype.h>
 #define ISLOWER(c) ('a' <= (c) && (c) <= 'z')
@@ -2900,7 +3057,7 @@ if (XOR (islower (i), ISLOWER (i)) || toupper (i) != TOUPPER (i)) exit(2);
 exit (0); }
 
 EOF
-if { (eval echo configure:2904: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest && (./conftest; exit) 2>/dev/null
+if { (eval echo configure:3061: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest && (./conftest; exit) 2>/dev/null
 then
   :
 else
@@ -2924,12 +3081,12 @@ EOF
 fi
 
 echo $ac_n "checking for size_t""... $ac_c" 1>&6
-echo "configure:2928: checking for size_t" >&5
+echo "configure:3085: checking for size_t" >&5
 if eval "test \"`echo '$''{'ac_cv_type_size_t'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   cat > conftest.$ac_ext <<EOF
-#line 2933 "configure"
+#line 3090 "configure"
 #include "confdefs.h"
 #include <sys/types.h>
 #if STDC_HEADERS
@@ -2957,7 +3114,7 @@ EOF
 fi
 
 echo $ac_n "checking size of long long""... $ac_c" 1>&6
-echo "configure:2961: checking size of long long" >&5
+echo "configure:3118: checking size of long long" >&5
 if eval "test \"`echo '$''{'ac_cv_sizeof_long_long'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
@@ -2965,7 +3122,7 @@ else
   ac_cv_sizeof_long_long=0
 else
   cat > conftest.$ac_ext <<EOF
-#line 2969 "configure"
+#line 3126 "configure"
 #include "confdefs.h"
 #include <stdio.h>
 main()
@@ -2976,7 +3133,7 @@ main()
   exit(0);
 }
 EOF
-if { (eval echo configure:2980: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest && (./conftest; exit) 2>/dev/null
+if { (eval echo configure:3137: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest && (./conftest; exit) 2>/dev/null
 then
   ac_cv_sizeof_long_long=`cat conftestval`
 else
@@ -2999,7 +3156,7 @@ EOF
 
 if test $ac_cv_func_sendmsg = no; then
     echo $ac_n "checking for sendmsg in -lsocket""... $ac_c" 1>&6
-echo "configure:3003: checking for sendmsg in -lsocket" >&5
+echo "configure:3160: checking for sendmsg in -lsocket" >&5
 ac_lib_var=`echo socket'_'sendmsg | sed 'y%./+-%__p_%'`
 if eval "test \"`echo '$''{'ac_cv_lib_$ac_lib_var'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
@@ -3007,7 +3164,7 @@ else
   ac_save_LIBS="$LIBS"
 LIBS="-lsocket  $LIBS"
 cat > conftest.$ac_ext <<EOF
-#line 3011 "configure"
+#line 3168 "configure"
 #include "confdefs.h"
 /* Override any gcc2 internal prototype to avoid an error.  */
 /* We use char because int might match the return type of a gcc2
@@ -3018,7 +3175,7 @@ int main() {
 sendmsg()
 ; return 0; }
 EOF
-if { (eval echo configure:3022: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then
+if { (eval echo configure:3179: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then
   rm -rf conftest*
   eval "ac_cv_lib_$ac_lib_var=yes"
 else
@@ -3051,12 +3208,12 @@ fi
 if test "$ac_cv_header_sys_vfs_h" = "yes"
 then
     echo $ac_n "checking "whether sys/vfs.h defines statfs"""... $ac_c" 1>&6
-echo "configure:3055: checking "whether sys/vfs.h defines statfs"" >&5
+echo "configure:3212: checking "whether sys/vfs.h defines statfs"" >&5
 if eval "test \"`echo '$''{'wine_cv_sys_vfs_has_statfs'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   cat > conftest.$ac_ext <<EOF
-#line 3060 "configure"
+#line 3217 "configure"
 #include "confdefs.h"
 
 	#include <sys/types.h>
@@ -3073,7 +3230,7 @@ int main() {
 	
 ; return 0; }
 EOF
-if { (eval echo configure:3077: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
+if { (eval echo configure:3234: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
   rm -rf conftest*
   wine_cv_sys_vfs_has_statfs=yes
 else
@@ -3100,12 +3257,12 @@ fi
 if test "$ac_cv_header_sys_statfs_h" = "yes"
 then
     echo $ac_n "checking "whether sys/statfs.h defines statfs"""... $ac_c" 1>&6
-echo "configure:3104: checking "whether sys/statfs.h defines statfs"" >&5
+echo "configure:3261: checking "whether sys/statfs.h defines statfs"" >&5
 if eval "test \"`echo '$''{'wine_cv_sys_statfs_has_statfs'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   cat > conftest.$ac_ext <<EOF
-#line 3109 "configure"
+#line 3266 "configure"
 #include "confdefs.h"
 
 	#include <sys/types.h>
@@ -3120,7 +3277,7 @@ int main() {
 	
 ; return 0; }
 EOF
-if { (eval echo configure:3124: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
+if { (eval echo configure:3281: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
   rm -rf conftest*
   wine_cv_sys_statfs_has_statfs=yes
 else
@@ -3147,12 +3304,12 @@ fi
 if test "$ac_cv_header_sys_mount_h" = "yes"
 then
     echo $ac_n "checking "whether sys/mount.h defines statfs"""... $ac_c" 1>&6
-echo "configure:3151: checking "whether sys/mount.h defines statfs"" >&5
+echo "configure:3308: checking "whether sys/mount.h defines statfs"" >&5
 if eval "test \"`echo '$''{'wine_cv_sys_mount_has_statfs'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   cat > conftest.$ac_ext <<EOF
-#line 3156 "configure"
+#line 3313 "configure"
 #include "confdefs.h"
 
 	#include <sys/types.h>
@@ -3167,7 +3324,7 @@ int main() {
 	
 ; return 0; }
 EOF
-if { (eval echo configure:3171: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
+if { (eval echo configure:3328: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
   rm -rf conftest*
   wine_cv_sys_mount_has_statfs=yes
 else
@@ -3193,7 +3350,7 @@ fi
 
 
 echo $ac_n "checking "for statfs.f_bfree"""... $ac_c" 1>&6
-echo "configure:3197: checking "for statfs.f_bfree"" >&5
+echo "configure:3354: checking "for statfs.f_bfree"" >&5
 if eval "test \"`echo '$''{'wine_cv_statfs_bfree'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
@@ -3202,7 +3359,7 @@ else
         wine_cv_statfs_bfree=no
     else
     	cat > conftest.$ac_ext <<EOF
-#line 3206 "configure"
+#line 3363 "configure"
 #include "confdefs.h"
 
 	#include <sys/types.h>
@@ -3229,7 +3386,7 @@ int main() {
 	
 ; return 0; }
 EOF
-if { (eval echo configure:3233: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
+if { (eval echo configure:3390: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
   rm -rf conftest*
   wine_cv_statfs_bfree=yes
 else
@@ -3253,7 +3410,7 @@ EOF
 fi
 
 echo $ac_n "checking "for statfs.f_bavail"""... $ac_c" 1>&6
-echo "configure:3257: checking "for statfs.f_bavail"" >&5
+echo "configure:3414: checking "for statfs.f_bavail"" >&5
 if eval "test \"`echo '$''{'wine_cv_statfs_bavail'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
@@ -3262,7 +3419,7 @@ else
         wine_cv_statfs_bavail=no
     else
     	cat > conftest.$ac_ext <<EOF
-#line 3266 "configure"
+#line 3423 "configure"
 #include "confdefs.h"
 
 	#include <sys/types.h>
@@ -3289,7 +3446,7 @@ int main() {
 	
 ; return 0; }
 EOF
-if { (eval echo configure:3293: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
+if { (eval echo configure:3450: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
   rm -rf conftest*
   wine_cv_statfs_bavail=yes
 else
@@ -3314,7 +3471,7 @@ fi
 
 
 echo $ac_n "checking "for working sigaltstack"""... $ac_c" 1>&6
-echo "configure:3318: checking "for working sigaltstack"" >&5
+echo "configure:3475: checking "for working sigaltstack"" >&5
 if eval "test \"`echo '$''{'ac_cv_c_working_sigaltstack'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
@@ -3323,7 +3480,7 @@ else
 
 else
   cat > conftest.$ac_ext <<EOF
-#line 3327 "configure"
+#line 3484 "configure"
 #include "confdefs.h"
 
 	#include <stdio.h>
@@ -3361,7 +3518,7 @@ else
 	}
 	
 EOF
-if { (eval echo configure:3365: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest && (./conftest; exit) 2>/dev/null
+if { (eval echo configure:3522: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest && (./conftest; exit) 2>/dev/null
 then
   ac_cv_c_working_sigaltstack="yes"
 else
@@ -3388,12 +3545,12 @@ fi
 
 
 echo $ac_n "checking "for msg_accrights in struct msghdr"""... $ac_c" 1>&6
-echo "configure:3392: checking "for msg_accrights in struct msghdr"" >&5
+echo "configure:3549: checking "for msg_accrights in struct msghdr"" >&5
 if eval "test \"`echo '$''{'ac_cv_c_msg_accrights'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   cat > conftest.$ac_ext <<EOF
-#line 3397 "configure"
+#line 3554 "configure"
 #include "confdefs.h"
 #include <sys/types.h>
 #include <sys/socket.h>
@@ -3401,7 +3558,7 @@ int main() {
 struct msghdr hdr; hdr.msg_accrights=0
 ; return 0; }
 EOF
-if { (eval echo configure:3405: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
+if { (eval echo configure:3562: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
   rm -rf conftest*
   ac_cv_c_msg_accrights="yes"
 else
@@ -3581,7 +3738,8 @@ tools/Makefile
 tools/wrc/Makefile
 tsx11/Makefile
 win32/Makefile
-windows/Makefile  include/config.h" | sed "s/:[^ ]*//g"` conftest*; exit 1' 1 2 15
+windows/Makefile
+windows/x11drv/Makefile  include/config.h" | sed "s/:[^ ]*//g"` conftest*; exit 1' 1 2 15
 EOF
 cat >> $CONFIG_STATUS <<EOF
 
@@ -3631,6 +3789,7 @@ s%@INSTALL_PROGRAM@%$INSTALL_PROGRAM%g
 s%@INSTALL_DATA@%$INSTALL_DATA%g
 s%@LN_S@%$LN_S%g
 s%@C2MAN@%$C2MAN%g
+s%@XLIB@%$XLIB%g
 s%@DLLFLAGS@%$DLLFLAGS%g
 /@MAKE_RULES@/r $MAKE_RULES
 s%@MAKE_RULES@%%g
@@ -3728,7 +3887,8 @@ tools/Makefile
 tools/wrc/Makefile
 tsx11/Makefile
 win32/Makefile
-windows/Makefile "}
+windows/Makefile
+windows/x11drv/Makefile "}
 EOF
 cat >> $CONFIG_STATUS <<\EOF
 for ac_file in .. $CONFIG_FILES; do if test "x$ac_file" != x..; then
diff --git a/configure.in b/configure.in
index b134116c87f6a366a2799adb4462b54263af5e68..46bf7da5469baecc026d05cdbd4e09a769999330 100644
--- a/configure.in
+++ b/configure.in
@@ -81,12 +81,32 @@ dnl Check for -li386 for NetBSD and OpenBSD
 AC_CHECK_LIB(i386,i386_set_ldt)
 dnl Check for -lw for Solaris
 AC_CHECK_LIB(w,iswalnum)
+dnl Check for -lnsl for Solaris
+AC_CHECK_FUNCS(gethostbyname)
+if test "$ac_cv_func_gethostbyname" = "no"
+then
+    AC_CHECK_LIB(nsl,gethostbyname)
+fi
 dnl Check for -lxpg4 for FreeBSD
 AC_CHECK_LIB(xpg4,setrunelocale)
 dnl Check for -ldl
 AC_CHECK_LIB(dl,dlopen)
-dnl Check for XFree86 DGA extension
-AC_CHECK_LIB(Xxf86dga,XF86DGAQueryExtension,AC_DEFINE(HAVE_LIBXXF86DGA) X_PRE_LIBS="$X_PRE_LIBS -lXxf86dga",,$X_LIBS -lXext -lX11)
+AC_SUBST(XLIB)
+if test "$have_x" = "yes"
+then
+    XLIB="-lXpm -lXext -lX11"
+    dnl Check for -lXpm
+    dnl FIXME: should be done once we can compile without -lXpm
+    dnl AC_CHECK_LIB(Xpm,XpmCreatePixmapFromData,AC_DEFINE(HAVE_LIBXXPM) X_PRE_LIBS="$X_PRE_LIBS -lXpm",,$X_LIBS -lXext -lX11)
+    dnl Check for X Shm extension
+    AC_CHECK_LIB(Xext,XShmQueryExtension,AC_DEFINE(HAVE_LIBXXSHM),,$X_LIBS -lXext -lX11)
+    dnl Check for XFree86 DGA extension
+    AC_CHECK_LIB(Xxf86dga,XF86DGAQueryExtension,AC_DEFINE(HAVE_LIBXXF86DGA) X_PRE_LIBS="$X_PRE_LIBS -lXxf86dga",,$X_LIBS -lXext -lX11)
+else
+    XLIB=""
+    X_CFLAGS=""
+    X_LIBS=""
+fi
 
 dnl **** Check for Open Sound System ****
 AC_CHECK_HEADERS(sys/soundcard.h machine/soundcard.h)
@@ -532,7 +552,8 @@ tools/Makefile
 tools/wrc/Makefile
 tsx11/Makefile
 win32/Makefile
-windows/Makefile ])
+windows/Makefile
+windows/x11drv/Makefile ])
 
 if test "$wine_cv_libc_reentrant" = "no" 
 then
diff --git a/include/acconfig.h b/include/acconfig.h
index 66ece2f024531b2641f5e4e2d23b0dda8c59dd6d..9934a3998c9bd42f29b2be784f596129544a7b2c 100644
--- a/include/acconfig.h
+++ b/include/acconfig.h
@@ -18,6 +18,9 @@
 /* Define if you have the Xxf86dga library (-lXxf86dga).  */
 #undef HAVE_LIBXXF86DGA
 
+/* Define if you have the X Shm extension */
+#undef HAVE_LIBXXSHM
+
 /* Define if you have the Open Sound system.  */
 #undef HAVE_OSS
 
diff --git a/include/config.h.in b/include/config.h.in
index 76e8c00e62c893caf8f03c3fcdcbfbe3505553c1..62b96c90756692a3a0df2634bb8947c964448bbf 100644
--- a/include/config.h.in
+++ b/include/config.h.in
@@ -30,6 +30,9 @@
 /* Define if you have the Xxf86dga library (-lXxf86dga).  */
 #undef HAVE_LIBXXF86DGA
 
+/* Define if you have the X Shm extension */
+#undef HAVE_LIBXXSHM
+
 /* Define if you have the Open Sound system.  */
 #undef HAVE_OSS
 
@@ -69,6 +72,9 @@
 /* Define if you have the clone function.  */
 #undef HAVE_CLONE
 
+/* Define if you have the gethostbyname function.  */
+#undef HAVE_GETHOSTBYNAME
+
 /* Define if you have the getpagesize function.  */
 #undef HAVE_GETPAGESIZE
 
@@ -165,6 +171,9 @@
 /* Define if you have the i386 library (-li386).  */
 #undef HAVE_LIBI386
 
+/* Define if you have the nsl library (-lnsl).  */
+#undef HAVE_LIBNSL
+
 /* Define if you have the socket library (-lsocket).  */
 #undef HAVE_LIBSOCKET
 
diff --git a/include/win.h b/include/win.h
index 9cffbe74c87ccb2416180dcd46f132627b7187bc..2954265933a62637322017f15821a6e0db1140e5 100644
--- a/include/win.h
+++ b/include/win.h
@@ -51,6 +51,7 @@ typedef enum
 #define RDW_C_DELETEHRGN	0x0002
 
 struct tagDCE;
+struct _WND_DRIVER;
 
 typedef struct tagWND
 {
@@ -81,9 +82,20 @@ typedef struct tagWND
     Window         window;        /* X window (only for top-level windows) */
     HMENU16        hSysMenu;      /* window's copy of System Menu */
     DWORD          userdata;      /* User private data */
+    struct _WND_DRIVER *pDriver;  /* Window driver */
     DWORD          wExtra[1];     /* Window extra bytes */
 } WND;
 
+typedef struct _WND_DRIVER
+{
+    BOOL32 (*pCreateWindow)(WND *, CLASS *, CREATESTRUCT32A *, BOOL32);
+    WND*   (*pSetParent)(WND *, WND *);
+} WND_DRIVER;
+
+/* X11 windows driver */
+/* FIXME: does not belong here */
+extern WND_DRIVER X11DRV_WND_Driver;
+
 typedef struct
 {
     RECT16	   rectNormal;
diff --git a/libtest/Makefile.in b/libtest/Makefile.in
index d387e29b0bc9f6626b312a9a67fb075966b8e4cc..084a2a6c69267a3b2ecf8d30ae083c7b35779541 100644
--- a/libtest/Makefile.in
+++ b/libtest/Makefile.in
@@ -5,7 +5,7 @@ VPATH     = @srcdir@
 MODULE    = none
 RCFLAGS   = -w32 -h
 PROGRAMS  = expand hello hello2 hello3 hello4 hello5 new rolex volinfo
-ALL_LIBS  = $(WINELIB) $(X_LIBS) $(XPM_LIB) $(XLIB) $(LIBS)
+ALL_LIBS  = $(WINELIB) $(X_LIBS) $(XLIB) $(LIBS)
 
 C_SRCS = \
 	expand.c \
diff --git a/programs/clock/Makefile.in b/programs/clock/Makefile.in
index 11ab860a94992d8937715844a48bd0be68cc8222..dc657372dc307f7af5dd20b3974d2cddc5844989 100644
--- a/programs/clock/Makefile.in
+++ b/programs/clock/Makefile.in
@@ -5,7 +5,7 @@ SRCDIR    = @srcdir@
 VPATH     = @srcdir@
 MODULE    = none
 PROGRAMS  = clock
-ALL_LIBS  = $(WINELIB) $(X_LIBS) $(XPM_LIB) $(XLIB) $(LIBS)
+ALL_LIBS  = $(WINELIB) $(X_LIBS) $(XLIB) $(LIBS)
 RCFLAGS   = -w32 -h
 WRCEXTRA  = -A -p $*
 
diff --git a/programs/control/Makefile.in b/programs/control/Makefile.in
index 07c41182c6f883bea8c77728e1e13cffa356a5a1..6b1fca7e5a1004923edab8c31279c5bc3696e6f9 100644
--- a/programs/control/Makefile.in
+++ b/programs/control/Makefile.in
@@ -5,7 +5,7 @@ SRCDIR    = @srcdir@
 VPATH     = @srcdir@
 MODULE    = none
 PROGRAMS  = control
-ALL_LIBS  = $(WINELIB) $(X_LIBS) $(XPM_LIB) $(XLIB) $(LIBS)
+ALL_LIBS  = $(WINELIB) $(X_LIBS) $(XLIB) $(LIBS)
 
 C_SRCS = control.c
 
diff --git a/programs/notepad/Makefile.in b/programs/notepad/Makefile.in
index aa6b9ee91ab3616ba05db9d903901df68f2f6884..b5cc06d85a2013598a41506be4bb25f76a5ff1c0 100644
--- a/programs/notepad/Makefile.in
+++ b/programs/notepad/Makefile.in
@@ -5,7 +5,7 @@ SRCDIR    = @srcdir@
 VPATH     = @srcdir@
 MODULE    = none
 PROGRAMS  = notepad
-ALL_LIBS  = $(WINELIB) $(X_LIBS) $(XPM_LIB) $(XLIB) $(LIBS)
+ALL_LIBS  = $(WINELIB) $(X_LIBS) $(XLIB) $(LIBS)
 RCFLAGS   = -w32 -h
 WRCEXTRA  = -A -p $*
 
diff --git a/programs/progman/Makefile.in b/programs/progman/Makefile.in
index ad3c8b98a67247d0588fbd568e7f787615ab8dec..3ba6e5961f013ec45dc58ab2a8e0709b3e30efb3 100644
--- a/programs/progman/Makefile.in
+++ b/programs/progman/Makefile.in
@@ -5,7 +5,7 @@ SRCDIR    = @srcdir@
 VPATH     = @srcdir@
 MODULE    = none
 PROGRAMS  = progman
-ALL_LIBS  = $(WINELIB) $(X_LIBS) $(XPM_LIB) $(XLIB) $(LIBS)
+ALL_LIBS  = $(WINELIB) $(X_LIBS) $(XLIB) $(LIBS)
 RCFLAGS   = -w32 -h
 WRCEXTRA  = -A -p $*
 
diff --git a/programs/regtest/Makefile.in b/programs/regtest/Makefile.in
index a1a1e8dfdd89c47af604249e1c1a98ab265c3bcc..b175592ffa7c1716e10228d73cee611df0d1efc7 100644
--- a/programs/regtest/Makefile.in
+++ b/programs/regtest/Makefile.in
@@ -5,7 +5,7 @@ SRCDIR    = @srcdir@
 VPATH     = @srcdir@
 MODULE    = none
 PROGRAMS  = regtest
-ALL_LIBS  = $(WINELIB) $(X_LIBS) $(XPM_LIB) $(XLIB) $(LIBS)
+ALL_LIBS  = $(WINELIB) $(X_LIBS) $(XLIB) $(LIBS)
 RCFLAGS   = -w32 -h
 WRCEXTRA  = -A -p $*
 
diff --git a/programs/view/Makefile.in b/programs/view/Makefile.in
index b531e803d025a99e722cc7c7123f629c9d26fbb7..3dc77ea9541bde35603a891b950a1e07068c2e31 100644
--- a/programs/view/Makefile.in
+++ b/programs/view/Makefile.in
@@ -5,7 +5,7 @@ SRCDIR    = @srcdir@
 VPATH     = @srcdir@
 MODULE    = none
 PROGRAMS  = view
-ALL_LIBS  = $(WINELIB) $(X_LIBS) $(XPM_LIB) $(XLIB) $(LIBS)
+ALL_LIBS  = $(WINELIB) $(X_LIBS) $(XLIB) $(LIBS)
 RCFLAGS   = -w32 -h
 WRCEXTRA  = -A -p $*
 
diff --git a/programs/winhelp/Makefile.in b/programs/winhelp/Makefile.in
index 775119cd3d32bc504872e3c623fe919bf8e31ca8..92ba48f7b007370383368a8c00752d0b64c172b7 100644
--- a/programs/winhelp/Makefile.in
+++ b/programs/winhelp/Makefile.in
@@ -5,7 +5,7 @@ SRCDIR    = @srcdir@
 VPATH     = @srcdir@
 MODULE    = none
 PROGRAMS  = winhelp hlp2sgml
-ALL_LIBS  = $(WINELIB) $(X_LIBS) $(XPM_LIB) $(XLIB) $(LIBS)
+ALL_LIBS  = $(WINELIB) $(X_LIBS) $(XLIB) $(LIBS)
 RCFLAGS   = -w32 -h
 WRCEXTRA  = -A -p $*
 
diff --git a/programs/winver/Makefile.in b/programs/winver/Makefile.in
index 60820046a7c79024d25b754465a4d08da3092d20..7891cd97da713f620aece708d6271763ddb47ff8 100644
--- a/programs/winver/Makefile.in
+++ b/programs/winver/Makefile.in
@@ -5,7 +5,7 @@ SRCDIR    = @srcdir@
 VPATH     = @srcdir@
 MODULE    = none
 PROGRAMS  = winver
-ALL_LIBS  = $(WINELIB) $(X_LIBS) $(XPM_LIB) $(XLIB) $(LIBS)
+ALL_LIBS  = $(WINELIB) $(X_LIBS) $(XLIB) $(LIBS)
 RCFLAGS   = -w32 -h
 WRCEXTRA  = -A -p $*
 
diff --git a/windows/win.c b/windows/win.c
index 62280d9c6568276c9b1c7778e521b47f8af06938..bacc1d1efc2fcdf2153a82b9867149cdb92ea539 100644
--- a/windows/win.c
+++ b/windows/win.c
@@ -6,8 +6,6 @@
 
 #include <stdlib.h>
 #include <string.h>
-#include <X11/Xatom.h>
-
 #include "options.h"
 #include "class.h"
 #include "win.h"
@@ -439,6 +437,7 @@ BOOL32 WIN_CreateDesktopWindow(void)
     pWndDesktop->window            = rootWindow;
     pWndDesktop->hSysMenu          = 0;
     pWndDesktop->userdata          = 0;
+    pWndDesktop->pDriver           = &X11DRV_WND_Driver;
 
     pWndDesktop->winproc = (WNDPROC16)class->winproc;
 
@@ -555,6 +554,7 @@ static HWND32 WIN_CreateWindowEx( CREATESTRUCT32A *cs, ATOM classAtom,
             wndPtr->owner = WIN_GetTopParentPtr(WIN_FindWndPtr(cs->hwndParent));
     }
 
+    wndPtr->pDriver        = &X11DRV_WND_Driver;
     wndPtr->window         = 0;
     wndPtr->class          = classPtr;
     wndPtr->winproc        = classPtr->winproc;
@@ -647,65 +647,7 @@ static HWND32 WIN_CreateWindowEx( CREATESTRUCT32A *cs, ATOM classAtom,
     wndPtr->rectWindow.bottom = cs->y + cs->cy;
     wndPtr->rectClient        = wndPtr->rectWindow;
 
-    /* Create the X window (only for top-level windows, and then only */
-    /* when there's no desktop window) */
-
-    if (!(cs->style & WS_CHILD) && (rootWindow == DefaultRootWindow(display)))
-    {
-        XSetWindowAttributes win_attr;
-
-	if (Options.managed && ((cs->style & (WS_DLGFRAME | WS_THICKFRAME)) ||
-            (cs->dwExStyle & WS_EX_DLGMODALFRAME)))
-        {
-	    win_attr.event_mask = ExposureMask | KeyPressMask |
-	                          KeyReleaseMask | PointerMotionMask |
-	                          ButtonPressMask | ButtonReleaseMask |
-	                          FocusChangeMask | StructureNotifyMask;
-	    win_attr.override_redirect = FALSE;
-            wndPtr->flags |= WIN_MANAGED;
-	}
-	else
-        {
-	    win_attr.event_mask = ExposureMask | KeyPressMask |
-	                          KeyReleaseMask | PointerMotionMask |
-	                          ButtonPressMask | ButtonReleaseMask |
-	                          FocusChangeMask;
-            win_attr.override_redirect = TRUE;
-	}
-        win_attr.colormap      = COLOR_GetColormap();
-        win_attr.backing_store = Options.backingstore ? WhenMapped : NotUseful;
-        win_attr.save_under    = ((classPtr->style & CS_SAVEBITS) != 0);
-        win_attr.cursor        = CURSORICON_XCursor;
-        wndPtr->window = TSXCreateWindow( display, rootWindow, cs->x, cs->y,
-                                        cs->cx, cs->cy, 0, CopyFromParent,
-                                        InputOutput, CopyFromParent,
-                                        CWEventMask | CWOverrideRedirect |
-                                        CWColormap | CWCursor | CWSaveUnder |
-                                        CWBackingStore, &win_attr );
-
-        if ((wndPtr->flags & WIN_MANAGED) &&
-            (cs->dwExStyle & WS_EX_DLGMODALFRAME))
-        {
-            XSizeHints* size_hints = TSXAllocSizeHints();
-
-            if (size_hints)
-            {
-                size_hints->min_width = size_hints->max_width = cs->cx;
-                size_hints->min_height = size_hints->max_height = cs->cy;
-                size_hints->flags = (PSize | PMinSize | PMaxSize);
-                TSXSetWMSizeHints( display, wndPtr->window, size_hints,
-                                 XA_WM_NORMAL_HINTS );
-                TSXFree(size_hints);
-            }
-        }
-
-	if (cs->hwndParent)  /* Get window owner */
-	{
-            Window win = WIN_GetXWindow( cs->hwndParent );
-            if (win) TSXSetTransientForHint( display, wndPtr->window, win );
-	}
-        EVENT_RegisterWindow( wndPtr );
-    }
+    (*wndPtr->pDriver->pCreateWindow)(wndPtr, classPtr, cs, unicode);
 
     /* Set the window menu */
 
@@ -1070,10 +1012,12 @@ BOOL32 WINAPI DestroyWindow32( HWND32 hwnd )
         while (siblingPtr)
         {
             if (siblingPtr->owner == wndPtr)
+	    {
                if (siblingPtr->hmemTaskQ == wndPtr->hmemTaskQ)
                    break;
                else 
                    siblingPtr->owner = NULL;
+	    }
             siblingPtr = siblingPtr->next;
         }
         if (siblingPtr) DestroyWindow32( siblingPtr->hwndSelf );
@@ -1956,49 +1900,15 @@ HWND16 WINAPI SetParent16( HWND16 hwndChild, HWND16 hwndNewParent )
  */
 HWND32 WINAPI SetParent32( HWND32 hwndChild, HWND32 hwndNewParent )
 {
-    WND *wndPtr = WIN_FindWndPtr( hwndChild );
-    WND *pWndParent = (hwndNewParent) ? WIN_FindWndPtr( hwndNewParent )
-				      : pWndDesktop;
+  WND *wndPtr = WIN_FindWndPtr( hwndChild );
+  WND *pWndNewParent = 
+    (hwndNewParent) ? WIN_FindWndPtr( hwndNewParent ) : pWndDesktop;
+  WND *pWndOldParent =
+    (*wndPtr->pDriver->pSetParent)(wndPtr, pWndNewParent);
 
-    if( wndPtr && pWndParent && (wndPtr != pWndDesktop) )
-    {
-	WND* pWndPrev = wndPtr->parent;
-
-	if( pWndParent != pWndPrev )
-	{
-	    BOOL32 bFixupDCE = IsWindowVisible32(hwndChild);
-
-	    if ( wndPtr->window )
-	    {
-		/* Toplevel window needs to be reparented.  Used by Tk 8.0 */
-
-		TSXDestroyWindow( display, wndPtr->window );
-		wndPtr->window = None;
-	    }
-	    else if( bFixupDCE )
-		DCE_InvalidateDCE( wndPtr, &wndPtr->rectWindow );
-
-	    WIN_UnlinkWindow(hwndChild);
-	    wndPtr->parent = pWndParent;
-
-	    /* FIXME: Create an X counterpart for reparented top-level windows
-	     * when not in the desktop mode. */
-     
-	    if ( pWndParent != pWndDesktop ) wndPtr->dwStyle |= WS_CHILD;
-	    WIN_LinkWindow(hwndChild, HWND_BOTTOM);
-
-	    if( bFixupDCE )
-	    {
-	        DCE_InvalidateDCE( wndPtr, &wndPtr->rectWindow );
-		UpdateWindow32(hwndChild);
-	    }
-	}
-	return pWndPrev->hwndSelf;
-    } /* failure */
-    return 0;
+  return pWndOldParent?pWndOldParent->hwndSelf:0;
 }
 
-
 /*******************************************************************
  *         IsChild16    (USER.48)
  */
diff --git a/windows/x11drv/.cvsignore b/windows/x11drv/.cvsignore
new file mode 100644
index 0000000000000000000000000000000000000000..f3c7a7c5da68804a1bdf391127ba34aed33c3cca
--- /dev/null
+++ b/windows/x11drv/.cvsignore
@@ -0,0 +1 @@
+Makefile
diff --git a/windows/x11drv/Makefile.in b/windows/x11drv/Makefile.in
new file mode 100644
index 0000000000000000000000000000000000000000..89eb67b3aeabae0683a950968be9bfb027054cdf
--- /dev/null
+++ b/windows/x11drv/Makefile.in
@@ -0,0 +1,15 @@
+DEFS      = @DLLFLAGS@ -D__WINE__
+TOPSRCDIR = @top_srcdir@
+TOPOBJDIR = ../..
+SRCDIR    = @srcdir@
+VPATH     = @srcdir@
+MODULE    = x11drv
+
+C_SRCS = \
+	init.c
+
+all: $(MODULE).o
+
+@MAKE_RULES@
+
+### Dependencies:
diff --git a/windows/x11drv/init.c b/windows/x11drv/init.c
new file mode 100644
index 0000000000000000000000000000000000000000..8ca6b38acef1b3d6b2c184d050b683dcb0a091d1
--- /dev/null
+++ b/windows/x11drv/init.c
@@ -0,0 +1,137 @@
+/*
+ * X11 windows driver
+ *
+ * Copyright 1993, 1994 Alexandre Julliard
+ * Copyright 1998 Patrik Stridvall
+ */
+
+#include <string.h>
+#include <X11/Xatom.h>
+#include "ts_xlib.h"
+#include "color.h"
+#include "cursoricon.h"
+#include "dce.h"
+#include "options.h"
+#include "message.h"
+#include "win.h"
+#include "windows.h"
+#include "x11drv.h"
+
+static BOOL32 X11DRV_WND_CreateWindow(WND *wndPtr, CLASS *classPtr, CREATESTRUCT32A *cs, BOOL32 bUnicode);
+static WND *X11DRV_WND_SetParent(WND *wndPtr, WND *pWndParent);
+
+WND_DRIVER X11DRV_WND_Driver =
+{
+    X11DRV_WND_CreateWindow,
+    X11DRV_WND_SetParent
+};
+
+/**********************************************************************
+ *		X11DRV_WND_CreateWindow	[Internal]
+ */
+static BOOL32 X11DRV_WND_CreateWindow(WND *wndPtr, CLASS *classPtr, CREATESTRUCT32A *cs, BOOL32 bUnicode)
+{
+  /* Create the X window (only for top-level windows, and then only */
+  /* when there's no desktop window) */
+  
+  if (!(cs->style & WS_CHILD) && (rootWindow == DefaultRootWindow(display)))
+    {
+      XSetWindowAttributes win_attr;
+      
+      if (Options.managed && ((cs->style & (WS_DLGFRAME | WS_THICKFRAME)) ||
+			      (cs->dwExStyle & WS_EX_DLGMODALFRAME)))
+        {
+	  win_attr.event_mask = ExposureMask | KeyPressMask |
+	    KeyReleaseMask | PointerMotionMask |
+	    ButtonPressMask | ButtonReleaseMask |
+	    FocusChangeMask | StructureNotifyMask;
+	  win_attr.override_redirect = FALSE;
+	  wndPtr->flags |= WIN_MANAGED;
+	}
+      else
+        {
+	  win_attr.event_mask = ExposureMask | KeyPressMask |
+	    KeyReleaseMask | PointerMotionMask |
+	    ButtonPressMask | ButtonReleaseMask |
+	    FocusChangeMask;
+	  win_attr.override_redirect = TRUE;
+	}
+      win_attr.colormap      = COLOR_GetColormap();
+      win_attr.backing_store = Options.backingstore ? WhenMapped : NotUseful;
+      win_attr.save_under    = ((classPtr->style & CS_SAVEBITS) != 0);
+      win_attr.cursor        = CURSORICON_XCursor;
+      wndPtr->window = TSXCreateWindow( display, rootWindow, cs->x, cs->y,
+                                        cs->cx, cs->cy, 0, CopyFromParent,
+                                        InputOutput, CopyFromParent,
+                                        CWEventMask | CWOverrideRedirect |
+                                        CWColormap | CWCursor | CWSaveUnder |
+                                        CWBackingStore, &win_attr );
+
+      if ((wndPtr->flags & WIN_MANAGED) &&
+	  (cs->dwExStyle & WS_EX_DLGMODALFRAME))
+        {
+	  XSizeHints* size_hints = TSXAllocSizeHints();
+	  
+	  if (size_hints)
+            {
+	      size_hints->min_width = size_hints->max_width = cs->cx;
+	      size_hints->min_height = size_hints->max_height = cs->cy;
+                size_hints->flags = (PSize | PMinSize | PMaxSize);
+                TSXSetWMSizeHints( display, wndPtr->window, size_hints,
+				   XA_WM_NORMAL_HINTS );
+                TSXFree(size_hints);
+            }
+        }
+      
+      if (cs->hwndParent)  /* Get window owner */
+	{
+	  Window win = WIN_GetXWindow( cs->hwndParent );
+	  if (win) TSXSetTransientForHint( display, wndPtr->window, win );
+	}
+      EVENT_RegisterWindow( wndPtr );
+    }
+  return TRUE;
+}
+
+/*****************************************************************
+ *		X11DRV_WND_SetParent	[Internal]
+ */
+static WND *X11DRV_WND_SetParent(WND *wndPtr, WND *pWndParent)
+{
+    if( wndPtr && pWndParent && (wndPtr != WIN_GetDesktop()) )
+    {
+	WND* pWndPrev = wndPtr->parent;
+
+	if( pWndParent != pWndPrev )
+	{
+	    BOOL32 bFixupDCE = IsWindowVisible32(wndPtr->hwndSelf);
+
+	    if ( wndPtr->window )
+	    {
+		/* Toplevel window needs to be reparented.  Used by Tk 8.0 */
+
+		TSXDestroyWindow( display, wndPtr->window );
+		wndPtr->window = None;
+	    }
+	    else if( bFixupDCE )
+		DCE_InvalidateDCE( wndPtr, &wndPtr->rectWindow );
+
+	    WIN_UnlinkWindow(wndPtr->hwndSelf);
+	    wndPtr->parent = pWndParent;
+
+	    /* FIXME: Create an X counterpart for reparented top-level windows
+	     * when not in the desktop mode. */
+     
+	    if ( pWndParent != WIN_GetDesktop() ) wndPtr->dwStyle |= WS_CHILD;
+	    WIN_LinkWindow(wndPtr->hwndSelf, HWND_BOTTOM);
+
+	    if( bFixupDCE )
+	    {
+	        DCE_InvalidateDCE( wndPtr, &wndPtr->rectWindow );
+		UpdateWindow32(wndPtr->hwndSelf);
+	    }
+	}
+	return pWndPrev;
+    } /* failure */
+    return 0;
+}