[Xfce4-commits] [panel-plugins/xfce4-battery-plugin] 01/01: Listen for UPower events for power source changes (Bug #14978)

noreply at xfce.org noreply at xfce.org
Sun Dec 16 22:23:19 CET 2018


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

a   n   d   r   e       p   u   s   h   e   d       a       c   o   m   m   i   t       t   o       b   r   a   n   c   h       m   a   s   t   e   r   
   in repository panel-plugins/xfce4-battery-plugin.

commit 205a18e99c554529b282b3f30e1cd8e40a5efa55
Author: Alexander Butenko <a.butenka at gmail.com>
Date:   Sun Dec 16 10:03:55 2018 -0400

    Listen for UPower events for power source changes (Bug #14978)
---
 configure.ac.in        |  1 +
 panel-plugin/battery.c | 30 ++++++++++++++++++++++++++++++
 2 files changed, 31 insertions(+)

diff --git a/configure.ac.in b/configure.ac.in
index 7d7810b..3a0ce3f 100644
--- a/configure.ac.in
+++ b/configure.ac.in
@@ -69,6 +69,7 @@ XDT_CHECK_PACKAGE([GTK], [gtk+-3.0], [3.16.0])
 XDT_CHECK_PACKAGE([LIBXFCE4UTIL], [libxfce4util-1.0], [4.8.0])
 XDT_CHECK_PACKAGE([LIBXFCE4UI], [libxfce4ui-2], [4.12.0])
 XDT_CHECK_PACKAGE([LIBXFCE4PANEL], [libxfce4panel-2.0], [4.12.0])
+XDT_CHECK_PACKAGE([GIO_UNIX], [gio-2.0], [2.28.0], [gio], [GIO UNIX features])
 
 dnl ***********************************
 dnl *** Check for debugging support ***
diff --git a/panel-plugin/battery.c b/panel-plugin/battery.c
index c516742..e45a458 100644
--- a/panel-plugin/battery.c
+++ b/panel-plugin/battery.c
@@ -1376,6 +1376,33 @@ battmon_show_about(XfcePanelPlugin *plugin, t_battmon *battmon)
       g_object_unref(G_OBJECT(icon));
 }
 
+static void
+on_power_change (GDBusProxy  *proxy,
+                 GVariant    *changed_properties,
+                 const gchar *invalidated_properties,
+                 gpointer     battmon)
+{
+    update_apm_status (battmon);
+}
+
+void
+battmon_dbus_monitor (t_battmon *battmon)
+{
+    GDBusProxy *proxy;
+
+    proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM,
+                                           G_DBUS_PROXY_FLAGS_NONE,
+                                           NULL,
+                                           "org.freedesktop.UPower",
+                                           "/org/freedesktop/UPower",
+                                           "org.freedesktop.UPower",
+                                           NULL, NULL);
+
+    g_return_if_fail (proxy != NULL);
+
+    g_signal_connect (proxy, "g-properties-changed", G_CALLBACK (on_power_change), battmon);
+}
+
 /* create the plugin */
 static void
 battmon_construct (XfcePanelPlugin *plugin)
@@ -1417,6 +1444,9 @@ battmon_construct (XfcePanelPlugin *plugin)
     /* Update battery status every 30 seconds */
     if(battmon->timeoutid == 0)
         battmon->timeoutid = g_timeout_add_seconds(30, (GSourceFunc) update_apm_status, battmon);
+
+    /* Update battery status on UPower events like power cord connected, disconnected, lid opened */
+    battmon_dbus_monitor (battmon);
 }
 
 /* register the plugin */

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


More information about the Xfce4-commits mailing list