Add a function to the compositor api to send full touch events
authorLaszlo Agocs <laszlo.p.agocs@nokia.com>
Tue, 10 Jan 2012 08:33:55 +0000 (10:33 +0200)
committerJørgen Lind <jorgen.lind@nokia.com>
Tue, 10 Jan 2012 11:36:44 +0000 (12:36 +0100)
A simple sendTouchPointEvent(id, x, y, ...) type of function will not
be sufficient in the future due to the amount of data in a touch
event; therefore an additional sendFullTouchEvent is introduced. This
function takes a QTouchEvent and posts a series of down, motion, up,
frame events as needed. In the future it may be changed so that it
maps to a protocol extension instead of the standard events.

As an example qwindow-compositor is updated to use this new function.

Change-Id: I39d3df1c6d4868364440f59789d01fc5b7b80dac
Sanity-Review: Qt Sanity Bot <qt_sanity_bot@ovi.com>
Reviewed-by: Jørgen Lind <jorgen.lind@nokia.com>
examples/qwindow-compositor/qwindowcompositor.cpp
src/compositor/compositor_api/waylandsurface.cpp
src/compositor/compositor_api/waylandsurface.h
src/compositor/wayland_wrapper/wlsurface.cpp
src/compositor/wayland_wrapper/wlsurface.h

index fd5b24a..14d43c4 100644 (file)
@@ -258,15 +258,12 @@ bool QWindowCompositor::eventFilter(QObject *obj, QEvent *event)
         QList<QTouchEvent::TouchPoint> points = te->touchPoints();
         for (int i = 0; i < points.count(); ++i) {
             const QTouchEvent::TouchPoint &tp(points.at(i));
-            QPoint local;
-            WaylandSurface *targetSurface = surfaceAt(tp.pos().toPoint(), &local);
-            if (targetSurface) {
-                targetSurface->sendTouchPointEvent(tp.id(), local.x(), local.y(), tp.state());
+            WaylandSurface *targetSurface = surfaceAt(tp.pos().toPoint());
+            if (targetSurface)
                 targets.insert(targetSurface);
-            }
         }
         foreach (WaylandSurface *surface, targets)
-            surface->sendTouchFrameEvent();
+            surface->sendFullTouchEvent(te);
         break;
     }
     default:
index 061c1aa..b0b53a7 100644 (file)
@@ -232,6 +232,12 @@ void WaylandSurface::sendTouchCancelEvent()
     d->surface->sendTouchCancelEvent();
 }
 
+void WaylandSurface::sendFullTouchEvent(QTouchEvent *event)
+{
+    Q_D(WaylandSurface);
+    d->surface->sendFullTouchEvent(event);
+}
+
 void WaylandSurface::frameFinished()
 {
     Q_D(WaylandSurface);
index a902c82..091e1b0 100644 (file)
@@ -52,6 +52,7 @@
 #include <QtGui/qopengl.h>
 #endif
 
+class QTouchEvent;
 class WaylandSurfacePrivate;
 
 #ifdef QT_COMPOSITOR_QUICK
@@ -110,6 +111,8 @@ public:
     void sendTouchFrameEvent();
     void sendTouchCancelEvent();
 
+    void sendFullTouchEvent(QTouchEvent *event);
+
     void sendOnScreenVisibilityChange(bool visible);
 
     void frameFinished();
index 86ae1e9..c638868 100644 (file)
@@ -49,6 +49,7 @@
 #include "wlsubsurface.h"
 
 #include <QtCore/QDebug>
+#include <QTouchEvent>
 
 #include <wayland-server.h>
 
@@ -750,6 +751,21 @@ void Surface::sendTouchCancelEvent()
                          WL_INPUT_DEVICE_TOUCH_CANCEL);
 }
 
+void Surface::sendFullTouchEvent(QTouchEvent *event)
+{
+    const QList<QTouchEvent::TouchPoint> points = event->touchPoints();
+    if (points.isEmpty())
+        return;
+    const int pointCount = points.count();
+    for (int i = 0; i < pointCount; ++i) {
+        const QTouchEvent::TouchPoint &tp(points.at(i));
+        // Convert the local pos in the compositor window to surface-relative.
+        QPoint p = (tp.pos() - pos()).toPoint();
+        sendTouchPointEvent(tp.id(), p.x(), p.y(), tp.state());
+    }
+    sendTouchFrameEvent();
+}
+
 void Surface::sendFrameCallback()
 {
     Q_D(Surface);
index 88bd15c..e784c6c 100644 (file)
@@ -59,6 +59,8 @@
 #include <QtGui/qopengl.h>
 #endif
 
+class QTouchEvent;
+
 namespace Wayland {
 
 class Compositor;
@@ -105,6 +107,8 @@ public:
     void sendTouchFrameEvent();
     void sendTouchCancelEvent();
 
+    void sendFullTouchEvent(QTouchEvent *event);
+
     void sendFrameCallback();
 
     void frameFinished();