feedback-manager: Split out event feedback preparation
It's becoming gradually more complex so move it to a separate function. Signed-off-by: Guido Günther <agx@sigxcpu.org>
This commit is contained in:
+48
-31
@@ -1,5 +1,7 @@
|
||||
/*
|
||||
* Copyright (C) 2020 Purism SPC
|
||||
* 2024-2025 The Phosh Developers
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-3.0+
|
||||
* Author: Guido Günther <agx@sigxcpu.org>
|
||||
*/
|
||||
@@ -359,6 +361,48 @@ parse_hints (GVariant *hints, FbdFeedbackProfileLevel *level, gboolean *hint_imp
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* add_event_feedbacks:
|
||||
*
|
||||
* Add the suitable feedacks to the event.
|
||||
*
|
||||
* Returns: `TRUE` if at least on feedback was added.
|
||||
*/
|
||||
static gboolean
|
||||
add_event_feedbacks (FbdFeedbackManager *self, FbdEvent *event, GSList *feedbacks)
|
||||
{
|
||||
gboolean has_vibra = FALSE;
|
||||
gboolean found_fb = FALSE;
|
||||
|
||||
if (!feedbacks)
|
||||
return FALSE;
|
||||
|
||||
for (GSList *l = feedbacks; l; l = l->next) {
|
||||
FbdFeedbackBase *fb = FBD_FEEDBACK_BASE (l->data);
|
||||
|
||||
if (fbd_feedback_is_available (FBD_FEEDBACK_BASE (fb))) {
|
||||
/* Handle one haptic feedback at a time. In practice haptics can handle multiple
|
||||
* patterns but none of the devices supports this atm */
|
||||
/* TODO: should respect priorities */
|
||||
if (FBD_IS_FEEDBACK_VIBRA (fb)) {
|
||||
if (fbd_dev_vibra_is_busy (self->vibra))
|
||||
continue;
|
||||
has_vibra = TRUE;
|
||||
}
|
||||
|
||||
fbd_event_add_feedback (event, fb);
|
||||
|
||||
/* Events take priority over the haptic interface */
|
||||
if (has_vibra)
|
||||
fbd_haptic_manager_end_feedback (self->haptic_manager);
|
||||
|
||||
found_fb = TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
return found_fb;
|
||||
}
|
||||
|
||||
|
||||
static gboolean
|
||||
fbd_feedback_manager_handle_trigger_feedback (LfbGdbusFeedback *object,
|
||||
@@ -370,7 +414,7 @@ fbd_feedback_manager_handle_trigger_feedback (LfbGdbusFeedback *object,
|
||||
{
|
||||
FbdFeedbackManager *self;
|
||||
FbdEvent *event;
|
||||
GSList *feedbacks, *l;
|
||||
GSList *feedbacks;
|
||||
guint event_id;
|
||||
const gchar *sender;
|
||||
FbdFeedbackProfileLevel level, hint_level = FBD_FEEDBACK_PROFILE_LEVEL_FULL;
|
||||
@@ -415,38 +459,11 @@ fbd_feedback_manager_handle_trigger_feedback (LfbGdbusFeedback *object,
|
||||
g_hash_table_insert (self->events, GUINT_TO_POINTER (event_id), event);
|
||||
|
||||
level = fbd_feedback_manager_get_effective_level (self, arg_app_id, hint_level, hint_important);
|
||||
|
||||
feedbacks = fbd_feedback_theme_lookup_feedback (self->theme, level, event);
|
||||
|
||||
if (feedbacks) {
|
||||
gboolean has_vibra = FALSE;
|
||||
|
||||
for (l = feedbacks; l; l = l->next) {
|
||||
FbdFeedbackBase *fb = FBD_FEEDBACK_BASE (l->data);
|
||||
|
||||
if (fbd_feedback_is_available (FBD_FEEDBACK_BASE (fb))) {
|
||||
/* Handle one haptic feedback at a time. In practice haptics can handle multiple
|
||||
* patterns but none of the devices supports this atm */
|
||||
/* TODO: should respect priorities */
|
||||
if (FBD_IS_FEEDBACK_VIBRA (fb)) {
|
||||
if (fbd_dev_vibra_is_busy (self->vibra))
|
||||
continue;
|
||||
has_vibra = TRUE;
|
||||
}
|
||||
|
||||
fbd_event_add_feedback (event, fb);
|
||||
|
||||
/* Events take priority over the haptic interface */
|
||||
if (has_vibra)
|
||||
fbd_haptic_manager_end_feedback (self->haptic_manager);
|
||||
|
||||
found_fb = TRUE;
|
||||
}
|
||||
}
|
||||
found_fb = add_event_feedbacks (self, event, feedbacks);
|
||||
if (feedbacks)
|
||||
g_slist_free_full (feedbacks, g_object_unref);
|
||||
} else {
|
||||
/* No feedbacks found at all */
|
||||
found_fb = FALSE;
|
||||
}
|
||||
|
||||
lfb_gdbus_feedback_complete_trigger_feedback (object, invocation, event_id);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user