Skip to content
Snippets Groups Projects
Commit f089f453 authored by Laszlo Agocs's avatar Laszlo Agocs
Browse files

Add TouchCancel support.


It maps to the protocol's touch_cancel pretty well. :)

Change-Id: Id417aac768106c2f6618b3e7ecb51d6929977c37
Reviewed-by: default avatarSamuel Rødal <samuel.rodal@nokia.com>
parent 0a25184b
No related branches found
No related tags found
No related merge requests found
......@@ -174,6 +174,11 @@ void InputDevice::sendFullTouchEvent(QTouchEvent *event)
return;
}
if (event->type() == QEvent::TouchCancel) {
sendTouchCancelEvent();
return;
}
TouchExtensionGlobal *ext = m_compositor->touchExtension();
if (ext) {
ext->postTouchEvent(event, mouseFocus());
......
......@@ -45,6 +45,7 @@
#include "qwaylandwindow.h"
#include "qwaylandbuffer.h"
#include "qwaylanddatadevicemanager.h"
#include "qwaylandtouch.h"
#include <QtGui/private/qpixmap_raster_p.h>
#include <QtGui/QPlatformWindow>
......@@ -508,7 +509,16 @@ void QWaylandInputDevice::handleTouchFrame()
void QWaylandInputDevice::inputHandleTouchCancel(void *data, struct wl_input_device *wl_input_device)
{
Q_UNUSED(wl_input_device);
Q_UNUSED(data);
QWaylandInputDevice *self = static_cast<QWaylandInputDevice *>(data);
self->mPrevTouchPoints.clear();
self->mTouchPoints.clear();
QWaylandTouchExtension *touchExt = self->mQDisplay->touchExtension();
if (touchExt)
touchExt->touchCanceled();
QWindowSystemInterface::handleTouchCancelEvent(0, self->mTouchDevice);
}
const struct wl_input_device_listener QWaylandInputDevice::inputDeviceListener = {
......
......@@ -49,6 +49,7 @@ QWaylandTouchExtension::QWaylandTouchExtension(QWaylandDisplay *display, uint32_
mDisplay = display;
mPointsLeft = 0;
mFlags = 0;
mMouseSourceId = -1;
mTouch = static_cast<struct wl_touch_extension *>(wl_display_bind(display->wl_display(), id, &wl_touch_extension_interface));
wl_touch_extension_add_listener(mTouch, &touch_listener, this);
......@@ -173,10 +174,13 @@ void QWaylandTouchExtension::sendTouchEvent()
const QWindowSystemInterface::TouchPoint &tp(mTouchPoints.at(i));
if (tp.id == mMouseSourceId) {
Qt::MouseButtons buttons = tp.state == Qt::TouchPointReleased ? Qt::NoButton : Qt::LeftButton;
QPointF globalPos = tp.area.center();
QPointF delta = globalPos - globalPos.toPoint();
QPointF localPos = mTargetWindow->mapFromGlobal(globalPos.toPoint()) + delta;
QWindowSystemInterface::handleMouseEvent(0, mTimestamp, localPos, globalPos, buttons);
mLastMouseGlobal = tp.area.center();
QPoint globalPoint = mLastMouseGlobal.toPoint();
QPointF delta = mLastMouseGlobal - globalPoint;
mLastMouseLocal = mTargetWindow->mapFromGlobal(globalPoint) + delta;
QWindowSystemInterface::handleMouseEvent(0, mTimestamp, mLastMouseLocal, mLastMouseGlobal, buttons);
if (buttons == Qt::NoButton)
mMouseSourceId = -1;
break;
}
}
......@@ -189,6 +193,14 @@ void QWaylandTouchExtension::sendTouchEvent()
mPrevTouchPoints.clear();
}
void QWaylandTouchExtension::touchCanceled()
{
mTouchPoints.clear();
mPrevTouchPoints.clear();
if (mMouseSourceId != -1)
QWindowSystemInterface::handleMouseEvent(0, mTimestamp, mLastMouseLocal, mLastMouseGlobal, Qt::NoButton);
}
void QWaylandTouchExtension::handle_configure(void *data, wl_touch_extension *ext, uint32_t flags)
{
Q_UNUSED(ext);
......
......@@ -52,6 +52,8 @@ class QWaylandTouchExtension
public:
QWaylandTouchExtension(QWaylandDisplay *display, uint32_t id);
void touchCanceled();
private:
QWaylandDisplay *mDisplay;
wl_touch_extension *mTouch;
......@@ -86,6 +88,8 @@ private:
int mPointsLeft;
uint32_t mFlags;
int mMouseSourceId;
QPointF mLastMouseLocal;
QPointF mLastMouseGlobal;
QWindow *mTargetWindow;
};
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment