summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKyle Hofmann <kyle.hofmann@gmail.com>2020-07-12 10:08:14 -0700
committerKyle Hofmann <kyle.hofmann@gmail.com>2020-07-13 19:50:09 -0700
commitd6bb63fd88e2c92d96ea6bc7a4e43c6756edb460 (patch)
treedeab4f7a1d57d26f978194bbc6e22029ebfa1e3f
parentdb9cefd0fcea6909134e92c844f4f6b515eaf5a3 (diff)
downloadgnome-settings-daemon-d6bb63fd88e2c92d96ea6bc7a4e43c6756edb460.tar.gz
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.
-rw-r--r--plugins/power/gsd-power-manager.c10
1 files 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",