From 56a36968b79c9b7c9d39dd3a3b0159043b28208b Mon Sep 17 00:00:00 2001 From: Raphael Coeffic Date: Mon, 24 Jan 2022 08:18:05 +0100 Subject: [PATCH] Fix propagating focus from LVGL to libopenui --- radio/src/thirdparty/libopenui/src/window.cpp | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/radio/src/thirdparty/libopenui/src/window.cpp b/radio/src/thirdparty/libopenui/src/window.cpp index 0176c427c..e65863097 100644 --- a/radio/src/thirdparty/libopenui/src/window.cpp +++ b/radio/src/thirdparty/libopenui/src/window.cpp @@ -74,6 +74,15 @@ static void window_event_cb(lv_event_t * e) case LV_EVENT_SCROLL_END: TRACE("SCROLL_END"); break; + case LV_EVENT_FOCUSED: { + lv_obj_t* target = lv_event_get_target(e); + bool lvgl_focused = lv_obj_has_state(target, LV_STATE_FOCUSED); + bool loiu_focused = ((Window*)target->user_data)->hasFocus(); + TRACE("FOCUSED[%d|%d]", lvgl_focused, loiu_focused); + if (!loiu_focused) { + ((Window*)target->user_data)->setFocus(); + } + } break; } } } @@ -237,9 +246,11 @@ void Window::setFocus(uint8_t flag, Window * from) if (focusWindow != this) { // synchronize lvgl focused state with libopenui - lv_obj_add_state(lvobj, LV_STATE_FOCUSED); - if (focusWindow != nullptr) { - lv_obj_clear_state(focusWindow->lvobj, LV_STATE_FOCUSED); + if (!lv_obj_has_state(lvobj, LV_STATE_FOCUSED)) { + lv_obj_add_state(lvobj, LV_STATE_FOCUSED); + if (focusWindow != nullptr) { + lv_obj_clear_state(focusWindow->lvobj, LV_STATE_FOCUSED); + } } // scroll before calling focusHandler so that the window can adjust the scroll position if needed