From e8a5371f68dd17463ca0cd58101afaa9eccb855d Mon Sep 17 00:00:00 2001 From: SkullzOTS <86809689+SkullzOTS@users.noreply.github.com> Date: Wed, 8 Jan 2025 19:05:01 -0300 Subject: [PATCH] fix bug when moving windows on android --- src/framework/platform/androidwindow.cpp | 33 +++++++++++++++++++----- src/framework/platform/androidwindow.h | 3 +++ 2 files changed, 30 insertions(+), 6 deletions(-) diff --git a/src/framework/platform/androidwindow.cpp b/src/framework/platform/androidwindow.cpp index 7c40ea4400..fb088809b4 100644 --- a/src/framework/platform/androidwindow.cpp +++ b/src/framework/platform/androidwindow.cpp @@ -247,20 +247,26 @@ void AndroidWindow::processTextInput() { } void AndroidWindow::processFingerDownAndUp() { - static ticks_t lastPress = 0; - bool isTouchdown = m_currentEvent.type == TOUCH_DOWN; - Fw::MouseButton mouseButton = (m_currentEvent.type == TOUCH_UP && stdext::millis() > lastPress + 500 ) ? + Fw::MouseButton mouseButton = (m_currentEvent.type == TOUCH_UP && !m_isDragging && stdext::millis() > m_lastPress + 500) ? Fw::MouseRightButton : Fw::MouseLeftButton; m_inputEvent.reset(); m_inputEvent.type = (isTouchdown) ? Fw::MousePressInputEvent : Fw::MouseReleaseInputEvent; m_inputEvent.mouseButton = mouseButton; - if(isTouchdown) { - lastPress = g_clock.millis(); + + if (isTouchdown) { + m_lastPress = g_clock.millis(); m_mouseButtonStates |= 1 << mouseButton; - } else { + } else if (m_currentEvent.type == TOUCH_UP) { + if (!m_isDragging) { + if (stdext::millis() > m_lastPress + 500) { + mouseButton = Fw::MouseRightButton; + m_inputEvent.mouseButton = mouseButton; + } + } + m_isDragging = false; g_dispatcher.addEvent([this, mouseButton] { m_mouseButtonStates &= ~(1 << mouseButton); }); } @@ -268,9 +274,24 @@ void AndroidWindow::processFingerDownAndUp() { } void AndroidWindow::processFingerMotion() { + static Point lastMousePos(-1, -1); + static const int dragThreshold = 5; + m_inputEvent.reset(); m_inputEvent.type = Fw::MouseMoveInputEvent; + Point newMousePos(m_currentEvent.x / m_displayDensity, m_currentEvent.y / m_displayDensity); + + if (lastMousePos.x != -1 && lastMousePos.y != -1) { + int dx = std::abs(newMousePos.x - lastMousePos.x); + int dy = std::abs(newMousePos.y - lastMousePos.y); + + if (dx > dragThreshold || dy > dragThreshold) { + m_isDragging = true; + } + } + lastMousePos = newMousePos; + handleInputEvent(); } diff --git a/src/framework/platform/androidwindow.h b/src/framework/platform/androidwindow.h index e0f1206ce7..ee1011a4dc 100644 --- a/src/framework/platform/androidwindow.h +++ b/src/framework/platform/androidwindow.h @@ -145,6 +145,9 @@ class AndroidWindow : public PlatformWindow std::queue m_events; NativeEvent m_currentEvent; + + ticks_t m_lastPress = 0; + bool m_isDragging = false; }; extern "C" {