Get rid of a bunch of TSX functions.

diff --git a/dlls/x11drv/X11_calls b/dlls/x11drv/X11_calls
index 8bc7383..ea2a42d 100644
--- a/dlls/x11drv/X11_calls
+++ b/dlls/x11drv/X11_calls
@@ -4,77 +4,40 @@
 # To add a new call, put it on this list and run tools/make_X11wrappers.
 # Also read the comments at the top of tools/make_X11wrappers.
 #
-XAllocColor
-XAllocColorCells
-XBell
 XChangeGC
 XChangeProperty
-XChangeWindowAttributes
-XCopyArea
-XCopyPlane
-XCreateBitmapFromData
-XCreateColormap
-XCreatePixmap
-XDefineCursor
-XDeleteProperty
 XDrawArc
 XDrawLine
 XDrawLines
-XDrawRectangle
 XDrawString16
 XDrawText16
 XFillArc
-XFillPolygon
 XFillRectangle
-XFlush
 XFree
-XFreeColormap
-XFreeColors
 XFreeFont
-XFreeFontNames
 XFreePixmap
 XGetAtomName
 XGetFontProperty
 XGetGeometry
-XGetImage
-XGetScreenSaver
 XGetSelectionOwner
-XGetWindowAttributes
 XGetWindowProperty
-XGrabPointer
-XGrabServer
 XInternAtom
 XKeycodeToKeysym
 XKeysymToKeycode
 XKeysymToString
-XListDepths
-XListFonts
-XLoadQueryFont
 XMapWindow
-XOpenDisplay
-XOpenIM
-XQueryColor
-XQueryColors
 XQueryPointer
 XQueryTree
-XReconfigureWMWindow
-XRefreshKeyboardMapping
-XSendEvent
 XSetArcMode
 XSetClipRectangles
 XSetDashes
 XSetForeground
 XSetFunction
-XSetGraphicsExposures
 XSetLineAttributes
-XSetScreenSaver
 XSetSelectionOwner
 XSetSubwindowMode
 XStoreColor
 XSync
 XTextExtents16
 XTextWidth16
-XUngrabPointer
-XUngrabServer
-XUninstallColormap
 XUnmapWindow
diff --git a/dlls/x11drv/clipboard.c b/dlls/x11drv/clipboard.c
index 9901701..3fe78a4 100644
--- a/dlls/x11drv/clipboard.c
+++ b/dlls/x11drv/clipboard.c
@@ -1589,7 +1589,9 @@
 
     /* Delete the property on the window now that we are done
      * This will send a PropertyNotify event to the selection owner. */
-    TSXDeleteProperty(display,w,prop);
+    wine_tsx11_lock();
+    XDeleteProperty(display,w,prop);
+    wine_tsx11_unlock();
 
     /* Free the retrieved property data */
     HeapFree(GetProcessHeap(),0,val);
diff --git a/dlls/x11drv/event.c b/dlls/x11drv/event.c
index 67cb16e..78ee890 100644
--- a/dlls/x11drv/event.c
+++ b/dlls/x11drv/event.c
@@ -852,11 +852,8 @@
       }
       else
       {
-          if (TRACE_ON(clipboard))
-	  {
-              TRACE_(clipboard)("Request for property %s (%ld) failed\n", 
-                  TSXGetAtomName(display, event->target), event->target);
-          }
+          TRACE_(clipboard)("Request for property %s (%ld) failed\n",
+                            TSXGetAtomName(display, event->target), event->target);
       }
   }
 
@@ -874,7 +871,9 @@
     result.target = event->target;
     result.time = event->time;
     TRACE("Sending SelectionNotify event...\n");
-    TSXSendEvent(display,event->requestor,False,NoEventMask,(XEvent*)&result);
+    wine_tsx11_lock();
+    XSendEvent(display,event->requestor,False,NoEventMask,(XEvent*)&result);
+    wine_tsx11_unlock();
   }
 }
 
diff --git a/dlls/x11drv/keyboard.c b/dlls/x11drv/keyboard.c
index 2bf36a8..91ef618 100644
--- a/dlls/x11drv/keyboard.c
+++ b/dlls/x11drv/keyboard.c
@@ -1624,7 +1624,9 @@
 {
     HWND hwnd;
 
-    TSXRefreshKeyboardMapping(event);
+    wine_tsx11_lock();
+    XRefreshKeyboardMapping(event);
+    wine_tsx11_unlock();
     X11DRV_InitKeyboard( pKeyStateTable );
 
     hwnd = GetFocus();
@@ -2196,5 +2198,7 @@
  */
 void X11DRV_Beep(void)
 {
-  TSXBell(thread_display(), 0);
+    wine_tsx11_lock();
+    XBell(thread_display(), 0);
+    wine_tsx11_unlock();
 }
diff --git a/dlls/x11drv/mouse.c b/dlls/x11drv/mouse.c
index 8976fcb..38f6c5f 100644
--- a/dlls/x11drv/mouse.c
+++ b/dlls/x11drv/mouse.c
@@ -162,7 +162,9 @@
     if (data->cursor_window != win)
     {
         data->cursor_window = win;
-        if (data->cursor) TSXDefineCursor( data->display, win, data->cursor );
+        wine_tsx11_lock();
+        if (data->cursor) XDefineCursor( data->display, win, data->cursor );
+        wine_tsx11_unlock();
     }
 }
 
diff --git a/dlls/x11drv/ts_xlib.c b/dlls/x11drv/ts_xlib.c
index b8caf3a..4ba659c 100644
--- a/dlls/x11drv/ts_xlib.c
+++ b/dlls/x11drv/ts_xlib.c
@@ -13,33 +13,6 @@
 #include "ts_xlib.h"
 
 
-XFontStruct * TSXLoadQueryFont(Display* a0, const  char* a1)
-{
-  XFontStruct * r;
-  wine_tsx11_lock();
-  r = XLoadQueryFont(a0, a1);
-  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;
-  wine_tsx11_lock();
-  r = XGetImage(a0, a1, a2, a3, a4, a5, a6, a7);
-  wine_tsx11_unlock();
-  return r;
-}
-
-Display * TSXOpenDisplay(const  char* a0)
-{
-  Display * r;
-  wine_tsx11_lock();
-  r = XOpenDisplay(a0);
-  wine_tsx11_unlock();
-  return r;
-}
-
 char * TSXGetAtomName(Display* a0, Atom a1)
 {
   char * r;
@@ -58,7 +31,7 @@
   return r;
 }
 
