[gnome-settings-daemon] power: Only install callback once



commit d6bb63fd88e2c92d96ea6bc7a4e43c6756edb460
Author: Kyle Hofmann <kyle hofmann gmail com>
Date:   Sun Jul 12 10:08:14 2020 -0700

    power: Only install callback once
    
    A mode change to normal causes iio_proxy_claim_light() to be called with
    active set to TRUE.  This connects iio_proxy_changed_cb() even if the
    previous mode was dim and the callback was already connected.  This
    caused the callback to be triggered multiple times on each change of the
    ambient light sensor.  With this patch, calls to iio_proxy_claim_light()
    always remove the callback first, and if active is TRUE they add it
    back.

 plugins/power/gsd-power-manager.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
---
diff --git a/plugins/power/gsd-power-manager.c b/plugins/power/gsd-power-manager.c
index 43428cad..36c89aaa 100644
--- a/plugins/power/gsd-power-manager.c
+++ b/plugins/power/gsd-power-manager.c
@@ -1069,13 +1069,15 @@ iio_proxy_claim_light (GsdPowerManager *manager, gboolean active)
          * Remove when iio-sensor-proxy sends events only to clients instead
          * of all listeners:
          * https://github.com/hadess/iio-sensor-proxy/issues/210 */
+
+        /* disconnect, otherwise callback can be added multiple times */
+        g_signal_handlers_disconnect_by_func (manager->iio_proxy,
+                                              G_CALLBACK (iio_proxy_changed_cb),
+                                              manager);
+
         if (active)
                 g_signal_connect (manager->iio_proxy, "g-properties-changed",
                                   G_CALLBACK (iio_proxy_changed_cb), manager);
-        else
-                g_signal_handlers_disconnect_by_func (manager->iio_proxy,
-                                                      G_CALLBACK (iio_proxy_changed_cb),
-                                                      manager);
 
         if (!g_dbus_proxy_call_sync (manager->iio_proxy,
                                      active ? "ClaimLight" : "ReleaseLight",


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