Adapt to new QPointingDevice API

QTouchDevice has been replaced with a more general QPointingDevice.

All input devices need detailed information and need to be registered
via QWindowSystemInterface::registerInputDevice().  This patch is not
doing that yet; it's just enough to get qtwayland to compile again.

Done-With: Liang Qi <liang.qi@qt.io>
Change-Id: Id3a2e475ed07294a1977004fc72b11e466acc216
Reviewed-by: Liang Qi <liang.qi@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
This commit is contained in:
Shawn Rutledge 2020-06-25 15:04:20 +02:00 committed by Liang Qi
parent 01c959c74e
commit f4807a0e1d
9 changed files with 64 additions and 61 deletions

View File

@ -73,7 +73,7 @@
#endif
#include <QtGui/QGuiApplication>
#include <QtGui/QTouchDevice>
#include <QtGui/QPointingDevice>
QT_BEGIN_NAMESPACE
@ -456,10 +456,11 @@ void QWaylandInputDevice::seat_capabilities(uint32_t caps)
mTouch->init(get_touch());
if (!mTouchDevice) {
mTouchDevice = new QTouchDevice;
mTouchDevice->setType(QTouchDevice::TouchScreen);
mTouchDevice->setCapabilities(QTouchDevice::Position);
QWindowSystemInterface::registerTouchDevice(mTouchDevice);
// TODO number of touchpoints, actual name and ID
mTouchDevice = new QPointingDevice(QLatin1String("some touchscreen"), 0,
QInputDevice::DeviceType::TouchScreen, QPointingDevice::PointerType::Finger,
QInputDevice::Capability::Position, 10, 0);
QWindowSystemInterface::registerInputDevice(mTouchDevice);
}
} else if (!(caps & WL_SEAT_CAPABILITY_TOUCH) && mTouch) {
delete mTouch;

View File

@ -195,7 +195,7 @@ private:
void seat_capabilities(uint32_t caps) override;
void handleTouchPoint(int id, Qt::TouchPointState state, const QPointF &surfacePosition = QPoint());
QTouchDevice *mTouchDevice = nullptr;
QPointingDevice *mTouchDevice = nullptr;
friend class QWaylandTouchExtension;
friend class QWaylandQtKeyExtension;

View File

@ -137,35 +137,35 @@ void QWaylandTabletToolV2::zwp_tablet_tool_v2_done()
case type::type_brush:
case type::type_pencil:
case type::type_pen:
m_pointerType = QTabletEvent::PointerType::Pen;
m_pointerType = QPointingDevice::PointerType::Pen;
break;
case type::type_eraser:
m_pointerType = QTabletEvent::PointerType::Eraser;
m_pointerType = QPointingDevice::PointerType::Eraser;
break;
case type::type_mouse:
case type::type_lens:
m_pointerType = QTabletEvent::PointerType::Cursor;
m_pointerType = QPointingDevice::PointerType::Cursor;
break;
case type::type_finger:
m_pointerType = QTabletEvent::PointerType::UnknownPointer;
m_pointerType = QPointingDevice::PointerType::Unknown;
break;
}
switch (m_toolType) {
case type::type_airbrush:
m_tabletDevice = QTabletEvent::TabletDevice::Airbrush;
m_tabletDevice = QInputDevice::DeviceType::Airbrush;
break;
case type::type_brush:
case type::type_pencil:
case type::type_pen:
case type::type_eraser:
m_tabletDevice = m_hasRotation ? QTabletEvent::TabletDevice::RotationStylus : QTabletEvent::TabletDevice::Stylus;
m_tabletDevice = QInputDevice::DeviceType::Stylus;
break;
case type::type_lens:
m_tabletDevice = QTabletEvent::TabletDevice::Puck;
m_tabletDevice = QInputDevice::DeviceType::Puck;
break;
case type::type_mouse:
case type::type_finger:
m_tabletDevice = QTabletEvent::TabletDevice::NoDevice;
m_tabletDevice = QInputDevice::DeviceType::Unknown;
break;
}
}
@ -261,7 +261,7 @@ void QWaylandTabletToolV2::zwp_tablet_tool_v2_button(uint32_t serial, uint32_t b
void QWaylandTabletToolV2::zwp_tablet_tool_v2_frame(uint32_t time)
{
if (m_pending.proximitySurface && !m_applied.proximitySurface) {
QWindowSystemInterface::handleTabletEnterProximityEvent(m_tabletDevice, m_pointerType, m_uid);
QWindowSystemInterface::handleTabletEnterProximityEvent(int(m_tabletDevice), int(m_pointerType), m_uid);
m_applied.proximitySurface = m_pending.proximitySurface;
}
@ -288,12 +288,12 @@ void QWaylandTabletToolV2::zwp_tablet_tool_v2_frame(uint32_t time)
qreal rotation = m_pending.rotation;
int z = int(m_pending.distance);
QWindowSystemInterface::handleTabletEvent(window, timestamp, localPosition, globalPosition,
m_tabletDevice, m_pointerType, buttons, pressure,
int(m_tabletDevice), int(m_pointerType), buttons, pressure,
xTilt, yTilt, tangentialPressure, rotation, z, m_uid);
}
if (!m_pending.proximitySurface && m_applied.enteredSurface) {
QWindowSystemInterface::handleTabletLeaveProximityEvent(m_tabletDevice, m_pointerType, m_uid);
QWindowSystemInterface::handleTabletLeaveProximityEvent(int(m_tabletDevice), int(m_pointerType), m_uid);
m_pending = State(); // Don't leave pressure etc. lying around when we enter the next surface
}

View File

@ -58,7 +58,8 @@
#include <QtCore/QObject>
#include <QtCore/QPointer>
#include <QtCore/QPointF>
#include <QtGui/QTabletEvent>
#include <QtGui/QPointingDevice>
#include <QtGui/QInputDevice>
QT_BEGIN_NAMESPACE
@ -142,8 +143,8 @@ protected:
private:
// Static state (sent before done event)
QTabletEvent::PointerType m_pointerType = QTabletEvent::PointerType::UnknownPointer;
QTabletEvent::TabletDevice m_tabletDevice = QTabletEvent::TabletDevice::NoDevice;
QPointingDevice::PointerType m_pointerType = QPointingDevice::PointerType::Unknown;
QInputDevice::DeviceType m_tabletDevice = QInputDevice::DeviceType::Unknown;
type m_toolType = type_pen;
bool m_hasRotation = false;
quint64 m_uid = 0;

View File

@ -42,7 +42,7 @@
#include "qwaylanddisplay_p.h"
#include "qwaylandsurface_p.h"
#include <QtGui/QTouchDevice>
#include <QtGui/QPointingDevice>
QT_BEGIN_NAMESPACE
@ -61,10 +61,11 @@ QWaylandTouchExtension::QWaylandTouchExtension(QWaylandDisplay *display, uint32_
void QWaylandTouchExtension::registerDevice(int caps)
{
mTouchDevice = new QTouchDevice;
mTouchDevice->setType(QTouchDevice::TouchScreen);
mTouchDevice->setCapabilities(QTouchDevice::Capabilities(caps));
QWindowSystemInterface::registerTouchDevice(mTouchDevice);
// TODO number of touchpoints, actual name and ID
mTouchDevice = new QPointingDevice(QLatin1String("some touchscreen"), 0,
QInputDevice::DeviceType::TouchScreen, QPointingDevice::PointerType::Finger,
QInputDevice::Capabilities(caps), 10, 0);
QWindowSystemInterface::registerInputDevice(mTouchDevice);
}
static inline qreal fromFixed(int f)

View File

@ -95,7 +95,7 @@ private:
QList<QWindowSystemInterface::TouchPoint> mTouchPoints;
QList<QWindowSystemInterface::TouchPoint> mPrevTouchPoints;
QTouchDevice *mTouchDevice = nullptr;
QPointingDevice *mTouchDevice = nullptr;
uint32_t mTimestamp;
int mPointsLeft;
uint32_t mFlags;

View File

@ -213,7 +213,7 @@ void tst_seatv4::mousePressFloat()
{
class Window : public QRasterWindow {
public:
void mousePressEvent(QMouseEvent *e) override { m_position = e->localPos(); }
void mousePressEvent(QMouseEvent *e) override { m_position = e->position(); }
QPointF m_position;
};

View File

@ -424,14 +424,14 @@ void tst_seatv5::singleTap()
QCOMPARE(e.type, QEvent::TouchBegin);
QCOMPARE(e.touchPointStates, Qt::TouchPointState::TouchPointPressed);
QCOMPARE(e.touchPoints.length(), 1);
QCOMPARE(e.touchPoints.first().pos(), QPointF(32-window.frameMargins().left(), 32-window.frameMargins().top()));
QCOMPARE(e.touchPoints.first().position(), QPointF(32-window.frameMargins().left(), 32-window.frameMargins().top()));
}
{
auto e = window.m_events.takeFirst();
QCOMPARE(e.type, QEvent::TouchEnd);
QCOMPARE(e.touchPointStates, Qt::TouchPointState::TouchPointReleased);
QCOMPARE(e.touchPoints.length(), 1);
QCOMPARE(e.touchPoints.first().pos(), QPointF(32-window.frameMargins().left(), 32-window.frameMargins().top()));
QCOMPARE(e.touchPoints.first().position(), QPointF(32-window.frameMargins().left(), 32-window.frameMargins().top()));
}
}
@ -455,14 +455,14 @@ void tst_seatv5::singleTapFloat()
QCOMPARE(e.type, QEvent::TouchBegin);
QCOMPARE(e.touchPointStates, Qt::TouchPointState::TouchPointPressed);
QCOMPARE(e.touchPoints.length(), 1);
QCOMPARE(e.touchPoints.first().pos(), QPointF(32.75-window.frameMargins().left(), 32.25-window.frameMargins().top()));
QCOMPARE(e.touchPoints.first().position(), QPointF(32.75-window.frameMargins().left(), 32.25-window.frameMargins().top()));
}
{
auto e = window.m_events.takeFirst();
QCOMPARE(e.type, QEvent::TouchEnd);
QCOMPARE(e.touchPointStates, Qt::TouchPointState::TouchPointReleased);
QCOMPARE(e.touchPoints.length(), 1);
QCOMPARE(e.touchPoints.first().pos(), QPointF(32.75-window.frameMargins().left(), 32.25-window.frameMargins().top()));
QCOMPARE(e.touchPoints.first().position(), QPointF(32.75-window.frameMargins().left(), 32.25-window.frameMargins().top()));
}
}
@ -500,10 +500,10 @@ void tst_seatv5::multiTouch()
QCOMPARE(e.touchPoints.length(), 2);
QCOMPARE(e.touchPoints[0].state(), Qt::TouchPointState::TouchPointPressed);
QCOMPARE(e.touchPoints[0].pos(), QPointF(32-window.frameMargins().left(), 32-window.frameMargins().top()));
QCOMPARE(e.touchPoints[0].position(), QPointF(32-window.frameMargins().left(), 32-window.frameMargins().top()));
QCOMPARE(e.touchPoints[1].state(), Qt::TouchPointState::TouchPointPressed);
QCOMPARE(e.touchPoints[1].pos(), QPointF(48-window.frameMargins().left(), 48-window.frameMargins().top()));
QCOMPARE(e.touchPoints[1].position(), QPointF(48-window.frameMargins().left(), 48-window.frameMargins().top()));
}
{
auto e = window.m_events.takeFirst();
@ -511,10 +511,10 @@ void tst_seatv5::multiTouch()
QCOMPARE(e.touchPoints.length(), 2);
QCOMPARE(e.touchPoints[0].state(), Qt::TouchPointState::TouchPointMoved);
QCOMPARE(e.touchPoints[0].pos(), QPointF(33-window.frameMargins().left(), 32-window.frameMargins().top()));
QCOMPARE(e.touchPoints[0].position(), QPointF(33-window.frameMargins().left(), 32-window.frameMargins().top()));
QCOMPARE(e.touchPoints[1].state(), Qt::TouchPointState::TouchPointMoved);
QCOMPARE(e.touchPoints[1].pos(), QPointF(49-window.frameMargins().left(), 48-window.frameMargins().top()));
QCOMPARE(e.touchPoints[1].position(), QPointF(49-window.frameMargins().left(), 48-window.frameMargins().top()));
}
{
auto e = window.m_events.takeFirst();
@ -523,10 +523,10 @@ void tst_seatv5::multiTouch()
QCOMPARE(e.touchPoints.length(), 2);
QCOMPARE(e.touchPoints[0].state(), Qt::TouchPointState::TouchPointReleased);
QCOMPARE(e.touchPoints[0].pos(), QPointF(33-window.frameMargins().left(), 32-window.frameMargins().top()));
QCOMPARE(e.touchPoints[0].position(), QPointF(33-window.frameMargins().left(), 32-window.frameMargins().top()));
QCOMPARE(e.touchPoints[1].state(), Qt::TouchPointState::TouchPointStationary);
QCOMPARE(e.touchPoints[1].pos(), QPointF(49-window.frameMargins().left(), 48-window.frameMargins().top()));
QCOMPARE(e.touchPoints[1].position(), QPointF(49-window.frameMargins().left(), 48-window.frameMargins().top()));
}
{
auto e = window.m_events.takeFirst();
@ -534,7 +534,7 @@ void tst_seatv5::multiTouch()
QCOMPARE(e.touchPointStates, Qt::TouchPointState::TouchPointReleased);
QCOMPARE(e.touchPoints.length(), 1);
QCOMPARE(e.touchPoints[0].state(), Qt::TouchPointState::TouchPointReleased);
QCOMPARE(e.touchPoints[0].pos(), QPointF(49-window.frameMargins().left(), 48-window.frameMargins().top()));
QCOMPARE(e.touchPoints[0].position(), QPointF(49-window.frameMargins().left(), 48-window.frameMargins().top()));
}
}

