[gpm] [patch] fixing backlight control
- From: Andy Wingo <wingo pobox com>
- To: gnome-power-manager-list <gnome-power-manager-list gnome org>
- Subject: [gpm] [patch] fixing backlight control
- Date: Sat, 19 Jan 2008 12:19:15 +0100
Hello,
Please find attached a patch to implement the algorithm I discussed last
week.
Thanks,
Andy
--
http://wingolog.org/
--- gnome-power-manager-2.21.1.orig/src/gpm-brightness-lcd.c
+++ gnome-power-manager-2.21.1/src/gpm-brightness-lcd.c
@@ -322,7 +322,7 @@
* If possible, put the brightness of the LCD up one unit.
**/
gboolean
-gpm_brightness_lcd_up (GpmBrightnessLcd *brightness)
+gpm_brightness_lcd_up (GpmBrightnessLcd *brightness, guint *new_percentage)
{
gint step;
gint percentage;
@@ -349,6 +349,7 @@
percentage = gpm_discrete_to_percent (brightness->priv->last_set_hw,
brightness->priv->levels);
+ *new_percentage = percentage;
gpm_debug ("emitting brightness-changed (%i)", percentage);
g_signal_emit (brightness, signals [BRIGHTNESS_CHANGED], 0, percentage);
@@ -362,7 +363,7 @@
* If possible, put the brightness of the LCD down one unit.
**/
gboolean
-gpm_brightness_lcd_down (GpmBrightnessLcd *brightness)
+gpm_brightness_lcd_down (GpmBrightnessLcd *brightness, guint *new_percentage)
{
gint step;
gint percentage;
@@ -389,6 +390,7 @@
percentage = gpm_discrete_to_percent (brightness->priv->last_set_hw,
brightness->priv->levels);
+ *new_percentage = percentage;
gpm_debug ("emitting brightness-changed (%i)", percentage);
g_signal_emit (brightness, signals [BRIGHTNESS_CHANGED], 0, percentage);
--- gnome-power-manager-2.21.1.orig/src/gpm-brightness-lcd.h
+++ gnome-power-manager-2.21.1/src/gpm-brightness-lcd.h
@@ -53,8 +53,10 @@
GpmBrightnessLcd *gpm_brightness_lcd_new (void);
gboolean gpm_brightness_lcd_has_hw (void);
-gboolean gpm_brightness_lcd_up (GpmBrightnessLcd *brightness);
-gboolean gpm_brightness_lcd_down (GpmBrightnessLcd *brightness);
+gboolean gpm_brightness_lcd_up (GpmBrightnessLcd *brightness,
+ guint *new_percentage);
+gboolean gpm_brightness_lcd_down (GpmBrightnessLcd *brightness,
+ guint *new_percentage);
gboolean gpm_brightness_lcd_get (GpmBrightnessLcd *brightness,
guint *brightness_level);
gboolean gpm_brightness_lcd_set_std (GpmBrightnessLcd *brightness,
--- gnome-power-manager-2.21.1.orig/src/gpm-backlight.c
+++ gnome-power-manager-2.21.1/src/gpm-backlight.c
@@ -500,6 +490,49 @@
gpm_backlight_brightness_evaluate_and_set (backlight, TRUE);
}
+static void
+adjust_brightness (GpmBacklight *backlight,
+ gboolean (*do_adjust_brightness)(GpmBrightnessLcd*, guint*))
+{
+ guint brightness, brightness_ac;
+ gboolean success, battery_reduce;
+
+ if (!backlight->priv->can_dim)
+ return;
+
+ success = do_adjust_brightness (backlight->priv->brightness,
+ &brightness);
+ if (!success)
+ return;
+
+ if (!gpm_ac_adapter_is_present (backlight->priv->ac_adapter)
+ && gpm_conf_get_uint (backlight->priv->conf,
+ GPM_CONF_BACKLIGHT_BRIGHTNESS_AC,
+ &brightness_ac)
+ && gpm_conf_get_bool (backlight->priv->conf,
+ GPM_CONF_BACKLIGHT_BATTERY_REDUCE,
+ &battery_reduce)
+ && battery_reduce) {
+ if (brightness >= brightness_ac) {
+ gpm_conf_set_uint (backlight->priv->conf,
+ GPM_CONF_BACKLIGHT_BRIGHTNESS_AC,
+ brightness);
+ gpm_conf_set_uint (backlight->priv->conf,
+ GPM_CONF_BACKLIGHT_BRIGHTNESS_BATT,
+ 0);
+ } else {
+ gpm_conf_set_uint (backlight->priv->conf,
+ GPM_CONF_BACKLIGHT_BRIGHTNESS_BATT,
+ (brightness_ac - brightness) * 100 / brightness_ac);
+ }
+ } else {
+ gpm_conf_set_uint (backlight->priv->conf,
+ GPM_CONF_BACKLIGHT_BRIGHTNESS_AC,
+ brightness);
+ }
+}
+
+
/**
* button_pressed_cb:
* @power: The power class instance
@@ -516,16 +549,10 @@
if (strcmp (type, GPM_BUTTON_BRIGHT_UP) == 0) {
- if (backlight->priv->can_dim == TRUE) {
- gpm_brightness_lcd_up (backlight->priv->brightness);
- }
-
+ adjust_brightness (backlight, gpm_brightness_lcd_up);
} else if (strcmp (type, GPM_BUTTON_BRIGHT_DOWN) == 0) {
- if (backlight->priv->can_dim == TRUE) {
- gpm_brightness_lcd_down (backlight->priv->brightness);
- }
-
+ adjust_brightness (backlight, gpm_brightness_lcd_down);
} else if (strcmp (type, GPM_BUTTON_LID_OPEN) == 0) {
/* make sure we undim when we lift the lid */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]