[Xfce4-commits] <xfce4-power-manager:master> Trigger notification on XF86XK_Battery key press

Ali Abdallah noreply at xfce.org
Tue Feb 15 10:04:07 CET 2011


Updating branch refs/heads/master
         to 42af0e50ca1c9ec25976beadde2ace326d0cd106 (commit)
       from ed9fda2c908c1c0a080de34d61b536acc70f0195 (commit)

commit 42af0e50ca1c9ec25976beadde2ace326d0cd106
Author: Ali Abdallah <aliov at xfce.org>
Date:   Tue Feb 15 10:02:19 2011 +0100

    Trigger notification on XF86XK_Battery key press

 src/xfpm-battery.c   |   42 +++++++++++++++++++++++++++++++-----------
 src/xfpm-battery.h   |    1 -
 src/xfpm-button.c    |    2 ++
 src/xfpm-enum-glib.h |    1 +
 src/xfpm-power.c     |    1 -
 5 files changed, 34 insertions(+), 13 deletions(-)

diff --git a/src/xfpm-battery.c b/src/xfpm-battery.c
index 26e2560..c701f14 100644
--- a/src/xfpm-battery.c
+++ b/src/xfpm-battery.c
@@ -36,6 +36,7 @@
 #include "xfpm-xfconf.h"
 #include "xfpm-notify.h"
 #include "xfpm-config.h"
+#include "xfpm-button.h"
 #include "xfpm-enum-glib.h"
 #include "xfpm-enum-types.h"
 #include "xfpm-debug.h"
@@ -51,6 +52,7 @@ struct XfpmBatteryPrivate
 {
     XfpmXfconf             *conf;
     XfpmNotify		   *notify;
+    XfpmButton             *button;
     DBusGProxy             *proxy;
     DBusGProxy 		   *proxy_prop;
     
@@ -65,10 +67,10 @@ struct XfpmBatteryPrivate
     gint64		    time_to_full;
     gint64		    time_to_empty;
 
-    const gchar            *backend_iface_device; /*upower or devkit*/
     const gchar            *battery_name;
     
     gulong		    sig;
+    gulong		    sig_bt;
 };
 
 enum
@@ -322,18 +324,15 @@ xfpm_battery_refresh_icon (XfpmBattery *battery)
     gtk_status_icon_set_from_icon_name (GTK_STATUS_ICON (battery), icon_name);
 }
 
-static gboolean
-xfpm_battery_notify_idle (gpointer data)
+static void
+xfpm_battery_notify (XfpmBattery *battery)
 {
-    XfpmBattery *battery;
     gchar *message = NULL;
     
-    battery = XFPM_BATTERY (data);
-    
     message = xfpm_battery_get_message_from_battery_state (battery);
     
     if ( !message )
-	return FALSE;
+	return;
 	
     xfpm_notify_show_notification (battery->priv->notify, 
 				   _("Power Manager"), 
@@ -345,7 +344,14 @@ xfpm_battery_notify_idle (gpointer data)
 				   GTK_STATUS_ICON (battery));
     
     g_free (message);
-    
+}
+
+static gboolean
+xfpm_battery_notify_idle (gpointer data)
+{
+    XfpmBattery *battery;
+    battery = XFPM_BATTERY (data);
+    xfpm_battery_notify (battery);
     return FALSE;
 }
 
@@ -574,12 +580,19 @@ xfpm_battery_refresh (XfpmBattery *battery, GHashTable *props)
 }
 
 static void
+xfpm_battery_button_pressed_cb (XfpmButton *button, XfpmButtonKey type, XfpmBattery *battery)
+{
+    if (type == BUTTON_BATTERY)
+	xfpm_battery_notify (battery);
+}
+
+static void
 xfpm_battery_changed_cb (DBusGProxy *proxy, XfpmBattery *battery)
 {
     GHashTable *props;
     
     props = xfpm_power_get_interface_properties (battery->priv->proxy_prop, 
-						 battery->priv->backend_iface_device);
+						 UPOWER_IFACE_DEVICE);
     
     if ( props )
 	xfpm_battery_refresh (battery, props);
@@ -721,10 +734,15 @@ xfpm_battery_init (XfpmBattery *battery)
     battery->priv->icon_prefix   = NULL;
     battery->priv->time_to_full  = 0;
     battery->priv->time_to_empty = 0;
+    battery->priv->button        = xfpm_button_new ();
     battery->priv->ac_online     = TRUE;
     
     battery->priv->sig = g_signal_connect (G_OBJECT (battery->priv->conf), "notify::" SHOW_TRAY_ICON_CFG,
 					   G_CALLBACK (xfpm_battery_tray_icon_settings_changed), battery);
