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

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