[gnome-flashback] backend: remove direct upower-glib usage
- From: Alberts Muktupāvels <muktupavels src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-flashback] backend: remove direct upower-glib usage
- Date: Sat, 23 Oct 2021 18:48:44 +0000 (UTC)
commit 86932eef922dab236b5dee9a6a2bc9c8a91c3983
Author: Alberts Muktupāvels <alberts muktupavels gmail com>
Date: Sun Sep 12 21:31:48 2021 +0300
backend: remove direct upower-glib usage
Based on mutter commit:
https://gitlab.gnome.org/GNOME/mutter/-/commit/fa9e330f2c6d
backends/gf-backend-private.h | 2 -
backends/gf-backend.c | 135 +++++++++++++++++++++++++++++++++++-------
configure.ac | 2 -
3 files changed, 115 insertions(+), 24 deletions(-)
---
diff --git a/backends/gf-backend-private.h b/backends/gf-backend-private.h
index e5ac27a..25f30be 100644
--- a/backends/gf-backend-private.h
+++ b/backends/gf-backend-private.h
@@ -26,8 +26,6 @@
#ifndef GF_BACKEND_PRIVATE_H
#define GF_BACKEND_PRIVATE_H
-#include <libupower-glib/upower.h>
-
#include "gf-backend.h"
#include "gf-monitor-manager-private.h"
#include "gf-monitor-manager-types-private.h"
diff --git a/backends/gf-backend.c b/backends/gf-backend.c
index 190226f..7e19304 100644
--- a/backends/gf-backend.c
+++ b/backends/gf-backend.c
@@ -39,7 +39,8 @@ typedef struct
GfMonitorManager *monitor_manager;
- UpClient *up_client;
+ guint upower_watch_id;
+ GDBusProxy *upower_proxy;
gboolean lid_is_closed;
GList *gpus;
@@ -71,16 +72,26 @@ create_monitor_manager (GfBackend *backend,
}
static void
-lid_is_closed_changed_cb (UpClient *client,
- GParamSpec *pspec,
- GfBackend *self)
+upower_properties_changed_cb (GDBusProxy *proxy,
+ GVariant *changed_properties,
+ GStrv invalidated_properties,
+ GfBackend *self)
{
GfBackendPrivate *priv;
+ GVariant *v;
gboolean lid_is_closed;
priv = gf_backend_get_instance_private (self);
- lid_is_closed = up_client_get_lid_is_closed (priv->up_client);
+ v = g_variant_lookup_value (changed_properties,
+ "LidIsClosed",
+ G_VARIANT_TYPE_BOOLEAN);
+
+ if (v == NULL)
+ return;
+
+ lid_is_closed = g_variant_get_boolean (v);
+ g_variant_unref (v);
if (priv->lid_is_closed == lid_is_closed)
return;
@@ -93,6 +104,91 @@ lid_is_closed_changed_cb (UpClient *client,
priv->lid_is_closed);
}
+static void
+upower_ready_cb (GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data)
+{
+ GError *error;
+ GDBusProxy *proxy;
+ GfBackend *self;
+ GfBackendPrivate *priv;
+ GVariant *v;
+
+ error = NULL;
+ proxy = g_dbus_proxy_new_finish (res, &error);
+
+ if (proxy == NULL)
+ {
+ if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
+ g_warning ("Failed to create UPower proxy: %s", error->message);
+
+ g_error_free (error);
+ return;
+ }
+
+ self = GF_BACKEND (user_data);
+ priv = gf_backend_get_instance_private (self);
+
+ priv->upower_proxy = proxy;
+
+ g_signal_connect (proxy,
+ "g-properties-changed",
+ G_CALLBACK (upower_properties_changed_cb),
+ self);
+
+ v = g_dbus_proxy_get_cached_property (proxy, "LidIsClosed");
+
+ if (v == NULL)
+ return;
+
+ priv->lid_is_closed = g_variant_get_boolean (v);
+ g_variant_unref (v);
+
+ if (priv->lid_is_closed)
+ {
+ g_signal_emit (self,
+ backend_signals[LID_IS_CLOSED_CHANGED],
+ 0,
+ priv->lid_is_closed);
+ }
+}
+
+static void
+upower_appeared_cb (GDBusConnection *connection,
+ const char *name,
+ const char *name_owner,
+ gpointer user_data)
+{
+ GfBackend *self;
+
+ self = GF_BACKEND (user_data);
+
+ g_dbus_proxy_new (connection,
+ G_DBUS_PROXY_FLAGS_NONE,
+ NULL,
+ "org.freedesktop.UPower",
+ "/org/freedesktop/UPower",
+ "org.freedesktop.UPower",
+ NULL,
+ upower_ready_cb,
+ self);
+}
+
+static void
+upower_vanished_cb (GDBusConnection *connection,
+ const char *name,
+ gpointer user_data)
+{
+ GfBackend *self;
+ GfBackendPrivate *priv;
+
+ self = GF_BACKEND (user_data);
+ priv = gf_backend_get_instance_private (self);
+
+ g_clear_object (&priv->upower_proxy);
+}
+
static gboolean
gf_backend_initable_init (GInitable *initable,
GCancellable *cancellable,
@@ -127,9 +223,6 @@ gf_backend_real_is_lid_closed (GfBackend *self)
priv = gf_backend_get_instance_private (self);
- if (priv->up_client == NULL)
- return FALSE;
-
return priv->lid_is_closed;
}
@@ -147,17 +240,13 @@ gf_backend_constructed (GObject *object)
if (self_class->is_lid_closed != gf_backend_real_is_lid_closed)
return;
- priv->up_client = up_client_new ();
-
- if (priv->up_client != NULL)
- {
- g_signal_connect (priv->up_client,
- "notify::lid-is-closed",
- G_CALLBACK (lid_is_closed_changed_cb),
- self);
-
- priv->lid_is_closed = up_client_get_lid_is_closed (priv->up_client);
- }
+ priv->upower_watch_id = g_bus_watch_name (G_BUS_TYPE_SYSTEM,
+ "org.freedesktop.UPower",
+ G_BUS_NAME_WATCHER_FLAGS_NONE,
+ upower_appeared_cb,
+ upower_vanished_cb,
+ self,
+ NULL);
}
static void
@@ -185,7 +274,13 @@ gf_backend_finalize (GObject *object)
self = GF_BACKEND (object);
priv = gf_backend_get_instance_private (self);
- g_clear_object (&priv->up_client);
+ if (priv->upower_watch_id != 0)
+ {
+ g_bus_unwatch_name (priv->upower_watch_id);
+ priv->upower_watch_id = 0;
+ }
+
+ g_clear_object (&priv->upower_proxy);
g_list_free_full (priv->gpus, g_object_unref);
diff --git a/configure.ac b/configure.ac
index 0e1f6ce..bb8143e 100644
--- a/configure.ac
+++ b/configure.ac
@@ -98,7 +98,6 @@ GSETTINGS_DESKTOP_SCHEMAS_REQUIRED=3.31.0
POLKIT_AGENT_REQUIRED=0.97
POLKIT_GOBJECT_REQUIRED=0.97
IBUS_REQUIRED=1.5.2
-UPOWER_GLIB_REQUIRED=0.99.0
XRANDR_REQUIRED=1.5.0
XXF86VM_REQUIRED=1.1.4
@@ -112,7 +111,6 @@ PKG_CHECK_MODULES([BACKENDS], [
gio-unix-2.0 >= $GLIB_REQUIRED
glib-2.0 >= $GLIB_REQUIRED
gnome-desktop-3.0 >= $LIBGNOME_DESKTOP_REQUIRED
- upower-glib >= $UPOWER_GLIB_REQUIRED
xcb-randr
xrandr >= $XRANDR_REQUIRED
x11-xcb
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]