Blame SOURCES/0002-backend-switch-to-using-generated-logind-proxy.patch

1c7749
From 063db6c9a7504a4d7baae28f7899bd661c459c41 Mon Sep 17 00:00:00 2001
1c7749
From: Ray Strode <rstrode@redhat.com>
1c7749
Date: Mon, 14 Jan 2019 11:11:01 -0500
1c7749
Subject: [PATCH 2/9] backend: switch to using generated logind proxy
1c7749
1c7749
Right now we listen to prepare-for-sleep using
1c7749
raw gdbus calls.
1c7749
1c7749
This commit switches it over to use a generated
1c7749
proxy, which will become useful in a future commit,
1c7749
for adding suspending inhibitors.
1c7749
---
1c7749
 src/backends/meta-backend.c    | 60 ++++++++++++++++++++++------------
1c7749
 src/org.freedesktop.login1.xml | 13 ++++++++
1c7749
 2 files changed, 52 insertions(+), 21 deletions(-)
1c7749
1c7749
diff --git a/src/backends/meta-backend.c b/src/backends/meta-backend.c
1c7749
index 23ab2faec..5d71977c6 100644
1c7749
--- a/src/backends/meta-backend.c
1c7749
+++ b/src/backends/meta-backend.c
1c7749
@@ -65,6 +65,7 @@
1c7749
 #include "meta/main.h"
1c7749
 #include "meta/meta-backend.h"
1c7749
 #include "meta/util.h"
1c7749
+#include "meta-dbus-login1.h"
1c7749
 
1c7749
 #ifdef HAVE_REMOTE_DESKTOP
1c7749
 #include "backends/meta-dbus-session-watcher.h"
1c7749
@@ -145,10 +146,12 @@ struct _MetaBackendPrivate
1c7749
   GDBusProxy *upower_proxy;
1c7749
   gboolean lid_is_closed;
1c7749
 
1c7749
-  guint sleep_signal_id;
1c7749
   GCancellable *cancellable;
1c7749
   GDBusConnection *system_bus;
1c7749
 
1c7749
+  Login1Manager *logind_proxy;
1c7749
+  int            inhibit_sleep_fd;
1c7749
+
1c7749
   gboolean was_headless;
1c7749
 };
1c7749
 typedef struct _MetaBackendPrivate MetaBackendPrivate;
1c7749
@@ -156,6 +159,10 @@ typedef struct _MetaBackendPrivate MetaBackendPrivate;
1c7749
 static void
1c7749
 initable_iface_init (GInitableIface *initable_iface);
1c7749
 
