From f25bd998a7250bdd6c0cb1ee542757f20092f0a7 Mon Sep 17 00:00:00 2001 From: Shawn Rutledge Date: Thu, 18 Jun 2020 09:52:19 +0200 Subject: [PATCH] Don't return a touchscreen from QPointingDevice::primaryPointingDevice() This was causing some bogus failures in Qt Quick autotests. Existing APIs like QQuickWindow::mouseGrabberItem() are not really compatible with the idea of a mouse-less system; but perhaps we can revisit this later. Task-number: QTBUG-85114 Change-Id: Id1c2e5894e5cf13a79998aaea28d5f42fad920cf Reviewed-by: Shawn Rutledge --- src/gui/kernel/qpointingdevice.cpp | 24 ++++++++----------- .../kernel/qinputdevice/tst_qinputdevice.cpp | 2 +- 2 files changed, 11 insertions(+), 15 deletions(-) diff --git a/src/gui/kernel/qpointingdevice.cpp b/src/gui/kernel/qpointingdevice.cpp index e1a66d522b..5f4b6e0fd8 100644 --- a/src/gui/kernel/qpointingdevice.cpp +++ b/src/gui/kernel/qpointingdevice.cpp @@ -301,17 +301,18 @@ QPointingDeviceUniqueId QPointingDevice::uniqueId() const Returns the primary pointing device (the core pointer, traditionally assumed to be a mouse) on the given seat \a seatName. - If multiple pointing devices are registered, this function prefers a - mouse, touchpad, or touchscreen (in that order) that matches the given - \a seatName and that does not have another device as its parent. - Usually only one master or core device does not have a parent device. + If multiple pointing devices are registered, this function prefers a mouse + or touchpad that matches the given \a seatName and that does not have + another device as its parent. Usually only one master or core device does + not have a parent device. But if such a device is not found, this function + creates a new virtual "core pointer" mouse. Thus Qt continues to work on + platforms that are not yet doing input device discovery and registration. */ const QPointingDevice *QPointingDevice::primaryPointingDevice(const QString& seatName) { const auto v = devices(); const QPointingDevice *mouse = nullptr; const QPointingDevice *touchpad = nullptr; - const QPointingDevice *touchscreen = nullptr; for (const QInputDevice *dev : v) { if (dev->seatName() != seatName) continue; @@ -324,13 +325,10 @@ const QPointingDevice *QPointingDevice::primaryPointingDevice(const QString& sea } else if (dev->type() == QInputDevice::DeviceType::TouchPad) { if (!touchpad || !dev->parent() || dev->parent()->metaObject() != dev->metaObject()) touchpad = static_cast(dev); - } else if (dev->type() == QInputDevice::DeviceType::TouchScreen) { - if (!touchscreen || !dev->parent() || dev->parent()->metaObject() != dev->metaObject()) - touchscreen = static_cast(dev); } } - if (!mouse && !touchpad && !touchscreen) { - qWarning() << "no pointing devices registered for seat" << seatName + if (!mouse && !touchpad) { + qWarning() << "no mouse-like devices registered for seat" << seatName << "The platform plugin should have provided one via " "QWindowSystemInterface::registerInputDevice(). Creating a default mouse for now."; mouse = new QPointingDevice(QLatin1String("core pointer"), 1, DeviceType::Mouse, @@ -339,12 +337,10 @@ const QPointingDevice *QPointingDevice::primaryPointingDevice(const QString& sea return mouse; } if (v.length() > 1) - qCWarning(lcQpaInputDevices) << "core pointer ambiguous for seat" << seatName; + qCDebug(lcQpaInputDevices) << "core pointer ambiguous for seat" << seatName; if (mouse) return mouse; - if (touchpad) - return touchpad; - return touchscreen; + return touchpad; } /*! diff --git a/tests/auto/gui/kernel/qinputdevice/tst_qinputdevice.cpp b/tests/auto/gui/kernel/qinputdevice/tst_qinputdevice.cpp index e34961aef7..a46a72532a 100644 --- a/tests/auto/gui/kernel/qinputdevice/tst_qinputdevice.cpp +++ b/tests/auto/gui/kernel/qinputdevice/tst_qinputdevice.cpp @@ -66,7 +66,7 @@ void tst_QInputDevice::multiSeatDevices() QVERIFY(!QInputDevicePrivate::fromId(2010)->hasCapability(QInputDevice::Capability::Scroll)); QTest::ignoreMessage(QtWarningMsg, "no keyboards registered for seat \"\" The platform plugin should have provided one via " "QWindowSystemInterface::registerInputDevice(). Creating a default one for now."); - QTest::ignoreMessage(QtWarningMsg, "no pointing devices registered for seat \"\" The platform plugin should have provided one via " + QTest::ignoreMessage(QtWarningMsg, "no mouse-like devices registered for seat \"\" The platform plugin should have provided one via " "QWindowSystemInterface::registerInputDevice(). Creating a default mouse for now."); QVERIFY(QInputDevice::primaryKeyboard()); QCOMPARE(QInputDevice::primaryKeyboard()->id(), 0);