diff --git a/radio/src/thirdparty/libopenui/src/mainwindow.cpp b/radio/src/thirdparty/libopenui/src/mainwindow.cpp index 7cbe46111..de96d7fa9 100644 --- a/radio/src/thirdparty/libopenui/src/mainwindow.cpp +++ b/radio/src/thirdparty/libopenui/src/mainwindow.cpp @@ -76,9 +76,9 @@ void MainWindow::checkEvents() touchState.lastDeltaY += SLIDE_SPEED_REDUCTION; else touchState.lastDeltaY = 0; - if (touchState.lastDeltaX || touchState.lastDeltaY) { - onTouchSlide(touchState.x, touchState.y, touchState.startX, touchState.startY, touchState.lastDeltaX, touchState.lastDeltaY); - } + + onTouchSlide(touchState.x, touchState.y, touchState.startX, touchState.startY, touchState.lastDeltaX, touchState.lastDeltaY); + slidingWindow = nullptr; } #endif diff --git a/radio/src/thirdparty/libopenui/src/window.cpp b/radio/src/thirdparty/libopenui/src/window.cpp index 7f0222f4a..46f5d4ce4 100644 --- a/radio/src/thirdparty/libopenui/src/window.cpp +++ b/radio/src/thirdparty/libopenui/src/window.cpp @@ -22,6 +22,7 @@ Window * Window::focusWindow = nullptr; Window * Window::slidingWindow = nullptr; +Window * Window::touchedWindow = nullptr; std::list Window::trash; Window::Window(Window * parent, const rect_t & rect, WindowFlags windowFlags, LcdFlags textFlags): @@ -411,6 +412,12 @@ bool Window::onTouchStart(coord_t x, coord_t y) auto child = *it; if (child->rect.contains(x, y)) { if (child->onTouchStart(x - child->rect.x + child->scrollPositionX, y - child->rect.y + child->scrollPositionY)) { + // remember the first window that processed the touch start event. We will give that window + // the opportunity to process the touchend first, and also after a slide end so the touched window + // always gets a touchEnd if it processed the touch start. + if (touchedWindow == nullptr) { + touchedWindow = child; + } return true; } } @@ -421,6 +428,26 @@ bool Window::onTouchStart(coord_t x, coord_t y) bool Window::forwardTouchEnd(coord_t x, coord_t y) { + // give the touched window the opportunity to process the touch first before it is + // forwarded: See on touchstart + if (touchedWindow != nullptr) { + auto savedTouchWindow = touchedWindow; + touchedWindow = nullptr; + // transalte x and y through the parent hierarchy + auto myParent = savedTouchWindow->parent; + while(myParent != nullptr) { + x = x - myParent->rect.x + myParent->scrollPositionX; + y = y - myParent->rect.y + myParent->scrollPositionY; + myParent = myParent->parent; + } + + if (savedTouchWindow->onTouchEnd( + x - savedTouchWindow->rect.x + savedTouchWindow->scrollPositionX, + y - savedTouchWindow->rect.y + savedTouchWindow->scrollPositionY)) { + return true; + } + } + for (auto it = children.rbegin(); it != children.rend(); ++it) { auto child = *it; if (child->rect.contains(x, y)) { diff --git a/radio/src/thirdparty/libopenui/src/window.h b/radio/src/thirdparty/libopenui/src/window.h index 6902eb4e4..2b9b045e6 100644 --- a/radio/src/thirdparty/libopenui/src/window.h +++ b/radio/src/thirdparty/libopenui/src/window.h @@ -395,6 +395,7 @@ class Window static Window * focusWindow; static Window * slidingWindow; + static Window * touchedWindow; static std::list trash; std::function closeHandler;