diff options
Diffstat (limited to 'src/gui/kernel/qinputdevice.cpp')
-rw-r--r-- | src/gui/kernel/qinputdevice.cpp | 231 |
1 files changed, 163 insertions, 68 deletions
diff --git a/src/gui/kernel/qinputdevice.cpp b/src/gui/kernel/qinputdevice.cpp index d64f2c4ddc..f7b216dcf0 100644 --- a/src/gui/kernel/qinputdevice.cpp +++ b/src/gui/kernel/qinputdevice.cpp @@ -1,54 +1,18 @@ -/**************************************************************************** -** -** Copyright (C) 2020 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtGui module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** 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 Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** 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-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2020 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only #include "qinputdevice.h" #include "qinputdevice_p.h" #include "qpointingdevice.h" +#include "qwindowsysteminterface_p.h" #include <QCoreApplication> #include <QDebug> -#include <QLoggingCategory> #include <QMutex> #include <QScreen> QT_BEGIN_NAMESPACE -Q_DECLARE_LOGGING_CATEGORY(lcQpaInputDevices) +using namespace Qt::StringLiterals; /*! \class QInputDevice @@ -68,10 +32,76 @@ Q_DECLARE_LOGGING_CATEGORY(lcQpaInputDevices) */ /*! - Creates a new invalid input device instance. + \enum QInputDevice::Capability + + Indicates what kind of information the input device or its driver can + provide. + + \value None + No information about input device capabilities available. + + \value Position + Indicates that position information is available, meaning that the + position() family of functions in the touch points return valid points. + + \value Area + Indicates that touch area information is available, meaning that + QEventPoint::ellipseDiameters() in the touch points return valid + values. + + \value Pressure + Indicates that pressure information is available, meaning that + QEventPoint::pressure() returns a valid value. + + \value Velocity + Indicates that velocity information is available, meaning that + QEventPoint::velocity() returns a valid vector. + + \value NormalizedPosition + Indicates that the normalized position is available, meaning that + QEventPoint::globalPosition() returns a valid value. + + \value MouseEmulation + Indicates that the device synthesizes mouse events. + + \value Scroll + Indicates that the device has a scroll capability. + + \value [since 6.2] PixelScroll + Indicates that the device (usually a + \l {QInputDevice::DeviceType::TouchPad}{touchpad}) + scrolls with \l {QWheelEvent::pixelDelta()}{pixel precision}. + + \value Hover + Indicates that the device has a hover capability. + + \value Rotation + Indicates that \l {QEventPoint::}{rotation} information is available. + + \value XTilt + Indicates that \l {QTabletEvent::xTilt()}{tilt} information is + available for the X-axis. + + \value YTilt + Indicates that \l {QTabletEvent::yTilt()}{tilt} information is + available for the Y-axis. + + \value TangentialPressure + Indicates that \l {QTabletEvent::tangentialPressure()} + {tangential pressure} information is available. + + \value ZPosition + Indicates that position information for the \l {QTabletEvent::z()} + {Z-axis} is available. + + \value All */ -QInputDevice::QInputDevice() - : QObject(*(new QInputDevicePrivate(QString(), -1, QInputDevice::DeviceType::Unknown)), nullptr) + +/*! + Creates a new invalid input device instance as a child of \a parent. +*/ +QInputDevice::QInputDevice(QObject *parent) + : QObject(*(new QInputDevicePrivate(QString(), -1, QInputDevice::DeviceType::Unknown)), parent) { } @@ -113,6 +143,29 @@ QInputDevice::QInputDevice(QInputDevicePrivate &d, QObject *parent) } /*! + Returns the region within the \l{QScreen::availableVirtualGeometry}{virtual desktop} + that this device can access. + + For example a \l {QInputDevice::DeviceType}{TouchScreen} input + device is fixed in place upon a single physical screen, and usually + calibrated so that this area is the same as QScreen::geometry(); whereas a + \l {QInputDevice::DeviceType}{Mouse} can probably access all screens + on the virtual desktop. A Wacom graphics tablet may be configured in a way + that it's mapped to all screens, or only to the screen where the user + prefers to create drawings, or to the window in which drawing occurs. + A \l {QInputDevice::DeviceType}{Stylus} device that is integrated + with a touchscreen may be physically limited to that screen. + + If the returned rectangle is \l {QRect::isNull()}{null}, it means this device + can access the entire virtual desktop. +*/ +QRect QInputDevice::availableVirtualGeometry() const +{ + Q_D(const QInputDevice); + return d->availableVirtualGeometry; +} + +/*! Returns the device name. This string may be empty. It is however useful on systems that have @@ -152,14 +205,14 @@ bool QInputDevice::hasCapability(QInputDevice::Capability capability) const } /*! - Returns the platform ID (for example xinput ID on the X11 platform). + Returns the platform specific system ID (for example xinput ID on the X11 platform). - All platforms are expected to provide a unique ID for each device. + All platforms are expected to provide a unique system ID for each device. */ -qint64 QInputDevice::id() const +qint64 QInputDevice::systemId() const { Q_D(const QInputDevice); - return d->id; + return d->systemId; } /*! @@ -177,14 +230,21 @@ QString QInputDevice::seatName() const using InputDevicesList = QList<const QInputDevice *>; Q_GLOBAL_STATIC(InputDevicesList, deviceList) -static QBasicMutex devicesMutex; +Q_CONSTINIT static QBasicMutex devicesMutex; /*! Returns a list of all registered input devices (keyboards and pointing devices). + \note The list of devices is not always complete on all platforms. So far, + the most-complete information is available on the \l {Qt for Linux/X11}{X11} + platform, at startup and in response to hot-plugging. Most other platforms + are only able to provide generic devices of various types, only after receiving + events from them; and most platforms do not tell Qt when a device is plugged in, + or when it is unplugged at runtime. + \note The returned list cannot be used to add new devices. To add a simulated touch screen for an autotest, QTest::createTouchDevice() can be used. - Platform plugins should call \l QWindowSystemInterface::registerInputDevice() + Platform plugins should call QWindowSystemInterface::registerInputDevice() to add devices as they are discovered. */ QList<const QInputDevice *> QInputDevice::devices() @@ -194,16 +254,37 @@ QList<const QInputDevice *> QInputDevice::devices() } /*! + \since 6.3 + + Returns a list of seat names for all registered input devices (keyboards and pointing devices). +*/ +QStringList QInputDevice::seatNames() +{ + QMutexLocker locker(&devicesMutex); + const InputDevicesList devices = *deviceList(); + locker.unlock(); + QStringList result; + for (const QInputDevice *d : devices) { + if (!result.contains(d->seatName())) + result.append(d->seatName()); + } + + return result; +} + +/*! Returns the core or master keyboard on the given seat \a seatName. */ 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; @@ -215,7 +296,7 @@ const QInputDevice *QInputDevice::primaryKeyboard(const QString& seatName) qCDebug(lcQpaInputDevices) << "no keyboards registered for seat" << seatName << "The platform plugin should have provided one via " "QWindowSystemInterface::registerInputDevice(). Creating a default one for now."; - ret = new QInputDevice(QLatin1String("core keyboard"), 0, DeviceType::Keyboard, seatName); + ret = new QInputDevice("core keyboard"_L1, 0, DeviceType::Keyboard, seatName, QCoreApplication::instance()); QInputDevicePrivate::registerDevice(ret); return ret; } @@ -223,6 +304,9 @@ const QInputDevice *QInputDevice::primaryKeyboard(const QString& seatName) return ret; } +QInputDevicePrivate::~QInputDevicePrivate() + = default; + /*! \internal Checks whether a matching device is already registered @@ -242,17 +326,21 @@ bool QInputDevicePrivate::isRegistered(const QInputDevice *dev) /*! \internal - Find the device with the given \a id, which must be unique. + Find the device with the given \a systemId (for example the xinput + device ID on X11), which is expected to be unique if nonzero. + + If the \a systemId is not unique, this function returns the first one found. - \note Use QPointingDevice::tabletDevice() if the device is a tablet - or a tablet stylus; in that case, \a id is not unique. + \note Use QInputDevicePrivate::queryTabletDevice() if the device is a + tablet or a tablet stylus; in that case, \a id is not unique. */ -const QInputDevice *QInputDevicePrivate::fromId(qint64 id) +const QInputDevice *QInputDevicePrivate::fromId(qint64 systemId) { QMutexLocker locker(&devicesMutex); - for (const QInputDevice *dev : *deviceList()) - if (const_cast<QInputDevicePrivate *>(QInputDevicePrivate::get(dev))->id == id) + for (const QInputDevice *dev : *deviceList()) { + if (dev->systemId() == systemId) return dev; + } return nullptr; } @@ -273,28 +361,35 @@ void QInputDevicePrivate::unregisterDevice(const QInputDevice *dev) bool QInputDevice::operator==(const QInputDevice &other) const { - return id() == other.id(); + return systemId() == other.systemId(); } #ifndef QT_NO_DEBUG_STREAM QDebug operator<<(QDebug debug, const QInputDevice *device) { - const QInputDevicePrivate *d = QInputDevicePrivate::get(device); - if (d->pointingDeviceType) - return operator<<(debug, static_cast<const QPointingDevice *>(device)); QDebugStateSaver saver(debug); debug.nospace(); debug.noquote(); + debug << "QInputDevice("; - if (device) { - debug << '"' << device->name() << "\", type=" << device->type() - << Qt::hex << ", ID=" << device->id() << ", seat='" << device->seatName() << "'"; - } else { - debug << '0'; + if (!device) { + debug << "0)"; + return debug; } + + const QInputDevicePrivate *d = QInputDevicePrivate::get(device); + + if (d->pointingDeviceType) + return operator<<(debug, static_cast<const QPointingDevice *>(device)); + + debug << "QInputDevice("; + debug << '"' << device->name() << "\", type=" << device->type() + << ", ID=" << device->systemId() << ", seat='" << device->seatName() << "'"; debug << ')'; return debug; } #endif // !QT_NO_DEBUG_STREAM QT_END_NAMESPACE + +#include "moc_qinputdevice.cpp" |