diff options
-rw-r--r-- | src/gui/kernel/qinputdevice.cpp | 8 | ||||
-rw-r--r-- | src/gui/kernel/qpointingdevice.cpp | 2 | ||||
-rw-r--r-- | tests/auto/gui/kernel/qinputdevice/tst_qinputdevice.cpp | 51 |
3 files changed, 51 insertions, 10 deletions
diff --git a/src/gui/kernel/qinputdevice.cpp b/src/gui/kernel/qinputdevice.cpp index 13bd672f3d..8aea2f6e2e 100644 --- a/src/gui/kernel/qinputdevice.cpp +++ b/src/gui/kernel/qinputdevice.cpp @@ -305,11 +305,13 @@ QStringList QInputDevice::seatNames() const QInputDevice *QInputDevice::primaryKeyboard(const QString& seatName) { QMutexLocker locker(&devicesMutex); - InputDevicesList v = *deviceList(); + const InputDevicesList devices = *deviceList(); locker.unlock(); const QInputDevice *ret = nullptr; - for (const QInputDevice *d : v) { - if (d->type() == DeviceType::Keyboard && d->seatName() == seatName) { + for (const QInputDevice *d : devices) { + if (d->type() != 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; diff --git a/src/gui/kernel/qpointingdevice.cpp b/src/gui/kernel/qpointingdevice.cpp index e2f17f821c..750be2b728 100644 --- a/src/gui/kernel/qpointingdevice.cpp +++ b/src/gui/kernel/qpointingdevice.cpp @@ -286,7 +286,7 @@ const QPointingDevice *QPointingDevice::primaryPointingDevice(const QString& sea const QPointingDevice *mouse = nullptr; const QPointingDevice *touchpad = nullptr; for (const QInputDevice *dev : v) { - if (dev->seatName() != seatName) + if (!seatName.isNull() && dev->seatName() != seatName) continue; if (dev->type() == QInputDevice::DeviceType::Mouse) { if (!mouse) 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")); |