From 558a5634d60221e5485083193155d1ee062c8e0e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?R=C3=A9mi=20Cardona?= <remi@gentoo.org>
Date: Fri, 11 Sep 2009 21:33:58 +0200
Subject: [PATCH] Check for XRR* functions using library version instead of proto version
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

randrproto 1.3 can be installed with libXrandr 1.2, which causes linking
errors with g-p-m. This patch checks that libXrandr (and not randrproto)
1.3 is available.

Signed-off-by: RĂ©mi Cardona <remi@gentoo.org>
---
 configure.ac                |    4 ++++
 src/gpm-brightness-xrandr.c |   13 ++++++-------
 2 files changed, 10 insertions(+), 7 deletions(-)

diff --git a/configure.ac b/configure.ac
index 4cbe47c..4baa0cf 100644
--- a/configure.ac
+++ b/configure.ac
@@ -171,6 +171,10 @@ PKG_CHECK_MODULES(XRANDR, [
 AC_SUBST(XRANDR_CFLAGS)
 AC_SUBST(XRANDR_LIBS)
 
+PKG_CHECK_EXISTS(
+ [xrandr >= 1.3],
+ [AC_DEFINE(HAVE_XRANDR_13, 1, [xrandr 1.3 available])])
+
 PKG_CHECK_MODULES(LIBNOTIFY, libnotify >= $LIBNOTIFY_REQUIRED)
 AC_SUBST(LIBNOTIFY_CFLAGS)
 AC_SUBST(LIBNOTIFY_LIBS)
diff --git a/src/gpm-brightness-xrandr.c b/src/gpm-brightness-xrandr.c
index cce4df2..3332be3 100644
--- a/src/gpm-brightness-xrandr.c
+++ b/src/gpm-brightness-xrandr.c
@@ -60,7 +60,7 @@ struct GpmBrightnessXRandRPrivate
 	Display			*dpy;
 	guint			 shared_value;
 	gboolean		 has_extension;
-#if (RANDR_MAJOR == 1 && RANDR_MINOR >= 3)
+#ifdef HAVE_XRANDR_13
 	gboolean		 has_randr13;
 #endif
 	gboolean		 hw_changed;
@@ -173,7 +173,7 @@ gpm_brightness_xrandr_setup_display (GpmBrightnessXRandR *brightness)
 	return TRUE;
 }
 
-#if (RANDR_MAJOR == 1 && RANDR_MINOR >= 3)
+#ifdef HAVE_XRANDR_13
 /**
  * gpm_brightness_xrandr_setup_version: Check whether xserver really supports xrandr-1.3 features.
  **/
@@ -650,14 +650,13 @@ gpm_brightness_xrandr_update_cache (GpmBrightnessXRandR *brightness)
 		   in RandR 1.3 or higher and of course xserver needs
 		   to support it.
 		*/
-#if (RANDR_MAJOR == 1 && RANDR_MINOR >= 3)
+#ifdef HAVE_XRANDR_13
 		if (brightness->priv->has_randr13)
 			resource = XRRGetScreenResourcesCurrent (brightness->priv->dpy, root);
 		else
-			resource = XRRGetScreenResources (brightness->priv->dpy, root);
-#else
-		resource = XRRGetScreenResources (brightness->priv->dpy, root);
 #endif
+			resource = XRRGetScreenResources (brightness->priv->dpy, root);
+
 		if (resource != NULL) {
 			egg_debug ("adding resource %p", resource);
 			g_ptr_array_add (brightness->priv->resources, resource);
@@ -724,7 +723,7 @@ gpm_brightness_xrandr_init (GpmBrightnessXRandR *brightness)
 		egg_debug ("no XRANDR extension, so aborting init");
 		return;
 	}
-#if (RANDR_MAJOR == 1 && RANDR_MINOR >= 3)
+#ifdef HAVE_XRANDR_13
 	brightness->priv->has_randr13 = gpm_brightness_xrandr_setup_version (brightness);
 #endif
 
-- 
1.6.5.1