-Atom  TSXInternAtom(Display* a0, const  char* a1, int a2)
+Atom  TSXInternAtom(Display* a0, const char* a1, int a2)
 {
   Atom  r;
   wine_tsx11_lock();
@@ -67,33 +40,6 @@
   return r;
 }
 
-Colormap  TSXCreateColormap(Display* a0, Window a1, Visual* a2, int a3)
-{
-  Colormap  r;
-  wine_tsx11_lock();
-  r = XCreateColormap(a0, a1, a2, a3);
-  wine_tsx11_unlock();
-  return r;
-}
-
-Pixmap  TSXCreatePixmap(Display* a0, Drawable a1, unsigned int a2, unsigned int a3, unsigned int a4)
-{
-  Pixmap  r;
-  wine_tsx11_lock();
-  r = XCreatePixmap(a0, a1, a2, a3, a4);
-  wine_tsx11_unlock();
-  return r;
-}
-
-Pixmap  TSXCreateBitmapFromData(Display* a0, Drawable a1, const  char* a2, unsigned int a3, unsigned int a4)
-{
-  Pixmap  r;
-  wine_tsx11_lock();
-  r = XCreateBitmapFromData(a0, a1, a2, a3, a4);
-  wine_tsx11_unlock();
-  return r;
-}
-
 Window  TSXGetSelectionOwner(Display* a0, Atom a1)
 {
   Window  r;
@@ -103,15 +49,6 @@
   return r;
 }
 
-char ** TSXListFonts(Display* a0, const  char* a1, int a2, int* a3)
-{
-  char ** r;
-  wine_tsx11_lock();
-  r = XListFonts(a0, a1, a2, a3);
-  wine_tsx11_unlock();
-  return r;
-}
-
 KeySym  TSXKeycodeToKeysym(Display* a0, unsigned int a1, int a2)
 {
   KeySym  r;
@@ -121,51 +58,6 @@
   return r;
 }
 
-int * TSXListDepths(Display* a0, int a1, int* a2)
-{
-  int * r;
-  wine_tsx11_lock();
-  r = XListDepths(a0, a1, a2);
-  wine_tsx11_unlock();
-  return r;
-}
-
-int   TSXReconfigureWMWindow(Display* a0, Window a1, int a2, unsigned int a3, XWindowChanges* a4)
-{
-  int   r;
-  wine_tsx11_lock();
-  r = XReconfigureWMWindow(a0, a1, a2, a3, a4);
-  wine_tsx11_unlock();
-  return r;
-}
-
-int   TSXAllocColor(Display* a0, Colormap a1, XColor* a2)
-{
-  int   r;
-  wine_tsx11_lock();
-  r = XAllocColor(a0, a1, a2);
-  wine_tsx11_unlock();
-  return r;
-}
-
-int   TSXAllocColorCells(Display* a0, Colormap a1, int a2, unsigned long* a3, unsigned int a4, unsigned long* a5, unsigned int a6)
-{
-  int   r;
-  wine_tsx11_lock();
-  r = XAllocColorCells(a0, a1, a2, a3, a4, a5, a6);
-  wine_tsx11_unlock();
-  return r;
-}
-
-int  TSXBell(Display* a0, int a1)
-{
-  int  r;
-  wine_tsx11_lock();
-  r = XBell(a0, a1);
-  wine_tsx11_unlock();
-  return r;
-}
-
 int  TSXChangeGC(Display* a0, GC a1, unsigned long a2, XGCValues* a3)
 {
   int  r;
@@ -175,7 +67,7 @@
   return r;
 }
 
-int  TSXChangeProperty(Display* a0, Window a1, Atom a2, Atom a3, int a4, int a5, const  unsigned char* a6, int a7)
+int  TSXChangeProperty(Display* a0, Window a1, Atom a2, Atom a3, int a4, int a5, const unsigned char* a6, int a7)
 {
   int  r;
   wine_tsx11_lock();
@@ -184,51 +76,6 @@
   return r;
 }
 
