[Xfce4-commits] [xfce/xfce4-power-manager] 09/17: Install property to track current brightness switch value

noreply at xfce.org noreply at xfce.org
Wed Jul 23 22:02:59 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 fc8b491c9828f16176b253593de1218fd5f1e2c4
Author: Harald Judt <h.judt at gmx.at>
Date:   Wed Jul 23 10:31:04 2014 +0200

    Install property to track current brightness switch value
    
    Similar to xfpm-power we set this up in xfpm-backlight.
---
 src/xfpm-backlight.c |   80 ++++++++++++++++++++++++++++++++++++++++++++++++++
 src/xfpm-config.h    |    2 ++
 src/xfpm-xfconf.c    |    4 +++
 3 files changed, 86 insertions(+)

diff --git a/src/xfpm-backlight.c b/src/xfpm-backlight.c
index 4b4dc3e..a2cd0f1 100644
--- a/src/xfpm-backlight.c
+++ b/src/xfpm-backlight.c
@@ -49,6 +49,16 @@
 
 static void xfpm_backlight_finalize     (GObject *object);
 
+static void xfpm_backlight_get_property (GObject *object,
+                                         guint prop_id,
+                                         GValue *value,
+                                         GParamSpec *pspec);
+
+static void xfpm_backlight_set_property (GObject *object,
+                                         guint prop_id,
+                                         const GValue *value,
+                                         GParamSpec *pspec);
+
 #define ALARM_DISABLED 9
 
 #define XFPM_BACKLIGHT_GET_PRIVATE(o) \
@@ -71,12 +81,22 @@ struct XfpmBacklightPrivate
     gint32          last_level;
     gint32 	    max_level;
     
+    gint            brightness_switch;
+
     gboolean        dimmed;
     gboolean	    block;
 };
 
+enum
+{
+    PROP_0,
+    PROP_BRIGHTNESS_SWITCH,
+    N_PROPERTIES
+};
+
 G_DEFINE_TYPE (XfpmBacklight, xfpm_backlight, G_TYPE_OBJECT)
 
+
 static void
 xfpm_backlight_dim_brightness (XfpmBacklight *backlight)
 {
@@ -285,8 +305,19 @@ xfpm_backlight_class_init (XfpmBacklightClass *klass)
 {
     GObjectClass *object_class = G_OBJECT_CLASS (klass);
 
+    object_class->get_property = xfpm_backlight_get_property;
+    object_class->set_property = xfpm_backlight_set_property;
     object_class->finalize = xfpm_backlight_finalize;
 
+    g_object_class_install_property (object_class,
+                                     PROP_BRIGHTNESS_SWITCH,
+                                     g_param_spec_int (BRIGHTNESS_SWITCH,
+                                                       NULL, NULL,
+                                                       -1,
+                                                       1,
+                                                       -1,
+                                                       G_PARAM_READWRITE));
+
     g_type_class_add_private (klass, sizeof (XfpmBacklightPrivate));
 }
 
@@ -319,6 +350,7 @@ xfpm_backlight_init (XfpmBacklight *backlight)
 	backlight->priv->power    = xfpm_power_get ();
 	backlight->priv->notify = xfpm_notify_new ();
 	backlight->priv->max_level = xfpm_brightness_get_max_level (backlight->priv->brightness);
+
 	g_signal_connect (backlight->priv->idle, "alarm-expired",
                           G_CALLBACK (xfpm_backlight_alarm_timeout_cb), backlight);
         
@@ -345,6 +377,54 @@ xfpm_backlight_init (XfpmBacklight *backlight)
 }
 
 static void
+xfpm_backlight_get_property (GObject *object,
+                             guint prop_id,
+                             GValue *value,
+                             GParamSpec *pspec)
+{
+    XfpmBacklight *backlight = XFPM_BACKLIGHT (object);
+
+    switch (prop_id)
+    {
+    case PROP_BRIGHTNESS_SWITCH:
+        g_value_set_int (value, backlight->priv->brightness_switch);
+        break;
+    default:
+        G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+        break;
+    }
+}
+
+static void
+xfpm_backlight_set_property (GObject *object,
+                             guint prop_id,
+                             const GValue *value,
+                             GParamSpec *pspec)
+{
+    XfpmBacklight *backlight = XFPM_BACKLIGHT (object);
+    gboolean ret;
+
+    switch (prop_id)
+    {
+	case PROP_BRIGHTNESS_SWITCH:
+        backlight->priv->brightness_switch = g_value_get_int (value);
+        ret = xfpm_brightness_set_switch (backlight->priv->brightness,
+                                          backlight->priv->brightness_switch);
+        if (!ret)
+            g_warning ("Unable to set the kernel brightness switch parameter to %d.",
+                       backlight->priv->brightness_switch);
+        else
+            g_message ("Set kernel brightness switch to %d",
+                       backlight->priv->brightness_switch);
+
+	    break;
+    default:
+        G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+        break;
+    }
+}
+
+static void
 xfpm_backlight_finalize (GObject *object)
 {
     XfpmBacklight *backlight;
diff --git a/src/xfpm-config.h b/src/xfpm-config.h
index e434cf9..488f1de 100644
--- a/src/xfpm-config.h
+++ b/src/xfpm-config.h
@@ -67,6 +67,8 @@ G_BEGIN_DECLS
 #define     	SHOW_BRIGHTNESS_POPUP        	"show-brightness-popup"
 #define     	HANDLE_BRIGHTNESS_KEYS          "handle-brightness-keys"
 
+#define     	BRIGHTNESS_SWITCH        	"brightness-switch"
+
 #define 	SHOW_TRAY_ICON_CFG          	"show-tray-icon"
 #define 	CRITICAL_BATT_ACTION_CFG    	"critical-power-action"
 
diff --git a/src/xfpm-xfconf.c b/src/xfpm-xfconf.c
index 35acda8..decd308 100644
--- a/src/xfpm-xfconf.c
+++ b/src/xfpm-xfconf.c
@@ -193,6 +193,10 @@ xfpm_xfconf_property_changed_cb (XfconfChannel *channel, gchar *property,
          g_strcmp0 (property, "/xfce4-power-manager/blank-on-battery") == 0)
         return;
 
+    /* We handle brightness switch in xfpm-backlight directly */
+    if ( g_strcmp0 (property, PROPERTIES_PREFIX BRIGHTNESS_SWITCH) == 0 )
+        return;
+
     XFPM_DEBUG ("Property modified: %s\n", property);
     
     g_object_set_property (G_OBJECT (conf), property + strlen (PROPERTIES_PREFIX), value);

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


More information about the Xfce4-commits mailing list