Load the XRandR extension dynamically (with help from Alex Pasadyn).

diff --git a/configure b/configure
index 27467ec..d25d2a6 100755
--- a/configure
+++ b/configure
@@ -8265,38 +8265,25 @@
 
                 if test "$ac_cv_header_X11_extensions_Xrandr_h" = "yes"
         then
-                echo "$as_me:$LINENO: checking for XRRSetScreenConfigAndRate in -lXrandr" >&5
-echo $ECHO_N "checking for XRRSetScreenConfigAndRate in -lXrandr... $ECHO_C" >&6
-if test "${ac_cv_lib_Xrandr_XRRSetScreenConfigAndRate+set}" = set; then
-  echo $ECHO_N "(cached) $ECHO_C" >&6
-else
-  ac_check_lib_save_LIBS=$LIBS
-LIBS="-lXrandr $X_LIBS -lXrender -lXext -lX11 $X_EXTRA_LIBS $LIBS"
-cat >conftest.$ac_ext <<_ACEOF
+                cat >conftest.$ac_ext <<_ACEOF
 /* confdefs.h.  */
 _ACEOF
 cat confdefs.h >>conftest.$ac_ext
 cat >>conftest.$ac_ext <<_ACEOF
 /* end confdefs.h.  */
-
-/* Override any gcc2 internal prototype to avoid an error.  */
-#ifdef __cplusplus
-extern "C"
-#endif
-/* We use char because int might match the return type of a gcc2
-   builtin and then its argument prototype would still apply.  */
-char XRRSetScreenConfigAndRate ();
+#include <X11/Xlib.h>
+#include <X11/extensions/Xrandr.h>
 int
 main ()
 {
-XRRSetScreenConfigAndRate ();
+static typeof(XRRSetScreenConfigAndRate) * func;
   ;
   return 0;
 }
 _ACEOF
-rm -f conftest.$ac_objext conftest$ac_exeext
-if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
-  (eval $ac_link) 2>conftest.er1
+rm -f conftest.$ac_objext
+if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
+  (eval $ac_compile) 2>conftest.er1
   ac_status=$?
   grep -v '^ *+' conftest.er1 >conftest.err
   rm -f conftest.er1
@@ -8309,35 +8296,23 @@
   ac_status=$?
   echo "$as_me:$LINENO: \$? = $ac_status" >&5
   (exit $ac_status); }; } &&
-	 { ac_try='test -s conftest$ac_exeext'
+	 { ac_try='test -s conftest.$ac_objext'
   { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
   (eval $ac_try) 2>&5
   ac_status=$?
   echo "$as_me:$LINENO: \$? = $ac_status" >&5
   (exit $ac_status); }; }; then
-  ac_cv_lib_Xrandr_XRRSetScreenConfigAndRate=yes
-else
-  echo "$as_me: failed program was:" >&5
-sed 's/^/| /' conftest.$ac_ext >&5
-
-ac_cv_lib_Xrandr_XRRSetScreenConfigAndRate=no
-fi
-rm -f conftest.err conftest.$ac_objext \
-      conftest$ac_exeext conftest.$ac_ext
-LIBS=$ac_check_lib_save_LIBS
-fi
-echo "$as_me:$LINENO: result: $ac_cv_lib_Xrandr_XRRSetScreenConfigAndRate" >&5
-echo "${ECHO_T}$ac_cv_lib_Xrandr_XRRSetScreenConfigAndRate" >&6
-if test $ac_cv_lib_Xrandr_XRRSetScreenConfigAndRate = yes; then
 
 cat >>confdefs.h <<\_ACEOF
 #define HAVE_LIBXRANDR 1
 _ACEOF
 
-                     X_PRE_LIBS="$X_PRE_LIBS -lXrandr -lXrender"
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
 
 fi
-
+rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
         fi
 
                 if test "$ac_cv_header_X11_extensions_Xvlib_h" = "yes"
@@ -14907,6 +14882,80 @@
 _ACEOF
 fi
 
+echo "$as_me:$LINENO: checking for -lXrandr soname" >&5
+echo $ECHO_N "checking for -lXrandr soname... $ECHO_C" >&6
+if test "${ac_cv_lib_soname_Xrandr+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  ac_get_soname_save_LIBS=$LIBS
+LIBS="-lXrandr $X_LIBS -lXext -lX11 $X_EXTRA_LIBS $LIBS"
+  cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+
+/* Override any gcc2 internal prototype to avoid an error.  */
+#ifdef __cplusplus
+extern "C"
+#endif
+/* We use char because int might match the return type of a gcc2
+   builtin and then its argument prototype would still apply.  */
+char XRRQueryExtension ();
+int
+main ()
+{
+XRRQueryExtension ();
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext conftest$ac_exeext
+if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
+  (eval $ac_link) 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } &&
+	 { ac_try='test -z "$ac_c_werror_flag"			 || test ! -s conftest.err'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; } &&
+	 { ac_try='test -s conftest$ac_exeext'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+  ac_cv_lib_soname_Xrandr=`$ac_cv_path_LDD conftest$ac_exeext | grep libXrandr\\.so | sed 's/^.*\(libXrandr\.so[^	 ]*\).*$/\1/'`
+  if test "x$ac_cv_lib_soname_Xrandr" = "x"
+  then
+     ac_cv_lib_soname_Xrandr="libXrandr.so"
+  fi
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+ac_cv_lib_soname_Xrandr="libXrandr.so"
+fi
+rm -f conftest.err conftest.$ac_objext \
+      conftest$ac_exeext conftest.$ac_ext
+  LIBS=$ac_get_soname_save_LIBS
+fi
+echo "$as_me:$LINENO: result: $ac_cv_lib_soname_Xrandr" >&5
+echo "${ECHO_T}$ac_cv_lib_soname_Xrandr" >&6
+if test "x$ac_cv_lib_soname_Xrandr" != xNONE
+then
+cat >>confdefs.h <<_ACEOF
+#define SONAME_LIBXRANDR "$ac_cv_lib_soname_Xrandr"
+_ACEOF
+fi
+
 echo "$as_me:$LINENO: checking for -lfreetype soname" >&5
 echo $ECHO_N "checking for -lfreetype soname... $ECHO_C" >&6
 if test "${ac_cv_lib_soname_freetype+set}" = set; then