summaryrefslogtreecommitdiffstats
path: root/tests/auto/gui
diff options
context:
space:
mode:
authorLiang Qi <liang.qi@qt.io>2021-10-25 17:07:32 +0200
committerLiang Qi <liang.qi@qt.io>2022-03-13 22:08:16 +0100
commit9c6b986d967b42bea5faca0d9fa1000c7edb023e (patch)
tree8e80fb4ceba370410780e087c78b21a1a4521a10 /tests/auto/gui
parent7382e5735ea734fe5e5777518394963593603c32 (diff)
gui: return first default device when seatName isNull
for QInputDevice::primaryKeyboard() and QPointingDevice::primaryPointingDevice(). This also reverts ae9fefe3c89fd5720ccaad0687f125e32f7c3fe6. Fixes: QTBUG-100790 Pick-to: 6.3 Change-Id: Id02f277db25f823eb29e939e25801325df8e4076 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
Diffstat (limited to 'tests/auto/gui')
-rw-r--r--tests/auto/gui/kernel/qinputdevice/tst_qinputdevice.cpp51
1 files changed, 45 insertions, 6 deletions
diff --git a/tests/auto/gui/kernel/qinputdevice/tst_qinputdevice.cpp b/tests/auto/gui/kernel/qinputdevice/tst_qinputdevice.cpp
index 06887420cf..2722583a83 100644
--- a/tests/auto/gui/kernel/qinputdevice/tst_qinputdevice.cpp
+++ b/tests/auto/gui/kernel/qinputdevice/tst_qinputdevice.cpp
@@ -43,15 +43,54 @@ private slots:
void multiSeatDevices();
private:
+ const QInputDevice *getPrimaryKeyboard(const QString& seatName = QString());
+ const QPointingDevice *getPrimaryPointingDevice(const QString& seatName = QString());
};
void tst_QInputDevice::initTestCase()
{
}
-static bool isPlatformWayland()
+const QInputDevice *tst_QInputDevice::getPrimaryKeyboard(const QString& seatName)
{
- return !QGuiApplication::platformName().compare(QLatin1String("wayland"), Qt::CaseInsensitive);
+ QList<const QInputDevice *> devices = QInputDevice::devices();
+ const QInputDevice *ret = nullptr;
+ for (const QInputDevice *d : devices) {
+ if (d->type() != QInputDevice::DeviceType::Keyboard)
+ continue;
+ if (seatName.isNull() || d->seatName() == seatName) {
+ // the master keyboard's parent is not another input device
+ if (!d->parent() || !qobject_cast<const QInputDevice *>(d->parent()))
+ return d;
+ if (!ret)
+ ret = d;
+ }
+ }
+ return ret;
+}
+
+const QPointingDevice *tst_QInputDevice::getPrimaryPointingDevice(const QString& seatName)
+{
+ QList<const QInputDevice *> devices = QInputDevice::devices();
+ const QPointingDevice *mouse = nullptr;
+ const QPointingDevice *touchpad = nullptr;
+ for (const QInputDevice *dev : devices) {
+ if (!seatName.isNull() && dev->seatName() != seatName)
+ continue;
+ if (dev->type() == QInputDevice::DeviceType::Mouse) {
+ if (!mouse)
+ mouse = static_cast<const QPointingDevice *>(dev);
+ // the core pointer is likely a mouse, and its parent is not another input device
+ if (!mouse->parent() || !qobject_cast<const QInputDevice *>(mouse->parent()))
+ return mouse;
+ } else if (dev->type() == QInputDevice::DeviceType::TouchPad) {
+ if (!touchpad || !dev->parent() || dev->parent()->metaObject() != dev->metaObject())
+ touchpad = static_cast<const QPointingDevice *>(dev);
+ }
+ }
+ if (mouse)
+ return mouse;
+ return touchpad;
}
void tst_QInputDevice::multiSeatDevices()
@@ -70,11 +109,11 @@ void tst_QInputDevice::multiSeatDevices()
QVERIFY(QInputDevicePrivate::fromId(2010));
QVERIFY(!QInputDevicePrivate::fromId(2010)->hasCapability(QInputDevice::Capability::Scroll));
QVERIFY(QInputDevice::primaryKeyboard());
- if (isPlatformWayland())
- QEXPECT_FAIL("", "This fails on Wayland, see QTBUG-100790.", Abort);
- QCOMPARE(QInputDevice::primaryKeyboard()->systemId(), qint64(1) << 33);
+ if (!getPrimaryKeyboard())
+ QCOMPARE(QInputDevice::primaryKeyboard()->systemId(), qint64(1) << 33);
QVERIFY(QPointingDevice::primaryPointingDevice());
- QCOMPARE(QPointingDevice::primaryPointingDevice()->systemId(), 1);
+ if (!getPrimaryPointingDevice())
+ QCOMPARE(QPointingDevice::primaryPointingDevice()->systemId(), 1);
QVERIFY(QInputDevice::primaryKeyboard("seat 1"));
QCOMPARE(QInputDevice::primaryKeyboard("seat 1")->systemId(), 1000);
QVERIFY(QPointingDevice::primaryPointingDevice("seat 1"));