Blame SOURCES/0003-backend-add-signals-for-reporting-suspend-and-resume.patch

657d8e
From c5020c3d303ab211a970d88638e7d723034688db Mon Sep 17 00:00:00 2001
657d8e
From: Ray Strode <rstrode@redhat.com>
657d8e
Date: Thu, 10 Jan 2019 10:47:19 -0500
657d8e
Subject: [PATCH 3/9] backend: add signals for reporting suspend and resume
657d8e
657d8e
This commit adds "suspending" and "resuming" signals
657d8e
to MetaBackend.
657d8e
657d8e
It's preliminary work needed for tracking when to purge
657d8e
and recreate all textures (needed by nvidia).
657d8e
---
657d8e
 src/backends/meta-backend.c    | 98 ++++++++++++++++++++++++++++++----
657d8e
 src/org.freedesktop.login1.xml |  1 +
657d8e
 2 files changed, 88 insertions(+), 11 deletions(-)
657d8e
657d8e
diff --git a/src/backends/meta-backend.c b/src/backends/meta-backend.c
657d8e
index 5d71977c6..f59b899b7 100644
657d8e
--- a/src/backends/meta-backend.c
657d8e
+++ b/src/backends/meta-backend.c
657d8e
@@ -53,6 +53,8 @@
657d8e
 
657d8e
 #include <stdlib.h>
657d8e
 
657d8e
+#include <gio/gunixfdlist.h>
657d8e
+
657d8e
 #include "backends/meta-cursor-tracker-private.h"
657d8e
 #include "backends/meta-idle-monitor-private.h"
657d8e
 #include "backends/meta-input-settings-private.h"
657d8e
@@ -87,6 +89,8 @@ enum
657d8e
   LAST_DEVICE_CHANGED,
657d8e
   LID_IS_CLOSED_CHANGED,
657d8e
 
657d8e
+  SUSPENDING,
657d8e
+  RESUMING,
657d8e
   N_SIGNALS
657d8e
 };
657d8e
 
657d8e
@@ -745,6 +749,20 @@ meta_backend_class_init (MetaBackendClass *klass)
657d8e
                   0,
657d8e
                   NULL, NULL, NULL,
657d8e
                   G_TYPE_NONE, 1, G_TYPE_BOOLEAN);
657d8e
+  signals[SUSPENDING] =
657d8e
+    g_signal_new ("suspending",
657d8e
+                  G_TYPE_FROM_CLASS (object_class),
657d8e
+                  G_SIGNAL_RUN_LAST,
657d8e
+                  0,
657d8e
+                  NULL, NULL, NULL,
657d8e
+                  G_TYPE_NONE, 0);
657d8e
+  signals[RESUMING] =
657d8e
+    g_signal_new ("resuming",
657d8e
+                  G_TYPE_FROM_CLASS (object_class),
657d8e
+                  G_SIGNAL_RUN_LAST,
657d8e
+                  0,
657d8e
+                  NULL, NULL, NULL,
657d8e
+                  G_TYPE_NONE, 0);
657d8e
 
657d8e
   mutter_stage_views = g_getenv ("MUTTER_STAGE_VIEWS");
657d8e
   stage_views_disabled = g_strcmp0 (mutter_stage_views, "0") == 0;
657d8e
@@ -768,15 +786,66 @@ meta_backend_create_renderer (MetaBackend *backend,
657d8e
   return META_BACKEND_GET_CLASS (backend)->create_renderer (backend, error);
657d8e
 }
657d8e
 
657d8e
+static void
657d8e
+inhibit_sleep (MetaBackend *backend)
657d8e
+{
657d8e
+  MetaBackendPrivate *priv = meta_backend_get_instance_private (backend);
657d8e
+  g_autoptr (GVariant) fd_variant = NULL;
657d8e
+  g_autoptr (GUnixFDList) fd_list = NULL;
657d8e
+  g_autoptr (GError) error = NULL;
657d8e
+  int handle, fd;
657d8e
+
657d8e
+  if (priv->inhibit_sleep_fd >= 0)
657d8e
+    return;
657d8e
+
657d8e
+  if (!login1_manager_call_inhibit_sync (priv->logind_proxy,
657d8e
+                                         "sleep",
657d8e
+                                         "Display Server",
657d8e
+                                         "Prepare for suspend",
657d8e
+                                         "delay",
657d8e
+                                         NULL,
657d8e
+                                         &fd_variant,
657d8e
+                                         &fd_list,
657d8e
+                                         priv->cancellable,
657d8e
+                                         &error))
657d8e
+    {
657d8e
+      g_warning ("Failed to inhibit sleep: %s", error->message);
657d8e
+      return;
657d8e
+    }
657d8e
+
657d8e
+  handle = g_variant_get_handle (fd_variant);
657d8e
+  fd = g_unix_fd_list_get (fd_list, handle, &error);
657d8e
+
657d8e
+  if (fd < 0)
657d8e
+    {
657d8e
+      g_warning ("Failed to fetch sleep inhibitor fd: %s", error->message);
657d8e
+      return;
657d8e
+    }
657d8e
+
657d8e
+  priv->inhibit_sleep_fd = fd;
657d8e
+}
657d8e
+
657d8e
+static void
657d8e
+uninhibit_sleep (MetaBackend *backend)
657d8e
+{
657d8e
+  MetaBackendPrivate *priv = meta_backend_get_instance_private (backend);
657d8e
+
657d8e
+  close (priv->inhibit_sleep_fd);
657d8e
+  priv->inhibit_sleep_fd = -1;
657d8e
+}
657d8e
+
657d8e
 static void
