summaryrefslogtreecommitdiffstats
path: root/src/plugins/platforms/android/androidjniinput.cpp
diff options
context:
space:
mode:
authorAndrew Forrest <[email protected]>2025-02-03 16:10:15 +0000
committerAndrew Forrest <[email protected]>2025-02-05 18:29:14 +0000
commitd908e043984dcfed3aa80e30cd1cafacd13b644d (patch)
treed13960e493d8ab87a35730873994760732febe59 /src/plugins/platforms/android/androidjniinput.cpp
parent97049278443860d3dd1b1efd20d1f7dabaf72a35 (diff)
Android: Fix mouse button processing
Fixes clicking UI elements with a mouse on Android. 8d8cbe87e21f05b7d611ed4be47299977288b267 introduced changes to support mouse buttons other than Qt::LeftButton, but the release always looked like no buttons changed, nor were they tracked (m_buttons is always Qt::NoButton). Qt was not notified of mouse up, so nothing was clickable. Now all mouse events go through sendMouseButtonEvents, and the last seen button state is tracked for every event. If a mouse up with no buttons occurs, the last seen set of buttons is used instead, so Qt correctly handles the event. Also adds the mouse button state information to mouse move events from Android, so the workaround for delivering Qt::LeftButton when a window is tracking a move while a button is pressed has been removed. Tested on a Samsung A1 with a Bluetooth mouse. Fixes: QTBUG-132700 Fixes: QTBUG-130297 Pick-to: 6.8 6.9 Change-Id: I241282c2915d7e6cf99db7f0bc1ad2d541349077 Reviewed-by: Assam Boudjelthia <[email protected]>
Diffstat (limited to 'src/plugins/platforms/android/androidjniinput.cpp')
-rw-r--r--src/plugins/platforms/android/androidjniinput.cpp32
1 files changed, 16 insertions, 16 deletions
diff --git a/src/plugins/platforms/android/androidjniinput.cpp b/src/plugins/platforms/android/androidjniinput.cpp
index cf4fc0a0d9d..8d1cdd80628 100644
--- a/src/plugins/platforms/android/androidjniinput.cpp
+++ b/src/plugins/platforms/android/androidjniinput.cpp
@@ -28,7 +28,7 @@ Q_DECLARE_JNI_CLASS(QtInputInterface, "org/qtproject/qt/android/QtInputInterface
namespace QtAndroidInput
{
static bool m_ignoreMouseEvents = false;
- static Qt::MouseButtons m_buttons = Qt::NoButton;
+ static Qt::MouseButtons m_lastSeenButtons = Qt::NoButton;
static QRect m_softwareKeyboardRect;
@@ -143,19 +143,22 @@ namespace QtAndroidInput
static void sendMouseButtonEvents(QWindow *topLevel, QPoint localPos, QPoint globalPos,
jint mouseButtonState, QEvent::Type type)
{
- const Qt::MouseButtons mouseButtons = toMouseButtons(mouseButtonState);
- const Qt::MouseButtons changedButtons = mouseButtons & ~m_buttons;
+ const Qt::MouseButtons qtButtons = toMouseButtons(mouseButtonState);
+ const bool mouseReleased = type == QEvent::MouseButtonRelease && qtButtons == Qt::NoButton;
+ const Qt::MouseButtons eventButtons = mouseReleased ? m_lastSeenButtons : qtButtons;
+ m_lastSeenButtons = qtButtons;
- if (changedButtons == Qt::NoButton)
- return;
-
- static_assert (sizeof(changedButtons) <= sizeof(uint), "Qt::MouseButtons size changed. Adapt code.");
+ static_assert (sizeof(eventButtons) <= sizeof(uint), "Qt::MouseButtons size changed. Adapt code.");
- for (uint buttonInt = 0x1; static_cast<uint>(changedButtons) >= buttonInt; buttonInt <<= 1) {
+ if (eventButtons == Qt::NoButton) {
+ QWindowSystemInterface::handleMouseEvent(topLevel, localPos, globalPos, qtButtons, Qt::NoButton, type);
+ return;
+ }
+ for (uint buttonInt = 0x1; static_cast<uint>(eventButtons) >= buttonInt; buttonInt <<= 1) {
const auto button = static_cast<Qt::MouseButton>(buttonInt);
- if (changedButtons.testFlag(button)) {
+ if (eventButtons.testFlag(button)) {
QWindowSystemInterface::handleMouseEvent(topLevel, localPos, globalPos,
- mouseButtons, button, type);
+ qtButtons, button, type);
}
}
}
@@ -188,9 +191,8 @@ namespace QtAndroidInput
m_mouseGrabber.clear();
}
- static void mouseMove(JNIEnv */*env*/, jobject /*thiz*/, jint winId, jint x, jint y)
+ static void mouseMove(JNIEnv */*env*/, jobject /*thiz*/, jint winId, jint x, jint y, jint mouseButtonState)
{
-
if (m_ignoreMouseEvents)
return;
@@ -200,9 +202,7 @@ namespace QtAndroidInput
window = windowFromId(winId);
const QPoint localPos = window && window->handle() ?
window->handle()->mapFromGlobal(globalPos) : globalPos;
- QWindowSystemInterface::handleMouseEvent(window, localPos, globalPos,
- Qt::MouseButtons(m_mouseGrabber ? Qt::LeftButton : Qt::NoButton),
- Qt::NoButton, QEvent::MouseMove);
+ sendMouseButtonEvents(window, localPos, globalPos, mouseButtonState, QEvent::MouseMove);
}
static void mouseWheel(JNIEnv */*env*/, jobject /*thiz*/, jint winId, jint x, jint y, jfloat hdelta, jfloat vdelta)
@@ -914,7 +914,7 @@ namespace QtAndroidInput
{"touchCancel", "(I)V", (void *)touchCancel},
{"mouseDown", "(IIII)V", (void *)mouseDown},
{"mouseUp", "(IIII)V", (void *)mouseUp},
- {"mouseMove", "(III)V", (void *)mouseMove},
+ {"mouseMove", "(IIII)V", (void *)mouseMove},
{"mouseWheel", "(IIIFF)V", (void *)mouseWheel},
{"longPress", "(III)V", (void *)longPress},
{"isTabletEventSupported", "()Z", (void *)isTabletEventSupported},