2020-06-12 13:32:49 +00:00
|
|
|
/****************************************************************************
|
|
|
|
**
|
|
|
|
** Copyright (C) 2020 The Qt Company Ltd.
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
|
|
|
**
|
|
|
|
** This file is part of the test suite of the Qt Toolkit.
|
|
|
|
**
|
|
|
|
** $QT_BEGIN_LICENSE:GPL-EXCEPT$
|
|
|
|
** Commercial License Usage
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
|
|
|
**
|
|
|
|
** GNU General Public License Usage
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
|
|
|
**
|
|
|
|
** $QT_END_LICENSE$
|
|
|
|
**
|
|
|
|
****************************************************************************/
|
|
|
|
|
2020-11-26 16:31:50 +00:00
|
|
|
#include <QTest>
|
2020-06-12 13:32:49 +00:00
|
|
|
#include <qpa/qwindowsysteminterface.h>
|
|
|
|
#include <QtGui/qinputdevice.h>
|
|
|
|
#include <QtGui/qpointingdevice.h>
|
|
|
|
#include <QtGui/private/qinputdevice_p.h>
|
|
|
|
|
|
|
|
class tst_QInputDevice : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
tst_QInputDevice() {}
|
|
|
|
virtual ~tst_QInputDevice() {}
|
|
|
|
private slots:
|
|
|
|
void initTestCase();
|
|
|
|
void multiSeatDevices();
|
|
|
|
|
|
|
|
private:
|
|
|
|
};
|
|
|
|
|
|
|
|
void tst_QInputDevice::initTestCase()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void tst_QInputDevice::multiSeatDevices()
|
|
|
|
{
|
|
|
|
QWindowSystemInterface::registerInputDevice(new QInputDevice("seat 1 kbd", 1000, QInputDevice::DeviceType::Keyboard, "seat 1", this));
|
|
|
|
QWindowSystemInterface::registerInputDevice(new QPointingDevice("seat 1 mouse", 1010, QInputDevice::DeviceType::Mouse, QPointingDevice::PointerType::Generic,
|
|
|
|
QInputDevice::Capability::Position | QInputDevice::Capability::Hover | QInputDevice::Capability::Scroll,
|
|
|
|
1, 5, "seat 1", QPointingDeviceUniqueId(), this));
|
|
|
|
QWindowSystemInterface::registerInputDevice(new QInputDevice("seat 2 kbd", 2000, QInputDevice::DeviceType::Keyboard, "seat 2", this));
|
|
|
|
QWindowSystemInterface::registerInputDevice(new QPointingDevice("seat 2 mouse", 2010, QInputDevice::DeviceType::Mouse, QPointingDevice::PointerType::Generic,
|
|
|
|
QInputDevice::Capability::Position | QInputDevice::Capability::Hover,
|
|
|
|
1, 2, "seat 2", QPointingDeviceUniqueId(), this));
|
|
|
|
QVERIFY(QInputDevice::devices().count() >= 4);
|
|
|
|
QVERIFY(QInputDevicePrivate::fromId(1010));
|
|
|
|
QVERIFY(QInputDevicePrivate::fromId(1010)->hasCapability(QInputDevice::Capability::Scroll));
|
|
|
|
QVERIFY(QInputDevicePrivate::fromId(2010));
|
|
|
|
QVERIFY(!QInputDevicePrivate::fromId(2010)->hasCapability(QInputDevice::Capability::Scroll));
|
|
|
|
QVERIFY(QInputDevice::primaryKeyboard());
|
Separate QPD::tabletDevice into priv tabletDevice and queryTabletDevice
There doesn't seem to be any reason users will need to query tablet
devices by their IDs, because every event comes with a complete
instance already, and we have QInputDevice::devices() to list them all.
QPointingDevicePrivate::tabletDevice() can create a new instance if a
matching one is not found (and complains about that); it's intended
for use in QtGui, as a way to find the device if it was not part of the
QWSI event. Now it sets the parent of those auto-created instances
to QCoreApplication to avoid a memory leak.
On the other hand, queryTabletDevice() is intended for use in platform plugins
that need to check whether an instance exists; but they will take care
of creating new instances themselves, and thus have more control over the
parent and the details being stored. Now that the systemId can also be given,
the search is more likely to have a unique result, on window systems
that provide device IDs.
Rename id() to systemId() to clarify that it's a system-specific unique
device ID of some sort, not the same as the uniqueId that a stylus has.
However it seems that in practice, this will often be 0; so clarify that
if it's not unique, QInputDevicePrivate::fromId() and queryTabletDevice()
may not always find the right instance.
Clarify the function usage via comments.
Change-Id: I82bb8d1c26eeaf06f07c290828aa17ec4a31646b
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
2020-06-30 09:08:49 +00:00
|
|
|
QCOMPARE(QInputDevice::primaryKeyboard()->systemId(), qint64(1) << 33);
|
2020-06-12 13:32:49 +00:00
|
|
|
QVERIFY(QPointingDevice::primaryPointingDevice());
|
Separate QPD::tabletDevice into priv tabletDevice and queryTabletDevice
There doesn't seem to be any reason users will need to query tablet
devices by their IDs, because every event comes with a complete
instance already, and we have QInputDevice::devices() to list them all.
QPointingDevicePrivate::tabletDevice() can create a new instance if a
matching one is not found (and complains about that); it's intended
for use in QtGui, as a way to find the device if it was not part of the
QWSI event. Now it sets the parent of those auto-created instances
to QCoreApplication to avoid a memory leak.
On the other hand, queryTabletDevice() is intended for use in platform plugins
that need to check whether an instance exists; but they will take care
of creating new instances themselves, and thus have more control over the
parent and the details being stored. Now that the systemId can also be given,
the search is more likely to have a unique result, on window systems
that provide device IDs.
Rename id() to systemId() to clarify that it's a system-specific unique
device ID of some sort, not the same as the uniqueId that a stylus has.
However it seems that in practice, this will often be 0; so clarify that
if it's not unique, QInputDevicePrivate::fromId() and queryTabletDevice()
may not always find the right instance.
Clarify the function usage via comments.
Change-Id: I82bb8d1c26eeaf06f07c290828aa17ec4a31646b
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
2020-06-30 09:08:49 +00:00
|
|
|
QCOMPARE(QPointingDevice::primaryPointingDevice()->systemId(), 1);
|
2020-06-12 13:32:49 +00:00
|
|
|
QVERIFY(QInputDevice::primaryKeyboard("seat 1"));
|
Separate QPD::tabletDevice into priv tabletDevice and queryTabletDevice
There doesn't seem to be any reason users will need to query tablet
devices by their IDs, because every event comes with a complete
instance already, and we have QInputDevice::devices() to list them all.
QPointingDevicePrivate::tabletDevice() can create a new instance if a
matching one is not found (and complains about that); it's intended
for use in QtGui, as a way to find the device if it was not part of the
QWSI event. Now it sets the parent of those auto-created instances
to QCoreApplication to avoid a memory leak.
On the other hand, queryTabletDevice() is intended for use in platform plugins
that need to check whether an instance exists; but they will take care
of creating new instances themselves, and thus have more control over the
parent and the details being stored. Now that the systemId can also be given,
the search is more likely to have a unique result, on window systems
that provide device IDs.
Rename id() to systemId() to clarify that it's a system-specific unique
device ID of some sort, not the same as the uniqueId that a stylus has.
However it seems that in practice, this will often be 0; so clarify that
if it's not unique, QInputDevicePrivate::fromId() and queryTabletDevice()
may not always find the right instance.
Clarify the function usage via comments.
Change-Id: I82bb8d1c26eeaf06f07c290828aa17ec4a31646b
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
2020-06-30 09:08:49 +00:00
|
|
|
QCOMPARE(QInputDevice::primaryKeyboard("seat 1")->systemId(), 1000);
|
2020-06-12 13:32:49 +00:00
|
|
|
QVERIFY(QPointingDevice::primaryPointingDevice("seat 1"));
|
Separate QPD::tabletDevice into priv tabletDevice and queryTabletDevice
There doesn't seem to be any reason users will need to query tablet
devices by their IDs, because every event comes with a complete
instance already, and we have QInputDevice::devices() to list them all.
QPointingDevicePrivate::tabletDevice() can create a new instance if a
matching one is not found (and complains about that); it's intended
for use in QtGui, as a way to find the device if it was not part of the
QWSI event. Now it sets the parent of those auto-created instances
to QCoreApplication to avoid a memory leak.
On the other hand, queryTabletDevice() is intended for use in platform plugins
that need to check whether an instance exists; but they will take care
of creating new instances themselves, and thus have more control over the
parent and the details being stored. Now that the systemId can also be given,
the search is more likely to have a unique result, on window systems
that provide device IDs.
Rename id() to systemId() to clarify that it's a system-specific unique
device ID of some sort, not the same as the uniqueId that a stylus has.
However it seems that in practice, this will often be 0; so clarify that
if it's not unique, QInputDevicePrivate::fromId() and queryTabletDevice()
may not always find the right instance.
Clarify the function usage via comments.
Change-Id: I82bb8d1c26eeaf06f07c290828aa17ec4a31646b
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
2020-06-30 09:08:49 +00:00
|
|
|
QCOMPARE(QPointingDevice::primaryPointingDevice("seat 1")->systemId(), 1010);
|
2020-06-12 13:32:49 +00:00
|
|
|
QVERIFY(QInputDevice::primaryKeyboard("seat 2"));
|
Separate QPD::tabletDevice into priv tabletDevice and queryTabletDevice
There doesn't seem to be any reason users will need to query tablet
devices by their IDs, because every event comes with a complete
instance already, and we have QInputDevice::devices() to list them all.
QPointingDevicePrivate::tabletDevice() can create a new instance if a
matching one is not found (and complains about that); it's intended
for use in QtGui, as a way to find the device if it was not part of the
QWSI event. Now it sets the parent of those auto-created instances
to QCoreApplication to avoid a memory leak.
On the other hand, queryTabletDevice() is intended for use in platform plugins
that need to check whether an instance exists; but they will take care
of creating new instances themselves, and thus have more control over the
parent and the details being stored. Now that the systemId can also be given,
the search is more likely to have a unique result, on window systems
that provide device IDs.
Rename id() to systemId() to clarify that it's a system-specific unique
device ID of some sort, not the same as the uniqueId that a stylus has.
However it seems that in practice, this will often be 0; so clarify that
if it's not unique, QInputDevicePrivate::fromId() and queryTabletDevice()
may not always find the right instance.
Clarify the function usage via comments.
Change-Id: I82bb8d1c26eeaf06f07c290828aa17ec4a31646b
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
2020-06-30 09:08:49 +00:00
|
|
|
QCOMPARE(QInputDevice::primaryKeyboard("seat 2")->systemId(), 2000);
|
2020-06-12 13:32:49 +00:00
|
|
|
QVERIFY(QPointingDevice::primaryPointingDevice("seat 2"));
|
Separate QPD::tabletDevice into priv tabletDevice and queryTabletDevice
There doesn't seem to be any reason users will need to query tablet
devices by their IDs, because every event comes with a complete
instance already, and we have QInputDevice::devices() to list them all.
QPointingDevicePrivate::tabletDevice() can create a new instance if a
matching one is not found (and complains about that); it's intended
for use in QtGui, as a way to find the device if it was not part of the
QWSI event. Now it sets the parent of those auto-created instances
to QCoreApplication to avoid a memory leak.
On the other hand, queryTabletDevice() is intended for use in platform plugins
that need to check whether an instance exists; but they will take care
of creating new instances themselves, and thus have more control over the
parent and the details being stored. Now that the systemId can also be given,
the search is more likely to have a unique result, on window systems
that provide device IDs.
Rename id() to systemId() to clarify that it's a system-specific unique
device ID of some sort, not the same as the uniqueId that a stylus has.
However it seems that in practice, this will often be 0; so clarify that
if it's not unique, QInputDevicePrivate::fromId() and queryTabletDevice()
may not always find the right instance.
Clarify the function usage via comments.
Change-Id: I82bb8d1c26eeaf06f07c290828aa17ec4a31646b
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
2020-06-30 09:08:49 +00:00
|
|
|
QCOMPARE(QPointingDevice::primaryPointingDevice("seat 2")->systemId(), 2010);
|
2020-06-12 13:32:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QTEST_MAIN(tst_QInputDevice)
|
|
|
|
#include "tst_qinputdevice.moc"
|