From b62db404ee33c68f2524c931051f06b980c3b5f0 Mon Sep 17 00:00:00 2001 From: Rui Matos Date: Wed, 27 May 2015 20:10:51 +0200 Subject: [PATCH] backends/native: Reset idle time when resuming from suspend https://bugzilla.gnome.org/show_bug.cgi?id=749994 --- src/backends/native/meta-backend-native.c | 56 +++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/src/backends/native/meta-backend-native.c b/src/backends/native/meta-backend-native.c index a14bd4c4d..e1d66c18a 100644 --- a/src/backends/native/meta-backend-native.c +++ b/src/backends/native/meta-backend-native.c @@ -42,6 +42,9 @@ struct _MetaBackendNativePrivate MetaLauncher *launcher; MetaBarrierManagerNative *barrier_manager; UpClient *up_client; + guint sleep_signal_id; + GCancellable *cancellable; + GDBusConnection *system_bus; }; typedef struct _MetaBackendNativePrivate MetaBackendNativePrivate; @@ -56,10 +59,57 @@ meta_backend_native_finalize (GObject *object) meta_launcher_free (priv->launcher); g_object_unref (priv->up_client); + if (priv->sleep_signal_id) + g_dbus_connection_signal_unsubscribe (priv->system_bus, priv->sleep_signal_id); + g_cancellable_cancel (priv->cancellable); + g_clear_object (&priv->cancellable); + g_clear_object (&priv->system_bus); G_OBJECT_CLASS (meta_backend_native_parent_class)->finalize (object); } +static void +prepare_for_sleep_cb (GDBusConnection *connection, + const gchar *sender_name, + const gchar *object_path, + const gchar *interface_name, + const gchar *signal_name, + GVariant *parameters, + gpointer user_data) +{ + gboolean suspending; + g_variant_get (parameters, "(b)", &suspending); + if (suspending) + return; + meta_idle_monitor_native_reset_idletime (meta_idle_monitor_get_core ()); +} + +static void +system_bus_gotten_cb (GObject *object, + GAsyncResult *res, + gpointer user_data) +{ + MetaBackendNativePrivate *priv; + GDBusConnection *bus; + + bus = g_bus_get_finish (res, NULL); + if (!bus) + return; + + priv = meta_backend_native_get_instance_private (META_BACKEND_NATIVE (user_data)); + priv->system_bus = bus; + priv->sleep_signal_id = g_dbus_connection_signal_subscribe (priv->system_bus, + "org.freedesktop.login1", + "org.freedesktop.login1.Manager", + "PrepareForSleep", + "/org/freedesktop/login1", + NULL, + G_DBUS_SIGNAL_FLAGS_NONE, + prepare_for_sleep_cb, + NULL, + NULL); +} + static void lid_is_closed_changed_cb (UpClient *client, GParamSpec *pspec, @@ -286,6 +336,12 @@ meta_backend_native_init (MetaBackendNative *native) priv->up_client = up_client_new (); g_signal_connect (priv->up_client, "notify::lid-is-closed", G_CALLBACK (lid_is_closed_changed_cb), NULL); + + priv->cancellable = g_cancellable_new (); + g_bus_get (G_BUS_TYPE_SYSTEM, + priv->cancellable, + system_bus_gotten_cb, + native); } gboolean