Index: /trunk/configure
===================================================================
--- /trunk/configure	(revision 83223)
+++ /trunk/configure	(revision 83224)
@@ -2860,6 +2860,4 @@
   # tools/common/makeself*
   [ $OSE -ge 1 ] && check_makeself
-  # Use header files from our tree for randr and xinerama. don't link but rather dlopen libXrand
-  VBOX_WITH_DISTRO_XRAND_XINERAMA=
 fi
 
Index: /trunk/src/VBox/Additions/x11/VBoxClient/Makefile.kmk
===================================================================
--- /trunk/src/VBox/Additions/x11/VBoxClient/Makefile.kmk	(revision 83223)
+++ /trunk/src/VBox/Additions/x11/VBoxClient/Makefile.kmk	(revision 83224)
@@ -19,4 +19,7 @@
 include $(KBUILD_PATH)/subheader.kmk
 
+# Use header files from our tree for randr and xinerama. and don't link but rather dlopen libXrand
+VBOX_WITH_DISTRO_XRAND_XINERAMA=
+
 #
 # VBoxClient - clipboard and seamless.
@@ -29,4 +32,7 @@
 ifdef VBOX_WITH_DBUS
  VBoxClient_DEFS += VBOX_WITH_DBUS
+endif
+ifdef VBOX_WITH_DISTRO_XRAND_XINERAMA
+ VBoxClient_DEFS += WITH_DISTRO_XRAND_XINERAMA
 endif
 VBoxClient_DEFS.linux += _GNU_SOURCE
@@ -54,6 +60,8 @@
 	dl
 VBoxClient_LIBS = \
-	X11 Xrandr Xt Xext Xmu
-
+	X11 Xt Xext Xmu
+ifdef VBOX_WITH_DISTRO_XRAND_XINERAMA
+VBoxClient_LIBS += Xrandr
+endif
 # XXX: -L comes from the template, but not rpath
 VBoxClient_LDFLAGS.netbsd = \
Index: /trunk/src/VBox/Additions/x11/VBoxClient/display-svga-x11.cpp
===================================================================
--- /trunk/src/VBox/Additions/x11/VBoxClient/display-svga-x11.cpp	(revision 83223)
+++ /trunk/src/VBox/Additions/x11/VBoxClient/display-svga-x11.cpp	(revision 83224)
@@ -54,8 +54,4 @@
 #include <X11/extensions/panoramiXproto.h>
 
-#define OLD_JUNK
-
-//#define DL_OPEN_RANDR
-
 /** Maximum number of supported screens.  DRM and X11 both limit this to 32. */
 /** @todo if this ever changes, dynamically allocate resizeable arrays in the
@@ -121,4 +117,6 @@
     Bool (*pXRRQueryExtension) (Display *, int *, int *);
     Status (*pXRRQueryVersion) (Display *, int *, int*);
+    XRRMonitorInfo* (*pXRRGetMonitors)(Display *, Window, Bool, int *);
+    void (*pXRRFreeMonitors)(XRRMonitorInfo *);
 };
 
@@ -181,5 +179,4 @@
 }
 
-#ifndef OLD_JUNK
 /** This function assumes monitors are named as from Virtual1 to VirtualX. */
 static int getMonitorIdFromName(const char *sMonitorName)
@@ -222,10 +219,18 @@
     }
 
-    XRRScreenResources *pScreenResources = XRRGetScreenResources (x11Context.pDisplay, DefaultRootWindow(x11Context.pDisplay));
-    AssertReturnVoid(pScreenResources);
-    XRRFreeScreenResources (pScreenResources);
+    // XRRScreenResources *pScreenResources = XRRGetScreenResources(x11Context.pDisplay, DefaultRootWindow(x11Context.pDisplay));
+    // AssertReturnVoid(pScreenResources);
+    // XRRFreeScreenResources(pScreenResources);
 
     int iMonitorCount = 0;
-    XRRMonitorInfo *pMonitorInfo = XRRGetMonitors(x11Context.pDisplay, DefaultRootWindow(x11Context.pDisplay), true, &iMonitorCount);
+    XRRMonitorInfo *pMonitorInfo = NULL;
+#ifdef WITH_DISTRO_XRAND_XINERAMA
+    pMonitorInfo = XRRGetMonitors(x11Context.pDisplay, DefaultRootWindow(x11Context.pDisplay), true, &iMonitorCount);
+#else
+    if (x11Context.pXRRGetMonitors)
+        x11Context.pXRRGetMonitors(x11Context.pDisplay, DefaultRootWindow(x11Context.pDisplay), true, &iMonitorCount);
+#endif
+    if (!pMonitorInfo)
+        return;
     if (iMonitorCount == -1)
         VBClLogError("Could not get monitor info\n");
@@ -254,11 +259,14 @@
             sendMonitorPositions(mpMonitorPositions, x11Context.hOutputCount);
     }
+#ifdef WITH_DISTRO_XRAND_XINERAMA
     XRRFreeMonitors(pMonitorInfo);
-}
+#else
+    if (x11Context.pXRRFreeMonitors)
+        x11Context.pXRRFreeMonitors(pMonitorInfo);
 #endif
+}
 
 static void monitorRandREvents()
 {
-#ifndef OLD_JUNK
     XEvent event;
     XNextEvent(x11Context.pDisplay, &event);
@@ -277,5 +285,4 @@
             break;
     }
-#endif
 }
 
