[gnome-settings-daemon] power: On raw backlight types, clamp the value to a minumum



commit bb5c1aec2b7e0684c55ee8b1d7025ff0c1acba8e
Author: Rui Matos <tiagomatos gmail com>
Date:   Tue Feb 10 16:56:48 2015 +0100

    power: On raw backlight types, clamp the value to a minumum
    
    On raw backlight types, it's likely that setting it to zero will
    completely turn the backlight off which isn't very useful. Instead,
    let's always clamp the value to a minimum in that case.
    
    For now we just clamp if the backlight has at least 100 levels but we
    might tweak it as needed.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=744278

 plugins/power/gsd-backlight-helper.c |   29 +++++++++++++++++++++++++++++
 1 files changed, 29 insertions(+), 0 deletions(-)
---
diff --git a/plugins/power/gsd-backlight-helper.c b/plugins/power/gsd-backlight-helper.c
index 1eb264d..0714207 100644
--- a/plugins/power/gsd-backlight-helper.c
+++ b/plugins/power/gsd-backlight-helper.c
@@ -116,6 +116,21 @@ gsd_backlight_helper_get_max (const gchar *filename, GError **error)
        return value;
 }
 
+static gint
+clamp_minimum (gint max, gint value)
+{
+       gint minimum;
+       /* If the interface has less than 100 possible values, it's
+        * likely that 0 doesn't turn the backlight off so we let 0 be
+        * set in that case. */
+       if (max > 99)
+               minimum = 1;
+       else
+               minimum = 0;
+
+       return MAX (value, minimum);
+}
+
 int
 main (int argc, char *argv[])
 {
@@ -223,6 +238,20 @@ main (int argc, char *argv[])
        /* SetBrightness */
        if (set_brightness != -1) {
                gboolean ret = FALSE;
+               gint max = gsd_backlight_helper_get_max (filename, &error);
+
+               if (max < 0) {
+                       g_print ("%s: %s\n",
+                                "Could not get the maximum value of the backlight",
+                                error->message);
+                       g_error_free (error);
+                       retval = GSD_BACKLIGHT_HELPER_EXIT_CODE_ARGUMENTS_INVALID;
+                       goto out;
+               }
+
+               if (type == GSD_BACKLIGHT_TYPE_RAW)
+                       set_brightness = clamp_minimum (max, set_brightness);
+
                ret = gsd_backlight_helper_write (filename, set_brightness, &error);
                if (!ret) {
                        g_print ("%s: %s\n",


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