[mutter/wip/hadess/unidle-on-battery-change: 2/2] backend: Reset idletime when unplugging the power cable




commit 8eae62e4decc1d7e220e23b0d4efd70af416afa9
Author: Bastien Nocera <hadess hadess net>
Date:   Thu Sep 30 17:40:40 2021 +0200

    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

 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 333d5b7c9f..651cd592f7 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


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]