From 26531557a24f8f4414e8e44357b173d40297f55f Mon Sep 17 00:00:00 2001 From: Alexander Butenko Date: Sun, 16 Dec 2018 10:03:55 -0400 Subject: [PATCH] Listen for UPower events for power source change --- 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..aba066d 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 = NULL; + GError *error = NULL; + + 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, + &error); + if (proxy == NULL) + return; + 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 coord connected, disconnected, lid opened */ + battmon_dbus_monitor (battmon); } /* register the plugin */ -- 2.19.1