From cde86464dfceabeaf8320e2d48bab037f9d2d4b5 Mon Sep 17 00:00:00 2001 From: Assam Boudjelthia Date: Thu, 4 Jun 2020 16:05:06 +0300 Subject: Android: fix behovior of right click to not interfere with other clicks To allow treating long press as right click on Android, set the environment variable QT_ANDROID_ENABLE_RIGHT_MOUSE_FROM_LONG_PRESS to 1. Pick-to: 5.15 Fixes: QTBUG-73416 Task-number: QTBUG-84179 Change-Id: Ibe1d6af6ab9965112f1418638a088717798b554c Reviewed-by: Shawn Rutledge --- src/plugins/platforms/android/androidjniinput.cpp | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'src/plugins/platforms/android') diff --git a/src/plugins/platforms/android/androidjniinput.cpp b/src/plugins/platforms/android/androidjniinput.cpp index 97370236b1..68e8da03a4 100644 --- a/src/plugins/platforms/android/androidjniinput.cpp +++ b/src/plugins/platforms/android/androidjniinput.cpp @@ -202,7 +202,7 @@ namespace QtAndroidInput QMetaObject::invokeMethod(inputContext, "longPress", Q_ARG(int, x), Q_ARG(int, y)); //### TODO: add proper API for Qt 5.2 - static bool rightMouseFromLongPress = qEnvironmentVariableIntValue("QT_NECESSITAS_COMPATIBILITY_LONG_PRESS"); + static bool rightMouseFromLongPress = qEnvironmentVariableIntValue("QT_ANDROID_ENABLE_RIGHT_MOUSE_FROM_LONG_PRESS"); if (!rightMouseFromLongPress) return; m_ignoreMouseEvents = true; @@ -210,15 +210,15 @@ namespace QtAndroidInput QWindow *tlw = topLevelWindowAt(globalPos); QPoint localPos = tlw ? (globalPos-tlw->position()) : globalPos; - // Release left button - QWindowSystemInterface::handleMouseEvent(tlw, localPos, globalPos, - Qt::MouseButtons(Qt::NoButton), Qt::LeftButton, - QEvent::MouseButtonRelease); - - // Press right button - QWindowSystemInterface::handleMouseEvent(tlw, localPos, globalPos, - Qt::MouseButtons(Qt::RightButton), Qt::RightButton, - QEvent::MouseButtonPress); + // Click right button if no other button is already pressed. + if (!m_mouseGrabber) { + QWindowSystemInterface::handleMouseEvent(tlw, localPos, globalPos, + Qt::MouseButtons(Qt::RightButton), Qt::RightButton, + QEvent::MouseButtonPress); + QWindowSystemInterface::handleMouseEvent(tlw, localPos, globalPos, + Qt::MouseButtons(Qt::NoButton), Qt::RightButton, + QEvent::MouseButtonRelease); + } } static void touchBegin(JNIEnv */*env*/, jobject /*thiz*/, jint /*winId*/) -- cgit v1.2.3