mirror of
https://github.com/brl/mutter.git
synced 2024-11-28 02:50:41 -05:00
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.
This commit is contained in:
parent
a566c6677c
commit
f6e8e867b4
@ -35,6 +35,7 @@
|
|||||||
#include "backends/x11/meta-backend-x11.h"
|
#include "backends/x11/meta-backend-x11.h"
|
||||||
#include "meta-cursor-tracker-private.h"
|
#include "meta-cursor-tracker-private.h"
|
||||||
#include "meta-stage-private.h"
|
#include "meta-stage-private.h"
|
||||||
|
#include "meta-dbus-login1.h"
|
||||||
|
|
||||||
#ifdef HAVE_REMOTE_DESKTOP
|
#ifdef HAVE_REMOTE_DESKTOP
|
||||||
#include "backends/meta-dbus-session-watcher.h"
|
#include "backends/meta-dbus-session-watcher.h"
|
||||||
@ -114,15 +115,21 @@ struct _MetaBackendPrivate
|
|||||||
MetaDnd *dnd;
|
MetaDnd *dnd;
|
||||||
|
|
||||||
UpClient *up_client;
|
UpClient *up_client;
|
||||||
guint sleep_signal_id;
|
|
||||||
GCancellable *cancellable;
|
GCancellable *cancellable;
|
||||||
GDBusConnection *system_bus;
|
GDBusConnection *system_bus;
|
||||||
|
|
||||||
|
Login1Manager *logind_proxy;
|
||||||
|
int inhibit_sleep_fd;
|
||||||
};
|
};
|
||||||
typedef struct _MetaBackendPrivate MetaBackendPrivate;
|
typedef struct _MetaBackendPrivate MetaBackendPrivate;
|
||||||
|
|
||||||
static void
|
static void
|
||||||
initable_iface_init (GInitableIface *initable_iface);
|
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_DEFINE_ABSTRACT_TYPE_WITH_CODE (MetaBackend, meta_backend, G_TYPE_OBJECT,
|
||||||
G_ADD_PRIVATE (MetaBackend)
|
G_ADD_PRIVATE (MetaBackend)
|
||||||
G_IMPLEMENT_INTERFACE (G_TYPE_INITABLE,
|
G_IMPLEMENT_INTERFACE (G_TYPE_INITABLE,
|
||||||
@ -145,8 +152,6 @@ meta_backend_finalize (GObject *object)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
g_object_unref (priv->up_client);
|
g_object_unref (priv->up_client);
|
||||||
if (priv->sleep_signal_id)
|
|
||||||
g_dbus_connection_signal_unsubscribe (priv->system_bus, priv->sleep_signal_id);
|
|
||||||
g_cancellable_cancel (priv->cancellable);
|
g_cancellable_cancel (priv->cancellable);
|
||||||
g_clear_object (&priv->cancellable);
|
g_clear_object (&priv->cancellable);
|
||||||
g_clear_object (&priv->system_bus);
|
g_clear_object (&priv->system_bus);
|
||||||
@ -580,13 +585,8 @@ lid_is_closed_changed_cb (UpClient *client,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
prepare_for_sleep_cb (GDBusConnection *connection,
|
prepare_for_sleep_cb (MetaBackend *backend,
|
||||||
const gchar *sender_name,
|
gboolean suspending)
|
||||||
const gchar *object_path,
|
|
||||||
const gchar *interface_name,
|
|
||||||
const gchar *signal_name,
|
|
||||||
GVariant *parameters,
|
|
||||||
gpointer user_data)
|
|
||||||
{
|
{
|
||||||
gboolean suspending;
|
gboolean suspending;
|
||||||
|
|
||||||
@ -596,12 +596,31 @@ prepare_for_sleep_cb (GDBusConnection *connection,
|
|||||||
meta_idle_monitor_reset_idletime (meta_idle_monitor_get_core ());
|
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
|
static void
|
||||||
system_bus_gotten_cb (GObject *object,
|
system_bus_gotten_cb (GObject *object,
|
||||||
GAsyncResult *res,
|
GAsyncResult *res,
|
||||||
gpointer user_data)
|
gpointer user_data)
|
||||||
{
|
{
|
||||||
MetaBackendPrivate *priv;
|
MetaBackendPrivate *priv;
|
||||||
|
g_autoptr (GError) error = NULL;
|
||||||
GDBusConnection *bus;
|
GDBusConnection *bus;
|
||||||
|
|
||||||
bus = g_bus_get_finish (res, NULL);
|
bus = g_bus_get_finish (res, NULL);
|
||||||
@ -610,17 +629,16 @@ system_bus_gotten_cb (GObject *object,
|
|||||||
|
|
||||||
priv = meta_backend_get_instance_private (user_data);
|
priv = meta_backend_get_instance_private (user_data);
|
||||||
priv->system_bus = bus;
|
priv->system_bus = bus;
|
||||||
priv->sleep_signal_id =
|
priv->logind_proxy = get_logind_proxy (priv->cancellable, &error);
|
||||||
g_dbus_connection_signal_subscribe (priv->system_bus,
|
|
||||||
"org.freedesktop.login1",
|
if (!priv->logind_proxy)
|
||||||
"org.freedesktop.login1.Manager",
|
g_warning ("Failed to get logind proxy: %s", error->message);
|
||||||
"PrepareForSleep",
|
|
||||||
"/org/freedesktop/login1",
|
g_signal_connect_object (priv->logind_proxy,
|
||||||
NULL,
|
"prepare-for-sleep",
|
||||||
G_DBUS_SIGNAL_FLAGS_NONE,
|
G_CALLBACK (prepare_for_sleep_cb),
|
||||||
prepare_for_sleep_cb,
|
user_data,
|
||||||
NULL,
|
G_CONNECT_SWAPPED);
|
||||||
NULL);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
|
@ -43,4 +43,17 @@
|
|||||||
<arg name="vt" type="u"/>
|
<arg name="vt" type="u"/>
|
||||||
</method>
|
</method>
|
||||||
</interface>
|
</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>
|
</node>
|
||||||
|
Loading…
Reference in New Issue
Block a user