diff --git a/dlls/x11drv/dga2.c b/dlls/x11drv/dga2.c
index 234c0614bf78c1d351ce72a6aab1a3124c2902e5..3ed01c1b66c247c5be79eaf9a0a9e5e8773581cf 100644
--- a/dlls/x11drv/dga2.c
+++ b/dlls/x11drv/dga2.c
@@ -23,7 +23,8 @@
 #ifdef HAVE_LIBXXF86DGA2
 
 #include "ts_xlib.h"
-#include "ts_xf86dga2.h"
+#include <X11/extensions/xf86dga.h>
+
 #include "x11drv.h"
 #include "x11ddraw.h"
 #include "dga2.h"
@@ -75,25 +76,31 @@ void X11DRV_XF86DGA2_Init(void)
 
   if (!usedga) return;
 
-  if (!TSXDGAQueryExtension(gdi_display, &dga_event, &dga_error)) return;
-
-  X11DRV_expect_error(gdi_display, DGA2ErrorHandler, NULL);
-  ok = TSXDGAQueryVersion(gdi_display, &major, &minor);
-  if (X11DRV_check_error()) ok = FALSE;
+  wine_tsx11_lock();
+  ok = XDGAQueryExtension(gdi_display, &dga_event, &dga_error);
+  if (ok)
+  {
+      X11DRV_expect_error(gdi_display, DGA2ErrorHandler, NULL);
+      ok = XDGAQueryVersion(gdi_display, &major, &minor);
+      if (X11DRV_check_error()) ok = FALSE;
+  }
+  wine_tsx11_unlock();
   if (!ok) return;
 
   if (major < 2) return; /* only bother with DGA 2+ */
 
   /* test that it works */
