[gnome-settings-daemon] power: discretize the set backlight value



commit cb655c963114dc5744ac0d14b81827f572236fe5
Author: Giovanni Campagna <gcampagna src gnome org>
Date:   Sat May 3 19:22:47 2014 +0200

    power: discretize the set backlight value
    
    Most firmware backlight devices only allow a limited number of
    backlight settings (around 10 or 15), but we previously sometime
    failed to map the value from outside onto the discrete set of allowed
    percentages.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=729500

 plugins/power/gpm-common.c        |   14 ++++++++++----
 plugins/power/gpm-common.h        |    2 +-
 plugins/power/gsd-power-manager.c |    2 +-
 3 files changed, 12 insertions(+), 6 deletions(-)
---
diff --git a/plugins/power/gpm-common.c b/plugins/power/gpm-common.c
index a16846e..dbe610e 100644
--- a/plugins/power/gpm-common.c
+++ b/plugins/power/gpm-common.c
@@ -576,7 +576,7 @@ backlight_get_max (GnomeRRScreen *rr_screen, GError **error)
 
 gboolean
 backlight_set_percentage (GnomeRRScreen *rr_screen,
-                          guint value,
+                          gint *value,
                           GError **error)
 {
         GnomeRROutput *output;
@@ -587,17 +587,23 @@ backlight_set_percentage (GnomeRRScreen *rr_screen,
 
         /* prefer xbacklight */
         output = get_primary_output (rr_screen);
-        if (output != NULL)
-                return gnome_rr_output_set_backlight (output, value, error);
+        if (output != NULL) {
+                if (!gnome_rr_output_set_backlight (output, *value, error))
+                        return ret;
+                *value = gnome_rr_output_get_backlight (output);
+                return TRUE;
+        }
 
         /* fall back to the polkit helper */
         max = backlight_helper_get_value ("get-max-brightness", error);
         if (max < 0)
                 return ret;
-        discrete = PERCENTAGE_TO_ABS (min, max, value);
+        discrete = PERCENTAGE_TO_ABS (min, max, *value);
         ret = backlight_helper_set_value ("set-brightness",
                                           discrete,
                                           error);
+        if (ret)
+                *value = ABS_TO_PERCENTAGE (min, max, discrete);
 
         return ret;
 }
diff --git a/plugins/power/gpm-common.h b/plugins/power/gpm-common.h
index 422f130..675dfeb 100644
--- a/plugins/power/gpm-common.h
+++ b/plugins/power/gpm-common.h
@@ -50,7 +50,7 @@ int              backlight_get_percentage               (GnomeRRScreen *rr_scree
 int              backlight_get_min                      (GnomeRRScreen *rr_screen);
 int              backlight_get_max                      (GnomeRRScreen *rr_screen, GError **error);
 gboolean         backlight_set_percentage               (GnomeRRScreen *rr_screen,
-                                                         guint value,
+                                                         gint *value,
                                                          GError **error);
 int              backlight_step_up                      (GnomeRRScreen *rr_screen, GError **error);
 int              backlight_step_down                    (GnomeRRScreen *rr_screen, GError **error);
diff --git a/plugins/power/gsd-power-manager.c b/plugins/power/gsd-power-manager.c
index 54e3782..d4c15be 100644
--- a/plugins/power/gsd-power-manager.c
+++ b/plugins/power/gsd-power-manager.c
@@ -2647,7 +2647,7 @@ handle_set_property_other (GsdPowerManager *manager,
 
         if (g_strcmp0 (interface_name, GSD_POWER_DBUS_INTERFACE_SCREEN) == 0) {
                 g_variant_get (value, "i", &brightness_value);
-                if (backlight_set_percentage (manager->priv->rr_screen, brightness_value, error)) {
+                if (backlight_set_percentage (manager->priv->rr_screen, &brightness_value, error)) {
                         backlight_iface_emit_changed (manager, GSD_POWER_DBUS_INTERFACE_SCREEN, 
brightness_value);
                         return TRUE;
                 } else {


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