View File

@ -416,7 +416,7 @@ public:
};
Q_DECLARE_METATYPE(QtWaylandServer::zwp_tablet_tool_v2::type);
Q_DECLARE_METATYPE(QTabletEvent::PointerType);
Q_DECLARE_METATYPE(QPointingDevice::PointerType);
Q_DECLARE_METATYPE(Qt::MouseButton);
class tst_tabletv2 : public QObject, private TabletCompositor
@ -465,8 +465,8 @@ protected:
case QEvent::TabletEnterProximity:
case QEvent::TabletLeaveProximity: {
auto *e = static_cast<QTabletEvent *>(event);
auto *ev = new QTabletEvent(e->type(), e->posF(), e->globalPosF(), e->deviceType(),
e->pointerType(), e->pressure(), e->xTilt(), e->yTilt(),
auto *ev = new QTabletEvent(e->type(), e->position(), e->globalPosition(), int(e->deviceType()),
int(e->pointerType()), e->pressure(), e->xTilt(), e->yTilt(),
e->tangentialPressure(), e->rotation(), e->z(),
Qt::KeyboardModifier::NoModifier, e->uniqueId(),
e->button(), e->buttons());
@ -600,8 +600,8 @@ public:
void tabletEvent(QTabletEvent *e) override
{
m_events << new QTabletEvent(e->type(), e->posF(), e->globalPosF(), e->deviceType(),
e->pointerType(), e->pressure(), e->xTilt(), e->yTilt(),
m_events << new QTabletEvent(e->type(), e->position(), e->globalPosition(), int(e->deviceType()),
int(e->pointerType()), e->pressure(), e->xTilt(), e->yTilt(),
e->tangentialPressure(), e->rotation(), e->z(),
Qt::KeyboardModifier::NoModifier, e->uniqueId(), e->button(),
e->buttons());
@ -650,34 +650,34 @@ void tst_tabletv2::moveEvent()
QTabletEvent *event = window.popEvent();
QCOMPARE(event->type(), QEvent::TabletMove);
QCOMPARE(event->pressure(), 0);
QCOMPARE(event->posF(), QPointF(12, 34));
QCOMPARE(event->position(), QPointF(12, 34));
}
void tst_tabletv2::pointerType_data()
{
QTest::addColumn<ToolType>("toolType");
QTest::addColumn<QTabletEvent::PointerType>("pointerType");
QTest::addColumn<QTabletEvent::TabletDevice>("tabletDevice");
QTest::addColumn<QPointingDevice::PointerType>("pointerType");
QTest::addColumn<QInputDevice::DeviceType>("tabletDevice");
QTest::newRow("pen") << ToolType::type_pen << QTabletEvent::PointerType::Pen << QTabletEvent::TabletDevice::Stylus;
QTest::newRow("eraser") << ToolType::type_eraser << QTabletEvent::PointerType::Eraser << QTabletEvent::TabletDevice::Stylus;
QTest::newRow("pencil") << ToolType::type_pencil << QTabletEvent::PointerType::Pen << QTabletEvent::TabletDevice::Stylus;
QTest::newRow("airbrush") << ToolType::type_airbrush << QTabletEvent::PointerType::Pen << QTabletEvent::TabletDevice::Airbrush;
QTest::newRow("brush") << ToolType::type_brush << QTabletEvent::PointerType::Pen << QTabletEvent::TabletDevice::Stylus; // TODO: is TabletDevice::Stylus the right thing?
QTest::newRow("lens") << ToolType::type_lens << QTabletEvent::PointerType::Cursor << QTabletEvent::TabletDevice::Puck;
QTest::newRow("pen") << ToolType::type_pen << QPointingDevice::PointerType::Pen << QInputDevice::DeviceType::Stylus;
QTest::newRow("eraser") << ToolType::type_eraser << QPointingDevice::PointerType::Eraser << QInputDevice::DeviceType::Stylus;
QTest::newRow("pencil") << ToolType::type_pencil << QPointingDevice::PointerType::Pen << QInputDevice::DeviceType::Stylus;
QTest::newRow("airbrush") << ToolType::type_airbrush << QPointingDevice::PointerType::Pen << QInputDevice::DeviceType::Airbrush;
QTest::newRow("brush") << ToolType::type_brush << QPointingDevice::PointerType::Pen << QInputDevice::DeviceType::Stylus; // TODO: is TabletDevice::Stylus the right thing?
QTest::newRow("lens") << ToolType::type_lens << QPointingDevice::PointerType::Cursor << QInputDevice::DeviceType::Puck;
// TODO: also add tests for FourDMouse and RotationStylus (also need to send capabilities)
// TODO: should these rather be mapped to touch/mouse events?
QTest::newRow("finger") << ToolType::type_finger << QTabletEvent::PointerType::UnknownPointer << QTabletEvent::TabletDevice::NoDevice;
QTest::newRow("mouse") << ToolType::type_mouse << QTabletEvent::PointerType::Cursor << QTabletEvent::TabletDevice::NoDevice;
QTest::newRow("finger") << ToolType::type_finger << QPointingDevice::PointerType::Unknown << QInputDevice::DeviceType::Unknown;
QTest::newRow("mouse") << ToolType::type_mouse << QPointingDevice::PointerType::Cursor << QInputDevice::DeviceType::Unknown;
}
void tst_tabletv2::pointerType()
{
using ToolType = QtWaylandServer::zwp_tablet_tool_v2::type;
QFETCH(ToolType, toolType);
QFETCH(QTabletEvent::PointerType, pointerType);
QFETCH(QTabletEvent::TabletDevice, tabletDevice);
QFETCH(QPointingDevice::PointerType, pointerType);
QFETCH(QInputDevice::DeviceType, tabletDevice);
ProximityFilter filter;
@ -726,7 +726,7 @@ void tst_tabletv2::pointerType()
void tst_tabletv2::hardwareSerial()
{
ProximityFilter filter;
const quint64 uid = 0xbaba15dead15f00d;
const qint64 uid = 0xbaba15dead15f00d;
QCOMPOSITOR_TRY_VERIFY(tabletSeat());
exec([&] {
@ -860,7 +860,7 @@ void tst_tabletv2::tabletEvents()
QTabletEvent *event = window.popEvent();
QCOMPARE(event->type(), QEvent::TabletPress);
QCOMPARE(event->pressure(), 1.0);
QCOMPARE(event->posF(), QPointF(12, 34));
QCOMPARE(event->position(), QPointF(12, 34));
// Values we didn't send should be 0
QCOMPARE(event->rotation(), 0);
@ -882,7 +882,7 @@ void tst_tabletv2::tabletEvents()
QVERIFY(qAbs(event->rotation() - 90) < 0.01);
QVERIFY(qAbs(event->xTilt() - 13) < 0.01);
QVERIFY(qAbs(event->yTilt() - 37) < 0.01);
QCOMPARE(event->posF(), QPointF(45, 56));
QCOMPARE(event->position(), QPointF(45, 56));
// Verify that the values stay the same if we don't update them
exec([&] {
@ -896,7 +896,7 @@ void tst_tabletv2::tabletEvents()
QVERIFY(qAbs(event->rotation() - 90) < 0.01);
QVERIFY(qAbs(event->xTilt() - 13) < 0.01);
QVERIFY(qAbs(event->yTilt() - 37) < 0.01);
QCOMPARE(event->posF(), QPointF(10, 11));
QCOMPARE(event->position(), QPointF(10, 11));
exec([&] {
tabletTool()->sendPressure(0);
@ -911,7 +911,7 @@ void tst_tabletv2::tabletEvents()
event = window.popEvent();
QCOMPARE(event->type(), QEvent::TabletRelease);
QCOMPARE(event->pressure(), 0);
QCOMPARE(event->posF(), QPointF(10, 11));
QCOMPARE(event->position(), QPointF(10, 11));
}
QCOMPOSITOR_TEST_MAIN(tst_tabletv2)