Mouse->touch synthesis: send touch event with mouse device
In 4e400369c08db251cd489fec1229398c224d02b4 we began to send synth-mouse events from the touch device, but in the opposite direction it was not consistent. Add autotests to prove that it's consistent both ways now. Change-Id: I7df2328fef224dc1529ca5d27411cd8a5a9c8df9 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
This commit is contained in:
parent
1fdbbb49d9
commit
a54988c822
@ -189,7 +189,6 @@ static Qt::LayoutDirection layout_direction = Qt::LayoutDirectionAuto;
|
|||||||
static bool force_reverse = false;
|
static bool force_reverse = false;
|
||||||
|
|
||||||
QGuiApplicationPrivate *QGuiApplicationPrivate::self = nullptr;
|
QGuiApplicationPrivate *QGuiApplicationPrivate::self = nullptr;
|
||||||
QPointingDevice *QGuiApplicationPrivate::m_fakeTouchDevice = nullptr;
|
|
||||||
int QGuiApplicationPrivate::m_fakeMouseSourcePointId = 0;
|
int QGuiApplicationPrivate::m_fakeMouseSourcePointId = 0;
|
||||||
|
|
||||||
#ifndef QT_NO_CLIPBOARD
|
#ifndef QT_NO_CLIPBOARD
|
||||||
@ -2282,10 +2281,6 @@ void QGuiApplicationPrivate::processMouseEvent(QWindowSystemInterfacePrivate::Mo
|
|||||||
if (!e->synthetic() && !ev.isAccepted()
|
if (!e->synthetic() && !ev.isAccepted()
|
||||||
&& !e->nonClientArea
|
&& !e->nonClientArea
|
||||||
&& qApp->testAttribute(Qt::AA_SynthesizeTouchForUnhandledMouseEvents)) {
|
&& qApp->testAttribute(Qt::AA_SynthesizeTouchForUnhandledMouseEvents)) {
|
||||||
if (!m_fakeTouchDevice) {
|
|
||||||
m_fakeTouchDevice = new QPointingDevice;
|
|
||||||
QWindowSystemInterface::registerInputDevice(m_fakeTouchDevice);
|
|
||||||
}
|
|
||||||
QList<QWindowSystemInterface::TouchPoint> points;
|
QList<QWindowSystemInterface::TouchPoint> points;
|
||||||
QWindowSystemInterface::TouchPoint point;
|
QWindowSystemInterface::TouchPoint point;
|
||||||
point.id = 1;
|
point.id = 1;
|
||||||
@ -2310,7 +2305,7 @@ void QGuiApplicationPrivate::processMouseEvent(QWindowSystemInterfacePrivate::Mo
|
|||||||
const QList<QEventPoint> &touchPoints =
|
const QList<QEventPoint> &touchPoints =
|
||||||
QWindowSystemInterfacePrivate::fromNativeTouchPoints(points, window, &type);
|
QWindowSystemInterfacePrivate::fromNativeTouchPoints(points, window, &type);
|
||||||
|
|
||||||
QWindowSystemInterfacePrivate::TouchEvent fake(window, e->timestamp, type, m_fakeTouchDevice, touchPoints, e->modifiers);
|
QWindowSystemInterfacePrivate::TouchEvent fake(window, e->timestamp, type, device, touchPoints, e->modifiers);
|
||||||
fake.flags |= QWindowSystemInterfacePrivate::WindowSystemEvent::Synthetic;
|
fake.flags |= QWindowSystemInterfacePrivate::WindowSystemEvent::Synthetic;
|
||||||
processTouchEvent(&fake);
|
processTouchEvent(&fake);
|
||||||
}
|
}
|
||||||
|
@ -45,6 +45,8 @@
|
|||||||
# include <QtCore/qt_windows.h>
|
# include <QtCore/qt_windows.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
Q_LOGGING_CATEGORY(lcTests, "qt.gui.tests")
|
||||||
|
|
||||||
class tst_QWindow: public QObject
|
class tst_QWindow: public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
@ -957,6 +959,8 @@ public:
|
|||||||
}
|
}
|
||||||
void mousePressEvent(QMouseEvent *event) override
|
void mousePressEvent(QMouseEvent *event) override
|
||||||
{
|
{
|
||||||
|
qCDebug(lcTests) << event;
|
||||||
|
mouseDevice = event->pointingDevice();
|
||||||
if (ignoreMouse) {
|
if (ignoreMouse) {
|
||||||
event->ignore();
|
event->ignore();
|
||||||
} else {
|
} else {
|
||||||
@ -971,6 +975,7 @@ public:
|
|||||||
}
|
}
|
||||||
void mouseReleaseEvent(QMouseEvent *event) override
|
void mouseReleaseEvent(QMouseEvent *event) override
|
||||||
{
|
{
|
||||||
|
qCDebug(lcTests) << event;
|
||||||
if (ignoreMouse) {
|
if (ignoreMouse) {
|
||||||
event->ignore();
|
event->ignore();
|
||||||
} else {
|
} else {
|
||||||
@ -981,6 +986,7 @@ public:
|
|||||||
}
|
}
|
||||||
void mouseMoveEvent(QMouseEvent *event) override
|
void mouseMoveEvent(QMouseEvent *event) override
|
||||||
{
|
{
|
||||||
|
qCDebug(lcTests) << event;
|
||||||
buttonStateInGeneratedMove = event->buttons();
|
buttonStateInGeneratedMove = event->buttons();
|
||||||
if (ignoreMouse) {
|
if (ignoreMouse) {
|
||||||
event->ignore();
|
event->ignore();
|
||||||
@ -992,6 +998,7 @@ public:
|
|||||||
}
|
}
|
||||||
void mouseDoubleClickEvent(QMouseEvent *event) override
|
void mouseDoubleClickEvent(QMouseEvent *event) override
|
||||||
{
|
{
|
||||||
|
qCDebug(lcTests) << event;
|
||||||
if (ignoreMouse) {
|
if (ignoreMouse) {
|
||||||
event->ignore();
|
event->ignore();
|
||||||
} else {
|
} else {
|
||||||
@ -1001,12 +1008,14 @@ public:
|
|||||||
}
|
}
|
||||||
void touchEvent(QTouchEvent *event) override
|
void touchEvent(QTouchEvent *event) override
|
||||||
{
|
{
|
||||||
|
qCDebug(lcTests) << event;
|
||||||
|
touchDevice = event->pointingDevice();
|
||||||
if (ignoreTouch) {
|
if (ignoreTouch) {
|
||||||
event->ignore();
|
event->ignore();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
touchEventType = event->type();
|
touchEventType = event->type();
|
||||||
QList<QTouchEvent::TouchPoint> points = event->touchPoints();
|
QList<QTouchEvent::TouchPoint> points = event->points();
|
||||||
for (int i = 0; i < points.count(); ++i) {
|
for (int i = 0; i < points.count(); ++i) {
|
||||||
switch (points.at(i).state()) {
|
switch (points.at(i).state()) {
|
||||||
case QEventPoint::State::Pressed:
|
case QEventPoint::State::Pressed:
|
||||||
@ -1029,9 +1038,11 @@ public:
|
|||||||
{
|
{
|
||||||
switch (e->type()) {
|
switch (e->type()) {
|
||||||
case QEvent::Enter:
|
case QEvent::Enter:
|
||||||
|
qCDebug(lcTests) << e;
|
||||||
++enterEventCount;
|
++enterEventCount;
|
||||||
break;
|
break;
|
||||||
case QEvent::Leave:
|
case QEvent::Leave:
|
||||||
|
qCDebug(lcTests) << e;
|
||||||
++leaveEventCount;
|
++leaveEventCount;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@ -1063,6 +1074,9 @@ public:
|
|||||||
|
|
||||||
bool spinLoopWhenPressed = false;
|
bool spinLoopWhenPressed = false;
|
||||||
Qt::MouseButtons buttonStateInGeneratedMove;
|
Qt::MouseButtons buttonStateInGeneratedMove;
|
||||||
|
|
||||||
|
const QPointingDevice *mouseDevice = nullptr;
|
||||||
|
const QPointingDevice *touchDevice = nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
static void simulateMouseClick(QWindow *target, const QPointF &local, const QPointF &global)
|
static void simulateMouseClick(QWindow *target, const QPointF &local, const QPointF &global)
|
||||||
@ -1176,6 +1190,8 @@ void tst_QWindow::touchToMouseTranslation()
|
|||||||
QTRY_COMPARE(window.mouseReleaseButton, int(Qt::LeftButton));
|
QTRY_COMPARE(window.mouseReleaseButton, int(Qt::LeftButton));
|
||||||
QTRY_COMPARE(window.mousePressScreenPos, pressArea.center());
|
QTRY_COMPARE(window.mousePressScreenPos, pressArea.center());
|
||||||
QTRY_COMPARE(window.mouseMoveScreenPos, moveArea.center());
|
QTRY_COMPARE(window.mouseMoveScreenPos, moveArea.center());
|
||||||
|
QCOMPARE(window.mouseDevice, window.touchDevice);
|
||||||
|
QCOMPARE(window.mouseDevice->type(), QInputDevice::DeviceType::TouchScreen);
|
||||||
|
|
||||||
window.mousePressButton = 0;
|
window.mousePressButton = 0;
|
||||||
window.mouseReleaseButton = 0;
|
window.mouseReleaseButton = 0;
|
||||||
@ -1258,6 +1274,8 @@ void tst_QWindow::mouseToTouchTranslation()
|
|||||||
|
|
||||||
QTRY_COMPARE(window.touchPressedCount, 1);
|
QTRY_COMPARE(window.touchPressedCount, 1);
|
||||||
QTRY_COMPARE(window.touchReleasedCount, 1);
|
QTRY_COMPARE(window.touchReleasedCount, 1);
|
||||||
|
QCOMPARE(window.mouseDevice, window.touchDevice);
|
||||||
|
QCOMPARE(window.touchDevice->type(), QInputDevice::DeviceType::Mouse);
|
||||||
|
|
||||||
QCoreApplication::setAttribute(Qt::AA_SynthesizeTouchForUnhandledMouseEvents, true);
|
QCoreApplication::setAttribute(Qt::AA_SynthesizeTouchForUnhandledMouseEvents, true);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user