From e2b4264d84693a7869125ee99296b2324d1b7ec3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guido=20G=C3=BCnther?= Date: Sat, 1 Apr 2023 15:18:59 +0200 Subject: gsd-power-manager: Connect to light sensor async Claiming the light sensor can take a noticeable amount of time when the sensor is being polled constantly (e.g. via monitor-sensor). Due to the function being invoked in backlight_enable this can lead to a noticeable delay when unblanking via key press. Fix this by claiming the sensor async. Fixes: https://gitlab.gnome.org/World/Phosh/phosh/-/issues/915 --- plugins/power/gsd-power-manager.c | 61 ++++++++++++++++++++++++++++++--------- 1 file changed, 47 insertions(+), 14 deletions(-) (limited to 'plugins') diff --git a/plugins/power/gsd-power-manager.c b/plugins/power/gsd-power-manager.c index 0263e9f6..dbdb6ab3 100644 --- a/plugins/power/gsd-power-manager.c +++ b/plugins/power/gsd-power-manager.c @@ -1186,10 +1186,48 @@ action_hibernate (GsdPowerManager *manager) "Error calling Hibernate"); } + +static void +light_claimed_cb (GObject *source_object, + GAsyncResult *res, + gpointer user_data) +{ + GsdPowerManager *manager = user_data; + g_autoptr(GError) error = NULL; + g_autoptr(GVariant) result = NULL; + + result = g_dbus_proxy_call_finish (G_DBUS_PROXY (source_object), + res, + &error); + if (result == NULL) { + g_warning ("Claiming light sensor failed: %s", error->message); + return; + } + iio_proxy_changed (manager); +} + + +static void +light_released_cb (GObject *source_object, + GAsyncResult *res, + gpointer user_data) +{ + g_autoptr(GError) error = NULL; + g_autoptr(GVariant) result = NULL; + + result = g_dbus_proxy_call_finish (G_DBUS_PROXY (source_object), + res, + &error); + if (result == NULL) { + g_warning ("Release of light sensors failed: %s", error->message); + return; + } +} + + static void iio_proxy_claim_light (GsdPowerManager *manager, gboolean active) { - GError *error = NULL; if (manager->iio_proxy == NULL) return; if (!manager->backlight) @@ -1211,19 +1249,14 @@ iio_proxy_claim_light (GsdPowerManager *manager, gboolean active) g_signal_connect (manager->iio_proxy, "g-properties-changed", G_CALLBACK (iio_proxy_changed_cb), manager); - if (!g_dbus_proxy_call_sync (manager->iio_proxy, - active ? "ClaimLight" : "ReleaseLight", - NULL, - G_DBUS_CALL_FLAGS_NONE, - -1, - NULL, - &error)) { - g_warning ("Call to iio-proxy failed: %s", error->message); - g_error_free (error); - } - - if (active) - iio_proxy_changed (manager); + g_dbus_proxy_call (manager->iio_proxy, + active ? "ClaimLight" : "ReleaseLight", + NULL, + G_DBUS_CALL_FLAGS_NONE, + -1, + manager->cancellable, + active ? light_claimed_cb : light_released_cb, + manager); } static void -- cgit v1.2.1