[mutter/wip/hadess/unidle-on-battery-change: 1/2] backend: Refactor "lid-is-closed" handling code
- From: Bastien Nocera <hadess src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [mutter/wip/hadess/unidle-on-battery-change: 1/2] backend: Refactor "lid-is-closed" handling code
- Date: Thu, 30 Sep 2021 15:44:35 +0000 (UTC)
commit fe65e3e1828f13cae9da32096c9b22f21e4673a7
Author: Bastien Nocera <hadess hadess net>
Date: Thu Sep 30 17:39:28 2021 +0200
backend: Refactor "lid-is-closed" handling code
We'll need to handle another property in the same place, so refactor the
code to allow falling-through to handle another property.
Part-of: <>
src/backends/meta-backend.c | 48 ++++++++++++++++++++++++---------------------
1 file changed, 26 insertions(+), 22 deletions(-)
---
diff --git a/src/backends/meta-backend.c b/src/backends/meta-backend.c
index 84ace613bc..333d5b7c9f 100644
--- a/src/backends/meta-backend.c
+++ b/src/backends/meta-backend.c
@@ -647,28 +647,31 @@ upower_properties_changed (GDBusProxy *proxy,
MetaBackend *backend = user_data;
MetaBackendPrivate *priv = meta_backend_get_instance_private (backend);
GVariant *v;
- gboolean lid_is_closed;
+ gboolean reset_idle_time = FALSE;
v = g_variant_lookup_value (changed_properties,
"LidIsClosed",
G_VARIANT_TYPE_BOOLEAN);
- if (!v)
- return;
-
- lid_is_closed = g_variant_get_boolean (v);
- g_variant_unref (v);
+ if (v)
+ {
+ gboolean lid_is_closed;
- if (lid_is_closed == priv->lid_is_closed)
- return;
+ lid_is_closed = g_variant_get_boolean (v);
+ g_variant_unref (v);
- priv->lid_is_closed = lid_is_closed;
- g_signal_emit (backend, signals[LID_IS_CLOSED_CHANGED], 0,
- priv->lid_is_closed);
+ if (lid_is_closed != priv->lid_is_closed)
+ {
+ priv->lid_is_closed = lid_is_closed;
+ g_signal_emit (backend, signals[LID_IS_CLOSED_CHANGED], 0,
+ priv->lid_is_closed);
- if (lid_is_closed)
- return;
+ if (lid_is_closed)
+ reset_idle_time = TRUE;
+ }
+ }
- meta_idle_manager_reset_idle_time (priv->idle_manager);
+ if (reset_idle_time)
+ meta_idle_manager_reset_idle_time (priv->idle_manager);
}
static void
@@ -699,15 +702,16 @@ upower_ready_cb (GObject *source_object,
G_CALLBACK (upower_properties_changed), backend);
v = g_dbus_proxy_get_cached_property (proxy, "LidIsClosed");
- if (!v)
- return;
- priv->lid_is_closed = g_variant_get_boolean (v);
- g_variant_unref (v);
-
- if (priv->lid_is_closed)
+ if (v)
{
- g_signal_emit (backend, signals[LID_IS_CLOSED_CHANGED], 0,
- priv->lid_is_closed);
+ priv->lid_is_closed = g_variant_get_boolean (v);
+ g_variant_unref (v);
+
+ if (priv->lid_is_closed)
+ {
+ g_signal_emit (backend, signals[LID_IS_CLOSED_CHANGED], 0,
+ priv->lid_is_closed);
+ }
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]