-int  TSXChangeWindowAttributes(Display* a0, Window a1, unsigned long a2, XSetWindowAttributes* a3)
-{
-  int  r;
-  wine_tsx11_lock();
-  r = XChangeWindowAttributes(a0, a1, a2, a3);
-  wine_tsx11_unlock();
-  return r;
-}
-
-int  TSXCopyArea(Display* a0, Drawable a1, Drawable a2, GC a3, int a4, int a5, unsigned int a6, unsigned int a7, int a8, int a9)
-{
-  int  r;
-  wine_tsx11_lock();
-  r = XCopyArea(a0, a1, a2, a3, a4, a5, a6, a7, a8, a9);
-  wine_tsx11_unlock();
-  return r;
-}
-
-int  TSXCopyPlane(Display* a0, Drawable a1, Drawable a2, GC a3, int a4, int a5, unsigned int a6, unsigned int a7, int a8, int a9, unsigned long a10)
-{
-  int  r;
-  wine_tsx11_lock();
-  r = XCopyPlane(a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10);
-  wine_tsx11_unlock();
-  return r;
-}
-
-int  TSXDefineCursor(Display* a0, Window a1, Cursor a2)
-{
-  int  r;
-  wine_tsx11_lock();
-  r = XDefineCursor(a0, a1, a2);
-  wine_tsx11_unlock();
-  return r;
-}
-
-int  TSXDeleteProperty(Display* a0, Window a1, Atom a2)
-{
-  int  r;
-  wine_tsx11_lock();
-  r = XDeleteProperty(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;
@@ -256,16 +103,7 @@
   return r;
 }
 
-int  TSXDrawRectangle(Display* a0, Drawable a1, GC a2, int a3, int a4, unsigned int a5, unsigned int a6)
-{
-  int  r;
-  wine_tsx11_lock();
-  r = XDrawRectangle(a0, a1, a2, a3, a4, a5, a6);
-  wine_tsx11_unlock();
-  return r;
-}
-
-int  TSXDrawString16(Display* a0, Drawable a1, GC a2, int a3, int a4, const  XChar2b* a5, int a6)
+int  TSXDrawString16(Display* a0, Drawable a1, GC a2, int a3, int a4, const XChar2b* a5, int a6)
 {
   int  r;
   wine_tsx11_lock();
@@ -292,15 +130,6 @@
   return r;
 }
 
-int  TSXFillPolygon(Display* a0, Drawable a1, GC a2, XPoint* a3, int a4, int a5, int a6)
-{
-  int  r;
-  wine_tsx11_lock();
-  r = XFillPolygon(a0, a1, a2, a3, a4, a5, a6);
-  wine_tsx11_unlock();
-  return r;
-}
-
 int  TSXFillRectangle(Display* a0, Drawable a1, GC a2, int a3, int a4, unsigned int a5, unsigned int a6)
 {
   int  r;
@@ -310,15 +139,6 @@
   return r;
 }
 
-int  TSXFlush(Display* a0)
-{
-  int  r;
-  wine_tsx11_lock();
-  r = XFlush(a0);
-  wine_tsx11_unlock();
-  return r;
-}
-
 int  TSXFree(void* a0)
 {
   int  r;
@@ -328,24 +148,6 @@
   return r;
 }
 
-int  TSXFreeColormap(Display* a0, Colormap a1)
-{
-  int  r;
-  wine_tsx11_lock();
-  r = XFreeColormap(a0, a1);
-  wine_tsx11_unlock();
-  return r;
-}
-
-int  TSXFreeColors(Display* a0, Colormap a1, unsigned long* a2, int a3, unsigned long a4)
-{
-  int  r;
-  wine_tsx11_lock();
-  r = XFreeColors(a0, a1, a2, a3, a4);
-  wine_tsx11_unlock();
-  return r;
-}
-
 int  TSXFreeFont(Display* a0, XFontStruct* a1)
 {
   int  r;
@@ -355,15 +157,6 @@
   return r;
 }
 
-int  TSXFreeFontNames(char** a0)
-{
-  int  r;
-  wine_tsx11_lock();
-  r = XFreeFontNames(a0);
-  wine_tsx11_unlock();
-  return r;
-}
-
 int  TSXFreePixmap(Display* a0, Pixmap a1)
 {
   int  r;
@@ -373,29 +166,20 @@
   return r;
 }
 
-int   TSXGetFontProperty(XFontStruct* a0, Atom a1, unsigned long* a2)
+int  TSXGetFontProperty(XFontStruct* a0, Atom a1, unsigned long* a2)
 {
-  int   r;
+  int  r;
   wine_tsx11_lock();
   r = XGetFontProperty(a0, a1, a2);
   wine_tsx11_unlock();
   return r;
 }
 
-int   TSXGetGeometry(Display* a0, Drawable a1, Window* a2, int* a3, int* a4, unsigned int* a5, unsigned int* a6, unsigned int* a7, unsigned int* a8)
-{
-  int   r;
-  wine_tsx11_lock();
-  r = XGetGeometry(a0, a1, a2, a3, a4, a5, a6, a7, a8);
-  wine_tsx11_unlock();
-  return r;
-}
-
-int  TSXGetScreenSaver(Display* a0, int* a1, int* a2, int* a3, int* a4)
+int  TSXGetGeometry(Display* a0, Drawable a1, Window* a2, int* a3, int* a4, unsigned int* a5, unsigned int* a6, unsigned int* a7, unsigned int* a8)
 {
   int  r;
   wine_tsx11_lock();
-  r = XGetScreenSaver(a0, a1, a2, a3, a4);
+  r = XGetGeometry(a0, a1, a2, a3, a4, a5, a6, a7, a8);
   wine_tsx11_unlock();
   return r;
 }
@@ -409,33 +193,6 @@
   return r;
 }
 
-int   TSXGetWindowAttributes(Display* a0, Window a1, XWindowAttributes* a2)
-{
-  int   r;
-  wine_tsx11_lock();
-  r = XGetWindowAttributes(a0, a1, a2);
-  wine_tsx11_unlock();
-  return r;
-}
-
-int  TSXGrabPointer(Display* a0, Window a1, int a2, unsigned int a3, int a4, int a5, Window a6, Cursor a7, Time a8)
-{
-  int  r;
-  wine_tsx11_lock();
-  r = XGrabPointer(a0, a1, a2, a3, a4, a5, a6, a7, a8);
-  wine_tsx11_unlock();
-  return r;
-}
-
-int  TSXGrabServer(Display* a0)
-{
-  int  r;
-  wine_tsx11_lock();
-  r = XGrabServer(a0);
-  wine_tsx11_unlock();
-  return r;
-}
-
 KeyCode  TSXKeysymToKeycode(Display* a0, KeySym a1)
 {
   KeyCode  r;
@@ -454,56 +211,20 @@
   return r;
 }
 
-int  TSXQueryColor(Display* a0, Colormap a1, XColor* a2)
+int  TSXQueryPointer(Display* a0, Window a1, Window* a2, Window* a3, int* a4, int* a5, int* a6, int* a7, unsigned int* a8)
 {
   int  r;
   wine_tsx11_lock();
-  r = XQueryColor(a0, a1, a2);
-  wine_tsx11_unlock();
-  return r;
-}
-
-int  TSXQueryColors(Display* a0, Colormap a1, XColor* a2, int a3)
-{
-  int  r;
-  wine_tsx11_lock();
-  r = XQueryColors(a0, a1, a2, a3);
-  wine_tsx11_unlock();
-  return r;
-}
-
-int   TSXQueryPointer(Display* a0, Window a1, Window* a2, Window* a3, int* a4, int* a5, int* a6, int* a7, unsigned int* a8)
-{
-  int   r;
-  wine_tsx11_lock();
   r = XQueryPointer(a0, a1, a2, a3, a4, a5, a6, a7, a8);
   wine_tsx11_unlock();
   return r;
 }
 
-int   TSXQueryTree(Display* a0, Window a1, Window* a2, Window* a3, Window** a4, unsigned int* a5)
-{
-  int   r;
-  wine_tsx11_lock();
-  r = XQueryTree(a0, a1, a2, a3, a4, a5);
-  wine_tsx11_unlock();
-  return r;
-}
-
-int  TSXRefreshKeyboardMapping(XMappingEvent* a0)
+int  TSXQueryTree(Display* a0, Window a1, Window* a2, Window* a3, Window** a4, unsigned int* a5)
 {
   int  r;
   wine_tsx11_lock();
-  r = XRefreshKeyboardMapping(a0);
-  wine_tsx11_unlock();
-  return r;
-}
-
-int   TSXSendEvent(Display* a0, Window a1, int a2, long a3, XEvent* a4)
-{
-  int   r;
-  wine_tsx11_lock();
-  r = XSendEvent(a0, a1, a2, a3, a4);
+  r = XQueryTree(a0, a1, a2, a3, a4, a5);
   wine_tsx11_unlock();
   return r;
 }
