Hello,

Attached is a very usefull patch. It removes the runtime dependency on 
libX11. This way one can build MC with support for X11 events and can
distribute it both to users who have X and other which dont. This patch's 
aim is to make the life of package maintainers easier.

This patch is kind an incomplete at the moment though. The source is fine 
but it should be backed with some knowledge about the system on which MC 
is being built i.e. it needs some support from configure.

1.) The proper name of the X library should be determined at configure 
time i.e. libX11.dll or only libX11 for cygwin and libX11.so for unices.

2.) The name of the symbols may be decorated in a different way on 
different systems i.e. cygwin and linux have XOpenDisplay while OpenBSD 
has _XOpenDisplay. I guess one can find the names with the help of 'nm'.

So, some help with the configure stuff would be appreciated. I'm also 
working on it now but I dont want to waste too much time on fixing 
configure if there is no chance the patch to be accepted.

I started this since I wanted to provied a single package for Cygwin. 

Thanks! :)
diff -urN -x .build -x .inst -x .sinst mc-4.6.0-orig/src/key.c mc-4.6.0/src/key.c
--- mc-4.6.0-orig/src/key.c     2003-01-27 23:37:56.000000000 +0100
+++ mc-4.6.0/src/key.c  2003-02-08 15:00:55.000000000 +0100
@@ -41,6 +41,7 @@
 #include "../vfs/vfs.h"
 
 #ifdef HAVE_TEXTMODE_X11_SUPPORT
+#include <dlfcn.h>
 #include <X11/Xlib.h>
 #endif
 
@@ -247,6 +248,16 @@
 }
 
 #ifdef HAVE_TEXTMODE_X11_SUPPORT
+typedef Display * (* XOPENDISPLAY) (_Xconst char *);
+typedef int (* XCLOSEDISPLAY) (Display *);
+typedef Bool (* XQUERYPOINTER) (Display *, Window, Window *, Window*,
+                               int *, int *, int *, int *, unsigned int *);
+
+static void *x11_h; /* handle returned by dlopen () */
+static XOPENDISPLAY func_XOpenDisplay;
+static XCLOSEDISPLAY func_XCloseDisplay;
+static XQUERYPOINTER func_XQueryPointer;
+
 static Display *x11_display;
 static Window x11_window;
 #endif /* HAVE_TEXTMODE_X11_SUPPORT */
@@ -290,9 +301,19 @@
 #endif /* __QNX__ */
 
 #ifdef HAVE_TEXTMODE_X11_SUPPORT
-    x11_display = XOpenDisplay (0);
-    if (x11_display)
-        x11_window = DefaultRootWindow (x11_display);
+    x11_h = dlopen ("libX11.so", RTLD_LAZY);
+    if (x11_h != NULL) {
+       func_XOpenDisplay = dlsym (x11_h, "XOpenDisplay");
+       func_XCloseDisplay = dlsym (x11_h, "XCloseDisplay");
+       func_XQueryPointer = dlsym (x11_h, "XQueryPointer");
+       if (func_XOpenDisplay != NULL &&
+           func_XCloseDisplay != NULL &&
+           func_XQueryPointer != NULL) {
+           x11_display = (*func_XOpenDisplay) (0);
+           if (x11_display)
+               x11_window = DefaultRootWindow (x11_display);
+       }
+    }
 #endif /* HAVE_TEXTMODE_X11_SUPPORT */
 }
 
@@ -1049,8 +1070,8 @@
        int win_x, win_y;
        unsigned int mask;
 
-       XQueryPointer (x11_display, x11_window, &root, &child, &root_x,
-                      &root_y, &win_x, &win_y, &mask);
+       (*func_XQueryPointer) (x11_display, x11_window, &root, &child,
+                              &root_x, &root_y, &win_x, &win_y, &mask);
 
        if (mask & ShiftMask)
            result |= KEY_M_SHIFT;
@@ -1106,6 +1127,8 @@
 
 #ifdef HAVE_TEXTMODE_X11_SUPPORT
     if (x11_display)
-       XCloseDisplay (x11_display);
+       (*func_XCloseDisplay) (x11_display);
+    if (x11_h != NULL)
+       dlclose (x11_h);
 #endif /* HAVE_TEXTMODE_X11_SUPPORT */
 }

Reply via email to