From 4222603f8ea3a0d0ef5b9a190605ad86e00f27f6 Mon Sep 17 00:00:00 2001 From: Laszlo Agocs Date: Sun, 27 Nov 2011 17:42:23 +0200 Subject: Extend touch events. The capability flags indicate which information is valid in the touch points. Previously there was no way to tell if e.g. the value returned by pressure() is actually the value provided by the driver/device or it is just something bogus due to pressure not being supported. The points' flags return information about the individual touch points. One use case is to differentiate between touches made by finger and pen. Velocity, if available, is now also exposed. Each touch point can now contain an additional list of "raw" positions. These points are not reported individually but are taken into account in some way by the underlying device and drivers to generate the final, "accurate" touch point. In case the underlying drivers expose these additional positions, they are made available in the lists returned by the touch points' rawScreenPosition(). The raw positions are only available in screen coordinates to prevent wasting time with mapping from global positions in applications that do not use this data. Instead, apps can query the QWindow to which the touch event was sent via QTouchEvent::window() and can call mapFromGlobal() manually if they need local raw positions. The capability and device type information is now held in a new QTouchDevice class. Each touch event will contain only a pointer to one of the global QTouchDevice instances. On top of type and capability, the new class also contains a name which can be used to differentiate between multiple touch input devices (i.e. to tell from which one a given QTouchEvent originates from). The introduction of QTouchDevice has three implications: The QTouchEvent constructor and QWindowSystemInterface::handleTouchEvent need to be changed (to pass a QTouchDevice pointer instead of merely a device type value), and each platform or generic plug-in is now responsible for registering one or more devices using the new API QWindowSystemInterface::registerTouchDevice. Change-Id: Ic1468d3e43933d8b5691d75aa67c43e1bc7ffe3e Reviewed-by: Lars Knoll --- src/plugins/generic/touchscreen/qtoucheventsenderqpa.cpp | 6 +++++- src/plugins/generic/touchscreen/qtoucheventsenderqpa.h | 3 +++ src/plugins/platforms/cocoa/qnsview.mm | 16 ++++++++++++---- src/plugins/platforms/windows/qwindowsmousehandler.cpp | 12 ++++++++++-- src/plugins/platforms/windows/qwindowsmousehandler.h | 2 ++ src/plugins/platforms/xcb/qxcbconnection_maemo.cpp | 15 +++++++++++++-- 6 files changed, 45 insertions(+), 9 deletions(-) (limited to 'src/plugins') diff --git a/src/plugins/generic/touchscreen/qtoucheventsenderqpa.cpp b/src/plugins/generic/touchscreen/qtoucheventsenderqpa.cpp index d9ec92cda7..08db058e10 100644 --- a/src/plugins/generic/touchscreen/qtoucheventsenderqpa.cpp +++ b/src/plugins/generic/touchscreen/qtoucheventsenderqpa.cpp @@ -52,6 +52,10 @@ QT_BEGIN_NAMESPACE QTouchEventSenderQPA::QTouchEventSenderQPA(const QString &spec) { m_forceToActiveWindow = spec.split(QLatin1Char(':')).contains(QLatin1String("force_window")); + m_device = new QTouchDevice; + m_device->setType(QTouchDevice::TouchScreen); + m_device->setCapabilities(QTouchDevice::Position | QTouchDevice::Area); + QWindowSystemInterface::registerTouchDevice(m_device); } void QTouchEventSenderQPA::touch_configure(int x_min, int x_max, int y_min, int y_max) @@ -103,7 +107,7 @@ void QTouchEventSenderQPA::touch_point(QEvent::Type state, #endif } - QWindowSystemInterface::handleTouchEvent(0, state, QTouchEvent::TouchScreen, touchPoints); + QWindowSystemInterface::handleTouchEvent(0, state, m_device, touchPoints); } QT_END_NAMESPACE diff --git a/src/plugins/generic/touchscreen/qtoucheventsenderqpa.h b/src/plugins/generic/touchscreen/qtoucheventsenderqpa.h index 91a6b4f3bb..b6e1613b24 100644 --- a/src/plugins/generic/touchscreen/qtoucheventsenderqpa.h +++ b/src/plugins/generic/touchscreen/qtoucheventsenderqpa.h @@ -48,6 +48,8 @@ QT_BEGIN_HEADER QT_BEGIN_NAMESPACE +class QTouchDevice; + class QTouchEventSenderQPA : public QTouchScreenObserver { public: @@ -61,6 +63,7 @@ private: int hw_range_x_max; int hw_range_y_min; int hw_range_y_max; + QTouchDevice *m_device; }; QT_END_NAMESPACE diff --git a/src/plugins/platforms/cocoa/qnsview.mm b/src/plugins/platforms/cocoa/qnsview.mm index 7c9873a908..4ae268dda5 100644 --- a/src/plugins/platforms/cocoa/qnsview.mm +++ b/src/plugins/platforms/cocoa/qnsview.mm @@ -54,6 +54,8 @@ #include #endif +static QTouchDevice *touchDevice = 0; + @interface NSEvent (Qt_Compile_Leopard_DeviceDelta) - (CGFloat)deviceDeltaX; - (CGFloat)deviceDeltaY; @@ -69,6 +71,12 @@ m_cgImage = 0; m_window = 0; m_buttons = Qt::NoButton; + if (!touchDevice) { + touchDevice = new QTouchDevice; + touchDevice->setType(QTouchDevice::TouchPad); + touchDevice->setCapabilities(QTouchDevice::Position | QTouchDevice::NormalizedPosition); + QWindowSystemInterface::registerTouchDevice(touchDevice); + } } return self; } @@ -287,28 +295,28 @@ { const NSTimeInterval timestamp = [event timestamp]; const QList points = QCocoaTouch::getCurrentTouchPointList(event, /*acceptSingleTouch= ### true or false?*/false); - QWindowSystemInterface::handleTouchEvent(m_window, timestamp * 1000, QEvent::TouchBegin, QTouchEvent::TouchPad, points); + QWindowSystemInterface::handleTouchEvent(m_window, timestamp * 1000, QEvent::TouchBegin, touchDevice, points); } - (void)touchesMovedWithEvent:(NSEvent *)event { const NSTimeInterval timestamp = [event timestamp]; const QList points = QCocoaTouch::getCurrentTouchPointList(event, /*acceptSingleTouch= ### true or false?*/false); - QWindowSystemInterface::handleTouchEvent(m_window, timestamp * 1000, QEvent::TouchUpdate, QTouchEvent::TouchPad, points); + QWindowSystemInterface::handleTouchEvent(m_window, timestamp * 1000, QEvent::TouchUpdate, touchDevice, points); } - (void)touchesEndedWithEvent:(NSEvent *)event { const NSTimeInterval timestamp = [event timestamp]; const QList points = QCocoaTouch::getCurrentTouchPointList(event, /*acceptSingleTouch= ### true or false?*/false); - QWindowSystemInterface::handleTouchEvent(m_window, timestamp * 1000, QEvent::TouchEnd, QTouchEvent::TouchPad, points); + QWindowSystemInterface::handleTouchEvent(m_window, timestamp * 1000, QEvent::TouchEnd, touchDevice, points); } - (void)touchesCancelledWithEvent:(NSEvent *)event { const NSTimeInterval timestamp = [event timestamp]; const QList points = QCocoaTouch::getCurrentTouchPointList(event, /*acceptSingleTouch= ### true or false?*/false); - QWindowSystemInterface::handleTouchEvent(m_window, timestamp * 1000, QEvent::TouchEnd, QTouchEvent::TouchPad, points); + QWindowSystemInterface::handleTouchEvent(m_window, timestamp * 1000, QEvent::TouchEnd, touchDevice, points); } #ifndef QT_NO_WHEELEVENT diff --git a/src/plugins/platforms/windows/qwindowsmousehandler.cpp b/src/plugins/platforms/windows/qwindowsmousehandler.cpp index 3ac4b24f1e..a2b6aa8d68 100644 --- a/src/plugins/platforms/windows/qwindowsmousehandler.cpp +++ b/src/plugins/platforms/windows/qwindowsmousehandler.cpp @@ -124,7 +124,8 @@ static inline void compressMouseMove(MSG *msg) */ QWindowsMouseHandler::QWindowsMouseHandler() : - m_windowUnderMouse(0) + m_windowUnderMouse(0), + m_touchDevice(0) { } @@ -277,10 +278,17 @@ bool QWindowsMouseHandler::translateTouchEvent(QWindow *window, HWND, if ((allStates & Qt::TouchPointStateMask) == Qt::TouchPointReleased) m_touchInputIDToTouchPointID.clear(); + if (!m_touchDevice) { + m_touchDevice = new QTouchDevice; + m_touchDevice->setType(QTouchDevice::TouchScreen); + m_touchDevice->setCapabilities(QTouchDevice::Position | QTouchDevice::Area | QTouchDevice::NormalizedPosition); + QWindowSystemInterface::registerTouchDevice(m_touchDevice); + } + // TODO: Device used to be hardcoded to screen in previous code. // What is the correct event type? Which parts of translateRawTouchEvent() are required? QWindowSystemInterface::handleTouchEvent(window, QEvent::TouchBegin, - QTouchEvent::TouchScreen, + m_touchDevice, touchPoints); return true; } diff --git a/src/plugins/platforms/windows/qwindowsmousehandler.h b/src/plugins/platforms/windows/qwindowsmousehandler.h index 8d62becb74..178936e2ec 100644 --- a/src/plugins/platforms/windows/qwindowsmousehandler.h +++ b/src/plugins/platforms/windows/qwindowsmousehandler.h @@ -51,6 +51,7 @@ QT_BEGIN_NAMESPACE class QWindow; +class QTouchDevice; class QWindowsMouseHandler { @@ -76,6 +77,7 @@ private: QPointer m_windowUnderMouse; QHash m_touchInputIDToTouchPointID; + QTouchDevice *m_touchDevice; }; Qt::MouseButtons QWindowsMouseHandler::keyStateToMouseButtons(int wParam) diff --git a/src/plugins/platforms/xcb/qxcbconnection_maemo.cpp b/src/plugins/platforms/xcb/qxcbconnection_maemo.cpp index 327f7c54f6..719fc85ae2 100644 --- a/src/plugins/platforms/xcb/qxcbconnection_maemo.cpp +++ b/src/plugins/platforms/xcb/qxcbconnection_maemo.cpp @@ -62,6 +62,7 @@ struct XInput2Data { , xideviceinfo(0) , xibuttonclassinfo(0) , xiMaxContacts(0) + , qtTouchDevice(0) { } // true if Qt is compiled w/ XInput2 or Tablet support and we have a tablet. @@ -74,6 +75,7 @@ struct XInput2Data { XIButtonClassInfo *xibuttonclassinfo; int xiMaxContacts; QList allTouchPoints; + QTouchDevice *qtTouchDevice; }; bool QXcbConnection::isUsingXInput2() @@ -277,8 +279,17 @@ void QXcbConnection::handleGenericEvent(xcb_ge_event_t *event) if (!(active & (1 << i)) && touchPoints.at(i).state != Qt::TouchPointReleased) touchPoints[i].state = Qt::TouchPointReleased; - if (QXcbWindow *platformWindow = platformWindowFromId(xideviceevent->event)) - QWindowSystemInterface::handleTouchEvent(platformWindow->window(), xideviceevent->time, (QEvent::Type)0 /*None*/, QTouchEvent::TouchScreen, touchPoints); + if (QXcbWindow *platformWindow = platformWindowFromId(xideviceevent->event)) { + QTouchDevice *dev = m_xinputData->qtTouchDevice; + if (!dev) { + dev = new QTouchDevice; + dev->setType(QTouchDevice::TouchScreen); + dev->setCapabilities(QTouchDevice::Position | QTouchDevice::Area | QTouchDevice::Pressure | QTouchDevice::NormalizedPosition); + QWindowSystemInterface::registerTouchDevice(dev); + m_xinputData->qtTouchDevice = dev; + } + QWindowSystemInterface::handleTouchEvent(platformWindow->window(), xideviceevent->time, (QEvent::Type)0 /*None*/, dev, touchPoints); + } if (xideviceevent->evtype == XI_ButtonRelease) { // final event, forget touch state -- cgit v1.2.3