diff options
author | Shawn Rutledge <shawn.rutledge@qt.io> | 2023-11-08 15:33:29 -0700 |
---|---|---|
committer | Tor Arne Vestbø <tor.arne.vestbo@qt.io> | 2023-11-09 12:10:52 -0800 |
commit | 68369237bfefc81410a0d8d7389ed5e0fba0b421 (patch) | |
tree | 373775eb4924d5046d7a8000a9beac221ff5cbe5 /src/plugins/platforms/ios | |
parent | f639c04f84322b9c81b11261cf14625497d78f00 (diff) |
iOS: Make nextTouchId static, unsigned and let it overflow
If an application has two windows, and the user tries to do multi-touch
gestures with different fingers in each window at the same time, we want
the touchpoint IDs to be unique. m_nextTouchId was a per-window variable
before; the result was that the QEventPoint delivered to the second
window was replacing values (including QEventPointPrivate::window)
in the persistent QEventPoint that was still being held in the first
window; then when the release of the first point occurred,
QGuiApplicationPrivate::processTouchEvent() saw its destination window
pointer as null because the second touchpoint had already been released.
QEventPoint::id is of type int, with negative values being invalid.
nextTouchId is of type quint16 so that it will always be positive, and
we can let it eventually overflow (wrap back to 0) rather than resetting
it to 0 after each touch gesture. The only requirement is that the IDs
need to be unique and positive (and typically they are sequential: that
makes debug output easier to understand).
Task-number: QTBUG-118909
Change-Id: Ia0f1edc9a5e2b362028bed4418fed228814cddb6
Pick-to: 6.5 6.6
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
Diffstat (limited to 'src/plugins/platforms/ios')
-rw-r--r-- | src/plugins/platforms/ios/quiview.mm | 10 |
1 files changed, 4 insertions, 6 deletions
diff --git a/src/plugins/platforms/ios/quiview.mm b/src/plugins/platforms/ios/quiview.mm index 979de6a313..7b1de0ae71 100644 --- a/src/plugins/platforms/ios/quiview.mm +++ b/src/plugins/platforms/ios/quiview.mm @@ -53,7 +53,6 @@ inline ulong getTimeStamp(UIEvent *event) @implementation QUIView { QHash<NSUInteger, QWindowSystemInterface::TouchPoint> m_activeTouches; UITouch *m_activePencilTouch; - int m_nextTouchId; NSMutableArray<UIAccessibilityElement *> *m_accessibleElements; UIPanGestureRecognizer *m_scrollGestureRecognizer; CGPoint m_lastScrollCursorPos; @@ -518,7 +517,10 @@ inline ulong getTimeStamp(UIEvent *event) { Q_ASSERT(!m_activeTouches.contains(touch.hash)); #endif - m_activeTouches[touch.hash].id = m_nextTouchId++; + // Use window-independent touch identifiers, so that + // multi-touch works across windows. + static quint16 nextTouchId = 0; + m_activeTouches[touch.hash].id = nextTouchId++; #if QT_CONFIG(tabletevent) } #endif @@ -560,9 +562,6 @@ inline ulong getTimeStamp(UIEvent *event) // tvOS only supports single touch m_activeTouches.clear(); #endif - - if (m_activeTouches.isEmpty() && !m_activePencilTouch) - m_nextTouchId = 0; } - (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event @@ -595,7 +594,6 @@ inline ulong getTimeStamp(UIEvent *event) qWarning("Subset of active touches cancelled by UIKit"); m_activeTouches.clear(); - m_nextTouchId = 0; m_activePencilTouch = nil; ulong timestamp = event ? getTimeStamp(event) : ([[NSProcessInfo processInfo] systemUptime] * 1000); |