mutter/SOURCES/0002-backend-switch-to-using-generated-logind-proxy.patch
2021-10-08 13:54:48 +00:00

164 lines
5.6 KiB
Diff

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