Skip to content

Commit 9b16480

Browse files
committed
Backport crucial Qt 6.8.3 fixes to our overlay Qt ports
1 parent 9b41339 commit 9b16480

File tree

5 files changed

+400
-0
lines changed

5 files changed

+400
-0
lines changed
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
From 154560df217475825651682e463fccea5affcdd8 Mon Sep 17 00:00:00 2001
2+
From: Bartlomiej Moskal <[email protected]>
3+
Date: Wed, 5 Feb 2025 12:20:46 +0100
4+
Subject: [PATCH] Android: Fix cursorHandle and EditPopup positions
5+
6+
After the commit 28df9a49776a88cb1a8e69348ae19a59b16a5b7e, a regression
7+
occurred in the positioning of cursorHandle and EditPopup.
8+
9+
Previously, these positions were calculated using QtEditText
10+
coordinates, which worked correctly because the QtEditText size matched
11+
the QtWindow size. However, after the mentioned commit, the QtEditText
12+
size no longer reflects the window size. In this case, we need to use
13+
the parent View for calculations.
14+
15+
This adjustment was already made for the single cursorHandle.
16+
17+
This commit also updates the positioning of selection handles and the EditPopup.
18+
19+
Fixes: QTBUG-132589
20+
Change-Id: I861292e363452d487284e3f603fe03a21a334aa4
21+
Reviewed-by: Assam Boudjelthia <[email protected]>
22+
(cherry picked from commit 5bd26fda7a3f0a509a64847b58b916830ebc2d0c)
23+
Reviewed-by: Qt Cherry-pick Bot <[email protected]>
24+
(cherry picked from commit 941434e81fe073d55607267ea839025282413900)
25+
---
26+
.../jar/src/org/qtproject/qt/android/CursorHandle.java | 12 ++++++++++--
27+
.../jar/src/org/qtproject/qt/android/EditPopupMenu.java | 15 +++++++++++----
28+
.../jar/src/org/qtproject/qt/android/QtEditText.java | 2 +-
29+
3 files changed, 22 insertions(+), 7 deletions(-)
30+
31+
diff --git a/src/android/jar/src/org/qtproject/qt/android/CursorHandle.java b/src/android/jar/src/org/qtproject/qt/android/CursorHandle.java
32+
index 519fe86968d3..79e25ea977aa 100644
33+
--- a/src/android/jar/src/org/qtproject/qt/android/CursorHandle.java
34+
+++ b/src/android/jar/src/org/qtproject/qt/android/CursorHandle.java
35+
@@ -133,7 +133,15 @@ class CursorHandle implements ViewTreeObserver.OnPreDrawListener
36+
initOverlay();
37+
38+
final int[] layoutLocation = new int[2];
39+
- m_layout.getLocationOnScreen(layoutLocation);
40+
+
41+
+ // m_layout is QtEditText. Since it doesn't match the QtWindow size, we should use its
42+
+ // parent for cursorHandle positioning. However, there may be cases where the parent is
43+
+ // not set. In such cases, we need to use QtEditText instead.
44+
+ View positioningView = (View) m_layout.getParent();
45+
+ if (positioningView == null)
46+
+ positioningView = m_layout;
47+
+
48+
+ positioningView.getLocationOnScreen(layoutLocation);
49+
50+
// These values are used for handling split screen case
51+
final int[] activityLocation = new int[2];
52+
@@ -156,7 +164,7 @@ class CursorHandle implements ViewTreeObserver.OnPreDrawListener
53+
m_popup.update(x2, y2, -1, -1);
54+
m_cursorView.adjusted(x - m_posX, y - m_posY);
55+
} else {
56+
- m_popup.showAtLocation(m_layout, 0, x2, y2);
57+
+ m_popup.showAtLocation(positioningView, 0, x2, y2);
58+
}
59+
60+
m_posX = x;
61+
diff --git a/src/android/jar/src/org/qtproject/qt/android/EditPopupMenu.java b/src/android/jar/src/org/qtproject/qt/android/EditPopupMenu.java
62+
index cd107ab4882a..885c43225d2f 100644
63+
--- a/src/android/jar/src/org/qtproject/qt/android/EditPopupMenu.java
64+
+++ b/src/android/jar/src/org/qtproject/qt/android/EditPopupMenu.java
65+
@@ -58,7 +58,14 @@ class EditPopupMenu implements ViewTreeObserver.OnPreDrawListener, View.OnLayout
66+
Point viewSize = m_view.getCalculatedSize();
67+
68+
final int[] layoutLocation = new int[2];
69+
- m_editText.getLocationOnScreen(layoutLocation);
70+
+
71+
+ // Since QtEditText doesn't match the QtWindow size, we should use its parent for
72+
+ // EditPopupMenu positioning. However, there may be cases where the parent is
73+
+ // not set. In such cases, we need to use QtEditText instead.
74+
+ View positioningView = (View) m_editText.getParent();
75+
+ if (positioningView == null)
76+
+ positioningView = m_editText;
77+
+ positioningView.getLocationOnScreen(layoutLocation);
78+
79+
// These values are used for handling split screen case
80+
final int[] activityLocation = new int[2];
81+
@@ -88,8 +95,8 @@ class EditPopupMenu implements ViewTreeObserver.OnPreDrawListener, View.OnLayout
82+
}
83+
}
84+
85+
- if (m_editText.getWidth() < x + viewSize.x / 2)
86+
- x2 = m_editText.getWidth() - viewSize.x;
87+
+ if (positioningView.getWidth() < x + viewSize.x / 2)
88+
+ x2 = positioningView.getWidth() - viewSize.x;
89+
90+
if (x2 < 0)
91+
x2 = 0;
92+
@@ -97,7 +104,7 @@ class EditPopupMenu implements ViewTreeObserver.OnPreDrawListener, View.OnLayout
93+
if (m_popup.isShowing())
94+
m_popup.update(x2, y2, -1, -1);
95+
else
96+
- m_popup.showAtLocation(m_editText, 0, x2, y2);
97+
+ m_popup.showAtLocation(positioningView, 0, x2, y2);
98+
99+
m_posX = x;
100+
m_posY = y;
101+
diff --git a/src/android/jar/src/org/qtproject/qt/android/QtEditText.java b/src/android/jar/src/org/qtproject/qt/android/QtEditText.java
102+
index 69126192169c..edff72d6937d 100644
103+
--- a/src/android/jar/src/org/qtproject/qt/android/QtEditText.java
104+
+++ b/src/android/jar/src/org/qtproject/qt/android/QtEditText.java
105+
@@ -267,7 +267,7 @@ class QtEditText extends View
106+
break;
107+
case CursorHandleShowNormal:
108+
if (m_cursorHandle == null) {
109+
- m_cursorHandle = new CursorHandle((Activity) getContext(), (View) getParent(),
110+
+ m_cursorHandle = new CursorHandle((Activity) getContext(), this,
111+
CursorHandle.IdCursorHandle,
112+
android.R.attr.textSelectHandle, false);
113+
}
114+
--
115+
2.16.3
116+
Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
From a3203542dced8b679633e666ff008ba5f017e827 Mon Sep 17 00:00:00 2001
2+
From: Andrew Forrest <[email protected]>
3+
Date: Mon, 3 Feb 2025 16:10:15 +0000
4+
Subject: [PATCH] Android: Fix mouse button processing
5+
6+
Fixes clicking UI elements with a mouse on Android.
7+
8+
8d8cbe87e21f05b7d611ed4be47299977288b267 introduced changes to support
9+
mouse buttons other than Qt::LeftButton, but the release always looked
10+
like no buttons changed, nor were they tracked (m_buttons is always
11+
Qt::NoButton). Qt was not notified of mouse up, so nothing was clickable.
12+
13+
Now all mouse events go through sendMouseButtonEvents, and the last seen
14+
button state is tracked for every event. If a mouse up with no buttons
15+
occurs, the last seen set of buttons is used instead, so Qt correctly
16+
handles the event. Also adds the mouse button state information to
17+
mouse move events from Android, so the workaround for delivering
18+
Qt::LeftButton when a window is tracking a move while a button is
19+
pressed has been removed.
20+
21+
Tested on a Samsung A1 with a Bluetooth mouse.
22+
23+
Fixes: QTBUG-132700
24+
Fixes: QTBUG-130297
25+
Change-Id: I241282c2915d7e6cf99db7f0bc1ad2d541349077
26+
Reviewed-by: Assam Boudjelthia <[email protected]>
27+
(cherry picked from commit d908e043984dcfed3aa80e30cd1cafacd13b644d)
28+
Reviewed-by: Qt Cherry-pick Bot <[email protected]>
29+
(cherry picked from commit 65e9eca63b3f522065018777ac07c5a71c08ff37)
30+
---
31+
.../org/qtproject/qt/android/QtInputDelegate.java | 6 ++--
32+
src/plugins/platforms/android/androidjniinput.cpp | 32 +++++++++++-----------
33+
2 files changed, 19 insertions(+), 19 deletions(-)
34+
35+
diff --git a/src/android/jar/src/org/qtproject/qt/android/QtInputDelegate.java b/src/android/jar/src/org/qtproject/qt/android/QtInputDelegate.java
36+
index 89f2529ab870..2531942de565 100644
37+
--- a/src/android/jar/src/org/qtproject/qt/android/QtInputDelegate.java
38+
+++ b/src/android/jar/src/org/qtproject/qt/android/QtInputDelegate.java
39+
@@ -517,7 +517,7 @@ class QtInputDelegate implements QtInputConnection.QtInputConnectionListener, Qt
40+
// pointer methods
41+
static native void mouseDown(int winId, int x, int y, int mouseButtonState);
42+
static native void mouseUp(int winId, int x, int y, int mouseButtonState);
43+
- static native void mouseMove(int winId, int x, int y);
44+
+ static native void mouseMove(int winId, int x, int y, int mouseButtonState);
45+
static native void mouseWheel(int winId, int x, int y, float hDelta, float vDelta);
46+
static native void touchBegin(int winId);
47+
static native void touchAdd(int winId, int pointerId, int action, boolean primary,
48+
@@ -643,12 +643,12 @@ class QtInputDelegate implements QtInputConnection.QtInputConnectionListener, Qt
49+
case MotionEvent.ACTION_HOVER_MOVE:
50+
case MotionEvent.ACTION_MOVE:
51+
if (event.getToolType(0) == MotionEvent.TOOL_TYPE_MOUSE) {
52+
- mouseMove(id, (int) event.getX(), (int) event.getY());
53+
+ mouseMove(id, (int) event.getX(), (int) event.getY(), event.getButtonState());
54+
} else {
55+
int dx = (int) (event.getX() - m_oldX);
56+
int dy = (int) (event.getY() - m_oldY);
57+
if (Math.abs(dx) > 5 || Math.abs(dy) > 5) {
58+
- mouseMove(id, (int) event.getX(), (int) event.getY());
59+
+ mouseMove(id, (int) event.getX(), (int) event.getY(), event.getButtonState());
60+
m_oldX = (int) event.getX();
61+
m_oldY = (int) event.getY();
62+
}
63+
diff --git a/src/plugins/platforms/android/androidjniinput.cpp b/src/plugins/platforms/android/androidjniinput.cpp
64+
index a0faedcc5b2f..461b2da51c96 100644
65+
--- a/src/plugins/platforms/android/androidjniinput.cpp
66+
+++ b/src/plugins/platforms/android/androidjniinput.cpp
67+
@@ -28,7 +28,7 @@ Q_DECLARE_JNI_CLASS(QtInputInterface, "org/qtproject/qt/android/QtInputInterface
68+
namespace QtAndroidInput
69+
{
70+
static bool m_ignoreMouseEvents = false;
71+
- static Qt::MouseButtons m_buttons = Qt::NoButton;
72+
+ static Qt::MouseButtons m_lastSeenButtons = Qt::NoButton;
73+
74+
static QRect m_softwareKeyboardRect;
75+
76+
@@ -143,19 +143,22 @@ namespace QtAndroidInput
77+
static void sendMouseButtonEvents(QWindow *topLevel, QPoint localPos, QPoint globalPos,
78+
jint mouseButtonState, QEvent::Type type)
79+
{
80+
- const Qt::MouseButtons mouseButtons = toMouseButtons(mouseButtonState);
81+
- const Qt::MouseButtons changedButtons = mouseButtons & ~m_buttons;
82+
+ const Qt::MouseButtons qtButtons = toMouseButtons(mouseButtonState);
83+
+ const bool mouseReleased = type == QEvent::MouseButtonRelease && qtButtons == Qt::NoButton;
84+
+ const Qt::MouseButtons eventButtons = mouseReleased ? m_lastSeenButtons : qtButtons;
85+
+ m_lastSeenButtons = qtButtons;
86+
87+
- if (changedButtons == Qt::NoButton)
88+
- return;
89+
-
90+
- static_assert (sizeof(changedButtons) <= sizeof(uint), "Qt::MouseButtons size changed. Adapt code.");
91+
+ static_assert (sizeof(eventButtons) <= sizeof(uint), "Qt::MouseButtons size changed. Adapt code.");
92+
93+
- for (uint buttonInt = 0x1; static_cast<uint>(changedButtons) >= buttonInt; buttonInt <<= 1) {
94+
+ if (eventButtons == Qt::NoButton) {
95+
+ QWindowSystemInterface::handleMouseEvent(topLevel, localPos, globalPos, qtButtons, Qt::NoButton, type);
96+
+ return;
97+
+ }
98+
+ for (uint buttonInt = 0x1; static_cast<uint>(eventButtons) >= buttonInt; buttonInt <<= 1) {
99+
const auto button = static_cast<Qt::MouseButton>(buttonInt);
100+
- if (changedButtons.testFlag(button)) {
101+
+ if (eventButtons.testFlag(button)) {
102+
QWindowSystemInterface::handleMouseEvent(topLevel, localPos, globalPos,
103+
- mouseButtons, button, type);
104+
+ qtButtons, button, type);
105+
}
106+
}
107+
}
108+
@@ -188,9 +191,8 @@ namespace QtAndroidInput
109+
m_mouseGrabber.clear();
110+
}
111+
112+
- static void mouseMove(JNIEnv */*env*/, jobject /*thiz*/, jint winId, jint x, jint y)
113+
+ static void mouseMove(JNIEnv */*env*/, jobject /*thiz*/, jint winId, jint x, jint y, jint mouseButtonState)
114+
{
115+
-
116+
if (m_ignoreMouseEvents)
117+
return;
118+
119+
@@ -200,9 +202,7 @@ namespace QtAndroidInput
120+
window = windowFromId(winId);
121+
const QPoint localPos = window && window->handle() ?
122+
window->handle()->mapFromGlobal(globalPos) : globalPos;
123+
- QWindowSystemInterface::handleMouseEvent(window, localPos, globalPos,
124+
- Qt::MouseButtons(m_mouseGrabber ? Qt::LeftButton : Qt::NoButton),
125+
- Qt::NoButton, QEvent::MouseMove);
126+
+ sendMouseButtonEvents(window, localPos, globalPos, mouseButtonState, QEvent::MouseMove);
127+
}
128+
129+
static void mouseWheel(JNIEnv */*env*/, jobject /*thiz*/, jint winId, jint x, jint y, jfloat hdelta, jfloat vdelta)
130+
@@ -909,7 +909,7 @@ namespace QtAndroidInput
131+
{"touchCancel", "(I)V", (void *)touchCancel},
132+
{"mouseDown", "(IIII)V", (void *)mouseDown},
133+
{"mouseUp", "(IIII)V", (void *)mouseUp},
134+
- {"mouseMove", "(III)V", (void *)mouseMove},
135+
+ {"mouseMove", "(IIII)V", (void *)mouseMove},
136+
{"mouseWheel", "(IIIFF)V", (void *)mouseWheel},
137+
{"longPress", "(III)V", (void *)longPress},
138+
{"isTabletEventSupported", "()Z", (void *)isTabletEventSupported},
139+
--
140+
2.16.3
141+

vcpkg/ports/qtbase/portfile.cmake

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ set(${PORT}_PATCHES
2323
fix_deploy_windows.patch
2424
fix-link-lib-discovery.patch
2525
macdeployqt-symlinks.patch
26+
bluetooth_mouse_fix.patch
27+
android_cursor_location.patch
2628
)
2729

2830
if(VCPKG_TARGET_IS_WINDOWS AND NOT VCPKG_TARGET_IS_MINGW)

vcpkg/ports/qtmultimedia/portfile.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ set(${PORT}_PATCHES
77
remove-static-ssl-stub.patch
88
private_libs.patch
99
ffmpeg-compile-def.patch
10+
video_recording_fix.patch
1011
)
1112

1213
vcpkg_check_features(OUT_FEATURE_OPTIONS FEATURE_OPTIONS

0 commit comments

Comments
 (0)