[Xfce4-commits] [xfce/xfce4-power-manager] 03/07: Use xfconf property for limiting the minimum brightness of the plugin slider

noreply at xfce.org noreply at xfce.org
Tue Aug 5 10:08:46 CEST 2014


This is an automated email from the git hooks/post-receive script.

hjudt pushed a commit to branch master
in repository xfce/xfce4-power-manager.

commit a1dc21d9053bc2da26e6479f882916ba656f1f0e
Author: Harald Judt <h.judt at gmx.at>
Date:   Mon Aug 4 23:19:39 2014 +0200

    Use xfconf property for limiting the minimum brightness of the plugin slider
    
    This makes use of the xfconf property introduced in the previous commit.
    Initially, min_level is set to -1, which causes automatic determination of
    the best minimum level when the slider is created.
    
    Setting a minimum level other than 0 might only make sense for newer
    laptops, which can be heuristically determined by looking at the available
    range of brightness steps. Any backlight interface providing more than 100
    steps will set the minimum level the slider will support to 5, which is
    barely enough light to see the screen contents. The user can change this
    via xfce4-settings-editor, or its command line companion xfconf-query.
---
 panel-plugins/battery/battery-button.c |   25 +++++++++++++++++++++++--
 1 file changed, 23 insertions(+), 2 deletions(-)

diff --git a/panel-plugins/battery/battery-button.c b/panel-plugins/battery/battery-button.c
index 0570ce5..84a69c9 100644
--- a/panel-plugins/battery/battery-button.c
+++ b/panel-plugins/battery/battery-button.c
@@ -43,6 +43,7 @@
 
 
 #define SET_LEVEL_TIMEOUT (50)
+#define SAFE_SLIDER_MIN_LEVEL (5)
 
 #define BATTERY_BUTTON_GET_PRIVATE(o) \
 (G_TYPE_INSTANCE_GET_PRIVATE ((o), BATTERY_TYPE_BUTTON, BatteryButtonPrivate))
@@ -876,7 +877,7 @@ battery_button_show_menu (BatteryButton *button)
     GdkScreen *gscreen;
     GList *item;
     gboolean show_separator_flag = FALSE;
-    gint32 max_level, current_level = 0;
+    gint32 min_level, max_level, current_level = 0;
 
     if(gtk_widget_has_screen(GTK_WIDGET(button)))
         gscreen = gtk_widget_get_screen(GTK_WIDGET(button));
@@ -913,7 +914,26 @@ battery_button_show_menu (BatteryButton *button)
 
         max_level = xfpm_brightness_get_max_level (button->priv->brightness);
 
-        mi = scale_menu_item_new_with_range (0, max_level, 1);
+        /* determine minimum value for slider */
+        min_level = xfconf_channel_get_int (button->priv->channel,
+                                            "/xfce4-power-manager/brightness-slider-min-level",
+                                            -1);
+        if (min_level == -1)
+        {
+            /* Some laptops (and mostly newer ones with intel graphics) can turn off the
+             * backlight completely. If the user is not careful and sets the brightness
+             * very low using the slider, he might not be able to see the screen contents
+             * anymore. Brightness keys do not work on every laptop, so it's better to use
+             * a safe default minimum level that the user can change via the settings
+             * editor if desired.
+             */
+            min_level = (max_level > 100) ? SAFE_SLIDER_MIN_LEVEL : 0;
+            xfconf_channel_set_int (button->priv->channel,
+                                    "/xfce4-power-manager/brightness-slider-min-level",
+                                    min_level);
+        }
+
+        mi = scale_menu_item_new_with_range (min_level, max_level, 1);
 
         /* attempt to load and display the brightness icon */
         pix = gtk_icon_theme_load_icon (gtk_icon_theme_get_default (),
@@ -935,6 +955,7 @@ battery_button_show_menu (BatteryButton *button)
         /* update the slider to the current brightness level */
         xfpm_brightness_get_level (button->priv->brightness, &current_level);
         gtk_range_set_value (GTK_RANGE(button->priv->range), current_level);
+
         g_signal_connect (mi, "value-changed", G_CALLBACK (range_value_changed_cb), button);
         g_signal_connect (mi, "scroll-event", G_CALLBACK (range_scroll_cb), button);
         g_signal_connect (menu, "show", G_CALLBACK (range_show_cb), button);

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the Xfce4-commits mailing list