changeset 1168:045f186426e1

Dynamically load X11 libraries like we currently do for alsa, esd, etc. This allows you to run an SDL program on a system without Xlib, since it'll just report the x11 target unavailable at runtime.
author Ryan C. Gordon <icculus@icculus.org>
date Sat, 05 Nov 2005 19:53:37 +0000
parents 435c2e481299
children 4b3e2294782d
files configure.in src/video/Xext/Xinerama/Xinerama.c src/video/Xext/Xv/Xv.c src/video/Xext/Xv/Xvlibint.h src/video/Xext/Xxf86dga/XF86DGA.c src/video/Xext/Xxf86dga/XF86DGA2.c src/video/Xext/Xxf86vm/XF86VMode.c src/video/Xext/extensions/extutil.h src/video/dga/SDL_dgaevents.c src/video/dga/SDL_dgavideo.c src/video/x11/Makefile.am src/video/x11/SDL_x11dyn.c src/video/x11/SDL_x11dyn.h src/video/x11/SDL_x11events.c src/video/x11/SDL_x11gamma.c src/video/x11/SDL_x11gl.c src/video/x11/SDL_x11image.c src/video/x11/SDL_x11modes.c src/video/x11/SDL_x11mouse.c src/video/x11/SDL_x11sym.h src/video/x11/SDL_x11video.c src/video/x11/SDL_x11video.h src/video/x11/SDL_x11wm.c src/video/x11/SDL_x11yuv.c
diffstat 24 files changed, 942 insertions(+), 514 deletions(-) [+]
line wrap: on
line diff
--- a/configure.in	Sat Nov 05 17:41:11 2005 +0000
+++ b/configure.in	Sat Nov 05 19:53:37 2005 +0000
@@ -609,11 +609,45 @@
         AC_PATH_X
         AC_PATH_XTRA
         if test x$have_x = xyes; then
-            CFLAGS="$CFLAGS $X_CFLAGS -DENABLE_X11 -DXTHREADS -I$srcdir/include -I$srcdir/src/video"
+            AC_ARG_ENABLE(x11-shared,
+[  --enable-x11-shared     dynamically load X11 support [default=yes]],
+                          , enable_x11_shared=yes)
+
+            dnl !!! FIXME: make this work?
+            dnl x11_lib_spec=`echo $X11_LIBS | sed 's/.*-L\([[^ ]]*\).*/\1\/libX11.so.*/'`
+            dnl x11_lib=`ls $x11_lib_spec | sed 's/.*\/\(.*\)/\1/; q'`
+            dnl echo "-- $x11_lib_spec -> $x11_lib"
+            dnl x11ext_lib_spec=`echo $X11EXT_LIBS | sed 's/.*-L\([[^ ]]*\).*/\1\/libXext.so.*/'`
+            dnl x11ext_lib=`ls $x11ext_lib_spec | sed 's/.*\/\(.*\)/\1/; q'`
+            dnl echo "-- $x11ext_lib_spec -> $x11ext_lib"
+
+            x11_lib_spec='/usr/X11R6/lib/libX11.so.*'
+            x11_lib='libX11.so.6'
+            echo "-- $x11_lib_spec -> $x11_lib"
+            x11ext_lib_spec='/usr/X11R6/lib/libXext.so.*'
+            x11_lib='libXext.so.6'
+            echo "-- $x11ext_lib_spec -> $x11_lib"
+
+            if test x$use_dlopen != xyes && \
+               test x$enable_x11_shared = xyes; then
+                AC_MSG_ERROR([You must have dlopen() support and use the --enable-dlopen option])
+            fi
+
+            if test x$use_dlopen = xyes && \
+               test x$enable_x11_shared = xyes && test x$x11_lib != x; then
+                CFLAGS="$CFLAGS $X_CFLAGS -DENABLE_X11 -DXTHREADS -DX11_DYNAMIC=\$(x11_lib) -DX11EXT_DYNAMIC=\$(x11ext_lib) -I$srcdir/include -I$srcdir/src/video"
+                SYSTEM_LIBS="$SYSTEM_LIBS $X_LIBS"
+                AC_SUBST(x11_lib)
+                AC_SUBST(x11ext_lib)
+            else
+                CFLAGS="$CFLAGS $X_CFLAGS -DENABLE_X11 -DXTHREADS -I$srcdir/include -I$srcdir/src/video"
+                SYSTEM_LIBS="$SYSTEM_LIBS $X_LIBS -lX11 -lXext"
+            fi
+
             if test x$ac_cv_func_shmat != xyes; then
                 CFLAGS="$CFLAGS -DNO_SHARED_MEMORY"
             fi
-            SYSTEM_LIBS="$SYSTEM_LIBS $X_LIBS -lX11 -lXext"
+
             VIDEO_SUBDIRS="$VIDEO_SUBDIRS x11"
             VIDEO_DRIVERS="$VIDEO_DRIVERS x11/libvideo_x11.la"
 
--- a/src/video/Xext/Xinerama/Xinerama.c	Sat Nov 05 17:41:11 2005 +0000
+++ b/src/video/Xext/Xinerama/Xinerama.c	Sat Nov 05 19:53:37 2005 +0000
@@ -35,6 +35,13 @@
 #include "panoramiXproto.h"		/* in ../include */
 #include "Xinerama.h"
 
+#include "../../x11/SDL_x11dyn.h"
+
+/* Workaround code in headers... */
+#define _XFlush p_XFlush
+#define _XFlushGCCache p_XFlushGCCache
+#define _XReply p_XReply
+#define _XSend p_XSend
 
 static XExtensionInfo _panoramiX_ext_info_data;
 static XExtensionInfo *panoramiX_ext_info = &_panoramiX_ext_info_data;
@@ -111,7 +118,7 @@
     req->panoramiXReqType = X_PanoramiXQueryVersion;
     req->clientMajor = PANORAMIX_MAJOR_VERSION;
     req->clientMinor = PANORAMIX_MINOR_VERSION;
