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

776610
From 76c34858d18c7ec2bdef6ceeee22b047a0a1bdcb 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 ++++++++++++++++++++++------------
776610
 src/org.freedesktop.login1.xml | 14 ++++++++
776610
 2 files changed, 53 insertions(+), 21 deletions(-)
776610
776610
diff --git a/src/backends/meta-backend.c b/src/backends/meta-backend.c
776610
index 28f1cd92f..2f090e233 100644
776610
--- a/src/backends/meta-backend.c
776610
+++ b/src/backends/meta-backend.c
776610
@@ -8,60 +8,61 @@
776610
  * published by the Free Software Foundation; either version 2 of the
776610
  * License, or (at your option) any later version.
776610
  *
776610
  * This program is distributed in the hope that it will be useful, but
776610
  * WITHOUT ANY WARRANTY; without even the implied warranty of
776610
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
776610
  * General Public License for more details.
776610
  *
776610
  * You should have received a copy of the GNU General Public License
776610
  * along with this program; if not, write to the Free Software
776610
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
776610
  * 02111-1307, USA.
776610
  *
776610
  * Written by:
776610
  *     Jasper St. Pierre <jstpierre@mecheye.net>
776610
  */
776610
 
776610
 #include "config.h"
776610
 
776610
 #include <stdlib.h>
776610
 
776610
 #include <clutter/clutter-mutter.h>
776610
 #include <meta/meta-backend.h>
776610
 #include <meta/main.h>
776610
 #include <meta/util.h>
776610
 #include "meta-backend-private.h"
776610
 #include "meta-input-settings-private.h"
776610
 #include "backends/x11/meta-backend-x11.h"
776610
 #include "meta-cursor-tracker-private.h"
776610
 #include "meta-stage-private.h"
776610
+#include "meta-dbus-login1.h"
776610
 
776610
 #ifdef HAVE_REMOTE_DESKTOP
776610
 #include "backends/meta-dbus-session-watcher.h"
776610
 #include "backends/meta-screen-cast.h"
776610
 #include "backends/meta-remote-access-controller-private.h"
776610
 #include "backends/meta-remote-desktop.h"
776610
 #endif
776610
 
776610
 #ifdef HAVE_NATIVE_BACKEND
776610
 #include "backends/native/meta-backend-native.h"
776610
 #endif
776610
 
776610
 #include "backends/meta-idle-monitor-private.h"
776610
 #include "backends/meta-logical-monitor.h"
776610
 #include "backends/meta-monitor-manager-dummy.h"
776610
 #include "backends/meta-settings-private.h"
776610
 
776610
 #define META_IDLE_MONITOR_CORE_DEVICE 0
776610
 
776610
 enum
776610
 {
776610
   KEYMAP_CHANGED,
776610
   KEYMAP_LAYOUT_GROUP_CHANGED,
776610
   LAST_DEVICE_CHANGED,
776610
 
776610
   N_SIGNALS
776610
 };
776610
 
776610
 static guint signals[N_SIGNALS];
776610
 
776610
@@ -87,93 +88,97 @@ struct _MetaBackendPrivate
776610
   MetaMonitorManager *monitor_manager;
776610
   MetaOrientationManager *orientation_manager;
776610
   MetaCursorTracker *cursor_tracker;
776610
   MetaCursorRenderer *cursor_renderer;
776610
   MetaInputSettings *input_settings;
776610
   MetaRenderer *renderer;
776610
   MetaEgl *egl;
776610
   MetaSettings *settings;
776610
 #ifdef HAVE_REMOTE_DESKTOP
776610
   MetaRemoteAccessController *remote_access_controller;
776610
   MetaDbusSessionWatcher *dbus_session_watcher;
776610
   MetaScreenCast *screen_cast;
776610
   MetaRemoteDesktop *remote_desktop;
776610
 #endif
776610
 
776610
   ClutterBackend *clutter_backend;
776610
   ClutterActor *stage;
776610
 
776610
   gboolean is_pointer_position_initialized;
776610
 
776610
   guint device_update_idle_id;
776610
 
776610
   GHashTable *device_monitors;
776610
 
776610
   int current_device_id;
776610
 
776610
   MetaPointerConstraint *client_pointer_constraint;
776610
   MetaDnd *dnd;
776610
 
776610
   UpClient *up_client;
776610
-  guint sleep_signal_id;
776610
   GCancellable *cancellable;
776610
   GDBusConnection *system_bus;
776610
+
776610
+  Login1Manager *logind_proxy;
776610
+  int            inhibit_sleep_fd;
776610
 };
776610
 typedef struct _MetaBackendPrivate MetaBackendPrivate;
776610
 
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,
776610
                                                          initable_iface_init));
776610
 
776610
 static void
776610
 meta_backend_finalize (GObject *object)
776610
 {
776610
   MetaBackend *backend = META_BACKEND (object);
776610
   MetaBackendPrivate *priv = meta_backend_get_instance_private (backend);
776610
 
776610
   g_clear_object (&priv->monitor_manager);
776610
   g_clear_object (&priv->orientation_manager);
776610
   g_clear_object (&priv->input_settings);
776610
 #ifdef HAVE_REMOTE_DESKTOP
776610
   g_clear_object (&priv->remote_desktop);
776610
   g_clear_object (&priv->screen_cast);
776610
   g_clear_object (&priv->dbus_session_watcher);
776610
   g_clear_object (&priv->remote_access_controller);
776610
 #endif
776610
 
776610
   g_object_unref (priv->up_client);
776610
-  if (priv->sleep_signal_id)
776610
-    g_dbus_connection_signal_unsubscribe (priv->system_bus, priv->sleep_signal_id);
776610
   g_cancellable_cancel (priv->cancellable);
776610
   g_clear_object (&priv->cancellable);
776610
   g_clear_object (&priv->system_bus);
776610
 
776610
   if (priv->device_update_idle_id)
776610
     g_source_remove (priv->device_update_idle_id);
776610
 
776610
   g_hash_table_destroy (priv->device_monitors);
776610
 
776610
   g_clear_object (&priv->settings);
776610
 
776610
   G_OBJECT_CLASS (meta_backend_parent_class)->finalize (object);
776610
 }
