From c789b6be385c03bd0da110519fa30df6fb69e84b Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Thu, 30 Sep 2021 17:40:40 +0200 Subject: [PATCH] backend: Reset idletime when unplugging the power cable Avoid having laptops suspend or lock as soon as the power cable is unplugged as the timeout for those actions when on battery are smaller than the timeouts when on AC. - laptop is plugged in, and hasn't been used for X minutes - laptop is unplugged - the gnome-settings-daemon power plugin sets up its timeouts for inactivity for the "on battery" case - those X minutes of inactivity are still counting, and are above the level of one of the timeouts (say, suspend or lock screen), mutter fires the timeouts - gsd-power activates the action associated with the timeout Fixes: https://gitlab.gnome.org/GNOME/mutter/-/issues/1953 Part-of: --- src/backends/meta-backend.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/backends/meta-backend.c b/src/backends/meta-backend.c index 333d5b7c9..651cd592f 100644 --- a/src/backends/meta-backend.c +++ b/src/backends/meta-backend.c @@ -181,6 +181,7 @@ struct _MetaBackendPrivate guint upower_watch_id; GDBusProxy *upower_proxy; gboolean lid_is_closed; + gboolean on_battery; guint sleep_signal_id; GCancellable *cancellable; @@ -670,6 +671,23 @@ upower_properties_changed (GDBusProxy *proxy, } } + v = g_variant_lookup_value (changed_properties, + "OnBattery", + G_VARIANT_TYPE_BOOLEAN); + if (v) + { + gboolean on_battery; + + on_battery = g_variant_get_boolean (v); + g_variant_unref (v); + + if (on_battery != priv->on_battery) + { + priv->on_battery = on_battery; + reset_idle_time = TRUE; + } + } + if (reset_idle_time) meta_idle_manager_reset_idle_time (priv->idle_manager); } @@ -713,6 +731,13 @@ upower_ready_cb (GObject *source_object, priv->lid_is_closed); } } + + v = g_dbus_proxy_get_cached_property (proxy, "OnBattery"); + if (v) + { + priv->on_battery = g_variant_get_boolean (v); + g_variant_unref (v); + } } static void