kathenas / rpms / mutter

Forked from rpms/mutter 5 years ago
Clone

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

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