Ignore xrandr brightness update if the output has no CRTC (i.e. it's off).
Otherwise X server returns always zero, and it screws up.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
---
 src/gpm-brightness-xrandr.c |   37 ++++++++++++++++++++++++-------------
 1 file changed, 24 insertions(+), 13 deletions(-)

Index: gnome-power-manager-2.24.1/src/gpm-brightness-xrandr.c
===================================================================
--- gnome-power-manager-2.24.1.orig/src/gpm-brightness-xrandr.c
+++ gnome-power-manager-2.24.1/src/gpm-brightness-xrandr.c
@@ -85,17 +85,28 @@ static guint signals [LAST_SIGNAL] = { 0
  * gpm_brightness_xrandr_output_get_internal:
  **/
 static gboolean
-gpm_brightness_xrandr_output_get_internal (GpmBrightnessXRandR *brightness, RROutput output, guint *cur)
+gpm_brightness_xrandr_output_get_internal (GpmBrightnessXRandR *brightness, XRRScreenResources *resources, RROutput output, guint *cur)
 {
 	unsigned long nitems;
 	unsigned long bytes_after;
 	unsigned char *prop;
+	XRROutputInfo *info;
 	Atom actual_type;
 	int actual_format;
 	gboolean ret = FALSE;
 
 	g_return_val_if_fail (GPM_IS_BRIGHTNESS_XRANDR (brightness), FALSE);
 
+	info = XRRGetOutputInfo (brightness->priv->dpy, resources, output);
+	if (!info) {
+		egg_debug ("failed to get output info");
+		return FALSE;
+	}
+	if (info->crtc == None) {
+		egg_debug ("no CRTC");
+		return FALSE;
+	}
+
 	if (XRRGetOutputProperty (brightness->priv->dpy, output, brightness->priv->backlight,
 				  0, 4, False, False, None,
 				  &actual_type, &actual_format,
@@ -237,7 +248,7 @@ out:
  * gpm_brightness_xrandr_output_get_percentage:
  **/
 static gboolean
-gpm_brightness_xrandr_output_get_percentage (GpmBrightnessXRandR *brightness, RROutput output)
+gpm_brightness_xrandr_output_get_percentage (GpmBrightnessXRandR *brightness, XRRScreenResources *resources, RROutput output)
 {
 	guint cur;
 	gboolean ret;
@@ -246,7 +257,7 @@ gpm_brightness_xrandr_output_get_percent
 
 	g_return_val_if_fail (GPM_IS_BRIGHTNESS_XRANDR (brightness), FALSE);
 
-	ret = gpm_brightness_xrandr_output_get_internal (brightness, output, &cur);
+	ret = gpm_brightness_xrandr_output_get_internal (brightness, resources, output, &cur);
 	if (!ret) {
 		return FALSE;
 	}
@@ -265,7 +276,7 @@ gpm_brightness_xrandr_output_get_percent
  * gpm_brightness_xrandr_output_down:
  **/
 static gboolean
-gpm_brightness_xrandr_output_down (GpmBrightnessXRandR *brightness, RROutput output)
+gpm_brightness_xrandr_output_down (GpmBrightnessXRandR *brightness, XRRScreenResources *resources, RROutput output)
 {
 	guint cur;
 	gboolean ret;
@@ -273,7 +284,7 @@ gpm_brightness_xrandr_output_down (GpmBr
 
 	g_return_val_if_fail (GPM_IS_BRIGHTNESS_XRANDR (brightness), FALSE);
 
-	ret = gpm_brightness_xrandr_output_get_internal (brightness, output, &cur);
+	ret = gpm_brightness_xrandr_output_get_internal (brightness, resources, output, &cur);
 	if (!ret) {
 		return FALSE;
 	}
@@ -299,7 +310,7 @@ gpm_brightness_xrandr_output_down (GpmBr
  * gpm_brightness_xrandr_output_up:
  **/
 static gboolean
-gpm_brightness_xrandr_output_up (GpmBrightnessXRandR *brightness, RROutput output)
+gpm_brightness_xrandr_output_up (GpmBrightnessXRandR *brightness, XRRScreenResources *resources, RROutput output)
 {
 	guint cur;
 	gboolean ret;
@@ -307,7 +318,7 @@ gpm_brightness_xrandr_output_up (GpmBrig
 
 	g_return_val_if_fail (GPM_IS_BRIGHTNESS_XRANDR (brightness), FALSE);
 
-	ret = gpm_brightness_xrandr_output_get_internal (brightness, output, &cur);
+	ret = gpm_brightness_xrandr_output_get_internal (brightness, resources, output, &cur);
 	if (!ret) {
 		return FALSE;
 	}
@@ -333,7 +344,7 @@ gpm_brightness_xrandr_output_up (GpmBrig
  * gpm_brightness_xrandr_output_set:
  **/
 static gboolean
-gpm_brightness_xrandr_output_set (GpmBrightnessXRandR *brightness, RROutput output)
+gpm_brightness_xrandr_output_set (GpmBrightnessXRandR *brightness, XRRScreenResources *resources, RROutput output)
 {
 	guint cur;
 	gboolean ret;
@@ -344,7 +355,7 @@ gpm_brightness_xrandr_output_set (GpmBri
 
 	g_return_val_if_fail (GPM_IS_BRIGHTNESS_XRANDR (brightness), FALSE);
 
-	ret = gpm_brightness_xrandr_output_get_internal (brightness, output, &cur);
+	ret = gpm_brightness_xrandr_output_get_internal (brightness, resources, output, &cur);
 	if (!ret) {
 		return FALSE;
 	}
@@ -420,13 +431,13 @@ gpm_brightness_xrandr_foreach_resource (
 		egg_debug ("resource %i of %i", i+1, resources->noutput);
 		RROutput output = resources->outputs[i];
 		if (op==ACTION_BACKLIGHT_GET) {
-			ret = gpm_brightness_xrandr_output_get_percentage (brightness, output);
+			ret = gpm_brightness_xrandr_output_get_percentage (brightness, resources, output);
 		} else if (op==ACTION_BACKLIGHT_INC) {
-			ret = gpm_brightness_xrandr_output_up (brightness, output);
+			ret = gpm_brightness_xrandr_output_up (brightness, resources, output);
 		} else if (op==ACTION_BACKLIGHT_DEC) {
-			ret = gpm_brightness_xrandr_output_down (brightness, output);
+			ret = gpm_brightness_xrandr_output_down (brightness, resources, output);
 		} else if (op==ACTION_BACKLIGHT_SET) {
-			ret = gpm_brightness_xrandr_output_set (brightness, output);
+			ret = gpm_brightness_xrandr_output_set (brightness, resources, output);
 		} else {
 			ret = FALSE;
 			egg_warning ("op not known");