-  if (!TSXDGAOpenFramebuffer(gdi_display, DefaultScreen(gdi_display))) {
-    WARN("disabling XF86DGA2 (insufficient permissions?)\n");
-    return;
+  wine_tsx11_lock();
+  if ((ok = XDGAOpenFramebuffer(gdi_display, DefaultScreen(gdi_display))))
+  {
+      XDGACloseFramebuffer(gdi_display, DefaultScreen(gdi_display));
+      /* retrieve modes */
+      modes = XDGAQueryModes(gdi_display, DefaultScreen(gdi_display), &nmodes);
+      if (!modes) ok = FALSE;
   }
-  TSXDGACloseFramebuffer(gdi_display, DefaultScreen(gdi_display));
-
-  /* retrieve modes */
-  modes = TSXDGAQueryModes(gdi_display, DefaultScreen(gdi_display), &nmodes);
-  if (!modes) return;
+  else WARN("disabling XF86DGA2 (insufficient permissions?)\n");
+  wine_tsx11_unlock();
+  if (!ok) return;
 
   TRACE("DGA modes: count=%d\n", nmodes);
 
@@ -128,18 +135,19 @@ static DWORD PASCAL X11DRV_XF86DGA2_SetMode(LPDDHAL_SETMODEDATA data)
   Display *display = gdi_display;
 
   data->ddRVal = DD_OK;
+  wine_tsx11_lock();
   if (data->dwModeIndex) {
     /* enter DGA */
     XDGADevice *new_dev = NULL;
-    if (dga_dev || TSXDGAOpenFramebuffer(display, DefaultScreen(display)))
-      new_dev = TSXDGASetMode(display, DefaultScreen(display), modes[data->dwModeIndex-1].num);
+    if (dga_dev || XDGAOpenFramebuffer(display, DefaultScreen(display)))
+      new_dev = XDGASetMode(display, DefaultScreen(display), modes[data->dwModeIndex-1].num);
     if (new_dev) {
-      TSXDGASetViewport(display, DefaultScreen(display), 0, 0, XDGAFlipImmediate);
+      XDGASetViewport(display, DefaultScreen(display), 0, 0, XDGAFlipImmediate);
       if (dga_dev) {
 	VirtualFree(dga_dev->data, 0, MEM_RELEASE);
-	TSXFree(dga_dev);
+	XFree(dga_dev);
       } else {
-	TSXDGASelectInput(display, DefaultScreen(display),
+	XDGASelectInput(display, DefaultScreen(display),
 			  KeyPressMask|KeyReleaseMask|
 			  ButtonPressMask|ButtonReleaseMask|
 			  PointerMotionMask);
@@ -157,7 +165,7 @@ static DWORD PASCAL X11DRV_XF86DGA2_SetMode(LPDDHAL_SETMODEDATA data)
     }
     else {
       ERR("failed\n");
-      if (!dga_dev) TSXDGACloseFramebuffer(display, DefaultScreen(display));
+      if (!dga_dev) XDGACloseFramebuffer(display, DefaultScreen(display));
       data->ddRVal = DDERR_GENERIC;
     }
   }
@@ -165,14 +173,15 @@ static DWORD PASCAL X11DRV_XF86DGA2_SetMode(LPDDHAL_SETMODEDATA data)
     /* exit DGA */
     X11DRV_DD_IsDirect = FALSE;
     X11DRV_DDHAL_SwitchMode(0, NULL, NULL);
-    TSXDGASetMode(display, DefaultScreen(display), 0);
+    XDGASetMode(display, DefaultScreen(display), 0);
     VirtualFree(dga_dev->data, 0, MEM_RELEASE);
     X11DRV_EVENT_SetInputMethod(X11DRV_INPUT_ABSOLUTE);
     X11DRV_EVENT_SetDGAStatus(0, -1);
-    TSXFree(dga_dev);
-    TSXDGACloseFramebuffer(display, DefaultScreen(display));
+    XFree(dga_dev);
+    XDGACloseFramebuffer(display, DefaultScreen(display));
     dga_dev = NULL;
   }
+  wine_tsx11_unlock();
   return DDHAL_DRIVER_HANDLED;
 }
 
@@ -198,7 +207,10 @@ static DWORD PASCAL X11DRV_XF86DGA2_CreateSurface(LPDDHAL_CREATESURFACEDATA data
 static DWORD PASCAL X11DRV_XF86DGA2_CreatePalette(LPDDHAL_CREATEPALETTEDATA data)
 {
   Display *display = gdi_display;
-  data->lpDDPalette->u1.dwReserved1 = TSXDGACreateColormap(display, DefaultScreen(display), dga_dev, AllocAll);
+  wine_tsx11_lock();
+  data->lpDDPalette->u1.dwReserved1 = XDGACreateColormap(display, DefaultScreen(display),
+                                                         dga_dev, AllocAll);
+  wine_tsx11_unlock();
   if (data->lpColorTable)
     X11DRV_DDHAL_SetPalEntries(data->lpDDPalette->u1.dwReserved1, 0, 256,
 			       data->lpColorTable);
@@ -211,10 +223,12 @@ static DWORD PASCAL X11DRV_XF86DGA2_Flip(LPDDHAL_FLIPDATA data)
   Display *display = gdi_display;
   if (data->lpSurfCurr == X11DRV_DD_Primary) {
     DWORD ofs = data->lpSurfCurr->lpGbl->fpVidMem - dga_mem.fpStart;
-    TSXDGASetViewport(display, DefaultScreen(display),
-                      (ofs % dga_dev->mode.bytesPerScanline)*8/dga_dev->mode.bitsPerPixel,
-                      ofs / dga_dev->mode.bytesPerScanline,
-                      XDGAFlipImmediate);
+    wine_tsx11_lock();
+    XDGASetViewport(display, DefaultScreen(display),
+                    (ofs % dga_dev->mode.bytesPerScanline)*8/dga_dev->mode.bitsPerPixel,
+                    ofs / dga_dev->mode.bytesPerScanline,
+                    XDGAFlipImmediate);
+    wine_tsx11_unlock();
   }
   data->ddRVal = DD_OK;
   return DDHAL_DRIVER_HANDLED;
@@ -224,8 +238,11 @@ static DWORD PASCAL X11DRV_XF86DGA2_SetPalette(LPDDHAL_SETPALETTEDATA data)
 {
   Display *display = gdi_display;
   if ((data->lpDDSurface == X11DRV_DD_Primary) &&
-      data->lpDDPalette && data->lpDDPalette->u1.dwReserved1) {
-    TSXDGAInstallColormap(display, DefaultScreen(display), data->lpDDPalette->u1.dwReserved1);
+      data->lpDDPalette && data->lpDDPalette->u1.dwReserved1)
+  {
+      wine_tsx11_lock();
+      XDGAInstallColormap(display, DefaultScreen(display), data->lpDDPalette->u1.dwReserved1);
+      wine_tsx11_unlock();
   }
   data->ddRVal = DD_OK;
   return DDHAL_DRIVER_HANDLED;
diff --git a/dlls/x11drv/event.c b/dlls/x11drv/event.c
index dc6e9c374dc205a8a8db0f75aa0a36a0f42103ba..e14869407b0c864c6589d6a33976f09ff5f2ab91 100644
--- a/dlls/x11drv/event.c
+++ b/dlls/x11drv/event.c
@@ -25,9 +25,10 @@
 #include <X11/keysym.h>
 
 #include "ts_xlib.h"
-#include "ts_xutil.h"
+#include <X11/Xresource.h>
+#include <X11/Xutil.h>
 #ifdef HAVE_LIBXXF86DGA2
-#include "ts_xf86dga2.h"
+#include <X11/extensions/xf86dga.h>
 #endif
 
 #include <assert.h>
@@ -261,8 +262,10 @@ static void EVENT_ProcessEvent( XEvent *event )
   }
 #endif
 
-  if (TSXFindContext( display, event->xany.window, winContext, (char **)&hWnd ) != 0)
+  wine_tsx11_lock();
+  if (XFindContext( display, event->xany.window, winContext, (char **)&hWnd ) != 0)
       hWnd = 0;  /* Not for a registered window */
+  wine_tsx11_unlock();
 
   if ( !hWnd && event->xany.window != root_window
              && event->type != PropertyNotify
@@ -506,8 +509,16 @@ static void EVENT_FocusOut( HWND hwnd, XFocusChangeEvent *event )
     /* don't reset the foreground window, if the window which is
        getting the focus is a Wine window */
 
-    TSXGetInputFocus( thread_display(), &focus_win, &revert );
-    if (!focus_win || TSXFindContext( thread_display(), focus_win, winContext, (char **)&hwnd_tmp ))
+    wine_tsx11_lock();
+    XGetInputFocus( thread_display(), &focus_win, &revert );
+    if (focus_win)
+    {
+        if (XFindContext( thread_display(), focus_win, winContext, (char **)&hwnd_tmp ) != 0)
+            focus_win = 0;
+    }
+    wine_tsx11_unlock();
+
+    if (!focus_win)
     {
         /* Abey : 6-Oct-99. Check again if the focus out window is the
            Foreground window, because in most cases the messages sent
@@ -1389,9 +1400,13 @@ static void EVENT_ClientMessage( HWND hWnd, XClientMessageEvent *event )
         Window root, child;
         int root_x, root_y, child_x, child_y;
         unsigned int u;
-        TSXQueryPointer( event->display, root_window, &root, &child,
-                         &root_x, &root_y, &child_x, &child_y, &u);
-        if (TSXFindContext( event->display, child, winContext, (char **)&hWnd ) != 0) return;
+
+        wine_tsx11_lock();
+        XQueryPointer( event->display, root_window, &root, &child,
+                       &root_x, &root_y, &child_x, &child_y, &u);
+        if (XFindContext( event->display, child, winContext, (char **)&hWnd ) != 0) hWnd = 0;
+        wine_tsx11_unlock();
+        if (!hWnd) return;
         if (event->data.l[0] == DndFile || event->data.l[0] == DndFiles)
             EVENT_DropFromOffiX(hWnd, event);
         else if (event->data.l[0] == DndURL)
diff --git a/dlls/x11drv/keyboard.c b/dlls/x11drv/keyboard.c
index 8b708959f71f0a410fbc9b3096c1a60c9e8aed64..15523e56572da74838207bd596e860e6d95df843 100644
--- a/dlls/x11drv/keyboard.c
+++ b/dlls/x11drv/keyboard.c
@@ -29,7 +29,8 @@
 #include <X11/keysym.h>
 
 #include "ts_xlib.h"
-#include "ts_xutil.h"
+#include <X11/Xresource.h>
+#include <X11/Xutil.h>
 #ifdef HAVE_XKB
 #include <X11/XKBlib.h>
 #endif
@@ -779,11 +780,12 @@ static const WORD nonchar_key_scan[256] =
 
 
 /* Returns the Windows virtual key code associated with the X event <e> */
+/* x11 lock must be held */
 static WORD EVENT_event_to_vkey( XKeyEvent *e)
 {
     KeySym keysym;
 
-    TSXLookupString(e, NULL, 0, &keysym, NULL);
+    XLookupString(e, NULL, 0, &keysym, NULL);
 
     if ((keysym >= 0xFFAE) && (keysym <= 0xFFB9) && (keysym != 0xFFAF)
 	&& (e->state & NumLockMask))
@@ -934,7 +936,9 @@ void X11DRV_KeyEvent( HWND hwnd, XKeyEvent *event )
     if ((event->keycode >> 8) == 0x10)
 	event->keycode=(event->keycode & 0xff);
 
-    ascii_chars = TSXLookupString(event, Str, sizeof(Str), &keysym, NULL);
+    wine_tsx11_lock();
+    ascii_chars = XLookupString(event, Str, sizeof(Str), &keysym, NULL);
+    wine_tsx11_unlock();
 
     /* Ignore some unwanted events */
     if (keysym == XK_ISO_Prev_Group ||
@@ -970,7 +974,9 @@ void X11DRV_KeyEvent( HWND hwnd, XKeyEvent *event )
                     keysym, ksname, ascii_chars, Str[0] & 0xff, Str);
     }
 
+    wine_tsx11_lock();
     vkey = EVENT_event_to_vkey(event);
+    wine_tsx11_unlock();
 
     TRACE_(key)("keycode 0x%x converted to vkey 0x%x\n",
                 event->keycode, vkey);
@@ -1024,6 +1030,7 @@ void X11DRV_KeyEvent( HWND hwnd, XKeyEvent *event )
  * Called from X11DRV_InitKeyboard
  *  This routine walks through the defined keyboard layouts and selects
  *  whichever matches most closely.
+ * X11 lock must be held.
  */
 static void
 X11DRV_KEYBOARD_DetectLayout (void)
@@ -1054,7 +1061,7 @@ X11DRV_KEYBOARD_DetectLayout (void)
     for (keyc = min_keycode; keyc <= max_keycode; keyc++) {
       /* get data for keycode from X server */
       for (i = 0; i < syms; i++) {
-	keysym = TSXKeycodeToKeysym (display, keyc, i);
+	keysym = XKeycodeToKeysym (display, keyc, i);
 	/* Allow both one-byte and two-byte national keysyms */
 	if ((keysym < 0x8000) && (keysym != ' '))
 	  ckey[i] = keysym & 0xFF;
@@ -1140,8 +1147,8 @@ void X11DRV_InitKeyboard( BYTE *key_state_table )
 
     pKeyStateTable = key_state_table;
 
-#ifdef HAVE_XKB
     wine_tsx11_lock();
+#ifdef HAVE_XKB
     is_xkb = XkbQueryExtension(display,
                                &xkb_opcode, &xkb_event, &xkb_error,
                                &xkb_major, &xkb_minor);
@@ -1149,15 +1156,15 @@ void X11DRV_InitKeyboard( BYTE *key_state_table )
         /* we have XKB, approximate Windows behaviour */
         XkbSetDetectableAutoRepeat(display, True, NULL);
     }
-    wine_tsx11_unlock();
 #endif
-    TSXDisplayKeycodes(display, &min_keycode, &max_keycode);
-    ksp = TSXGetKeyboardMapping(display, min_keycode,
+    XDisplayKeycodes(display, &min_keycode, &max_keycode);
+    ksp = XGetKeyboardMapping(display, min_keycode,
                               max_keycode + 1 - min_keycode, &keysyms_per_keycode);
     /* We are only interested in keysyms_per_keycode.
        There is no need to hold a local copy of the keysyms table */
-    TSXFree(ksp);
-    mmp = TSXGetModifierMapping(display);
+    XFree(ksp);
+
+    mmp = XGetModifierMapping(display);
     kcp = mmp->modifiermap;
     for (i = 0; i < 8; i += 1) /* There are 8 modifier keys */
     {
@@ -1169,14 +1176,14 @@ void X11DRV_InitKeyboard( BYTE *key_state_table )
 		int k;
 
 		for (k = 0; k < keysyms_per_keycode; k += 1)
-                    if (TSXKeycodeToKeysym(display, *kcp, k) == XK_Num_Lock)
+                    if (XKeycodeToKeysym(display, *kcp, k) == XK_Num_Lock)
 		    {
                         NumLockMask = 1 << i;
                         TRACE_(key)("NumLockMask is %x\n", NumLockMask);
 		    }
             }
     }
-    TSXFreeModifiermap(mmp);
+    XFreeModifiermap(mmp);
 
     /* Detect the keyboard layout */
     X11DRV_KEYBOARD_DetectLayout();
@@ -1194,7 +1201,7 @@ void X11DRV_InitKeyboard( BYTE *key_state_table )
     for (keyc = min_keycode; keyc <= max_keycode; keyc++)
     {
         e2.keycode = (KeyCode)keyc;
-        TSXLookupString(&e2, NULL, 0, &keysym, NULL);
+        XLookupString(&e2, NULL, 0, &keysym, NULL);
         vkey = 0; scan = 0;
         if (keysym)  /* otherwise, keycode not used */
         {
@@ -1211,7 +1218,7 @@ void X11DRV_InitKeyboard( BYTE *key_state_table )
 	      /* we seem to need to search the layout-dependent scancodes */
 	      int maxlen=0,maxval=-1,ok;
 	      for (i=0; i<syms; i++) {
-		keysym = TSXKeycodeToKeysym(display, keyc, i);
+		keysym = XKeycodeToKeysym(display, keyc, i);
 		if ((keysym<0x800) && (keysym!=' ')) {
 		  ckey[i] = keysym & 0xFF;
 		} else {
@@ -1240,7 +1247,7 @@ void X11DRV_InitKeyboard( BYTE *key_state_table )
 	    /* (most Winelib apps ought to be able to work without layout tables!) */
             for (i = 0; (i < keysyms_per_keycode) && (!vkey); i++)
             {
-                keysym = TSXLookupKeysym(&e2, i);
+                keysym = XLookupKeysym(&e2, i);
                 if ((keysym >= VK_0 && keysym <= VK_9)
                     || (keysym >= VK_A && keysym <= VK_Z)) {
 		    vkey = keysym;
@@ -1249,7 +1256,7 @@ void X11DRV_InitKeyboard( BYTE *key_state_table )
 
             for (i = 0; (i < keysyms_per_keycode) && (!vkey); i++)
             {
-                keysym = TSXLookupKeysym(&e2, i);
+                keysym = XLookupKeysym(&e2, i);
 		switch (keysym)
 		{
 		case ';':             vkey = VK_OEM_1; break;
@@ -1288,8 +1295,8 @@ void X11DRV_InitKeyboard( BYTE *key_state_table )
                     {
                         char	*ksname;
 
-                        keysym = TSXLookupKeysym(&e2, i);
-                        ksname = TSXKeysymToString(keysym);
+                        keysym = XLookupKeysym(&e2, i);
+                        ksname = XKeysymToString(keysym);
                         if (!ksname)
 			    ksname = "NoSymbol";
                         DPRINTF( "%lX (%s) ", keysym, ksname);
@@ -1306,8 +1313,8 @@ void X11DRV_InitKeyboard( BYTE *key_state_table )
     for (scan = 0x60, keyc = min_keycode; keyc <= max_keycode; keyc++)
       if (keyc2vkey[keyc]&&!keyc2scan[keyc]) {
 	char *ksname;
-	keysym = TSXKeycodeToKeysym(display, keyc, 0);
-	ksname = TSXKeysymToString(keysym);
+	keysym = XKeycodeToKeysym(display, keyc, 0);
+	ksname = XKeysymToString(keysym);
 	if (!ksname) ksname = "NoSymbol";
 
 	/* should make sure the scancode is unassigned here, but >=0x60 currently always is */
@@ -1317,12 +1324,13 @@ void X11DRV_InitKeyboard( BYTE *key_state_table )
       }
 
     /* Now store one keycode for each modifier. Used to simulate keypresses. */
-    kcControl = TSXKeysymToKeycode(display, XK_Control_L);
-    kcAlt = TSXKeysymToKeycode(display, XK_Alt_L);
-    if (!kcAlt) kcAlt = TSXKeysymToKeycode(display, XK_Meta_L);
-    kcShift = TSXKeysymToKeycode(display, XK_Shift_L);
-    kcNumLock = TSXKeysymToKeycode(display, XK_Num_Lock);
-    kcCapsLock = TSXKeysymToKeycode(display, XK_Caps_Lock);
+    kcControl = XKeysymToKeycode(display, XK_Control_L);
+    kcAlt = XKeysymToKeycode(display, XK_Alt_L);
+    if (!kcAlt) kcAlt = XKeysymToKeycode(display, XK_Meta_L);
+    kcShift = XKeysymToKeycode(display, XK_Shift_L);
+    kcNumLock = XKeysymToKeycode(display, XK_Num_Lock);
+    kcCapsLock = XKeysymToKeycode(display, XK_Caps_Lock);
+    wine_tsx11_unlock();
 }
 
 
@@ -1432,6 +1440,8 @@ UINT X11DRV_MapVirtualKey(UINT wCode, UINT wMapType)
 			/* LockMask should behave exactly like caps lock - upercase
 			 * the letter keys and thats about it. */
 
+                        wine_tsx11_lock();
+
 			e.keycode = 0;
 			/* We exit on the first keycode found, to speed up the thing. */
 			for (keyc=min_keycode; (keyc<=max_keycode) && (!e.keycode) ; keyc++)
@@ -1447,22 +1457,27 @@ UINT X11DRV_MapVirtualKey(UINT wCode, UINT wMapType)
 			}
 
 			if ((wCode>=VK_NUMPAD0) && (wCode<=VK_NUMPAD9))
-			  e.keycode = TSXKeysymToKeycode(e.display, wCode-VK_NUMPAD0+XK_KP_0);
+			  e.keycode = XKeysymToKeycode(e.display, wCode-VK_NUMPAD0+XK_KP_0);
 
 			if (wCode==VK_DECIMAL)
-			  e.keycode = TSXKeysymToKeycode(e.display, XK_KP_Decimal);
+			  e.keycode = XKeysymToKeycode(e.display, XK_KP_Decimal);
 
 			if (!e.keycode)
 			{
 			  WARN("Unknown virtual key %X !!! \n", wCode);
+                          wine_tsx11_unlock();
 			  return 0; /* whatever */
 			}
 			TRACE("Found keycode %d (0x%2X)\n",e.keycode,e.keycode);
 
-			if (TSXLookupString(&e, s, 2, &keysym, NULL))
-			  returnMVK (*s);
+			if (XLookupString(&e, s, 2, &keysym, NULL))
+                        {
+                            wine_tsx11_unlock();
+                            returnMVK (*s);
+                        }
 
 			TRACE("returning no ANSI.\n");
+                        wine_tsx11_unlock();
 			return 0;
 			}
 
@@ -1715,6 +1730,7 @@ INT X11DRV_ToUnicode(UINT virtKey, UINT scanCode, LPBYTE lpKeyState,
 
     TRACE_(key)("(%04X, %04X) : faked state = %X\n",
 		virtKey, scanCode, e.state);
+    wine_tsx11_lock();
     /* We exit on the first keycode found, to speed up the thing. */
     for (keyc=min_keycode; (keyc<=max_keycode) && (!e.keycode) ; keyc++)
       { /* Find a keycode that could have generated this virtual key */
@@ -1729,19 +1745,22 @@ INT X11DRV_ToUnicode(UINT virtKey, UINT scanCode, LPBYTE lpKeyState,
       }
 
     if ((virtKey>=VK_NUMPAD0) && (virtKey<=VK_NUMPAD9))
-        e.keycode = TSXKeysymToKeycode(e.display, virtKey-VK_NUMPAD0+XK_KP_0);
+        e.keycode = XKeysymToKeycode(e.display, virtKey-VK_NUMPAD0+XK_KP_0);
 
     if (virtKey==VK_DECIMAL)
-        e.keycode = TSXKeysymToKeycode(e.display, XK_KP_Decimal);
+        e.keycode = XKeysymToKeycode(e.display, XK_KP_Decimal);
 
     if (!e.keycode)
       {
 	WARN("Unknown virtual key %X !!! \n",virtKey);
+        wine_tsx11_unlock();
 	return virtKey; /* whatever */
       }
     else TRACE("Found keycode %d (0x%2X)\n",e.keycode,e.keycode);
 
-    ret = TSXLookupString(&e, (LPVOID)lpChar, 2, &keysym, NULL);
+    ret = XLookupString(&e, (LPVOID)lpChar, 2, &keysym, NULL);
+    wine_tsx11_unlock();
+
     if (ret == 0)
 	{
 	BYTE dead_char;
diff --git a/dlls/x11drv/mouse.c b/dlls/x11drv/mouse.c
index 0aae64d07ed92a4b0e6b68e7f9685fdcaff50a94..40b0781a8ca0de552e2db262de401aa335eafbc1 100644
--- a/dlls/x11drv/mouse.c
+++ b/dlls/x11drv/mouse.c
@@ -22,7 +22,7 @@
 
 #include "ts_xlib.h"
 #ifdef HAVE_LIBXXF86DGA2
-#include "ts_xf86dga2.h"
+#include <X11/extensions/xf86dga.h>
 #endif
 
 #include "windef.h"
diff --git a/dlls/x11drv/scroll.c b/dlls/x11drv/scroll.c
index 0382390934576db3ee60f94964fa995757b61c7d..b147b2f99430a1781a924ff8727c654976edfbda 100644
--- a/dlls/x11drv/scroll.c
+++ b/dlls/x11drv/scroll.c
@@ -23,7 +23,6 @@
 #include "config.h"
 
 #include "ts_xlib.h"
-#include "ts_xutil.h"
 
 #include "winbase.h"
 #include "wingdi.h"
diff --git a/dlls/x11drv/window.c b/dlls/x11drv/window.c
index 3b5a33161ebcd52592899cb2c7a7ae1a7c5352d8..3f72793990e5f9371eb2da89f88a4fcbd63895fc 100644
--- a/dlls/x11drv/window.c
+++ b/dlls/x11drv/window.c
@@ -25,7 +25,8 @@
 #include <stdlib.h>
 
 #include "ts_xlib.h"
-#include "ts_xutil.h"
+#include <X11/Xresource.h>
+#include <X11/Xutil.h>
 
 #include "winbase.h"
 #include "wingdi.h"
@@ -398,10 +399,11 @@ void X11DRV_set_wm_hints( Display *display, WND *win )
                          PropModeReplace, (char*)&mwm_hints, sizeof(mwm_hints)/sizeof(long) );
     }
 
+    wm_hints = XAllocWMHints();
     wine_tsx11_unlock();
 
     /* wm hints */
-    if ((wm_hints = TSXAllocWMHints()))
+    if (wm_hints)
     {
         wm_hints->flags = InputHint | StateHint | WindowGroupHint;
         wm_hints->input = !(win->dwStyle & WS_DISABLED);
@@ -1214,14 +1216,18 @@ HICON X11DRV_SetWindowIcon( HWND hwnd, HICON icon, BOOL small )
     if (wndPtr->dwExStyle & WS_EX_MANAGED)
     {
         Window win = get_whole_window(wndPtr);
-        XWMHints* wm_hints = TSXGetWMHints( display, win );
+        XWMHints* wm_hints;
 
-        if (!wm_hints) wm_hints = TSXAllocWMHints();
+        wine_tsx11_lock();
+        if (!(wm_hints = XGetWMHints( display, win ))) wm_hints = XAllocWMHints();
+        wine_tsx11_unlock();
         if (wm_hints)
         {
             set_icon_hints( display, wndPtr, wm_hints );
-            TSXSetWMHints( display, win, wm_hints );
-            TSXFree( wm_hints );
+            wine_tsx11_lock();
+            XSetWMHints( display, win, wm_hints );
+            XFree( wm_hints );
+            wine_tsx11_unlock();
         }
     }
     WIN_ReleasePtr( wndPtr );
diff --git a/dlls/x11drv/winpos.c b/dlls/x11drv/winpos.c
index 2966628345bcbf1a8182165104680ec91c453533..b1a9b51149854830839a4e2ba74322e01f3c17aa 100644
--- a/dlls/x11drv/winpos.c
+++ b/dlls/x11drv/winpos.c
@@ -22,7 +22,6 @@
 #include "config.h"
 
 #include "ts_xlib.h"
-#include "ts_xutil.h"
 #ifdef HAVE_LIBXSHAPE
 #include <X11/IntrinsicP.h>
 #include <X11/extensions/shape.h>
diff --git a/dlls/x11drv/x11drv_main.c b/dlls/x11drv/x11drv_main.c
index 5285b15ddfce7d2b50fa6db9a1bd1f2c9ddebeeb..aaa93bd064f5e6ba01b3207100777d91e8eec7ef 100644
--- a/dlls/x11drv/x11drv_main.c
+++ b/dlls/x11drv/x11drv_main.c
@@ -33,7 +33,6 @@
 #endif
 #include <X11/cursorfont.h>
 #include "ts_xlib.h"
-#include "ts_xutil.h"
 
 #include "winbase.h"
 #include "wine/winbase16.h"
@@ -276,13 +275,13 @@ static void setup_opengl_visual( Display *display )
 
     /* In order to support OpenGL or D3D, we require a double-buffered
      * visual */
+    wine_tsx11_lock();
     if (glXQueryExtension(display, &err_base, &evt_base) == True) {
 	  int dblBuf[]={GLX_RGBA,GLX_DEPTH_SIZE,16,GLX_DOUBLEBUFFER,None};
 
-	  ENTER_GL();
 	  desktop_vi = glXChooseVisual(display, DefaultScreen(display), dblBuf);
-	  LEAVE_GL();
     }
+    wine_tsx11_unlock();
 
     if (desktop_vi != NULL) {
       visual       = desktop_vi->visual;
diff --git a/dlls/x11drv/xvidmode.c b/dlls/x11drv/xvidmode.c
index 3710e3348d13d46045574aa6112d3c772d6da7b2..581230dd40fcf3630bbab37cca927ed35149ac39 100644
--- a/dlls/x11drv/xvidmode.c
+++ b/dlls/x11drv/xvidmode.c
@@ -24,8 +24,14 @@
 #include <string.h>
 
 #include "ts_xlib.h"
-#include "ts_xf86vmode.h"
+
+#ifdef HAVE_LIBXXF86VM
+#define XMD_H
+#include "basetsd.h"
+#include <X11/extensions/xf86vmode.h>
+#endif  /* HAVE_LIBXXF86VM */
 #include "x11drv.h"
+
 #include "x11ddraw.h"
 #include "xvidmode.h"
 
@@ -111,29 +117,31 @@ void X11DRV_XF86VM_Init(void)
   if (!usexvidmode) return;
 
   /* see if XVidMode is available */
-  if (!TSXF86VidModeQueryExtension(gdi_display, &xf86vm_event, &xf86vm_error)) return;
-  X11DRV_expect_error(gdi_display, XVidModeErrorHandler, NULL);
-  ok = TSXF86VidModeQueryVersion(gdi_display, &xf86vm_major, &xf86vm_minor);
-  if (X11DRV_check_error()) ok = FALSE;
-  if (!ok) return;
-
-#ifdef X_XF86VidModeSetGammaRamp
-  if (xf86vm_major > 2 || (xf86vm_major == 2 && xf86vm_minor >= 1))
+  wine_tsx11_lock();
+  ok = !XF86VidModeQueryExtension(gdi_display, &xf86vm_event, &xf86vm_error);
+  if (ok)
   {
-      wine_tsx11_lock();
-      XF86VidModeGetGammaRampSize(gdi_display, DefaultScreen(gdi_display),
-				  &xf86vm_gammaramp_size);
-      wine_tsx11_unlock();
-
-      if (xf86vm_gammaramp_size == 256)
-	  xf86vm_use_gammaramp = TRUE;
+      X11DRV_expect_error(gdi_display, XVidModeErrorHandler, NULL);
+      ok = XF86VidModeQueryVersion(gdi_display, &xf86vm_major, &xf86vm_minor);
+      if (X11DRV_check_error()) ok = FALSE;
   }
+  if (ok)
+  {
+#ifdef X_XF86VidModeSetGammaRamp
+      if (xf86vm_major > 2 || (xf86vm_major == 2 && xf86vm_minor >= 1))
+      {
+          XF86VidModeGetGammaRampSize(gdi_display, DefaultScreen(gdi_display),
+                                      &xf86vm_gammaramp_size);
+          if (xf86vm_gammaramp_size == 256)
+              xf86vm_use_gammaramp = TRUE;
+      }
 #endif
 
-  /* retrieve modes */
-  if (!TSXF86VidModeGetAllModeLines(gdi_display, DefaultScreen(gdi_display), &nmodes,
-				    &modes))
-    return;
+      /* retrieve modes */
+      ok = XF86VidModeGetAllModeLines(gdi_display, DefaultScreen(gdi_display), &nmodes, &modes);
+  }
+  wine_tsx11_unlock();
+  if (!ok) return;
 
   TRACE("XVidMode modes: count=%d\n", nmodes);
 
@@ -142,8 +150,7 @@ void X11DRV_XF86VM_Init(void)
 
   /* convert modes to DDHALMODEINFO format */
   for (i=0; i<nmodes; i++)
-    convert_modeinfo(modes[i], &xf86vm_modes[i]);
-
+      convert_modeinfo(modes[i], &xf86vm_modes[i]);
   TRACE("Enabling XVidMode\n");
 }
 
@@ -161,7 +168,9 @@ int X11DRV_XF86VM_GetCurrentMode(void)
   if (!xf86vm_modes) return 0; /* no XVidMode */
 
   TRACE("Querying XVidMode current mode\n");
-  TSXF86VidModeGetModeLine(gdi_display, DefaultScreen(gdi_display), &dotclock, &line);
+  wine_tsx11_lock();
+  XF86VidModeGetModeLine(gdi_display, DefaultScreen(gdi_display), &dotclock, &line);
+  wine_tsx11_unlock();
   convert_modeline(dotclock, &line, &cmode);
   for (i=0; i<xf86vm_mode_count; i++)
     if (memcmp(&xf86vm_modes[i], &cmode, sizeof(cmode)) == 0) {
@@ -176,20 +185,24 @@ void X11DRV_XF86VM_SetCurrentMode(int mode)
 {
   if (!xf86vm_modes) return; /* no XVidMode */
 
-  TSXF86VidModeSwitchToMode(gdi_display, DefaultScreen(gdi_display), modes[mode]);
+  wine_tsx11_lock();
+  XF86VidModeSwitchToMode(gdi_display, DefaultScreen(gdi_display), modes[mode]);
 #if 0 /* it is said that SetViewPort causes problems with some X servers */
-  TSXF86VidModeSetViewPort(gdi_display, DefaultScreen(gdi_display), 0, 0);
+  XF86VidModeSetViewPort(gdi_display, DefaultScreen(gdi_display), 0, 0);
 #else
-  TSXWarpPointer(gdi_display, None, DefaultRootWindow(gdi_display), 0, 0, 0, 0, 0, 0);
+  XWarpPointer(gdi_display, None, DefaultRootWindow(gdi_display), 0, 0, 0, 0, 0, 0);
 #endif
-  TSXSync(gdi_display, False);
+  XSync(gdi_display, False);
+  wine_tsx11_unlock();
 }
 
 void X11DRV_XF86VM_SetExclusiveMode(int lock)
 {
   if (!xf86vm_modes) return; /* no XVidMode */
 
-  TSXF86VidModeLockModeSwitch(gdi_display, DefaultScreen(gdi_display), lock);
+  wine_tsx11_lock();
+  XF86VidModeLockModeSwitch(gdi_display, DefaultScreen(gdi_display), lock);
+  wine_tsx11_unlock();
 }
 
 /* actual DirectDraw HAL stuff */
diff --git a/graphics/x11drv/bitmap.c b/graphics/x11drv/bitmap.c
index 7ce26c7439419e461dcea92ed4f0efd52ea02aaa..5d0dc242a09f700aa22bd3f9256b2cbd42a8b251 100644
--- a/graphics/x11drv/bitmap.c
+++ b/graphics/x11drv/bitmap.c
@@ -22,7 +22,6 @@
 #include "config.h"
 
 #include "ts_xlib.h"
-#include "ts_xutil.h"
 
 #include <stdio.h>
 #include <stdlib.h>
@@ -561,4 +560,3 @@ Pixmap X11DRV_BITMAP_Pixmap(HBITMAP hbitmap)
     }
     return pixmap;
 }
-
diff --git a/graphics/x11drv/dib.c b/graphics/x11drv/dib.c
index 5d13fa1ac837006c896b4bfd3ca82e076fe16823..82ec72df92b97fa34ebaa5d745c34cac08243b66 100644
--- a/graphics/x11drv/dib.c
+++ b/graphics/x11drv/dib.c
@@ -21,7 +21,6 @@
 #include "config.h"
 
 #include "ts_xlib.h"
-#include "ts_xutil.h"
 #ifdef HAVE_LIBXXSHM
 #include <X11/extensions/XShm.h>
 # ifdef HAVE_SYS_SHM_H
diff --git a/graphics/x11drv/graphics.c b/graphics/x11drv/graphics.c
index 7e72d25a1ba797108a43808d6cc05cab140d329c..c36646d0a787aa486f2daeb9a044a6088d8eb5db 100644
--- a/graphics/x11drv/graphics.c
+++ b/graphics/x11drv/graphics.c
@@ -28,7 +28,8 @@
 #include <X11/Intrinsic.h>
 
 #include "ts_xlib.h"
-#include "ts_xutil.h"
+#include <X11/Xresource.h>
+#include <X11/Xutil.h>
 
 #include <math.h>
 #ifdef HAVE_FLOAT_H
@@ -1271,7 +1272,9 @@ X11DRV_ExtFloodFill( X11DRV_PDEVICE *physDev, INT x, INT y, COLORREF color,
         X11DRV_UnlockDIBSection(physDev, TRUE);
     }
 
-    TSXDestroyImage( image );
+    wine_tsx11_lock();
+    XDestroyImage( image );
+    wine_tsx11_unlock();
     return TRUE;
 }
 
diff --git a/include/ts_xf86dga2.h b/include/ts_xf86dga2.h
deleted file mode 100644
index 8f7758cdcfc5e2df9774969872e8d693b9126a10..0000000000000000000000000000000000000000
--- a/include/ts_xf86dga2.h
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * Thread safe wrappers around xf86dga2 calls.
- * Always include this file instead of <X11/xf86dga2.h>.
- * This file was generated automatically by tools/make_X11wrappers
- * DO NOT EDIT!
- */
-
-#ifndef __WINE_TS_XF86DGA2_H
-#define __WINE_TS_XF86DGA2_H
-
-#ifndef __WINE_CONFIG_H
-# error You must include config.h to use this header
-#endif
-
-#ifdef HAVE_LIBXXF86DGA2
-
-#include <X11/Xlib.h>
-#include <X11/extensions/xf86dga.h>
-
-extern void (*wine_tsx11_lock)(void);
-extern void (*wine_tsx11_unlock)(void);
-
-extern Bool TSXDGAQueryVersion(Display*, int*, int*);
-extern Bool TSXDGAQueryExtension(Display*, int*, int*);
-extern XDGAMode* TSXDGAQueryModes(Display*, int, int*);
-extern XDGADevice* TSXDGASetMode(Display*, int, int);
-extern Bool TSXDGAOpenFramebuffer(Display*, int);
-extern void TSXDGACloseFramebuffer(Display*, int);
-extern void TSXDGASetViewport(Display*, int, int, int, int);
-extern void TSXDGAInstallColormap(Display*, int, Colormap);
-extern Colormap TSXDGACreateColormap(Display*, int, XDGADevice*, int);
-extern void TSXDGASelectInput(Display*, int, long);
-
-#endif /* defined(HAVE_LIBXXF86DGA2) */
-
-#endif /* __WINE_TS_XF86DGA2_H */
diff --git a/include/ts_xf86vmode.h b/include/ts_xf86vmode.h
deleted file mode 100644
index 041473c186820b43c27095c1bbcdca9b4049ddee..0000000000000000000000000000000000000000
--- a/include/ts_xf86vmode.h
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * Thread safe wrappers around xf86vmode calls.
- * Always include this file instead of <X11/xf86vmode.h>.
- * This file was generated automatically by tools/make_X11wrappers
- * DO NOT EDIT!
- */
-
-#ifndef __WINE_TS_XF86VMODE_H
-#define __WINE_TS_XF86VMODE_H
-
-#ifndef __WINE_CONFIG_H
-# error You must include config.h to use this header
-#endif
-
-#include "windef.h"
-#ifdef HAVE_LIBXXF86VM
-#define XMD_H
-#include "basetsd.h"
-
-#include <X11/Xlib.h>
-#include <X11/extensions/xf86vmode.h>
-
-extern void (*wine_tsx11_lock)(void);
-extern void (*wine_tsx11_unlock)(void);
-
-extern Bool TSXF86VidModeQueryVersion(Display*,int*,int*);
-extern Bool TSXF86VidModeQueryExtension(Display*,int*,int*);
-extern Bool TSXF86VidModeGetModeLine(Display*,int,int*,XF86VidModeModeLine*);
-extern Bool TSXF86VidModeGetAllModeLines(Display*,int,int*,XF86VidModeModeInfo***);
-extern Bool TSXF86VidModeSwitchToMode(Display*,int,XF86VidModeModeInfo*);
-extern Bool TSXF86VidModeLockModeSwitch(Display*,int,int);
-extern Bool TSXF86VidModeSetViewPort(Display*,int,int,int);
-
-#endif /* defined(HAVE_LIBXXF86VM) */
-
-#endif /* __WINE_TS_XF86VMODE_H */
diff --git a/include/ts_xlib.h b/include/ts_xlib.h
index c4ebbe068d2f0ae16c8c84a58a8f45990429338d..fd0f1ca900081c5ccd25eadb096f91bee3558c85 100644
--- a/include/ts_xlib.h
+++ b/include/ts_xlib.h
@@ -20,7 +20,6 @@ extern void (*wine_tsx11_lock)(void);
 extern void (*wine_tsx11_unlock)(void);
 
 extern XFontStruct * TSXLoadQueryFont(Display*, const  char*);
-extern XModifierKeymap	* TSXGetModifierMapping(Display*);
 extern XImage * TSXGetImage(Display*, Drawable, int, int, unsigned int, unsigned int, unsigned long, int);
 extern Display * TSXOpenDisplay(const  char*);
 extern char * TSXGetAtomName(Display*, Atom);
@@ -32,8 +31,6 @@ extern Pixmap  TSXCreateBitmapFromData(Display*, Drawable, const  char*, unsigne
 extern Window  TSXGetSelectionOwner(Display*, Atom);
 extern char ** TSXListFonts(Display*, const  char*, int, int*);
 extern KeySym  TSXKeycodeToKeysym(Display*, unsigned int, int);
-extern KeySym  TSXLookupKeysym(XKeyEvent*, int);
-extern KeySym * TSXGetKeyboardMapping(Display*, unsigned int, int, int*);
 extern int * TSXListDepths(Display*, int, int*);
 extern int   TSXReconfigureWMWindow(Display*, Window, int, unsigned int, XWindowChanges*);
 extern int   TSXAllocColor(Display*, Colormap, XColor*);
@@ -46,7 +43,6 @@ extern int  TSXCopyArea(Display*, Drawable, Drawable, GC, int, int, unsigned int
 extern int  TSXCopyPlane(Display*, Drawable, Drawable, GC, int, int, unsigned int, unsigned int, int, int, unsigned long);
 extern int  TSXDefineCursor(Display*, Window, Cursor);
 extern int  TSXDeleteProperty(Display*, Window, Atom);
-extern int  TSXDisplayKeycodes(Display*, int*, int*);
 extern int  TSXDrawArc(Display*, Drawable, GC, int, int, unsigned int, unsigned int, int, int);
 extern int  TSXDrawLine(Display*, Drawable, GC, int, int, int, int);
 extern int  TSXDrawLines(Display*, Drawable, GC, XPoint*, int, int);
@@ -62,11 +58,9 @@ extern int  TSXFreeColormap(Display*, Colormap);
 extern int  TSXFreeColors(Display*, Colormap, unsigned long*, int, unsigned long);
 extern int  TSXFreeFont(Display*, XFontStruct*);
 extern int  TSXFreeFontNames(char**);
-extern int  TSXFreeModifiermap(XModifierKeymap*);
 extern int  TSXFreePixmap(Display*, Pixmap);
 extern int   TSXGetFontProperty(XFontStruct*, Atom, unsigned long*);
 extern int   TSXGetGeometry(Display*, Drawable, Window*, int*, int*, unsigned int*, unsigned int*, unsigned int*, unsigned int*);
-extern int  TSXGetInputFocus(Display*, Window*, int*);
 extern int  TSXGetScreenSaver(Display*, int*, int*, int*, int*);
 extern int  TSXGetWindowProperty(Display*, Window, Atom, long, long, int, Atom, Atom*, int*, unsigned long*, unsigned long*, unsigned char**);
 extern int   TSXGetWindowAttributes(Display*, Window, XWindowAttributes*);
@@ -98,7 +92,6 @@ extern int  TSXUngrabPointer(Display*, Time);
 extern int  TSXUngrabServer(Display*);
 extern int  TSXUninstallColormap(Display*, Colormap);
 extern int  TSXUnmapWindow(Display*, Window);
-extern int  TSXWarpPointer(Display*, Window, Window, int, int, unsigned int, unsigned int, int, int);
 extern XIM  TSXOpenIM(Display*, struct _XrmHashBucketRec*, char*, char*);
 
 #endif /* defined(HAVE_X11_XLIB_H) */
diff --git a/include/ts_xutil.h b/include/ts_xutil.h
deleted file mode 100644
index edb9417a149e0abcadc7bc45ee8d58cc2dc5a0ac..0000000000000000000000000000000000000000
--- a/include/ts_xutil.h
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * Thread safe wrappers around Xutil calls.
- * Always include this file instead of <X11/Xutil.h>.
- * This file was generated automatically by tools/make_X11wrappers
- * DO NOT EDIT!
- */
-
-#ifndef __WINE_TS_XUTIL_H
-#define __WINE_TS_XUTIL_H
-
-#ifndef __WINE_CONFIG_H
-# error You must include config.h to use this header
-#endif
-
-#ifdef HAVE_X11_XLIB_H
-
-#include <X11/Xlib.h>
-#include <X11/Xresource.h>
-#include <X11/Xutil.h>
-
-extern void (*wine_tsx11_lock)(void);
-extern void (*wine_tsx11_unlock)(void);
-
-extern XWMHints * TSXAllocWMHints(void);
-extern int  TSXFindContext(Display*, XID, XContext, XPointer*);
-extern XWMHints * TSXGetWMHints(Display*, Window);
-extern int  TSXLookupString(XKeyEvent*, char*, int, KeySym*, XComposeStatus*);
-extern int  TSXSetWMHints(Display*, Window, XWMHints*);
-extern int TSXDestroyImage(struct _XImage *);
-
-#endif /* defined(HAVE_X11_XLIB_H) */
-
-#endif /* __WINE_TS_XUTIL_H */
diff --git a/tools/make_X11wrappers b/tools/make_X11wrappers
index c163c127c6dff2001251407684bebdfc44e88ac0..c757f2910099d6eadd9e2d1fd1ec0d89e334add7 100755
--- a/tools/make_X11wrappers
+++ b/tools/make_X11wrappers
@@ -30,7 +30,7 @@
 $X11_include_dir = "/usr/X11/include";
 $outdir = "tsx11";
 $wantfile = "$outdir/X11_calls";
-@dolist = ("Xlib", "Xutil", "xf86dga2", "xf86vmode");
+@dolist = ("Xlib");
 
 # First read list of wanted function names.
 
@@ -60,23 +60,6 @@ foreach $name (@dolist) {
     $pre_file = "#ifdef HAVE_X11_XLIB_H\n";
     $post_file = "#endif /* defined(HAVE_X11_XLIB_H) */\n";
     $inc_name = $name;
-    if($name eq "Xutil") {
-	# For Xutil, we need X11/Xresource.h for XUniqueContext().
-	$x11_incl = "#include <X11/Xlib.h>\n#include <X11/Xresource.h>\n";
-    }
-    if($name eq "xf86dga2")  {
-    	$x11_incl = "#include <X11/Xlib.h>\n";
-	$extensions_dir = "extensions/";
-	$pre_file = "#ifdef HAVE_LIBXXF86DGA2\n";
-	$post_file = "#endif /* defined(HAVE_LIBXXF86DGA2) */\n";
-	$inc_name = "xf86dga";
-    }
-    if($name eq "xf86vmode") {
-     	$x11_incl = "#include <X11/Xlib.h>\n";
-	$extensions_dir = "extensions/";
-	$pre_file = "#include \"windef.h\"\n#ifdef HAVE_LIBXXF86VM\n#define XMD_H\n#include \"basetsd.h\"\n";
-	$post_file = "#endif /* defined(HAVE_LIBXXF86VM) */\n";
-    }
 
     print OUTH <<END;
 /*
@@ -117,55 +100,6 @@ $x11_incl#include <X11/$extensions_dir$inc_name.h>
 
 END
 
-    if($name eq "xf86dga2") {
-    	output_fn_short("Bool", "XDGAQueryVersion", "Display*" ,"int*","int*");
-    	output_fn_short("Bool", "XDGAQueryExtension", "Display*" ,"int*","int*");
-    	output_fn_short("XDGAMode*", "XDGAQueryModes", "Display*" ,"int", "int*");
-    	output_fn_short("XDGADevice*", "XDGASetMode", "Display*" ,"int","int");
-    	output_fn_short("Bool", "XDGAOpenFramebuffer", "Display*" ,"int");
-    	output_fn_short("void", "XDGACloseFramebuffer", "Display*" ,"int");
-    	output_fn_short("void", "XDGASetViewport", "Display*" ,"int", "int", "int", "int");
-    	output_fn_short("void", "XDGAInstallColormap", "Display*" , "int", "Colormap");
-	output_fn_short("Colormap", "XDGACreateColormap", "Display*" ,"int", "XDGADevice*", "int");
-    	output_fn_short("void", "XDGASelectInput", "Display*" ,"int", "long");
-    } elsif($name eq "xf86vmode") {
-    	output_fn("XF86VidModeQueryVersion",Bool,
-		"Display*,int*,int*",
-		"Display*a0,int*a1,int*a2",
-		"a0,a1,a2"
-	);
-	output_fn("XF86VidModeQueryExtension",Bool,
-		"Display*,int*,int*",
-		"Display*a0,int*a1,int*a2",
-		"a0,a2,a2"
-	);
-	output_fn("XF86VidModeGetModeLine",Bool,
-		"Display*,int,int*,XF86VidModeModeLine*",
-		"Display*a0,int a1,int*a2,XF86VidModeModeLine*a3",
-		"a0,a1,a2,a3"
-	);
-	output_fn("XF86VidModeGetAllModeLines",Bool,
-		"Display*,int,int*,XF86VidModeModeInfo***",
-		"Display*a0,int a1,int*a2,XF86VidModeModeInfo***a3",
-		"a0,a1,a2,a3"
-	);
-	output_fn("XF86VidModeSwitchToMode",Bool,
-		"Display*,int,XF86VidModeModeInfo*",
-		"Display*a0,int a1,XF86VidModeModeInfo*a2",
-		"a0,a1,a2"
-	);
-	output_fn("XF86VidModeLockModeSwitch",Bool,
-		"Display*,int,int",
-		"Display*a0,int a1,int a2",
-		"a0,a1,a2"
-	);
-	output_fn("XF86VidModeSetViewPort",Bool,
-		"Display*,int,int,int",
-		"Display*a0,int a1,int a2,int a3",
-		"a0,a1,a2,a3"
-	);
-
-    } else {
 	open(IN,
 	     "echo \"$x11_incl#include <X11/$extensions_dir$name.h>\" | " .
 	     "gcc -L$X11_include_dir -DNeedFunctionPrototypes -E - | " .
@@ -213,12 +147,6 @@ END
 	      output_fn($fn_name, $result_type, $proto, $formals, $actuals);
 	  }
       }
-    }
-
-    if ($name eq "Xutil") {
-	output_fn("XDestroyImage", "int",
-		  "struct _XImage *", "struct _XImage *a0", "a0");
-    }
 
     print OUTH <<END;
 
diff --git a/tsx11/Makefile.in b/tsx11/Makefile.in
index c4fa115fbfb763e919a0d48f095ae501edf6e98d..bfdba002c46a40428bfc89ab73be02f6277e9a50 100644
--- a/tsx11/Makefile.in
+++ b/tsx11/Makefile.in
@@ -11,10 +11,7 @@ EXTRALIBS = $(X_LIBS) $(XLIB)
 
 C_SRCS = \
 	locking.c \
-	ts_xf86dga2.c \
-	ts_xf86vmode.c \
-	ts_xlib.c \
-	ts_xutil.c
+	ts_xlib.c
 
 all: libwine_tsx11.$(LIBEXT)
 
diff --git a/tsx11/X11_calls b/tsx11/X11_calls
index debfb0b4302a02ba83b944f8f7045116767dd801..8bc738316465db3a74da2242bb3c80f7757b66dd 100644
--- a/tsx11/X11_calls
+++ b/tsx11/X11_calls
@@ -6,7 +6,6 @@
 #
 XAllocColor
 XAllocColorCells
-XAllocWMHints
 XBell
 XChangeGC
 XChangeProperty
@@ -16,55 +15,30 @@ XCopyPlane
 XCreateBitmapFromData
 XCreateColormap
 XCreatePixmap
-XDGACloseFramebuffer
-XDGACreateColormap
-XDGAInstallColormap
-XDGAOpenFramebuffer
-XDGAQueryExtension
-XDGAQueryModes
-XDGAQueryVersion
-XDGASelectInput
-XDGASetMode
-XDGASetViewport
 XDefineCursor
 XDeleteProperty
-XDestroyImage
-XDisplayKeycodes
 XDrawArc
 XDrawLine
 XDrawLines
 XDrawRectangle
 XDrawString16
 XDrawText16
-XF86VidModeGetAllModeLines
-XF86VidModeGetModeLine
-XF86VidModeLockModeSwitch
-XF86VidModeQueryExtension
-XF86VidModeQueryVersion
-XF86VidModeSetViewPort
-XF86VidModeSwitchToMode
 XFillArc
 XFillPolygon
 XFillRectangle
-XFindContext
 XFlush
 XFree
 XFreeColormap
 XFreeColors
 XFreeFont
 XFreeFontNames
-XFreeModifiermap
 XFreePixmap
 XGetAtomName
 XGetFontProperty
 XGetGeometry
 XGetImage
-XGetInputFocus
-XGetKeyboardMapping
-XGetModifierMapping
 XGetScreenSaver
 XGetSelectionOwner
-XGetWMHints
 XGetWindowAttributes
 XGetWindowProperty
 XGrabPointer
@@ -76,8 +50,6 @@ XKeysymToString
 XListDepths
 XListFonts
 XLoadQueryFont
-XLookupKeysym
-XLookupString
 XMapWindow
 XOpenDisplay
 XOpenIM
@@ -98,7 +70,6 @@ XSetLineAttributes
 XSetScreenSaver
 XSetSelectionOwner
 XSetSubwindowMode
-XSetWMHints
 XStoreColor
 XSync
 XTextExtents16
@@ -107,4 +78,3 @@ XUngrabPointer
 XUngrabServer
 XUninstallColormap
 XUnmapWindow
-XWarpPointer
diff --git a/tsx11/ts_xf86dga2.c b/tsx11/ts_xf86dga2.c
deleted file mode 100644
index 47b628ba7f3bda71a72b98c1ad805729b760233f..0000000000000000000000000000000000000000
--- a/tsx11/ts_xf86dga2.c
+++ /dev/null
@@ -1,100 +0,0 @@
-/*
- * Thread safe wrappers around xf86dga2 calls.
- * This file was generated automatically by tools/make_X11wrappers
- * DO NOT EDIT!
- */
-
-#include "config.h"
-
-#ifdef HAVE_LIBXXF86DGA2
-
-#include <X11/Xlib.h>
-#include <X11/extensions/xf86dga.h>
-
-#include "ts_xf86dga2.h"
-
-
-Bool TSXDGAQueryVersion(Display* a0, int* a1, int* a2)
-{
-  Bool r;
-  wine_tsx11_lock();
-  r = XDGAQueryVersion( a0,  a1,  a2);
-  wine_tsx11_unlock();
-  return r;
-}
-
-Bool TSXDGAQueryExtension(Display* a0, int* a1, int* a2)
-{
-  Bool r;
-  wine_tsx11_lock();
-  r = XDGAQueryExtension( a0,  a1,  a2);
-  wine_tsx11_unlock();
-  return r;
-}
-
-XDGAMode* TSXDGAQueryModes(Display* a0, int a1, int* a2)
-{
-  XDGAMode* r;
-  wine_tsx11_lock();
-  r = XDGAQueryModes( a0,  a1,  a2);
-  wine_tsx11_unlock();
-  return r;
-}
-
-XDGADevice* TSXDGASetMode(Display* a0, int a1, int a2)
-{
-  XDGADevice* r;
-  wine_tsx11_lock();
-  r = XDGASetMode( a0,  a1,  a2);
-  wine_tsx11_unlock();
-  return r;
-}
-
-Bool TSXDGAOpenFramebuffer(Display* a0, int a1)
-{
-  Bool r;
-  wine_tsx11_lock();
-  r = XDGAOpenFramebuffer( a0,  a1);
-  wine_tsx11_unlock();
-  return r;
-}
-
-void TSXDGACloseFramebuffer(Display* a0, int a1)
-{
-  wine_tsx11_lock();
-  XDGACloseFramebuffer( a0,  a1);
-  wine_tsx11_unlock();
-}
-
-void TSXDGASetViewport(Display* a0, int a1, int a2, int a3, int a4)
-{
-  wine_tsx11_lock();
-  XDGASetViewport( a0,  a1,  a2,  a3,  a4);
-  wine_tsx11_unlock();
-}
-
-void TSXDGAInstallColormap(Display* a0, int a1, Colormap a2)
-{
-  wine_tsx11_lock();
-  XDGAInstallColormap( a0,  a1,  a2);
-  wine_tsx11_unlock();
-}
-
-Colormap TSXDGACreateColormap(Display* a0, int a1, XDGADevice* a2, int a3)
-{
-  Colormap r;
-  wine_tsx11_lock();
-  r = XDGACreateColormap( a0,  a1,  a2,  a3);
-  wine_tsx11_unlock();
-  return r;
-}
-
-void TSXDGASelectInput(Display* a0, int a1, long a2)
-{
-  wine_tsx11_lock();
-  XDGASelectInput( a0,  a1,  a2);
-  wine_tsx11_unlock();
-}
-
-#endif /* defined(HAVE_LIBXXF86DGA2) */
-
diff --git a/tsx11/ts_xf86vmode.c b/tsx11/ts_xf86vmode.c
deleted file mode 100644
index aa8b7235817b3aef665801f0608a0316fc1ef32a..0000000000000000000000000000000000000000
--- a/tsx11/ts_xf86vmode.c
+++ /dev/null
@@ -1,84 +0,0 @@
-/*
- * Thread safe wrappers around xf86vmode calls.
- * This file was generated automatically by tools/make_X11wrappers
- * DO NOT EDIT!
- */
-
-#include "config.h"
-
-#include "windef.h"
-#ifdef HAVE_LIBXXF86VM
-#define XMD_H
-#include "basetsd.h"
-
-#include <X11/Xlib.h>
-#include <X11/extensions/xf86vmode.h>
-
-#include "ts_xf86vmode.h"
-
-
-Bool TSXF86VidModeQueryVersion(Display*a0,int*a1,int*a2)
-{
-  Bool r;
-  wine_tsx11_lock();
-  r = XF86VidModeQueryVersion(a0,a1,a2);
-  wine_tsx11_unlock();
-  return r;
-}
-
-Bool TSXF86VidModeQueryExtension(Display*a0,int*a1,int*a2)
-{
-  Bool r;
-  wine_tsx11_lock();
-  r = XF86VidModeQueryExtension(a0,a2,a2);
-  wine_tsx11_unlock();
-  return r;
-}
-
-Bool TSXF86VidModeGetModeLine(Display*a0,int a1,int*a2,XF86VidModeModeLine*a3)
-{
-  Bool r;
-  wine_tsx11_lock();
-  r = XF86VidModeGetModeLine(a0,a1,a2,a3);
-  wine_tsx11_unlock();
-  return r;
-}
-
-Bool TSXF86VidModeGetAllModeLines(Display*a0,int a1,int*a2,XF86VidModeModeInfo***a3)
-{
-  Bool r;
-  wine_tsx11_lock();
-  r = XF86VidModeGetAllModeLines(a0,a1,a2,a3);
-  wine_tsx11_unlock();
-  return r;
-}
-
-Bool TSXF86VidModeSwitchToMode(Display*a0,int a1,XF86VidModeModeInfo*a2)
-{
-  Bool r;
-  wine_tsx11_lock();
-  r = XF86VidModeSwitchToMode(a0,a1,a2);
-  wine_tsx11_unlock();
-  return r;
-}
-
-Bool TSXF86VidModeLockModeSwitch(Display*a0,int a1,int a2)
-{
-  Bool r;
-  wine_tsx11_lock();
-  r = XF86VidModeLockModeSwitch(a0,a1,a2);
-  wine_tsx11_unlock();
-  return r;
-}
-
-Bool TSXF86VidModeSetViewPort(Display*a0,int a1,int a2,int a3)
-{
-  Bool r;
-  wine_tsx11_lock();
-  r = XF86VidModeSetViewPort(a0,a1,a2,a3);
-  wine_tsx11_unlock();
-  return r;
-}
-
-#endif /* defined(HAVE_LIBXXF86VM) */
-
diff --git a/tsx11/ts_xlib.c b/tsx11/ts_xlib.c
index 27a05750012651fc6621ac211aeb4473ca40cfc4..4c6158fa9df1a061403aef6bdda199b607b7735a 100644
--- a/tsx11/ts_xlib.c
+++ b/tsx11/ts_xlib.c
@@ -22,15 +22,6 @@ XFontStruct * TSXLoadQueryFont(Display* a0, const  char* a1)
   return r;
 }
 
-XModifierKeymap	* TSXGetModifierMapping(Display* a0)
-{
-  XModifierKeymap	* r;
-  wine_tsx11_lock();
-  r = XGetModifierMapping(a0);
-  wine_tsx11_unlock();
-  return r;
-}
-
 XImage * TSXGetImage(Display* a0, Drawable a1, int a2, int a3, unsigned int a4, unsigned int a5, unsigned long a6, int a7)
 {
   XImage * r;
@@ -130,24 +121,6 @@ KeySym  TSXKeycodeToKeysym(Display* a0, unsigned int a1, int a2)
   return r;
 }
 
-KeySym  TSXLookupKeysym(XKeyEvent* a0, int a1)
-{
-  KeySym  r;
-  wine_tsx11_lock();
-  r = XLookupKeysym(a0, a1);
-  wine_tsx11_unlock();
-  return r;
-}
-
-KeySym * TSXGetKeyboardMapping(Display* a0, unsigned int a1, int a2, int* a3)
-{
-  KeySym * r;
-  wine_tsx11_lock();
-  r = XGetKeyboardMapping(a0, a1, a2, a3);
-  wine_tsx11_unlock();
-  return r;
-}
-
 int * TSXListDepths(Display* a0, int a1, int* a2)
 {
   int * r;
@@ -256,15 +229,6 @@ int  TSXDeleteProperty(Display* a0, Window a1, Atom a2)
   return r;
 }
 
-int  TSXDisplayKeycodes(Display* a0, int* a1, int* a2)
-{
-  int  r;
-  wine_tsx11_lock();
-  r = XDisplayKeycodes(a0, a1, a2);
-  wine_tsx11_unlock();
-  return r;
-}
-
 int  TSXDrawArc(Display* a0, Drawable a1, GC a2, int a3, int a4, unsigned int a5, unsigned int a6, int a7, int a8)
 {
   int  r;
@@ -400,15 +364,6 @@ int  TSXFreeFontNames(char** a0)
   return r;
 }
 
-int  TSXFreeModifiermap(XModifierKeymap* a0)
-{
-  int  r;
-  wine_tsx11_lock();
-  r = XFreeModifiermap(a0);
-  wine_tsx11_unlock();
-  return r;
-}
-
 int  TSXFreePixmap(Display* a0, Pixmap a1)
 {
   int  r;
@@ -436,15 +391,6 @@ int   TSXGetGeometry(Display* a0, Drawable a1, Window* a2, int* a3, int* a4, uns
   return r;
 }
 
-int  TSXGetInputFocus(Display* a0, Window* a1, int* a2)
-{
-  int  r;
-  wine_tsx11_lock();
-  r = XGetInputFocus(a0, a1, a2);
-  wine_tsx11_unlock();
-  return r;
-}
-
 int  TSXGetScreenSaver(Display* a0, int* a1, int* a2, int* a3, int* a4)
 {
   int  r;
@@ -724,15 +670,6 @@ int  TSXUnmapWindow(Display* a0, Window a1)
   return r;
 }
 
-int  TSXWarpPointer(Display* a0, Window a1, Window a2, int a3, int a4, unsigned int a5, unsigned int a6, int a7, int a8)
-{
-  int  r;
-  wine_tsx11_lock();
-  r = XWarpPointer(a0, a1, a2, a3, a4, a5, a6, a7, a8);
-  wine_tsx11_unlock();
-  return r;
-}
-
 XIM  TSXOpenIM(Display* a0, struct _XrmHashBucketRec* a1, char* a2, char* a3)
 {
   XIM  r;
diff --git a/tsx11/ts_xutil.c b/tsx11/ts_xutil.c
deleted file mode 100644
index b8b00cf1e481760c0ec05dd530822e9ce1386f7a..0000000000000000000000000000000000000000
--- a/tsx11/ts_xutil.c
+++ /dev/null
@@ -1,73 +0,0 @@
-/*
- * Thread safe wrappers around Xutil calls.
- * This file was generated automatically by tools/make_X11wrappers
- * DO NOT EDIT!
- */
-
-#include "config.h"
-
-#ifdef HAVE_X11_XLIB_H
-
-#include <X11/Xlib.h>
-#include <X11/Xresource.h>
-#include <X11/Xutil.h>
-
-#include "ts_xutil.h"
-
-
-XWMHints * TSXAllocWMHints(void)
-{
-  XWMHints * r;
-  wine_tsx11_lock();
-  r = XAllocWMHints();
-  wine_tsx11_unlock();
-  return r;
-}
-
-int  TSXFindContext(Display* a0, XID a1, XContext a2, XPointer* a3)
-{
-  int  r;
-  wine_tsx11_lock();
-  r = XFindContext(a0, a1, a2, a3);
-  wine_tsx11_unlock();
-  return r;
-}
-
-XWMHints * TSXGetWMHints(Display* a0, Window a1)
-{
-  XWMHints * r;
-  wine_tsx11_lock();
-  r = XGetWMHints(a0, a1);
-  wine_tsx11_unlock();
-  return r;
-}
-
-int  TSXLookupString(XKeyEvent* a0, char* a1, int a2, KeySym* a3, XComposeStatus* a4)
-{
-  int  r;
-  wine_tsx11_lock();
-  r = XLookupString(a0, a1, a2, a3, a4);
-  wine_tsx11_unlock();
-  return r;
-}
-
-int  TSXSetWMHints(Display* a0, Window a1, XWMHints* a2)
-{
-  int  r;
-  wine_tsx11_lock();
-  r = XSetWMHints(a0, a1, a2);
-  wine_tsx11_unlock();
-  return r;
-}
-
-int TSXDestroyImage(struct _XImage *a0)
-{
-  int r;
-  wine_tsx11_lock();
-  r = XDestroyImage(a0);
-  wine_tsx11_unlock();
-  return r;
-}
-
-#endif /* defined(HAVE_X11_XLIB_H) */
-