From a8366ab97d969a5b2e295f21eda90ce890fd4a5a Mon Sep 17 00:00:00 2001
From: "Ryan C. Gordon" <icculus@icculus.org>
Date: Mon, 30 Jan 2006 18:21:44 +0000
Subject: [PATCH] Corrects dynamic X11 code on Tru64 systems.

Fixes Bugzilla #87.

--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%401302
---
 configure.in                 | 11 +++++++++++
 src/video/x11/SDL_x11dyn.h   | 13 ++++++++++++-
 src/video/x11/SDL_x11sym.h   |  9 ++++++++-
 src/video/x11/SDL_x11video.c | 14 ++++++++++++++
 4 files changed, 45 insertions(+), 2 deletions(-)

diff --git a/configure.in b/configure.in
index 53a549a4..06bf21b2 100644
--- a/configure.in
+++ b/configure.in
@@ -619,6 +619,10 @@ CheckX11()
                     x11_lib='/usr/X11R6/lib/libX11.6.dylib'
                     x11ext_lib='/usr/X11R6/lib/libXext.6.dylib'
                     ;;
+                *-*-osf* )
+                    x11_lib='libX11.so'
+                    x11ext_lib='libXext.so'
+                    ;;
                 *)
                     x11_lib='libX11.so.6'
                     x11ext_lib='libXext.so.6'
@@ -2585,6 +2589,13 @@ case "$target" in
         if test x$enable_timers = xyes; then
             COPY_ARCH_SRC(src/timer, linux, SDL_systimer.c)
         fi
+        # FIXME: If building without -lX11, you get the following messages.
+        # Xlib: connection to ":0.0" refused by server
+        # Xlib: XDM authorization key matches an existing client!
+        # It only has to run xhost +localhost in a such case.
+        #if test x$enable_x11_shared = xyes; then
+        #    SYSTEM_LIBS="$SYSTEM_LIBS -lX11"
+        #fi
         ;;
     *-*-qnx*)
         ARCH=qnx
diff --git a/src/video/x11/SDL_x11dyn.h b/src/video/x11/SDL_x11dyn.h
index 15962cc2..602dd753 100644
--- a/src/video/x11/SDL_x11dyn.h
+++ b/src/video/x11/SDL_x11dyn.h
@@ -72,10 +72,21 @@ typedef int (*SDL_X11_XSetExtensionErrorHandlerType)(Display *,char *,char *);
 #define _XFlushGCCache p_XFlushGCCache
 #define _XReply p_XReply
 #define _XSend p_XSend
-#define _XData32 p_XData32
 #define XFree pXFree
+
+#if !defined(__osf__) || defined(X11_DYNAMIC)
+#define _XData32 p_XData32
 #endif
 
+#if defined(__osf__) && defined(X11_DYNAMIC)
+#define _SmtBufferOverflow p_SmtBufferOverflow
+#define _SmtIpError p_SmtIpError
+#define ipAllocateData pipAllocateData
+#define ipUnallocateAndSendData pipUnallocateAndSendData
+#endif
+
+#endif /* !__SDL_NO_REDEFINE_X11_HEADER_SYMS */
+
 int SDL_X11_LoadSymbols(void);
 void SDL_X11_UnloadSymbols(void);
 
diff --git a/src/video/x11/SDL_x11sym.h b/src/video/x11/SDL_x11sym.h
index ce76ef34..c379854f 100644
--- a/src/video/x11/SDL_x11sym.h
+++ b/src/video/x11/SDL_x11sym.h
@@ -139,11 +139,18 @@ SDL_X11_SYM(1,unsigned long,_XSetLastRequestRead,(Display*,xGenericReply*))
  * These don't exist in 32-bit versions and are removed by Xlib macros, but
  *  64+ bit systems will use them.
  */
-#ifdef LONG64
+#if defined(LONG64) && !defined(__osf__) || defined(X11_DYNAMIC)
 SDL_X11_SYM(1,int,_XData32,(Display *dpy,register long *data,unsigned len))
 SDL_X11_SYM(1,void,_XRead32,(Display *dpy,register long *data,long len))
 #endif
 
+#if defined(__osf__) && defined(X11_DYNAMIC)
+SDL_X11_SYM(1,void,_SmtBufferOverflow,(Display *dpy,register smtDisplayPtr))
+SDL_X11_SYM(1,void,_SmtIpError,(Display *dpy,register smtDisplayPtr, int))
+SDL_X11_SYM(1,int,ipAllocateData,(ChannelPtr, IPCard, IPDataPtr *))
+SDL_X11_SYM(1,int,ipUnallocateAndSendData,(ChannelPtr, IPCard))
+#endif
+
 #if NeedWidePrototypes
 SDL_X11_SYM(1,KeySym,XKeycodeToKeysym,(Display*,unsigned int,int))
 #else
diff --git a/src/video/x11/SDL_x11video.c b/src/video/x11/SDL_x11video.c
index dd1e4517..8396a298 100644
--- a/src/video/x11/SDL_x11video.c
+++ b/src/video/x11/SDL_x11video.c
@@ -436,6 +436,20 @@ static int X11_VideoInit(_THIS, SDL_PixelFormat *vformat)
 		local_X11 = 0;
 	}
 	SDL_Display = pXOpenDisplay(display);
+#if defined(__osf__) && defined(X11_DYNAMIC)
+	/* On Tru64 if linking without -lX11, it fails and you get following message.
+	 * Xlib: connection to ":0.0" refused by server
+	 * Xlib: XDM authorization key matches an existing client!
+	 *
+	 * It succeeds if retrying 1 second later
+	 * or if running xhost +localhost on shell.
+	 *
+	 */
+	if ( SDL_Display == NULL ) {
+		SDL_Delay(1000);
+		SDL_Display = pXOpenDisplay(display);
+	}
+#endif
 	if ( SDL_Display == NULL ) {
 		SDL_SetError("Couldn't open X11 display");
 		return(-1);
-- 
2.18.1