summaryrefslogtreecommitdiff
path: root/libnotify
diff options
context:
space:
mode:
authorMartin Pitt <martin.pitt@ubuntu.com>2010-02-23 22:25:34 +0100
committerWilliam Jon McCann <jmccann@redhat.com>2010-04-02 19:43:35 -0400
commit3dc04fac9093e14476450d26d0e09472b1c6759b (patch)
tree3cce9392b1473ef5a88193eea41d2c48276ed610 /libnotify
parent3de71571ea822dd55d0a325553414e34b66d888a (diff)
downloadlibnotify-3dc04fac9093e14476450d26d0e09472b1c6759b.tar.gz
lazily start the daemon
notify_init() caused the daemon to be D-Bus activated already, even if the program that calls it doesn't send an actual notification for a long time (or potentially not at all). In order to optimize desktop startup speed, and to avoid unnecessary processes, launch the daemon on demand only. https://bugzilla.gnome.org/show_bug.cgi?id=610880
Diffstat (limited to 'libnotify')
-rw-r--r--libnotify/notify.c90
1 files changed, 47 insertions, 43 deletions
diff --git a/libnotify/notify.c b/libnotify/notify.c
index b1455a2..ccc3ed3 100644
--- a/libnotify/notify.c
+++ b/libnotify/notify.c
@@ -77,9 +77,6 @@ _notify_update_spec_version (void)
gboolean
notify_init (const char *app_name)
{
- GError *error = NULL;
- DBusGConnection *bus = NULL;
-
g_return_val_if_fail (app_name != NULL, FALSE);
g_return_val_if_fail (*app_name != '\0', FALSE);
@@ -90,46 +87,6 @@ notify_init (const char *app_name)
g_type_init ();
- bus = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
-
- if (error != NULL) {
- g_message ("Unable to get session bus: %s", error->message);
- g_error_free (error);
- return FALSE;
- }
-
- _proxy = dbus_g_proxy_new_for_name (bus,
- NOTIFY_DBUS_NAME,
- NOTIFY_DBUS_CORE_OBJECT,
- NOTIFY_DBUS_CORE_INTERFACE);
- dbus_g_connection_unref (bus);
-
- dbus_g_object_register_marshaller (notify_marshal_VOID__UINT_UINT,
- G_TYPE_NONE,
- G_TYPE_UINT,
- G_TYPE_UINT, G_TYPE_INVALID);
-
- dbus_g_object_register_marshaller (notify_marshal_VOID__UINT_STRING,
- G_TYPE_NONE,
- G_TYPE_UINT,
- G_TYPE_STRING, G_TYPE_INVALID);
-
- dbus_g_proxy_add_signal (_proxy,
- "NotificationClosed",
- G_TYPE_UINT,
- G_TYPE_UINT,
- G_TYPE_INVALID);
- dbus_g_proxy_add_signal (_proxy,
- "ActionInvoked",
- G_TYPE_UINT,
- G_TYPE_STRING,
- G_TYPE_INVALID);
-
- if (!_notify_update_spec_version ()) {
- g_message ("Error getting spec version");
- return FALSE;
- }
-
_initted = TRUE;
return TRUE;
@@ -205,6 +162,53 @@ _notify_get_dbus_g_conn (void)
DBusGProxy *
_notify_get_g_proxy (void)
{
+ GError *error = NULL;
+ DBusGConnection *bus = NULL;
+
+ if (_proxy != NULL)
+ return _proxy;
+
+ /* lazily initialize D-Bus connection */
+ bus = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
+
+ if (error != NULL) {
+ g_message ("Unable to get session bus: %s", error->message);
+ g_error_free (error);
+ return NULL;
+ }
+
+ _proxy = dbus_g_proxy_new_for_name (bus,
+ NOTIFY_DBUS_NAME,
+ NOTIFY_DBUS_CORE_OBJECT,
+ NOTIFY_DBUS_CORE_INTERFACE);
+ dbus_g_connection_unref (bus);
+
+ dbus_g_object_register_marshaller (notify_marshal_VOID__UINT_UINT,
+ G_TYPE_NONE,
+ G_TYPE_UINT,
+ G_TYPE_UINT, G_TYPE_INVALID);
+
+ dbus_g_object_register_marshaller (notify_marshal_VOID__UINT_STRING,
+ G_TYPE_NONE,
+ G_TYPE_UINT,
+ G_TYPE_STRING, G_TYPE_INVALID);
+
+ dbus_g_proxy_add_signal (_proxy,
+ "NotificationClosed",
+ G_TYPE_UINT,
+ G_TYPE_UINT,
+ G_TYPE_INVALID);
+ dbus_g_proxy_add_signal (_proxy,
+ "ActionInvoked",
+ G_TYPE_UINT,
+ G_TYPE_STRING,
+ G_TYPE_INVALID);
+
+ if (!_notify_update_spec_version ()) {
+ g_message ("Error getting spec version");
+ return NULL;
+ }
+
return _proxy;
}