[Xfce4-commits] [xfce/xfce4-power-manager] 08/17: Implement brightness switch handling in common/xfpm-brightness
noreply at xfce.org
noreply at xfce.org
Wed Jul 23 22:02:58 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 b6cd657502fe307d3150a7c0f453164541ae49ee
Author: Harald Judt <h.judt at gmx.at>
Date: Mon Jul 21 18:12:34 2014 +0200
Implement brightness switch handling in common/xfpm-brightness
This adds the necessary utility functions to read and write the kernel
brightness switch setting.
---
common/xfpm-brightness.c | 71 +++++++++++++++++++++++++++++++++++++++++++++-
common/xfpm-brightness.h | 6 ++++
2 files changed, 76 insertions(+), 1 deletion(-)
diff --git a/common/xfpm-brightness.c b/common/xfpm-brightness.c
index 2b94777..54d2d05 100644
--- a/common/xfpm-brightness.c
+++ b/common/xfpm-brightness.c
@@ -333,7 +333,12 @@ xfpm_brightness_helper_get_value (const gchar *argument)
if ( exit_status != 0 )
goto out;
- value = atoi (stdout_data);
+ if ( stdout_data[0] == 'N' )
+ value = 0;
+ else if ( stdout_data[0] == 'Y' )
+ value = 1;
+ else
+ value = atoi (stdout_data);
out:
g_free (command);
@@ -406,6 +411,46 @@ out:
}
static gboolean
+xfpm_brightness_helper_get_switch (XfpmBrightness *brg, gint *brightness_switch)
+{
+ gint ret;
+
+ ret = xfpm_brightness_helper_get_value ("get-brightness-switch");
+
+ if ( ret >= 0 )
+ {
+ *brightness_switch = ret;
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
+static gboolean
+xfpm_brightness_helper_set_switch (XfpmBrightness *brg, gint brightness_switch)
+{
+ gboolean ret;
+ GError *error = NULL;
+ gint exit_status = 0;
+ gchar *command = NULL;
+
+ command = g_strdup_printf ("pkexec " SBINDIR "/xfpm-power-backlight-helper --set-brightness-switch %i", brightness_switch);
+ ret = g_spawn_command_line_sync (command, NULL, NULL, &exit_status, &error);
+ if ( !ret )
+ {
+ g_warning ("xfpm_brightness_helper_set_switch: failed to set value: %s", error->message);
+ g_error_free (error);
+ goto out;
+ }
+ g_debug ("executed %s; retval: %i", command, exit_status);
+ ret = (exit_status == 0);
+
+out:
+ g_free (command);
+ return ret;
+}
+
+static gboolean
xfpm_brightness_helper_up (XfpmBrightness *brightness, gint32 *new_level)
{
gint32 hw_level;
@@ -659,3 +704,27 @@ gboolean xfpm_brightness_dim_down (XfpmBrightness *brightness)
return ret;
}
+
+gboolean xfpm_brightness_get_switch (XfpmBrightness *brightness, gint *brightness_switch)
+{
+ gboolean ret = FALSE;
+
+#ifdef ENABLE_POLKIT
+ if ( brightness->priv->helper_has_hw )
+ ret = xfpm_brightness_helper_get_switch (brightness, brightness_switch);
+#endif
+
+ return ret;
+}
+
+gboolean xfpm_brightness_set_switch (XfpmBrightness *brightness, gint brightness_switch)
+{
+ gboolean ret = FALSE;
+
+#ifdef ENABLE_POLKIT
+ if ( brightness->priv->helper_has_hw )
+ ret = xfpm_brightness_helper_set_switch (brightness, brightness_switch);
+#endif
+
+ return ret;
+}
diff --git a/common/xfpm-brightness.h b/common/xfpm-brightness.h
index 9cb7a02..990927d 100644
--- a/common/xfpm-brightness.h
+++ b/common/xfpm-brightness.h
@@ -68,6 +68,12 @@ gboolean xfpm_brightness_set_level (XfpmBrightness *brightness,
gboolean xfpm_brightness_dim_down (XfpmBrightness *brightness);
+gboolean xfpm_brightness_get_switch (XfpmBrightness *brightness,
+ gint *brightness_switch);
+
+gboolean xfpm_brightness_set_switch (XfpmBrightness *brightness,
+ gint brightness_switch);
+
G_END_DECLS
#endif /* __XFPM_BRIGHTNESS_H */
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the Xfce4-commits
mailing list