@@ -526,7 +247,7 @@
   return r;
 }
 
-int  TSXSetDashes(Display* a0, GC a1, int a2, const  char* a3, int a4)
+int  TSXSetDashes(Display* a0, GC a1, int a2, const char* a3, int a4)
 {
   int  r;
   wine_tsx11_lock();
@@ -553,15 +274,6 @@
   return r;
 }
 
-int  TSXSetGraphicsExposures(Display* a0, GC a1, int a2)
-{
-  int  r;
-  wine_tsx11_lock();
-  r = XSetGraphicsExposures(a0, a1, a2);
-  wine_tsx11_unlock();
-  return r;
-}
-
 int  TSXSetLineAttributes(Display* a0, GC a1, unsigned int a2, int a3, int a4, int a5)
 {
   int  r;
@@ -571,15 +283,6 @@
   return r;
 }
 
-int  TSXSetScreenSaver(Display* a0, int a1, int a2, int a3, int a4)
-{
-  int  r;
-  wine_tsx11_lock();
-  r = XSetScreenSaver(a0, a1, a2, a3, a4);
-  wine_tsx11_unlock();
-  return r;
-}
-
 int  TSXSetSelectionOwner(Display* a0, Atom a1, Window a2, Time a3)
 {
   int  r;
@@ -616,7 +319,7 @@
   return r;
 }
 
-int  TSXTextExtents16(XFontStruct* a0, const  XChar2b* a1, int a2, int* a3, int* a4, int* a5, XCharStruct* a6)
+int  TSXTextExtents16(XFontStruct* a0, const XChar2b* a1, int a2, int* a3, int* a4, int* a5, XCharStruct* a6)
 {
   int  r;
   wine_tsx11_lock();
@@ -625,7 +328,7 @@
   return r;
 }
 
-int  TSXTextWidth16(XFontStruct* a0, const  XChar2b* a1, int a2)
+int  TSXTextWidth16(XFontStruct* a0, const XChar2b* a1, int a2)
 {
   int  r;
   wine_tsx11_lock();
@@ -634,33 +337,6 @@
   return r;
 }
 
-int  TSXUngrabPointer(Display* a0, Time a1)
-{
-  int  r;
-  wine_tsx11_lock();
-  r = XUngrabPointer(a0, a1);
-  wine_tsx11_unlock();
-  return r;
-}
-
-int  TSXUngrabServer(Display* a0)
-{
-  int  r;
-  wine_tsx11_lock();
-  r = XUngrabServer(a0);
-  wine_tsx11_unlock();
-  return r;
-}
-
-int  TSXUninstallColormap(Display* a0, Colormap a1)
-{
-  int  r;
-  wine_tsx11_lock();
-  r = XUninstallColormap(a0, a1);
-  wine_tsx11_unlock();
-  return r;
-}
-
 int  TSXUnmapWindow(Display* a0, Window a1)
 {
   int  r;
@@ -670,13 +346,4 @@
   return r;
 }
 
-XIM  TSXOpenIM(Display* a0, struct _XrmHashBucketRec* a1, char* a2, char* a3)
-{
-  XIM  r;
-  wine_tsx11_lock();
-  r = XOpenIM(a0, a1, a2, a3);
-  wine_tsx11_unlock();
-  return r;
-}
-
 #endif /* defined(HAVE_X11_XLIB_H) */
diff --git a/dlls/x11drv/ts_xlib.h b/dlls/x11drv/ts_xlib.h
index 056fa56..dc5e643 100644
--- a/dlls/x11drv/ts_xlib.h
+++ b/dlls/x11drv/ts_xlib.h
@@ -19,80 +19,43 @@
 extern void wine_tsx11_lock(void);
 extern void wine_tsx11_unlock(void);
 
-extern XFontStruct * TSXLoadQueryFont(Display*, const  char*);
-extern XImage * TSXGetImage(Display*, Drawable, int, int, unsigned int, unsigned int, unsigned long, int);
-extern Display * TSXOpenDisplay(const  char*);
 extern char * TSXGetAtomName(Display*, Atom);
 extern char * TSXKeysymToString(KeySym);
-extern Atom  TSXInternAtom(Display*, const  char*, int);
-extern Colormap  TSXCreateColormap(Display*, Window, Visual*, int);
-extern Pixmap  TSXCreatePixmap(Display*, Drawable, unsigned int, unsigned int, unsigned int);
-extern Pixmap  TSXCreateBitmapFromData(Display*, Drawable, const  char*, unsigned int, unsigned int);
+extern Atom  TSXInternAtom(Display*, const char*, int);
 extern Window  TSXGetSelectionOwner(Display*, Atom);
-extern char ** TSXListFonts(Display*, const  char*, int, int*);
 extern KeySym  TSXKeycodeToKeysym(Display*, unsigned int, int);
-extern int * TSXListDepths(Display*, int, int*);
-extern int   TSXReconfigureWMWindow(Display*, Window, int, unsigned int, XWindowChanges*);
-extern int   TSXAllocColor(Display*, Colormap, XColor*);
-extern int   TSXAllocColorCells(Display*, Colormap, int, unsigned long*, unsigned int, unsigned long*, unsigned int);
-extern int  TSXBell(Display*, int);
 extern int  TSXChangeGC(Display*, GC, unsigned long, XGCValues*);
