diff options
Diffstat (limited to 'src/gui/kernel/qinputdevice.cpp')
-rw-r--r-- | src/gui/kernel/qinputdevice.cpp | 108 |
1 files changed, 56 insertions, 52 deletions
diff --git a/src/gui/kernel/qinputdevice.cpp b/src/gui/kernel/qinputdevice.cpp index 4505a6b568..f7b216dcf0 100644 --- a/src/gui/kernel/qinputdevice.cpp +++ b/src/gui/kernel/qinputdevice.cpp @@ -1,41 +1,5 @@ -/**************************************************************************** -** -** 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" @@ -48,6 +12,8 @@ QT_BEGIN_NAMESPACE +using namespace Qt::StringLiterals; + /*! \class QInputDevice \brief The QInputDevice class describes a device from which a QInputEvent originates. @@ -101,7 +67,7 @@ QT_BEGIN_NAMESPACE \value Scroll Indicates that the device has a scroll capability. - \value PixelScroll \since 6.2 + \value [since 6.2] PixelScroll Indicates that the device (usually a \l {QInputDevice::DeviceType::TouchPad}{touchpad}) scrolls with \l {QWheelEvent::pixelDelta()}{pixel precision}. @@ -264,11 +230,18 @@ 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 QWindowSystemInterface::registerInputDevice() @@ -281,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; @@ -302,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, QCoreApplication::instance()); + ret = new QInputDevice("core keyboard"_L1, 0, DeviceType::Keyboard, seatName, QCoreApplication::instance()); QInputDevicePrivate::registerDevice(ret); return ret; } @@ -310,6 +304,9 @@ const QInputDevice *QInputDevice::primaryKeyboard(const QString& seatName) return ret; } +QInputDevicePrivate::~QInputDevicePrivate() + = default; + /*! \internal Checks whether a matching device is already registered @@ -370,22 +367,29 @@ bool QInputDevice::operator==(const QInputDevice &other) const #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->systemId() << ", 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" |