Remove X_DC_INFO from DC and make it behave like any other PDEVICE.

diff --git a/graphics/ddraw.c b/graphics/ddraw.c
index 6e3056f..bd5ecf2 100644
--- a/graphics/ddraw.c
+++ b/graphics/ddraw.c
@@ -19,6 +19,7 @@
 #include "ts_xlib.h"
 #include <sys/signal.h>
 #include <fcntl.h>
+#include <string.h>
 
 #include "windows.h"
 #include "winerror.h"
@@ -35,6 +36,7 @@
 #include "compobj.h"
 #include "spy.h"
 #include "message.h"
+#include "x11drv.h"
 
 #ifdef HAVE_LIBXXF86DGA
 #include "ts_xf86dga.h"
diff --git a/graphics/painting.c b/graphics/painting.c
index abb8f8c..69dc22c 100644
--- a/graphics/painting.c
+++ b/graphics/painting.c
@@ -25,6 +25,7 @@
 #include "path.h"
 #include "debug.h"
 #include "winerror.h"
+#include "x11drv.h"
 
 /***********************************************************************
  *           LineTo16    (GDI.19)
@@ -623,9 +624,11 @@
     HPEN32 hOldPen, hnewPen;
     INT32 oldDrawMode, oldBkMode;
     INT32 left, top, right, bottom;
+    X11DRV_PDEVICE *physDev;
 
     DC * dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC );
     if (!dc) return;
+    physDev = (X11DRV_PDEVICE *)dc->physDev;
 
     left   = XLPTODP( dc, rc->left );
     top    = YLPTODP( dc, rc->top );
@@ -641,10 +644,10 @@
     oldBkMode = SetBkMode32(hdc, TRANSPARENT);
 
     /* Hack: make sure the XORPEN operation has an effect */
-    dc->u.x.pen.pixel = (1 << screenDepth) - 1;
+    physDev->pen.pixel = (1 << screenDepth) - 1;
 
     if (X11DRV_SetupGCForPen( dc ))
-	TSXDrawRectangle( display, dc->u.x.drawable, dc->u.x.gc,
+	TSXDrawRectangle( display, physDev->drawable, physDev->gc,
 		        dc->w.DCOrgX + left, dc->w.DCOrgY + top,
 		        right-left-1, bottom-top-1 );
 
diff --git a/graphics/wing.c b/graphics/wing.c
index 3654cad..52c9288 100644
--- a/graphics/wing.c
+++ b/graphics/wing.c
@@ -17,6 +17,7 @@
 #include "dc.h"
 #include "gdi.h"
 #include "xmalloc.h"
+#include "x11drv.h"
 #include "debug.h"
 
 typedef enum WING_DITHER_TYPE
@@ -262,9 +263,12 @@
     /* destDC is a display DC, srcDC is a memory DC */
 
     DC *dcDst, *dcSrc;
+    X11DRV_PDEVICE *physDevDst, *physDevSrc;
 
     if (!(dcDst = (DC *)GDI_GetObjPtr( destDC, DC_MAGIC ))) return FALSE;
     if (!(dcSrc = (DC *) GDI_GetObjPtr( srcDC, DC_MAGIC ))) return FALSE;
+    physDevDst = (X11DRV_PDEVICE *)dcDst->physDev;
+    physDevSrc = (X11DRV_PDEVICE *)dcSrc->physDev;
 
     if (dcDst->w.flags & DC_DIRTY) CLIPPING_UpdateGCRegion( dcDst );
 
@@ -275,10 +279,10 @@
     widDest = widDest * dcDst->vportExtX / dcDst->wndExtX;
     heiDest = heiDest * dcDst->vportExtY / dcDst->wndExtY;
 
-    TSXSetFunction( display, dcDst->u.x.gc, GXcopy );
-    TSXCopyArea( display, dcSrc->u.x.drawable,
-               dcDst->u.x.drawable, dcDst->u.x.gc,
-               xSrc, ySrc, widDest, heiDest, xDest, yDest );
+    TSXSetFunction( display, physDevDst->gc, GXcopy );
+    TSXCopyArea( display, physDevSrc->drawable,
+		 physDevDst->drawable, physDevDst->gc,
+		 xSrc, ySrc, widDest, heiDest, xDest, yDest );
     return TRUE;
 }
 
