On Fri, Dec 25, 2009 at 04:31:27PM -0500, Richard Stallman wrote:
> I have an external battery connected.
> I reduce the brightness to conserve power.
> Every so often the system spontaneously changes to
> full brightness.

This bug was reported in 2006 and fixed upstream in April 2008, but
the version of gnome-power-manager we are using (from debian lenny) is
too old to include the fix.

  https://bugzilla.gnome.org/show_bug.cgi?id=335673

I backported the fix to the version in lenny and metad.  I've attached
a patch to this email, compiled it for mipsel/loongson, and put the
new source and binary packages into:

  fencepost.gnu.org:~mhw/gpm-metad1/

> For each of the distinct states it knows about, it should remember
> what brightness the user ast chose in that state.  When it leaves
> a state, it should store the current brightness as the last brightness
> for that state.  When it enters a state, it should set the brightness
> to the value stored for that state.  This way, no user-specified brightness
> change will ever be countermanded.  Instead, user-specified brightnesses
> will be swapped in and out.

Note that they considered this kind of scheme, but decided against it.
The problem is that the ambient light level is a better predictor of
desired brightness than the ac-power-state.  For example, if you were
in a bright environment the last time you used battery power, and now
are in a dark environment, unplugging the AC power would *brighten*
the backlight.

They opted for a scheme which remembers a "master" brightness level,
and optionally dims by a certain relative amount when switching to
battery power.

Ideally, it should probably *learn* the relationship between
desired-brightness-on-ac and desired-brightness-on-battery by watching
how the user adjusts the brightness shortly after ac-power-state
changes.

Note also that the backlight adjustment logic has gone through a great
deal of evolution since the version we are currently using.  We are
using version 2.20, and the last release is 2.30.  So far I've only
backported a single small fix from April 2008, but it might be
worthwhile to consider a more extensive backporting effort.

     Mark
diff -ruN gnome-power-manager-2.22.1-debian-orig/debian/changelog gnome-power-manager-2.22.1/debian/changelog
--- gnome-power-manager-2.22.1-debian-orig/debian/changelog	2010-04-09 00:34:18.000000000 -0400
+++ gnome-power-manager-2.22.1/debian/changelog	2010-04-09 00:32:43.000000000 -0400
@@ -1,3 +1,14 @@
+gnome-power-manager (2.22.1-4+metad1) metad; urgency=low
+
+  * Backported backlight fix by Richard Hughes <rich...@hughsie.com>
+    from revision 2768 of upstream (2008-04-09), which makes the
+    backlight do what the user expects rather than what the policy
+    says.  This fixes the bug where auto-dimming returns the level to
+    the policy value rather than the value the user just set using the
+    brightness applet or brightness keys.
+
+ -- Mark H Weaver <m...@netris.org>  Fri, 09 Apr 2010 00:32:41 -0400
+
 gnome-power-manager (2.22.1-4) unstable; urgency=low
 
   * Rewrite description. Closes: #388109.