-extern int  TSXChangeProperty(Display*, Window, Atom, Atom, int, int, const  unsigned char*, int);
-extern int  TSXChangeWindowAttributes(Display*, Window, unsigned long, XSetWindowAttributes*);
-extern int  TSXCopyArea(Display*, Drawable, Drawable, GC, int, int, unsigned int, unsigned int, int, 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  TSXChangeProperty(Display*, Window, Atom, Atom, int, int, const unsigned char*, 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);
-extern int  TSXDrawRectangle(Display*, Drawable, GC, int, int, unsigned int, unsigned int);
-extern int  TSXDrawString16(Display*, Drawable, GC, int, int, const  XChar2b*, int);
+extern int  TSXDrawString16(Display*, Drawable, GC, int, int, const XChar2b*, int);
 extern int  TSXDrawText16(Display*, Drawable, GC, int, int, XTextItem16*, int);
 extern int  TSXFillArc(Display*, Drawable, GC, int, int, unsigned int, unsigned int, int, int);
-extern int  TSXFillPolygon(Display*, Drawable, GC, XPoint*, int, int, int);
 extern int  TSXFillRectangle(Display*, Drawable, GC, int, int, unsigned int, unsigned int);
-extern int  TSXFlush(Display*);
 extern int  TSXFree(void*);
-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  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  TSXGetScreenSaver(Display*, int*, int*, int*, int*);
+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  TSXGetWindowProperty(Display*, Window, Atom, long, long, int, Atom, Atom*, int*, unsigned long*, unsigned long*, unsigned char**);
-extern int   TSXGetWindowAttributes(Display*, Window, XWindowAttributes*);
-extern int  TSXGrabPointer(Display*, Window, int, unsigned int, int, int, Window, Cursor, Time);
-extern int  TSXGrabServer(Display*);
 extern KeyCode  TSXKeysymToKeycode(Display*, KeySym);
 extern int  TSXMapWindow(Display*, Window);
-extern int  TSXQueryColor(Display*, Colormap, XColor*);
-extern int  TSXQueryColors(Display*, Colormap, XColor*, int);
-extern int   TSXQueryPointer(Display*, Window, Window*, Window*, int*, int*, int*, int*, unsigned int*);
-extern int   TSXQueryTree(Display*, Window, Window*, Window*, Window**, unsigned int*);
-extern int  TSXRefreshKeyboardMapping(XMappingEvent*);
-extern int   TSXSendEvent(Display*, Window, int, long, XEvent*);
+extern int  TSXQueryPointer(Display*, Window, Window*, Window*, int*, int*, int*, int*, unsigned int*);
+extern int  TSXQueryTree(Display*, Window, Window*, Window*, Window**, unsigned int*);
 extern int  TSXSetArcMode(Display*, GC, int);
 extern int  TSXSetClipRectangles(Display*, GC, int, int, XRectangle*, int, int);
-extern int  TSXSetDashes(Display*, GC, int, const  char*, int);
+extern int  TSXSetDashes(Display*, GC, int, const char*, int);
 extern int  TSXSetForeground(Display*, GC, unsigned long);
 extern int  TSXSetFunction(Display*, GC, int);
-extern int  TSXSetGraphicsExposures(Display*, GC, int);
 extern int  TSXSetLineAttributes(Display*, GC, unsigned int, int, int, int);
-extern int  TSXSetScreenSaver(Display*, int, int, int, int);
 extern int  TSXSetSelectionOwner(Display*, Atom, Window, Time);
 extern int  TSXSetSubwindowMode(Display*, GC, int);
 extern int  TSXStoreColor(Display*, Colormap, XColor*);
 extern int  TSXSync(Display*, int);
-extern int  TSXTextExtents16(XFontStruct*, const  XChar2b*, int, int*, int*, int*, XCharStruct*);
-extern int  TSXTextWidth16(XFontStruct*, const  XChar2b*, int);
-extern int  TSXUngrabPointer(Display*, Time);
-extern int  TSXUngrabServer(Display*);
-extern int  TSXUninstallColormap(Display*, Colormap);
+extern int  TSXTextExtents16(XFontStruct*, const XChar2b*, int, int*, int*, int*, XCharStruct*);
+extern int  TSXTextWidth16(XFontStruct*, const XChar2b*, int);
 extern int  TSXUnmapWindow(Display*, Window);
-extern XIM  TSXOpenIM(Display*, struct _XrmHashBucketRec*, char*, char*);
 
 #endif /* defined(HAVE_X11_XLIB_H) */
 
diff --git a/dlls/x11drv/window.c b/dlls/x11drv/window.c
index 0d33423..eb9ed45 100644
--- a/dlls/x11drv/window.c
+++ b/dlls/x11drv/window.c
@@ -1256,8 +1256,10 @@
 
     if (!hwnd)  /* If setting the focus to 0, uninstall the colormap */
     {
+        wine_tsx11_lock();
         if (X11DRV_PALETTE_PaletteFlags & X11DRV_PALETTE_PRIVATE)
-            TSXUninstallColormap( display, X11DRV_PALETTE_PaletteXColormap );
+            XUninstallColormap( display, X11DRV_PALETTE_PaletteXColormap );
+        wine_tsx11_unlock();
         return;
     }
 
diff --git a/dlls/x11drv/winpos.c b/dlls/x11drv/winpos.c
index 6a5bcdf..f8f31fc 100644
--- a/dlls/x11drv/winpos.c
+++ b/dlls/x11drv/winpos.c
@@ -2205,8 +2205,11 @@
             WND *ptr = WIN_FindWndPtr( list[i] );
             if (!ptr) continue;
             if (!IsRectEmpty( &ptr->rectWindow ) && get_whole_window(ptr))
-                TSXReconfigureWMWindow( display, get_whole_window(ptr), 0,
-                                        CWStackMode, &winChanges );
+            {
+                wine_tsx11_lock();
+                XReconfigureWMWindow( display, get_whole_window(ptr), 0, CWStackMode, &winChanges );
+                wine_tsx11_unlock();
+            }
             WIN_ReleaseWndPtr( ptr );
         }
     }
diff --git a/dlls/x11drv/x11ddraw.c b/dlls/x11drv/x11ddraw.c
index 996f4d5..b1818c0 100644
--- a/dlls/x11drv/x11ddraw.c
+++ b/dlls/x11drv/x11ddraw.c
@@ -83,11 +83,15 @@
       win = root_window;
     }
 
-    TSXGrabPointer(display, win, True, 0, GrabModeAsync, GrabModeAsync, win, None, CurrentTime);
+    wine_tsx11_lock();
+    XGrabPointer(display, win, True, 0, GrabModeAsync, GrabModeAsync, win, None, CurrentTime);
+    wine_tsx11_unlock();
   }
   else
   {
-    TSXUngrabPointer(display, CurrentTime);
+    wine_tsx11_lock();
+    XUngrabPointer(display, CurrentTime);
+    wine_tsx11_unlock();
   }
 
   return 0;
@@ -212,7 +216,12 @@
 static DWORD PASCAL X11DRV_DDHAL_DestroyPalette(LPDDHAL_DESTROYPALETTEDATA data)
 {
   Colormap pal = data->lpDDPalette->u1.dwReserved1;
-  if (pal) TSXFreeColormap(gdi_display, pal);
+  if (pal)
+  {
+      wine_tsx11_lock();
+      XFreeColormap(gdi_display, pal);
+      wine_tsx11_unlock();
+  }
   data->ddRVal = DD_OK;
   return DDHAL_DRIVER_HANDLED;
 }