diff --git a/graphics/x11drv/bitblt.c b/graphics/x11drv/bitblt.c
index 80e5243..7d43a65 100644
--- a/graphics/x11drv/bitblt.c
+++ b/graphics/x11drv/bitblt.c
@@ -816,6 +816,8 @@
                                       RECT32 *visRectSrc, RECT32 *visRectDst )
 {
     XImage *imageSrc, *imageDst;
+    X11DRV_PDEVICE *physDevSrc = (X11DRV_PDEVICE *)dcSrc->physDev;
+    X11DRV_PDEVICE *physDevDst = (X11DRV_PDEVICE *)dcDst->physDev;
 
     RECT32 rectSrc = *visRectSrc;
     RECT32 rectDst = *visRectDst;
@@ -828,7 +830,7 @@
     OffsetRect32( &rectDst, -xDst, -yDst );
 
     /* FIXME: avoid BadMatch errors */
-    imageSrc = XGetImage( display, dcSrc->u.x.drawable,
+    imageSrc = XGetImage( display, physDevSrc->drawable,
                           visRectSrc->left, visRectSrc->top,
                           visRectSrc->right - visRectSrc->left,
                           visRectSrc->bottom - visRectSrc->top,
@@ -837,9 +839,9 @@
                   rectDst.bottom - rectDst.top, dcDst->w.bitsPerPixel );
     BITBLT_StretchImage( imageSrc, imageDst, widthSrc, heightSrc,
                          widthDst, heightDst, &rectSrc, &rectDst,
-                         dcDst->u.x.textPixel, dcDst->w.bitsPerPixel != 1 ?
-                         dcDst->u.x.backgroundPixel :
-			 dcSrc->u.x.backgroundPixel,
+                         physDevDst->textPixel, dcDst->w.bitsPerPixel != 1 ?
+                         physDevDst->backgroundPixel :
+			 physDevSrc->backgroundPixel,
                          dcDst->w.stretchBltMode );
     XPutImage( display, pixmap, gc, imageDst, 0, 0, 0, 0,
                rectDst.right - rectDst.left, rectDst.bottom - rectDst.top );
@@ -861,25 +863,27 @@
     register INT32 x, y;
     INT32 width  = visRectSrc->right - visRectSrc->left;
     INT32 height = visRectSrc->bottom - visRectSrc->top;
+    X11DRV_PDEVICE *physDevSrc = (X11DRV_PDEVICE *)dcSrc->physDev;
+    X11DRV_PDEVICE *physDevDst = (X11DRV_PDEVICE *)dcDst->physDev;
 
     if (dcSrc->w.bitsPerPixel == dcDst->w.bitsPerPixel)
     {
         if (!COLOR_PixelToPalette ||
             (dcDst->w.bitsPerPixel == 1))  /* monochrome -> monochrome */
         {
-            XCopyArea( display, dcSrc->u.x.drawable, pixmap, gc,
+            XCopyArea( display, physDevSrc->drawable, pixmap, gc,
                        visRectSrc->left, visRectSrc->top, width, height, 0, 0);
         }
         else  /* color -> color */
         {
             if (dcSrc->w.flags & DC_MEMORY)
-                imageSrc = XGetImage( display, dcSrc->u.x.drawable,
+                imageSrc = XGetImage( display, physDevSrc->drawable,
                                       visRectSrc->left, visRectSrc->top,
                                       width, height, AllPlanes, ZPixmap );
             else
             {
                 /* Make sure we don't get a BadMatch error */
-                XCopyArea( display, dcSrc->u.x.drawable, pixmap, gc,
+                XCopyArea( display, physDevSrc->drawable, pixmap, gc,
                            visRectSrc->left, visRectSrc->top,
                            width, height, 0, 0);
                 imageSrc = XGetImage( display, pixmap, 0, 0, width, height,
@@ -901,30 +905,30 @@
             if (COLOR_PixelToPalette)
             {
                 XSetBackground( display, gc, 
-                             COLOR_PixelToPalette[dcDst->u.x.textPixel] );
+                             COLOR_PixelToPalette[physDevDst->textPixel] );
                 XSetForeground( display, gc,
-                             COLOR_PixelToPalette[dcDst->u.x.backgroundPixel]);
+                             COLOR_PixelToPalette[physDevDst->backgroundPixel]);
             }
             else
             {
-                XSetBackground( display, gc, dcDst->u.x.textPixel );
-                XSetForeground( display, gc, dcDst->u.x.backgroundPixel );
+                XSetBackground( display, gc, physDevDst->textPixel );
+                XSetForeground( display, gc, physDevDst->backgroundPixel );
             }
-            XCopyPlane( display, dcSrc->u.x.drawable, pixmap, gc,
+            XCopyPlane( display, physDevSrc->drawable, pixmap, gc,
                         visRectSrc->left, visRectSrc->top,
                         width, height, 0, 0, 1 );
         }
         else  /* color -> monochrome */
         {
             /* FIXME: avoid BadMatch error */
-            imageSrc = XGetImage( display, dcSrc->u.x.drawable,
+            imageSrc = XGetImage( display, physDevSrc->drawable,
                                   visRectSrc->left, visRectSrc->top,
                                   width, height, AllPlanes, ZPixmap );
             XCREATEIMAGE( imageDst, width, height, dcDst->w.bitsPerPixel );
             for (y = 0; y < height; y++)
                 for (x = 0; x < width; x++)
                     XPutPixel(imageDst, x, y, (XGetPixel(imageSrc,x,y) ==
-                                               dcSrc->u.x.backgroundPixel) );
+                                               physDevSrc->backgroundPixel) );
             XPutImage( display, pixmap, gc, imageDst,
                        0, 0, 0, 0, width, height );
             XDestroyImage( imageSrc );
@@ -944,11 +948,12 @@
 {
     INT32 width  = visRectDst->right - visRectDst->left;
     INT32 height = visRectDst->bottom - visRectDst->top;
+    X11DRV_PDEVICE *physDev = (X11DRV_PDEVICE *)dc->physDev;
 
     if (!COLOR_PixelToPalette || (dc->w.bitsPerPixel == 1) ||
 	(COLOR_GetSystemPaletteFlags() & COLOR_VIRTUAL) )
     {
-        XCopyArea( display, dc->u.x.drawable, pixmap, gc,
+        XCopyArea( display, physDev->drawable, pixmap, gc,
                    visRectDst->left, visRectDst->top, width, height, 0, 0 );
     }
     else
@@ -957,13 +962,13 @@
         XImage *image;
 
         if (dc->w.flags & DC_MEMORY)
-            image = XGetImage( display, dc->u.x.drawable,
+            image = XGetImage( display, physDev->drawable,
                                visRectDst->left, visRectDst->top,
                                width, height, AllPlanes, ZPixmap );
         else
         {
             /* Make sure we don't get a BadMatch error */
-            XCopyArea( display, dc->u.x.drawable, pixmap, gc,
+            XCopyArea( display, physDev->drawable, pixmap, gc,
                        visRectDst->left, visRectDst->top, width, height, 0, 0);
             image = XGetImage( display, pixmap, 0, 0, width, height,
                                AllPlanes, ZPixmap );
@@ -988,13 +993,14 @@
 {
     INT32 width  = visRectDst->right - visRectDst->left;
     INT32 height = visRectDst->bottom - visRectDst->top;
+    X11DRV_PDEVICE *physDev = (X11DRV_PDEVICE *)dc->physDev;
 
     /* !COLOR_PaletteToPixel is _NOT_ enough */
 
     if (!COLOR_PaletteToPixel || (dc->w.bitsPerPixel == 1) || 
         (COLOR_GetSystemPaletteFlags() & COLOR_VIRTUAL) )
     {
-        XCopyArea( display, pixmap, dc->u.x.drawable, gc, 0, 0,
+        XCopyArea( display, pixmap, physDev->drawable, gc, 0, 0,
                    width, height, visRectDst->left, visRectDst->top );
     }
     else
@@ -1008,7 +1014,7 @@
                 XPutPixel( image, x, y,
                            COLOR_PaletteToPixel[XGetPixel( image, x, y )]);
             }
-        XPutImage( display, dc->u.x.drawable, gc, image, 0, 0,
+        XPutImage( display, physDev->drawable, gc, image, 0, 0,
                    visRectDst->left, visRectDst->top, width, height );
         XDestroyImage( image );
     }
@@ -1101,7 +1107,10 @@
     const BYTE *opcode;
     Pixmap pixmaps[3] = { 0, 0, 0 };  /* pixmaps for DST, SRC, TMP */
     GC tmpGC = 0;
+    X11DRV_PDEVICE *physDevSrc = NULL;
+    X11DRV_PDEVICE *physDevDst = (X11DRV_PDEVICE *)dcDst->physDev;
 
+    if(dcSrc) physDevSrc = (X11DRV_PDEVICE *)dcSrc->physDev;
     usePat = (((rop >> 4) & 0x0f0000) != (rop & 0x0f0000));
     useSrc = (((rop >> 2) & 0x330000) != (rop & 0x330000));
     useDst = (((rop >> 1) & 0x550000) != (rop & 0x550000));
@@ -1169,14 +1178,14 @@
     {
     case BLACKNESS:  /* 0x00 */
         if ((dcDst->w.bitsPerPixel == 1) || !COLOR_PaletteToPixel)
-            XSetFunction( display, dcDst->u.x.gc, GXclear );
+            XSetFunction( display, physDevDst->gc, GXclear );
         else
         {
-            XSetFunction( display, dcDst->u.x.gc, GXcopy );
-            XSetForeground( display, dcDst->u.x.gc, COLOR_PaletteToPixel[0] );
-            XSetFillStyle( display, dcDst->u.x.gc, FillSolid );
+            XSetFunction( display, physDevDst->gc, GXcopy );
+            XSetForeground( display, physDevDst->gc, COLOR_PaletteToPixel[0] );
+            XSetFillStyle( display, physDevDst->gc, FillSolid );
         }
-        XFillRectangle( display, dcDst->u.x.drawable, dcDst->u.x.gc,
+        XFillRectangle( display, physDevDst->drawable, physDevDst->gc,
                         visRectDst.left, visRectDst.top, width, height );
         return TRUE;
 
@@ -1184,10 +1193,10 @@
         if ((dcDst->w.bitsPerPixel == 1) || !COLOR_PaletteToPixel ||
             !Options.perfectGraphics)
         {
-            XSetFunction( display, dcDst->u.x.gc, GXinvert );
+            XSetFunction( display, physDevDst->gc, GXinvert );
 
             if( COLOR_GetSystemPaletteFlags() & (COLOR_PRIVATE | COLOR_VIRTUAL) )
-                XSetFunction( display, dcDst->u.x.gc, GXinvert);
+                XSetFunction( display, physDevDst->gc, GXinvert);
             else
             {
                 /* Xor is much better when we do not have full colormap.   */
@@ -1195,11 +1204,11 @@
                 /* and white. */
                 Pixel xor_pix = (WhitePixelOfScreen(screen) ^
                                  BlackPixelOfScreen(screen));
-                XSetFunction( display, dcDst->u.x.gc, GXxor );
-                XSetForeground( display, dcDst->u.x.gc, xor_pix);
-                XSetFillStyle( display, dcDst->u.x.gc, FillSolid ); 
+                XSetFunction( display, physDevDst->gc, GXxor );
+                XSetForeground( display, physDevDst->gc, xor_pix);
+                XSetFillStyle( display, physDevDst->gc, FillSolid ); 
             }
-            XFillRectangle( display, dcDst->u.x.drawable, dcDst->u.x.gc,
+            XFillRectangle( display, physDevDst->drawable, physDevDst->gc,
                             visRectDst.left, visRectDst.top, width, height ); 
             return TRUE;
         }
@@ -1209,8 +1218,8 @@
 	if (Options.perfectGraphics) break;
         if (X11DRV_SetupGCForBrush( dcDst ))
         {
-            XSetFunction( display, dcDst->u.x.gc, GXxor );
-            XFillRectangle( display, dcDst->u.x.drawable, dcDst->u.x.gc,
+            XSetFunction( display, physDevDst->gc, GXxor );
+            XFillRectangle( display, physDevDst->drawable, physDevDst->gc,
 			    visRectDst.left, visRectDst.top, width, height );
         }
         return TRUE;
@@ -1219,8 +1228,8 @@
 	if (Options.perfectGraphics) break;
 	if (X11DRV_SetupGCForBrush( dcDst ))
 	{
-	    XSetFunction( display, dcDst->u.x.gc, GXequiv );
-	    XFillRectangle( display, dcDst->u.x.drawable, dcDst->u.x.gc,
+	    XSetFunction( display, physDevDst->gc, GXequiv );
+	    XFillRectangle( display, physDevDst->drawable, physDevDst->gc,
 			    visRectDst.left, visRectDst.top, width, height );
 	}
 	return TRUE;
@@ -1228,53 +1237,54 @@
     case SRCCOPY:  /* 0xcc */
         if (dcSrc->w.bitsPerPixel == dcDst->w.bitsPerPixel)
         {
-            XSetGraphicsExposures( display, dcDst->u.x.gc, True );
-            XSetFunction( display, dcDst->u.x.gc, GXcopy );
-	    XCopyArea( display, dcSrc->u.x.drawable,
-                       dcDst->u.x.drawable, dcDst->u.x.gc,
+            XSetGraphicsExposures( display, physDevDst->gc, True );
+            XSetFunction( display, physDevDst->gc, GXcopy );
+	    XCopyArea( display, physDevSrc->drawable,
+                       physDevDst->drawable, physDevDst->gc,
                        visRectSrc.left, visRectSrc.top,
                        width, height, visRectDst.left, visRectDst.top );
-            XSetGraphicsExposures( display, dcDst->u.x.gc, False );
+            XSetGraphicsExposures( display, physDevDst->gc, False );
             return TRUE;
         }
         if (dcSrc->w.bitsPerPixel == 1)
         {
-            XSetBackground( display, dcDst->u.x.gc, dcDst->u.x.textPixel );
-            XSetForeground( display, dcDst->u.x.gc, dcDst->u.x.backgroundPixel );
-            XSetFunction( display, dcDst->u.x.gc, GXcopy );
-            XSetGraphicsExposures( display, dcDst->u.x.gc, True );
-	    XCopyPlane( display, dcSrc->u.x.drawable,
-                        dcDst->u.x.drawable, dcDst->u.x.gc,
+            XSetBackground( display, physDevDst->gc, physDevDst->textPixel );
+            XSetForeground( display, physDevDst->gc, 
+			    physDevDst->backgroundPixel );
+            XSetFunction( display, physDevDst->gc, GXcopy );
+            XSetGraphicsExposures( display, physDevDst->gc, True );
+	    XCopyPlane( display, physDevSrc->drawable,
+                        physDevDst->drawable, physDevDst->gc,
                         visRectSrc.left, visRectSrc.top,
                         width, height, visRectDst.left, visRectDst.top, 1 );
-            XSetGraphicsExposures( display, dcDst->u.x.gc, False );
+            XSetGraphicsExposures( display, physDevDst->gc, False );
             return TRUE;
         }
         break;
 
     case PATCOPY:  /* 0xf0 */
         if (!X11DRV_SetupGCForBrush( dcDst )) return TRUE;
-        XSetFunction( display, dcDst->u.x.gc, GXcopy );
-        XFillRectangle( display, dcDst->u.x.drawable, dcDst->u.x.gc,
+        XSetFunction( display, physDevDst->gc, GXcopy );
+        XFillRectangle( display, physDevDst->drawable, physDevDst->gc,
                         visRectDst.left, visRectDst.top, width, height );
         return TRUE;
 
     case WHITENESS:  /* 0xff */
         if ((dcDst->w.bitsPerPixel == 1) || !COLOR_PaletteToPixel)
-            XSetFunction( display, dcDst->u.x.gc, GXset );
+            XSetFunction( display, physDevDst->gc, GXset );
         else
         {
-            XSetFunction( display, dcDst->u.x.gc, GXcopy );
-            XSetForeground( display, dcDst->u.x.gc, 
+            XSetFunction( display, physDevDst->gc, GXcopy );
+            XSetForeground( display, physDevDst->gc, 
                             COLOR_PaletteToPixel[COLOR_GetSystemPaletteSize() - 1]);
-            XSetFillStyle( display, dcDst->u.x.gc, FillSolid );
+            XSetFillStyle( display, physDevDst->gc, FillSolid );
         }
-        XFillRectangle( display, dcDst->u.x.drawable, dcDst->u.x.gc,
+        XFillRectangle( display, physDevDst->drawable, physDevDst->gc,
                         visRectDst.left, visRectDst.top, width, height );
         return TRUE;
     }
 
-    tmpGC = XCreateGC( display, dcDst->u.x.drawable, 0, NULL );
+    tmpGC = XCreateGC( display, physDevDst->drawable, 0, NULL );
     pixmaps[DST] = XCreatePixmap( display, rootWindow, width, height,
                                   dcDst->w.bitsPerPixel );
     if (useSrc)
@@ -1331,9 +1341,9 @@
             break;
         }
     }
-    XSetFunction( display, dcDst->u.x.gc, GXcopy );
+    XSetFunction( display, physDevDst->gc, GXcopy );
     BITBLT_PutDstArea( dcDst, pixmaps[destUsed ? DST : SRC],
-                       dcDst->u.x.gc, &visRectDst );
+                       physDevDst->gc, &visRectDst );
     XFreePixmap( display, pixmaps[DST] );
     if (pixmaps[SRC]) XFreePixmap( display, pixmaps[SRC] );
     if (pixmaps[TMP]) XFreePixmap( display, pixmaps[TMP] );
diff --git a/graphics/x11drv/bitmap.c b/graphics/x11drv/bitmap.c
index 8ea1f26..a9f7338 100644
--- a/graphics/x11drv/bitmap.c
+++ b/graphics/x11drv/bitmap.c
@@ -58,6 +58,8 @@
     HRGN32 hrgn;
     HBITMAP32 prevHandle = dc->w.hBitmap;
     X11DRV_PHYSBITMAP *pbitmap;
+    X11DRV_PDEVICE *physDev = (X11DRV_PDEVICE *)dc->physDev;
+
 
     if (!(dc->w.flags & DC_MEMORY)) return 0;
 
@@ -66,7 +68,7 @@
 	    return 0;
 
     if(bmp->DDBitmap->funcs != dc->funcs) {
-        WARN(bitmap, "Trying to select non-X11 DDB into an X11 dc\n");
+        WARN(x11drv, "Trying to select non-X11 DDB into an X11 dc\n");
 	return 0;
     }
 
@@ -87,15 +89,15 @@
        dc->w.hVisRgn    = hrgn;
     }
 
-    dc->u.x.drawable = pbitmap->pixmap;
-    dc->w.hBitmap    = hbitmap;
+    physDev->drawable = pbitmap->pixmap;
+    dc->w.hBitmap     = hbitmap;
 
       /* Change GC depth if needed */
 
     if (dc->w.bitsPerPixel != bmp->bitmap.bmBitsPixel)
     {
-	TSXFreeGC( display, dc->u.x.gc );
-	dc->u.x.gc = TSXCreateGC( display, dc->u.x.drawable, 0, NULL );
+	TSXFreeGC( display, physDev->gc );
+	physDev->gc = TSXCreateGC( display, physDev->drawable, 0, NULL );
 	dc->w.bitsPerPixel = bmp->bitmap.bmBitsPixel;
         DC_InitDC( dc );
     }
@@ -139,19 +141,18 @@
     X11DRV_PHYSBITMAP *pbitmap;
 
     if(!(bmp->DDBitmap = HeapAlloc(GetProcessHeap(), 0, sizeof(DDBITMAP)))) {
-        WARN(bitmap, "Can't alloc DDBITMAP\n");
+        WARN(x11drv, "Can't alloc DDBITMAP\n");
 	return NULL;
     }
 
     if(!(pbitmap = HeapAlloc(GetProcessHeap(), 0,sizeof(X11DRV_PHYSBITMAP)))) {
-        WARN(bitmap, "Can't alloc X11DRV_PHYSBITMAP\n");
+        WARN(x11drv, "Can't alloc X11DRV_PHYSBITMAP\n");
         HeapFree(GetProcessHeap(), 0, bmp->DDBitmap);
 	return NULL;
     }
 
     bmp->DDBitmap->physBitmap = pbitmap;
     bmp->DDBitmap->funcs = DRIVER_FindDriver( "DISPLAY" );
-
     return pbitmap;
 }
 
@@ -172,7 +173,7 @@
     BITMAPOBJ *bmp = (BITMAPOBJ *) GDI_GetObjPtr( hbitmap, BITMAP_MAGIC );
 
     if(!bmp) {
-        WARN(bitmap, "Bad bitmap handle %08x\n", hbitmap);
+        WARN(x11drv, "Bad bitmap handle %08x\n", hbitmap);
 	return FALSE;
     }
 
@@ -180,6 +181,8 @@
     if (bmp->bitmap.bmPlanes != 1) return 0;
     if ((bmp->bitmap.bmBitsPixel != 1) && 
 	(bmp->bitmap.bmBitsPixel != screenDepth)) {
+        ERR(x11drv, "Trying to make bitmap with planes=%d, bpp=%d\n",
+	    bmp->bitmap.bmPlanes, bmp->bitmap.bmBitsPixel);
         GDI_HEAP_UNLOCK( hbitmap );
 	return FALSE;
     }
@@ -194,7 +197,7 @@
     pbitmap->pixmap = TSXCreatePixmap(display, rootWindow, bmp->bitmap.bmWidth,
 			      bmp->bitmap.bmHeight, bmp->bitmap.bmBitsPixel);
     if (!pbitmap->pixmap) {
-        WARN(bitmap, "Can't create Pixmap\n");
+        WARN(x11drv, "Can't create Pixmap\n");
         HeapFree(GetProcessHeap(), 0, bmp->DDBitmap->physBitmap);
         HeapFree(GetProcessHeap(), 0, bmp->DDBitmap);
 	GDI_HEAP_UNLOCK( hbitmap );
@@ -239,7 +242,7 @@
     LPBYTE tbuf;
     int	h, w, pad;
 
-    TRACE(x11drv, "(bmp=%p, buffer=%p, count=%lx)\n", bmp, buffer, count);
+    TRACE(x11drv, "(bmp=%p, buffer=%p, count=0x%lx)\n", bmp, buffer, count);
 
     pad = BITMAP_GetPadding(bmp->bitmap.bmWidth, bmp->bitmap.bmBitsPixel);
 
@@ -340,7 +343,7 @@
 	}
         break;
     default:
-        FIXME(bitmap, "Unhandled bits:%d\n", bmp->bitmap.bmBitsPixel);
+        FIXME(x11drv, "Unhandled bits:%d\n", bmp->bitmap.bmBitsPixel);
     }
     XDestroyImage( image );
     LeaveCriticalSection( &X11DRV_CritSection );
@@ -365,7 +368,7 @@
     LPBYTE sbuf;
     int	w, h, pad;
 
-    TRACE(x11drv, "(bmp=%p, bits=%p, count=%lx)\n", bmp, bits, count);
+    TRACE(x11drv, "(bmp=%p, bits=%p, count=0x%lx)\n", bmp, bits, count);
     
     pad = BITMAP_GetPadding(bmp->bitmap.bmWidth, bmp->bitmap.bmBitsPixel);
 
@@ -451,7 +454,7 @@
         }
         break;
     default:
-      FIXME(bitmap, "Unhandled bits:%d\n", bmp->bitmap.bmBitsPixel);
+      FIXME(x11drv, "Unhandled bits:%d\n", bmp->bitmap.bmBitsPixel);
 
     }
 
@@ -475,7 +478,7 @@
     BITMAPOBJ *bmp = (BITMAPOBJ *) GDI_GetObjPtr( hbitmap, BITMAP_MAGIC );
     LONG ret;
     if(!bmp) {
-        WARN(bitmap, "Bad bitmap handle %08x\n", hbitmap);
+        WARN(x11drv, "Bad bitmap handle %08x\n", hbitmap);
 	return FALSE;
     }
 
@@ -484,7 +487,7 @@
     else if(flags == DDB_SET)
         ret = X11DRV_SetBitmapBits(bmp, bits, count);
     else {
-        ERR(bitmap, "Unknown flags value %d\n", flags);
+        ERR(x11drv, "Unknown flags value %d\n", flags);
 	ret = 0;
     }
     
diff --git a/graphics/x11drv/brush.c b/graphics/x11drv/brush.c
index 1d25c91..379857e 100644
--- a/graphics/x11drv/brush.c
+++ b/graphics/x11drv/brush.c
@@ -1,5 +1,5 @@
 /*
- * GDI brush objects
+ * X11DRV brush objects
  *
  * Copyright 1993, 1994  Alexandre Julliard
  */
@@ -142,18 +142,20 @@
  */
 static void BRUSH_SelectSolidBrush( DC *dc, COLORREF color )
 {
+    X11DRV_PDEVICE *physDev = (X11DRV_PDEVICE *)dc->physDev;
+
     if ((dc->w.bitsPerPixel > 1) && (screenDepth <= 8) && !COLOR_IsSolid( color ))
     {
 	  /* Dithered brush */
-	dc->u.x.brush.pixmap = BRUSH_DitherColor( dc, color );
-	dc->u.x.brush.fillStyle = FillTiled;
-	dc->u.x.brush.pixel = 0;
+	physDev->brush.pixmap = BRUSH_DitherColor( dc, color );
+	physDev->brush.fillStyle = FillTiled;
+	physDev->brush.pixel = 0;
     }
     else
     {
 	  /* Solid brush */
-	dc->u.x.brush.pixel = COLOR_ToPhysical( dc, color );
-	dc->u.x.brush.fillStyle = FillSolid;
+	physDev->brush.pixel = COLOR_ToPhysical( dc, color );
+	physDev->brush.fillStyle = FillSolid;
     }
 }
 
@@ -164,6 +166,7 @@
 static BOOL32 BRUSH_SelectPatternBrush( DC * dc, HBITMAP32 hbitmap )
 {
     X11DRV_PHYSBITMAP *pbitmap;
+    X11DRV_PDEVICE *physDev = (X11DRV_PDEVICE *)dc->physDev;
     BITMAPOBJ * bmp = (BITMAPOBJ *) GDI_GetObjPtr( hbitmap, BITMAP_MAGIC );
     if (!bmp) return FALSE;
 
@@ -181,28 +184,28 @@
     if ((dc->w.bitsPerPixel == 1) && (bmp->bitmap.bmBitsPixel != 1))
     {
         /* Special case: a color pattern on a monochrome DC */
-        dc->u.x.brush.pixmap = TSXCreatePixmap( display, rootWindow, 8, 8, 1 );
+        physDev->brush.pixmap = TSXCreatePixmap( display, rootWindow, 8, 8, 1);
         /* FIXME: should probably convert to monochrome instead */
-        TSXCopyPlane( display, pbitmap->pixmap, dc->u.x.brush.pixmap,
+        TSXCopyPlane( display, pbitmap->pixmap, physDev->brush.pixmap,
                     BITMAP_monoGC, 0, 0, 8, 8, 0, 0, 1 );
     }
     else
     {
-        dc->u.x.brush.pixmap = TSXCreatePixmap( display, rootWindow,
-                                              8, 8, bmp->bitmap.bmBitsPixel );
-        TSXCopyArea( display, pbitmap->pixmap, dc->u.x.brush.pixmap,
+        physDev->brush.pixmap = TSXCreatePixmap( display, rootWindow,
+					       8, 8, bmp->bitmap.bmBitsPixel );
+        TSXCopyArea( display, pbitmap->pixmap, physDev->brush.pixmap,
                    BITMAP_GC(bmp), 0, 0, 8, 8, 0, 0 );
     }
     
     if (bmp->bitmap.bmBitsPixel > 1)
     {
-	dc->u.x.brush.fillStyle = FillTiled;
-	dc->u.x.brush.pixel = 0;  /* Ignored */
+	physDev->brush.fillStyle = FillTiled;
+	physDev->brush.pixel = 0;  /* Ignored */
     }
     else
     {
-	dc->u.x.brush.fillStyle = FillOpaqueStippled;
-	dc->u.x.brush.pixel = -1;  /* Special case (see DC_SetupGCForBrush) */
+	physDev->brush.fillStyle = FillOpaqueStippled;
+	physDev->brush.pixel = -1;  /* Special case (see DC_SetupGCForBrush) */
     }
     GDI_HEAP_UNLOCK( hbitmap );
     return TRUE;
@@ -219,38 +222,19 @@
     HBITMAP16 hBitmap;
     BITMAPINFO * bmpInfo;
     HBRUSH16 prevHandle = dc->w.hBrush;
-
+    X11DRV_PDEVICE *physDev = (X11DRV_PDEVICE *)dc->physDev;
+    
     TRACE(gdi, "hdc=%04x hbrush=%04x\n",
                 dc->hSelf,hbrush);
-#ifdef NOTDEF
-    if (dc->header.wMagic == METAFILE_DC_MAGIC)
-    {
-        LOGBRUSH16 logbrush = { brush->logbrush.lbStyle,
-                                brush->logbrush.lbColor,
-                                brush->logbrush.lbHatch };
-	switch (brush->logbrush.lbStyle)
-	{
-	case BS_SOLID:
-	case BS_HATCHED:
-	case BS_HOLLOW:
-	    if (!MF_CreateBrushIndirect( dc, hbrush, &logbrush )) return 0;
-	    break;
-	case BS_PATTERN:
-	case BS_DIBPATTERN:
-	    if (!MF_CreatePatternBrush( dc, hbrush, &logbrush )) return 0;
-	    break;
-	}
-	return 1;  /* FIXME? */
-    }
-#endif    
+
     dc->w.hBrush = hbrush;
 
-    if (dc->u.x.brush.pixmap)
+    if (physDev->brush.pixmap)
     {
-	TSXFreePixmap( display, dc->u.x.brush.pixmap );
-	dc->u.x.brush.pixmap = 0;
+	TSXFreePixmap( display, physDev->brush.pixmap );
+	physDev->brush.pixmap = 0;
     }
-    dc->u.x.brush.style = brush->logbrush.lbStyle;
+    physDev->brush.style = brush->logbrush.lbStyle;
     
     switch(brush->logbrush.lbStyle)
     {
@@ -265,10 +249,10 @@
 	
       case BS_HATCHED:
 	TRACE(gdi, "BS_HATCHED\n" );
-	dc->u.x.brush.pixel = COLOR_ToPhysical( dc, brush->logbrush.lbColor );
-	dc->u.x.brush.pixmap = TSXCreateBitmapFromData( display, rootWindow,
+	physDev->brush.pixel = COLOR_ToPhysical( dc, brush->logbrush.lbColor );
+	physDev->brush.pixmap = TSXCreateBitmapFromData( display, rootWindow,
 				 HatchBrushes[brush->logbrush.lbHatch], 8, 8 );
-	dc->u.x.brush.fillStyle = FillStippled;
+	physDev->brush.fillStyle = FillStippled;
 	break;
 	
       case BS_PATTERN:
diff --git a/graphics/x11drv/clipping.c b/graphics/x11drv/clipping.c
index 60f9319..8af6eaf 100644
--- a/graphics/x11drv/clipping.c
+++ b/graphics/x11drv/clipping.c
@@ -21,12 +21,13 @@
 void X11DRV_SetDeviceClipping( DC * dc )
 {
     XRectangle *pXrect;
+    X11DRV_PDEVICE *physDev = (X11DRV_PDEVICE *)dc->physDev;
+    
     RGNOBJ *obj = (RGNOBJ *) GDI_GetObjPtr(dc->w.hGCClipRgn, REGION_MAGIC);
     if (!obj)
     {
         ERR(x11drv, "Rgn is 0. Please report this.\n");
 	return;
-        /*exit(1);*/
     }
     
     if (obj->rgn->numRects > 0)
@@ -54,7 +55,7 @@
     else
         pXrect = NULL;
 
-    TSXSetClipRectangles( display, dc->u.x.gc, 0, 0,
+    TSXSetClipRectangles( display, physDev->gc, 0, 0,
                           pXrect, obj->rgn->numRects, YXBanded );
 
     if(pXrect)
diff --git a/graphics/x11drv/dib.c b/graphics/x11drv/dib.c
index 848bc9c..fdaeb5f 100644
--- a/graphics/x11drv/dib.c
+++ b/graphics/x11drv/dib.c
@@ -1098,6 +1098,7 @@
     DWORD width, oldcy = cy;
     INT32 result;
     int height, tmpheight;
+    X11DRV_PDEVICE *physDev = (X11DRV_PDEVICE *)dc->physDev;
 
 
     if (DIB_GetBitmapInfo( &info->bmiHeader, &width, &height, 
@@ -1115,7 +1116,7 @@
     if (!cx || !cy) return 0;
 
     X11DRV_SetupGCForText( dc );  /* To have the correct colors */
-    TSXSetFunction(display, dc->u.x.gc, X11DRV_XROPfunction[dc->w.ROPmode-1]);
+    TSXSetFunction(display, physDev->gc, X11DRV_XROPfunction[dc->w.ROPmode-1]);
 
     if (descr.infoBpp <= 8)
     {
@@ -1132,8 +1133,8 @@
     descr.lines     = tmpheight >= 0 ? lines : -lines;
     descr.infoWidth = width;
     descr.depth     = dc->w.bitsPerPixel;
-    descr.drawable  = dc->u.x.drawable;
-    descr.gc        = dc->u.x.gc;
+    descr.drawable  = physDev->drawable;
+    descr.gc        = physDev->gc;
     descr.xSrc      = xSrc;
     descr.ySrc      = tmpheight >= 0 ? lines-(ySrc-startscan)-cy+(oldcy-cy) 
                                      : ySrc - startscan;
diff --git a/graphics/x11drv/graphics.c b/graphics/x11drv/graphics.c
index 8304a80..93aedc5 100644
--- a/graphics/x11drv/graphics.c
+++ b/graphics/x11drv/graphics.c
@@ -75,21 +75,22 @@
     XGCValues val;
     unsigned long mask;
     Pixmap pixmap = 0;
+    X11DRV_PDEVICE *physDev = (X11DRV_PDEVICE *)dc->physDev;
 
-    if (dc->u.x.brush.style == BS_NULL) return FALSE;
-    if (dc->u.x.brush.pixel == -1)
+    if (physDev->brush.style == BS_NULL) return FALSE;
+    if (physDev->brush.pixel == -1)
     {
 	/* Special case used for monochrome pattern brushes.
 	 * We need to swap foreground and background because
 	 * Windows does it the wrong way...
 	 */
-	val.foreground = dc->u.x.backgroundPixel;
-	val.background = dc->u.x.textPixel;
+	val.foreground = physDev->backgroundPixel;
+	val.background = physDev->textPixel;
     }
     else
     {
-	val.foreground = dc->u.x.brush.pixel;
-	val.background = dc->u.x.backgroundPixel;
+	val.foreground = physDev->brush.pixel;
+	val.background = physDev->backgroundPixel;
     }
     if (fMapColors && COLOR_PixelToPalette)
     {
@@ -110,13 +111,13 @@
 	val.foreground = BlackPixelOfScreen(screen) ^ WhitePixelOfScreen(screen);
 	val.function = GXxor;
 	}
-    val.fill_style = dc->u.x.brush.fillStyle;
+    val.fill_style = physDev->brush.fillStyle;
     switch(val.fill_style)
     {
     case FillStippled:
     case FillOpaqueStippled:
 	if (dc->w.backgroundMode==OPAQUE) val.fill_style = FillOpaqueStippled;
-	val.stipple = dc->u.x.brush.pixmap;
+	val.stipple = physDev->brush.pixmap;
 	mask = GCStipple;
         break;
 
@@ -127,7 +128,7 @@
             XImage *image;
             EnterCriticalSection( &X11DRV_CritSection );
             pixmap = XCreatePixmap( display, rootWindow, 8, 8, screenDepth );
-            image = XGetImage( display, dc->u.x.brush.pixmap, 0, 0, 8, 8,
+            image = XGetImage( display, physDev->brush.pixmap, 0, 0, 8, 8,
                                AllPlanes, ZPixmap );
             for (y = 0; y < 8; y++)
                 for (x = 0; x < 8; x++)
@@ -138,7 +139,7 @@
             LeaveCriticalSection( &X11DRV_CritSection );
             val.tile = pixmap;
         }
-        else val.tile = dc->u.x.brush.pixmap;
+        else val.tile = physDev->brush.pixmap;
 	mask = GCTile;
         break;
 
@@ -161,26 +162,28 @@
 /***********************************************************************
  *           X11DRV_SetupGCForBrush
  *
- * Setup dc->u.x.gc for drawing operations using current brush.
+ * Setup physDev->gc for drawing operations using current brush.
  * Return FALSE if brush is BS_NULL, TRUE otherwise.
  */
 BOOL32 X11DRV_SetupGCForBrush( DC * dc )
 {
-    return X11DRV_SetupGCForPatBlt( dc, dc->u.x.gc, FALSE );
+    X11DRV_PDEVICE *physDev = (X11DRV_PDEVICE *)dc->physDev;
+    return X11DRV_SetupGCForPatBlt( dc, physDev->gc, FALSE );
 }
 
 
 /***********************************************************************
  *           X11DRV_SetupGCForPen
  *
- * Setup dc->u.x.gc for drawing operations using current pen.
+ * Setup physDev->gc for drawing operations using current pen.
  * Return FALSE if pen is PS_NULL, TRUE otherwise.
  */
 BOOL32 X11DRV_SetupGCForPen( DC * dc )
 {
     XGCValues val;
+    X11DRV_PDEVICE *physDev = (X11DRV_PDEVICE *)dc->physDev;
 
-    if (dc->u.x.pen.style == PS_NULL) return FALSE;
+    if (physDev->pen.style == PS_NULL) return FALSE;
 
     if (dc->w.flags & DC_DIRTY) CLIPPING_UpdateGCRegion(dc); 
 
@@ -195,7 +198,7 @@
 	val.function = GXcopy;
 	break;
     case R2_XORPEN :
-	val.foreground = dc->u.x.pen.pixel;
+	val.foreground = physDev->pen.pixel;
 	/* It is very unlikely someone wants to XOR with 0 */
 	/* This fixes the rubber-drawings in paintbrush */
 	if (val.foreground == 0)
@@ -204,24 +207,24 @@
 	val.function = GXxor;
 	break;
     default :
-	val.foreground = dc->u.x.pen.pixel;
+	val.foreground = physDev->pen.pixel;
 	val.function   = X11DRV_XROPfunction[dc->w.ROPmode-1];
     }
-    val.background = dc->u.x.backgroundPixel;
+    val.background = physDev->backgroundPixel;
     val.fill_style = FillSolid;
-    if ((dc->u.x.pen.style!=PS_SOLID) && (dc->u.x.pen.style!=PS_INSIDEFRAME))
+    if ((physDev->pen.style!=PS_SOLID) && (physDev->pen.style!=PS_INSIDEFRAME))
     {
-	TSXSetDashes( display, dc->u.x.gc, 0,
-		    dc->u.x.pen.dashes, dc->u.x.pen.dash_len );
+	TSXSetDashes( display, physDev->gc, 0, physDev->pen.dashes,
+		      physDev->pen.dash_len );
 	val.line_style = (dc->w.backgroundMode == OPAQUE) ?
 	                      LineDoubleDash : LineOnOffDash;
     }
     else val.line_style = LineSolid;
-    val.line_width = dc->u.x.pen.width;
+    val.line_width = physDev->pen.width;
     if (val.line_width <= 1) {
 	val.cap_style = CapNotLast;
     } else {
-	switch (dc->u.x.pen.endcap)
+	switch (physDev->pen.endcap)
 	{
 	case PS_ENDCAP_SQUARE:
 	    val.cap_style = CapProjecting;
@@ -234,7 +237,7 @@
 	    val.cap_style = CapRound;
 	}
     }
-    switch (dc->u.x.pen.linejoin)
+    switch (physDev->pen.linejoin)
     {
     case PS_JOIN_BEVEL:
 	val.join_style = JoinBevel;
@@ -246,7 +249,7 @@
     default:
 	val.join_style = JoinRound;
     }
-    TSXChangeGC( display, dc->u.x.gc, 
+    TSXChangeGC( display, physDev->gc, 
 	       GCFunction | GCForeground | GCBackground | GCLineWidth |
 	       GCLineStyle | GCCapStyle | GCJoinStyle | GCFillStyle, &val );
     return TRUE;
@@ -256,12 +259,13 @@
 /***********************************************************************
  *           X11DRV_SetupGCForText
  *
- * Setup dc->u.x.gc for text drawing operations.
+ * Setup physDev->gc for text drawing operations.
  * Return FALSE if the font is null, TRUE otherwise.
  */
 BOOL32 X11DRV_SetupGCForText( DC * dc )
 {
-    XFontStruct* xfs = XFONT_GetFontStruct( dc->u.x.font );
+    X11DRV_PDEVICE *physDev = (X11DRV_PDEVICE *)dc->physDev;
+    XFontStruct* xfs = XFONT_GetFontStruct( physDev->font );
 
     if( xfs )
     {
@@ -270,12 +274,12 @@
 	if (dc->w.flags & DC_DIRTY) CLIPPING_UpdateGCRegion(dc);
 
 	val.function   = GXcopy;  /* Text is always GXcopy */
-	val.foreground = dc->u.x.textPixel;
-	val.background = dc->u.x.backgroundPixel;
+	val.foreground = physDev->textPixel;
+	val.background = physDev->backgroundPixel;
 	val.fill_style = FillSolid;
 	val.font       = xfs->fid;
 
-	TSXChangeGC( display, dc->u.x.gc,
+	TSXChangeGC( display, physDev->gc,
 		   GCFunction | GCForeground | GCBackground | GCFillStyle |
 		   GCFont, &val );
 	return TRUE;
@@ -285,9 +289,6 @@
 }
 
 
-
-
-
 /**********************************************************************
  *	     X11DRV_MoveToEx
  */
@@ -309,8 +310,10 @@
 BOOL32
 X11DRV_LineTo( DC *dc, INT32 x, INT32 y )
 {
+    X11DRV_PDEVICE *physDev = (X11DRV_PDEVICE *)dc->physDev;
+
     if (X11DRV_SetupGCForPen( dc ))
-	TSXDrawLine(display, dc->u.x.drawable, dc->u.x.gc, 
+	TSXDrawLine(display, physDev->drawable, physDev->gc, 
 		  dc->w.DCOrgX + XLPTODP( dc, dc->w.CursPosX ),
 		  dc->w.DCOrgY + YLPTODP( dc, dc->w.CursPosY ),
 		  dc->w.DCOrgX + XLPTODP( dc, x ),
@@ -338,6 +341,7 @@
     INT32 width, oldwidth, oldendcap;
     double start_angle, end_angle;
     XPoint points[4];
+    X11DRV_PDEVICE *physDev = (X11DRV_PDEVICE *)dc->physDev;
 
     left   = XLPTODP( dc, left );
     top    = YLPTODP( dc, top );
@@ -353,12 +357,12 @@
     if ((left == right) || (top == bottom)
             ||(lines && ((right-left==1)||(bottom-top==1)))) return TRUE;
 
-    oldwidth = width = dc->u.x.pen.width;
-    oldendcap= dc->u.x.pen.endcap;
+    oldwidth = width = physDev->pen.width;
+    oldendcap = physDev->pen.endcap;
     if (!width) width = 1;
-    if(dc->u.x.pen.style == PS_NULL) width = 0;
+    if(physDev->pen.style == PS_NULL) width = 0;
 
-    if ((dc->u.x.pen.style == PS_INSIDEFRAME))
+    if ((physDev->pen.style == PS_INSIDEFRAME))
     {
         if (2*width > (right-left)) width=(right-left + 1)/2;
         if (2*width > (bottom-top)) width=(bottom-top + 1)/2;
@@ -367,9 +371,9 @@
         top    += width / 2;
         bottom -= (width - 1) / 2;
     }
-    if(width == 0) width=1; /* more accurate */
-    dc->u.x.pen.width=width;
-    dc->u.x.pen.endcap=PS_ENDCAP_SQUARE;
+    if(width == 0) width = 1; /* more accurate */
+    physDev->pen.width = width;
+    physDev->pen.endcap = PS_ENDCAP_SQUARE;
 
     xcenter = (right + left) / 2;
     ycenter = (bottom + top) / 2;
@@ -395,8 +399,9 @@
       /* Fill arc with brush if Chord() or Pie() */
 
     if ((lines > 0) && X11DRV_SetupGCForBrush( dc )) {
-        TSXSetArcMode( display, dc->u.x.gc, (lines==1) ? ArcChord : ArcPieSlice);
-        TSXFillArc( display, dc->u.x.drawable, dc->u.x.gc,
+        TSXSetArcMode( display, physDev->gc,
+		       (lines==1) ? ArcChord : ArcPieSlice);
+        TSXFillArc( display, physDev->drawable, physDev->gc,
                  dc->w.DCOrgX + left, dc->w.DCOrgY + top,
                  right-left-1, bottom-top-1, istart_angle, idiff_angle );
     }
@@ -404,7 +409,7 @@
       /* Draw arc and lines */
 
     if (X11DRV_SetupGCForPen( dc )){
-    TSXDrawArc( display, dc->u.x.drawable, dc->u.x.gc,
+    TSXDrawArc( display, physDev->drawable, physDev->gc,
 	      dc->w.DCOrgX + left, dc->w.DCOrgY + top,
 	      right-left-1, bottom-top-1, istart_angle, idiff_angle );
         if (lines) {
@@ -460,12 +465,12 @@
                 }
                 lines++;
     }
-    TSXDrawLines( display, dc->u.x.drawable, dc->u.x.gc,
+    TSXDrawLines( display, physDev->drawable, physDev->gc,
 	        points, lines+1, CoordModeOrigin );
         }
     }
-    dc->u.x.pen.width=oldwidth;
-    dc->u.x.pen.endcap=oldendcap;
+    physDev->pen.width = oldwidth;
+    physDev->pen.endcap = oldendcap;
     return TRUE;
 }
 
@@ -512,6 +517,8 @@
 X11DRV_Ellipse( DC *dc, INT32 left, INT32 top, INT32 right, INT32 bottom )
 {
     INT32 width, oldwidth;
+    X11DRV_PDEVICE *physDev = (X11DRV_PDEVICE *)dc->physDev;
+
     left   = XLPTODP( dc, left );
     top    = YLPTODP( dc, top );
     right  = XLPTODP( dc, right );
@@ -521,11 +528,11 @@
     if (right < left) { INT32 tmp = right; right = left; left = tmp; }
     if (bottom < top) { INT32 tmp = bottom; bottom = top; top = tmp; }
     
-    oldwidth = width = dc->u.x.pen.width;
+    oldwidth = width = physDev->pen.width;
     if (!width) width = 1;
-    if(dc->u.x.pen.style == PS_NULL) width = 0;
+    if(physDev->pen.style == PS_NULL) width = 0;
 
-    if ((dc->u.x.pen.style == PS_INSIDEFRAME))
+    if ((physDev->pen.style == PS_INSIDEFRAME))
     {
         if (2*width > (right-left)) width=(right-left + 1)/2;
         if (2*width > (bottom-top)) width=(bottom-top + 1)/2;
@@ -534,18 +541,18 @@
         top    += width / 2;
         bottom -= (width - 1) / 2;
     }
-    if(width == 0) width=1; /* more accurate */
-    dc->u.x.pen.width=width;
+    if(width == 0) width = 1; /* more accurate */
+    physDev->pen.width = width;
 
     if (X11DRV_SetupGCForBrush( dc ))
-	TSXFillArc( display, dc->u.x.drawable, dc->u.x.gc,
+	TSXFillArc( display, physDev->drawable, physDev->gc,
 		  dc->w.DCOrgX + left, dc->w.DCOrgY + top,
 		  right-left-1, bottom-top-1, 0, 360*64 );
     if (X11DRV_SetupGCForPen( dc ))
-	TSXDrawArc( display, dc->u.x.drawable, dc->u.x.gc,
+	TSXDrawArc( display, physDev->drawable, physDev->gc,
 		  dc->w.DCOrgX + left, dc->w.DCOrgY + top,
 		  right-left-1, bottom-top-1, 0, 360*64 );
-    dc->u.x.pen.width=oldwidth;
+    physDev->pen.width = oldwidth;
     return TRUE;
 }
 
@@ -557,6 +564,7 @@
 X11DRV_Rectangle(DC *dc, INT32 left, INT32 top, INT32 right, INT32 bottom)
 {
     INT32 width, oldwidth, oldjoinstyle;
+    X11DRV_PDEVICE *physDev = (X11DRV_PDEVICE *)dc->physDev;
 
     TRACE(graphics, "(%d %d %d %d)\n", 
     	left, top, right, bottom);
@@ -571,11 +579,11 @@
     if (right < left) { INT32 tmp = right; right = left; left = tmp; }
     if (bottom < top) { INT32 tmp = bottom; bottom = top; top = tmp; }
 
-    oldwidth = width = dc->u.x.pen.width;
+    oldwidth = width = physDev->pen.width;
     if (!width) width = 1;
-    if(dc->u.x.pen.style == PS_NULL) width = 0;
+    if(physDev->pen.style == PS_NULL) width = 0;
 
-    if ((dc->u.x.pen.style == PS_INSIDEFRAME))
+    if ((physDev->pen.style == PS_INSIDEFRAME))
     {
         if (2*width > (right-left)) width=(right-left + 1)/2;
         if (2*width > (bottom-top)) width=(bottom-top + 1)/2;
@@ -584,27 +592,27 @@
         top    += width / 2;
         bottom -= (width - 1) / 2;
     }
-    if(width == 1) width=0;
-    dc->u.x.pen.width=width;
-    oldjoinstyle=dc->u.x.pen.linejoin;
-    if(dc->u.x.pen.type!=PS_GEOMETRIC)
-            dc->u.x.pen.linejoin=PS_JOIN_MITER;
+    if(width == 1) width = 0;
+    physDev->pen.width = width;
+    oldjoinstyle = physDev->pen.linejoin;
+    if(physDev->pen.type != PS_GEOMETRIC)
+        physDev->pen.linejoin = PS_JOIN_MITER;
 
     if ((right > left + width) && (bottom > top + width))
     {
         if (X11DRV_SetupGCForBrush( dc ))
-            TSXFillRectangle( display, dc->u.x.drawable, dc->u.x.gc,
+            TSXFillRectangle( display, physDev->drawable, physDev->gc,
                             dc->w.DCOrgX + left + (width + 1) / 2,
                             dc->w.DCOrgY + top + (width + 1) / 2,
                             right-left-width-1, bottom-top-width-1);
     }
     if (X11DRV_SetupGCForPen( dc ))
-	TSXDrawRectangle( display, dc->u.x.drawable, dc->u.x.gc,
+	TSXDrawRectangle( display, physDev->drawable, physDev->gc,
 		        dc->w.DCOrgX + left, dc->w.DCOrgY + top,
 		        right-left-1, bottom-top-1 );
 
-    dc->u.x.pen.width=oldwidth;
-    dc->u.x.pen.linejoin=oldjoinstyle;
+    physDev->pen.width = oldwidth;
+    physDev->pen.linejoin = oldjoinstyle;
     return TRUE;
 }
 
@@ -616,6 +624,7 @@
                   INT32 bottom, INT32 ell_width, INT32 ell_height )
 {
     INT32 width, oldwidth, oldendcap;
+    X11DRV_PDEVICE *physDev = (X11DRV_PDEVICE *)dc->physDev;
 
     TRACE(graphics, "(%d %d %d %d  %d %d\n", 
     	left, top, right, bottom, ell_width, ell_height);
@@ -638,12 +647,12 @@
     if (right < left) { INT32 tmp = right; right = left; left = tmp; }
     if (bottom < top) { INT32 tmp = bottom; bottom = top; top = tmp; }
 
-    oldwidth=width = dc->u.x.pen.width;
-    oldendcap = dc->u.x.pen.endcap;
+    oldwidth = width = physDev->pen.width;
+    oldendcap = physDev->pen.endcap;
     if (!width) width = 1;
-    if(dc->u.x.pen.style == PS_NULL) width = 0;
+    if(physDev->pen.style == PS_NULL) width = 0;
 
-    if ((dc->u.x.pen.style == PS_INSIDEFRAME))
+    if ((physDev->pen.style == PS_INSIDEFRAME))
     {
         if (2*width > (right-left)) width=(right-left + 1)/2;
         if (2*width > (bottom-top)) width=(bottom-top + 1)/2;
@@ -652,59 +661,60 @@
         top    += width / 2;
         bottom -= (width - 1) / 2;
     }
-    if(width == 0) width=1;
-    dc->u.x.pen.width=width;
-    dc->u.x.pen.endcap=PS_ENDCAP_SQUARE;
+    if(width == 0) width = 1;
+    physDev->pen.width = width;
+    physDev->pen.endcap = PS_ENDCAP_SQUARE;
 
     if (X11DRV_SetupGCForBrush( dc ))
     {
         if (ell_width > (right-left) )
             if (ell_height > (bottom-top) )
-                    TSXFillArc( display, dc->u.x.drawable, dc->u.x.gc,
-                              dc->w.DCOrgX + left, dc->w.DCOrgY + top,
-                              right - left - 1, bottom - top - 1,
-                              0, 360 * 64 );
+                    TSXFillArc( display, physDev->drawable, physDev->gc,
+				dc->w.DCOrgX + left, dc->w.DCOrgY + top,
+				right - left - 1, bottom - top - 1,
+				0, 360 * 64 );
             else{
-                    TSXFillArc( display, dc->u.x.drawable, dc->u.x.gc,
-                              dc->w.DCOrgX + left, dc->w.DCOrgY + top,
-                              right - left - 1, ell_height, 0, 180 * 64 );
-                    TSXFillArc( display, dc->u.x.drawable, dc->u.x.gc,
-                              dc->w.DCOrgX + left,
-                              dc->w.DCOrgY + bottom - ell_height - 1,
-                              right - left - 1, ell_height, 180 * 64, 180 * 64 );
+                    TSXFillArc( display, physDev->drawable, physDev->gc,
+				dc->w.DCOrgX + left, dc->w.DCOrgY + top,
+				right - left - 1, ell_height, 0, 180 * 64 );
+                    TSXFillArc( display, physDev->drawable, physDev->gc,
+				dc->w.DCOrgX + left,
+				dc->w.DCOrgY + bottom - ell_height - 1,
+				right - left - 1, ell_height, 180 * 64,
+				180 * 64 );
            }
 	else if (ell_height > (bottom-top) ){
-                TSXFillArc( display, dc->u.x.drawable, dc->u.x.gc,
+                TSXFillArc( display, physDev->drawable, physDev->gc,
                       dc->w.DCOrgX + left, dc->w.DCOrgY + top,
                       ell_width, bottom - top - 1, 90 * 64, 180 * 64 );
-                TSXFillArc( display, dc->u.x.drawable, dc->u.x.gc,
+                TSXFillArc( display, physDev->drawable, physDev->gc,
                       dc->w.DCOrgX + right - ell_width -1, dc->w.DCOrgY + top,
                       ell_width, bottom - top - 1, 270 * 64, 180 * 64 );
         }else{
-                TSXFillArc( display, dc->u.x.drawable, dc->u.x.gc,
+                TSXFillArc( display, physDev->drawable, physDev->gc,
                       dc->w.DCOrgX + left, dc->w.DCOrgY + top,
                       ell_width, ell_height, 90 * 64, 90 * 64 );
-                TSXFillArc( display, dc->u.x.drawable, dc->u.x.gc,
+                TSXFillArc( display, physDev->drawable, physDev->gc,
                       dc->w.DCOrgX + left,
                       dc->w.DCOrgY + bottom - ell_height - 1,
                       ell_width, ell_height, 180 * 64, 90 * 64 );
-                TSXFillArc( display, dc->u.x.drawable, dc->u.x.gc,
+                TSXFillArc( display, physDev->drawable, physDev->gc,
                       dc->w.DCOrgX + right - ell_width - 1,
                       dc->w.DCOrgY + bottom - ell_height - 1,
                       ell_width, ell_height, 270 * 64, 90 * 64 );
-                TSXFillArc( display, dc->u.x.drawable, dc->u.x.gc,
+                TSXFillArc( display, physDev->drawable, physDev->gc,
                       dc->w.DCOrgX + right - ell_width - 1,
                       dc->w.DCOrgY + top,
                       ell_width, ell_height, 0, 90 * 64 );
         }
         if (ell_width < right - left)
         {
-            TSXFillRectangle( display, dc->u.x.drawable, dc->u.x.gc,
+            TSXFillRectangle( display, physDev->drawable, physDev->gc,
                             dc->w.DCOrgX + left + (ell_width + 1) / 2,
                             dc->w.DCOrgY + top + 1,
                             right - left - ell_width - 1,
                             (ell_height + 1) / 2 - 1);
-            TSXFillRectangle( display, dc->u.x.drawable, dc->u.x.gc,
+            TSXFillRectangle( display, physDev->drawable, physDev->gc,
                             dc->w.DCOrgX + left + (ell_width + 1) / 2,
                             dc->w.DCOrgY + bottom - (ell_height) / 2 - 1,
                             right - left - ell_width - 1,
@@ -712,7 +722,7 @@
         }
         if  (ell_height < bottom - top)
         {
-            TSXFillRectangle( display, dc->u.x.drawable, dc->u.x.gc,
+            TSXFillRectangle( display, physDev->drawable, physDev->gc,
                             dc->w.DCOrgX + left + 1,
                             dc->w.DCOrgY + top + (ell_height + 1) / 2,
                             right - left - 2,
@@ -731,49 +741,49 @@
     if (X11DRV_SetupGCForPen(dc)) {
         if (ell_width > (right-left) )
             if (ell_height > (bottom-top) )
-                TSXDrawArc( display, dc->u.x.drawable, dc->u.x.gc,
+                TSXDrawArc( display, physDev->drawable, physDev->gc,
 		      dc->w.DCOrgX + left, dc->w.DCOrgY + top,
 		      right - left - 1, bottom -top - 1, 0 , 360 * 64 );
             else{
-		TSXDrawArc( display, dc->u.x.drawable, dc->u.x.gc,
+		TSXDrawArc( display, physDev->drawable, physDev->gc,
 		      dc->w.DCOrgX + left, dc->w.DCOrgY + top,
 		      right - left - 1, ell_height - 1, 0 , 180 * 64 );
-		TSXDrawArc( display, dc->u.x.drawable, dc->u.x.gc,
+		TSXDrawArc( display, physDev->drawable, physDev->gc,
 		      dc->w.DCOrgX + left, 
                       dc->w.DCOrgY + bottom - ell_height,
 		      right - left - 1, ell_height - 1, 180 * 64 , 180 * 64 );
             }
 	else if (ell_height > (bottom-top) ){
-                TSXDrawArc( display, dc->u.x.drawable, dc->u.x.gc,
+                TSXDrawArc( display, physDev->drawable, physDev->gc,
                       dc->w.DCOrgX + left, dc->w.DCOrgY + top,
                       ell_width - 1 , bottom - top - 1, 90 * 64 , 180 * 64 );
-                TSXDrawArc( display, dc->u.x.drawable, dc->u.x.gc,
+                TSXDrawArc( display, physDev->drawable, physDev->gc,
                       dc->w.DCOrgX + right - ell_width, 
                       dc->w.DCOrgY + top,
                       ell_width - 1 , bottom - top - 1, 270 * 64 , 180 * 64 );
 	}else{
-            TSXDrawArc( display, dc->u.x.drawable, dc->u.x.gc,
+            TSXDrawArc( display, physDev->drawable, physDev->gc,
                       dc->w.DCOrgX + left, dc->w.DCOrgY + top,
                       ell_width - 1, ell_height - 1, 90 * 64, 90 * 64 );
-            TSXDrawArc( display, dc->u.x.drawable, dc->u.x.gc,
+            TSXDrawArc( display, physDev->drawable, physDev->gc,
                       dc->w.DCOrgX + left, dc->w.DCOrgY + bottom - ell_height,
                       ell_width - 1, ell_height - 1, 180 * 64, 90 * 64 );
-            TSXDrawArc( display, dc->u.x.drawable, dc->u.x.gc,
+            TSXDrawArc( display, physDev->drawable, physDev->gc,
                       dc->w.DCOrgX + right - ell_width,
                       dc->w.DCOrgY + bottom - ell_height,
                       ell_width - 1, ell_height - 1, 270 * 64, 90 * 64 );
-            TSXDrawArc( display, dc->u.x.drawable, dc->u.x.gc,
+            TSXDrawArc( display, physDev->drawable, physDev->gc,
                       dc->w.DCOrgX + right - ell_width, dc->w.DCOrgY + top,
                       ell_width - 1, ell_height - 1, 0, 90 * 64 );
 	}
 	if (ell_width < right - left)
 	{
-	    TSXDrawLine( display, dc->u.x.drawable, dc->u.x.gc, 
+	    TSXDrawLine( display, physDev->drawable, physDev->gc, 
                dc->w.DCOrgX + left + ell_width / 2,
 		       dc->w.DCOrgY + top,
                dc->w.DCOrgX + right - (ell_width+1) / 2,
 		       dc->w.DCOrgY + top);
-	    TSXDrawLine( display, dc->u.x.drawable, dc->u.x.gc, 
+	    TSXDrawLine( display, physDev->drawable, physDev->gc, 
                dc->w.DCOrgX + left + ell_width / 2 ,
 		       dc->w.DCOrgY + bottom - 1,
                dc->w.DCOrgX + right - (ell_width+1)/ 2,
@@ -781,20 +791,20 @@
 	}
 	if (ell_height < bottom - top)
 	{
-	    TSXDrawLine( display, dc->u.x.drawable, dc->u.x.gc, 
+	    TSXDrawLine( display, physDev->drawable, physDev->gc, 
 		       dc->w.DCOrgX + right - 1,
                dc->w.DCOrgY + top + ell_height / 2,
 		       dc->w.DCOrgX + right - 1,
                dc->w.DCOrgY + bottom - (ell_height+1) / 2);
-	    TSXDrawLine( display, dc->u.x.drawable, dc->u.x.gc, 
+	    TSXDrawLine( display, physDev->drawable, physDev->gc, 
 		       dc->w.DCOrgX + left,
                dc->w.DCOrgY + top + ell_height / 2,
 		       dc->w.DCOrgX + left,
                dc->w.DCOrgY + bottom - (ell_height+1) / 2);
 	}
     }
-    dc->u.x.pen.width=oldwidth;
-    dc->u.x.pen.endcap=oldendcap;
+    physDev->pen.width = oldwidth;
+    physDev->pen.endcap = oldendcap;
     return TRUE;
 }
 
@@ -806,14 +816,15 @@
 X11DRV_SetPixel( DC *dc, INT32 x, INT32 y, COLORREF color )
 {
     Pixel pixel;
+    X11DRV_PDEVICE *physDev = (X11DRV_PDEVICE *)dc->physDev;
     
     x = dc->w.DCOrgX + XLPTODP( dc, x );
     y = dc->w.DCOrgY + YLPTODP( dc, y );
     pixel = COLOR_ToPhysical( dc, color );
     
-    TSXSetForeground( display, dc->u.x.gc, pixel );
-    TSXSetFunction( display, dc->u.x.gc, GXcopy );
-    TSXDrawPoint( display, dc->u.x.drawable, dc->u.x.gc, x, y );
+    TSXSetForeground( display, physDev->gc, pixel );
+    TSXSetFunction( display, physDev->gc, GXcopy );
+    TSXDrawPoint( display, physDev->drawable, physDev->gc, x, y );
 
     /* inefficient but simple... */
 
@@ -830,13 +841,14 @@
     static Pixmap pixmap = 0;
     XImage * image;
     int pixel;
+    X11DRV_PDEVICE *physDev = (X11DRV_PDEVICE *)dc->physDev;
 
     x = dc->w.DCOrgX + XLPTODP( dc, x );
     y = dc->w.DCOrgY + YLPTODP( dc, y );
     EnterCriticalSection( &X11DRV_CritSection );
     if (dc->w.flags & DC_MEMORY)
     {
-        image = XGetImage( display, dc->u.x.drawable, x, y, 1, 1,
+        image = XGetImage( display, physDev->drawable, x, y, 1, 1,
                            AllPlanes, ZPixmap );
     }
     else
@@ -845,7 +857,7 @@
         /* to avoid a BadMatch error */
         if (!pixmap) pixmap = XCreatePixmap( display, rootWindow,
                                              1, 1, dc->w.bitsPerPixel );
-        XCopyArea( display, dc->u.x.drawable, pixmap, BITMAP_colorGC,
+        XCopyArea( display, physDev->drawable, pixmap, BITMAP_colorGC,
                    x, y, 1, 1, 0, 0 );
         image = XGetImage( display, pixmap, 0, 0, 1, 1, AllPlanes, ZPixmap );
     }
@@ -866,6 +878,7 @@
     RECT32 box;
     HRGN32 tmpVisRgn, prevVisRgn;
     HDC32  hdc = dc->hSelf; /* FIXME: should not mix dc/hdc this way */
+    X11DRV_PDEVICE *physDev = (X11DRV_PDEVICE *)dc->physDev;
 
     if (!(tmpVisRgn = CreateRectRgn32( 0, 0, 0, 0 ))) return FALSE;
 
@@ -889,7 +902,7 @@
 
     GetRgnBox32( dc->w.hGCClipRgn, &box );
     if (X11DRV_SetupGCForBrush( dc ))
-	TSXFillRectangle( display, dc->u.x.drawable, dc->u.x.gc,
+	TSXFillRectangle( display, physDev->drawable, physDev->gc,
 		          box.left, box.top,
 		          box.right-box.left, box.bottom-box.top );
 
@@ -908,7 +921,9 @@
     INT32 oldwidth;
     register int i;
     XPoint *points;
-    if((oldwidth=dc->u.x.pen.width)==0) dc->u.x.pen.width=1;
+    X11DRV_PDEVICE *physDev = (X11DRV_PDEVICE *)dc->physDev;
+
+    if((oldwidth = physDev->pen.width) == 0) physDev->pen.width = 1;
 
     points = (XPoint *) xmalloc (sizeof (XPoint) * (count));
     for (i = 0; i < count; i++)
@@ -918,11 +933,11 @@
     }
 
     if (X11DRV_SetupGCForPen ( dc ))
-    TSXDrawLines( display, dc->u.x.drawable, dc->u.x.gc,
+    TSXDrawLines( display, physDev->drawable, physDev->gc,
            points, count, CoordModeOrigin );
 
     free( points );
-    dc->u.x.pen.width=oldwidth;
+    physDev->pen.width = oldwidth;
     return TRUE;
 }
 
@@ -935,6 +950,7 @@
 {
     register int i;
     XPoint *points;
+    X11DRV_PDEVICE *physDev = (X11DRV_PDEVICE *)dc->physDev;
 
     points = (XPoint *) xmalloc (sizeof (XPoint) * (count+1));
     for (i = 0; i < count; i++)
@@ -945,11 +961,11 @@
     points[count] = points[0];
 
     if (X11DRV_SetupGCForBrush( dc ))
-	TSXFillPolygon( display, dc->u.x.drawable, dc->u.x.gc,
+	TSXFillPolygon( display, physDev->drawable, physDev->gc,
 		     points, count+1, Complex, CoordModeOrigin);
 
     if (X11DRV_SetupGCForPen ( dc ))
-	TSXDrawLines( display, dc->u.x.drawable, dc->u.x.gc,
+	TSXDrawLines( display, physDev->drawable, physDev->gc,
 		   points, count+1, CoordModeOrigin );
 
     free( points );
@@ -964,11 +980,11 @@
 X11DRV_PolyPolygon( DC *dc, const POINT32* pt, const INT32* counts, UINT32 polygons)
 {
     HRGN32 hrgn;
+    X11DRV_PDEVICE *physDev = (X11DRV_PDEVICE *)dc->physDev;
 
-      /* FIXME: The points should be converted to device coords before */
-      /* creating the region. But as CreatePolyPolygonRgn is not */
-      /* really correct either, it doesn't matter much... */
-      /* At least the outline will be correct :-) */
+    /* FIXME: The points should be converted to device coords before */
+    /* creating the region. */
+
     hrgn = CreatePolyPolygonRgn32( pt, counts, polygons, dc->w.polyFillMode );
     X11DRV_PaintRgn( dc, hrgn );
     DeleteObject32( hrgn );
@@ -992,7 +1008,7 @@
 		pt++;
 	    }
 	    points[j] = points[0];
-	    TSXDrawLines( display, dc->u.x.drawable, dc->u.x.gc,
+	    TSXDrawLines( display, physDev->drawable, physDev->gc,
 		        points, j + 1, CoordModeOrigin );
 	}
 	free( points );
@@ -1007,6 +1023,7 @@
 BOOL32 
 X11DRV_PolyPolyline( DC *dc, const POINT32* pt, const DWORD* counts, DWORD polylines )
 {
+    X11DRV_PDEVICE *physDev = (X11DRV_PDEVICE *)dc->physDev;
     if (X11DRV_SetupGCForPen ( dc ))
     {
         int i, j, max = 0;
@@ -1024,7 +1041,7 @@
                 pt++;
             }
             points[j] = points[0];
-            TSXDrawLines( display, dc->u.x.drawable, dc->u.x.gc,
+            TSXDrawLines( display, physDev->drawable, physDev->gc,
                         points, j + 1, CoordModeOrigin );
         }
         free( points );
@@ -1045,6 +1062,7 @@
                                      int xOrg, int yOrg,
                                      Pixel pixel, WORD fillType )
 {
+    X11DRV_PDEVICE *physDev = (X11DRV_PDEVICE *)dc->physDev;
     int left, right;
 
 #define TO_FLOOD(x,y)  ((fillType == FLOODFILLBORDER) ? \
@@ -1058,7 +1076,7 @@
     left = right = x;
     while ((left > 0) && TO_FLOOD( left-1, y )) left--;
     while ((right < image->width) && TO_FLOOD( right, y )) right++;
-    XFillRectangle( display, dc->u.x.drawable, dc->u.x.gc,
+    XFillRectangle( display, physDev->drawable, physDev->gc,
                     xOrg + left, yOrg + y, right-left, 1 );
 
       /* Set the pixels of this line so we don't fill it again */
@@ -1124,10 +1142,11 @@
     XImage *image;
     RECT32 rect;
     DC *dc = params->dc;
+    X11DRV_PDEVICE *physDev = (X11DRV_PDEVICE *)dc->physDev;
 
     if (GetRgnBox32( dc->w.hGCClipRgn, &rect ) == ERROR) return FALSE;
 
-    if (!(image = XGetImage( display, dc->u.x.drawable,
+    if (!(image = XGetImage( display, physDev->drawable,
                              rect.left,
                              rect.top,
                              rect.right - rect.left,
@@ -1137,7 +1156,7 @@
     if (X11DRV_SetupGCForBrush( dc ))
     {
           /* ROP mode is always GXcopy for flood-fill */
-        XSetFunction( display, dc->u.x.gc, GXcopy );
+        XSetFunction( display, physDev->gc, GXcopy );
         X11DRV_InternalFloodFill(image, dc,
                                  XLPTODP(dc,params->x) + dc->w.DCOrgX - rect.left,
                                  YLPTODP(dc,params->y) + dc->w.DCOrgY - rect.top,
@@ -1293,8 +1312,10 @@
 static void X11DRV_Bezier(int level, DC * dc, POINT32 *Points, 
                           XPoint* xpoints, unsigned int* pIx)
 {
+    X11DRV_PDEVICE *physDev = (X11DRV_PDEVICE *)dc->physDev;
+
     if(*pIx == BEZMAXPOINTS){
-        TSXDrawLines( display, dc->u.x.drawable, dc->u.x.gc,
+        TSXDrawLines( display, physDev->drawable, physDev->gc,
                     xpoints, *pIx, CoordModeOrigin );
         *pIx=0;
     }
@@ -1343,6 +1364,8 @@
     int i;
     unsigned int ix=0;
     XPoint* xpoints;
+    X11DRV_PDEVICE *physDev = (X11DRV_PDEVICE *)dc->physDev;
+
     TRACE(graphics, "dc=%04x count=%ld %d,%d - %d,%d - %d,%d -%d,%d \n", 
             (int)dc, count,
             start.x, start.y,
@@ -1366,8 +1389,8 @@
         X11DRV_Bezier(BEZIERMAXDEPTH , dc, Points, xpoints, &ix );
         count -=3;
     }
-    if( ix) TSXDrawLines( display, dc->u.x.drawable, dc->u.x.gc,
-                xpoints, ix, CoordModeOrigin );
+    if( ix) TSXDrawLines( display, physDev->drawable, physDev->gc,
+			  xpoints, ix, CoordModeOrigin );
     free(xpoints);
     return TRUE;
 }
diff --git a/graphics/x11drv/init.c b/graphics/x11drv/init.c
index 1147c9d..4091c4f 100644
--- a/graphics/x11drv/init.c
+++ b/graphics/x11drv/init.c
@@ -8,7 +8,8 @@
 #include "x11drv.h"
 #include "color.h"
 #include "bitmap.h"
-
+#include "winnt.h"
+#include "debug.h"
 
 static BOOL32 X11DRV_CreateDC( DC *dc, LPCSTR driver, LPCSTR device,
                                LPCSTR output, const DEVMODE16* initData );
@@ -170,10 +171,13 @@
 {
     X11DRV_PDEVICE *physDev;
 
-    physDev = &dc->u.x;  /* for now */
+    dc->physDev = physDev = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY,
+				       sizeof(*physDev) );
+    if(!physDev) {
+        ERR(x11drv, "Can't allocate physDev\n");
+	return FALSE;
+    }
 
-    memset( physDev, 0, sizeof(*physDev) );
-    dc->physDev        = physDev;
     dc->w.devCaps      = &X11DRV_DevCaps;
     if (dc->w.flags & DC_MEMORY)
     {
@@ -227,6 +231,8 @@
 {
     X11DRV_PDEVICE *physDev = (X11DRV_PDEVICE *)dc->physDev;
     TSXFreeGC( display, physDev->gc );
+    HeapFree( GetProcessHeap(), 0, physDev );
+    dc->physDev = NULL;
     return TRUE;
 }
 
diff --git a/graphics/x11drv/pen.c b/graphics/x11drv/pen.c
index 5251075..4c26d1e 100644
--- a/graphics/x11drv/pen.c
+++ b/graphics/x11drv/pen.c
@@ -1,5 +1,5 @@
 /*
- * GDI pen objects
+ * X11DRV pen objects
  *
  * Copyright 1993 Alexandre Julliard
  */
@@ -20,40 +20,41 @@
 HPEN32 X11DRV_PEN_SelectObject( DC * dc, HPEN32 hpen, PENOBJ * pen )
 {
     HPEN32 prevHandle = dc->w.hPen;
+    X11DRV_PDEVICE *physDev = (X11DRV_PDEVICE *)dc->physDev;
 
     dc->w.hPen = hpen;
-    dc->u.x.pen.style = pen->logpen.lopnStyle & PS_STYLE_MASK;
-    dc->u.x.pen.type = pen->logpen.lopnStyle & PS_TYPE_MASK;
-    dc->u.x.pen.endcap = pen->logpen.lopnStyle & PS_ENDCAP_MASK;
-    dc->u.x.pen.linejoin = pen->logpen.lopnStyle & PS_JOIN_MASK;
+    physDev->pen.style = pen->logpen.lopnStyle & PS_STYLE_MASK;
+    physDev->pen.type = pen->logpen.lopnStyle & PS_TYPE_MASK;
+    physDev->pen.endcap = pen->logpen.lopnStyle & PS_ENDCAP_MASK;
+    physDev->pen.linejoin = pen->logpen.lopnStyle & PS_JOIN_MASK;
 
-    dc->u.x.pen.width = (pen->logpen.lopnWidth.x * dc->vportExtX +
+    physDev->pen.width = (pen->logpen.lopnWidth.x * dc->vportExtX +
                     dc->wndExtX / 2) / dc->wndExtX;
-    if (dc->u.x.pen.width < 0) dc->u.x.pen.width = -dc->u.x.pen.width;
-    if (dc->u.x.pen.width == 1) dc->u.x.pen.width = 0;  /* Faster */
-    dc->u.x.pen.pixel = COLOR_ToPhysical( dc, pen->logpen.lopnColor );    
+    if (physDev->pen.width < 0) physDev->pen.width = -physDev->pen.width;
+    if (physDev->pen.width == 1) physDev->pen.width = 0;  /* Faster */
+    physDev->pen.pixel = COLOR_ToPhysical( dc, pen->logpen.lopnColor );    
     switch(pen->logpen.lopnStyle & PS_STYLE_MASK)
     {
       case PS_DASH:
-	dc->u.x.pen.dashes = (char *)PEN_dash;
-	dc->u.x.pen.dash_len = 2;
+	physDev->pen.dashes = (char *)PEN_dash;
+	physDev->pen.dash_len = 2;
 	break;
       case PS_DOT:
-	dc->u.x.pen.dashes = (char *)PEN_dot;
-	dc->u.x.pen.dash_len = 2;
+	physDev->pen.dashes = (char *)PEN_dot;
+	physDev->pen.dash_len = 2;
 	break;
       case PS_DASHDOT:
-	dc->u.x.pen.dashes = (char *)PEN_dashdot;
-	dc->u.x.pen.dash_len = 4;
+	physDev->pen.dashes = (char *)PEN_dashdot;
+	physDev->pen.dash_len = 4;
 	break;
       case PS_DASHDOTDOT:
-	dc->u.x.pen.dashes = (char *)PEN_dashdotdot;
-	dc->u.x.pen.dash_len = 6;
+	physDev->pen.dashes = (char *)PEN_dashdotdot;
+	physDev->pen.dash_len = 6;
 	break;
       case PS_ALTERNATE:
 	/* FIXME: should be alternating _pixels_ that are set */
-	dc->u.x.pen.dashes = (char *)PEN_alternate;
-	dc->u.x.pen.dash_len = 2;
+	physDev->pen.dashes = (char *)PEN_alternate;
+	physDev->pen.dash_len = 2;
 	break;
       case PS_USERSTYLE:
 	/* FIXME */
diff --git a/graphics/x11drv/text.c b/graphics/x11drv/text.c
index ba65559..8f09124 100644
--- a/graphics/x11drv/text.c
+++ b/graphics/x11drv/text.c
@@ -35,10 +35,11 @@
     RECT32 		rect;
     char		dfBreakChar, lfUnderline, lfStrikeOut;
     BOOL32		rotated = FALSE;
+    X11DRV_PDEVICE      *physDev = (X11DRV_PDEVICE *)dc->physDev;
 
     if (!X11DRV_SetupGCForText( dc )) return TRUE;
 
-    pfo = XFONT_GetFontObject( dc->u.x.font );
+    pfo = XFONT_GetFontObject( physDev->font );
     font = pfo->fs;
      
     if (pfo->lf.lfEscapement && pfo->lpX11Trans)
@@ -48,7 +49,7 @@
     lfStrikeOut = (pfo->fo_flags & FO_SYNTH_STRIKEOUT) ? 1 : 0;
 
     TRACE(text,"hdc=%04x df=%04x %d,%d %s, %d  flags=%d lpDx=%p\n",
-	  dc->hSelf, (UINT16)(dc->u.x.font), x, y,
+	  dc->hSelf, (UINT16)(physDev->font), x, y,
 	  debugstr_an (str, count), count, flags, lpDx);
 
     /* some strings sent here end in a newline for whatever reason.  I have no
@@ -102,8 +103,8 @@
 
     if (flags & ETO_OPAQUE)
     {
-        TSXSetForeground( display, dc->u.x.gc, dc->u.x.backgroundPixel );
-        TSXFillRectangle( display, dc->u.x.drawable, dc->u.x.gc,
+        TSXSetForeground( display, physDev->gc, physDev->backgroundPixel );
+        TSXFillRectangle( display, physDev->drawable, physDev->gc,
                         dc->w.DCOrgX + rect.left, dc->w.DCOrgY + rect.top,
                         rect.right-rect.left, rect.bottom-rect.top );
     }
@@ -195,8 +196,9 @@
                 (y - ascent < rect.top) ||
                 (y + descent >= rect.bottom))
             {
-                TSXSetForeground( display, dc->u.x.gc, dc->u.x.backgroundPixel );
-                TSXFillRectangle( display, dc->u.x.drawable, dc->u.x.gc,
+                TSXSetForeground( display, physDev->gc,
+				  physDev->backgroundPixel );
+                TSXFillRectangle( display, physDev->drawable, physDev->gc,
                                 dc->w.DCOrgX + x,
                                 dc->w.DCOrgY + y - ascent,
                                 width,
@@ -207,12 +209,12 @@
     
     /* Draw the text (count > 0 verified) */
 
-    TSXSetForeground( display, dc->u.x.gc, dc->u.x.textPixel );
+    TSXSetForeground( display, physDev->gc, physDev->textPixel );
     if (!dc->w.charExtra && !dc->w.breakExtra && !lpDx)
     {
       if(!rotated)
       {
-        TSXDrawString( display, dc->u.x.drawable, dc->u.x.gc, 
+        TSXDrawString( display, physDev->drawable, physDev->gc, 
                      dc->w.DCOrgX + x, dc->w.DCOrgY + y, str, count );
       }
       else 
@@ -229,7 +231,7 @@
 	  int y_i = IROUND((double) (dc->w.DCOrgY + y) - offset *
 			   pfo->lpX11Trans->b / 1000.0 );
 
-	  TSXDrawString( display, dc->u.x.drawable, dc->u.x.gc,
+	  TSXDrawString( display, physDev->drawable, physDev->gc,
 			 x_i, y_i, &str[i], 1);
 	  offset += (double) (font->per_char ?
 		     font->per_char[char_metric_offset].attributes:
@@ -293,7 +295,7 @@
             } 
         }
 
-        TSXDrawText( display, dc->u.x.drawable, dc->u.x.gc,
+        TSXDrawText( display, physDev->drawable, physDev->gc,
                    dc->w.DCOrgX + x, dc->w.DCOrgY + y, items, pitem - items );
         HeapFree( GetProcessHeap(), 0, items );
     }
@@ -309,11 +311,11 @@
 	if (!TSXGetFontProperty( font, XA_UNDERLINE_THICKNESS, &lineWidth ))
 	    lineWidth = 0;
 	else if (lineWidth == 1) lineWidth = 0;
-	TSXSetLineAttributes( display, dc->u.x.gc, lineWidth,
-			    LineSolid, CapRound, JoinBevel ); 
-        TSXDrawLine( display, dc->u.x.drawable, dc->u.x.gc,
-		   dc->w.DCOrgX + x, dc->w.DCOrgY + y + linePos,
-		   dc->w.DCOrgX + x + width, dc->w.DCOrgY + y + linePos );
+	TSXSetLineAttributes( display, physDev->gc, lineWidth,
+			      LineSolid, CapRound, JoinBevel ); 
+        TSXDrawLine( display, physDev->drawable, physDev->gc,
+		     dc->w.DCOrgX + x, dc->w.DCOrgY + y + linePos,
+		     dc->w.DCOrgX + x + width, dc->w.DCOrgY + y + linePos );
     }
     if (lfStrikeOut)
     {
@@ -322,9 +324,9 @@
 	    lineAscent = ascent / 2;
 	if (!TSXGetFontProperty( font, XA_STRIKEOUT_DESCENT, &lineDescent ))
 	    lineDescent = -lineAscent * 2 / 3;
-	TSXSetLineAttributes( display, dc->u.x.gc, lineAscent + lineDescent,
+	TSXSetLineAttributes( display, physDev->gc, lineAscent + lineDescent,
 			    LineSolid, CapRound, JoinBevel ); 
-	TSXDrawLine( display, dc->u.x.drawable, dc->u.x.gc,
+	TSXDrawLine( display, physDev->drawable, physDev->gc,
 		   dc->w.DCOrgX + x, dc->w.DCOrgY + y - lineAscent,
 		   dc->w.DCOrgX + x + width, dc->w.DCOrgY + y - lineAscent );
     }
diff --git a/graphics/x11drv/xfont.c b/graphics/x11drv/xfont.c
index 9c670a3..25396d9 100644
--- a/graphics/x11drv/xfont.c
+++ b/graphics/x11drv/xfont.c
@@ -2206,16 +2206,17 @@
 {
     HFONT32 hPrevFont = 0;
     LOGFONT16 lf;
+    X11DRV_PDEVICE *physDev = (X11DRV_PDEVICE *)dc->physDev;
 
-    if( CHECK_PFONT(dc->u.x.font) ) 
-        XFONT_ReleaseCacheEntry( __PFONT(dc->u.x.font) );
+    if( CHECK_PFONT(physDev->font) ) 
+        XFONT_ReleaseCacheEntry( __PFONT(physDev->font) );
 
     /* FIXME: do we need to pass anything back from here? */
     memcpy(&lf,&font->logfont,sizeof(lf));
     lf.lfWidth  = font->logfont.lfWidth * dc->vportExtX/dc->wndExtX;
     lf.lfHeight = font->logfont.lfHeight* dc->vportExtY/dc->wndExtY;
 
-    dc->u.x.font = XFONT_RealizeFont( &lf );
+    physDev->font = XFONT_RealizeFont( &lf );
     hPrevFont = dc->w.hFont;
     dc->w.hFont = hfont;
 
@@ -2268,7 +2269,8 @@
 BOOL32 X11DRV_GetTextExtentPoint( DC *dc, LPCSTR str, INT32 count,
                                   LPSIZE32 size )
 {
-    fontObject* pfo = XFONT_GetFontObject( dc->u.x.font );
+    X11DRV_PDEVICE *physDev = (X11DRV_PDEVICE *)dc->physDev;
+    fontObject* pfo = XFONT_GetFontObject( physDev->font );
     if( pfo ) {
         if( !pfo->lpX11Trans ) {
 	    int dir, ascent, descent;
@@ -2307,9 +2309,11 @@
  */
 BOOL32 X11DRV_GetTextMetrics(DC *dc, TEXTMETRIC32A *metrics)
 {
-    if( CHECK_PFONT(dc->u.x.font) )
+    X11DRV_PDEVICE *physDev = (X11DRV_PDEVICE *)dc->physDev;
+
+    if( CHECK_PFONT(physDev->font) )
     {
-	fontObject* pfo = __PFONT(dc->u.x.font);
+	fontObject* pfo = __PFONT(physDev->font);
 	XFONT_GetTextMetric( pfo, metrics );
 
 	return TRUE;
@@ -2324,7 +2328,8 @@
 BOOL32 X11DRV_GetCharWidth( DC *dc, UINT32 firstChar, UINT32 lastChar,
                             LPINT32 buffer )
 {
-    fontObject* pfo = XFONT_GetFontObject( dc->u.x.font );
+    X11DRV_PDEVICE *physDev = (X11DRV_PDEVICE *)dc->physDev;
+    fontObject* pfo = XFONT_GetFontObject( physDev->font );
 
     if( pfo )
     {
diff --git a/include/bitmap.h b/include/bitmap.h
index 64765ef..e24e621 100644
--- a/include/bitmap.h
+++ b/include/bitmap.h
@@ -8,6 +8,8 @@
 #define __WINE_BITMAP_H
 
 #include "gdi.h"
+#include "ts_xlib.h"
+#include "ts_xutil.h"
 
   /* Additional info for DIB section objects */
 typedef struct
diff --git a/include/color.h b/include/color.h
index 949c180..e699e82 100644
--- a/include/color.h
+++ b/include/color.h
@@ -3,6 +3,7 @@
 
 #include "palette.h"
 #include "gdi.h"
+#include "x11drv.h"
 
 #define COLOR_FIXED     0x0001          /* read-only colormap - have to use XAllocColor (if not virtual)*/
 #define COLOR_VIRTUAL   0x0002          /* no mapping needed - pixel == pixel color */
diff --git a/include/gdi.h b/include/gdi.h
index 066fd4e..e7717a5 100644
--- a/include/gdi.h
+++ b/include/gdi.h
@@ -10,7 +10,6 @@
 #include "windows.h"
 #include "ldt.h"
 #include "local.h"
-#include "x11drv.h"
 #include "path.h"
 #include <math.h>
 
@@ -139,8 +138,6 @@
     BOOL32        vport2WorldValid;  /* Is xformVport2World valid? */
 } WIN_DC_INFO;
 
-typedef X11DRV_PDEVICE X_DC_INFO;  /* Temporary */
-
 typedef struct tagDC
 {
     GDIOBJHDR      header;
@@ -161,14 +158,12 @@
     INT32          vportExtY;
 
     WIN_DC_INFO w;
-    union
-    {
-	X_DC_INFO x;
-	/* other devices (e.g. printer) */
-    } u;
 } DC;
 
 /* Device functions for the Wine driver interface */
+
+typedef INT32 (*DEVICEFONTENUMPROC)(LPENUMLOGFONT16,LPNEWTEXTMETRIC16,UINT16,LPARAM);
+
 typedef struct tagDC_FUNCS
 {
     BOOL32     (*pArc)(DC*,INT32,INT32,INT32,INT32,INT32,INT32,INT32,INT32);
@@ -432,11 +427,4 @@
 extern const DC_FUNCTIONS *DRIVER_FindDriver( LPCSTR name );
 extern BOOL32 DRIVER_UnregisterDriver( LPCSTR name );
 
-extern BOOL32 DIB_Init(void);
-
-extern Display * display;
-extern Screen * screen;
-extern Window rootWindow;
-extern int screenWidth, screenHeight, screenDepth;
-
 #endif  /* __WINE_GDI_H */
diff --git a/include/x11drv.h b/include/x11drv.h
index 1f7aef2..186227c 100644
--- a/include/x11drv.h
+++ b/include/x11drv.h
@@ -9,6 +9,7 @@
 #include "ts_xutil.h"
 #include "winbase.h"
 #include "windows.h"
+#include "gdi.h"
 #include "xmalloc.h" /* for XCREATEIMAGE macro */
 
   /* X physical pen */
@@ -59,7 +60,6 @@
 #define BITMAP_GC(bmp) \
   (((bmp)->bitmap.bmBitsPixel == 1) ? BITMAP_monoGC : BITMAP_colorGC)
 
-typedef INT32 (*DEVICEFONTENUMPROC)(LPENUMLOGFONT16,LPNEWTEXTMETRIC16,UINT16,LPARAM);
 
 /* Wine driver X11 functions */
 
@@ -158,6 +158,12 @@
 
 extern const int X11DRV_XROPfunction[];
 
+extern Display * display;
+extern Screen * screen;
+extern Window rootWindow;
+extern int screenWidth, screenHeight, screenDepth;
+
+
 /* Xlib critical section */
 
 extern CRITICAL_SECTION X11DRV_CritSection;
diff --git a/include/x11font.h b/include/x11font.h
index 268fe1a..df63728 100644
--- a/include/x11font.h
+++ b/include/x11font.h
@@ -8,7 +8,7 @@
 #define __WINE_X11FONT_H
 
 #include "gdi.h"
-
+#include "x11drv.h"
 #pragma pack(1)
 
 /* this is a part of the font resource header, should 
diff --git a/misc/main.c b/misc/main.c
index f469d49..3905e9d 100644
--- a/misc/main.c
+++ b/misc/main.c
@@ -34,6 +34,7 @@
 #include "xmalloc.h"
 #include "version.h"
 #include "winnls.h"
+#include "x11drv.h"
 
 /* when adding new languages look at ole/ole2nls.c 
  * for proper iso name and Windows code (add 0x0400 
diff --git a/objects/bitmap.c b/objects/bitmap.c
index 3e446c3..2218e3b 100644
--- a/objects/bitmap.c
+++ b/objects/bitmap.c
@@ -16,7 +16,7 @@
 #include "cursoricon.h"
 #include "color.h"
 #include "debug.h"
-
+#include "x11drv.h"
 
 /***********************************************************************
  *           BITMAP_GetPadding
diff --git a/objects/color.c b/objects/color.c
index d7f4604..c46fa1d 100644
--- a/objects/color.c
+++ b/objects/color.c
@@ -14,6 +14,7 @@
 #include "color.h"
 #include "debug.h"
 #include "xmalloc.h"
+#include "x11drv.h"
 
 /* Palette indexed mode:
 
diff --git a/objects/dc.c b/objects/dc.c
index 10532c2..2ea4f56 100644
--- a/objects/dc.c
+++ b/objects/dc.c
@@ -14,7 +14,7 @@
 #include "debug.h"
 #include "font.h"
 #include "winerror.h"
-
+#include "x11drv.h"
 
 /***********************************************************************
  *           DC_Init_DC_INFO
@@ -221,7 +221,6 @@
 
     TRACE(dc, "(%04x): returning %04x\n", hdc, handle );
 
-    memset( &newdc->u.x, 0, sizeof(newdc->u.x) );
     newdc->w.flags            = dc->w.flags | DC_SAVED;
     newdc->w.devCaps          = dc->w.devCaps;
     newdc->w.hPen             = dc->w.hPen;       
@@ -854,15 +853,18 @@
 BOOL32 WINAPI GetDCOrgEx( HDC32 hDC, LPPOINT32 lpp )
 {
     DC * dc;
+    X11DRV_PDEVICE *physDev;
+
     if (!lpp) return FALSE;
     if (!(dc = (DC *) GDI_GetObjPtr( hDC, DC_MAGIC ))) return FALSE;
+    physDev = (X11DRV_PDEVICE *)dc->physDev;
 
     if (!(dc->w.flags & DC_MEMORY))
     {
        Window root;
        int w, h, border, depth;
        /* FIXME: this is not correct for managed windows */
-       TSXGetGeometry( display, dc->u.x.drawable, &root,
+       TSXGetGeometry( display, physDev->drawable, &root,
                     &lpp->x, &lpp->y, &w, &h, &border, &depth );
     }
     else lpp->x = lpp->y = 0;
diff --git a/objects/gdiobj.c b/objects/gdiobj.c
index 633bd83..eba145a 100644
--- a/objects/gdiobj.c
+++ b/objects/gdiobj.c
@@ -16,7 +16,7 @@
 #include "region.h"
 #include "debug.h"
 #include "gdi.h"
-
+#include "x11drv.h"
 
 /***********************************************************************
  *          GDI stock objects 
diff --git a/windows/dce.c b/windows/dce.c
index fbb8e09..910e2a4 100644
--- a/windows/dce.c
+++ b/windows/dce.c
@@ -26,6 +26,7 @@
 #include "heap.h"
 #include "sysmetrics.h"
 #include "debug.h"
+#include "x11drv.h"
 
 #define NB_DCE    5  /* Number of DCEs created at startup */
 
@@ -522,12 +523,14 @@
  */
 static void DCE_SetDrawable( WND *wndPtr, DC *dc, WORD flags, BOOL32 bSetClipOrigin )
 {
+    X11DRV_PDEVICE *physDev = (X11DRV_PDEVICE *)dc->physDev;
+
     if (!wndPtr)  /* Get a DC for the whole screen */
     {
         dc->w.DCOrgX = 0;
         dc->w.DCOrgY = 0;
-        dc->u.x.drawable = rootWindow;
-        TSXSetSubwindowMode( display, dc->u.x.gc, IncludeInferiors );
+        physDev->drawable = rootWindow;
+        TSXSetSubwindowMode( display, physDev->gc, IncludeInferiors );
     }
     else
     {
@@ -549,7 +552,7 @@
         }
         dc->w.DCOrgX -= wndPtr->rectWindow.left;
         dc->w.DCOrgY -= wndPtr->rectWindow.top;
-        dc->u.x.drawable = wndPtr->window;
+        physDev->drawable = wndPtr->window;
 
 #if 0
 	/* This is needed when we reuse a cached DC because
@@ -558,7 +561,7 @@
 	 */
 
 	if( bSetClipOrigin )
-	    TSXSetClipOrigin( display, dc->u.x.gc, dc->w.DCOrgX, dc->w.DCOrgY );
+	    TSXSetClipOrigin( display, physDev->gc, dc->w.DCOrgX, dc->w.DCOrgY );
 #endif
     }
 }
diff --git a/windows/display.c b/windows/display.c
index 4e82512..c34a145 100644
--- a/windows/display.c
+++ b/windows/display.c
@@ -20,6 +20,7 @@
 #include "heap.h"
 #include "debug.h"
 #include "debugtools.h"
+#include "x11drv.h"
 
 Cursor DISPLAY_XCursor = None;    /* Current X cursor */
 
diff --git a/windows/event.c b/windows/event.c
index d520fd7..3c96220 100644
--- a/windows/event.c
+++ b/windows/event.c
@@ -41,7 +41,7 @@
 #include "dde_proc.h"
 #include "winsock.h"
 #include "mouse.h"
-
+#include "x11drv.h"
 
 #define NB_BUTTONS      3     /* Windows can handle 3 buttons */
 
diff --git a/windows/graphics.c b/windows/graphics.c
index fe9a6b6..66104f9 100644
--- a/windows/graphics.c
+++ b/windows/graphics.c
@@ -15,6 +15,7 @@
 #include "bitmap.h"
 #include "gdi.h"
 #include "dc.h"
+#include "x11drv.h"
 
 #define MAX_DRAWLINES 8
 
@@ -33,6 +34,7 @@
     if( (dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC )) )
     {
 	HPEN32  hPrevPen  = 0;
+	X11DRV_PDEVICE *physDev = (X11DRV_PDEVICE *)dc->physDev;
 
 	if( hPen ) hPrevPen = SelectObject32( hdc, hPen );
 	if( X11DRV_SetupGCForPen( dc ) )
@@ -48,7 +50,7 @@
 		 l[i].y1 = pXY[j].y + dc->w.DCOrgY;
 		 l[i].y2 = pXY[j + 1].y + dc->w.DCOrgY;
 	    }
-	    TSXDrawSegments( display, dc->u.x.drawable, dc->u.x.gc, l, N );
+	    TSXDrawSegments( display, physDev->drawable, physDev->gc, l, N );
 	    bRet = TRUE;
 	}
 	if( hPrevPen ) SelectObject32( hdc, hPrevPen );
@@ -72,6 +74,7 @@
     DC *dc;
     BOOL32 ret = TRUE;
     X11DRV_PHYSBITMAP *pbitmap;
+    X11DRV_PDEVICE *physDev;
 
     if (!(dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC ))) return FALSE;
     if (!(bmp = (BITMAPOBJ *) GDI_GetObjPtr( hbitmap, BITMAP_MAGIC )))
@@ -79,6 +82,7 @@
         GDI_HEAP_UNLOCK( hdc );
         return FALSE;
     }
+    physDev = (X11DRV_PDEVICE *)dc->physDev;
 
     /* HACK for now */
     if(!bmp->DDBitmap)
@@ -87,12 +91,12 @@
 
     xdest += dc->w.DCOrgX; ydest += dc->w.DCOrgY;
 
-    TSXSetFunction( display, dc->u.x.gc, GXcopy );
+    TSXSetFunction( display, physDev->gc, GXcopy );
     if (bmp->bitmap.bmBitsPixel == 1)
     {
-        TSXSetForeground( display, dc->u.x.gc, dc->u.x.backgroundPixel );
-        TSXSetBackground( display, dc->u.x.gc, dc->u.x.textPixel );
-        TSXCopyPlane( display, pbitmap->pixmap, dc->u.x.drawable, dc->u.x.gc,
+        TSXSetForeground( display, physDev->gc, physDev->backgroundPixel );
+        TSXSetBackground( display, physDev->gc, physDev->textPixel );
+        TSXCopyPlane( display, pbitmap->pixmap, physDev->drawable, physDev->gc,
                     xsrc, ysrc, width, height, xdest, ydest, 1 );
     }
     else if (bmp->bitmap.bmBitsPixel == dc->w.bitsPerPixel)
@@ -103,21 +107,25 @@
 
 	    if( COLOR_GetMonoPlane(&plane) )
 	    {
-		TSXSetForeground(display, dc->u.x.gc, dc->u.x.backgroundPixel);
-		TSXSetBackground(display, dc->u.x.gc, dc->u.x.textPixel);
+		TSXSetForeground( display, physDev->gc,
+				  physDev->backgroundPixel );
+		TSXSetBackground( display, physDev->gc, physDev->textPixel );
 	    }
 	    else
 	    {
-		TSXSetForeground(display, dc->u.x.gc, dc->u.x.textPixel);
-		TSXSetBackground(display, dc->u.x.gc, dc->u.x.backgroundPixel);
+		TSXSetForeground( display, physDev->gc, physDev->textPixel );
+		TSXSetBackground( display, physDev->gc,
+				  physDev->backgroundPixel );
 	    }
-	    TSXCopyPlane( display, pbitmap->pixmap, dc->u.x.drawable, dc->u.x.gc,
-			xsrc, ysrc, width, height, xdest, ydest, plane );
+	    TSXCopyPlane( display, pbitmap->pixmap, physDev->drawable,
+			  physDev->gc, xsrc, ysrc, width, height, xdest, ydest,
+			  plane );
 	}
 	else 
 	{
-	    TSXCopyArea( display, pbitmap->pixmap, dc->u.x.drawable, 
-		       dc->u.x.gc, xsrc, ysrc, width, height, xdest, ydest );
+	    TSXCopyArea( display, pbitmap->pixmap, physDev->drawable, 
+			 physDev->gc, xsrc, ysrc, width, height, xdest,
+			 ydest );
 	}
     }
     else 
@@ -170,9 +178,10 @@
     HBRUSH32 	hPrevBrush;
     INT32 	w, h;
     RECT32	r = *rect;
+    X11DRV_PDEVICE *physDev;
 
     if (!(dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC ))) return;
-
+    physDev = (X11DRV_PDEVICE *)dc->physDev;
     OffsetRect32( &r, dc->w.DCOrgX, dc->w.DCOrgY);
     h = rect->bottom - rect->top;  w = rect->right - rect->left;
 
@@ -182,12 +191,12 @@
     {
          INT32	i;
 
-	 TSXSetFunction( display, dc->u.x.gc, GXcopy );
+	 TSXSetFunction( display, physDev->gc, GXcopy );
          for (i = 0; i < highlight_size; i++)
          {
-	      TSXFillRectangle( display, dc->u.x.drawable, dc->u.x.gc,
+	      TSXFillRectangle( display, physDev->drawable, physDev->gc,
 					r.left + i, r.top, 1, h - i );
-	      TSXFillRectangle( display, dc->u.x.drawable, dc->u.x.gc,
+	      TSXFillRectangle( display, physDev->drawable, physDev->gc,
 					r.left, r.top + i, w - i, 1 );
          }
     }
@@ -197,12 +206,12 @@
     {
 	 INT32	i;
 
-	 TSXSetFunction( display, dc->u.x.gc, GXcopy );
+	 TSXSetFunction( display, physDev->gc, GXcopy );
          for (i = 0; i < shadow_size; i++)
          {
-	      TSXFillRectangle( display, dc->u.x.drawable, dc->u.x.gc,
+	      TSXFillRectangle( display, physDev->drawable, physDev->gc,
 			      r.right - i - 1, r.top + i, 1, h - i );
-	      TSXFillRectangle( display, dc->u.x.drawable, dc->u.x.gc,
+	      TSXFillRectangle( display, physDev->drawable, physDev->gc,
 			      r.left + i, r.bottom - i - 1, w - i, 1 );
          }
     }
@@ -224,10 +233,11 @@
     if( (dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC )) ) 
     {
         HPEN32	hPrevPen  = 0; 
+	X11DRV_PDEVICE *physDev = (X11DRV_PDEVICE *)dc->physDev;
 
 	if( hPen ) hPrevPen = SelectObject32( hdc, hPen );
 	if( X11DRV_SetupGCForPen( dc ) )
-	    TSXDrawRectangle( display, dc->u.x.drawable, dc->u.x.gc, 
+	    TSXDrawRectangle( display, physDev->drawable, physDev->gc, 
 			    x + dc->w.DCOrgX, y + dc->w.DCOrgY, w - 1, h - 1);
 	if( hPrevPen ) SelectObject32( hdc, hPrevPen );
 	GDI_HEAP_UNLOCK( hdc );
@@ -242,8 +252,10 @@
     BITMAPOBJ *bmp = NULL;
     DC *dc;
     X11DRV_PHYSBITMAP *pbitmap = NULL;
+    X11DRV_PDEVICE *physDev;
 
     if (!(dc = (DC *) GDI_GetObjPtr( hdc, DC_MAGIC ))) return FALSE;
+    physDev = (X11DRV_PDEVICE *)dc->physDev;
     if ( hMonoBitmap ) 
     {
        if ( !(bmp = (BITMAPOBJ *) GDI_GetObjPtr( hMonoBitmap, BITMAP_MAGIC)) 
@@ -257,10 +269,11 @@
        if(!bmp->DDBitmap)
 	   X11DRV_CreateBitmap( hMonoBitmap );
        pbitmap = bmp->DDBitmap->physBitmap;
-       TSXSetClipOrigin( display, dc->u.x.gc, dc->w.DCOrgX + x, dc->w.DCOrgY + y);
+       TSXSetClipOrigin( display, physDev->gc, dc->w.DCOrgX + x,
+			 dc->w.DCOrgY + y );
     }
 
-    TSXSetClipMask( display, dc->u.x.gc, (bmp) ? pbitmap->pixmap : None );
+    TSXSetClipMask( display, physDev->gc, (bmp) ? pbitmap->pixmap : None );
 
     GDI_HEAP_UNLOCK( hdc );
     GDI_HEAP_UNLOCK( hMonoBitmap );
diff --git a/windows/input.c b/windows/input.c
index 10e5623..e38e90e 100644
--- a/windows/input.c
+++ b/windows/input.c
@@ -26,6 +26,7 @@
 #include "debugtools.h"
 #include "struct32.h"
 #include "winerror.h"
+#include "x11drv.h"
 
 static INT16  captureHT = HTCLIENT;
 static HWND32 captureWnd = 0;
diff --git a/windows/mouse.c b/windows/mouse.c
index 47f1094..7f9047d 100644
--- a/windows/mouse.c
+++ b/windows/mouse.c
@@ -11,7 +11,7 @@
 #include "mouse.h"
 #include "debug.h"
 #include "debugtools.h"
-
+#include "x11drv.h"
 
 static LPMOUSE_EVENT_PROC DefMouseEventProc = NULL;
 
diff --git a/windows/scroll.c b/windows/scroll.c
index 9f9062d..5bc814d 100644
--- a/windows/scroll.c
+++ b/windows/scroll.c
@@ -18,7 +18,7 @@
 #include "graphics.h"
 #include "sysmetrics.h"
 #include "debug.h"
-
+#include "x11drv.h"
 
 /*************************************************************************
  *             ScrollWindow16   (USER.61)
@@ -346,6 +346,7 @@
 		       ((flags & SW_SCROLLCHILDREN) ? DCX_NOCLIPCHILDREN : 0) );
 	if( (dc = (DC *)GDI_GetObjPtr(hDC, DC_MAGIC)) )
 	{
+	    X11DRV_PDEVICE *physDev = (X11DRV_PDEVICE *)dc->physDev;
 	    POINT32 dst, src;
 
 	    if( dx > 0 ) dst.x = (src.x = dc->w.DCOrgX + cliprc.left) + dx;
@@ -358,13 +359,15 @@
                 (cliprc.bottom - cliprc.top > abs(dy)))
             {
                 if (bUpdate) /* handles non-Wine windows hanging over the scrolled area */
-                    TSXSetGraphicsExposures( display, dc->u.x.gc, True );
-                TSXSetFunction( display, dc->u.x.gc, GXcopy );
-                TSXCopyArea( display, dc->u.x.drawable, dc->u.x.drawable, dc->u.x.gc, 
-                             src.x, src.y, cliprc.right - cliprc.left - abs(dx),
-                             cliprc.bottom - cliprc.top - abs(dy), dst.x, dst.y );
+                    TSXSetGraphicsExposures( display, physDev->gc, True );
+                TSXSetFunction( display, physDev->gc, GXcopy );
+                TSXCopyArea( display, physDev->drawable, physDev->drawable,
+			     physDev->gc, src.x, src.y,
+			     cliprc.right - cliprc.left - abs(dx),
+                             cliprc.bottom - cliprc.top - abs(dy),
+			     dst.x, dst.y );
                 if (bUpdate)
-                    TSXSetGraphicsExposures( display, dc->u.x.gc, False );
+                    TSXSetGraphicsExposures( display, physDev->gc, False );
             }
 
 	    if( dc->w.hVisRgn && bUpdate )
diff --git a/windows/sysmetrics.c b/windows/sysmetrics.c
index 7acd305..6b626a6 100644
--- a/windows/sysmetrics.c
+++ b/windows/sysmetrics.c
@@ -10,6 +10,7 @@
 #include "options.h"
 #include "tweak.h"
 #include "sysmetrics.h"
+#include "x11drv.h"
 
 short sysMetrics[SM_CMETRICS+1];
 
diff --git a/windows/user.c b/windows/user.c
index eedd30a..33a4223 100644
--- a/windows/user.c
+++ b/windows/user.c
@@ -25,6 +25,7 @@
 #include "queue.h"
 #include "shell.h"
 #include "callback.h"
+#include "x11drv.h"
 
 /***********************************************************************
  *           GetFreeSystemResources   (USER.284)