657d8e
 prepare_for_sleep_cb (MetaBackend *backend,
657d8e
                       gboolean     suspending)
657d8e
 {
657d8e
-  gboolean suspending;
657d8e
-
657d8e
-  g_variant_get (parameters, "(b)", &suspending);
657d8e
-  if (suspending)
657d8e
+  if (suspending) {
657d8e
+    g_signal_emit (backend, signals[SUSPENDING], 0);
657d8e
+    uninhibit_sleep (backend);
657d8e
     return;
657d8e
+  }
657d8e
+
657d8e
+  inhibit_sleep (backend);
657d8e
+  g_signal_emit (backend, signals[RESUMING], 0);
657d8e
   meta_idle_monitor_reset_idletime (meta_idle_monitor_get_core ());
657d8e
 }
657d8e
 
657d8e
@@ -803,6 +872,7 @@ system_bus_gotten_cb (GObject      *object,
657d8e
                       GAsyncResult *res,
657d8e
                       gpointer      user_data)
657d8e
 {
657d8e
+  MetaBackend *backend = META_BACKEND (user_data);
657d8e
   MetaBackendPrivate *priv;
657d8e
   g_autoptr (GError) error = NULL;
657d8e
   GDBusConnection *bus;
657d8e
@@ -814,15 +884,21 @@ system_bus_gotten_cb (GObject      *object,
657d8e
   priv = meta_backend_get_instance_private (user_data);
657d8e
   priv->system_bus = bus;
657d8e
   priv->logind_proxy = get_logind_proxy (priv->cancellable, &error);
657d8e
+  priv->inhibit_sleep_fd = -1;
657d8e
 
657d8e
   if (!priv->logind_proxy)
657d8e
-    g_warning ("Failed to get logind proxy: %s", error->message);
657d8e
-
657d8e
-  g_signal_connect_object (priv->logind_proxy,
657d8e
-                           "prepare-for-sleep",
657d8e
-                           G_CALLBACK (prepare_for_sleep_cb),
657d8e
-                           user_data,
657d8e
-                           G_CONNECT_SWAPPED);
657d8e
+    {
657d8e
+      g_warning ("Failed to get logind proxy: %s", error->message);
657d8e
+    }
657d8e
+  else
657d8e
+    {
657d8e
+      inhibit_sleep (backend);
657d8e
+      g_signal_connect_object (priv->logind_proxy,
657d8e
+                               "prepare-for-sleep",
657d8e
+                               G_CALLBACK (prepare_for_sleep_cb),
657d8e
+                               user_data,
657d8e
+                               G_CONNECT_SWAPPED);
657d8e
+    }
657d8e
 }
657d8e
 
657d8e
 static gboolean
657d8e
diff --git a/src/org.freedesktop.login1.xml b/src/org.freedesktop.login1.xml
657d8e
index 1ecfd976f..7db8f373c 100644
657d8e
--- a/src/org.freedesktop.login1.xml
657d8e
+++ b/src/org.freedesktop.login1.xml
657d8e
@@ -46,6 +46,7 @@
657d8e
 
657d8e
   <interface name="org.freedesktop.login1.Manager">
657d8e
     <method name="Inhibit">
657d8e
+      <annotation name="org.gtk.GDBus.C.UnixFD" value="true"/>
657d8e
       <arg name="what" type="s" direction="in"/>
657d8e
       <arg name="who" type="s" direction="in"/>
657d8e
       <arg name="why" type="s" direction="in"/>
657d8e
-- 
657d8e
2.21.0
657d8e