diff --git a/src/monitor-sensor.c b/src/monitor-sensor.c index c320931..aa62ea5 100644 --- a/src/monitor-sensor.c +++ b/src/monitor-sensor.c @@ -54,6 +54,19 @@ properties_changed (GDBusProxy *proxy, g_variant_unref (v); g_variant_unref (unit); } + if (g_variant_dict_contains (&dict, "HasProximity")) { + v = g_dbus_proxy_get_cached_property (iio_proxy, "HasProximity"); + if (g_variant_get_boolean (v)) + g_print ("+++ Proximity sensor appeared\n"); + else + g_print ("--- Proximity sensor disappeared\n"); + g_variant_unref (v); + } + if (g_variant_dict_contains (&dict, "ProximityNear")) { + v = g_dbus_proxy_get_cached_property (iio_proxy, "ProximityNear"); + g_print (" Proximity value changed: %d\n", g_variant_get_boolean (v)); + g_variant_unref (v); + } if (g_variant_dict_contains (&dict, "HasCompass")) { v = g_dbus_proxy_get_cached_property (iio_proxy_compass, "HasCompass"); if (g_variant_get_boolean (v)) @@ -103,6 +116,17 @@ print_initial_values (void) } g_variant_unref (v); + v = g_dbus_proxy_get_cached_property (iio_proxy, "HasProximity"); + if (g_variant_get_boolean (v)) { + g_variant_unref (v); + v = g_dbus_proxy_get_cached_property (iio_proxy, "ProximityNear"); + g_print ("=== Has proximity sensor (near: %d)\n", + g_variant_get_boolean (v)); + } else { + g_print ("=== No proximity sensor\n"); + } + g_variant_unref (v); + if (!iio_proxy_compass) return; @@ -188,6 +212,21 @@ appeared_cb (GDBusConnection *connection, } g_clear_pointer (&ret, g_variant_unref); + /* Proximity sensor */ + ret = g_dbus_proxy_call_sync (iio_proxy, + "ClaimProximity", + NULL, + G_DBUS_CALL_FLAGS_NONE, + -1, + NULL, &error); + if (!ret) { + if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) + g_warning ("Failed to claim proximity sensor: %s", error->message); + g_main_loop_quit (loop); + return; + } + g_clear_pointer (&ret, g_variant_unref); + /* Compass */ if (g_strcmp0 (g_get_user_name (), "geoclue") == 0) { ret = g_dbus_proxy_call_sync (iio_proxy_compass,