[mutter/wip/texture-purge-on-nvidia: 2/4] backend: switch to using generated logind proxy



commit d349ca0a89640db98f8e82e060b98134f9621743
Author: Ray Strode <rstrode redhat com>
Date:   Mon Jan 14 11:11:01 2019 -0500

    backend: switch to using generated logind proxy
    
    Right now we listen to prepare-for-sleep using
    raw gdbus calls.
    
    This commit switches it over to use a generated
    proxy, which will become useful in a future commit,
    for adding suspending inhibitors.

 src/backends/meta-backend.c    | 60 +++++++++++++++++++++++++++---------------
 src/org.freedesktop.login1.xml | 13 +++++++++
 2 files changed, 52 insertions(+), 21 deletions(-)
---
diff --git a/src/backends/meta-backend.c b/src/backends/meta-backend.c
index 28f1cd92f..2f090e233 100644
--- a/src/backends/meta-backend.c
+++ b/src/backends/meta-backend.c
@@ -35,6 +35,7 @@
 #include "backends/x11/meta-backend-x11.h"
 #include "meta-cursor-tracker-private.h"
 #include "meta-stage-private.h"
+#include "meta-dbus-login1.h"
 
 #ifdef HAVE_REMOTE_DESKTOP
 #include "backends/meta-dbus-session-watcher.h"
@@ -114,15 +115,21 @@ struct _MetaBackendPrivate
   MetaDnd *dnd;
 
   UpClient *up_client;
-  guint sleep_signal_id;
   GCancellable *cancellable;
   GDBusConnection *system_bus;
+
+  Login1Manager *logind_proxy;
+  int            inhibit_sleep_fd;
 };
 typedef struct _MetaBackendPrivate MetaBackendPrivate;
 
 static void
 initable_iface_init (GInitableIface *initable_iface);
 
+
+static void prepare_for_sleep_cb (MetaBackend *backend,
+                                  gboolean     suspending);
+
 G_DEFINE_ABSTRACT_TYPE_WITH_CODE (MetaBackend, meta_backend, G_TYPE_OBJECT,
                                   G_ADD_PRIVATE (MetaBackend)
                                   G_IMPLEMENT_INTERFACE (G_TYPE_INITABLE,
@@ -145,8 +152,6 @@ meta_backend_finalize (GObject *object)
 #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);
@@ -580,13 +585,8 @@ lid_is_closed_changed_cb (UpClient   *client,
 }
 
 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)
+prepare_for_sleep_cb (MetaBackend *backend,
+                      gboolean     suspending)
 {
   gboolean suspending;
 
@@ -596,12 +596,31 @@ prepare_for_sleep_cb (GDBusConnection *connection,
   meta_idle_monitor_reset_idletime (meta_idle_monitor_get_core ());
 }
 
+static Login1Manager *
+get_logind_proxy (GCancellable *cancellable,
+                  GError      **error)
+{
+  Login1Manager *proxy;
+
+  proxy =
+    login1_manager_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM,
+                                           G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START,
+                                           "org.freedesktop.login1",
+                                           "/org/freedesktop/login1",
+                                           cancellable, error);
+  if (!proxy)
+    g_prefix_error (error, "Could not get logind proxy: ");
+
+  return proxy;
+}
+
 static void
 system_bus_gotten_cb (GObject      *object,
                       GAsyncResult *res,
                       gpointer      user_data)
 {
   MetaBackendPrivate *priv;
+  g_autoptr (GError) error = NULL;
   GDBusConnection *bus;
 
   bus = g_bus_get_finish (res, NULL);
@@ -610,17 +629,16 @@ system_bus_gotten_cb (GObject      *object,
 
   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);
+  priv->logind_proxy = get_logind_proxy (priv->cancellable, &error);
+
+  if (!priv->logind_proxy)
+    g_warning ("Failed to get logind proxy: %s", error->message);
+
+  g_signal_connect_object (priv->logind_proxy,
+                           "prepare-for-sleep",
+                           G_CALLBACK (prepare_for_sleep_cb),
+                           user_data,
+                           G_CONNECT_SWAPPED);
 }
 
 static gboolean
diff --git a/src/org.freedesktop.login1.xml b/src/org.freedesktop.login1.xml
index 765475132..1ecfd976f 100644
--- a/src/org.freedesktop.login1.xml
+++ b/src/org.freedesktop.login1.xml
@@ -43,4 +43,17 @@
       <arg name="vt" type="u"/>
     </method>
   </interface>
+
+  <interface name="org.freedesktop.login1.Manager">
+    <method name="Inhibit">
+      <arg name="what" type="s" direction="in"/>
+      <arg name="who" type="s" direction="in"/>
+      <arg name="why" type="s" direction="in"/>
+      <arg name="mode" type="s" direction="in"/>
+      <arg name="fd" type="h" direction="out"/>
+    </method>
+    <signal name="PrepareForSleep">
+      <arg name="active" type="b"/>
+    </signal>
+  </interface>
 </node>


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]