From 6692d8922b76b1dc9e819869adae8db862f8dd33 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guido=20G=C3=BCnther?= Date: Sat, 4 Jul 2020 13:55:19 +0200 Subject: [PATCH] feedback-manager: Add hint to select feedback profile per event This e.g. allows events that are meant for haptic only to avoid emitting a sound by omitting the 'full' level and using "quiet" instead. Closes: #7 --- src/fbd-feedback-manager.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/fbd-feedback-manager.c b/src/fbd-feedback-manager.c index 1c1b033..1806444 100644 --- a/src/fbd-feedback-manager.c +++ b/src/fbd-feedback-manager.c @@ -224,6 +224,21 @@ get_max_level (FbdFeedbackProfileLevel global_level, return level; } +static gboolean +parse_hints (GVariant *hints, FbdFeedbackProfileLevel *level) +{ + const gchar *profile; + gboolean found; + g_auto (GVariantDict) dict = G_VARIANT_DICT_INIT (NULL); + + g_variant_dict_init (&dict, hints); + found = g_variant_dict_lookup (&dict, "profile", "&s", &profile); + + if (level && found) + *level = fbd_feedback_profile_level (profile); + return TRUE; +} + static gboolean fbd_feedback_manager_handle_trigger_feedback (LfbGdbusFeedback *object, GDBusMethodInvocation *invocation, @@ -259,6 +274,13 @@ fbd_feedback_manager_handle_trigger_feedback (LfbGdbusFeedback *object, return TRUE; } + if (!parse_hints (arg_hints, &hint_level)) { + g_dbus_method_invocation_return_error (invocation, G_DBUS_ERROR, + G_DBUS_ERROR_INVALID_ARGS, + "Invalid hints"); + return TRUE; + } + if (arg_timeout < -1) arg_timeout = -1;