+					   
+    
+    battery->priv->sig_bt = g_signal_connect (G_OBJECT (battery->priv->button), "button-pressed",
+					   G_CALLBACK (xfpm_battery_button_pressed_cb), battery);
 }
 
 static void
@@ -741,11 +759,15 @@ xfpm_battery_finalize (GObject *object)
 				    
     if ( g_signal_handler_is_connected (battery->priv->conf, battery->priv->sig ) )
 	g_signal_handler_disconnect (G_OBJECT (battery->priv->conf), battery->priv->sig);
+	
+     if ( g_signal_handler_is_connected (battery->priv->button, battery->priv->sig_bt ) )
+	g_signal_handler_disconnect (G_OBJECT (battery->priv->button), battery->priv->sig_bt);
 				    
     g_object_unref (battery->priv->proxy);
     g_object_unref (battery->priv->proxy_prop);
     g_object_unref (battery->priv->conf);
     g_object_unref (battery->priv->notify);
+    g_object_unref (battery->priv->button);
 
     G_OBJECT_CLASS (xfpm_battery_parent_class)->finalize (object);
 }
@@ -826,14 +848,12 @@ xfpm_battery_new (void)
 void xfpm_battery_monitor_device (XfpmBattery *battery,
 				  DBusGProxy *proxy,
 				  DBusGProxy *proxy_prop,
-				  const gchar *backend_iface_device,
 				  XfpmDeviceType device_type)
 {
     battery->priv->type = device_type;
     battery->priv->proxy_prop = proxy_prop;
     battery->priv->proxy = proxy;
     battery->priv->icon_prefix = xfpm_battery_get_icon_prefix_device_enum_type (device_type);
-    battery->priv->backend_iface_device = backend_iface_device;
     battery->priv->battery_name = xfpm_battery_get_name (device_type);
     
     
diff --git a/src/xfpm-battery.h b/src/xfpm-battery.h
index 116312c..58cb784 100644
--- a/src/xfpm-battery.h
+++ b/src/xfpm-battery.h
@@ -58,7 +58,6 @@ GtkStatusIcon              *xfpm_battery_new             (void);
 void			    xfpm_battery_monitor_device  (XfpmBattery *battery,
 							  DBusGProxy *proxy,
 							  DBusGProxy *proxy_prop,
-							  const gchar *backend_iface_device,
 							  XfpmDeviceType device_type);
 
 XfpmDeviceType	   	    xfpm_battery_get_device_type (XfpmBattery *battery);
diff --git a/src/xfpm-button.c b/src/xfpm-button.c
index d914ded..b93684e 100644
--- a/src/xfpm-button.c
+++ b/src/xfpm-button.c
@@ -211,6 +211,8 @@ xfpm_button_setup (XfpmButton *button)
 	
     if (xfpm_button_xevent_key (button, XF86XK_MonBrightnessDown, BUTTON_MON_BRIGHTNESS_DOWN) )
 	button->priv->mapped_buttons |= BRIGHTNESS_KEY_DOWN;
+	
+    xfpm_button_xevent_key (button, XF86XK_Battery, BUTTON_BATTERY);
 
     gdk_window_add_filter (button->priv->window, 
 			   xfpm_button_filter_x_events, button);
diff --git a/src/xfpm-enum-glib.h b/src/xfpm-enum-glib.h
index 1dcc16e..583e18c 100644
--- a/src/xfpm-enum-glib.h
+++ b/src/xfpm-enum-glib.h
@@ -93,6 +93,7 @@ typedef enum
     BUTTON_MON_BRIGHTNESS_UP,
     BUTTON_MON_BRIGHTNESS_DOWN,
     BUTTON_LID_CLOSED,
+    BUTTON_BATTERY,
     NUMBER_OF_BUTTONS
     
 } XfpmButtonKey;
diff --git a/src/xfpm-power.c b/src/xfpm-power.c
index 2a37601..6f1b563 100644
--- a/src/xfpm-power.c
+++ b/src/xfpm-power.c
@@ -933,7 +933,6 @@ xfpm_power_add_device (XfpmPower *power, const gchar *object_path)
 	xfpm_battery_monitor_device (XFPM_BATTERY (battery), 
 				     proxy, 
 				     proxy_prop, 
-				     UPOWER_IFACE_DEVICE, 
 				     device_type);
 
 	g_hash_table_insert (power->priv->hash, g_strdup (object_path), battery);



More information about the Xfce4-commits mailing list