@@ -333,5 +340,4 @@
 static bool callVMWCTRL()
 {
-#ifndef OLD_JUNK
     const int hHeight = 600;
     const int hWidth = 800;
@@ -352,7 +358,4 @@
                                  DefaultScreen(x11Context.pDisplay),
                                  extents, x11Context.hOutputCount);
-#else
-    return true;
-#endif
 }
 
@@ -365,9 +368,9 @@
     if (RT_FAILURE(startX11MonitorThread()))
         return false;
-#ifdef DL_OPEN_RANDR
+#ifdef WITH_DISTRO_XRAND_XINERAMA
+    XRRSelectInput(x11Context.pDisplay, x11Context.rootWindow, x11Context.hEventMask);
+#else
     if (x11Context.pXRRSelectInput)
         x11Context.pXRRSelectInput(x11Context.pDisplay, x11Context.rootWindow, x11Context.hEventMask);
-#else
-    XRRSelectInput(x11Context.pDisplay, x11Context.rootWindow, x11Context.hEventMask);
 #endif
     return true;
@@ -387,14 +390,14 @@
         x11Context.pRandLibraryHandle = NULL;
     }
-#ifdef DL_OPEN_RANDR
+#ifdef WITH_DISTRO_XRAND_XINERAMA
+    XRRSelectInput(x11Context.pDisplay, x11Context.rootWindow, 0);
+#else
     if (x11Context.pXRRSelectInput)
         x11Context.pXRRSelectInput(x11Context.pDisplay, x11Context.rootWindow, 0);
-#else
-    XRRSelectInput(x11Context.pDisplay, x11Context.rootWindow, 0);
 #endif
     XCloseDisplay(x11Context.pDisplay);
 }
 
-#ifdef DL_OPEN_RANDR
+#ifndef WITH_DISTRO_XRAND_XINERAMA
 static int openLibRandR()
 {
@@ -434,4 +437,25 @@
         return VERR_NOT_FOUND;
     }
+
+    x11Context.pXRRGetMonitors = (XRRMonitorInfo* (*)(Display *, Window, Bool, int *))
+        dlsym(x11Context.pRandLibraryHandle, "XRRGetMonitors");
+    if (!x11Context.pXRRGetMonitors)
+    {
+        VBClLogFatalError("Could not find address for the symbol XRRGetMonitors\n");
+        dlclose(x11Context.pRandLibraryHandle);
+        x11Context.pRandLibraryHandle = NULL;
+        return VERR_NOT_FOUND;
+    }
+
+    x11Context.pXRRFreeMonitors = (void (*)(XRRMonitorInfo *))
+        dlsym(x11Context.pRandLibraryHandle, "XRRFreeMonitors");
+    if (!x11Context.pXRRFreeMonitors)
+    {
+        VBClLogFatalError("Could not find address for the symbol XRRFreeMonitors\n");
+        dlclose(x11Context.pRandLibraryHandle);
+        x11Context.pRandLibraryHandle = NULL;
+        return VERR_NOT_FOUND;
+    }
+
     return VINF_SUCCESS;
 }
@@ -454,18 +478,18 @@
     }
     bool fSuccess = false;
-#ifdef DL_OPEN_RANDR
+#ifdef WITH_DISTRO_XRAND_XINERAMA
+    fSuccess = XRRQueryExtension(x11Context.pDisplay, &x11Context.hRandREventBase, &x11Context.hRandRErrorBase);
+#else
     if (x11Context.pXRRQueryExtension)
         fSuccess = x11Context.pXRRQueryExtension(x11Context.pDisplay, &x11Context.hRandREventBase, &x11Context.hRandRErrorBase);
-#else
-    fSuccess = XRRQueryExtension(x11Context.pDisplay, &x11Context.hRandREventBase, &x11Context.hRandRErrorBase);
 #endif
     if (fSuccess)
     {
         fSuccess = false;
-#ifdef DL_OPEN_RANDR
+#ifdef WITH_DISTRO_XRAND_XINERAMA
+        fSuccess = XRRQueryVersion(x11Context.pDisplay, &x11Context.hRandRMajor, &x11Context.hRandRMinor);
+#else
     if (x11Context.pXRRQueryVersion)
         fSuccess = x11Context.pXRRQueryVersion(x11Context.pDisplay, &x11Context.hRandRMajor, &x11Context.hRandRMinor);
-#else
-        fSuccess = XRRQueryVersion(x11Context.pDisplay, &x11Context.hRandRMajor, &x11Context.hRandRMinor);
 #endif
         if (!fSuccess)
@@ -477,5 +501,4 @@
     }
     x11Context.hEventMask = 0;
-#ifndef OLD_JUNK
     x11Context.hEventMask = RRScreenChangeNotifyMask;
     if (x11Context.hRandRMinor >= 2)
@@ -483,5 +506,4 @@
                                | RROutputChangeNotifyMask
                                | RROutputPropertyNotifyMask;
-#endif
     x11Context.rootWindow = DefaultRootWindow(x11Context.pDisplay);
     x11Context.hOutputCount = determineOutputCount();
@@ -490,5 +512,7 @@
     x11Context.pXRRQueryExtension = NULL;
     x11Context.pXRRQueryVersion = NULL;
-#ifdef DL_OPEN_RANDR
+    x11Context.pXRRGetMonitors = NULL;
+    x11Context.pXRRFreeMonitors = NULL;
+#ifndef WITH_DISTRO_XRAND_XINERAMA
     if (openLibRandR() != VINF_SUCCESS)
     {
