From 4837cec89f12d4bc9f4751bbe2f65d70e0e44135 Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Wed, 21 Mar 2018 12:18:32 +0100 Subject: [PATCH] backend: Reset idle when lid is opened or resuming from suspend There's no particular reason for this code to only ever be triggered on Wayland, and allows removing X11-specific work-arounds from gnome-settings-daemon. See https://bugs.freedesktop.org/show_bug.cgi?id=59576 https://bugzilla.gnome.org/show_bug.cgi?id=705942 --- src/backends/meta-backend.c | 77 +++++++++++++++++++++++ src/backends/native/meta-backend-native.c | 74 ---------------------- 2 files changed, 77 insertions(+), 74 deletions(-) diff --git a/src/backends/meta-backend.c b/src/backends/meta-backend.c index de20cddfe..1c44b9c7f 100644 --- a/src/backends/meta-backend.c +++ b/src/backends/meta-backend.c @@ -110,6 +110,11 @@ struct _MetaBackendPrivate MetaPointerConstraint *client_pointer_constraint; MetaDnd *dnd; + + UpClient *up_client; + guint sleep_signal_id; + GCancellable *cancellable; + GDBusConnection *system_bus; }; typedef struct _MetaBackendPrivate MetaBackendPrivate; @@ -136,6 +141,13 @@ meta_backend_finalize (GObject *object) g_clear_object (&priv->dbus_session_watcher); #endif + 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); + if (priv->device_update_idle_id) g_source_remove (priv->device_update_idle_id); @@ -592,6 +604,61 @@ meta_backend_create_renderer (MetaBackend *backend, return META_BACKEND_GET_CLASS (backend)->create_renderer (backend, error); } +static void +lid_is_closed_changed_cb (UpClient *client, + GParamSpec *pspec, + gpointer user_data) +{ + if (up_client_get_lid_is_closed (client)) + return; + + meta_idle_monitor_reset_idletime (meta_idle_monitor_get_core ()); +} + +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_reset_idletime (meta_idle_monitor_get_core ()); +} + +static void +system_bus_gotten_cb (GObject *object, + GAsyncResult *res, + gpointer user_data) +{ + MetaBackendPrivate *priv; + GDBusConnection *bus; + + bus = g_bus_get_finish (res, NULL); + if (!bus) + return; + + priv = meta_backend_get_instance_private (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 gboolean meta_backend_initable_init (GInitable *initable, GCancellable *cancellable, @@ -621,6 +688,16 @@ meta_backend_initable_init (GInitable *initable, priv->dnd = g_object_new (META_TYPE_DND, NULL); + 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, + backend); + return TRUE; } diff --git a/src/backends/native/meta-backend-native.c b/src/backends/native/meta-backend-native.c index 4c2342ff5..f7803da03 100644 --- a/src/backends/native/meta-backend-native.c +++ b/src/backends/native/meta-backend-native.c @@ -60,10 +60,6 @@ struct _MetaBackendNativePrivate { MetaLauncher *launcher; MetaBarrierManagerNative *barrier_manager; - UpClient *up_client; - guint sleep_signal_id; - GCancellable *cancellable; - GDBusConnection *system_bus; }; typedef struct _MetaBackendNativePrivate MetaBackendNativePrivate; @@ -85,69 +81,9 @@ 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_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, - gpointer user_data) -{ - if (up_client_get_lid_is_closed (client)) - return; - - meta_idle_monitor_reset_idletime (meta_idle_monitor_get_core ()); -} - static void constrain_to_barriers (ClutterInputDevice *device, guint32 time, @@ -627,16 +563,6 @@ meta_backend_native_init (MetaBackendNative *native) } priv->barrier_manager = meta_barrier_manager_native_new (); - - 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); } MetaLauncher *