Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qinputdevice.cpp
Go to the documentation of this file.
1// Copyright (C) 2020 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#include "qinputdevice.h"
5#include "qinputdevice_p.h"
6#include "qpointingdevice.h"
8#include <QCoreApplication>
9#include <QDebug>
10#include <QMutex>
11#include <QScreen>
12
14
15using namespace Qt::StringLiterals;
16
107
112
132 const QString &seatName, QObject *parent)
133 : QObject(*new QInputDevicePrivate(name, id, type, QInputDevice::Capability::None, seatName), parent)
134{
135}
136
144
163{
164 Q_D(const QInputDevice);
165 return d->availableVirtualGeometry;
166}
167
176{
177 Q_D(const QInputDevice);
178 return d->name;
179}
180
185{
186 Q_D(const QInputDevice);
187 return d->deviceType;
188}
189
193QInputDevice::Capabilities QInputDevice::capabilities() const
194{
195 Q_D(const QInputDevice);
196 return QInputDevice::Capabilities(d->capabilities);
197}
198
203{
204 return capabilities().testFlag(capability);
205}
206
213{
214 Q_D(const QInputDevice);
215 return d->systemId;
216}
217
226{
227 Q_D(const QInputDevice);
228 return d->seatName;
229}
230
231using InputDevicesList = QList<const QInputDevice *>;
233Q_CONSTINIT static QBasicMutex devicesMutex;
234
251{
253 return *deviceList();
254}
255
262{
263 QMutexLocker locker(&devicesMutex);
264 const InputDevicesList devices = *deviceList();
265 locker.unlock();
267 for (const QInputDevice *d : devices) {
268 if (!result.contains(d->seatName()))
269 result.append(d->seatName());
270 }
271
272 return result;
273}
274
279{
280 QMutexLocker locker(&devicesMutex);
281 const InputDevicesList devices = *deviceList();
282 locker.unlock();
283 const QInputDevice *ret = nullptr;
284 for (const QInputDevice *d : devices) {
285 if (d->type() != DeviceType::Keyboard)
286 continue;
287 if (seatName.isNull() || d->seatName() == seatName) {
288 // the master keyboard's parent is not another input device
289 if (!d->parent() || !qobject_cast<const QInputDevice *>(d->parent()))
290 return d;
291 if (!ret)
292 ret = d;
293 }
294 }
295 if (!ret) {
296 qCDebug(lcQpaInputDevices) << "no keyboards registered for seat" << seatName
297 << "The platform plugin should have provided one via "
298 "QWindowSystemInterface::registerInputDevice(). Creating a default one for now.";
301 return ret;
302 }
303 qWarning() << "core keyboard ambiguous for seat" << seatName;
304 return ret;
305}
306
308 = default;
309
316{
317 if (!dev)
318 return false;
319 QMutexLocker locker(&devicesMutex);
320 InputDevicesList v = *deviceList();
321 for (const QInputDevice *d : v)
322 if (d && *d == *dev)
323 return true;
324 return false;
325}
326
338{
339 QMutexLocker locker(&devicesMutex);
340 for (const QInputDevice *dev : *deviceList()) {
341 if (dev->systemId() == systemId)
342 return dev;
343 }
344 return nullptr;
345}
346
348{
350 deviceList()->append(dev);
351}
352
357{
359 deviceList()->removeOne(dev);
360}
361
363{
364 return systemId() == other.systemId();
365}
366
367#ifndef QT_NO_DEBUG_STREAM
369{
370 QDebugStateSaver saver(debug);
371 debug.nospace();
372 debug.noquote();
373
374 debug << "QInputDevice(";
375 if (!device) {
376 debug << "0)";
377 return debug;
378 }
379
381
382 if (d->pointingDeviceType)
383 return operator<<(debug, static_cast<const QPointingDevice *>(device));
384
385 debug << "QInputDevice(";
386 debug << '"' << device->name() << "\", type=" << device->type()
387 << ", ID=" << device->systemId() << ", seat='" << device->seatName() << "'";
388 debug << ')';
389 return debug;
390}
391#endif // !QT_NO_DEBUG_STREAM
392
394
395#include "moc_qinputdevice.cpp"
IOBluetoothDevice * device
static QCoreApplication * instance() noexcept
Returns a pointer to the application's QCoreApplication (or QGuiApplication/QApplication) instance.
\inmodule QtCore
\inmodule QtCore
~QInputDevicePrivate() override
static QInputDevicePrivate * get(QInputDevice *q)
static void registerDevice(const QInputDevice *dev)
static void unregisterDevice(const QInputDevice *dev)
static const QInputDevice * fromId(qint64 systemId)
static bool isRegistered(const QInputDevice *dev)
The QInputDevice class describes a device from which a QInputEvent originates.
Capabilities capabilities
DeviceType
This enum represents the type of device that generated a QPointerEvent.
QRect availableVirtualGeometry
bool hasCapability(Capability cap) const
Returns whether the device capabilities include the given capability.
QInputDevice(QObject *parent=nullptr)
Creates a new invalid input device instance as a child of parent.
Capability
Indicates what kind of information the input device or its driver can provide.
bool operator==(const QInputDevice &other) const
QString seatName
DeviceType type
qint64 systemId
static const QInputDevice * primaryKeyboard(const QString &seatName=QString())
Returns the core or master keyboard on the given seat seatName.
static QList< const QInputDevice * > devices()
Returns a list of all registered input devices (keyboards and pointing devices).
static QStringList seatNames()
Definition qlist.h:75
\inmodule QtCore
Definition qmutex.h:313
void unlock() noexcept
Unlocks this mutex locker.
Definition qmutex.h:319
\inmodule QtCore
Definition qmutex.h:281
\inmodule QtCore
Definition qobject.h:103
\inmodule QtCore\reentrant
Definition qrect.h:30
\inmodule QtCore
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
bool isNull() const
Returns true if this string is null; otherwise returns false.
Definition qstring.h:994
Combined button and popup list for selecting options.
EGLDeviceEXT * devices
#define Q_GLOBAL_STATIC(TYPE, NAME,...)
@ None
Definition qhash.cpp:531
QList< const QInputDevice * > InputDevicesList
static Q_CONSTINIT QBasicMutex devicesMutex
QDebug operator<<(QDebug debug, const QInputDevice *device)
#define qWarning
Definition qlogging.h:166
#define qCDebug(category,...)
return ret
GLsizei const GLfloat * v
[13]
GLenum GLuint id
[7]
GLenum type
GLuint name
GLuint64EXT * result
[6]
long long qint64
Definition qtypes.h:60
QReadWriteLock lock
[0]
QSharedPointer< T > other(t)
[5]