776610
 
776610
 static void
776610
 meta_backend_sync_screen_size (MetaBackend *backend)
776610
 {
776610
   MetaBackendPrivate *priv = meta_backend_get_instance_private (backend);
776610
   int width, height;
776610
 
776610
   meta_monitor_manager_get_screen_size (priv->monitor_manager, &width, &height);
776610
 
776610
   META_BACKEND_GET_CLASS (backend)->update_screen_size (backend, width, height);
776610
 }
776610
 
776610
 static void
776610
 reset_pointer_position (MetaBackend *backend)
776610
 {
776610
   MetaBackendPrivate *priv = meta_backend_get_instance_private (backend);
776610
   MetaMonitorManager *monitor_manager = priv->monitor_manager;
776610
@@ -553,101 +558,114 @@ meta_backend_class_init (MetaBackendClass *klass)
776610
 static MetaMonitorManager *
776610
 meta_backend_create_monitor_manager (MetaBackend *backend,
776610
                                      GError     **error)
776610
 {
776610
   if (g_getenv ("META_DUMMY_MONITORS"))
776610
     return g_object_new (META_TYPE_MONITOR_MANAGER_DUMMY, NULL);
776610
 
776610
   return META_BACKEND_GET_CLASS (backend)->create_monitor_manager (backend,
776610
                                                                    error);
776610
 }
776610
 
776610
 static MetaRenderer *
776610
 meta_backend_create_renderer (MetaBackend *backend,
776610
                               GError     **error)
776610
 {
776610
   return META_BACKEND_GET_CLASS (backend)->create_renderer (backend, error);
776610
 }
776610
 
776610
 static void
776610
 lid_is_closed_changed_cb (UpClient   *client,
776610
                           GParamSpec *pspec,
776610
                           gpointer    user_data)
776610
 {
776610
   if (up_client_get_lid_is_closed (client))
776610
     return;
776610
 
776610
   meta_idle_monitor_reset_idletime (meta_idle_monitor_get_core ());
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
 
776610
   g_variant_get (parameters, "(b)", &suspending);
776610
   if (suspending)
776610
     return;
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);
776610
   if (!bus)
776610
     return;
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
 meta_backend_initable_init (GInitable     *initable,
776610
                             GCancellable  *cancellable,
776610
                             GError       **error)
776610
 {
776610
   MetaBackend *backend = META_BACKEND (initable);
776610
   MetaBackendPrivate *priv = meta_backend_get_instance_private (backend);
776610
 
776610
   priv->settings = meta_settings_new (backend);
776610
 
776610
   priv->egl = g_object_new (META_TYPE_EGL, NULL);
776610
 
776610
   priv->orientation_manager = g_object_new (META_TYPE_ORIENTATION_MANAGER, NULL);
776610
 
776610
   priv->monitor_manager = meta_backend_create_monitor_manager (backend, error);
776610
   if (!priv->monitor_manager)
776610
     return FALSE;
776610
 
776610
   priv->renderer = meta_backend_create_renderer (backend, error);
776610
   if (!priv->renderer)
776610
     return FALSE;
776610
 
776610
   priv->cursor_tracker = g_object_new (META_TYPE_CURSOR_TRACKER, NULL);
776610
 
776610
   priv->dnd = g_object_new (META_TYPE_DND, NULL);
776610
 
776610
   priv->up_client = up_client_new ();
776610
   g_signal_connect (priv->up_client, "notify::lid-is-closed",
776610
diff --git a/src/org.freedesktop.login1.xml b/src/org.freedesktop.login1.xml
776610
index 765475132..7db8f373c 100644
776610
--- a/src/org.freedesktop.login1.xml
776610
+++ b/src/org.freedesktop.login1.xml
776610
@@ -16,31 +16,45 @@
776610
       <arg name="major" type="u" direction="in"/>
776610
       <arg name="minor" type="u" direction="in"/>
776610
       <arg name="fd" type="h" direction="out"/>
776610
       <arg name="paused" type="b" direction="out"/>
776610
     </method>
776610
     <method name="ReleaseDevice">
776610
       <arg name="major" type="u"/>
776610
       <arg name="minor" type="u"/>
776610
     </method>
776610
     <method name="PauseDeviceComplete">
776610
       <arg name="major" type="u"/>
776610
       <arg name="minor" type="u"/>
776610
     </method>
776610
     <signal name="PauseDevice">
776610
       <arg name="major" type="u"/>
776610
       <arg name="minor" type="u"/>
776610
       <arg name="type" type="s"/>
776610
     </signal>
776610
     <signal name="ResumeDevice">
776610
       <arg name="major" type="u"/>
776610
       <arg name="minor" type="u"/>
776610
       <arg name="fd" type="h"/>
776610
     </signal>
776610
   </interface>
776610
 
776610
   <interface name="org.freedesktop.login1.Seat">
776610
     <method name="SwitchTo">
776610
       <arg name="vt" type="u"/>
776610
     </method>
776610
   </interface>
776610
+
776610
+  <interface name="org.freedesktop.login1.Manager">
776610
+    <method name="Inhibit">
776610
+      <annotation name="org.gtk.GDBus.C.UnixFD" value="true"/>
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
-- 
776610
2.18.1
776610