[gnome-power-manager/gnome-2-32] Use the correct backlight step value when using the legacy fallback device



commit abd02c6724bb78823fd0ebee1956eaf11030ff8d
Author: Will Woods <wwoods redhat com>
Date:   Tue Aug 31 13:36:03 2010 +0100

    Use the correct backlight step value when using the legacy fallback device
    
    The 'legacy fallback' backlight handling code in gnome-power-manager
    increments/decrements the backlight value by one whenever the brightness
    buttons are pressed.
    
    On systems like the Apple MacBook, where the backlight has upwards of 1024
    brightness levels, this doesn't work.
    
    The attached patch uses the gpm_brightness_get_step function (like the
    xrandr-based code does) to properly step the backlight value.
    
    Signed-off-by: Richard Hughes <richard hughsie com>

 src/gpm-brightness.c |   26 ++++++++++++++++++++++----
 1 files changed, 22 insertions(+), 4 deletions(-)
---
diff --git a/src/gpm-brightness.c b/src/gpm-brightness.c
index ef0aba4..aa1c19f 100644
--- a/src/gpm-brightness.c
+++ b/src/gpm-brightness.c
@@ -676,6 +676,7 @@ gboolean
 gpm_brightness_up (GpmBrightness *brightness, gboolean *hw_changed)
 {
 	gboolean ret = FALSE;
+	guint step;
 
 	g_return_val_if_fail (GPM_IS_BRIGHTNESS (brightness), FALSE);
 
@@ -696,8 +697,15 @@ gpm_brightness_up (GpmBrightness *brightness, gboolean *hw_changed)
 		if (brightness->priv->extension_levels < 0)
 			brightness->priv->extension_levels = gpm_brightness_helper_get_value ("get-max-brightness");
 		brightness->priv->extension_current = gpm_brightness_helper_get_value ("get-brightness");
-		if (brightness->priv->extension_current < brightness->priv->extension_levels)
-			ret = gpm_brightness_helper_set_value ("set-brightness", ++brightness->priv->extension_current);
+
+		/* increase by the step, limiting to the maximum possible levels */
+		if (brightness->priv->extension_current < brightness->priv->extension_levels) {
+			step = gpm_brightness_get_step (brightness->priv->extension_levels);
+			brightness->priv->extension_current += step;
+			if (brightness->priv->extension_current > brightness->priv->extension_levels)
+				brightness->priv->extension_current = brightness->priv->extension_levels;
+			ret = gpm_brightness_helper_set_value ("set-brightness", brightness->priv->extension_current);
+		}
 		if (hw_changed != NULL)
 			*hw_changed = ret;
 		brightness->priv->cache_trusted = FALSE;
@@ -719,6 +727,7 @@ gboolean
 gpm_brightness_down (GpmBrightness *brightness, gboolean *hw_changed)
 {
 	gboolean ret = FALSE;
+	guint step;
 
 	g_return_val_if_fail (GPM_IS_BRIGHTNESS (brightness), FALSE);
 
@@ -736,9 +745,18 @@ gpm_brightness_down (GpmBrightness *brightness, gboolean *hw_changed)
 
 	/* legacy fallback */
 	if (!ret) {
+		if (brightness->priv->extension_levels < 0)
+			brightness->priv->extension_levels = gpm_brightness_helper_get_value ("get-max-brightness");
 		brightness->priv->extension_current = gpm_brightness_helper_get_value ("get-brightness");
-		if (brightness->priv->extension_current > 0)
-			ret = gpm_brightness_helper_set_value ("set-brightness", --brightness->priv->extension_current);
+
+		/* decrease by the step, limiting to zero */
+		if (brightness->priv->extension_current > 0) {
+			step = gpm_brightness_get_step (brightness->priv->extension_levels);
+			brightness->priv->extension_current -= step;
+			if (brightness->priv->extension_current < 0)
+				brightness->priv->extension_current = 0;
+			ret = gpm_brightness_helper_set_value ("set-brightness", brightness->priv->extension_current);
+		}
 		if (hw_changed != NULL)
 			*hw_changed = ret;
 		brightness->priv->cache_trusted = FALSE;



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