[Xfce4-commits] <xfce4-power-manager:devkit-power> Survive D-Bus system bus restarts.
Ali Abdallah
noreply at xfce.org
Fri Nov 6 14:40:04 CET 2009
Updating branch refs/heads/devkit-power
to 9b5cb60049ed2c355a0c498bde810fb6f7fa937f (commit)
from 7d69232b827bfacb160dc2b501588023dac92141 (commit)
commit 9b5cb60049ed2c355a0c498bde810fb6f7fa937f
Author: Ali Abdallah <ali at ali-xfce.org>
Date: Fri Nov 6 14:06:47 2009 +0100
Survive D-Bus system bus restarts.
TODO | 2 --
libdbus/xfpm-dbus-monitor.c | 2 +-
libdbus/xfpm-dbus-monitor.h | 2 ++
src/xfpm-manager.c | 20 ++++++++++++++++++++
4 files changed, 23 insertions(+), 3 deletions(-)
diff --git a/TODO b/TODO
index c1a5c9e..b7cb0c9 100644
--- a/TODO
+++ b/TODO
@@ -1,5 +1,3 @@
-* Reimplement the org.freedesktop.PowerManagement interface.
* Hard drive spinning.
-* Survive D-Bus restarts.
* Probably provide a PermissionDenied error on the inhibit interface?
* Update the documentations.
diff --git a/libdbus/xfpm-dbus-monitor.c b/libdbus/xfpm-dbus-monitor.c
index 1721901..84e9f52 100644
--- a/libdbus/xfpm-dbus-monitor.c
+++ b/libdbus/xfpm-dbus-monitor.c
@@ -194,7 +194,7 @@ xfpm_dbus_monitor_query_system_bus_idle (gpointer data)
static void
xfpm_dbus_monitor_setup_system_watch (XfpmDBusMonitor *monitor)
{
- g_timeout_add_seconds (5, (GSourceFunc) xfpm_dbus_monitor_query_system_bus_idle, monitor);
+ g_timeout_add_seconds (2, (GSourceFunc) xfpm_dbus_monitor_query_system_bus_idle, monitor);
}
static DBusHandlerResult
diff --git a/libdbus/xfpm-dbus-monitor.h b/libdbus/xfpm-dbus-monitor.h
index cc78002..374e625 100644
--- a/libdbus/xfpm-dbus-monitor.h
+++ b/libdbus/xfpm-dbus-monitor.h
@@ -70,6 +70,8 @@ GType xfpm_dbus_monitor_get_type (void) G_GNUC_CONST;
XfpmDBusMonitor *xfpm_dbus_monitor_new (void);
+void xfpm_dbus_monitor_watch_system_bus (XfpmDBusMonitor *monitor);
+
gboolean xfpm_dbus_monitor_add_unique_name (XfpmDBusMonitor *monitor,
DBusBusType bus_type,
const gchar *unique_name);
diff --git a/src/xfpm-manager.c b/src/xfpm-manager.c
index a209d11..480f789 100644
--- a/src/xfpm-manager.c
+++ b/src/xfpm-manager.c
@@ -53,6 +53,7 @@
#include "xfpm-enum.h"
#include "xfpm-enum-glib.h"
#include "xfpm-enum-types.h"
+#include "xfpm-dbus-monitor.h"
static void xfpm_manager_finalize (GObject *object);
@@ -77,9 +78,12 @@ struct XfpmManagerPrivate
XfpmXfconf *conf;
XfpmBacklight *backlight;
XfpmConsoleKit *console;
+ XfpmDBusMonitor *monitor;
+
#ifdef HAVE_DPMS
XfpmDpms *dpms;
#endif
+
GTimer *timer;
gboolean inhibited;
@@ -122,6 +126,7 @@ xfpm_manager_finalize (GObject *object)
g_object_unref (manager->priv->conf);
g_object_unref (manager->priv->client);
g_object_unref (manager->priv->console);
+ g_object_unref (manager->priv->monitor);
g_timer_destroy (manager->priv->timer);
#ifdef HAVE_DPMS
@@ -153,6 +158,17 @@ xfpm_manager_quit (XfpmManager *manager)
return TRUE;
}
+static void
+xfpm_manager_system_bus_connection_changed_cb (XfpmDBusMonitor *monitor, gboolean connected, XfpmManager *manager)
+{
+ if ( connected == TRUE )
+ {
+ TRACE ("System bus connection changed to TRUE, restarting the power manager");
+ xfpm_manager_quit (manager);
+ g_spawn_command_line_async ("xfce4-power-manager", NULL);
+ }
+}
+
static gboolean
xfpm_manager_reserve_names (XfpmManager *manager)
{
@@ -378,6 +394,10 @@ void xfpm_manager_start (XfpmManager *manager)
manager->priv->button = xfpm_button_new ();
manager->priv->conf = xfpm_xfconf_new ();
manager->priv->console = xfpm_console_kit_new ();
+ manager->priv->monitor = xfpm_dbus_monitor_new ();
+
+ g_signal_connect (manager->priv->monitor, "system-bus-connection-changed",
+ G_CALLBACK (xfpm_manager_system_bus_connection_changed_cb), manager);
manager->priv->backlight = xfpm_backlight_new ();
More information about the Xfce4-commits
mailing list