Commit 6fe29b52 authored by Sharaf Zaman's avatar Sharaf Zaman Committed by Halla Rempt

Android: Properly handle tablet events

Qt didn't properly pass down tablet events which caused problems with
hovering, TabletPress/Release.

BUG:423299
BUG:431611
CCBUG:429940
parent 71ac4050
From 87e7c56efb62aa990c54ac795fa04948a4e51fdd Mon Sep 17 00:00:00 2001
From: Sharaf Zaman <sharafzaz121@gmail.com>
Date: Thu, 10 Sep 2020 10:46:57 +0000
Subject: [PATCH 5/5] Handle Primary and Secondary stylus buttons on Android
Change-Id: Ibe4fcae58cf994c92fe7dcc525d5daa3699996ca
---
.../platforms/android/androidjniinput.cpp | 18 ++++++++++++------
.../platforms/android/androidjniinput.h | 10 ++++++++++
2 files changed, 22 insertions(+), 6 deletions(-)
diff --git a/src/plugins/platforms/android/androidjniinput.cpp b/src/plugins/platforms/android/androidjniinput.cpp
index deb30e404a..313407575e 100644
--- a/src/plugins/platforms/android/androidjniinput.cpp
+++ b/src/plugins/platforms/android/androidjniinput.cpp
@@ -63,6 +63,7 @@ namespace QtAndroidInput
static bool m_ignoreMouseEvents = false;
static bool m_softwareKeyboardVisible = false;
static QRect m_softwareKeyboardRect;
+ static int m_previousButtons = Qt::NoButton;
static QList<QWindowSystemInterface::TouchPoint> m_touchPoints;
@@ -357,17 +358,22 @@ namespace QtAndroidInput
// when action == ACTION_UP (1) it's a release; otherwise we say which button is pressed
Qt::MouseButtons buttons = Qt::NoButton;
switch (action) {
- case 1: // ACTION_UP
- case 212: // stylus release while side-button held on Galaxy Note 4
+ case ACTION_UP:
buttons = Qt::NoButton;
break;
- default: // action is press or drag
- if (buttonState == 0)
+ default: // for now only ACTION_DOWN
+ if (buttonState == NO_BUTTON)
buttons = Qt::LeftButton;
- else // 2 means RightButton
- buttons = Qt::MouseButtons(buttonState);
+ else if (buttonState == BUTTON_STYLUS_PRIMARY)
+ buttons = Qt::MiddleButton;
+ else if (buttonState == BUTTON_STYLUS_SECONDARY)
+ buttons = Qt::RightButton;
break;
}
+ if (m_previousButtons != buttons && m_previousButtons != Qt::NoButton) {
+ buttons = Qt::NoButton;
+ }
+ m_previousButtons = buttons;
#ifdef QT_DEBUG_ANDROID_STYLUS
qDebug() << action << pointerType << buttonState << '@' << x << y << "pressure" << pressure << ": buttons" << buttons;
diff --git a/src/plugins/platforms/android/androidjniinput.h b/src/plugins/platforms/android/androidjniinput.h
index cc3070c4aa..8f32485193 100644
--- a/src/plugins/platforms/android/androidjniinput.h
+++ b/src/plugins/platforms/android/androidjniinput.h
@@ -48,6 +48,16 @@ QT_BEGIN_NAMESPACE
namespace QtAndroidInput
{
+ enum Actions {
+ ACTION_DOWN = 0,
+ ACTION_UP = 1,
+ };
+ enum ButtonStates {
+ NO_BUTTON = 0,
+ BUTTON_STYLUS_PRIMARY = 32, // 0x00000020
+ BUTTON_STYLUS_SECONDARY = 64, // 0x00000040
+ };
+
// Software keyboard support
void showSoftwareKeyboard(int top, int left, int width, int height, int inputHints, int enterKeyType);
void resetSoftwareKeyboard();
--
2.28.0
From f59d4cdfcaf5d546fa92e88df7f33a8f6b3b0e5a Mon Sep 17 00:00:00 2001
From: Sharaf Zaman <sharafzaz121@gmail.com>
Date: Thu, 10 Sep 2020 10:46:57 +0000
Subject: [PATCH] Android: Properly handle Tablet events
Prior to this Hover events from stylus/tablet were treated as Mouse
events and primary and secondary stylus buttons weren't handled either.
---
.../org/qtproject/qt5/android/QtNative.java | 21 +++++++++++++------
.../platforms/android/androidjniinput.cpp | 15 ++++++++-----
2 files changed, 25 insertions(+), 11 deletions(-)
diff --git a/src/android/jar/src/org/qtproject/qt5/android/QtNative.java b/src/android/jar/src/org/qtproject/qt5/android/QtNative.java
index 2b76651072..9aaf8aa76b 100644
--- a/src/android/jar/src/org/qtproject/qt5/android/QtNative.java
+++ b/src/android/jar/src/org/qtproject/qt5/android/QtNative.java
@@ -691,7 +691,7 @@ public class QtNative
}
//@ANDROID-9
- static public void sendTouchEvent(MotionEvent event, int id)
+ static public boolean sendTouchEvent(MotionEvent event, int id)
{
int pointerType = 0;
@@ -708,15 +708,16 @@ public class QtNative
}
if (event.getToolType(0) == MotionEvent.TOOL_TYPE_MOUSE) {
- sendMouseEvent(event, id);
+ return sendMouseEvent(event, id);
} else if (m_tabletEventSupported && pointerType != 0) {
float tiltRot = event.getAxisValue(MotionEvent.AXIS_TILT);
float orientation = event.getAxisValue(MotionEvent.AXIS_ORIENTATION);
float tiltX = (float) Math.toDegrees(-Math.sin(orientation) * tiltRot);
float tiltY = (float) Math.toDegrees(Math.cos(orientation) * tiltRot);
- tabletEvent(id, event.getDeviceId(), event.getEventTime(), event.getAction(), pointerType,
+ tabletEvent(id, event.getDeviceId(), event.getEventTime(), event.getActionMasked(), pointerType,
event.getButtonState(), event.getX(), event.getY(), event.getPressure(), tiltX, tiltY,
(float) Math.toDegrees(orientation), event.getMetaState());
+ return true;
} else {
touchBegin(id);
for (int i = 0; i < event.getPointerCount(); ++i) {
@@ -732,6 +733,7 @@ public class QtNative
event.getPressure(i));
}
touchEnd(id, event.getAction());
+ return true;
}
}
@@ -742,12 +744,19 @@ public class QtNative
static public boolean sendGenericMotionEvent(MotionEvent event, int id)
{
- if (((event.getAction() & (MotionEvent.ACTION_SCROLL | MotionEvent.ACTION_HOVER_MOVE)) == 0)
- || (event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != InputDevice.SOURCE_CLASS_POINTER) {
+ if (!event.isFromSource(InputDevice.SOURCE_CLASS_POINTER)) {
return false;
}
- return sendMouseEvent(event, id);
+ if (event.isFromSource(InputDevice.SOURCE_MOUSE)) {
+ return sendMouseEvent(event, id);
+ } else if ((event.getSource() & (InputDevice.SOURCE_STYLUS |
+ InputDevice.SOURCE_TOUCHPAD |
+ InputDevice.SOURCE_TOUCHSCREEN)) != 0) {
+
+ return sendTouchEvent(event, id);
+ }
+ return false;
}
static public boolean sendMouseEvent(MotionEvent event, int id)
diff --git a/src/plugins/platforms/android/androidjniinput.cpp b/src/plugins/platforms/android/androidjniinput.cpp
index a5d61f0fe4..81075e7f94 100644
--- a/src/plugins/platforms/android/androidjniinput.cpp
+++ b/src/plugins/platforms/android/androidjniinput.cpp
@@ -377,14 +377,19 @@ namespace QtAndroidInput
// when action == ACTION_UP (1) it's a release; otherwise we say which button is pressed
Qt::MouseButtons buttons = Qt::NoButton;
switch (action) {
- case 1: // ACTION_UP
- case 212: // stylus release while side-button held on Galaxy Note 4
+ case AMOTION_EVENT_ACTION_UP:
buttons = Qt::NoButton;
break;
- default: // action is press or drag
- if (buttonState == 0)
+ case AMOTION_EVENT_ACTION_MOVE:
+ case AMOTION_EVENT_ACTION_DOWN:
+ if (!buttonState)
buttons = Qt::LeftButton;
- else // 2 means RightButton
+ default:
+ if (buttonState == AMOTION_EVENT_BUTTON_STYLUS_PRIMARY)
+ buttons = Qt::MiddleButton;
+ else if (buttonState == AMOTION_EVENT_BUTTON_STYLUS_SECONDARY)
+ buttons = Qt::RightButton;
+ else if (buttonState)
buttons = Qt::MouseButtons(buttonState);
break;
}
--
2.29.2
......@@ -121,11 +121,11 @@ elseif (ANDROID)
COMMAND ${PATCH_COMMAND} -p1 -d qtbase -i ${CMAKE_CURRENT_SOURCE_DIR}/0094-Bugfix-fix-the-offset-bug-when-using-Stylus-with-And.patch
COMMAND ${PATCH_COMMAND} -p1 -d qtbase -i ${CMAKE_CURRENT_SOURCE_DIR}/0095-Add-support-for-pen-tilt-rotation-for-Android.patch
COMMAND ${PATCH_COMMAND} -p1 -d qtbase -i ${CMAKE_CURRENT_SOURCE_DIR}/0097-Pass-keyboard-modifiers-for-mouse-and-tablet-events.patch
COMMAND ${PATCH_COMMAND} -p1 -d qtbase -i ${CMAKE_CURRENT_SOURCE_DIR}/0098-Handle-Primary-and-Secondary-stylus-buttons-on-Andro.patch
COMMAND ${PATCH_COMMAND} -p1 -d qtbase -i ${CMAKE_CURRENT_SOURCE_DIR}/0099-Emulate-Long-Press-as-Right-Click-on-Android.patch
COMMAND ${PATCH_COMMAND} -p1 -d qtbase -i ${CMAKE_CURRENT_SOURCE_DIR}/0100-Fix-artifacts-when-rendering-multisubpath-dashed-QPa.patch
COMMAND ${PATCH_COMMAND} -p1 -d qtbase -i ${CMAKE_CURRENT_SOURCE_DIR}/0096-Android-Pass-the-button-state-through-JNI.patch
COMMAND ${PATCH_COMMAND} -p1 -d qtbase -i ${CMAKE_CURRENT_SOURCE_DIR}/0101-Android-Handle-the-ACTION_CANCEL-Event-from-Android.patch
COMMAND ${PATCH_COMMAND} -p1 -d qtbase -i ${CMAKE_CURRENT_SOURCE_DIR}/0102-Android-Properly-handle-Tablet-events.patch
# Upstream Qt 5.13
COMMAND ${PATCH_COMMAND} -p1 -d qtbase -i ${CMAKE_CURRENT_SOURCE_DIR}/0040-Add-file-engine-for-Android-content-URLs.patch
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment