diff --git a/radio/src/thirdparty/libopenui/src/mainwindow.cpp b/radio/src/thirdparty/libopenui/src/mainwindow.cpp index e5d5b4d92..7ebb47f14 100644 --- a/radio/src/thirdparty/libopenui/src/mainwindow.cpp +++ b/radio/src/thirdparty/libopenui/src/mainwindow.cpp @@ -77,73 +77,6 @@ void MainWindow::setTouchEnabled(bool enable) } #endif -#if defined(HARDWARE_TOUCH) -bool getTouchOccured(); -#endif -void MainWindow::checkEvents() -{ -#if defined(HARDWARE_TOUCH) - -// if (touchPanelEventOccured()) { - if (getTouchOccured()) { - short lastDeltaX = touchState.lastDeltaX; - short lastDeltaY = touchState.lastDeltaY;; - TouchState newTouchState = touchPanelRead(); - if(touchState.event != TE_SLIDE_END || newTouchState.event != TE_NONE) - touchState = newTouchState; - touchState.lastDeltaX = lastDeltaX; - touchState.lastDeltaY = lastDeltaY; - } - - TouchEnableState currentState = touchEnableState; - - switch(touchState.event) - { - case TE_DOWN: - case TE_SLIDE: - if(touchEnableState == TouchOn) - touchEnableState = TouchOn_Touching; - else if (touchEnableState == TouchOff) - touchEnableState = TouchOff_Touching; - break; - case TE_UP: - case TE_SLIDE_END: - if(touchEnableState == TouchOn_Touching) - touchEnableState = TouchOn; - else if (touchEnableState == TouchOff_Touching) - touchEnableState = TouchOff; - else if(touchEnableState == TouchOnToOff_Touching) - touchEnableState = TouchOff; - else if(touchEnableState == TouchOffToOn_Touching) - touchEnableState = TouchOn; - break; - default: - break; - } - - if(touchState.event != TE_NONE) - _touchEventOccured = true; - - if ( currentState == TouchOff - || currentState == TouchOff_Touching - || currentState == TouchOffToOn_Touching) - { - touchState.event = TE_NONE; - } - - if (touchState.event == TE_DOWN) { - onTouchStart(touchState.x + scrollPositionX, touchState.y + scrollPositionY); - slidingWindow = nullptr; - } - else if (touchState.event == TE_UP) { - touchState.event = TE_NONE; - onTouchEnd(touchState.startX + scrollPositionX, touchState.startY + scrollPositionY); - } -#endif - - Window::checkEvents(); -} - void MainWindow::invalidate(const rect_t & rect) { if (invalidatedRect.w) { diff --git a/radio/src/thirdparty/libopenui/src/mainwindow.h b/radio/src/thirdparty/libopenui/src/mainwindow.h index 0cd3ec1b7..ec140811d 100644 --- a/radio/src/thirdparty/libopenui/src/mainwindow.h +++ b/radio/src/thirdparty/libopenui/src/mainwindow.h @@ -69,8 +69,6 @@ class MainWindow: public Window } #endif - void checkEvents() override; - #if defined(HARDWARE_TOUCH) void setTouchEnabled(bool enable); bool touchEventOccured() { diff --git a/radio/src/thirdparty/libopenui/src/window.cpp b/radio/src/thirdparty/libopenui/src/window.cpp index e65863097..65c1bb94e 100644 --- a/radio/src/thirdparty/libopenui/src/window.cpp +++ b/radio/src/thirdparty/libopenui/src/window.cpp @@ -26,6 +26,10 @@ Window * Window::slidingWindow = nullptr; Window * Window::capturedWindow = nullptr; std::list Window::trash; +extern lv_obj_t *virtual_kb; + +static bool is_scrolling = false; + static void window_event_cb(lv_event_t * e) { lv_event_code_t code = lv_event_get_code(e); @@ -41,48 +45,98 @@ static void window_event_cb(lv_event_t * e) return; } - lv_obj_t *currentTarget = lv_event_get_current_target(e); - - // if the event bubbled to the topmost window then hand it to libopenui MainWindow. - if (MainWindow::isMainWindowCreated() - && (lv_obj_get_parent(currentTarget) == nullptr)) { + // If the event bubbled to the topmost window then + // hand it to libopenui MainWindow. + lv_obj_t *cur_target = lv_event_get_current_target(e); + if (MainWindow::isMainWindowCreated() && + (lv_obj_get_parent(cur_target) == nullptr)) { + lv_obj_t *target = lv_event_get_target(e); + switch (code) { + case LV_EVENT_PRESSED: + case LV_EVENT_RELEASED: { + lv_indev_t* click_source = (lv_indev_t*)lv_event_get_param(e); + if(click_source == NULL || is_scrolling) return; - switch(code) { - case LV_EVENT_PRESSED: - case LV_EVENT_RELEASED: - case LV_EVENT_KEY: - // do legacy processing - MainWindow::instance()->checkEvents(); - break; - case LV_EVENT_SCROLL: { - lv_obj_t* target = lv_event_get_target(e); - lv_coord_t scroll_y = lv_obj_get_scroll_y(target); - lv_coord_t scroll_x = lv_obj_get_scroll_x(target); - TRACE("SCROLL[x=%d;y=%d]", scroll_x, scroll_y); - Window* w = (Window*)lv_obj_get_user_data(target); - if (w) { + // Exclude keyboard ? + // if(lv_indev_get_type(click_source) == LV_INDEV_TYPE_KEYPAD || + // lv_indev_get_type(click_source) == LV_INDEV_TYPE_ENCODER) { + // return; + // } + lv_area_t obj_coords; + lv_obj_get_coords(target, &obj_coords); + + lv_point_t point_act; + lv_indev_get_point(click_source, &point_act); + + // Ignore event from keypad + if(point_act.x < 0 || point_act.y < 0) return; + + lv_point_t rel_pos; + rel_pos.x = point_act.x - obj_coords.x1; + rel_pos.y = point_act.y - obj_coords.y1; + + auto w = (Window*)lv_obj_get_user_data(target); + if (!w) return; + + rel_pos.x += w->getScrollPositionX(); + rel_pos.y += w->getScrollPositionY(); + + if (code == LV_EVENT_PRESSED) { + TRACE("PRESSED[%d|%d]", rel_pos.x, rel_pos.y); + w->onTouchStart(rel_pos.x, rel_pos.y); + } else { + + lv_point_t vect_act; + lv_indev_get_vect(click_source, &vect_act); + + TRACE("RELEASED[%d|%d] vect[%d|%d]", + rel_pos.x, rel_pos.y, + vect_act.x, vect_act.y, + lv_indev_get_scroll_dir(click_source)); + + if (vect_act.x != 0 || vect_act.y != 0) return; + w->onTouchEnd(rel_pos.x, rel_pos.y); + } + } break; + + case LV_EVENT_CLICKED: + TRACE("CLICKED"); + break; + + case LV_EVENT_KEY: + // do legacy processing + MainWindow::instance()->checkEvents(); + break; + + case LV_EVENT_SCROLL: { + lv_coord_t scroll_y = lv_obj_get_scroll_y(target); + lv_coord_t scroll_x = lv_obj_get_scroll_x(target); + TRACE("SCROLL[x=%d;y=%d]", scroll_x, scroll_y); + Window *w = (Window *)lv_obj_get_user_data(target); + if (w) { #if defined(DEBUG_WINDOWS) - TRACE("%s", w->getWindowDebugString().c_str()); + TRACE("%s", w->getWindowDebugString().c_str()); #endif - w->setScrollPositionY(scroll_y); - w->setScrollPositionX(scroll_x); - } - } break; - case LV_EVENT_SCROLL_BEGIN: - TRACE("SCROLL_BEGIN"); - break; - 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; + w->setScrollPositionY(scroll_y); + w->setScrollPositionX(scroll_x); + } + } break; + case LV_EVENT_SCROLL_BEGIN: + TRACE("SCROLL_BEGIN"); + is_scrolling = true; + break; + case LV_EVENT_SCROLL_END: + TRACE("SCROLL_END"); + is_scrolling = false; + break; + case LV_EVENT_FOCUSED: { + 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; } } } diff --git a/radio/src/thirdparty/libopenui/src/window.h b/radio/src/thirdparty/libopenui/src/window.h index a63158bb4..617ddf2e3 100644 --- a/radio/src/thirdparty/libopenui/src/window.h +++ b/radio/src/thirdparty/libopenui/src/window.h @@ -404,6 +404,11 @@ class Window return _deleted; } +#if defined(HARDWARE_TOUCH) + virtual bool onTouchStart(coord_t x, coord_t y); + virtual bool onTouchEnd(coord_t x, coord_t y); +#endif + inline lv_obj_t *getLvObj() { return lvobj; } protected: @@ -463,13 +468,11 @@ class Window } #if defined(HARDWARE_TOUCH) - static coord_t getSnapStep(coord_t relativeScrollPosition, coord_t pageSize); + static coord_t getSnapStep(coord_t relativeScrollPosition, + coord_t pageSize); - virtual bool onTouchStart(coord_t x, coord_t y); - - virtual bool onTouchEnd(coord_t x, coord_t y); - - virtual bool onTouchSlide(coord_t x, coord_t y, coord_t startX, coord_t startY, coord_t slideX, coord_t slideY); + virtual bool onTouchSlide(coord_t x, coord_t y, coord_t startX, + coord_t startY, coord_t slideX, coord_t slideY); #endif bool forwardTouchEnd(coord_t x, coord_t y);