xcb: Track touch points on a per device basis

Until now there was no connection between the tracked touch points and
the touch device. So the touch point for one device could be updated
by the touch event from another device.

Change-Id: I09fcf03a171cc361c6b5b4995758aa53d29ff414
Reviewed-by: Shawn Rutledge <shawn.rutledge@theqtcompany.com>
This commit is contained in:
Alexander Volkov 2015-06-02 11:40:38 +03:00
parent f04ed82ca2
commit 015bc9d7ce
2 changed files with 6 additions and 6 deletions

View File

@ -607,7 +607,6 @@ private:
#endif
QXcbEventReader *m_reader;
#if defined(XCB_USE_XINPUT2)
QHash<int, QWindowSystemInterface::TouchPoint> m_touchPoints;
QHash<int, XInput2TouchDeviceData*> m_touchDevices;
#endif
#ifdef Q_XCB_DEBUG

View File

@ -52,6 +52,7 @@ struct XInput2TouchDeviceData {
}
XIDeviceInfo *xiDeviceInfo;
QTouchDevice *qtTouchDevice;
QHash<int, QWindowSystemInterface::TouchPoint> touchPoints;
// Stuff that is relevant only for touchpads
QHash<int, QPointF> pointPressedPosition; // in screen coordinates where each point was pressed
@ -552,15 +553,15 @@ void QXcbConnection::xi2ProcessTouch(void *xiDevEvent, QXcbWindow *platformWindo
xXIDeviceEvent *xiDeviceEvent = static_cast<xXIDeviceEvent *>(xiDevEvent);
XInput2TouchDeviceData *dev = touchDeviceForId(xiDeviceEvent->sourceid);
Q_ASSERT(dev);
const bool firstTouch = m_touchPoints.isEmpty();
const bool firstTouch = dev->touchPoints.isEmpty();
if (xiDeviceEvent->evtype == XI_TouchBegin) {
QWindowSystemInterface::TouchPoint tp;
tp.id = xiDeviceEvent->detail % INT_MAX;
tp.state = Qt::TouchPointPressed;
tp.pressure = -1.0;
m_touchPoints[tp.id] = tp;
dev->touchPoints[tp.id] = tp;
}
QWindowSystemInterface::TouchPoint &touchPoint = m_touchPoints[xiDeviceEvent->detail];
QWindowSystemInterface::TouchPoint &touchPoint = dev->touchPoints[xiDeviceEvent->detail];
qreal x = fixed1616ToReal(xiDeviceEvent->root_x);
qreal y = fixed1616ToReal(xiDeviceEvent->root_y);
qreal nx = -1.0, ny = -1.0, d = 0.0;
@ -677,10 +678,10 @@ void QXcbConnection::xi2ProcessTouch(void *xiDevEvent, QXcbWindow *platformWindo
if (Q_UNLIKELY(lcQpaXInput().isDebugEnabled()))
qCDebug(lcQpaXInput) << " touchpoint " << touchPoint.id << " state " << touchPoint.state << " pos norm " << touchPoint.normalPosition <<
" area " << touchPoint.area << " pressure " << touchPoint.pressure;
QWindowSystemInterface::handleTouchEvent(platformWindow->window(), xiDeviceEvent->time, dev->qtTouchDevice, m_touchPoints.values());
QWindowSystemInterface::handleTouchEvent(platformWindow->window(), xiDeviceEvent->time, dev->qtTouchDevice, dev->touchPoints.values());
if (touchPoint.state == Qt::TouchPointReleased)
// If a touchpoint was released, we can forget it, because the ID won't be reused.
m_touchPoints.remove(touchPoint.id);
dev->touchPoints.remove(touchPoint.id);
else
// Make sure that we don't send TouchPointPressed/Moved in more than one QTouchEvent
// with this touch point if the next XI2 event is about a different touch point.