QtBase  v6.3.1
qinputdevice.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2020 The Qt Company Ltd.
4 ** Contact: https://www.qt.io/licensing/
5 **
6 ** This file is part of the QtGui module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and The Qt Company. For licensing terms
14 ** and conditions see https://www.qt.io/terms-conditions. For further
15 ** information use the contact form at https://www.qt.io/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 3 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL3 included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 3 requirements
23 ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24 **
25 ** GNU General Public License Usage
26 ** Alternatively, this file may be used under the terms of the GNU
27 ** General Public License version 2.0 or (at your option) the GNU General
28 ** Public license version 3 or any later version approved by the KDE Free
29 ** Qt Foundation. The licenses are as published by the Free Software
30 ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31 ** included in the packaging of this file. Please review the following
32 ** information to ensure the GNU General Public License requirements will
33 ** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34 ** https://www.gnu.org/licenses/gpl-3.0.html.
35 **
36 ** $QT_END_LICENSE$
37 **
38 ****************************************************************************/
39 
40 #include "qinputdevice.h"
41 #include "qinputdevice_p.h"
42 #include "qpointingdevice.h"
44 #include <QCoreApplication>
45 #include <QDebug>
46 #include <QMutex>
47 #include <QScreen>
48 
50 
138  : QObject(*(new QInputDevicePrivate(QString(), -1, QInputDevice::DeviceType::Unknown)), parent)
139 {
140 }
141 
143 {
145 }
146 
166  const QString &seatName, QObject *parent)
168 {
169 }
170 
175  : QObject(d, parent)
176 {
177 }
178 
197 {
198  Q_D(const QInputDevice);
199  return d->availableVirtualGeometry;
200 }
201 
210 {
211  Q_D(const QInputDevice);
212  return d->name;
213 }
214 
219 {
220  Q_D(const QInputDevice);
221  return d->deviceType;
222 }
223 
227 QInputDevice::Capabilities QInputDevice::capabilities() const
228 {
229  Q_D(const QInputDevice);
230  return QInputDevice::Capabilities(d->capabilities);
231 }
232 
237 {
238  return capabilities().testFlag(capability);
239 }
240 
247 {
248  Q_D(const QInputDevice);
249  return d->systemId;
250 }
251 
260 {
261  Q_D(const QInputDevice);
262  return d->seatName;
263 }
264 
267 static QBasicMutex devicesMutex;
268 
278 {
279  QMutexLocker lock(&devicesMutex);
280  return *deviceList();
281 }
282 
289 {
290  QMutexLocker locker(&devicesMutex);
291  const InputDevicesList devices = *deviceList();
292  locker.unlock();
294  for (const QInputDevice *d : devices) {
295  if (!result.contains(d->seatName()))
296  result.append(d->seatName());
297  }
298 
299  return result;
300 }
301 
306 {
307  QMutexLocker locker(&devicesMutex);
308  const InputDevicesList devices = *deviceList();
309  locker.unlock();
310  const QInputDevice *ret = nullptr;
311  for (const QInputDevice *d : devices) {
312  if (d->type() != DeviceType::Keyboard)
313  continue;
314  if (seatName.isNull() || d->seatName() == seatName) {
315  // the master keyboard's parent is not another input device
316  if (!d->parent() || !qobject_cast<const QInputDevice *>(d->parent()))
317  return d;
318  if (!ret)
319  ret = d;
320  }
321  }
322  if (!ret) {
323  qCDebug(lcQpaInputDevices) << "no keyboards registered for seat" << seatName
324  << "The platform plugin should have provided one via "
325  "QWindowSystemInterface::registerInputDevice(). Creating a default one for now.";
328  return ret;
329  }
330  qWarning() << "core keyboard ambiguous for seat" << seatName;
331  return ret;
332 }
333 
335  = default;
336 
343 {
344  if (!dev)
345  return false;
346  QMutexLocker locker(&devicesMutex);
347  InputDevicesList v = *deviceList();
348  for (const QInputDevice *d : v)
349  if (d && *d == *dev)
350  return true;
351  return false;
352 }
353 
365 {
366  QMutexLocker locker(&devicesMutex);
367  for (const QInputDevice *dev : *deviceList()) {
368  if (dev->systemId() == systemId)
369  return dev;
370  }
371  return nullptr;
372 }
373 
375 {
376  QMutexLocker lock(&devicesMutex);
377  deviceList()->append(dev);
378 }
379 
384 {
385  QMutexLocker lock(&devicesMutex);
386  deviceList()->removeOne(dev);
387 }
388 
390 {
391  return systemId() == other.systemId();
392 }
393 
394 #ifndef QT_NO_DEBUG_STREAM
396 {
398  if (d->pointingDeviceType)
399  return operator<<(debug, static_cast<const QPointingDevice *>(device));
400  QDebugStateSaver saver(debug);
401  debug.nospace();
402  debug.noquote();
403  debug << "QInputDevice(";
404  if (device) {
405  debug << '"' << device->name() << "\", type=" << device->type()
406  << Qt::hex << ", ID=" << device->systemId() << ", seat='" << device->seatName() << "'";
407  } else {
408  debug << '0';
409  }
410  debug << ')';
411  return debug;
412 }
413 #endif // !QT_NO_DEBUG_STREAM
414 
416 
417 #include "moc_qinputdevice.cpp"
static QCoreApplication * instance()
operator<<(QDataStream &ds, qfloat16 f)
Definition: qfloat16.cpp:327
The QDebug class provides an output stream for debugging information.
Definition: qdebug.h:65
Convenience class for custom QDebug operators.
Definition: qdebug.h:176
The QInputDevice class describes a device from which a QInputEvent originates.
Definition: qinputdevice.h:53
Capabilities capabilities
Definition: qinputdevice.h:58
QRect availableVirtualGeometry
Definition: qinputdevice.h:62
bool hasCapability(Capability cap) const
QInputDevice(QObject *parent=nullptr)
bool operator==(const QInputDevice &other) const
QString seatName
Definition: qinputdevice.h:60
DeviceType type
Definition: qinputdevice.h:57
qint64 systemId
Definition: qinputdevice.h:59
static const QInputDevice * primaryKeyboard(const QString &seatName=QString())
static QList< const QInputDevice * > devices()
static QStringList seatNames()
QString name
Definition: qinputdevice.h:56
~QInputDevicePrivate() override
static void registerDevice(const QInputDevice *dev)
static QInputDevicePrivate * get(QInputDevice *q)
static void unregisterDevice(const QInputDevice *dev)
static const QInputDevice * fromId(qint64 systemId)
static bool isRegistered(const QInputDevice *dev)
The QLatin1String class provides a thin wrapper around an US-ASCII/Latin-1 encoded string literal.
Definition: qstring.h:84
Definition: qlist.h:108
The QMutex class provides access serialization between threads.
Definition: qmutex.h:285
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes.
Definition: qmutex.h:317
void unlock() noexcept
Definition: qmutex.h:322
The QObject class is the base class of all Qt objects.
Definition: qobject.h:125
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:59
The QString class provides a Unicode character string.
Definition: qstring.h:388
bool isNull() const
Definition: qstring.h:1078
The QStringList class provides a list of strings.
QTextStream & hex(QTextStream &stream)
#define None
long long qint64
Definition: qglobal.h:298
#define Q_GLOBAL_STATIC(TYPE, NAME,...)
#define qWarning
Definition: qlogging.h:179
#define qCDebug(category,...)
GLenum GLuint id
[6]
Definition: qopengl.h:270
GLenum type
Definition: qopengl.h:270
GLsizei const GLfloat * v
[13]
GLuint name
GLuint64EXT * result
[6]
Definition: qopenglext.h:10932
QReadWriteLock lock
[0]
QSharedPointer< T > other(t)
[5]
IUIAutomationTreeWalker __RPC__deref_out_opt IUIAutomationElement ** parent