Re: [gpm] Changing Backlight
- From: Ted Gould <ted ubuntu com>
- To: Richard Hughes <hughsient gmail com>
- Cc: GNOME Power Manager List <gnome-power-manager-list gnome org>
- Subject: Re: [gpm] Changing Backlight
- Date: Fri, 14 Mar 2008 20:51:36 -0700
On Wed, 2008-03-12 at 21:16 +0000, Richard Hughes wrote:
> > + /* Never let going on battery turn off the display */
> > + if (brightness + scale < 0.05f) {
> > + scale = 0.05f - brightness;
>
> Turn off the display? Why is <5% off? 0% should be "low dim" not "off".
Update with this change.
--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-14 20:08:25.000000000 -0700
@@ -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.0f) {
+ scale = 0.0f - 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.0f) {
+ scale = 0.0f - 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);
diff -ur gnome-power-manager-orig/src/gpm-prefs-core.c gnome-power-manager-ted/src/gpm-prefs-core.c
--- gnome-power-manager-orig/src/gpm-prefs-core.c 2008-01-17 13:33:15.000000000 -0800
+++ gnome-power-manager-ted/src/gpm-prefs-core.c 2008-03-14 20:10:46.000000000 -0700
@@ -946,9 +946,9 @@
widget = glade_xml_get_widget (prefs->priv->glade_xml, "hbox_ac_cpu");
gtk_widget_hide_all (widget);
}
- if (prefs->priv->has_lcd == FALSE) {
widget = glade_xml_get_widget (prefs->priv->glade_xml, "hbox_ac_brightness");
gtk_widget_hide_all (widget);
+ if (prefs->priv->has_lcd == FALSE) {
widget = glade_xml_get_widget (prefs->priv->glade_xml, "checkbutton_ac_display_dim");
gtk_widget_hide_all (widget);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]