1c7749
+
1c7749
+static void prepare_for_sleep_cb (MetaBackend *backend,
1c7749
+                                  gboolean     suspending);
1c7749
+
1c7749
 G_DEFINE_ABSTRACT_TYPE_WITH_CODE (MetaBackend, meta_backend, G_TYPE_OBJECT,
1c7749
                                   G_ADD_PRIVATE (MetaBackend)
1c7749
                                   G_IMPLEMENT_INTERFACE (G_TYPE_INITABLE,
1c7749
@@ -177,8 +184,6 @@ meta_backend_finalize (GObject *object)
1c7749
   g_clear_object (&priv->remote_access_controller);
1c7749
 #endif
1c7749
 
1c7749
-  if (priv->sleep_signal_id)
1c7749
-    g_dbus_connection_signal_unsubscribe (priv->system_bus, priv->sleep_signal_id);
1c7749
   if (priv->upower_watch_id)
1c7749
     g_bus_unwatch_name (priv->upower_watch_id);
1c7749
   g_cancellable_cancel (priv->cancellable);
1c7749
@@ -764,13 +769,8 @@ meta_backend_create_renderer (MetaBackend *backend,
1c7749
 }
1c7749
 
1c7749
 static void
1c7749
-prepare_for_sleep_cb (GDBusConnection *connection,
1c7749
-                      const gchar     *sender_name,
1c7749
-                      const gchar     *object_path,
1c7749
-                      const gchar     *interface_name,
1c7749
-                      const gchar     *signal_name,
1c7749
-                      GVariant        *parameters,
1c7749
-                      gpointer         user_data)
1c7749
+prepare_for_sleep_cb (MetaBackend *backend,
1c7749
+                      gboolean     suspending)
1c7749
 {
1c7749
   gboolean suspending;
1c7749
 
1c7749
@@ -780,12 +780,31 @@ prepare_for_sleep_cb (GDBusConnection *connection,
1c7749
   meta_idle_monitor_reset_idletime (meta_idle_monitor_get_core ());
1c7749
 }
1c7749
 
1c7749
+static Login1Manager *
1c7749
+get_logind_proxy (GCancellable *cancellable,
1c7749
+                  GError      **error)
1c7749
+{
1c7749
+  Login1Manager *proxy;
1c7749
+
1c7749
+  proxy =
1c7749
+    login1_manager_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM,
1c7749
+                                           G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START,
1c7749
+                                           "org.freedesktop.login1",
1c7749
+                                           "/org/freedesktop/login1",
1c7749
+                                           cancellable, error);
1c7749
+  if (!proxy)
1c7749
+    g_prefix_error (error, "Could not get logind proxy: ");
1c7749
+
1c7749
+  return proxy;
1c7749
+}
1c7749
+
1c7749
 static void
1c7749
 system_bus_gotten_cb (GObject      *object,
1c7749
                       GAsyncResult *res,
1c7749
                       gpointer      user_data)
1c7749
 {
1c7749
   MetaBackendPrivate *priv;
1c7749
+  g_autoptr (GError) error = NULL;
1c7749
   GDBusConnection *bus;
1c7749
 
1c7749
   bus = g_bus_get_finish (res, NULL);
1c7749
@@ -794,17 +813,16 @@ system_bus_gotten_cb (GObject      *object,
1c7749
 
1c7749
   priv = meta_backend_get_instance_private (user_data);
1c7749
   priv->system_bus = bus;
1c7749
-  priv->sleep_signal_id =
1c7749
-    g_dbus_connection_signal_subscribe (priv->system_bus,
1c7749
-                                        "org.freedesktop.login1",
1c7749
-                                        "org.freedesktop.login1.Manager",
1c7749
-                                        "PrepareForSleep",
1c7749
-                                        "/org/freedesktop/login1",
1c7749
-                                        NULL,
1c7749
-                                        G_DBUS_SIGNAL_FLAGS_NONE,
1c7749
-                                        prepare_for_sleep_cb,
1c7749
-                                        NULL,
1c7749
-                                        NULL);
1c7749
+  priv->logind_proxy = get_logind_proxy (priv->cancellable, &error);
1c7749
+
1c7749
+  if (!priv->logind_proxy)
1c7749
+    g_warning ("Failed to get logind proxy: %s", error->message);
1c7749
+
1c7749
+  g_signal_connect_object (priv->logind_proxy,
1c7749
+                           "prepare-for-sleep",
1c7749
+                           G_CALLBACK (prepare_for_sleep_cb),
1c7749
+                           user_data,
1c7749
+                           G_CONNECT_SWAPPED);
1c7749
 }
1c7749
 
1c7749
 static gboolean
1c7749
diff --git a/src/org.freedesktop.login1.xml b/src/org.freedesktop.login1.xml
1c7749
index 765475132..1ecfd976f 100644
1c7749
--- a/src/org.freedesktop.login1.xml
1c7749
+++ b/src/org.freedesktop.login1.xml
1c7749
@@ -43,4 +43,17 @@
1c7749
       <arg name="vt" type="u"/>
1c7749
     </method>
1c7749
   </interface>
1c7749
+
1c7749
+  <interface name="org.freedesktop.login1.Manager">
1c7749
+    <method name="Inhibit">
1c7749
+      <arg name="what" type="s" direction="in"/>
1c7749
+      <arg name="who" type="s" direction="in"/>
1c7749
+      <arg name="why" type="s" direction="in"/>
1c7749
+      <arg name="mode" type="s" direction="in"/>
1c7749
+      <arg name="fd" type="h" direction="out"/>
1c7749
+    </method>
1c7749
+    <signal name="PrepareForSleep">
1c7749
+      <arg name="active" type="b"/>
1c7749
+    </signal>
1c7749
+  </interface>
1c7749
 </node>
1c7749
-- 
1c7749
2.21.0
1c7749