diff -ruN gnome-power-manager-2.22.1-debian-orig/debian/patches/09-backlight-fix.patch gnome-power-manager-2.22.1/debian/patches/09-backlight-fix.patch
--- gnome-power-manager-2.22.1-debian-orig/debian/patches/09-backlight-fix.patch	1969-12-31 19:00:00.000000000 -0500
+++ gnome-power-manager-2.22.1/debian/patches/09-backlight-fix.patch	2010-04-09 00:33:02.000000000 -0400
@@ -0,0 +1,165 @@
+--- ChangeLog.mhw1	2008-03-28 12:09:45.000000000 -0400
++++ ChangeLog	2010-04-09 00:26:59.000000000 -0400
+@@ -1,3 +1,15 @@
++2008-04-09  Richard Hughes  <rich...@hughsie.com>
++
++	* src/gpm-backlight.c: (gpm_backlight_get_brightness),
++	(gpm_backlight_set_brightness),
++	(gpm_backlight_brightness_evaluate_and_set), (conf_key_changed_cb),
++	(gpm_backlight_button_pressed_cb), (idle_changed_cb),
++	(gpm_backlight_init):
++	Make the backlight do what the user expects rather than what the policy says.
++	This should fix the bug where auto-dimming returns the level to the policy value
++	rather than the value the user just set using the brightness applet or brightness keys.
++	(backported by Mark H Weaver <m...@netris.org>)
++
+ 2008-03-28  Richard Hughes  <rich...@hughsie.com>
+ 
+ 	==== Version 2.22.1 ====
+--- src/gpm-backlight.c.mhw1	2008-03-10 17:49:46.000000000 -0400
++++ src/gpm-backlight.c	2010-04-09 00:25:05.000000000 -0400
+@@ -81,6 +81,7 @@
+ 	GTimer			*idle_timer;
+ 	gfloat			 ambient_sensor_value;
+ 	guint			 idle_dim_timeout;
++	guint			 master_percentage;
+ };
+ 
+ enum {
+@@ -304,6 +305,8 @@
+ 			      guint	    brightness,
+ 			      GError	   **error)
+ {
++	gboolean ret;
++
+ 	g_return_val_if_fail (backlight != NULL, FALSE);
+ 	g_return_val_if_fail (GPM_IS_BACKLIGHT (backlight), FALSE);
+ 
+@@ -316,9 +319,8 @@
+ 	}
+ 
+ 	/* just set the AC brightness for now, don't try to be clever */
+-	gpm_conf_set_uint (backlight->priv->conf, GPM_CONF_BACKLIGHT_BRIGHTNESS_AC, brightness);
+-#if 0
+-	gboolean ret;
++	backlight->priv->master_percentage = brightness;
++
+ 	/* sets the current policy brightness */
+ 	ret = gpm_brightness_lcd_set_std (backlight->priv->brightness, brightness);
+ 	if (ret == FALSE) {
+@@ -326,9 +328,7 @@
+ 				      GPM_BACKLIGHT_ERROR_GENERAL,
+ 				      "Cannot set policy brightness");
+ 	}
+-#endif
+-
+-	return TRUE;
++	return ret;
+ }
+ 
+ /**
+@@ -370,9 +370,8 @@
+ 		return FALSE;
+ 	}
+ 
+-	/* get the 'main' brightness */
+-	gpm_conf_get_uint (backlight->priv->conf, GPM_CONF_BACKLIGHT_BRIGHTNESS_AC, &value);
+-	brightness = value / 100.0f;
++	/* get the last set brightness */
++	brightness = backlight->priv->master_percentage / 100.0f;
+ 	gpm_debug ("1. main brightness %f", brightness);
+ 
+ 	/* get AC status */
+@@ -436,6 +435,7 @@
+ 
+ 	/* only show dialog if interactive */
+ 	if (interactive == TRUE) {
++		gpm_warning ("moo %f", brightness);
+ 		gpm_feedback_display_value (backlight->priv->feedback, (float) brightness);
+ 	}
+ 
+@@ -460,10 +460,13 @@
+ 	gboolean on_ac;
+ 	on_ac = gpm_ac_adapter_is_present (backlight->priv->ac_adapter);
+ 
+-	if (strcmp (key, GPM_CONF_BACKLIGHT_BRIGHTNESS_AC) == 0) {
++	if (on_ac && strcmp (key, GPM_CONF_BACKLIGHT_BRIGHTNESS_AC) == 0) {
++		gpm_conf_get_uint (backlight->priv->conf,
++				   GPM_CONF_BACKLIGHT_BRIGHTNESS_AC,
++				   &backlight->priv->master_percentage);
+ 		gpm_backlight_brightness_evaluate_and_set (backlight, FALSE);
+ 
+-	} else if (strcmp (key, GPM_CONF_BACKLIGHT_BRIGHTNESS_BATT) == 0) {
++	} else if (!on_ac && strcmp (key, GPM_CONF_BACKLIGHT_BRIGHTNESS_BATT) == 0) {
+ 		gpm_backlight_brightness_evaluate_and_set (backlight, FALSE);
+ 	}
+ 
+@@ -501,29 +504,46 @@
+ }
+ 
+ /**
+- * button_pressed_cb:
++ * gpm_backlight_button_pressed_cb:
+  * @power: The power class instance
+  * @type: The button type, e.g. "power"
+  * @state: The state, where TRUE is depressed or closed
+  * @brightness: This class instance
+  **/
+ static void
+-button_pressed_cb (GpmButton    *button,
+-		   const gchar  *type,
+-		   GpmBacklight *backlight)
++gpm_backlight_button_pressed_cb (GpmButton    *button,
++				 const gchar  *type,
++				 GpmBacklight *backlight)
+ {
++	guint percentage;
+ 	gpm_debug ("Button press event type=%s", type);
+ 
+ 	if (strcmp (type, GPM_BUTTON_BRIGHT_UP) == 0) {
+ 
+ 		if (backlight->priv->can_dim == TRUE) {
++			/* go up one step */
+ 			gpm_brightness_lcd_up (backlight->priv->brightness);
++
++			/* get the new value */
++			gpm_brightness_lcd_get (backlight->priv->brightness, &percentage);
++			gpm_feedback_display_value (backlight->priv->feedback, (float) percentage/100.0f);
++
++			/* save the new percentage */
++			backlight->priv->master_percentage = percentage;
+ 		}
+ 
+ 	} else if (strcmp (type, GPM_BUTTON_BRIGHT_DOWN) == 0) {
+ 
+ 		if (backlight->priv->can_dim == TRUE) {
++			/* go down one step */
+ 			gpm_brightness_lcd_down (backlight->priv->brightness);
++
++			/* get the new value */
++			gpm_brightness_lcd_get (backlight->priv->brightness, &percentage);
++			gpm_feedback_display_value (backlight->priv->feedback, (float) percentage/100.0f);
++
++			/* save the new percentage */
++			backlight->priv->master_percentage = percentage;
+ 		}
+ 
+ 	} else if (strcmp (type, GPM_BUTTON_LID_OPEN) == 0) {
+@@ -863,10 +883,16 @@
+ 			   GPM_CONF_GNOME_SS_PM_DELAY,
+ 			   backlight->priv->idle_dim_timeout);
+ 
++	/* set the main brightness, this is designed to be updated if the user changes the
++	 * brightness so we can undim to the 'correct' value */
++	gpm_conf_get_uint (backlight->priv->conf,
++			   GPM_CONF_BACKLIGHT_BRIGHTNESS_AC,
++			   &backlight->priv->master_percentage);
++
+ 	/* watch for brightness up and down buttons and also check lid state */
+ 	backlight->priv->button = gpm_button_new ();
+ 	g_signal_connect (backlight->priv->button, "button-pressed",
+-			  G_CALLBACK (button_pressed_cb), backlight);
++			  G_CALLBACK (gpm_backlight_button_pressed_cb), backlight);
+ 
+ 	/* we use ac_adapter for the ac-adapter-changed signal */
+ 	backlight->priv->ac_adapter = gpm_ac_adapter_new ();
_______________________________________________
gNewSense-dev mailing list
gNewSense-dev@nongnu.org
http://lists.nongnu.org/mailman/listinfo/gnewsense-dev

Reply via email to