From 7ed6a247bfcf314b4a7bc8332b813b3e92997e41 Mon Sep 17 00:00:00 2001 From: Laszlo Agocs Date: Mon, 23 Jan 2012 10:28:58 +0200 Subject: Fix synthesizing mouse events when touches change ordering MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit There is no guarantee the touches will be listed in the same order in an update: the platform/generic plug-in, the drivers, etc. are all free to shuffle the list of touch points in each report (even though the order is fairly stable with most systems). Therefore, to be safe, move and release events should be generated not from the first point in the list but from the one with the matching id. Change-Id: I6615224cbf2cfdc440143eb3191482a23d85c6a4 Reviewed-by: Samuel Rødal --- src/gui/kernel/qguiapplication.cpp | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) (limited to 'src/gui/kernel/qguiapplication.cpp') diff --git a/src/gui/kernel/qguiapplication.cpp b/src/gui/kernel/qguiapplication.cpp index 6e0d96a788..6a8f8582be 100644 --- a/src/gui/kernel/qguiapplication.cpp +++ b/src/gui/kernel/qguiapplication.cpp @@ -114,6 +114,7 @@ static bool force_reverse = false; QGuiApplicationPrivate *QGuiApplicationPrivate::self = 0; QTouchDevice *QGuiApplicationPrivate::m_fakeTouchDevice = 0; +int QGuiApplicationPrivate::m_fakeMouseSourcePointId = 0; #ifndef QT_NO_CLIPBOARD QClipboard *QGuiApplicationPrivate::qt_clipboard = 0; @@ -1036,11 +1037,22 @@ void QGuiApplicationPrivate::processTouchEvent(QWindowSystemInterfacePrivate::To if (touchEvent.device()->type() != QTouchDevice::TouchPad) { Qt::MouseButtons b = eventType == QEvent::TouchEnd ? Qt::NoButton : Qt::LeftButton; - const QTouchEvent::TouchPoint &touchPoint = touchEvent.touchPoints().first(); - - QWindowSystemInterfacePrivate::MouseEvent fake(w, e->timestamp, touchPoint.pos(), touchPoint.screenPos(), b, e->modifiers); - fake.synthetic = true; - processMouseEvent(&fake); + QList touchPoints = touchEvent.touchPoints(); + if (eventType == QEvent::TouchBegin) + m_fakeMouseSourcePointId = touchPoints.first().id(); + + for (int i = 0; i < touchPoints.count(); ++i) { + const QTouchEvent::TouchPoint &touchPoint = touchPoints.at(i); + if (touchPoint.id() == m_fakeMouseSourcePointId) { + QWindowSystemInterfacePrivate::MouseEvent fake(w, e->timestamp, + touchPoint.pos(), + touchPoint.screenPos(), + b, e->modifiers); + fake.synthetic = true; + processMouseEvent(&fake); + break; + } + } } } } -- cgit v1.2.3