[gpm] Changing Backlight



So,

In process of trying to fix a bunch of backlight idle and other
backlight changing bugs I ended up reworking the evaluation function.
Basically the approach that I'm taking here is that there are system
events, and those cause changes, rather than going to absolute values
based on them.  I've been using this on my laptop, and I like the
behavior much better.  I would like to hear other people's comments on
the patch (attached).

		--Ted

diff -ur gnome-power-manager-orig/src/gpm-backlight.c gnome-power-manager-ted/src/gpm-backlight.c
--- gnome-power-manager-orig/src/gpm-backlight.c	2007-11-18 07:36:20.000000000 -0800
+++ gnome-power-manager-ted/src/gpm-backlight.c	2008-03-06 13:21:16.000000000 -0800
@@ -81,6 +81,8 @@
 	GTimer			*idle_timer;
 	gfloat			 ambient_sensor_value;
 	guint			 idle_dim_timeout;
+	gboolean		 old_system_is_idle;
+	gboolean		 old_on_ac;
 };
 
 enum {
@@ -315,9 +317,8 @@
 		return FALSE;
 	}
 
-	/* 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
+	/* gpm_conf_set_uint (backlight->priv->conf, GPM_CONF_BACKLIGHT_BRIGHTNESS_AC, brightness); */
+#if 1
 	gboolean ret;
 	/* sets the current policy brightness */
 	ret = gpm_brightness_lcd_set_std (backlight->priv->brightness, brightness);
@@ -357,6 +358,7 @@
 	gboolean enable_action;
 	gboolean battery_reduce;
 	guint value;
+	guint value_ac;
 	guint old_value;
 
 	if (backlight->priv->can_dim == FALSE) {
@@ -370,24 +372,47 @@
 		return FALSE;
 	}
 
-	/* get the 'main' brightness */
-	gpm_conf_get_uint (backlight->priv->conf, GPM_CONF_BACKLIGHT_BRIGHTNESS_AC, &value);
+	/* get the current brightness */
+	gpm_brightness_lcd_get (backlight->priv->brightness, &value);
 	brightness = value / 100.0f;
-	gpm_debug ("1. main brightness %f", brightness);
+	gpm_debug ("1. currently set brightness %f", brightness);
 
 	/* get AC status */
 	on_ac = gpm_ac_adapter_is_present (backlight->priv->ac_adapter);
 
 	/* reduce if on battery power if we should */
 	gpm_conf_get_bool (backlight->priv->conf, GPM_CONF_BACKLIGHT_BATTERY_REDUCE, &battery_reduce);
-	if (on_ac == FALSE && battery_reduce == TRUE) {
+	if (battery_reduce == TRUE && on_ac != backlight->priv->old_on_ac) {
 		gpm_conf_get_uint (backlight->priv->conf, GPM_CONF_BACKLIGHT_BRIGHTNESS_BATT, &value);
-		scale = (100 - value) / 100.0f;
-		brightness *= scale;
-	} else {
-		scale = 1.0f;
+		gpm_conf_get_uint (backlight->priv->conf, GPM_CONF_BACKLIGHT_BRIGHTNESS_AC, &value_ac);
+
+		value = value_ac - value;
+		scale = value / 100.0f;
+
+		if (scale > 0.0f && scale < 1.0f) {
+			if (!on_ac) {
+				scale = -scale;
+			}
+		} else {
+			scale = 0.0f;
+		}
+
+		/* Never let going on battery turn off the display */
+		if (brightness + scale < 0.05f) {
+			scale = 0.05f - brightness;
+			if (scale > 0.0f) {
+				scale = 0.0f;
+			}
+		}
+		/* Never go over 100% -- it goes to 11! */
+		if (brightness + scale > 1.0f) {
+			scale = 1.0f - brightness;
+		}
+
+		brightness += scale;
 	}
-	gpm_debug ("2. battery scale %f, brightness %f", scale, brightness);
+	backlight->priv->old_on_ac = on_ac;
+	gpm_debug ("2. battery change by %f, brightness %f", scale, brightness);
 
 	/* reduce if system is momentarily idle */
 	if (on_ac == TRUE) {
@@ -395,14 +420,37 @@
 	} else {
 		gpm_conf_get_bool (backlight->priv->conf, GPM_CONF_BACKLIGHT_IDLE_DIM_BATT, &enable_action);
 	}
-	if (enable_action == TRUE && backlight->priv->system_is_idle == TRUE) {
+	if (enable_action == TRUE && backlight->priv->system_is_idle != backlight->priv->old_system_is_idle) {
 		gpm_conf_get_uint (backlight->priv->conf, GPM_CONF_BACKLIGHT_IDLE_BRIGHTNESS, &value);
+		gpm_conf_get_uint (backlight->priv->conf, GPM_CONF_BACKLIGHT_BRIGHTNESS_AC, &value_ac);
+
+		value = value_ac - value;
 		scale = value / 100.0f;
-		brightness *= scale;
-	} else {
-		scale = 1.0f;
+
+		if (scale > 0.0f && scale < 1.0f) {
+			if (!on_ac) {
+				scale = -scale;
+			}
+		} else {
+			scale = 0.0f;
+		}
+
+		/* Never let idle turn off the display */
+		if (brightness + scale < 0.05f) {
+			scale = 0.05f - brightness;
+			if (scale > 0.0f) {
+				scale = 0.0f;
+			}
+		}
+		/* Never go over 100% -- it goes to 11! */
+		if (brightness + scale > 1.0f) {
+			scale = 1.0f - brightness;
+		}
+
+		brightness += scale;
 	}
-	gpm_debug ("3. idle scale %f, brightness %f", scale, brightness);
+	backlight->priv->old_system_is_idle = backlight->priv->system_is_idle;
+	gpm_debug ("3. idle change by %f, brightness %f", scale, brightness);
 
 	/* reduce if ambient is low */
 	gpm_conf_get_bool (backlight->priv->conf, GPM_CONF_AMBIENT_ENABLE, &enable_action);
@@ -872,9 +920,11 @@
 	backlight->priv->ac_adapter = gpm_ac_adapter_new ();
 	g_signal_connect (backlight->priv->ac_adapter, "ac-adapter-changed",
 			  G_CALLBACK (ac_adapter_changed_cb), backlight);
+	backlight->priv->old_on_ac = gpm_ac_adapter_is_present (backlight->priv->ac_adapter);
 
 	/* assumption */
 	backlight->priv->system_is_idle = FALSE;
+	backlight->priv->old_system_is_idle = FALSE;
 	gpm_conf_get_uint (backlight->priv->conf,
 			   GPM_CONF_BACKLIGHT_IDLE_DIM_TIME,
 			   &backlight->priv->idle_dim_timeout);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]