[Xfce4-commits] [xfce/xfce4-power-manager] 16/17: Remember and restore original kernel brightness switch setting
noreply at xfce.org
noreply at xfce.org
Wed Jul 23 22:03:06 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 b29ae06dd57a2e49d719ce8d43819bf1da09b580
Author: Harald Judt <h.judt at gmx.at>
Date: Wed Jul 23 18:48:17 2014 +0200
Remember and restore original kernel brightness switch setting
On startup, save the kernel brightness switch setting and restore it
on exit. If xfce4-power-manager has crashed, restore it on the next
run.
---
src/xfpm-backlight.c | 58 ++++++++++++++++++++++++++++++++++++++++++++++----
1 file changed, 54 insertions(+), 4 deletions(-)
diff --git a/src/xfpm-backlight.c b/src/xfpm-backlight.c
index e88ade2..97a386f 100644
--- a/src/xfpm-backlight.c
+++ b/src/xfpm-backlight.c
@@ -381,6 +381,33 @@ xfpm_backlight_init (XfpmBacklight *backlight)
NULL);
backlight->priv->brightness_switch_initialized = TRUE;
+ /*
+ * If power manager has crashed last time, the brightness switch
+ * saved value will be set to the original value. In that case, we
+ * will use this saved value instead of the one found at the
+ * current startup so the setting is restored properly.
+ */
+ backlight->priv->brightness_switch_save =
+ xfconf_channel_get_int (xfpm_xfconf_get_channel(backlight->priv->conf),
+ PROPERTIES_PREFIX BRIGHTNESS_SWITCH_SAVE,
+ -1);
+
+ if (backlight->priv->brightness_switch_save == -1)
+ {
+ if (!xfconf_channel_set_int (xfpm_xfconf_get_channel(backlight->priv->conf),
+ PROPERTIES_PREFIX BRIGHTNESS_SWITCH_SAVE,
+ backlight->priv->brightness_switch))
+ g_critical ("Cannot set value for property %s\n", BRIGHTNESS_SWITCH_SAVE);
+
+ backlight->priv->brightness_switch_save = backlight->priv->brightness_switch;
+ }
+ else
+ {
+ g_warning ("It seems the kernel brightness switch handling value was "
+ "not restored properly on exit last time, xfce4-power-manager "
+ "will try to restore it this time.");
+ }
+
/* check whether to change the brightness switch */
handle_keys = xfconf_channel_get_bool (xfpm_xfconf_get_channel(backlight->priv->conf),
PROPERTIES_PREFIX HANDLE_BRIGHTNESS_KEYS,
@@ -481,14 +508,37 @@ xfpm_backlight_finalize (GObject *object)
xfpm_backlight_destroy_popup (backlight);
- if ( backlight->priv->brightness )
- g_object_unref (backlight->priv->brightness);
-
if ( backlight->priv->idle )
g_object_unref (backlight->priv->idle);
if ( backlight->priv->conf )
- g_object_unref (backlight->priv->conf);
+ {
+ /* restore video module brightness switch setting */
+ if ( backlight->priv->brightness_switch_save != -1 )
+ {
+ gboolean ret =
+ xfpm_brightness_set_switch (backlight->priv->brightness,
+ backlight->priv->brightness_switch_save);
+ /* unset the xfconf saved value after the restore */
+ if (!xfconf_channel_set_int (xfpm_xfconf_get_channel(backlight->priv->conf),
+ PROPERTIES_PREFIX BRIGHTNESS_SWITCH_SAVE, -1))
+ g_critical ("Cannot set value for property %s\n", BRIGHTNESS_SWITCH_SAVE);
+
+ if (ret)
+ {
+ backlight->priv->brightness_switch = backlight->priv->brightness_switch_save;
+ g_message ("Restored brightness switch value to: %d", backlight->priv->brightness_switch);
+ }
+ else
+ g_warning ("Unable to restore the kernel brightness switch parameter to its original value, "
+ "still resetting the saved value.");
+ }
+
+ g_object_unref (backlight->priv->conf);
+ }
+
+ if ( backlight->priv->brightness )
+ g_object_unref (backlight->priv->brightness);
if ( backlight->priv->button )
g_object_unref (backlight->priv->button);
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the Xfce4-commits
mailing list