diff options
author | Tinja Paavoseppä <[email protected]> | 2024-06-13 09:21:32 +0300 |
---|---|---|
committer | Tinja Paavoseppä <[email protected]> | 2024-06-13 17:18:16 +0300 |
commit | 15674f4ce9ea455b47f68d8871d5676d7a731630 (patch) | |
tree | 4c2b455c52ad098b04416c6b376a91417dfe638e /src/plugins/platforms/android/androidjniinput.cpp | |
parent | 0a10d23c4a49dd14a1ded41b7cc6921909b0ee7a (diff) |
Android: Map touch position to global coordinates
When QtWindow is not at 0,0 of its parent, not mapping the position
leads to offsets in the touched position in Android vs where it is
received in Qt, e.g. needing to touch below a button's actual
position to trigger a click.
Task-number: QTBUG-126178
Pick-to: 6.7 6.8
Change-Id: Icd62ed59f0f323ba3977145c3304e4e874aa4fa2
Reviewed-by: Assam Boudjelthia <[email protected]>
Diffstat (limited to 'src/plugins/platforms/android/androidjniinput.cpp')
-rw-r--r-- | src/plugins/platforms/android/androidjniinput.cpp | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/src/plugins/platforms/android/androidjniinput.cpp b/src/plugins/platforms/android/androidjniinput.cpp index 07f2786cc63..2692488ec62 100644 --- a/src/plugins/platforms/android/androidjniinput.cpp +++ b/src/plugins/platforms/android/androidjniinput.cpp @@ -266,7 +266,7 @@ namespace QtAndroidInput m_touchPoints.clear(); } - static void touchAdd(JNIEnv */*env*/, jobject /*thiz*/, jint /*winId*/, jint id, jint action, jboolean /*primary*/, jint x, jint y, + static void touchAdd(JNIEnv */*env*/, jobject /*thiz*/, jint winId, jint id, jint action, jboolean /*primary*/, jint x, jint y, jfloat major, jfloat minor, jfloat rotation, jfloat pressure) { QEventPoint::State state = QEventPoint::State::Stationary; @@ -287,16 +287,25 @@ namespace QtAndroidInput const int dw = availableWidthPixels(); const int dh = availableHeightPixels(); + QWindow *window = QtAndroid::windowFromId(winId); + if (!window) { + qCWarning(lcQpaInputMethods, "Touch event received for non-existing window %d", winId); + return; + } + + QPointF mappedTouchPoint = window->mapToGlobal(QPointF(x, y)); QWindowSystemInterface::TouchPoint touchPoint; touchPoint.id = id; touchPoint.pressure = pressure; touchPoint.rotation = qRadiansToDegrees(rotation); - touchPoint.normalPosition = QPointF(double(x / dw), double(y / dh)); + touchPoint.normalPosition = QPointF((mappedTouchPoint.x() / dw), + (mappedTouchPoint.y() / dh)); touchPoint.state = state; - touchPoint.area = QRectF(x - double(minor * 0.5f), - y - double(major * 0.5f), + touchPoint.area = QRectF(mappedTouchPoint.x() - double(minor * 0.5f), + mappedTouchPoint.y() - double(major * 0.5f), double(minor), double(major)); + m_touchPoints.push_back(touchPoint); if (state == QEventPoint::State::Pressed) { QAndroidInputContext *inputContext = QAndroidInputContext::androidInputContext(); |