-    if (!_XReply (dpy, (xReply *) &rep, 0, xTrue)) {
+    if (!p_XReply (dpy, (xReply *) &rep, 0, xTrue)) {
 	UnlockDisplay (dpy);
 	SyncHandle ();
 	return 0;
@@ -145,7 +152,7 @@
     req->reqType = info->codes->major_opcode;
     req->panoramiXReqType = X_PanoramiXGetState;
     req->window = drawable;
-    if (!_XReply (dpy, (xReply *) &rep, 0, xTrue)) {
+    if (!p_XReply (dpy, (xReply *) &rep, 0, xTrue)) {
 	UnlockDisplay (dpy);
 	SyncHandle ();
 	return 0;
@@ -174,7 +181,7 @@
     req->reqType = info->codes->major_opcode;
     req->panoramiXReqType = X_PanoramiXGetScreenCount;
     req->window = drawable;
-    if (!_XReply (dpy, (xReply *) &rep, 0, xTrue)) {
+    if (!p_XReply (dpy, (xReply *) &rep, 0, xTrue)) {
 	UnlockDisplay (dpy);
 	SyncHandle ();
 	return 0;
@@ -205,7 +212,7 @@
     req->panoramiXReqType = X_PanoramiXGetScreenSize;
     req->window = drawable;
     req->screen = screen_num;			/* need to define */ 
-    if (!_XReply (dpy, (xReply *) &rep, 0, xTrue)) {
+    if (!p_XReply (dpy, (xReply *) &rep, 0, xTrue)) {
 	UnlockDisplay (dpy);
 	SyncHandle ();
 	return 0;
@@ -285,7 +292,7 @@
     GetReq (XineramaQueryScreens, req);
     req->reqType = info->codes->major_opcode;
     req->panoramiXReqType = X_XineramaQueryScreens;
-    if (!_XReply (dpy, (xReply *) &rep, 0, xFalse)) {
+    if (!p_XReply (dpy, (xReply *) &rep, 0, xFalse)) {
 	UnlockDisplay (dpy);
 	SyncHandle ();
 	return NULL;
@@ -297,7 +304,7 @@
 	    int i;
 
 	    for(i = 0; i < rep.number; i++) {
-		_XRead(dpy, (char*)(&scratch), sz_XineramaScreenInfo);
+		p_XRead(dpy, (char*)(&scratch), sz_XineramaScreenInfo);
 		scrnInfo[i].screen_number = i;
 		scrnInfo[i].x_org 	  = scratch.x_org;
 		scrnInfo[i].y_org 	  = scratch.y_org;
@@ -307,7 +314,7 @@
 
 	    *number = rep.number;
 	} else
-	    _XEatData(dpy, rep.length << 2);
+	    p_XEatData(dpy, rep.length << 2);
     }
 
     UnlockDisplay (dpy);
--- a/src/video/Xext/Xv/Xv.c	Sat Nov 05 17:41:11 2005 +0000
+++ b/src/video/Xext/Xv/Xv.c	Sat Nov 05 19:53:37 2005 +0000
@@ -56,6 +56,14 @@
 #include <X11/extensions/XShm.h>
 #include "extutil.h"
 
+#include "../../x11/SDL_x11dyn.h"
+
+/* Workaround code in headers... */
+#define _XFlush p_XFlush
+#define _XFlushGCCache p_XFlushGCCache
+#define _XReply p_XReply
+#define _XSend p_XSend
+
 static XExtensionInfo _xv_info_data;
 static XExtensionInfo *xv_info = &_xv_info_data;
 static char *xv_extension_name = XvName;
@@ -121,7 +129,7 @@
 
   XvGetReq(QueryExtension, req);
 
-  if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) {
+  if (!p_XReply(dpy, (xReply *)&rep, 0, xFalse)) {
      UnlockDisplay(dpy);
      SyncHandle();
      return XvBadExtension;
@@ -171,7 +179,7 @@
 
   /* READ THE REPLY */
 
-  if (_XReply(dpy, (xReply *)&rep, 0, xFalse) == 0) {
+  if (p_XReply(dpy, (xReply *)&rep, 0, xFalse) == 0) {
       UnlockDisplay(dpy);
       SyncHandle();
       return(XvBadReply);
@@ -183,7 +191,7 @@
       SyncHandle();
       return(XvBadAlloc);
   }
-  _XRead (dpy, buffer, size);
+  p_XRead (dpy, buffer, size);
 
   u.buffer = buffer;
 
@@ -331,7 +339,7 @@
 
   /* READ THE REPLY */
 
-  if (_XReply(dpy, (xReply *)&rep, 0, xFalse) == 0) {
+  if (p_XReply(dpy, (xReply *)&rep, 0, xFalse) == 0) {
       UnlockDisplay(dpy);
       SyncHandle();
       return(XvBadReply);
@@ -343,7 +351,7 @@
       SyncHandle();
       return(XvBadAlloc);
   }
-  _XRead (dpy, buffer, size);
+  p_XRead (dpy, buffer, size);
 
   u.buffer = buffer;
 
@@ -619,7 +627,7 @@
   req->port = port;
   req->time = time;
 
-  if (_XReply (dpy, (xReply *) &rep, 0, xTrue) == 0) 
+  if (p_XReply (dpy, (xReply *) &rep, 0, xTrue) == 0) 
     rep.result = GrabSuccess;
 
   result = rep.result;
@@ -747,7 +755,7 @@
 
   /* READ THE REPLY */
 
-  if (_XReply(dpy, (xReply *)&rep, 0, xFalse) == 0) {
+  if (p_XReply(dpy, (xReply *)&rep, 0, xFalse) == 0) {
       UnlockDisplay(dpy);
       SyncHandle();
       return(XvBadReply);
@@ -792,7 +800,7 @@
 
   /* READ THE REPLY */
 
-  if (_XReply(dpy, (xReply *)&rep, 0, xFalse) == 0) {
+  if (p_XReply(dpy, (xReply *)&rep, 0, xFalse) == 0) {
       UnlockDisplay(dpy);
       SyncHandle();
       return(XvBadReply);
@@ -827,7 +835,7 @@
 
   /* READ THE REPLY */
 
-  if (_XReply(dpy, (xReply *)&rep, 0, xFalse) == 0) {
+  if (p_XReply(dpy, (xReply *)&rep, 0, xFalse) == 0) {
       UnlockDisplay(dpy);
       SyncHandle();
       return ret;
@@ -842,17 +850,17 @@
 	  int i;
 	
 	  for(i = 0; i < rep.num_attributes; i++) {
-             _XRead(dpy, (char*)(&Info), sz_xvAttributeInfo);
+             p_XRead(dpy, (char*)(&Info), sz_xvAttributeInfo);
 	      ret[i].flags = (int)Info.flags;	      
 	      ret[i].min_value = Info.min;	      
 	      ret[i].max_value = Info.max;	      
 	      ret[i].name = marker;
-	      _XRead(dpy, marker, Info.size);
+	      p_XRead(dpy, marker, Info.size);
 	      marker += Info.size;
 	      (*num)++;
 	  }
       } else
-	_XEatData(dpy, rep.length << 2);
+	p_XEatData(dpy, rep.length << 2);
   }
 
   UnlockDisplay(dpy);
@@ -882,7 +890,7 @@
 
   /* READ THE REPLY */
 
-  if (_XReply(dpy, (xReply *)&rep, 0, xFalse) == 0) {
+  if (p_XReply(dpy, (xReply *)&rep, 0, xFalse) == 0) {
       UnlockDisplay(dpy);
       SyncHandle();
       return NULL;
@@ -896,7 +904,7 @@
 	  int i;
 	
 	  for(i = 0; i < rep.num_formats; i++) {
-              _XRead(dpy, (char*)(&Info), sz_xvImageFormatInfo);
+              p_XRead(dpy, (char*)(&Info), sz_xvImageFormatInfo);
 	      ret[i].id = Info.id;	      
 	      ret[i].type = Info.type;	      
 	      ret[i].byte_order = Info.byte_order;	      
@@ -922,7 +930,7 @@
 	      (*num)++;
 	  }
       } else
-	_XEatData(dpy, rep.length << 2);
+	p_XEatData(dpy, rep.length << 2);
   }
 
   UnlockDisplay(dpy);
@@ -956,7 +964,7 @@
 
    /* READ THE REPLY */
 
-   if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) {
+   if (!p_XReply(dpy, (xReply *)&rep, 0, xFalse)) {
        UnlockDisplay(dpy);
        SyncHandle();
       return NULL;
@@ -972,10 +980,10 @@
 	ret->offsets = ret->pitches + rep.num_planes;
 	ret->data = data;
 	ret->obdata = NULL;
-  	_XRead(dpy, (char*)(ret->pitches), rep.num_planes << 2);
-	_XRead(dpy, (char*)(ret->offsets), rep.num_planes << 2);
+  	p_XRead(dpy, (char*)(ret->pitches), rep.num_planes << 2);
+	p_XRead(dpy, (char*)(ret->offsets), rep.num_planes << 2);
    } else
-	_XEatData(dpy, rep.length << 2);
+	p_XEatData(dpy, rep.length << 2);
 
    UnlockDisplay(dpy);
    SyncHandle();
@@ -1124,7 +1132,7 @@
     case XvVideoNotify:
       re->xvvideo.type = event->u.u.type & 0x7f;
       re->xvvideo.serial = 
-	_XSetLastRequestRead(dpy, (xGenericReply *)event);
+	p_XSetLastRequestRead(dpy, (xGenericReply *)event);
       re->xvvideo.send_event = ((event->u.u.type & 0x80) != 0);
       re->xvvideo.display = dpy;
       re->xvvideo.time = event->u.videoNotify.time;
@@ -1135,7 +1143,7 @@
     case XvPortNotify:
       re->xvport.type = event->u.u.type & 0x7f;
       re->xvport.serial = 
-	_XSetLastRequestRead(dpy, (xGenericReply *)event);
+	p_XSetLastRequestRead(dpy, (xGenericReply *)event);
       re->xvport.send_event = ((event->u.u.type & 0x80) != 0);
       re->xvport.display = dpy;
       re->xvport.time = event->u.portNotify.time;
--- a/src/video/Xext/Xv/Xvlibint.h	Sat Nov 05 17:41:11 2005 +0000
+++ b/src/video/Xext/Xv/Xvlibint.h	Sat Nov 05 19:53:37 2005 +0000
@@ -51,7 +51,7 @@
 #define XvGetReq(name, req) \
         WORD64ALIGN\
 	if ((dpy->bufptr + SIZEOF(xv##name##Req)) > dpy->bufmax)\
-		_XFlush(dpy);\
+		p_XFlush(dpy);\
 	req = (xv##name##Req *)(dpy->last_req = dpy->bufptr);\
 	req->reqType = info->codes->major_opcode;\
         req->xvReqType = xv_##name; \
@@ -63,7 +63,7 @@
 #define XvGetReq(name, req) \
         WORD64ALIGN\
 	if ((dpy->bufptr + SIZEOF(xv/**/name/**/Req)) > dpy->bufmax)\
-		_XFlush(dpy);\
+		p_XFlush(dpy);\
 	req = (xv/**/name/**/Req *)(dpy->last_req = dpy->bufptr);\
 	req->reqType = info->codes->major_opcode;\
 	req->xvReqType = xv_/**/name;\
--- a/src/video/Xext/Xxf86dga/XF86DGA.c	Sat Nov 05 17:41:11 2005 +0000
+++ b/src/video/Xext/Xxf86dga/XF86DGA.c	Sat Nov 05 19:53:37 2005 +0000
@@ -56,7 +56,6 @@
 #undef _SC_PAGESIZE
 #endif
 
-
 #define NEED_EVENTS
 #define NEED_REPLIES
 #include <X11/Xlibint.h>
@@ -65,6 +64,14 @@
 #include <X11/extensions/Xext.h>
 #include "extutil.h"
 
+#include "../../x11/SDL_x11dyn.h"
+
+/* Workaround code in headers... */
+#define _XFlush p_XFlush
+#define _XFlushGCCache p_XFlushGCCache
+#define _XReply p_XReply
+#define _XSend p_XSend
+
 extern XExtDisplayInfo* SDL_NAME(xdga_find_display)(Display*);
 extern char *SDL_NAME(xdga_extension_name);
 
@@ -112,7 +119,7 @@
     req->reqType = info->codes->major_opcode;
     req->dgaReqType = X_XF86DGAGetVideoLL;
     req->screen = screen;
-    if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) {
+    if (!p_XReply(dpy, (xReply *)&rep, 0, xFalse)) {
 	UnlockDisplay(dpy);
 	SyncHandle();
 	return False;
@@ -147,7 +154,7 @@
     req->enable = enable;
     UnlockDisplay(dpy);
     SyncHandle();
-    XSync(dpy,False);
+    pXSync(dpy,False);
     return True;
 }
 
@@ -168,7 +175,7 @@
     req->reqType = info->codes->major_opcode;
     req->dgaReqType = X_XF86DGAGetViewPortSize;
     req->screen = screen;
-    if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) {
+    if (!p_XReply(dpy, (xReply *)&rep, 0, xFalse)) {
 	UnlockDisplay(dpy);
 	SyncHandle();
 	return False;
@@ -203,7 +210,7 @@
     req->y = y;
     UnlockDisplay(dpy);
     SyncHandle();
-    XSync(dpy,False);
+    pXSync(dpy,False);
     return True;
 }
 
@@ -224,7 +231,7 @@
     req->reqType = info->codes->major_opcode;
     req->dgaReqType = X_XF86DGAGetVidPage;
     req->screen = screen;
-    if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) {
+    if (!p_XReply(dpy, (xReply *)&rep, 0, xFalse)) {
 	UnlockDisplay(dpy);
 	SyncHandle();
 	return False;
@@ -255,7 +262,7 @@
     req->vpage = vpage;
     UnlockDisplay(dpy);
     SyncHandle();
-    XSync(dpy,False);
+    pXSync(dpy,False);
     return True;
 }
 
@@ -277,7 +284,7 @@
     req->id = cmap;
     UnlockDisplay(dpy);
     SyncHandle();
-    XSync(dpy,False);
+    pXSync(dpy,False);
     return True;
 }
 
@@ -297,7 +304,7 @@
     req->reqType = info->codes->major_opcode;
     req->dgaReqType = X_XF86DGAQueryDirectVideo;
     req->screen = screen;
-    if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) {
+    if (!p_XReply(dpy, (xReply *)&rep, 0, xFalse)) {
 	UnlockDisplay(dpy);
 	SyncHandle();
 	return False;
@@ -325,7 +332,7 @@
     req->dgaReqType = X_XF86DGAViewPortChanged;
     req->screen = screen;
     req->n = n;
-    if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) {
+    if (!p_XReply(dpy, (xReply *)&rep, 0, xFalse)) {
 	UnlockDisplay(dpy);
 	SyncHandle();
 	return False;
@@ -598,7 +605,7 @@
 	for (i = 0; i < numScrs; i++) {
 	    sp = scrList[i];
 	    SDL_NAME(XF86DGADirectVideoLL)(sp->display, sp->screen, 0);
-	    XSync(sp->display, False);
+	    pXSync(sp->display, False);
 	}
         if (WIFEXITED(status))
 	    _exit(0);
@@ -658,7 +665,7 @@
     for (i = 0; i < numScrs; i++) {
 	sp = scrList[i];
 	SDL_NAME(XF86DGADirectVideo)(sp->display, sp->screen, 0);
-	XSync(sp->display, False);
+	pXSync(sp->display, False);
     }
     _exit(3);
 }
--- a/src/video/Xext/Xxf86dga/XF86DGA2.c	Sat Nov 05 17:41:11 2005 +0000
+++ b/src/video/Xext/Xxf86dga/XF86DGA2.c	Sat Nov 05 19:53:37 2005 +0000
@@ -28,6 +28,14 @@
 #include <linux/fb.h>
 #endif
 
+#include "../../x11/SDL_x11dyn.h"
+
+/* Workaround code in headers... */
+#define _XFlush p_XFlush
+#define _XFlushGCCache p_XFlushGCCache
+#define _XReply p_XReply
+#define _XSend p_XSend
+
 /* If you change this, change the Bases[] array below as well */
 #define MAX_HEADS 16
 
@@ -104,7 +112,7 @@
   case MotionNotify:
 	mevent = (SDL_NAME(XDGAMotionEvent)*)event;
 	mevent->type = wire->u.u.type & 0x7F;
-	mevent->serial = _XSetLastRequestRead(dpy, (xGenericReply *)wire);
+	mevent->serial = p_XSetLastRequestRead(dpy, (xGenericReply *)wire);
 	mevent->display = dpy;
 	mevent->screen = wire->u.event.screen;
 	mevent->time = wire->u.event.time;
@@ -116,7 +124,7 @@
   case ButtonRelease:
 	bevent = (SDL_NAME(XDGAButtonEvent)*)event;
 	bevent->type = wire->u.u.type & 0x7F;
-	bevent->serial = _XSetLastRequestRead(dpy, (xGenericReply *)wire);
+	bevent->serial = p_XSetLastRequestRead(dpy, (xGenericReply *)wire);
 	bevent->display = dpy;
 	bevent->screen = wire->u.event.screen;
 	bevent->time = wire->u.event.time;
@@ -127,7 +135,7 @@
   case KeyRelease:
 	kevent = (SDL_NAME(XDGAKeyEvent)*)event;
 	kevent->type = wire->u.u.type & 0x7F;
-	kevent->serial = _XSetLastRequestRead(dpy, (xGenericReply *)wire);
+	kevent->serial = p_XSetLastRequestRead(dpy, (xGenericReply *)wire);
 	kevent->display = dpy;
 	kevent->screen = wire->u.event.screen;
 	kevent->time = wire->u.event.time;
@@ -172,7 +180,7 @@
     GetReq(XDGAQueryVersion, req);
     req->reqType = info->codes->major_opcode;
     req->dgaReqType = X_XDGAQueryVersion;
-    if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) {
+    if (!p_XReply(dpy, (xReply *)&rep, 0, xFalse)) {
 	UnlockDisplay(dpy);
 	SyncHandle();
 	return False;
@@ -189,8 +197,8 @@
 	     i < XF86DGANumberEvents;
 	     i++, j++) 
 	{
-	    XESetWireToEvent (dpy, j, xdga_wire_to_event);
-	    XESetEventToWire (dpy, j, xdga_event_to_wire);
+	    pXESetWireToEvent(dpy, j, xdga_wire_to_event);
+	    pXESetEventToWire(dpy, j, xdga_event_to_wire);
 	}
 	SDL_NAME(XDGASetClientVersion)(dpy);
     }
@@ -233,7 +241,7 @@
     req->reqType = info->codes->major_opcode;
     req->dgaReqType = X_XDGAOpenFramebuffer;
     req->screen = screen;
-    if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) {
+    if (!p_XReply(dpy, (xReply *)&rep, 0, xFalse)) {
 	UnlockDisplay(dpy);
 	SyncHandle();
 	return False;
@@ -241,7 +249,7 @@
 
     if(rep.length) {
 	deviceName = Xmalloc(rep.length << 2);
-	_XRead(dpy, deviceName, rep.length << 2);
+	p_XRead(dpy, deviceName, rep.length << 2);
     }
 
     ret = SDL_NAME(XDGAMapFramebuffer)(screen, deviceName,
@@ -298,7 +306,7 @@
     req->dgaReqType = X_XDGAQueryModes;
     req->screen = screen;
 
-    if (_XReply(dpy, (xReply *)&rep, 0, xFalse)) {
+    if (p_XReply(dpy, (xReply *)&rep, 0, xFalse)) {
 	if(rep.length) {
 	   xXDGAModeInfo info;
 	   int i, size;
@@ -312,7 +320,7 @@
 
 	   if(modes) {	
 	      for(i = 0; i < rep.number; i++) {
-		_XRead(dpy, (char*)(&info), sz_xXDGAModeInfo);
+		p_XRead(dpy, (char*)(&info), sz_xXDGAModeInfo);
 
 		modes[i].num = info.num;
 		modes[i].verticalRefresh = 
@@ -340,13 +348,13 @@
 		modes[i].reserved1 = info.reserved1;
 		modes[i].reserved2 = info.reserved2;	
 
-		_XRead(dpy, offset, info.name_size);
+		p_XRead(dpy, offset, info.name_size);
 		modes[i].name = offset;
 		offset += info.name_size;
 	      }
 	      *num = rep.number;
 	   } else
-		_XEatData(dpy, rep.length << 2);
+		p_XEatData(dpy, rep.length << 2);
 	}
     }
 
@@ -379,7 +387,7 @@
     req->mode = mode;
     req->pid = pid = XAllocID(dpy);
     
-    if (_XReply(dpy, (xReply *)&rep, 0, xFalse)) {
+    if (p_XReply(dpy, (xReply *)&rep, 0, xFalse)) {
 	if(rep.length) {
 	   xXDGAModeInfo info;
 	   int size;
@@ -390,7 +398,7 @@
 	   dev = (SDL_NAME(XDGADevice)*)Xmalloc(sizeof(SDL_NAME(XDGADevice)) + size);
 	    
 	   if(dev) {
-		_XRead(dpy, (char*)(&info), sz_xXDGAModeInfo);
+		p_XRead(dpy, (char*)(&info), sz_xXDGAModeInfo);
 
 		dev->mode.num = info.num;
 		dev->mode.verticalRefresh = 
@@ -419,7 +427,7 @@
 		dev->mode.reserved2 = info.reserved2;
 
 		dev->mode.name = (char*)(&dev[1]);	
-		_XRead(dpy, dev->mode.name, info.name_size);
+		p_XRead(dpy, dev->mode.name, info.name_size);
 
 		dev->pixmap = (rep.flags & XDGAPixmap) ? pid : 0;
 		dev->data = SDL_NAME(XDGAGetMappedMemory)(screen);
@@ -610,7 +618,7 @@
     req->reqType = info->codes->major_opcode;
     req->dgaReqType = X_XDGAGetViewportStatus;
     req->screen = screen;
-    if (!_XReply(dpy, (xReply *)&rep, 0, xFalse))
+    if (!p_XReply(dpy, (xReply *)&rep, 0, xFalse))
 	status = rep.status;
     UnlockDisplay(dpy);
     SyncHandle();
@@ -632,7 +640,7 @@
     req->reqType = info->codes->major_opcode;
     req->dgaReqType = X_XDGASync;
     req->screen = screen;
-    _XReply(dpy, (xReply *)&rep, 0, xFalse);
+    p_XReply(dpy, (xReply *)&rep, 0, xFalse);
     UnlockDisplay(dpy);
     SyncHandle();
 }
@@ -659,7 +667,7 @@
     req->x = *x;
     req->y = *y;
     req->flags = mode;
-    _XReply(dpy, (xReply *)&rep, 0, xFalse);
+    p_XReply(dpy, (xReply *)&rep, 0, xFalse);
     *x = rep.x;
     *y = rep.y;
     UnlockDisplay(dpy);
--- a/src/video/Xext/Xxf86vm/XF86VMode.c	Sat Nov 05 17:41:11 2005 +0000
+++ b/src/video/Xext/Xxf86vm/XF86VMode.c	Sat Nov 05 19:53:37 2005 +0000
@@ -47,6 +47,14 @@
 #include "include/extensions/extutil.h"
 #endif
 
+#include "../../x11/SDL_x11dyn.h"
+
+/* Workaround code in headers... */
+#define _XFlush p_XFlush
+#define _XFlushGCCache p_XFlushGCCache
+#define _XReply p_XReply
+#define _XSend p_XSend
+
 #ifdef DEBUG
 #include <stdio.h>
 #endif
@@ -129,7 +137,7 @@
     GetReq(XF86VidModeQueryVersion, req);
     req->reqType = info->codes->major_opcode;
     req->xf86vidmodeReqType = X_XF86VidModeQueryVersion;
-    if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) {
+    if (!p_XReply(dpy, (xReply *)&rep, 0, xFalse)) {
 	UnlockDisplay(dpy);
 	SyncHandle();
 	return False;
@@ -197,7 +205,7 @@
     req->reqType = info->codes->major_opcode;
     req->xf86vidmodeReqType = X_XF86VidModeGetGamma;
     req->screen = screen;
-    if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) {
+    if (!p_XReply(dpy, (xReply *)&rep, 0, xFalse)) {
 	UnlockDisplay(dpy);
 	SyncHandle();
 	return False;
@@ -233,7 +241,7 @@
     req->screen = screen;
     
     if (majorVersion < 2) {
-	if (!_XReply(dpy, (xReply *)&oldrep, 
+	if (!p_XReply(dpy, (xReply *)&oldrep, 
             (SIZEOF(xXF86OldVidModeGetModeLineReply) - SIZEOF(xReply)) >> 2, xFalse)) {
 	    UnlockDisplay(dpy);
 	    SyncHandle();
@@ -252,7 +260,7 @@
 	modeline->flags      = oldrep.flags;
 	modeline->privsize   = oldrep.privsize;
     } else {
-	if (!_XReply(dpy, (xReply *)&rep, 
+	if (!p_XReply(dpy, (xReply *)&rep, 
             (SIZEOF(xXF86VidModeGetModeLineReply) - SIZEOF(xReply)) >> 2, xFalse)) {
 	    UnlockDisplay(dpy);
 	    SyncHandle();
@@ -274,11 +282,11 @@
     
     if (modeline->privsize > 0) {
 	if (!(modeline->private = Xcalloc(modeline->privsize, sizeof(INT32)))) {
-	    _XEatData(dpy, (modeline->privsize) * sizeof(INT32));
+	    p_XEatData(dpy, (modeline->privsize) * sizeof(INT32));
 	    Xfree(modeline->private);
 	    return False;
 	}
-	_XRead(dpy, (char*)modeline->private, modeline->privsize * sizeof(INT32));
+	p_XRead(dpy, (char*)modeline->private, modeline->privsize * sizeof(INT32));
     } else {
 	modeline->private = NULL;
     }
@@ -327,7 +335,7 @@
     req->reqType = info->codes->major_opcode;
     req->xf86vidmodeReqType = X_XF86VidModeGetAllModeLines;
     req->screen = screen;
-    if (!_XReply(dpy, (xReply *)&rep, 
+    if (!p_XReply(dpy, (xReply *)&rep, 
         (SIZEOF(xXF86VidModeGetAllModeLinesReply) - SIZEOF(xReply)) >> 2, xFalse)) {
         UnlockDisplay(dpy);
 	SyncHandle();
@@ -340,9 +348,9 @@
                                           sizeof(SDL_NAME(XF86VidModeModeInfo) *)
                                           +sizeof(SDL_NAME(XF86VidModeModeInfo))))) {
 	if (majorVersion < 2)
-            _XEatData(dpy, (rep.modecount) * sizeof(xXF86OldVidModeModeInfo));
+            p_XEatData(dpy, (rep.modecount) * sizeof(xXF86OldVidModeModeInfo));
 	else
-            _XEatData(dpy, (rep.modecount) * sizeof(xXF86VidModeModeInfo));
+            p_XEatData(dpy, (rep.modecount) * sizeof(xXF86VidModeModeInfo));
         Xfree(modelines);
         UnlockDisplay(dpy);
         SyncHandle();
@@ -356,7 +364,7 @@
     for (i = 0; i < rep.modecount; i++) {
         modelines[i] = mdinfptr++;
 	if (majorVersion < 2) {
-            _XRead(dpy, (char*)&oldxmdline, sizeof(xXF86OldVidModeModeInfo));
+            p_XRead(dpy, (char*)&oldxmdline, sizeof(xXF86OldVidModeModeInfo));
 	    modelines[i]->dotclock   = oldxmdline.dotclock;
 	    modelines[i]->hdisplay   = oldxmdline.hdisplay;
 	    modelines[i]->hsyncstart = oldxmdline.hsyncstart;
@@ -376,10 +384,10 @@
 		if (oldxmdline.privsize > 0) {
 	            if (!(modelines[i]->private =
 			    Xcalloc(oldxmdline.privsize, sizeof(INT32)))) {
-			_XEatData(dpy, (oldxmdline.privsize) * sizeof(INT32));
+			p_XEatData(dpy, (oldxmdline.privsize) * sizeof(INT32));
 			Xfree(modelines[i]->private);
 		    } else {
-			_XRead(dpy, (char*)modelines[i]->private,
+			p_XRead(dpy, (char*)modelines[i]->private,
 			     oldxmdline.privsize * sizeof(INT32));
 		    }
 		} else {
@@ -387,7 +395,7 @@
 		}
 	    }
 	} else {
-            _XRead(dpy, (char*)&xmdline, sizeof(xXF86VidModeModeInfo));
+            p_XRead(dpy, (char*)&xmdline, sizeof(xXF86VidModeModeInfo));
 	    modelines[i]->dotclock   = xmdline.dotclock;
 	    modelines[i]->hdisplay   = xmdline.hdisplay;
 	    modelines[i]->hsyncstart = xmdline.hsyncstart;
@@ -407,10 +415,10 @@
 		if (xmdline.privsize > 0) {
 		    if (!(modelines[i]->private =
 			    Xcalloc(xmdline.privsize, sizeof(INT32)))) {
-			_XEatData(dpy, (xmdline.privsize) * sizeof(INT32));
+			p_XEatData(dpy, (xmdline.privsize) * sizeof(INT32));
 			Xfree(modelines[i]->private);
 		    } else {
-			_XRead(dpy, (char*)modelines[i]->private,
+			p_XRead(dpy, (char*)modelines[i]->private,
 			     xmdline.privsize * sizeof(INT32));
 		    }
 		} else {
@@ -432,7 +440,7 @@
 #define GetOldReq(name, oldname, req) \
         WORD64ALIGN\
 	if ((dpy->bufptr + SIZEOF(x##oldname##Req)) > dpy->bufmax)\
-		_XFlush(dpy);\
+		p_XFlush(dpy);\
 	req = (x##oldname##Req *)(dpy->last_req = dpy->bufptr);\
 	req->reqType = X_##name;\
 	req->length = (SIZEOF(x##oldname##Req))>>2;\
@@ -443,7 +451,7 @@
 #define GetOldReq(name, oldname, req) \
         WORD64ALIGN\
 	if ((dpy->bufptr + SIZEOF(x/**/oldname/**/Req)) > dpy->bufmax)\
-		_XFlush(dpy);\
+		p_XFlush(dpy);\
 	req = (x/**/oldname/**/Req *)(dpy->last_req = dpy->bufptr);\
 	req->reqType = X_/**/name;\
 	req->length = (SIZEOF(x/**/oldname/**/Req))>>2;\
@@ -751,7 +759,7 @@
 	       modeline->privsize * sizeof(INT32));
 	}
     }
-    if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) {
+    if (!p_XReply(dpy, (xReply *)&rep, 0, xFalse)) {
 	UnlockDisplay(dpy);
 	SyncHandle();
 	return MODE_BAD;
@@ -913,7 +921,7 @@
     req->reqType = info->codes->major_opcode;
     req->xf86vidmodeReqType = X_XF86VidModeGetMonitor;
     req->screen = screen;
-    if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) {
+    if (!p_XReply(dpy, (xReply *)&rep, 0, xFalse)) {
 	UnlockDisplay(dpy);
 	SyncHandle();
 	return False;
@@ -925,7 +933,7 @@
 #endif
     if (rep.vendorLength) {
 	if (!(monitor->vendor = (char *)Xcalloc(rep.vendorLength + 1, 1))) {
-	    _XEatData(dpy, (rep.nhsync + rep.nvsync) * 4 +
+	    p_XEatData(dpy, (rep.nhsync + rep.nvsync) * 4 +
 		      ((rep.vendorLength+3) & ~3) + ((rep.modelLength+3) & ~3));
             UnlockDisplay(dpy);
             SyncHandle();
@@ -936,7 +944,7 @@
     }
     if (rep.modelLength) {
 	if (!(monitor->model = Xcalloc(rep.modelLength + 1, 1))) {
-	    _XEatData(dpy, (rep.nhsync + rep.nvsync) * 4 +
+	    p_XEatData(dpy, (rep.nhsync + rep.nvsync) * 4 +
 		      ((rep.vendorLength+3) & ~3) + ((rep.modelLength+3) & ~3));
 	    if (monitor->vendor)
 		Xfree(monitor->vendor);
@@ -948,7 +956,7 @@
 	monitor->model = NULL;
     }
     if (!(monitor->hsync = Xcalloc(rep.nhsync, sizeof(SDL_NAME(XF86VidModeSyncRange))))) {
-	_XEatData(dpy, (rep.nhsync + rep.nvsync) * 4 +
+	p_XEatData(dpy, (rep.nhsync + rep.nvsync) * 4 +
 		  ((rep.vendorLength+3) & ~3) + ((rep.modelLength+3) & ~3));
 	
 	if (monitor->vendor)
@@ -960,7 +968,7 @@
 	return False;
     }
     if (!(monitor->vsync = Xcalloc(rep.nvsync, sizeof(SDL_NAME(XF86VidModeSyncRange))))) {
-	_XEatData(dpy, (rep.nhsync + rep.nvsync) * 4 +
+	p_XEatData(dpy, (rep.nhsync + rep.nvsync) * 4 +
 		  ((rep.vendorLength+3) & ~3) + ((rep.modelLength+3) & ~3));
 	if (monitor->vendor)
 	    Xfree(monitor->vendor);
@@ -972,21 +980,21 @@
 	return False;
     }
     for (i = 0; i < rep.nhsync; i++) {
-	_XRead(dpy, (char *)&syncrange, 4);
+	p_XRead(dpy, (char *)&syncrange, 4);
 	monitor->hsync[i].lo = (float)(syncrange & 0xFFFF) / 100.0;
 	monitor->hsync[i].hi = (float)(syncrange >> 16) / 100.0;
     }
     for (i = 0; i < rep.nvsync; i++) {
-	_XRead(dpy, (char *)&syncrange, 4);
+	p_XRead(dpy, (char *)&syncrange, 4);
 	monitor->vsync[i].lo = (float)(syncrange & 0xFFFF) / 100.0;
 	monitor->vsync[i].hi = (float)(syncrange >> 16) / 100.0;
     }
     if (rep.vendorLength)
-	_XReadPad(dpy, monitor->vendor, rep.vendorLength);
+	p_XReadPad(dpy, monitor->vendor, rep.vendorLength);
     else
 	monitor->vendor = "";
     if (rep.modelLength)
-	_XReadPad(dpy, monitor->model, rep.modelLength);
+	p_XReadPad(dpy, monitor->model, rep.modelLength);
     else
 	monitor->model = "";
 	
@@ -1034,7 +1042,7 @@
 	*x = 0;
 	*y = 0;
     } else {
-	if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) {
+	if (!p_XReply(dpy, (xReply *)&rep, 0, xFalse)) {
 	    UnlockDisplay(dpy);
 	    SyncHandle();
 	    return False;
@@ -1092,7 +1100,7 @@
     req->reqType = info->codes->major_opcode;
     req->xf86vidmodeReqType = X_XF86VidModeGetDotClocks;
     req->screen = screen;
-    if (!_XReply(dpy, (xReply *)&rep, 
+    if (!p_XReply(dpy, (xReply *)&rep, 
         (SIZEOF(xXF86VidModeGetDotClocksReply) - SIZEOF(xReply)) >> 2, xFalse))
     {
         UnlockDisplay(dpy);
@@ -1104,7 +1112,7 @@
     *flagsPtr     = rep.flags;
 
     if (!(dotclocks = (int*) Xcalloc(rep.clocks, sizeof(int)))) {
-        _XEatData(dpy, (rep.clocks) * 4);
+        p_XEatData(dpy, (rep.clocks) * 4);
         Xfree(dotclocks);
         UnlockDisplay(dpy);
         SyncHandle();
@@ -1112,7 +1120,7 @@
     }
 
     for (i = 0; i < rep.clocks; i++) {
-        _XRead(dpy, (char*)&dotclk, 4);
+        p_XRead(dpy, (char*)&dotclk, 4);
 	dotclocks[i] = dotclk;
     }
     *clocksPtr = dotclocks;
@@ -1143,9 +1151,9 @@
     req->screen = screen;
     req->length += (length >> 1) * 3;
     req->size = size;
-    _XSend(dpy, (char*)red, size * 2);
-    _XSend(dpy, (char*)green, size * 2);
-    _XSend(dpy, (char*)blue, size * 2);
+    p_XSend(dpy, (char*)red, size * 2);
+    p_XSend(dpy, (char*)green, size * 2);
+    p_XSend(dpy, (char*)blue, size * 2);
     UnlockDisplay(dpy);
     SyncHandle();
     return True;
@@ -1174,15 +1182,15 @@
     req->xf86vidmodeReqType = X_XF86VidModeGetGammaRamp;
     req->screen = screen;
     req->size = size;
-    if (!_XReply (dpy, (xReply *) &rep, 0, xFalse)) {
+    if (!p_XReply (dpy, (xReply *) &rep, 0, xFalse)) {
         UnlockDisplay (dpy);
         SyncHandle ();
         return False;
     }
     if(rep.size) {
-	_XRead(dpy, (char*)red, rep.size << 1);
-	_XRead(dpy, (char*)green, rep.size << 1);
-	_XRead(dpy, (char*)blue, rep.size << 1);
+	p_XRead(dpy, (char*)red, rep.size << 1);
+	p_XRead(dpy, (char*)green, rep.size << 1);
+	p_XRead(dpy, (char*)blue, rep.size << 1);
     }
 
     UnlockDisplay(dpy);
@@ -1209,7 +1217,7 @@
     req->reqType = info->codes->major_opcode;
     req->xf86vidmodeReqType = X_XF86VidModeGetGammaRampSize;
     req->screen = screen;
-    if (!_XReply (dpy, (xReply *) &rep, 0, xTrue)) {
+    if (!p_XReply (dpy, (xReply *) &rep, 0, xTrue)) {
         UnlockDisplay (dpy);
         SyncHandle ();
         return False; 
--- a/src/video/Xext/extensions/extutil.h	Sat Nov 05 17:41:11 2005 +0000
+++ b/src/video/Xext/extensions/extutil.h	Sat Nov 05 19:53:37 2005 +0000
@@ -173,9 +173,9 @@
 
 #define XextHasExtension(i) ((i) && ((i)->codes))
 #define XextCheckExtension(dpy,i,name,val) \
-  if (!XextHasExtension(i)) { XMissingExtension (dpy, name); return val; }
+  if (!XextHasExtension(i)) { pXMissingExtension (dpy, name); return val; }
 #define XextSimpleCheckExtension(dpy,i,name) \
-  if (!XextHasExtension(i)) { XMissingExtension (dpy, name); return; }
+  if (!XextHasExtension(i)) { pXMissingExtension (dpy, name); return; }
 
 
 /*
@@ -188,9 +188,9 @@
 XExtDisplayInfo *proc (Display *dpy) \
 { \
     XExtDisplayInfo *dpyinfo; \
-    if (!extinfo) { if (!(extinfo = XextCreateExtension())) return NULL; } \
-    if (!(dpyinfo = XextFindDisplay (extinfo, dpy))) \
-      dpyinfo = XextAddDisplay (extinfo,dpy,extname,hooks,nev,data); \
+    if (!extinfo) { if (!(extinfo = pXextCreateExtension())) return NULL; } \
+    if (!(dpyinfo = pXextFindDisplay (extinfo, dpy))) \
+      dpyinfo = pXextAddDisplay (extinfo,dpy,extname,hooks,nev,data); \
     return dpyinfo; \
 }
 
@@ -200,7 +200,7 @@
 #define XEXT_GENERATE_CLOSE_DISPLAY(proc,extinfo) \
 int proc (Display *dpy, XExtCodes *codes) \
 { \
-    return XextRemoveDisplay (extinfo, dpy); \
+    return pXextRemoveDisplay (extinfo, dpy); \
 }
 
 #define XEXT_CLOSE_DISPLAY_PROTO(proc) \
@@ -213,7 +213,7 @@
     if (code >= 0 && code < nerr) { \
 	char tmp[256]; \
 	sprintf (tmp, "%s.%d", extname, code); \
-	XGetErrorDatabaseText (dpy, "XProtoError", tmp, errl[code], buf, n); \
+	pXGetErrorDatabaseText (dpy, "XProtoError", tmp, errl[code], buf, n); \
 	return buf; \
     } \
     return (char *)0; \
--- a/src/video/dga/SDL_dgaevents.c	Sat Nov 05 17:41:11 2005 +0000
+++ b/src/video/dga/SDL_dgaevents.c	Sat Nov 05 19:53:37 2005 +0000
@@ -47,7 +47,7 @@
 	int posted;
 	SDL_NAME(XDGAEvent) xevent;
 
-	XNextEvent(DGA_Display, (XEvent *)&xevent);
+	pXNextEvent(DGA_Display, (XEvent *)&xevent);
 
 	posted = 0;
 	xevent.type -= DGA_event_base;
--- a/src/video/dga/SDL_dgavideo.c	Sat Nov 05 17:41:11 2005 +0000
+++ b/src/video/dga/SDL_dgavideo.c	Sat Nov 05 19:53:37 2005 +0000
@@ -48,6 +48,9 @@
 #include "SDL_dgamouse_c.h"
 #include "SDL_dgaevents_c.h"
 
+/* get function pointers... */
+#include "../x11/SDL_x11dyn.h"
+
 /* Initialization/Query functions */
 static int DGA_VideoInit(_THIS, SDL_PixelFormat *vformat);
 static SDL_Rect **DGA_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags);
@@ -72,91 +75,98 @@
 
 static int DGA_Available(void)
 {
-	const char *display;
-	Display *dpy;
-	int available;
+	const char *display = NULL;
+	Display *dpy = NULL;
+	int available = 0;
 
 	/* The driver is available is available if the display is local
 	   and the DGA 2.0+ extension is available, and we can map mem.
 	*/
-	available = 0;
-	display = NULL;
-	if ( (strncmp(XDisplayName(display), ":", 1) == 0) ||
-	     (strncmp(XDisplayName(display), "unix:", 5) == 0) ) {
-		dpy = XOpenDisplay(display);
-		if ( dpy ) {
-			int events, errors, major, minor;
+	if ( SDL_X11_LoadSymbols() ) {
+		if ( (strncmp(pXDisplayName(display), ":", 1) == 0) ||
+		     (strncmp(pXDisplayName(display), "unix:", 5) == 0) ) {
+			dpy = pXOpenDisplay(display);
+			if ( dpy ) {
+				int events, errors, major, minor;
+
+				if ( SDL_NAME(XDGAQueryExtension)(dpy, &events, &errors) &&
+				     SDL_NAME(XDGAQueryVersion)(dpy, &major, &minor) ) {
+					int screen;
 
-			if ( SDL_NAME(XDGAQueryExtension)(dpy, &events, &errors) &&
-			     SDL_NAME(XDGAQueryVersion)(dpy, &major, &minor) ) {
-				int screen;
-
-				screen = DefaultScreen(dpy);
-				if ( (major >= 2) && 
-				     SDL_NAME(XDGAOpenFramebuffer)(dpy, screen) ) {
-					available = 1;
-					SDL_NAME(XDGACloseFramebuffer)(dpy, screen);
+					screen = DefaultScreen(dpy);
+					if ( (major >= 2) && 
+					     SDL_NAME(XDGAOpenFramebuffer)(dpy, screen) ) {
+						available = 1;
+						SDL_NAME(XDGACloseFramebuffer)(dpy, screen);
+					}
 				}
+				pXCloseDisplay(dpy);
 			}
-			XCloseDisplay(dpy);
 		}
+		SDL_X11_UnloadSymbols();
 	}
 	return(available);
 }
 
 static void DGA_DeleteDevice(SDL_VideoDevice *device)
 {
-	free(device->hidden);
-	free(device);
+	if (device != NULL) {
+		free(device->hidden);
+		free(device);
+		SDL_X11_UnloadSymbols();
+	}
 }
 
 static SDL_VideoDevice *DGA_CreateDevice(int devindex)
 {
-	SDL_VideoDevice *device;
+	SDL_VideoDevice *device = NULL;
 
 	/* Initialize all variables that we clean on shutdown */
-	device = (SDL_VideoDevice *)malloc(sizeof(SDL_VideoDevice));
-	if ( device ) {
-		memset(device, 0, (sizeof *device));
-		device->hidden = (struct SDL_PrivateVideoData *)
-				malloc((sizeof *device->hidden));
-	}
-	if ( (device == NULL) || (device->hidden == NULL) ) {
-		SDL_OutOfMemory();
+	if (SDL_X11_LoadSymbols()) {
+		device = (SDL_VideoDevice *)malloc(sizeof(SDL_VideoDevice));
 		if ( device ) {
-			free(device);
+			memset(device, 0, (sizeof *device));
+			device->hidden = (struct SDL_PrivateVideoData *)
+					malloc((sizeof *device->hidden));
 		}
-		return(0);
-	}
-	memset(device->hidden, 0, (sizeof *device->hidden));
+		if ( (device == NULL) || (device->hidden == NULL) ) {
+			SDL_OutOfMemory();
+			if ( device ) {
+				free(device);
+			}
+			SDL_X11_UnloadSymbols();
+			return(0);
+		}
+		memset(device->hidden, 0, (sizeof *device->hidden));
 
-	/* Set the function pointers */
-	device->VideoInit = DGA_VideoInit;
-	device->ListModes = DGA_ListModes;
-	device->SetVideoMode = DGA_SetVideoMode;
-	device->SetColors = DGA_SetColors;
-	device->UpdateRects = NULL;
-	device->VideoQuit = DGA_VideoQuit;
-	device->AllocHWSurface = DGA_AllocHWSurface;
-	device->CheckHWBlit = DGA_CheckHWBlit;
-	device->FillHWRect = DGA_FillHWRect;
-	device->SetHWColorKey = NULL;
-	device->SetHWAlpha = NULL;
-	device->LockHWSurface = DGA_LockHWSurface;
-	device->UnlockHWSurface = DGA_UnlockHWSurface;
-	device->FlipHWSurface = DGA_FlipHWSurface;
-	device->FreeHWSurface = DGA_FreeHWSurface;
-	device->SetGammaRamp = DGA_SetGammaRamp;
-	device->GetGammaRamp = NULL;
-	device->SetCaption = NULL;
-	device->SetIcon = NULL;
-	device->IconifyWindow = NULL;
-	device->GrabInput = NULL;
-	device->GetWMInfo = NULL;
-	device->InitOSKeymap = DGA_InitOSKeymap;
-	device->PumpEvents = DGA_PumpEvents;
+		/* Set the function pointers */
+		device->VideoInit = DGA_VideoInit;
+		device->ListModes = DGA_ListModes;
+		device->SetVideoMode = DGA_SetVideoMode;
+		device->SetColors = DGA_SetColors;
+		device->UpdateRects = NULL;
+		device->VideoQuit = DGA_VideoQuit;
+		device->AllocHWSurface = DGA_AllocHWSurface;
+		device->CheckHWBlit = DGA_CheckHWBlit;
+		device->FillHWRect = DGA_FillHWRect;
+		device->SetHWColorKey = NULL;
+		device->SetHWAlpha = NULL;
+		device->LockHWSurface = DGA_LockHWSurface;
+		device->UnlockHWSurface = DGA_UnlockHWSurface;
+		device->FlipHWSurface = DGA_FlipHWSurface;
+		device->FreeHWSurface = DGA_FreeHWSurface;
+		device->SetGammaRamp = DGA_SetGammaRamp;
+		device->GetGammaRamp = NULL;
+		device->SetCaption = NULL;
+		device->SetIcon = NULL;
+		device->IconifyWindow = NULL;
+		device->GrabInput = NULL;
+		device->GetWMInfo = NULL;
+		device->InitOSKeymap = DGA_InitOSKeymap;
+		device->PumpEvents = DGA_PumpEvents;
 
-	device->free = DGA_DeleteDevice;
+		device->free = DGA_DeleteDevice;
+	}
 
 	return device;
 }
@@ -329,7 +339,7 @@
 	/* Open the X11 display */
 	display = NULL;		/* Get it from DISPLAY environment variable */
 
-	DGA_Display = XOpenDisplay(display);
+	DGA_Display = pXOpenDisplay(display);
 	if ( DGA_Display == NULL ) {
 		SDL_SetError("Couldn't open X11 display");
 		return(-1);
@@ -339,12 +349,12 @@
 	if ( ! SDL_NAME(XDGAQueryExtension)(DGA_Display, &event_base, &error_base) ||
 	     ! SDL_NAME(XDGAQueryVersion)(DGA_Display, &major_version, &minor_version) ) {
 		SDL_SetError("DGA extension not available");
-		XCloseDisplay(DGA_Display);
+		pXCloseDisplay(DGA_Display);
 		return(-1);
 	}
 	if ( major_version < 2 ) {
 		SDL_SetError("DGA driver requires DGA 2.0 or newer");
-		XCloseDisplay(DGA_Display);
+		pXCloseDisplay(DGA_Display);
 		return(-1);
 	}
 	DGA_event_base = event_base;
@@ -356,10 +366,10 @@
 		int i, num_formats;
 
 		vformat->BitsPerPixel = DefaultDepth(DGA_Display, DGA_Screen);
-		pix_format = XListPixmapFormats(DGA_Display, &num_formats);
+		pix_format = pXListPixmapFormats(DGA_Display, &num_formats);
 		if ( pix_format == NULL ) {
 			SDL_SetError("Couldn't determine screen formats");
-			XCloseDisplay(DGA_Display);
+			pXCloseDisplay(DGA_Display);
 			return(-1);
 		}
 		for ( i=0; i<num_formats; ++i ) {
@@ -368,7 +378,7 @@
 		}
 		if ( i != num_formats )
 			vformat->BitsPerPixel = pix_format[i].bits_per_pixel;
-		XFree((char *)pix_format);
+		pXFree((char *)pix_format);
 	}
 	if ( vformat->BitsPerPixel > 8 ) {
 		vformat->Rmask = visual->red_mask;
@@ -379,7 +389,7 @@
 	/* Open access to the framebuffer */
 	if ( ! SDL_NAME(XDGAOpenFramebuffer)(DGA_Display, DGA_Screen) ) {
 		SDL_SetError("Unable to map the video memory");
-		XCloseDisplay(DGA_Display);
+		pXCloseDisplay(DGA_Display);
 		return(-1);
 	}
 
@@ -399,7 +409,7 @@
 		}
 	}
 	UpdateHWInfo(this, modes);
-	XFree(modes);
+	pXFree(modes);
 
 	/* Create the hardware surface lock mutex */
 	hw_lock = SDL_CreateMutex();
@@ -438,7 +448,7 @@
 
 	/* Free any previous colormap */
 	if ( DGA_colormap ) {
-		XFreeColormap(DGA_Display, DGA_colormap);
+		pXFreeColormap(DGA_Display, DGA_colormap);
 		DGA_colormap = 0;
 	}
 
@@ -469,7 +479,7 @@
 
 	/* Set the video mode */
 	mode = SDL_NAME(XDGASetMode)(DGA_Display, DGA_Screen, modes[i].num);
-	XFree(modes);
+	pXFree(modes);
 	if ( mode == NULL ) {
 		SDL_SetError("Unable to switch to requested mode");
 		return(NULL);
@@ -817,7 +827,7 @@
 #endif
 	SDL_NAME(XDGAFillRectangle)(DGA_Display, DGA_Screen, x, y, w, h, color);
 	if ( !(this->screen->flags & SDL_DOUBLEBUF) ) {
-		XFlush(DGA_Display);
+		pXFlush(DGA_Display);
 	}
 	DGA_AddBusySurface(dst);
 	UNLOCK_DISPLAY();
@@ -859,7 +869,7 @@
 			srcx, srcy, w, h, dstx, dsty);
 	}
 	if ( !(this->screen->flags & SDL_DOUBLEBUF) ) {
-		XFlush(DGA_Display);
+		pXFlush(DGA_Display);
 	}
 	DGA_AddBusySurface(src);
 	DGA_AddBusySurface(dst);
@@ -939,7 +949,7 @@
 	DGA_WaitFlip(this);
 	SDL_NAME(XDGASetViewport)(DGA_Display, DGA_Screen,
 	                0, flip_yoffset[flip_page], XDGAFlipRetrace);
-	XFlush(DGA_Display);
+	pXFlush(DGA_Display);
 	UNLOCK_DISPLAY();
 	was_flipped = 1;
 	flip_page = !flip_page;
@@ -972,8 +982,8 @@
 		xcmap[i].flags = (DoRed|DoGreen|DoBlue);
 	}
 	LOCK_DISPLAY();
-	XStoreColors(DGA_Display, DGA_colormap, xcmap, ncolors);
-	XSync(DGA_Display, False);
+	pXStoreColors(DGA_Display, DGA_colormap, xcmap, ncolors);
+	pXSync(DGA_Display, False);
 	UNLOCK_DISPLAY();
 
 	/* That was easy. :) */
@@ -1006,8 +1016,8 @@
 		xcmap[i].flags = (DoRed|DoGreen|DoBlue);
 	}
 	LOCK_DISPLAY();
-	XStoreColors(DGA_Display, DGA_colormap, xcmap, ncolors);
-	XSync(DGA_Display, False);
+	pXStoreColors(DGA_Display, DGA_colormap, xcmap, ncolors);
+	pXSync(DGA_Display, False);
 	UNLOCK_DISPLAY();
 	return(0);
 }
@@ -1019,7 +1029,7 @@
 	if ( DGA_Display ) {
 		/* Free colormap, if necessary */
 		if ( DGA_colormap ) {
-			XFreeColormap(DGA_Display, DGA_colormap);
+			pXFreeColormap(DGA_Display, DGA_colormap);
 			DGA_colormap = 0;
 		}
 
@@ -1059,6 +1069,6 @@
 		DGA_FreeHWSurfaces(this);
 
 		/* Close up the display */
-		XCloseDisplay(DGA_Display);
+		pXCloseDisplay(DGA_Display);
 	}
 }
--- a/src/video/x11/Makefile.am	Sat Nov 05 17:41:11 2005 +0000
+++ b/src/video/x11/Makefile.am	Sat Nov 05 19:53:37 2005 +0000
@@ -4,6 +4,9 @@
 noinst_LTLIBRARIES = libvideo_x11.la
 libvideo_x11_la_SOURCES = $(X11_SRCS)
 
+x11_lib = \"@x11_lib@\"
+x11ext_lib = \"@x11ext_lib@\"
+
 # The SDL X11 video driver sources
 X11_SRCS = 			\
 	SDL_x11dga.c		\
@@ -25,4 +28,8 @@
 	SDL_x11wm.c		\
 	SDL_x11wm_c.h		\
 	SDL_x11yuv.c		\
-	SDL_x11yuv_c.h
+	SDL_x11yuv_c.h		\
+	SDL_x11dyn.c		\
+	SDL_x11dyn.h		\
+	SDL_x11sym.h
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/video/x11/SDL_x11dyn.c	Sat Nov 05 19:53:37 2005 +0000
@@ -0,0 +1,127 @@
+/*
+    SDL - Simple DirectMedia Layer
+    Copyright (C) 1997-2004 Sam Lantinga
+
+    This library is free software; you can redistribute it and/or
+    modify it under the terms of the GNU Library General Public
+    License as published by the Free Software Foundation; either
+    version 2 of the License, or (at your option) any later version.
+
+    This library is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+    Library General Public License for more details.
+
+    You should have received a copy of the GNU Library General Public
+    License along with this library; if not, write to the Free
+    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+
+    Sam Lantinga
+    slouken@libsdl.org
+*/
+
+/*#define DEBUG_DYNAMIC_X11 1*/
+
+#include "SDL_x11dyn.h"
+
+#ifdef DEBUG_DYNAMIC_X11
+#include <stdio.h>
+#endif
+
+#ifdef X11_DYNAMIC
+#include <dlfcn.h>
+#include "SDL_name.h"
+#include "SDL_loadso.h"
+static const char *x11_library = X11_DYNAMIC;
+static void *x11_handle = NULL;
+static const char *x11ext_library = X11EXT_DYNAMIC;
+static void *x11ext_handle = NULL;
+
+static void *X11_GetSym(const char *fnname, int *rc)
+{
+	void *fn = NULL;
+	if (*rc) {  /* haven't already failed on a previous lookup? */
+		fn = SDL_LoadFunction(x11_handle, fnname);
+		#if DEBUG_DYNAMIC_X11
+		if (fn != NULL)
+			printf("X11: Found '%s' in libX11 (%p)\n", fnname, fn);
+		#endif
+
+		if (fn == NULL) {  /* not found? Check libX11ext ... */
+			fn = SDL_LoadFunction(x11ext_handle, fnname);
+			#if DEBUG_DYNAMIC_X11
+			if (fn != NULL)
+				printf("X11: Found '%s' in libXext (%p)\n", fnname, fn);
+			else
+				printf("X11: Symbol '%s' NOT FOUND!\n", fnname);
+			#endif
+		}
+		*rc = (fn != NULL);
+	}
+
+	return fn;
+}
+#endif  /* defined X11_DYNAMIC */
+
+/* Define all the function pointers... */
+#define SDL_X11_SYM(ret,fn,params) ret (*p##fn) params = NULL;
+#include "SDL_x11sym.h"
+#undef SDL_X11_SYM
+
+static int x11_load_refcount = 0;
+
+void SDL_X11_UnloadSymbols(void)
+{
+	/* Don't actually unload if more than one module is using the libs... */
+	if (x11_load_refcount > 0) {
+		if (--x11_load_refcount == 0) {
+			/* set all the function pointers to NULL. */
+			#define SDL_X11_SYM(ret,fn,params) p##fn = NULL;
+			#include "SDL_x11sym.h"
+			#undef SDL_X11_SYM
+
+			#ifdef X11_DYNAMIC
+			if (x11_handle != NULL) {
+				SDL_UnloadObject(x11_handle);
+				x11_handle = NULL;
+			}
+			if (x11ext_handle != NULL) {
+				SDL_UnloadObject(x11ext_handle);
+				x11ext_handle = NULL;
+			}
+			#endif
+		}
+	}
+}
+
+/* returns non-zero if all needed symbols were loaded. */
+int SDL_X11_LoadSymbols(void)
+{
+	int rc = 1;
+
+    /* deal with multiple modules (dga, x11, etc) needing these symbols... */
+	if (x11_load_refcount++ == 0) {
+		#ifdef X11_DYNAMIC
+			x11_handle = SDL_LoadObject(x11_library);
+			x11ext_handle = SDL_LoadObject(x11ext_library);
+			if ((x11_handle != NULL) && (x11ext_handle != NULL)) {
+				#define SDL_X11_SYM(r,fn,arg) p##fn = X11_GetSym(#fn, &rc);
+				#include "SDL_x11sym.h"
+				#undef SDL_X11_SYM
+			}
+
+			if (!rc)
+				SDL_X11_UnloadSymbols();  /* in case one of these loaded... */
+
+		#else
+			#define SDL_X11_SYM(r,fn,arg) p##fn = fn;
+			#include "SDL_x11sym.h"
+			#undef SDL_X11_SYM
+		#endif
+	}
+
+	return rc;
+}
+
+/* end of SDL_x11dyn.c ... */
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/video/x11/SDL_x11dyn.h	Sat Nov 05 19:53:37 2005 +0000
@@ -0,0 +1,71 @@
+/*
+    SDL - Simple DirectMedia Layer
+    Copyright (C) 1997-2004 Sam Lantinga
+
+    This library is free software; you can redistribute it and/or
+    modify it under the terms of the GNU Library General Public
+    License as published by the Free Software Foundation; either
+    version 2 of the License, or (at your option) any later version.
+
+    This library is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+    Library General Public License for more details.
+
+    You should have received a copy of the GNU Library General Public
+    License along with this library; if not, write to the Free
+    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+
+    Sam Lantinga
+    slouken@libsdl.org
+*/
+
+#ifndef _SDL_x11dyn_h
+#define _SDL_x11dyn_h
+
+#include <X11/Xlib.h>
+#include <X11/Xutil.h>
+#include <X11/Xatom.h>
+#include <X11/Xproto.h>
+#include <X11/Xlibint.h>
+#include <X11/extensions/extutil.h>
+
+#ifndef NO_SHARED_MEMORY
+#include <sys/ipc.h>
+#include <sys/shm.h>
+#include <X11/extensions/XShm.h>
+#endif
+
+/*
+ * Never reference Xlib directly...we might load it dynamically at runtime.
+ *  Even if we don't, for readability, we still use the function pointers
+ *  (although the symbol resolution will be done by the loader in that case).
+ *
+ * We define SDL_X11_SYM and include SDL_x11sym.h to accomplish various
+ *  goals, without having to duplicate those function signatures.
+ */
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* evil function signatures... */
+typedef Bool (*SDL_X11_XESetWireToEventRetType)(Display*,XEvent*,xEvent*);
+typedef int (*SDL_X11_XSynchronizeRetType)(Display*);
+typedef Status (*SDL_X11_XESetEventToWireRetType)(Display*,XEvent*,xEvent*);
+
+#define SDL_X11_SYM(ret,fn,params) extern ret (*p##fn) params;
+#include "SDL_x11sym.h"
+#undef SDL_X11_SYM
+
+/* Macro in the xlib headers, not an actual symbol... */
+#define pXDestroyImage XDestroyImage
+
+int SDL_X11_LoadSymbols(void);
+void SDL_X11_UnloadSymbols(void);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif  /* !defined _SDL_x11dyn_h */
+
--- a/src/video/x11/SDL_x11events.c	Sat Nov 05 17:41:11 2005 +0000
+++ b/src/video/x11/SDL_x11events.c	Sat Nov 05 19:53:37 2005 +0000
@@ -74,13 +74,13 @@
 	int repeated;
 
 	repeated = 0;
-	if ( XPending(display) ) {
-		XPeekEvent(display, &peekevent);
+	if ( pXPending(display) ) {
+		pXPeekEvent(display, &peekevent);
 		if ( (peekevent.type == KeyPress) &&
 		     (peekevent.xkey.keycode == event->xkey.keycode) &&
 		     ((peekevent.xkey.time-event->xkey.time) < 2) ) {
 			repeated = 1;
-			XNextEvent(display, &peekevent);
+			pXNextEvent(display, &peekevent);
 		}
 	}
 	return(repeated);
@@ -115,7 +115,7 @@
 	     (xevent->xmotion.y < MOUSE_FUDGE_FACTOR) ||
 	     (xevent->xmotion.y > (h-MOUSE_FUDGE_FACTOR)) ) {
 		/* Get the events that have accumulated */
-		while ( XCheckTypedEvent(SDL_Display, MotionNotify, xevent) ) {
+		while ( pXCheckTypedEvent(SDL_Display, MotionNotify, xevent) ) {
 			deltax = xevent->xmotion.x - mouse_last.x;
 			deltay = xevent->xmotion.y - mouse_last.y;
 #ifdef DEBUG_MOTION
@@ -127,10 +127,10 @@
 		}
 		mouse_last.x = w/2;
 		mouse_last.y = h/2;
-		XWarpPointer(SDL_Display, None, SDL_Window, 0, 0, 0, 0,
+		pXWarpPointer(SDL_Display, None, SDL_Window, 0, 0, 0, 0,
 					mouse_last.x, mouse_last.y);
 		for ( i=0; i<10; ++i ) {
-        		XMaskEvent(SDL_Display, PointerMotionMask, xevent);
+        		pXMaskEvent(SDL_Display, PointerMotionMask, xevent);
 			if ( (xevent->xmotion.x >
 			          (mouse_last.x-MOUSE_FUDGE_FACTOR)) &&
 			     (xevent->xmotion.x <
@@ -160,7 +160,7 @@
 	XEvent xevent;
 
 	memset(&xevent, '\0', sizeof (XEvent));  /* valgrind fix. --ryan. */
-	XNextEvent(SDL_Display, &xevent);
+	pXNextEvent(SDL_Display, &xevent);
 
 	posted = 0;
 	switch (xevent.type) {
@@ -437,8 +437,8 @@
 int X11_Pending(Display *display)
 {
 	/* Flush the display connection and look to see if events are queued */
-	XFlush(display);
-	if ( XEventsQueued(display, QueuedAlready) ) {
+	pXFlush(display);
+	if ( pXEventsQueued(display, QueuedAlready) ) {
 		return(1);
 	}
 
@@ -452,7 +452,7 @@
 		FD_ZERO(&fdset);
 		FD_SET(x11_fd, &fdset);
 		if ( select(x11_fd+1, &fdset, NULL, NULL, &zero_time) == 1 ) {
-			return(XPending(display));
+			return(pXPending(display));
 		}
 	}
 
@@ -619,7 +619,7 @@
 
 	/* Get the raw keyboard scancode */
 	keysym->scancode = kc;
-	xsym = XKeycodeToKeysym(display, kc, 0);
+	xsym = pXKeycodeToKeysym(display, kc, 0);
 #ifdef DEBUG_KEYS
 	fprintf(stderr, "Translating key 0x%.4x (%d)\n", xsym, kc);
 #endif
@@ -711,7 +711,7 @@
 		}
 #endif
 		/* Look up the translated value for the key event */
-		if ( XLookupString(xkey, (char *)keybuf, sizeof(keybuf),
+		if ( pXLookupString(xkey, (char *)keybuf, sizeof(keybuf),
 							NULL, &state) ) {
 			/*
 			 * FIXME,: XLookupString() may yield more than one
@@ -739,12 +739,12 @@
 	if(got_masks)
 		return;
 
-	xmods = XGetModifierMapping(display);
+	xmods = pXGetModifierMapping(display);
 	n = xmods->max_keypermod;
 	for(i = 3; i < 8; i++) {
 		for(j = 0; j < n; j++) {
 			KeyCode kc = xmods->modifiermap[i * n + j];
-			KeySym ks = XKeycodeToKeysym(display, kc, 0);
+			KeySym ks = pXKeycodeToKeysym(display, kc, 0);
 			unsigned mask = 1 << i;
 			switch(ks) {
 			case XK_Num_Lock:
@@ -762,7 +762,7 @@
 			}
 		}
 	}
-	XFreeModifiermap(xmods);
+	pXFreeModifiermap(xmods);
 	got_masks = 1;
 }
 
@@ -804,7 +804,7 @@
 		}
 	}
 
-	xkey.keycode = XKeysymToKeycode(xkey.display, xsym);
+	xkey.keycode = pXKeysymToKeycode(xkey.display, xsym);
 
 	get_modifier_masks(SDL_Display);
 	if(modifiers & KMOD_SHIFT)
@@ -827,7 +827,7 @@
 		xkey.state |= num_mask;
 
 	unicode = 0;
-	if ( XLookupString(&xkey, keybuf, sizeof(keybuf), NULL, NULL) )
+	if ( pXLookupString(&xkey, keybuf, sizeof(keybuf), NULL, NULL) )
 		unicode = (unsigned char)keybuf[0];
 	return(unicode);
 }
@@ -851,14 +851,14 @@
 
 	/* The first time the window is mapped, we initialize key state */
 	if ( ! key_vec ) {
-		XQueryKeymap(display, keys_return);
+		pXQueryKeymap(display, keys_return);
 		key_vec = keys_return;
 	}
 
 	/* Get the keyboard modifier state */
 	modstate = 0;
 	get_modifier_masks(display);
-	if ( XQueryPointer(display, DefaultRootWindow(display),
+	if ( pXQueryPointer(display, DefaultRootWindow(display),
 		&junk_window, &junk_window, &x, &y, &x, &y, &mask) ) {
 		if ( mask & LockMask ) {
 			modstate |= KMOD_CAPS;
--- a/src/video/x11/SDL_x11gamma.c	Sat Nov 05 17:41:11 2005 +0000
+++ b/src/video/x11/SDL_x11gamma.c	Sat Nov 05 19:53:37 2005 +0000
@@ -68,7 +68,7 @@
 	}
         if ( SDL_GetAppState() & SDL_APPACTIVE ) {
             succeeded = SDL_NAME(XF86VidModeSetGamma)(SDL_Display, SDL_Screen, &gamma);
-            XSync(SDL_Display, False);
+            pXSync(SDL_Display, False);
         } else {
             gamma_saved[0] = gamma.red;
             gamma_saved[1] = gamma.green;
--- a/src/video/x11/SDL_x11gl.c	Sat Nov 05 17:41:11 2005 +0000
+++ b/src/video/x11/SDL_x11gl.c	Sat Nov 05 19:53:37 2005 +0000
@@ -69,10 +69,10 @@
 		XVisualInfo vi_in;
 		int out_count;
 
-		XGetWindowAttributes(SDL_Display, SDL_Window, &a);
+		pXGetWindowAttributes(SDL_Display, SDL_Window, &a);
 		vi_in.screen = SDL_Screen;
-		vi_in.visualid = XVisualIDFromVisual(a.visual);
-		glx_visualinfo = XGetVisualInfo(SDL_Display,
+		vi_in.visualid = pXVisualIDFromVisual(a.visual);
+		glx_visualinfo = pXGetVisualInfo(SDL_Display,
 	                     VisualScreenMask|VisualIDMask, &vi_in, &out_count);
 		return glx_visualinfo;
 	}
@@ -188,7 +188,7 @@
 	attributes.colormap = SDL_XColorMap;
 	mask = CWBackPixel | CWBorderPixel | CWColormap;
 
-	SDL_Window = XCreateWindow(SDL_Display, WMwindow,
+	SDL_Window = pXCreateWindow(SDL_Display, WMwindow,
 			0, 0, w, h, 0, glx_visualinfo->depth,
 			InputOutput, glx_visualinfo->visual,
 			mask, &attributes);
@@ -209,10 +209,10 @@
 	int retval;
 #ifdef HAVE_OPENGL
 	/* We do this to create a clean separation between X and GLX errors. */
-	XSync( SDL_Display, False );
+	pXSync( SDL_Display, False );
 	glx_context = this->gl_data->glXCreateContext(GFX_Display, 
 				     glx_visualinfo, NULL, True);
-	XSync( GFX_Display, False );
+	pXSync( GFX_Display, False );
 
 	if (glx_context == NULL) {
 		SDL_SetError("Could not create GL context");
@@ -296,7 +296,7 @@
 		SDL_SetError("Unable to make GL context current");
 		retval = -1;
 	}
-	XSync( GFX_Display, False );
+	pXSync( GFX_Display, False );
 
 	/* 
 	 * The context is now current, check for glXReleaseBuffersMESA() 
--- a/src/video/x11/SDL_x11image.c	Sat Nov 05 17:41:11 2005 +0000
+++ b/src/video/x11/SDL_x11image.c	Sat Nov 05 19:53:37 2005 +0000
@@ -35,9 +35,6 @@
 
 #ifndef NO_SHARED_MEMORY
 
-/* Shared memory information */
-extern int XShmQueryExtension(Display *dpy);	/* Not in X11 headers */
-
 /* Shared memory error handler routine */
 static int shm_error;
 static int (*X_handler)(Display *, XErrorEvent *) = NULL;
@@ -61,10 +58,10 @@
 		shminfo.readOnly = False;
 		if ( shminfo.shmaddr != (char *)-1 ) {
 			shm_error = False;
-			X_handler = XSetErrorHandler(shm_errhandler);
-			XShmAttach(SDL_Display, &shminfo);
-			XSync(SDL_Display, True);
-			XSetErrorHandler(X_handler);
+			X_handler = pXSetErrorHandler(shm_errhandler);
+			pXShmAttach(SDL_Display, &shminfo);
+			pXSync(SDL_Display, True);
+			pXSetErrorHandler(X_handler);
 			if ( shm_error )
 				shmdt(shminfo.shmaddr);
 		} else {
@@ -90,13 +87,13 @@
 #ifndef NO_SHARED_MEMORY
 	try_mitshm(this, screen);
 	if(use_mitshm) {
-		SDL_Ximage = XShmCreateImage(SDL_Display, SDL_Visual,
+		SDL_Ximage = pXShmCreateImage(SDL_Display, SDL_Visual,
 					     this->hidden->depth, ZPixmap,
 					     shminfo.shmaddr, &shminfo, 
 					     screen->w, screen->h);
 		if(!SDL_Ximage) {
-			XShmDetach(SDL_Display, &shminfo);
-			XSync(SDL_Display, False);
+			pXShmDetach(SDL_Display, &shminfo);
+			pXSync(SDL_Display, False);
 			shmdt(shminfo.shmaddr);
 			screen->pixels = NULL;
 			goto error;
@@ -113,7 +110,7 @@
 			return -1;
 		}
  	        bpp = screen->format->BytesPerPixel;
-		SDL_Ximage = XCreateImage(SDL_Display, SDL_Visual,
+		SDL_Ximage = pXCreateImage(SDL_Display, SDL_Visual,
 					  this->hidden->depth, ZPixmap, 0,
 					  (char *)screen->pixels, 
 					  screen->w, screen->h,
@@ -136,11 +133,11 @@
 void X11_DestroyImage(_THIS, SDL_Surface *screen)
 {
 	if ( SDL_Ximage ) {
-		XDestroyImage(SDL_Ximage);
+		pXDestroyImage(SDL_Ximage);
 #ifndef NO_SHARED_MEMORY
 		if ( use_mitshm ) {
-			XShmDetach(SDL_Display, &shminfo);
-			XSync(SDL_Display, False);
+			pXShmDetach(SDL_Display, &shminfo);
+			pXSync(SDL_Display, False);
 			shmdt(shminfo.shmaddr);
 		}
 #endif /* ! NO_SHARED_MEMORY */
@@ -221,7 +218,7 @@
 int X11_LockHWSurface(_THIS, SDL_Surface *surface)
 {
 	if ( (surface == SDL_VideoSurface) && blit_queued ) {
-		XSync(GFX_Display, False);
+		pXSync(GFX_Display, False);
 		blit_queued = 0;
 	}
 	return(0);
@@ -244,15 +241,15 @@
 		if ( rects[i].w == 0 || rects[i].h == 0 ) { /* Clipped? */
 			continue;
 		}
-		XPutImage(GFX_Display, SDL_Window, SDL_GC, SDL_Ximage,
+		pXPutImage(GFX_Display, SDL_Window, SDL_GC, SDL_Ximage,
 			  rects[i].x, rects[i].y,
 			  rects[i].x, rects[i].y, rects[i].w, rects[i].h);
 	}
 	if ( SDL_VideoSurface->flags & SDL_ASYNCBLIT ) {
-		XFlush(GFX_Display);
+		pXFlush(GFX_Display);
 		blit_queued = 1;
 	} else {
-		XSync(GFX_Display, False);
+		pXSync(GFX_Display, False);
 	}
 }
 
@@ -265,16 +262,16 @@
 		if ( rects[i].w == 0 || rects[i].h == 0 ) { /* Clipped? */
 			continue;
 		}
-		XShmPutImage(GFX_Display, SDL_Window, SDL_GC, SDL_Ximage,
+		pXShmPutImage(GFX_Display, SDL_Window, SDL_GC, SDL_Ximage,
 				rects[i].x, rects[i].y,
 				rects[i].x, rects[i].y, rects[i].w, rects[i].h,
 									False);
 	}
 	if ( SDL_VideoSurface->flags & SDL_ASYNCBLIT ) {
-		XFlush(GFX_Display);
+		pXFlush(GFX_Display);
 		blit_queued = 1;
 	} else {
-		XSync(GFX_Display, False);
+		pXSync(GFX_Display, False);
 	}
 #endif /* ! NO_SHARED_MEMORY */
 }
@@ -308,14 +305,14 @@
 	}
 #ifndef NO_SHARED_MEMORY
 	if ( this->UpdateRects == X11_MITSHMUpdate ) {
-		XShmPutImage(SDL_Display, SDL_Window, SDL_GC, SDL_Ximage,
+		pXShmPutImage(SDL_Display, SDL_Window, SDL_GC, SDL_Ximage,
 				0, 0, 0, 0, this->screen->w, this->screen->h,
 				False);
 	} else
 #endif /* ! NO_SHARED_MEMORY */
 	{
-		XPutImage(SDL_Display, SDL_Window, SDL_GC, SDL_Ximage,
+		pXPutImage(SDL_Display, SDL_Window, SDL_GC, SDL_Ximage,
 			  0, 0, 0, 0, this->screen->w, this->screen->h);
 	}
-	XSync(SDL_Display, False);
+	pXSync(SDL_Display, False);
 }
--- a/src/video/x11/SDL_x11modes.c	Sat Nov 05 17:41:11 2005 +0000
+++ b/src/video/x11/SDL_x11modes.c	Sat Nov 05 19:53:37 2005 +0000
@@ -141,7 +141,7 @@
                  (modes[i]->vdisplay != mode.vdisplay) ) {
                 SDL_NAME(XF86VidModeSwitchToMode)(SDL_Display, SDL_Screen, modes[i]);
             }
-            XFree(modes);
+            pXFree(modes);
         }
     }
 #endif /* XFREE86_VM */
@@ -180,7 +180,7 @@
                                         SDL_modelist[i]->w, 
                                         SDL_modelist[i]->h, 
                                         0);
-                XSync(SDL_Display, False);
+                pXSync(SDL_Display, False);
             }
         }
     }
@@ -230,7 +230,7 @@
 {
     XEvent event;
     do {
-        XMaskEvent(SDL_Display, StructureNotifyMask, &event);
+        pXMaskEvent(SDL_Display, StructureNotifyMask, &event);
     } while ( (event.type != MapNotify) || (event.xmap.event != win) );
 }
 
@@ -239,19 +239,19 @@
 {
     XEvent event;
     do {
-        XMaskEvent(SDL_Display, StructureNotifyMask, &event);
+        pXMaskEvent(SDL_Display, StructureNotifyMask, &event);
     } while ( (event.type != UnmapNotify) || (event.xunmap.event != win) );
 }
 
 static void move_cursor_to(_THIS, int x, int y)
 {
-    XWarpPointer(SDL_Display, None, SDL_Root, 0, 0, 0, 0, x, y);
+    pXWarpPointer(SDL_Display, None, SDL_Root, 0, 0, 0, 0, x, y);
 }
 
 static int add_visual(_THIS, int depth, int class)
 {
     XVisualInfo vi;
-    if(XMatchVisualInfo(SDL_Display, SDL_Screen, depth, class, &vi)) {
+    if(pXMatchVisualInfo(SDL_Display, SDL_Screen, depth, class, &vi)) {
         int n = this->hidden->nvisuals;
         this->hidden->visuals[n].depth = vi.depth;
         this->hidden->visuals[n].visual = vi.visual;
@@ -267,13 +267,13 @@
     if ( visual_id ) {
         memset(&template, 0, (sizeof template));
         template.visualid = strtol(visual_id, NULL, 0);
-        vi = XGetVisualInfo(SDL_Display, VisualIDMask, &template, &nvis);
+        vi = pXGetVisualInfo(SDL_Display, VisualIDMask, &template, &nvis);
         if ( vi ) {
             int n = this->hidden->nvisuals;
             this->hidden->visuals[n].depth = vi->depth;
             this->hidden->visuals[n].visual = vi->visual;
             this->hidden->nvisuals++;
-            XFree(vi);
+            pXFree(vi);
         }
     }
     return(this->hidden->nvisuals);
@@ -400,7 +400,7 @@
             }
             SDL_modelist[n] = NULL;
         }
-        XFree(modes);
+        pXFree(modes);
 
         use_vidmode = vm_major * 100 + vm_minor;
         save_mode(this);
@@ -474,7 +474,7 @@
         use_xme = 0;
     }
     if ( modelist ) {
-        XFree(modelist);
+        pXFree(modelist);
     }
 #endif /* HAVE_XIGXME */
 
@@ -509,7 +509,7 @@
         }
             
         /* look up the pixel quantum for each depth */
-        pf = XListPixmapFormats(SDL_Display, &np);
+        pf = pXListPixmapFormats(SDL_Display, &np);
         for(i = 0; i < this->hidden->nvisuals; i++) {
             int d = this->hidden->visuals[i].depth;
             for(j = 0; j < np; j++)
@@ -518,7 +518,7 @@
             this->hidden->visuals[i].bpp = j < np ? pf[j].bits_per_pixel : d;
         }
 
-        XFree(pf);
+        pXFree(pf);
     }
 
     if ( SDL_modelist == NULL ) {
@@ -592,7 +592,7 @@
                 xinerama_y = xinerama[i].y_org;
             }
         }
-        XFree(xinerama);
+        pXFree(xinerama);
     }
 #endif /* HAVE_XINERAMA */
 
@@ -658,15 +658,15 @@
         if ( current_h > real_h ) {
             real_h = MAX(real_h, screen_h);
         }
-        XMoveResizeWindow(SDL_Display, FSwindow, x, y, real_w, real_h);
+        pXMoveResizeWindow(SDL_Display, FSwindow, x, y, real_w, real_h);
         move_cursor_to(this, real_w/2, real_h/2);
 
         /* Center and reparent the drawing window */
         x = (real_w - current_w)/2;
         y = (real_h - current_h)/2;
-        XReparentWindow(SDL_Display, SDL_Window, FSwindow, x, y);
+        pXReparentWindow(SDL_Display, SDL_Window, FSwindow, x, y);
         /* FIXME: move the mouse to the old relative location */
-        XSync(SDL_Display, True);   /* Flush spurious mode change events */
+        pXSync(SDL_Display, True);   /* Flush spurious mode change events */
     }
     return(1);
 }
@@ -676,7 +676,7 @@
     switch_waiting = 0x01 | SDL_FULLSCREEN;
     switch_time = SDL_GetTicks() + 1500;
 #if 0 /* This causes a BadMatch error if the window is iconified (not needed) */
-    XSetInputFocus(SDL_Display, WMwindow, RevertToNone, CurrentTime);
+    pXSetInputFocus(SDL_Display, WMwindow, RevertToNone, CurrentTime);
 #endif
 }
 
@@ -709,14 +709,14 @@
     if ( current_h > real_h ) {
         real_h = MAX(real_h, screen_h);
     }
-    XMoveResizeWindow(SDL_Display, FSwindow,
+    pXMoveResizeWindow(SDL_Display, FSwindow,
                       xinerama_x, xinerama_y, real_w, real_h);
-    XMapRaised(SDL_Display, FSwindow);
+    pXMapRaised(SDL_Display, FSwindow);
     X11_WaitMapped(this, FSwindow);
 
 #if 0 /* This seems to break WindowMaker in focus-follows-mouse mode */
     /* Make sure we got to the top of the window stack */
-    if ( XQueryTree(SDL_Display, SDL_Root, &tmpwin, &tmpwin,
+    if ( pXQueryTree(SDL_Display, SDL_Root, &tmpwin, &tmpwin,
                             &windows, &nwindows) && windows ) {
         /* If not, try to put us there - if fail... oh well */
         if ( windows[nwindows-1] != FSwindow ) {
@@ -729,13 +729,13 @@
                 }
             }
             windows[nwindows-1] = FSwindow;
-            XRestackWindows(SDL_Display, windows, nwindows);
-            XSync(SDL_Display, False);
+            pXRestackWindows(SDL_Display, windows, nwindows);
+            pXSync(SDL_Display, False);
         }
-        XFree(windows);
+        pXFree(windows);
     }
 #else
-    XRaiseWindow(SDL_Display, FSwindow);
+    pXRaiseWindow(SDL_Display, FSwindow);
 #endif
 
 #ifdef XFREE86_VM
@@ -753,7 +753,7 @@
     }
     /* Set the colormap */
     if ( SDL_XColorMap ) {
-        XInstallColormap(SDL_Display, SDL_XColorMap);
+        pXInstallColormap(SDL_Display, SDL_XColorMap);
     }
     if ( okay )
         X11_GrabInputNoLock(this, this->input_grab | SDL_GRAB_FULLSCREEN);
@@ -774,7 +774,7 @@
 int X11_LeaveFullScreen(_THIS)
 {
     if ( currently_fullscreen ) {
-        XReparentWindow(SDL_Display, SDL_Window, WMwindow, 0, 0);
+        pXReparentWindow(SDL_Display, SDL_Window, WMwindow, 0, 0);
 #ifdef XFREE86_VM
         if ( use_vidmode ) {
             restore_mode(this);
@@ -796,14 +796,14 @@
                                         saved_res.width, 
                                         saved_res.height,
                                         0);
-                XSync(SDL_Display, False);
+                pXSync(SDL_Display, False);
             }
         }
 #endif
 
-        XUnmapWindow(SDL_Display, FSwindow);
+        pXUnmapWindow(SDL_Display, FSwindow);
         X11_WaitUnmapped(this, FSwindow);
-        XSync(SDL_Display, True);   /* Flush spurious mode change events */
+        pXSync(SDL_Display, True);   /* Flush spurious mode change events */
         currently_fullscreen = 0;
     }
     /* If we get popped out of fullscreen mode for some reason, input_grab
--- a/src/video/x11/SDL_x11mouse.c	Sat Nov 05 17:41:11 2005 +0000
+++ b/src/video/x11/SDL_x11mouse.c	Sat Nov 05 19:53:37 2005 +0000
@@ -50,8 +50,8 @@
 {
 	if ( SDL_Display != NULL ) {
 		SDL_Lock_EventThread();
-		XFreeCursor(SDL_Display, cursor->x_cursor);
-		XSync(SDL_Display, False);
+		pXFreeCursor(SDL_Display, cursor->x_cursor);
+		pXSync(SDL_Display, False);
 		SDL_Unlock_EventThread();
 	}
 	free(cursor);
@@ -105,48 +105,48 @@
 	SDL_Lock_EventThread();
 
 	/* Create the data image */
-	data_image = XCreateImage(SDL_Display, 
+	data_image = pXCreateImage(SDL_Display, 
 			DefaultVisual(SDL_Display, SDL_Screen),
 					1, XYBitmap, 0, x_data, w, h, 8, w/8);
 	data_image->byte_order = MSBFirst;
 	data_image->bitmap_bit_order = MSBFirst;
-	data_pixmap = XCreatePixmap(SDL_Display, SDL_Root, w, h, 1);
+	data_pixmap = pXCreatePixmap(SDL_Display, SDL_Root, w, h, 1);
 
 	/* Create the data mask */
-	mask_image = XCreateImage(SDL_Display, 
+	mask_image = pXCreateImage(SDL_Display, 
 			DefaultVisual(SDL_Display, SDL_Screen),
 					1, XYBitmap, 0, x_mask, w, h, 8, w/8);
 	mask_image->byte_order = MSBFirst;
 	mask_image->bitmap_bit_order = MSBFirst;
-	mask_pixmap = XCreatePixmap(SDL_Display, SDL_Root, w, h, 1);
+	mask_pixmap = pXCreatePixmap(SDL_Display, SDL_Root, w, h, 1);
 
 	/* Create the graphics context */
 	GCvalues.function = GXcopy;
 	GCvalues.foreground = ~0;
 	GCvalues.background =  0;
 	GCvalues.plane_mask = AllPlanes;
-	GCcursor = XCreateGC(SDL_Display, data_pixmap,
+	GCcursor = pXCreateGC(SDL_Display, data_pixmap,
 			(GCFunction|GCForeground|GCBackground|GCPlaneMask),
 								&GCvalues);
 
 	/* Blit the images to the pixmaps */
-	XPutImage(SDL_Display, data_pixmap, GCcursor, data_image,
+	pXPutImage(SDL_Display, data_pixmap, GCcursor, data_image,
 							0, 0, 0, 0, w, h);
-	XPutImage(SDL_Display, mask_pixmap, GCcursor, mask_image,
+	pXPutImage(SDL_Display, mask_pixmap, GCcursor, mask_image,
 							0, 0, 0, 0, w, h);
-	XFreeGC(SDL_Display, GCcursor);
+	pXFreeGC(SDL_Display, GCcursor);
 	/* These free the x_data and x_mask memory pointers */
-	XDestroyImage(data_image);
-	XDestroyImage(mask_image);
+	pXDestroyImage(data_image);
+	pXDestroyImage(mask_image);
 
 	/* Create the cursor */
-	cursor->x_cursor = XCreatePixmapCursor(SDL_Display, data_pixmap,
+	cursor->x_cursor = pXCreatePixmapCursor(SDL_Display, data_pixmap,
 				mask_pixmap, &black, &white, hot_x, hot_y);
-	XFreePixmap(SDL_Display, data_pixmap);
-	XFreePixmap(SDL_Display, mask_pixmap);
+	pXFreePixmap(SDL_Display, data_pixmap);
+	pXFreePixmap(SDL_Display, mask_pixmap);
 
 	/* Release the event thread */
-	XSync(SDL_Display, False);
+	pXSync(SDL_Display, False);
 	SDL_Unlock_EventThread();
 
 	return(cursor);
@@ -164,13 +164,13 @@
 		SDL_Lock_EventThread();
 		if ( cursor == NULL ) {
 			if ( SDL_BlankCursor != NULL ) {
-				XDefineCursor(SDL_Display, SDL_Window,
+				pXDefineCursor(SDL_Display, SDL_Window,
 					SDL_BlankCursor->x_cursor);
 			}
 		} else {
-			XDefineCursor(SDL_Display, SDL_Window, cursor->x_cursor);
+			pXDefineCursor(SDL_Display, SDL_Window, cursor->x_cursor);
 		}
-		XSync(SDL_Display, False);
+		pXSync(SDL_Display, False);
 		SDL_Unlock_EventThread();
 	}
 	return(1);
@@ -187,8 +187,8 @@
 		SDL_PrivateMouseMotion(0, 0, x, y);
 	} else {
 		SDL_Lock_EventThread();
-		XWarpPointer(SDL_Display, None, SDL_Window, 0, 0, 0, 0, x, y);
-		XSync(SDL_Display, False);
+		pXWarpPointer(SDL_Display, None, SDL_Window, 0, 0, 0, 0, x, y);
+		pXSync(SDL_Display, False);
 		SDL_Unlock_EventThread();
 	}
 }
@@ -224,7 +224,7 @@
 		}
 	}
 	if ( mouse_param_buf ) {
-		XChangePointerControl(SDL_Display, True, True,
+		pXChangePointerControl(SDL_Display, True, True,
 			accel_value[0], accel_value[1], accel_value[2]);
 		free(mouse_param_buf);
 	}
@@ -257,7 +257,7 @@
 
 				SDL_GetMouseState(&mouse_last.x, &mouse_last.y);
 				/* Use as raw mouse mickeys as possible */
-				XGetPointerControl(SDL_Display,
+				pXGetPointerControl(SDL_Display,
 						&mouse_accel.numerator, 
 						&mouse_accel.denominator,
 						&mouse_accel.threshold);
@@ -273,7 +273,7 @@
 			if ( using_dga & DGA_MOUSE ) {
 				X11_DisableDGAMouse(this);
 			} else {
-				XChangePointerControl(SDL_Display, True, True,
+				pXChangePointerControl(SDL_Display, True, True,
 						mouse_accel.numerator, 
 						mouse_accel.denominator,
 						mouse_accel.threshold);
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/video/x11/SDL_x11sym.h	Sat Nov 05 19:53:37 2005 +0000
@@ -0,0 +1,144 @@
+/*
+    SDL - Simple DirectMedia Layer
+    Copyright (C) 1997-2004 Sam Lantinga
+
+    This library is free software; you can redistribute it and/or
+    modify it under the terms of the GNU Library General Public
+    License as published by the Free Software Foundation; either
+    version 2 of the License, or (at your option) any later version.
+
+    This library is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+    Library General Public License for more details.
+
+    You should have received a copy of the GNU Library General Public
+    License along with this library; if not, write to the Free
+    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+
+    Sam Lantinga
+    slouken@libsdl.org
+*/
+
+SDL_X11_SYM(XClassHint*,XAllocClassHint,(void))
+SDL_X11_SYM(Status,XAllocColor,(Display*,Colormap,XColor*))
+SDL_X11_SYM(XSizeHints*,XAllocSizeHints,(void))
+SDL_X11_SYM(XWMHints*,XAllocWMHints,(void))
+SDL_X11_SYM(int,XChangePointerControl,(Display*,Bool,Bool,int,int,int))
+SDL_X11_SYM(int,XChangeProperty,(Display*,Window,Atom,Atom,int,int,_Xconst unsigned char*,int))
+SDL_X11_SYM(int,XChangeWindowAttributes,(Display*,Window,unsigned long,XSetWindowAttributes*))
+SDL_X11_SYM(Bool,XCheckTypedEvent,(Display*,int,XEvent*))
+SDL_X11_SYM(int,XClearWindow,(Display*,Window))
+SDL_X11_SYM(int,XCloseDisplay,(Display*))
+SDL_X11_SYM(Colormap,XCreateColormap,(Display*,Window,Visual*,int))
+SDL_X11_SYM(Cursor,XCreatePixmapCursor,(Display*,Pixmap,Pixmap,XColor*,XColor*,unsigned int,unsigned int))
+SDL_X11_SYM(GC,XCreateGC,(Display*,Drawable,unsigned long,XGCValues*))
+SDL_X11_SYM(XImage*,XCreateImage,(Display*,Visual*,unsigned int,int,int,char*,unsigned int,unsigned int,int,int))
+SDL_X11_SYM(Pixmap,XCreatePixmap,(Display*,Drawable,unsigned int,unsigned int,unsigned int))
+SDL_X11_SYM(Pixmap,XCreatePixmapFromBitmapData,(Display*,Drawable,char*,unsigned int,unsigned int,unsigned long,unsigned long,unsigned int))
+SDL_X11_SYM(Window,XCreateSimpleWindow,(Display*,Window,int,int,unsigned int,unsigned int,unsigned int,unsigned long,unsigned long))
+SDL_X11_SYM(Window,XCreateWindow,(Display*,Window,int,int,unsigned int,unsigned int,unsigned int,int,unsigned int,Visual*,unsigned long,XSetWindowAttributes*))
+SDL_X11_SYM(int,XDefineCursor,(Display*,Window,Cursor))
+SDL_X11_SYM(int,XDeleteProperty,(Display*,Window,Atom))
+SDL_X11_SYM(int,XDestroyWindow,(Display*,Window))
+SDL_X11_SYM(char*,XDisplayName,(_Xconst char*))
+SDL_X11_SYM(int,XEventsQueued,(Display*,int))
+SDL_X11_SYM(int,XFlush,(Display*))
+SDL_X11_SYM(int,XFree,(void*))
+SDL_X11_SYM(int,XFreeColormap,(Display*,Colormap))
+SDL_X11_SYM(int,XFreeColors,(Display*,Colormap,unsigned long*,int,unsigned long))
+SDL_X11_SYM(int,XFreeCursor,(Display*,Cursor))
+SDL_X11_SYM(int,XFreeGC,(Display*,GC))
+SDL_X11_SYM(int,XFreeModifiermap,(XModifierKeymap*))
+SDL_X11_SYM(int,XFreePixmap,(Display*,Pixmap))
+SDL_X11_SYM(int,XGetErrorDatabaseText,(Display*,_Xconst char*,_Xconst char*,_Xconst char*,char*,int))
+SDL_X11_SYM(XModifierKeymap*,XGetModifierMapping,(Display*))
+SDL_X11_SYM(int,XGetPointerControl,(Display*,int*,int*,int*))
+SDL_X11_SYM(XVisualInfo*,XGetVisualInfo,(Display*,long,XVisualInfo*,int*))
+SDL_X11_SYM(XWMHints*,XGetWMHints,(Display*,Window))
+SDL_X11_SYM(Status,XGetWMIconName,(Display*,Window,XTextProperty*))
+SDL_X11_SYM(Status,XGetWMName,(Display*,Window,XTextProperty*))
+SDL_X11_SYM(Status,XGetWindowAttributes,(Display*,Window,XWindowAttributes*))
+SDL_X11_SYM(int,XGrabKeyboard,(Display*,Window,Bool,int,int,Time))
+SDL_X11_SYM(int,XGrabPointer,(Display*,Window,Bool,unsigned int,int,int,Window,Cursor,Time))
+SDL_X11_SYM(Status,XIconifyWindow,(Display*,Window,int))
+SDL_X11_SYM(int,XInstallColormap,(Display*,Colormap))
+SDL_X11_SYM(KeyCode,XKeysymToKeycode,(Display*,KeySym))
+SDL_X11_SYM(Atom,XInternAtom,(Display*,_Xconst char*,Bool))
+SDL_X11_SYM(XPixmapFormatValues*,XListPixmapFormats,(Display*,int*))
+SDL_X11_SYM(int,XLookupString,(XKeyEvent*,char*,int,KeySym*,XComposeStatus*))
+SDL_X11_SYM(int,XMapRaised,(Display*,Window))
+SDL_X11_SYM(int,XMapWindow,(Display*,Window))
+SDL_X11_SYM(int,XMaskEvent,(Display*,long,XEvent*))
+SDL_X11_SYM(Status,XMatchVisualInfo,(Display*,int,int,int,XVisualInfo*))
+SDL_X11_SYM(int,XMissingExtension,(Display*,_Xconst char*))
+SDL_X11_SYM(int,XMoveResizeWindow,(Display*,Window,int,int,unsigned int,unsigned int))
+SDL_X11_SYM(int,XMoveWindow,(Display*,Window,int,int))
+SDL_X11_SYM(int,XNextEvent,(Display*,XEvent*))
+SDL_X11_SYM(Display*,XOpenDisplay,(_Xconst char*))
+SDL_X11_SYM(int,XPeekEvent,(Display*,XEvent*))
+SDL_X11_SYM(int,XPending,(Display*))
+SDL_X11_SYM(int,XPutImage,(Display*,Drawable,GC,XImage*,int,int,int,int,unsigned int,unsigned int))
+SDL_X11_SYM(int,XQueryColors,(Display*,Colormap,XColor*,int))
+SDL_X11_SYM(int,XQueryKeymap,(Display*,char [32]))
+SDL_X11_SYM(Bool,XQueryPointer,(Display*,Window,Window*,Window*,int*,int*,int*,int*,unsigned int*))
+SDL_X11_SYM(int,XRaiseWindow,(Display*,Window))
+SDL_X11_SYM(int,XReparentWindow,(Display*,Window,Window,int,int))
+SDL_X11_SYM(int,XResizeWindow,(Display*,Window,unsigned int,unsigned int))
+SDL_X11_SYM(int,XSelectInput,(Display*,Window,long))
+SDL_X11_SYM(Status,XSendEvent,(Display*,Window,Bool,long,XEvent*))
+SDL_X11_SYM(int,XSetClassHint,(Display*,Window,XClassHint*))
+SDL_X11_SYM(XErrorHandler,XSetErrorHandler,(XErrorHandler))
+SDL_X11_SYM(XIOErrorHandler,XSetIOErrorHandler,(XIOErrorHandler))
+SDL_X11_SYM(int,XSetTransientForHint,(Display*,Window,Window))
+SDL_X11_SYM(int,XSetWMHints,(Display*,Window,XWMHints*))
+SDL_X11_SYM(void,XSetWMIconName,(Display*,Window,XTextProperty*))
+SDL_X11_SYM(void,XSetWMName,(Display*,Window,XTextProperty*))
+SDL_X11_SYM(void,XSetWMNormalHints,(Display*,Window,XSizeHints*))
+SDL_X11_SYM(Status,XSetWMProtocols,(Display*,Window,Atom*,int))
+SDL_X11_SYM(int,XSetWindowBackground,(Display*,Window,unsigned long))
+SDL_X11_SYM(int,XSetWindowBackgroundPixmap,(Display*,Window,Pixmap))
+SDL_X11_SYM(int,XSetWindowColormap,(Display*,Window,Colormap))
+SDL_X11_SYM(int,XStoreColors,(Display*,Colormap,XColor*,int))
+SDL_X11_SYM(Status,XStringListToTextProperty,(char**,int,XTextProperty*))
+SDL_X11_SYM(int,XSync,(Display*,Bool))
+SDL_X11_SYM(int,XUngrabKeyboard,(Display*,Time))
+SDL_X11_SYM(int,XUngrabPointer,(Display*,Time))
+SDL_X11_SYM(int,XUnmapWindow,(Display*,Window))
+SDL_X11_SYM(int,XWarpPointer,(Display*,Window,Window,int,int,unsigned int,unsigned int,int,int))
+SDL_X11_SYM(VisualID,XVisualIDFromVisual,(Visual*))
+SDL_X11_SYM(XExtDisplayInfo*,XextAddDisplay,(XExtensionInfo*,Display*,char*,XExtensionHooks*,int,XPointer))
+SDL_X11_SYM(XExtensionInfo*,XextCreateExtension,(void))
+SDL_X11_SYM(void,XextDestroyExtension,(XExtensionInfo*))
+SDL_X11_SYM(XExtDisplayInfo*,XextFindDisplay,(XExtensionInfo*,Display*))
+SDL_X11_SYM(int,XextRemoveDisplay,(XExtensionInfo*,Display*))
+SDL_X11_SYM(int,Xutf8TextListToTextProperty,(Display*,char**,int,XICCEncodingStyle,XTextProperty*))
+SDL_X11_SYM(void,_XEatData,(Display*,unsigned long))
+SDL_X11_SYM(void,_XFlush,(Display*))
+SDL_X11_SYM(void,_XFlushGCCache,(Display*,GC))
+SDL_X11_SYM(int,_XRead,(Display*,char*,long))
+SDL_X11_SYM(void,_XReadPad,(Display*,char*,long))
+SDL_X11_SYM(void,_XSend,(Display*,_Xconst char*,long))
+SDL_X11_SYM(Status,_XReply,(Display*,xReply*,int,Bool))
+SDL_X11_SYM(unsigned long,_XSetLastRequestRead,(Display*,xGenericReply*))
+
+#if NeedWidePrototypes
+SDL_X11_SYM(KeySym,XKeycodeToKeysym,(Display*,unsigned int,int))
+#else
+SDL_X11_SYM(KeySym,XKeycodeToKeysym,(Display*,KeyCode,int))
+#endif
+
+#ifndef NO_SHARED_MEMORY
+SDL_X11_SYM(Status,XShmAttach,(Display*,XShmSegmentInfo*))
+SDL_X11_SYM(Status,XShmDetach,(Display*,XShmSegmentInfo*))
+SDL_X11_SYM(Status,XShmPutImage,(Display*,Drawable,GC,XImage*,int,int,int,int,unsigned int,unsigned int,Bool))
+SDL_X11_SYM(XImage*,XShmCreateImage,(Display*,Visual*,unsigned int,int,char*,XShmSegmentInfo*,unsigned int,unsigned int))
+SDL_X11_SYM(Bool,XShmQueryExtension,(Display*))
+#endif
+
+SDL_X11_SYM(SDL_X11_XSynchronizeRetType,XSynchronize,(Display*,Bool))
+SDL_X11_SYM(SDL_X11_XESetWireToEventRetType,XESetWireToEvent,(Display*,int,SDL_X11_XESetWireToEventRetType))
+SDL_X11_SYM(SDL_X11_XESetEventToWireRetType,XESetEventToWire,(Display*,int,SDL_X11_XESetEventToWireRetType))
+
+/* end of SDL_x11sym.h ... */
+
--- a/src/video/x11/SDL_x11video.c	Sat Nov 05 17:41:11 2005 +0000
+++ b/src/video/x11/SDL_x11video.c	Sat Nov 05 19:53:37 2005 +0000
@@ -85,15 +85,18 @@
 static int X11_SetGammaRamp(_THIS, Uint16 *ramp);
 static void X11_VideoQuit(_THIS);
 
+
 /* X11 driver bootstrap functions */
 
 static int X11_Available(void)
 {
-	Display *display;
-
-	display = XOpenDisplay(NULL);
-	if ( display != NULL ) {
-		XCloseDisplay(display);
+	Display *display = NULL;
+	if ( SDL_X11_LoadSymbols() ) {
+		display = pXOpenDisplay(NULL);
+		if ( display != NULL ) {
+			pXCloseDisplay(display);
+		}
+		SDL_X11_UnloadSymbols();
 	}
 	return(display != NULL);
 }
@@ -108,80 +111,83 @@
 			free(device->gl_data);
 		}
 		free(device);
+		SDL_X11_UnloadSymbols();
 	}
 }
 
 static SDL_VideoDevice *X11_CreateDevice(int devindex)
 {
-	SDL_VideoDevice *device;
+	SDL_VideoDevice *device = NULL;
 
-	/* Initialize all variables that we clean on shutdown */
-	device = (SDL_VideoDevice *)malloc(sizeof(SDL_VideoDevice));
-	if ( device ) {
-		memset(device, 0, (sizeof *device));
-		device->hidden = (struct SDL_PrivateVideoData *)
-				malloc((sizeof *device->hidden));
-		device->gl_data = (struct SDL_PrivateGLData *)
-				malloc((sizeof *device->gl_data));
-	}
-	if ( (device == NULL) || (device->hidden == NULL) ||
-	                         (device->gl_data == NULL) ) {
-		SDL_OutOfMemory();
-		X11_DeleteDevice(device);
-		return(0);
-	}
-	memset(device->hidden, 0, (sizeof *device->hidden));
-	memset(device->gl_data, 0, (sizeof *device->gl_data));
+	if ( SDL_X11_LoadSymbols() ) {
+		/* Initialize all variables that we clean on shutdown */
+		device = (SDL_VideoDevice *)malloc(sizeof(SDL_VideoDevice));
+		if ( device ) {
+			memset(device, 0, (sizeof *device));
+			device->hidden = (struct SDL_PrivateVideoData *)
+					malloc((sizeof *device->hidden));
+			device->gl_data = (struct SDL_PrivateGLData *)
+					malloc((sizeof *device->gl_data));
+		}
+		if ( (device == NULL) || (device->hidden == NULL) ||
+		                         (device->gl_data == NULL) ) {
+			SDL_OutOfMemory();
+			X11_DeleteDevice(device); /* calls SDL_X11_UnloadSymbols(). */
+			return(0);
+		}
+		memset(device->hidden, 0, (sizeof *device->hidden));
+		memset(device->gl_data, 0, (sizeof *device->gl_data));
 
-	/* Set the driver flags */
-	device->handles_any_size = 1;
+		/* Set the driver flags */
+		device->handles_any_size = 1;
 
-	/* Set the function pointers */
-	device->VideoInit = X11_VideoInit;
-	device->ListModes = X11_ListModes;
-	device->SetVideoMode = X11_SetVideoMode;
-	device->ToggleFullScreen = X11_ToggleFullScreen;
-	device->UpdateMouse = X11_UpdateMouse;
+		/* Set the function pointers */
+		device->VideoInit = X11_VideoInit;
+		device->ListModes = X11_ListModes;
+		device->SetVideoMode = X11_SetVideoMode;
+		device->ToggleFullScreen = X11_ToggleFullScreen;
+		device->UpdateMouse = X11_UpdateMouse;
 #ifdef XFREE86_XV
-	device->CreateYUVOverlay = X11_CreateYUVOverlay;
+		device->CreateYUVOverlay = X11_CreateYUVOverlay;
 #endif
-	device->SetColors = X11_SetColors;
-	device->UpdateRects = NULL;
-	device->VideoQuit = X11_VideoQuit;
-	device->AllocHWSurface = X11_AllocHWSurface;
-	device->CheckHWBlit = NULL;
-	device->FillHWRect = NULL;
-	device->SetHWColorKey = NULL;
-	device->SetHWAlpha = NULL;
-	device->LockHWSurface = X11_LockHWSurface;
-	device->UnlockHWSurface = X11_UnlockHWSurface;
-	device->FlipHWSurface = X11_FlipHWSurface;
-	device->FreeHWSurface = X11_FreeHWSurface;
-	device->SetGamma = X11_SetVidModeGamma;
-	device->GetGamma = X11_GetVidModeGamma;
-	device->SetGammaRamp = X11_SetGammaRamp;
-	device->GetGammaRamp = NULL;
+		device->SetColors = X11_SetColors;
+		device->UpdateRects = NULL;
+		device->VideoQuit = X11_VideoQuit;
+		device->AllocHWSurface = X11_AllocHWSurface;
+		device->CheckHWBlit = NULL;
+		device->FillHWRect = NULL;
+		device->SetHWColorKey = NULL;
+		device->SetHWAlpha = NULL;
+		device->LockHWSurface = X11_LockHWSurface;
+		device->UnlockHWSurface = X11_UnlockHWSurface;
+		device->FlipHWSurface = X11_FlipHWSurface;
+		device->FreeHWSurface = X11_FreeHWSurface;
+		device->SetGamma = X11_SetVidModeGamma;
+		device->GetGamma = X11_GetVidModeGamma;
+		device->SetGammaRamp = X11_SetGammaRamp;
+		device->GetGammaRamp = NULL;
 #ifdef HAVE_OPENGL
-	device->GL_LoadLibrary = X11_GL_LoadLibrary;
-	device->GL_GetProcAddress = X11_GL_GetProcAddress;
-	device->GL_GetAttribute = X11_GL_GetAttribute;
-	device->GL_MakeCurrent = X11_GL_MakeCurrent;
-	device->GL_SwapBuffers = X11_GL_SwapBuffers;
+		device->GL_LoadLibrary = X11_GL_LoadLibrary;
+		device->GL_GetProcAddress = X11_GL_GetProcAddress;
+		device->GL_GetAttribute = X11_GL_GetAttribute;
+		device->GL_MakeCurrent = X11_GL_MakeCurrent;
+		device->GL_SwapBuffers = X11_GL_SwapBuffers;
 #endif
-	device->SetCaption = X11_SetCaption;
-	device->SetIcon = X11_SetIcon;
-	device->IconifyWindow = X11_IconifyWindow;
-	device->GrabInput = X11_GrabInput;
-	device->GetWMInfo = X11_GetWMInfo;
-	device->FreeWMCursor = X11_FreeWMCursor;
-	device->CreateWMCursor = X11_CreateWMCursor;
-	device->ShowWMCursor = X11_ShowWMCursor;
-	device->WarpWMCursor = X11_WarpWMCursor;
-	device->CheckMouseMode = X11_CheckMouseMode;
-	device->InitOSKeymap = X11_InitOSKeymap;
-	device->PumpEvents = X11_PumpEvents;
+		device->SetCaption = X11_SetCaption;
+		device->SetIcon = X11_SetIcon;
+		device->IconifyWindow = X11_IconifyWindow;
+		device->GrabInput = X11_GrabInput;
+		device->GetWMInfo = X11_GetWMInfo;
+		device->FreeWMCursor = X11_FreeWMCursor;
+		device->CreateWMCursor = X11_CreateWMCursor;
+		device->ShowWMCursor = X11_ShowWMCursor;
+		device->WarpWMCursor = X11_WarpWMCursor;
+		device->CheckMouseMode = X11_CheckMouseMode;
+		device->InitOSKeymap = X11_InitOSKeymap;
+		device->PumpEvents = X11_PumpEvents;
 
-	device->free = X11_DeleteDevice;
+		device->free = X11_DeleteDevice;
+	}
 
 	return device;
 }
@@ -191,9 +197,6 @@
 	X11_Available, X11_CreateDevice
 };
 
-/* Shared memory information */
-extern int XShmQueryExtension(Display *dpy);	/* Not in X11 headers */
-
 /* Normal X11 error handler routine */
 static int (*X_handler)(Display *, XErrorEvent *) = NULL;
 static int x_errhandler(Display *d, XErrorEvent *e)
@@ -275,21 +278,21 @@
     }
 
     if(FSwindow)
-	XDestroyWindow(SDL_Display, FSwindow);
+	pXDestroyWindow(SDL_Display, FSwindow);
 
     xattr.override_redirect = True;
     xattr.background_pixel = def_vis ? BlackPixel(SDL_Display, SDL_Screen) : 0;
     xattr.border_pixel = 0;
     xattr.colormap = SDL_XColorMap;
 
-    FSwindow = XCreateWindow(SDL_Display, SDL_Root,
+    FSwindow = pXCreateWindow(SDL_Display, SDL_Root,
                              xinerama_x, xinerama_y, 32, 32, 0,
 			     this->hidden->depth, InputOutput, SDL_Visual,
 			     CWOverrideRedirect | CWBackPixel | CWBorderPixel
 			     | CWColormap,
 			     &xattr);
 
-    XSelectInput(SDL_Display, FSwindow, StructureNotifyMask);
+    pXSelectInput(SDL_Display, FSwindow, StructureNotifyMask);
 
     /* Tell KDE to keep the fullscreen window on top */
     {
@@ -299,57 +302,57 @@
 	memset(&ev, 0, sizeof(ev));
 	ev.xclient.type = ClientMessage;
 	ev.xclient.window = SDL_Root;
-	ev.xclient.message_type = XInternAtom(SDL_Display,
+	ev.xclient.message_type = pXInternAtom(SDL_Display,
 					      "KWM_KEEP_ON_TOP", False);
 	ev.xclient.format = 32;
 	ev.xclient.data.l[0] = FSwindow;
 	ev.xclient.data.l[1] = CurrentTime;
 	mask = SubstructureRedirectMask;
-	XSendEvent(SDL_Display, SDL_Root, False, mask, &ev);
+	pXSendEvent(SDL_Display, SDL_Root, False, mask, &ev);
     }
 
     hints = NULL;
     titleprop.value = iconprop.value = NULL;
     if(WMwindow) {
 	/* All window attributes must survive the recreation */
-	hints = XGetWMHints(SDL_Display, WMwindow);
-	XGetWMName(SDL_Display, WMwindow, &titleprop);
-	XGetWMIconName(SDL_Display, WMwindow, &iconprop);
-	XDestroyWindow(SDL_Display, WMwindow);
+	hints = pXGetWMHints(SDL_Display, WMwindow);
+	pXGetWMName(SDL_Display, WMwindow, &titleprop);
+	pXGetWMIconName(SDL_Display, WMwindow, &iconprop);
+	pXDestroyWindow(SDL_Display, WMwindow);
     }
 
     /* Create the window for windowed management */
     /* (reusing the xattr structure above) */
-    WMwindow = XCreateWindow(SDL_Display, SDL_Root, 0, 0, 32, 32, 0,
+    WMwindow = pXCreateWindow(SDL_Display, SDL_Root, 0, 0, 32, 32, 0,
 			     this->hidden->depth, InputOutput, SDL_Visual,
 			     CWBackPixel | CWBorderPixel | CWColormap,
 			     &xattr);
 
     /* Set the input hints so we get keyboard input */
     if(!hints) {
-	hints = XAllocWMHints();
+	hints = pXAllocWMHints();
 	hints->input = True;
 	hints->flags = InputHint;
     }
-    XSetWMHints(SDL_Display, WMwindow, hints);
-    XFree(hints);
+    pXSetWMHints(SDL_Display, WMwindow, hints);
+    pXFree(hints);
     if(titleprop.value) {
-	XSetWMName(SDL_Display, WMwindow, &titleprop);
-	XFree(titleprop.value);
+	pXSetWMName(SDL_Display, WMwindow, &titleprop);
+	pXFree(titleprop.value);
     }
     if(iconprop.value) {
-	XSetWMIconName(SDL_Display, WMwindow, &iconprop);
-	XFree(iconprop.value);
+	pXSetWMIconName(SDL_Display, WMwindow, &iconprop);
+	pXFree(iconprop.value);
     }
 
-    XSelectInput(SDL_Display, WMwindow,
+    pXSelectInput(SDL_Display, WMwindow,
 		 FocusChangeMask | KeyPressMask | KeyReleaseMask
 		 | PropertyChangeMask | StructureNotifyMask | KeymapStateMask);
 
     /* Set the class hints so we can get an icon (AfterStep) */
     {
 	XClassHint *classhints;
-	classhints = XAllocClassHint();
+	classhints = pXAllocClassHint();
 	if(classhints != NULL) {
             char *classname = getenv("SDL_VIDEO_X11_WMCLASS");
             if ( ! classname ) {
@@ -357,14 +360,14 @@
             }
 	    classhints->res_name = classname;
 	    classhints->res_class = classname;
-	    XSetClassHint(SDL_Display, WMwindow, classhints);
-	    XFree(classhints);
+	    pXSetClassHint(SDL_Display, WMwindow, classhints);
+	    pXFree(classhints);
 	}
     }
 
     /* Allow the window to be deleted by the window manager */
-    WM_DELETE_WINDOW = XInternAtom(SDL_Display, "WM_DELETE_WINDOW", False);
-    XSetWMProtocols(SDL_Display, WMwindow, &WM_DELETE_WINDOW, 1);
+    WM_DELETE_WINDOW = pXInternAtom(SDL_Display, "WM_DELETE_WINDOW", False);
+    pXSetWMProtocols(SDL_Display, WMwindow, &WM_DELETE_WINDOW, 1);
 }
 
 static int X11_VideoInit(_THIS, SDL_PixelFormat *vformat)
@@ -375,36 +378,36 @@
 	/* Open the X11 display */
 	display = NULL;		/* Get it from DISPLAY environment variable */
 
-	if ( (strncmp(XDisplayName(display), ":", 1) == 0) ||
-	     (strncmp(XDisplayName(display), "unix:", 5) == 0) ) {
+	if ( (strncmp(pXDisplayName(display), ":", 1) == 0) ||
+	     (strncmp(pXDisplayName(display), "unix:", 5) == 0) ) {
 		local_X11 = 1;
 	} else {
 		local_X11 = 0;
 	}
-	SDL_Display = XOpenDisplay(display);
+	SDL_Display = pXOpenDisplay(display);
 	if ( SDL_Display == NULL ) {
 		SDL_SetError("Couldn't open X11 display");
 		return(-1);
 	}
 #ifdef X11_DEBUG
-	XSynchronize(SDL_Display, True);
+	pXSynchronize(SDL_Display, True);
 #endif
 
 	/* Create an alternate X display for graphics updates -- allows us
 	   to do graphics updates in a separate thread from event handling.
 	   Thread-safe X11 doesn't seem to exist.
 	 */
-	GFX_Display = XOpenDisplay(display);
+	GFX_Display = pXOpenDisplay(display);
 	if ( GFX_Display == NULL ) {
 		SDL_SetError("Couldn't open X11 display");
 		return(-1);
 	}
 
 	/* Set the normal X error handler */
-	X_handler = XSetErrorHandler(x_errhandler);
+	X_handler = pXSetErrorHandler(x_errhandler);
 
 	/* Set the error handler if we lose the X display */
-	XIO_handler = XSetIOErrorHandler(xio_errhandler);
+	XIO_handler = pXSetIOErrorHandler(xio_errhandler);
 
 	/* use default screen (from $DISPLAY) */
 	SDL_Screen = DefaultScreen(SDL_Display);
@@ -413,7 +416,7 @@
 	/* Check for MIT shared memory extension */
 	use_mitshm = 0;
 	if ( local_X11 ) {
-		use_mitshm = XShmQueryExtension(SDL_Display);
+		use_mitshm = pXShmQueryExtension(SDL_Display);
 	}
 #endif /* NO_SHARED_MEMORY */
 
@@ -436,7 +439,7 @@
 	if ( SDL_Visual == DefaultVisual(SDL_Display, SDL_Screen) ) {
 	    SDL_XColorMap = SDL_DisplayColormap;
 	} else {
-	    SDL_XColorMap = XCreateColormap(SDL_Display, SDL_Root,
+	    SDL_XColorMap = pXCreateColormap(SDL_Display, SDL_Root,
 					    SDL_Visual, AllocNone);
 	}
 	this->hidden->depth = this->hidden->visuals[i].depth;
@@ -463,7 +466,7 @@
 	this->info.wm_available = 1;
 
 	/* We're done! */
-	XFlush(SDL_Display);
+	pXFlush(SDL_Display);
 	return(0);
 }
 
@@ -478,7 +481,7 @@
 	if ( ! SDL_windowid ) {
 		/* Hide the managed window */
 		if ( WMwindow ) {
-			XUnmapWindow(SDL_Display, WMwindow);
+			pXUnmapWindow(SDL_Display, WMwindow);
 		}
 		if ( screen && (screen->flags & SDL_FULLSCREEN) ) {
 			screen->flags &= ~SDL_FULLSCREEN;
@@ -487,7 +490,7 @@
 
 		/* Destroy the output window */
 		if ( SDL_Window ) {
-			XDestroyWindow(SDL_Display, SDL_Window);
+			pXDestroyWindow(SDL_Display, SDL_Window);
 		}
 
 		/* Free the colormap entries */
@@ -497,7 +500,7 @@
 			numcolors = SDL_Visual->map_entries;
 			for ( pixel=0; pixel<numcolors; ++pixel ) {
 				while ( SDL_XPixels[pixel] > 0 ) {
-					XFreeColors(GFX_Display,
+					pXFreeColors(GFX_Display,
 						SDL_DisplayColormap,&pixel,1,0);
 					--SDL_XPixels[pixel];
 				}
@@ -508,7 +511,7 @@
 
 		/* Free the graphics context */
 		if ( SDL_GC ) {
-			XFreeGC(SDL_Display, SDL_GC);
+			pXFreeGC(SDL_Display, SDL_GC);
 			SDL_GC = 0;
 		}
 	}
@@ -538,7 +541,7 @@
 {
 	XSizeHints *hints;
 
-	hints = XAllocSizeHints();
+	hints = pXAllocSizeHints();
 	if ( hints ) {
 		if ( flags & SDL_RESIZABLE ) {
 			hints->min_width = 32;
@@ -558,13 +561,13 @@
 		/* Center it, if desired */
 		if ( X11_WindowPosition(this, &hints->x, &hints->y, w, h) ) {
 			hints->flags |= USPosition;
-			XMoveWindow(SDL_Display, WMwindow, hints->x, hints->y);
+			pXMoveWindow(SDL_Display, WMwindow, hints->x, hints->y);
 
 			/* Flush the resize event so we don't catch it later */
-			XSync(SDL_Display, True);
+			pXSync(SDL_Display, True);
 		}
-		XSetWMNormalHints(SDL_Display, WMwindow, hints);
-		XFree(hints);
+		pXSetWMNormalHints(SDL_Display, WMwindow, hints);
+		pXFree(hints);
 	}
 
 	/* Respect the window caption style */
@@ -576,7 +579,7 @@
 		set = SDL_FALSE;
 
 		/* First try to set MWM hints */
-		WM_HINTS = XInternAtom(SDL_Display, "_MOTIF_WM_HINTS", True);
+		WM_HINTS = pXInternAtom(SDL_Display, "_MOTIF_WM_HINTS", True);
 		if ( WM_HINTS != None ) {
 			/* Hints used by Motif compliant window managers */
 			struct {
@@ -587,7 +590,7 @@
 				unsigned long status;
 			} MWMHints = { (1L << 1), 0, 0, 0, 0 };
 
-			XChangeProperty(SDL_Display, WMwindow,
+			pXChangeProperty(SDL_Display, WMwindow,
 			                WM_HINTS, WM_HINTS, 32,
 			                PropModeReplace,
 					(unsigned char *)&MWMHints,
@@ -595,11 +598,11 @@
 			set = SDL_TRUE;
 		}
 		/* Now try to set KWM hints */
-		WM_HINTS = XInternAtom(SDL_Display, "KWM_WIN_DECORATION", True);
+		WM_HINTS = pXInternAtom(SDL_Display, "KWM_WIN_DECORATION", True);
 		if ( WM_HINTS != None ) {
 			long KWMHints = 0;
 
-			XChangeProperty(SDL_Display, WMwindow,
+			pXChangeProperty(SDL_Display, WMwindow,
 			                WM_HINTS, WM_HINTS, 32,
 			                PropModeReplace,
 					(unsigned char *)&KWMHints,
@@ -607,11 +610,11 @@
 			set = SDL_TRUE;
 		}
 		/* Now try to set GNOME hints */
-		WM_HINTS = XInternAtom(SDL_Display, "_WIN_HINTS", True);
+		WM_HINTS = pXInternAtom(SDL_Display, "_WIN_HINTS", True);
 		if ( WM_HINTS != None ) {
 			long GNOMEHints = 0;
 
-			XChangeProperty(SDL_Display, WMwindow,
+			pXChangeProperty(SDL_Display, WMwindow,
 			                WM_HINTS, WM_HINTS, 32,
 			                PropModeReplace,
 					(unsigned char *)&GNOMEHints,
@@ -620,7 +623,7 @@
 		}
 		/* Finally set the transient hints if necessary */
 		if ( ! set ) {
-			XSetTransientForHint(SDL_Display, WMwindow, SDL_Root);
+			pXSetTransientForHint(SDL_Display, WMwindow, SDL_Root);
 		}
 	} else {
 		SDL_bool set;
@@ -630,27 +633,27 @@
 		set = SDL_FALSE;
 
 		/* First try to unset MWM hints */
-		WM_HINTS = XInternAtom(SDL_Display, "_MOTIF_WM_HINTS", True);
+		WM_HINTS = pXInternAtom(SDL_Display, "_MOTIF_WM_HINTS", True);
 		if ( WM_HINTS != None ) {
-			XDeleteProperty(SDL_Display, WMwindow, WM_HINTS);
+			pXDeleteProperty(SDL_Display, WMwindow, WM_HINTS);
 			set = SDL_TRUE;
 		}
 		/* Now try to unset KWM hints */
-		WM_HINTS = XInternAtom(SDL_Display, "KWM_WIN_DECORATION", True);
+		WM_HINTS = pXInternAtom(SDL_Display, "KWM_WIN_DECORATION", True);
 		if ( WM_HINTS != None ) {
-			XDeleteProperty(SDL_Display, WMwindow, WM_HINTS);
+			pXDeleteProperty(SDL_Display, WMwindow, WM_HINTS);
 			set = SDL_TRUE;
 		}
 		/* Now try to unset GNOME hints */
-		WM_HINTS = XInternAtom(SDL_Display, "_WIN_HINTS", True);
+		WM_HINTS = pXInternAtom(SDL_Display, "_WIN_HINTS", True);
 		if ( WM_HINTS != None ) {
-			XDeleteProperty(SDL_Display, WMwindow, WM_HINTS);
+			pXDeleteProperty(SDL_Display, WMwindow, WM_HINTS);
 			set = SDL_TRUE;
 		}
 		/* Finally unset the transient hints if necessary */
 		if ( ! set ) {
 			/* NOTE: Does this work? */
-			XSetTransientForHint(SDL_Display, WMwindow, None);
+			pXSetTransientForHint(SDL_Display, WMwindow, None);
 		}
 	}
 }
@@ -688,7 +691,7 @@
 	} else if ( SDL_windowid ) {
 		XWindowAttributes a;
 
-		XGetWindowAttributes(SDL_Display, SDL_Window, &a);
+		pXGetWindowAttributes(SDL_Display, SDL_Window, &a);
 		vis = a.visual;
 		depth = a.depth;
 	} else {
@@ -717,7 +720,7 @@
 
 	/* Create the appropriate colormap */
 	if ( SDL_XColorMap != SDL_DisplayColormap ) {
-		XFreeColormap(SDL_Display, SDL_XColorMap);
+		pXFreeColormap(SDL_Display, SDL_XColorMap);
 	}
 	if ( SDL_Visual->class == PseudoColor ) {
 	    int ncolors;
@@ -737,7 +740,7 @@
 	    }
 	    if ( flags & SDL_HWPALETTE ) {
 		screen->flags |= SDL_HWPALETTE;
-		SDL_XColorMap = XCreateColormap(SDL_Display, SDL_Root,
+		SDL_XColorMap = pXCreateColormap(SDL_Display, SDL_Root,
 		                                SDL_Visual, AllocAll);
 	    } else {
 		SDL_XColorMap = SDL_DisplayColormap;
@@ -745,9 +748,9 @@
 	} else if ( SDL_Visual->class == DirectColor ) {
 
 	    /* Create a colormap which we can manipulate for gamma */
-	    SDL_XColorMap = XCreateColormap(SDL_Display, SDL_Root,
+	    SDL_XColorMap = pXCreateColormap(SDL_Display, SDL_Root,
 		                            SDL_Visual, AllocAll);
-            XSync(SDL_Display, False);
+            pXSync(SDL_Display, False);
 
 	    /* Initialize the colormap to the identity mapping */
 	    SDL_GetGammaRamp(0, 0, 0);
@@ -756,7 +759,7 @@
 	    this->screen = NULL;
 	} else {
 	    /* Create a read-only colormap for our window */
-	    SDL_XColorMap = XCreateColormap(SDL_Display, SDL_Root,
+	    SDL_XColorMap = pXCreateColormap(SDL_Display, SDL_Root,
 	                                    SDL_Visual, AllocNone);
 	}
 
@@ -769,8 +772,8 @@
 	       colour (0 is white on some displays), we should reset the
 	       background to 0 here since that is what the user expects
 	       with a private colormap */
-	    XSetWindowBackground(SDL_Display, FSwindow, 0);
-	    XClearWindow(SDL_Display, FSwindow);
+	    pXSetWindowBackground(SDL_Display, FSwindow, 0);
+	    pXClearWindow(SDL_Display, FSwindow);
 	}
 
 	/* resize the (possibly new) window manager window */
@@ -778,7 +781,7 @@
 	        X11_SetSizeHints(this, w, h, flags);
 		current_w = w;
 		current_h = h;
-		XResizeWindow(SDL_Display, WMwindow, w, h);
+		pXResizeWindow(SDL_Display, WMwindow, w, h);
 	}
 
 	/* Create (or use) the X11 display window */
@@ -793,14 +796,14 @@
 			swa.background_pixel = 0;
 			swa.border_pixel = 0;
 			swa.colormap = SDL_XColorMap;
-			SDL_Window = XCreateWindow(SDL_Display, WMwindow,
+			SDL_Window = pXCreateWindow(SDL_Display, WMwindow,
 		                           	0, 0, w, h, 0, depth,
 		                           	InputOutput, SDL_Visual,
 		                           	CWBackPixel | CWBorderPixel
 		                           	| CWColormap, &swa);
 		}
 		/* Only manage our input if we own the window */
-		XSelectInput(SDL_Display, SDL_Window,
+		pXSelectInput(SDL_Display, SDL_Window,
 					( EnterWindowMask | LeaveWindowMask
 					| ButtonPressMask | ButtonReleaseMask
 					| PointerMotionMask | ExposureMask ));
@@ -817,7 +820,7 @@
 		XGCValues gcv;
 
 		gcv.graphics_exposures = False;
-		SDL_GC = XCreateGC(SDL_Display, SDL_Window,
+		SDL_GC = pXCreateGC(SDL_Display, SDL_Window,
 		                   GCGraphicsExposures, &gcv);
 		if ( ! SDL_GC ) {
 			SDL_SetError("Couldn't create graphics context");
@@ -827,10 +830,10 @@
 
 	/* Set our colormaps when not setting a GL mode */
 	if ( ! (flags & SDL_OPENGL) ) {
-		XSetWindowColormap(SDL_Display, SDL_Window, SDL_XColorMap);
+		pXSetWindowColormap(SDL_Display, SDL_Window, SDL_XColorMap);
 		if( !SDL_windowid ) {
-		    XSetWindowColormap(SDL_Display, FSwindow, SDL_XColorMap);
-		    XSetWindowColormap(SDL_Display, WMwindow, SDL_XColorMap);
+		    pXSetWindowColormap(SDL_Display, FSwindow, SDL_XColorMap);
+		    pXSetWindowColormap(SDL_Display, WMwindow, SDL_XColorMap);
 		}
 	}
 
@@ -845,7 +848,7 @@
 		xscreen = ScreenOfDisplay(SDL_Display, SDL_Screen);
 		a.backing_store = DoesBackingStore(xscreen);
 		if ( a.backing_store != NotUseful ) {
-			XChangeWindowAttributes(SDL_Display, SDL_Window,
+			pXChangeWindowAttributes(SDL_Display, SDL_Window,
 			                        CWBackingStore, &a);
 		}
 	}
@@ -879,8 +882,8 @@
 
 	/* Map them both and go fullscreen, if requested */
 	if ( ! SDL_windowid ) {
-		XMapWindow(SDL_Display, SDL_Window);
-		XMapWindow(SDL_Display, WMwindow);
+		pXMapWindow(SDL_Display, SDL_Window);
+		pXMapWindow(SDL_Display, WMwindow);
 		X11_WaitMapped(this, WMwindow);
 		if ( flags & SDL_FULLSCREEN ) {
 			screen->flags |= SDL_FULLSCREEN;
@@ -900,7 +903,7 @@
 		X11_SetSizeHints(this, w, h, flags);
 		current_w = w;
 		current_h = h;
-		XResizeWindow(SDL_Display, WMwindow, w, h);
+		pXResizeWindow(SDL_Display, WMwindow, w, h);
 
 		/* Resize the fullscreen and display windows */
 		if ( flags & SDL_FULLSCREEN ) {
@@ -916,7 +919,7 @@
 				X11_LeaveFullScreen(this);
 			}
 		}
-		XResizeWindow(SDL_Display, SDL_Window, w, h);
+		pXResizeWindow(SDL_Display, SDL_Window, w, h);
 	}
 	return(0);
 }
@@ -938,7 +941,7 @@
 	}
 
 	/* Flush any delayed updates */
-	XSync(GFX_Display, False);
+	pXSync(GFX_Display, False);
 
 	/* Set up the X11 window */
 	saved_flags = current->flags;
@@ -968,7 +971,7 @@
 
   done:
 	/* Release the event thread */
-	XSync(SDL_Display, False);
+	pXSync(SDL_Display, False);
 	SDL_Unlock_EventThread();
 
 	/* We're done! */
@@ -1017,7 +1020,7 @@
 
 	/* Lock the event thread, in multi-threading environments */
 	SDL_Lock_EventThread();
-	if ( XQueryPointer(SDL_Display, SDL_Window, &u1, &current_win,
+	if ( pXQueryPointer(SDL_Display, SDL_Window, &u1, &current_win,
 	                   &u2, &u2, &x, &y, &mask) ) {
 		if ( (x >= 0) && (x < SDL_VideoSurface->w) &&
 		     (y >= 0) && (y < SDL_VideoSurface->h) ) {
@@ -1054,7 +1057,7 @@
 	 * XQueryColors sets the flags in the XColor struct, so we use
 	 * that to keep track of which colours are available
 	 */
-	XQueryColors(GFX_Display, SDL_XColorMap, all, 256);
+	pXQueryColors(GFX_Display, SDL_XColorMap, all, 256);
 
 	for(i = 0; i < nwant; i++) {
 		XColor *c;
@@ -1080,7 +1083,7 @@
 		if(SDL_XPixels[best])
 			continue; /* already allocated, waste no more time */
 		c = all + best;
-		if(XAllocColor(GFX_Display, SDL_XColorMap, c)) {
+		if(pXAllocColor(GFX_Display, SDL_XColorMap, c)) {
 			/* got it */
 			colors[c->pixel].r = c->red >> 8;
 			colors[c->pixel].g = c->green >> 8;
@@ -1122,8 +1125,8 @@
 			xcmap[i].blue  = (colors[i].b<<8)|colors[i].b;
 			xcmap[i].flags = (DoRed|DoGreen|DoBlue);
 		}
-		XStoreColors(GFX_Display, SDL_XColorMap, xcmap, ncolors);
-		XSync(GFX_Display, False);
+		pXStoreColors(GFX_Display, SDL_XColorMap, xcmap, ncolors);
+		pXSync(GFX_Display, False);
 		FREEA(xcmap);
 	} else {
 	        /*
@@ -1151,7 +1154,7 @@
 				--SDL_XPixels[pixel];
 			}
 		}
-		XFreeColors(GFX_Display, SDL_XColorMap, freelist, nfree, 0);
+		pXFreeColors(GFX_Display, SDL_XColorMap, freelist, nfree, 0);
 		FREEA(freelist);
 
 		want = ALLOCA(ncolors * sizeof(SDL_Color));
@@ -1168,7 +1171,7 @@
 			col.green = want[i].g << 8;
 			col.blue = want[i].b << 8;
 			col.flags = DoRed | DoGreen | DoBlue;
-			if(XAllocColor(GFX_Display, SDL_XColorMap, &col)) {
+			if(pXAllocColor(GFX_Display, SDL_XColorMap, &col)) {
 			        /* We got the colour, or at least the nearest
 				   the hardware could get. */
 			        colors[col.pixel].r = col.red >> 8;
@@ -1212,8 +1215,8 @@
 		xcmap[i].blue  = ramp[2*256+c];
 		xcmap[i].flags = (DoRed|DoGreen|DoBlue);
 	}
-	XStoreColors(GFX_Display, SDL_XColorMap, xcmap, ncolors);
-	XSync(GFX_Display, False);
+	pXStoreColors(GFX_Display, SDL_XColorMap, xcmap, ncolors);
+	pXSync(GFX_Display, False);
 	return(0);
 }
 
@@ -1226,14 +1229,14 @@
 	/* The event thread should be done, so we can touch SDL_Display */
 	if ( SDL_Display != NULL ) {
 		/* Flush any delayed updates */
-		XSync(GFX_Display, False);
+		pXSync(GFX_Display, False);
 
 		/* Start shutting down the windows */
 		X11_DestroyImage(this, this->screen);
 		X11_DestroyWindow(this, this->screen);
 		X11_FreeVideoModes(this);
 		if ( SDL_XColorMap != SDL_DisplayColormap ) {
-			XFreeColormap(SDL_Display, SDL_XColorMap);
+			pXFreeColormap(SDL_Display, SDL_XColorMap);
 		}
 		if ( SDL_iconcolors ) {
 			unsigned long pixel;
@@ -1241,7 +1244,7 @@
 							 SDL_Screen);
 			for(pixel = 0; pixel < 256; ++pixel) {
 				while(SDL_iconcolors[pixel] > 0) {
-					XFreeColors(GFX_Display,
+					pXFreeColors(GFX_Display,
 						    dcmap, &pixel, 1, 0);
 					--SDL_iconcolors[pixel];
 				}
@@ -1262,20 +1265,20 @@
 
 		/* Close the X11 graphics connection */
 		if ( GFX_Display != NULL ) {
-			XCloseDisplay(GFX_Display);
+			pXCloseDisplay(GFX_Display);
 			GFX_Display = NULL;
 		}
 
 		/* Close the X11 display connection */
-		XCloseDisplay(SDL_Display);
+		pXCloseDisplay(SDL_Display);
 		SDL_Display = NULL;
 
 		/* Reset the X11 error handlers */
 		if ( XIO_handler ) {
-			XSetIOErrorHandler(XIO_handler);
+			pXSetIOErrorHandler(XIO_handler);
 		}
 		if ( X_handler ) {
-			XSetErrorHandler(X_handler);
+			pXSetErrorHandler(X_handler);
 		}
 
 		/* Unload GL library after X11 shuts down */
--- a/src/video/x11/SDL_x11video.h	Sat Nov 05 17:41:11 2005 +0000
+++ b/src/video/x11/SDL_x11video.h	Sat Nov 05 19:53:37 2005 +0000
@@ -31,11 +31,7 @@
 #include <X11/Xlib.h>
 #include <X11/Xutil.h>
 #include <X11/Xatom.h>
-#ifndef NO_SHARED_MEMORY
-#include <sys/ipc.h>
-#include <sys/shm.h>
-#include <X11/extensions/XShm.h>
-#endif
+
 #ifdef XFREE86_DGAMOUSE
 #include <XFree86/extensions/xf86dga.h>
 #endif
@@ -50,6 +46,7 @@
 
 #include "SDL_mouse.h"
 #include "SDL_sysvideo.h"
+#include "SDL_x11dyn.h"
 
 /* Hidden "this" pointer for the video functions */
 #define _THIS	SDL_VideoDevice *this
--- a/src/video/x11/SDL_x11wm.c	Sat Nov 05 17:41:11 2005 +0000
+++ b/src/video/x11/SDL_x11wm.c	Sat Nov 05 19:53:37 2005 +0000
@@ -123,7 +123,7 @@
 					SDL_iconcolors[i]--;
 				}
 			}
-			XFreeColors(GFX_Display, dcmap, freelist, nfree, 0);
+			pXFreeColors(GFX_Display, dcmap, freelist, nfree, 0);
 		}
 		if(!SDL_iconcolors)
 			SDL_iconcolors = malloc(256 * sizeof *SDL_iconcolors);
@@ -138,7 +138,7 @@
 			c.green = want[i].g << 8;
 			c.blue = want[i].b << 8;
 			c.flags = DoRed | DoGreen | DoBlue;
-			if(XAllocColor(GFX_Display, dcmap, &c)) {
+			if(pXAllocColor(GFX_Display, dcmap, &c)) {
 				/* got the colour */
 				SDL_iconcolors[c.pixel]++;
 				got[c.pixel] = want[i];
@@ -152,13 +152,13 @@
 			XColor cols[256];
 			for(i = 0; i < 256; i++)
 				cols[i].pixel = i;
-			XQueryColors(GFX_Display, dcmap, cols, 256);
+			pXQueryColors(GFX_Display, dcmap, cols, 256);
 			for(i = 0; i < 256; i++) {
 				got[i].r = cols[i].red >> 8;
 				got[i].g = cols[i].green >> 8;
 				got[i].b = cols[i].blue >> 8;
 				if(!SDL_iconcolors[i]) {
-					if(XAllocColor(GFX_Display, dcmap,
+					if(pXAllocColor(GFX_Display, dcmap,
 							cols + i)) {
 						SDL_iconcolors[i] = 1;
 					} else {
@@ -191,13 +191,13 @@
 	memset(LSBmask, 0, masksize);
 	for(i = 0; i < masksize; i++)
 		LSBmask[i] = reverse_byte(mask[i]);
-	mask_pixmap = XCreatePixmapFromBitmapData(SDL_Display, WMwindow,
+	mask_pixmap = pXCreatePixmapFromBitmapData(SDL_Display, WMwindow,
 						  (char *)LSBmask,
 						  sicon->w, sicon->h,
 						  1L, 0L, 1);
 
 	/* Transfer the image to an X11 pixmap */
-	icon_image = XCreateImage(SDL_Display,
+	icon_image = pXCreateImage(SDL_Display,
 				  DefaultVisual(SDL_Display, SDL_Screen),
 				  DefaultDepth(SDL_Display, SDL_Screen),
 				  ZPixmap, 0, sicon->pixels,
@@ -205,13 +205,13 @@
 				  32, 0);
 	icon_image->byte_order = (SDL_BYTEORDER == SDL_BIG_ENDIAN)
 		                 ? MSBFirst : LSBFirst;
-	icon_pixmap = XCreatePixmap(SDL_Display, SDL_Root, sicon->w, sicon->h,
+	icon_pixmap = pXCreatePixmap(SDL_Display, SDL_Root, sicon->w, sicon->h,
 				    DefaultDepth(SDL_Display, SDL_Screen));
-	gc = XCreateGC(SDL_Display, icon_pixmap, 0, &GCvalues);
-	XPutImage(SDL_Display, icon_pixmap, gc, icon_image,
+	gc = pXCreateGC(SDL_Display, icon_pixmap, 0, &GCvalues);
+	pXPutImage(SDL_Display, icon_pixmap, gc, icon_image,
 		  0, 0, 0, 0, sicon->w, sicon->h);
-	XFreeGC(SDL_Display, gc);
-	XDestroyImage(icon_image);
+	pXFreeGC(SDL_Display, gc);
+	pXDestroyImage(icon_image);
 	free(LSBmask);
 	sicon->pixels = NULL;
 
@@ -220,17 +220,17 @@
 	   it screws up others. The default is only to use a pixmap. */
 	p = getenv("SDL_VIDEO_X11_ICONWIN");
 	if(p && *p) {
-		icon_window = XCreateSimpleWindow(SDL_Display, SDL_Root,
+		icon_window = pXCreateSimpleWindow(SDL_Display, SDL_Root,
 						  0, 0, sicon->w, sicon->h, 0,
 						  CopyFromParent,
 						  CopyFromParent);
-		XSetWindowBackgroundPixmap(SDL_Display, icon_window,
+		pXSetWindowBackgroundPixmap(SDL_Display, icon_window,
 					   icon_pixmap);
-		XClearWindow(SDL_Display, icon_window);
+		pXClearWindow(SDL_Display, icon_window);
 	}
 
 	/* Set the window icon to the icon pixmap (and icon window) */
-	wmhints = XAllocWMHints();
+	wmhints = pXAllocWMHints();
 	wmhints->flags = (IconPixmapHint | IconMaskHint);
 	wmhints->icon_pixmap = icon_pixmap;
 	wmhints->icon_mask = mask_pixmap;
@@ -238,9 +238,9 @@
 		wmhints->flags |= IconWindowHint;
 		wmhints->icon_window = icon_window;
 	}
-	XSetWMHints(SDL_Display, WMwindow, wmhints);
-	XFree(wmhints);
-	XSync(SDL_Display, False);
+	pXSetWMHints(SDL_Display, WMwindow, wmhints);
+	pXFree(wmhints);
+	pXSync(SDL_Display, False);
 
   done:
 	SDL_Unlock_EventThread();
@@ -257,30 +257,30 @@
 	if ( title != NULL ) {
 		int error = XLocaleNotSupported;
 #ifdef X_HAVE_UTF8_STRING
-		error = Xutf8TextListToTextProperty(SDL_Display,
+		error = pXutf8TextListToTextProperty(SDL_Display,
 				(char **)&title, 1, XUTF8StringStyle,
 				&titleprop);
 #endif
 		if ( error != Success ) {
-			XStringListToTextProperty((char **)&title, 1,
+			pXStringListToTextProperty((char **)&title, 1,
 					&titleprop);
 		}
-		XSetWMName(SDL_Display, WMwindow, &titleprop);
-		XFree(titleprop.value);
+		pXSetWMName(SDL_Display, WMwindow, &titleprop);
+		pXFree(titleprop.value);
 	}
 	if ( icon != NULL ) {
 		int error = XLocaleNotSupported;
 #ifdef X_HAVE_UTF8_STRING
-		error = Xutf8TextListToTextProperty(SDL_Display,
+		error = pXutf8TextListToTextProperty(SDL_Display,
 				(char **)&icon, 1, XUTF8StringStyle, &iconprop);
 #endif
 		if ( error != Success ) {
-			XStringListToTextProperty((char **)&icon, 1, &iconprop);
+			pXStringListToTextProperty((char **)&icon, 1, &iconprop);
 		}
-		XSetWMIconName(SDL_Display, WMwindow, &iconprop);
-		XFree(iconprop.value);
+		pXSetWMIconName(SDL_Display, WMwindow, &iconprop);
+		pXFree(iconprop.value);
 	}
-	XSync(SDL_Display, False);
+	pXSync(SDL_Display, False);
 
 	SDL_Unlock_EventThread();
 }
@@ -291,8 +291,8 @@
 	int result;
 
 	SDL_Lock_EventThread();
-	result = XIconifyWindow(SDL_Display, WMwindow, SDL_Screen);
-	XSync(SDL_Display, False);
+	result = pXIconifyWindow(SDL_Display, WMwindow, SDL_Screen);
+	pXSync(SDL_Display, False);
 	SDL_Unlock_EventThread();
 	return(result);
 }
@@ -308,12 +308,12 @@
 		return(mode);	/* Will be set later on mode switch */
 	}
 	if ( mode == SDL_GRAB_OFF ) {
-		XUngrabPointer(SDL_Display, CurrentTime);
-		XUngrabKeyboard(SDL_Display, CurrentTime);
+		pXUngrabPointer(SDL_Display, CurrentTime);
+		pXUngrabKeyboard(SDL_Display, CurrentTime);
 	} else {
 		if ( this->screen->flags & SDL_FULLSCREEN ) {
 			/* Unbind the mouse from the fullscreen window */
-			XUngrabPointer(SDL_Display, CurrentTime);
+			pXUngrabPointer(SDL_Display, CurrentTime);
 		}
 		/* Try to grab the mouse */
 #if 0 /* We'll wait here until we actually grab, otherwise behavior undefined */
@@ -321,7 +321,7 @@
 #else
 		while ( 1 ) {
 #endif
-			result = XGrabPointer(SDL_Display, SDL_Window, True, 0,
+			result = pXGrabPointer(SDL_Display, SDL_Window, True, 0,
 						GrabModeAsync, GrabModeAsync,
 						SDL_Window, None, CurrentTime);
 			if ( result == GrabSuccess ) {
@@ -333,17 +333,17 @@
 			/* Uh, oh, what do we do here? */ ;
 		}
 		/* Now grab the keyboard */
-		XGrabKeyboard(SDL_Display, WMwindow, True,
+		pXGrabKeyboard(SDL_Display, WMwindow, True,
 				GrabModeAsync, GrabModeAsync, CurrentTime);
 
 		/* Raise the window if we grab the mouse */
 		if ( !(this->screen->flags & SDL_FULLSCREEN) )
-			XRaiseWindow(SDL_Display, WMwindow);
+			pXRaiseWindow(SDL_Display, WMwindow);
 
 		/* Make sure we register input focus */
 		SDL_PrivateAppActive(1, SDL_APPINPUTFOCUS);
 	}
-	XSync(SDL_Display, False);
+	pXSync(SDL_Display, False);
 
 	return(mode);
 }
@@ -368,7 +368,7 @@
 {
 	/* Make sure any X11 transactions are completed */
 	SDL_VideoDevice *this = current_video;
-	XSync(SDL_Display, False);
+	pXSync(SDL_Display, False);
 	SDL_Unlock_EventThread();
 }
 int X11_GetWMInfo(_THIS, SDL_SysWMinfo *info)
--- a/src/video/x11/SDL_x11yuv.c	Sat Nov 05 17:41:11 2005 +0000
+++ b/src/video/x11/SDL_x11yuv.c	Sat Nov 05 19:53:37 2005 +0000
@@ -159,7 +159,7 @@
 					}
 				}
 				if ( formats ) {
-					XFree(formats);
+					pXFree(formats);
 				}
 			}
 		}
@@ -208,21 +208,21 @@
 		unsigned int i;
 
 		SDL_NAME(XvSelectPortNotify)(GFX_Display, xv_port, True);
-		X_handler = XSetErrorHandler(xv_errhandler);
+		X_handler = pXSetErrorHandler(xv_errhandler);
 		for ( i=0; i < sizeof(attr)/(sizeof attr[0]); ++i ) {
 			Atom a;
 
 			xv_error = False;
-			a = XInternAtom(GFX_Display, attr[i], True);
+			a = pXInternAtom(GFX_Display, attr[i], True);
 			if ( a != None ) {
      				SDL_NAME(XvSetPortAttribute)(GFX_Display, xv_port, a, 1);
-				XSync(GFX_Display, True);
+				pXSync(GFX_Display, True);
 				if ( ! xv_error ) {
 					break;
 				}
 			}
 		}
-		XSetErrorHandler(X_handler);
+		pXSetErrorHandler(X_handler);
 		SDL_NAME(XvSelectPortNotify)(GFX_Display, xv_port, False);
 	}
 
@@ -262,7 +262,7 @@
 #ifdef PITCH_WORKAROUND
 	if ( hwdata->image != NULL && hwdata->image->pitches[0] != (width*bpp) ) {
 		/* Ajust overlay width according to pitch */ 
-		XFree(hwdata->image);
+		pXFree(hwdata->image);
 		width = hwdata->image->pitches[0] / bpp;
 		hwdata->image = SDL_NAME(XvShmCreateImage)(GFX_Display, xv_port, format,
 							   0, width, height, yuvshm);
@@ -277,10 +277,10 @@
 			yuvshm->readOnly = False;
 			if ( yuvshm->shmaddr != (char *)-1 ) {
 				shm_error = False;
-				X_handler = XSetErrorHandler(shm_errhandler);
-				XShmAttach(GFX_Display, yuvshm);
-				XSync(GFX_Display, True);
-				XSetErrorHandler(X_handler);
+				X_handler = pXSetErrorHandler(shm_errhandler);
+				pXShmAttach(GFX_Display, yuvshm);
+				pXSync(GFX_Display, True);
+				pXSetErrorHandler(X_handler);
 				if ( shm_error )
 					shmdt(yuvshm->shmaddr);
 			} else {
@@ -291,7 +291,7 @@
 			shm_error = True;
 		}
 		if ( shm_error ) {
-			XFree(hwdata->image);
+			pXFree(hwdata->image);
 			hwdata->yuv_use_mitshm = 0;
 		} else {
 			hwdata->image->data = yuvshm->shmaddr;
@@ -306,7 +306,7 @@
 #ifdef PITCH_WORKAROUND
 		if ( hwdata->image != NULL && hwdata->image->pitches[0] != (width*bpp) ) {
 			/* Ajust overlay width according to pitch */ 
-			XFree(hwdata->image);
+			pXFree(hwdata->image);
 			width = hwdata->image->pitches[0] / bpp;
 			hwdata->image = SDL_NAME(XvCreateImage)(GFX_Display, xv_port, format,
 								0, width, height);
@@ -380,7 +380,7 @@
 				     hwdata->image, 0, 0, overlay->w, overlay->h,
 				     dstrect->x, dstrect->y, dstrect->w, dstrect->h);
 	}
-	XSync(GFX_Display, False);
+	pXSync(GFX_Display, False);
 	return(0);
 }
 
@@ -393,12 +393,12 @@
 		SDL_NAME(XvUngrabPort)(GFX_Display, hwdata->port, CurrentTime);
 #ifndef NO_SHARED_MEMORY
 		if ( hwdata->yuv_use_mitshm ) {
-			XShmDetach(GFX_Display, &hwdata->yuvshm);
+			pXShmDetach(GFX_Display, &hwdata->yuvshm);
 			shmdt(hwdata->yuvshm.shmaddr);
 		}
 #endif
 		if ( hwdata->image ) {
-			XFree(hwdata->image);
+			pXFree(hwdata->image);
 		}
 		free(hwdata);
 	}