@@ -426,14 +435,16 @@
   int n;
 
   if (pal) {
+    wine_tsx11_lock();
     c.flags = DoRed|DoGreen|DoBlue;
     c.pixel = dwBase;
     for (n=0; n<dwNumEntries; n++,c.pixel++) {
       c.red   = lpEntries[n].peRed   << 8;
       c.green = lpEntries[n].peGreen << 8;
       c.blue  = lpEntries[n].peBlue  << 8;
-      TSXStoreColor(gdi_display, pal, &c);
+      XStoreColor(gdi_display, pal, &c);
     }
-    TSXFlush(gdi_display); /* update display immediately */
+    XFlush(gdi_display); /* update display immediately */
+    wine_tsx11_unlock();
   }
 }
diff --git a/dlls/x11drv/x11drv_main.c b/dlls/x11drv/x11drv_main.c
index 03e610a..d2c196c 100644
--- a/dlls/x11drv/x11drv_main.c
+++ b/dlls/x11drv/x11drv_main.c
@@ -309,7 +309,7 @@
 
     /* Open display */
 
-    if (!(display = TSXOpenDisplay( NULL )))
+    if (!(display = XOpenDisplay( NULL )))
     {
         MESSAGE( "x11drv: Can't open display: %s\n", XDisplayName(NULL) );
         ExitProcess(1);
@@ -325,10 +325,10 @@
     if (screen_depth)  /* depth specified */
     {
         int depth_count, i;
-        int *depth_list = TSXListDepths(display, DefaultScreen(display), &depth_count);
+        int *depth_list = XListDepths(display, DefaultScreen(display), &depth_count);
         for (i = 0; i < depth_count; i++)
             if (depth_list[i] == screen_depth) break;
-        TSXFree( depth_list );
+        XFree( depth_list );
         if (i >= depth_count)
 	{
             MESSAGE( "x11drv: Depth %d not supported on this screen.\n", screen_depth );
@@ -508,7 +508,9 @@
 BOOL X11DRV_GetScreenSaveActive(void)
 {
     int timeout, temp;
-    TSXGetScreenSaver(gdi_display, &timeout, &temp, &temp, &temp);
+    wine_tsx11_lock();
+    XGetScreenSaver(gdi_display, &timeout, &temp, &temp, &temp);
+    wine_tsx11_unlock();
     return timeout != 0;
 }
 
@@ -522,11 +524,13 @@
     int timeout, interval, prefer_blanking, allow_exposures;
     static int last_timeout = 15 * 60;
 
-    TSXGetScreenSaver(gdi_display, &timeout, &interval, &prefer_blanking,
-                      &allow_exposures);
+    wine_tsx11_lock();
+    XGetScreenSaver(gdi_display, &timeout, &interval, &prefer_blanking,
+                    &allow_exposures);
     if (timeout) last_timeout = timeout;
 
     timeout = bActivate ? last_timeout : 0;
-    TSXSetScreenSaver(gdi_display, timeout, interval, prefer_blanking,
-                      allow_exposures);
+    XSetScreenSaver(gdi_display, timeout, interval, prefer_blanking,
+                    allow_exposures);
+    wine_tsx11_unlock();
 }
diff --git a/graphics/x11drv/bitmap.c b/graphics/x11drv/bitmap.c
index fb3826c..381de6a 100644
--- a/graphics/x11drv/bitmap.c
+++ b/graphics/x11drv/bitmap.c
@@ -145,9 +145,12 @@
 	  bmp->bitmap.bmHeight, bmp->bitmap.bmBitsPixel);
 
       /* Create the pixmap */
-    if (!(bmp->physBitmap = (void *)TSXCreatePixmap(gdi_display, root_window,
-                                                    bmp->bitmap.bmWidth, bmp->bitmap.bmHeight,
-                                                    bmp->bitmap.bmBitsPixel)))
+    wine_tsx11_lock();
+    bmp->physBitmap = (void *)XCreatePixmap(gdi_display, root_window,
+                                            bmp->bitmap.bmWidth, bmp->bitmap.bmHeight,
+                                            bmp->bitmap.bmBitsPixel);
+    wine_tsx11_unlock();
+    if (!bmp->physBitmap)
     {
         WARN("Can't create Pixmap\n");
 	GDI_ReleaseObj( hbitmap );
diff --git a/graphics/x11drv/brush.c b/graphics/x11drv/brush.c
index c52fc78..bda7fe8 100644
--- a/graphics/x11drv/brush.c
+++ b/graphics/x11drv/brush.c
@@ -185,21 +185,23 @@
 
     if(!bmp->physBitmap) goto done;
 
+    wine_tsx11_lock();
     if ((dc->bitsPerPixel == 1) && (bmp->bitmap.bmBitsPixel != 1))
     {
         /* Special case: a color pattern on a monochrome DC */
-        physDev->brush.pixmap = TSXCreatePixmap( gdi_display, root_window, 8, 8, 1);
+        physDev->brush.pixmap = XCreatePixmap( gdi_display, root_window, 8, 8, 1);
         /* FIXME: should probably convert to monochrome instead */
-        TSXCopyPlane( gdi_display, (Pixmap)bmp->physBitmap, physDev->brush.pixmap,
-                      BITMAP_monoGC, 0, 0, 8, 8, 0, 0, 1 );
+        XCopyPlane( gdi_display, (Pixmap)bmp->physBitmap, physDev->brush.pixmap,
+                    BITMAP_monoGC, 0, 0, 8, 8, 0, 0, 1 );
     }
     else
     {
-        physDev->brush.pixmap = TSXCreatePixmap( gdi_display, root_window,
-                                                 8, 8, bmp->bitmap.bmBitsPixel );
-        TSXCopyArea( gdi_display, (Pixmap)bmp->physBitmap, physDev->brush.pixmap,
-                     BITMAP_GC(bmp), 0, 0, 8, 8, 0, 0 );
+        physDev->brush.pixmap = XCreatePixmap( gdi_display, root_window,
+                                               8, 8, bmp->bitmap.bmBitsPixel );
+        XCopyArea( gdi_display, (Pixmap)bmp->physBitmap, physDev->brush.pixmap,
+                   BITMAP_GC(bmp), 0, 0, 8, 8, 0, 0 );
     }
+    wine_tsx11_unlock();
 
     if (bmp->bitmap.bmBitsPixel > 1)
     {
@@ -254,8 +256,10 @@
       case BS_HATCHED:
 	TRACE("BS_HATCHED\n" );
 	physDev->brush.pixel = X11DRV_PALETTE_ToPhysical( physDev, logbrush.lbColor );
-	physDev->brush.pixmap = TSXCreateBitmapFromData( gdi_display, root_window,
-				 HatchBrushes[logbrush.lbHatch], 8, 8 );
+        wine_tsx11_lock();
+        physDev->brush.pixmap = XCreateBitmapFromData( gdi_display, root_window,
+                                                       HatchBrushes[logbrush.lbHatch], 8, 8 );
+        wine_tsx11_unlock();
 	physDev->brush.fillStyle = FillStippled;
 	break;
 
diff --git a/graphics/x11drv/clipping.c b/graphics/x11drv/clipping.c
index a9cac64..8d81cdb 100644
--- a/graphics/x11drv/clipping.c
+++ b/graphics/x11drv/clipping.c
@@ -159,7 +159,9 @@
     if (dc)
     {
         X11DRV_PDEVICE *physDev = (X11DRV_PDEVICE *)dc->physDev;
-        TSXSetGraphicsExposures( gdi_display, physDev->gc, True );
+        wine_tsx11_lock();
+        XSetGraphicsExposures( gdi_display, physDev->gc, True );
+        wine_tsx11_unlock();
         physDev->exposures = 0;
         GDI_ReleaseObj( hdc );
     }
@@ -186,7 +188,6 @@
         XSetGraphicsExposures( gdi_display, physDev->gc, False );
         if (physDev->exposures)
         {
-            XSync( gdi_display, False );
             for (;;)
             {
                 XWindowEvent( gdi_display, physDev->drawable, ~0, &event );
diff --git a/graphics/x11drv/graphics.c b/graphics/x11drv/graphics.c
index 7b7729c..a607841 100644
--- a/graphics/x11drv/graphics.c
+++ b/graphics/x11drv/graphics.c
@@ -625,18 +625,22 @@
     {
         if (X11DRV_SetupGCForBrush( physDev ))
 	{
-            TSXFillRectangle( gdi_display, physDev->drawable, physDev->gc,
-                              physDev->org.x + rc.left + (width + 1) / 2,
-                              physDev->org.y + rc.top + (width + 1) / 2,
-                              rc.right-rc.left-width-1, rc.bottom-rc.top-width-1);
+            wine_tsx11_lock();
+            XFillRectangle( gdi_display, physDev->drawable, physDev->gc,
+                            physDev->org.x + rc.left + (width + 1) / 2,
+                            physDev->org.y + rc.top + (width + 1) / 2,
+                            rc.right-rc.left-width-1, rc.bottom-rc.top-width-1);
+            wine_tsx11_unlock();
 	    update = TRUE;
 	}
     }
     if (X11DRV_SetupGCForPen( physDev ))
     {
-        TSXDrawRectangle( gdi_display, physDev->drawable, physDev->gc,
-                          physDev->org.x + rc.left, physDev->org.y + rc.top,
-                          rc.right-rc.left-1, rc.bottom-rc.top-1 );
+        wine_tsx11_lock();
+        XDrawRectangle( gdi_display, physDev->drawable, physDev->gc,
+                        physDev->org.x + rc.left, physDev->org.y + rc.top,
+                        rc.right-rc.left-1, rc.bottom-rc.top-1 );
+        wine_tsx11_unlock();
 	update = TRUE;
     }
 
@@ -1038,14 +1042,18 @@
 
     if (X11DRV_SetupGCForBrush( physDev ))
     {
-        TSXFillPolygon( gdi_display, physDev->drawable, physDev->gc,
-                        points, count+1, Complex, CoordModeOrigin);
+        wine_tsx11_lock();
+        XFillPolygon( gdi_display, physDev->drawable, physDev->gc,
+                      points, count+1, Complex, CoordModeOrigin);
+        wine_tsx11_unlock();
 	update = TRUE;
     }
     if (X11DRV_SetupGCForPen ( physDev ))
     {
-        TSXDrawLines( gdi_display, physDev->drawable, physDev->gc,
-                      points, count+1, CoordModeOrigin );
+        wine_tsx11_lock();
+        XDrawLines( gdi_display, physDev->drawable, physDev->gc,
+                    points, count+1, CoordModeOrigin );
+        wine_tsx11_unlock();
 	update = TRUE;
     }
 
@@ -1240,12 +1248,13 @@
     if (!PtVisible( physDev->hdc, x, y )) return FALSE;
     if (GetRgnBox( dc->hGCClipRgn, &rect ) == ERROR) return FALSE;
 
-    if (!(image = TSXGetImage( gdi_display, physDev->drawable,
-                               physDev->org.x + rect.left,
-                               physDev->org.y + rect.top,
-                               rect.right - rect.left,
-                               rect.bottom - rect.top,
-                               AllPlanes, ZPixmap ))) return FALSE;
+    wine_tsx11_lock();
+    image = XGetImage( gdi_display, physDev->drawable,
+                       physDev->org.x + rect.left, physDev->org.y + rect.top,
+                       rect.right - rect.left, rect.bottom - rect.top,
+                       AllPlanes, ZPixmap );
+    wine_tsx11_unlock();
+    if (!image) return FALSE;
 
     if (X11DRV_SetupGCForBrush( physDev ))
     {
diff --git a/graphics/x11drv/palette.c b/graphics/x11drv/palette.c
index 3c52295..6490879 100644
--- a/graphics/x11drv/palette.c
+++ b/graphics/x11drv/palette.c
@@ -152,12 +152,13 @@
 	    RegCloseKey(hkey);
 	}
 
+        wine_tsx11_lock();
 	if (private_color_map)
 	{
 	    XSetWindowAttributes win_attr;
 
-	    X11DRV_PALETTE_PaletteXColormap = TSXCreateColormap( gdi_display, root_window,
-						 visual, AllocAll );
+	    X11DRV_PALETTE_PaletteXColormap = XCreateColormap( gdi_display, root_window,
+                                                               visual, AllocAll );
 	    if (X11DRV_PALETTE_PaletteXColormap)
 	    {
 	        X11DRV_PALETTE_PaletteFlags |= (X11DRV_PALETTE_PRIVATE | X11DRV_PALETTE_WHITESET);
@@ -169,21 +170,24 @@
 	        if( root_window != DefaultRootWindow(gdi_display) )
 	        {
 		    win_attr.colormap = X11DRV_PALETTE_PaletteXColormap;
-		    TSXChangeWindowAttributes( gdi_display, root_window, CWColormap, &win_attr );
+		    XChangeWindowAttributes( gdi_display, root_window, CWColormap, &win_attr );
 		}
 		break;
 	    }
 	}
-        X11DRV_PALETTE_PaletteXColormap = TSXCreateColormap(gdi_display, root_window,
-                                                            visual, AllocNone);
+        X11DRV_PALETTE_PaletteXColormap = XCreateColormap(gdi_display, root_window,
+                                                          visual, AllocNone);
+        wine_tsx11_unlock();
         break;
     }
 
     case StaticGray:
-        X11DRV_PALETTE_PaletteXColormap = TSXCreateColormap(gdi_display, root_window,
-                                                            visual, AllocNone);
+        wine_tsx11_lock();
+        X11DRV_PALETTE_PaletteXColormap = XCreateColormap(gdi_display, root_window,
+                                                          visual, AllocNone);
 	X11DRV_PALETTE_PaletteFlags |= X11DRV_PALETTE_FIXED;
         X11DRV_PALETTE_Graymax = (1 << screen_depth)-1;
+        wine_tsx11_unlock();
         break;
 
     case TrueColor:
@@ -193,24 +197,27 @@
 	/* FIXME: hack to detect XFree32 XF_VGA16 ... We just have
 	 * depths 1 and 4
 	 */
-	depths=TSXListDepths(gdi_display,DefaultScreen(gdi_display),&nrofdepths);
+        wine_tsx11_lock();
+        depths = XListDepths(gdi_display,DefaultScreen(gdi_display),&nrofdepths);
 	if ((nrofdepths==2) && ((depths[0]==4) || depths[1]==4)) {
 	    monoPlane = 1;
 	    for( white = palette_size - 1; !(white & 1); white >>= 1 )
 	        monoPlane++;
     	    X11DRV_PALETTE_PaletteFlags = (white & mask) ? X11DRV_PALETTE_WHITESET : 0;
-            X11DRV_PALETTE_PaletteXColormap = TSXCreateColormap(gdi_display, root_window,
-                                                                visual, AllocNone);
-	    TSXFree(depths);
-	    break;
+            X11DRV_PALETTE_PaletteXColormap = XCreateColormap(gdi_display, root_window,
+                                                              visual, AllocNone);
 	}
-	TSXFree(depths);
-        X11DRV_PALETTE_PaletteXColormap = TSXCreateColormap(gdi_display, root_window,
-                                                            visual, AllocNone);
-        X11DRV_PALETTE_PaletteFlags |= X11DRV_PALETTE_FIXED;
-        X11DRV_PALETTE_ComputeShifts(visual->red_mask, &X11DRV_PALETTE_PRed, &X11DRV_PALETTE_LRed);
-        X11DRV_PALETTE_ComputeShifts(visual->green_mask, &X11DRV_PALETTE_PGreen, &X11DRV_PALETTE_LGreen);
-        X11DRV_PALETTE_ComputeShifts(visual->blue_mask, &X11DRV_PALETTE_PBlue, &X11DRV_PALETTE_LBlue);
+        else
+        {
+            X11DRV_PALETTE_PaletteXColormap = XCreateColormap(gdi_display, root_window,
+                                                              visual, AllocNone);
+            X11DRV_PALETTE_PaletteFlags |= X11DRV_PALETTE_FIXED;
+            X11DRV_PALETTE_ComputeShifts(visual->red_mask, &X11DRV_PALETTE_PRed, &X11DRV_PALETTE_LRed);
+            X11DRV_PALETTE_ComputeShifts(visual->green_mask, &X11DRV_PALETTE_PGreen, &X11DRV_PALETTE_LGreen);
+            X11DRV_PALETTE_ComputeShifts(visual->blue_mask, &X11DRV_PALETTE_PBlue, &X11DRV_PALETTE_LBlue);
+        }
+        XFree(depths);
+        wine_tsx11_unlock();
         break;
       }
     }
@@ -250,9 +257,13 @@
 void X11DRV_PALETTE_Cleanup(void)
 {
   if( COLOR_gapFilled )
-    TSXFreeColors(gdi_display, X11DRV_PALETTE_PaletteXColormap,
+  {
+      wine_tsx11_lock();
+      XFreeColors(gdi_display, X11DRV_PALETTE_PaletteXColormap,
 		  (unsigned long*)(X11DRV_PALETTE_PaletteToXPixel + COLOR_gapStart),
 		  COLOR_gapFilled, 0);
+      wine_tsx11_unlock();
+  }
 }
 
 /***********************************************************************
@@ -796,8 +807,10 @@
 		   ((X11DRV_PALETTE_XPixelToPalette)?X11DRV_PALETTE_XPixelToPalette[pixel]:pixel)) ) & 0x00ffffff;
     }
 
+    wine_tsx11_lock();
     color.pixel = pixel;
-    TSXQueryColor(gdi_display, X11DRV_PALETTE_PaletteXColormap, &color);
+    XQueryColor(gdi_display, X11DRV_PALETTE_PaletteXColormap, &color);
+    wine_tsx11_unlock();
     return RGB(color.red >> 8, color.green >> 8, color.blue >> 8);
 }
 
diff --git a/graphics/x11drv/xfont.c b/graphics/x11drv/xfont.c
index 03997a3..3382503 100644
--- a/graphics/x11drv/xfont.c
+++ b/graphics/x11drv/xfont.c
@@ -2928,7 +2928,9 @@
   HKEY hkey;
 
 
-  x_pattern = TSXListFonts(gdi_display, "*", MAX_FONTS, &x_count );
+  wine_tsx11_lock();
+  x_pattern = XListFonts(gdi_display, "*", MAX_FONTS, &x_count );
+  wine_tsx11_unlock();
 
   TRACE("Font Mapper: initializing %i x11 fonts\n", x_count);
   if (x_count == MAX_FONTS)
@@ -2988,7 +2990,8 @@
       }
   }
 
-  TSXFreeFontNames(x_pattern);
+  wine_tsx11_lock();
+  XFreeFontNames(x_pattern);
 
   /* check if we're dealing with X11 R6 server */
   {
@@ -2997,9 +3000,11 @@
       if( (x_fs = safe_XLoadQueryFont(gdi_display, buffer)) )
       {
 	  text_caps |= TC_SF_X_YINDEP;
-	  TSXFreeFont(gdi_display, x_fs);
+	  XFreeFont(gdi_display, x_fs);
       }
   }
+  wine_tsx11_unlock();
+
   HeapFree(GetProcessHeap(), 0, buffer);
 
   XFONT_WindowsNames();