1// Copyright (C) 2016 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 "qinputdevicemanager_p.h"
5#include "qinputdevicemanager_p_p.h"
6
7QT_BEGIN_NAMESPACE
8
9QT_IMPL_METATYPE_EXTERN_TAGGED(QInputDeviceManager::DeviceType, QInputDeviceManager__DeviceType)
10
11/*!
12 \class QInputDeviceManager
13 \internal
14
15 \brief QInputDeviceManager acts as a communication hub between QtGui and the input handlers.
16
17 On embedded platforms the input handling code is either compiled into the platform
18 plugin or is loaded dynamically as a generic plugin without any interface. The input
19 handler in use may also change between each run (e.g. evdevmouse/keyboard/touch
20 vs. libinput). QWindowSystemInterface is too limiting when Qt (the platform plugin) is
21 acting as a windowing system, and is one way only.
22
23 QInputDeviceManager solves this by providing a global object that is used to communicate
24 from the input handlers to the rest of Qt (e.g. the number of connected mice, which may
25 be important information for the cursor drawing code), and vice-versa (e.g. to indicate
26 to the input handler that a manual cursor position change was requested by the
27 application via QCursor::setPos and thus any internal state has to be updated accordingly).
28*/
29
30QInputDeviceManager::QInputDeviceManager(QObject *parent)
31 : QObject(*new QInputDeviceManagerPrivate, parent)
32{
33 qRegisterMetaType<DeviceType>();
34}
35
36QInputDeviceManager::~QInputDeviceManager() = default;
37
38int QInputDeviceManager::deviceCount(DeviceType type) const
39{
40 Q_D(const QInputDeviceManager);
41 return d->deviceCount(type);
42}
43
44int QInputDeviceManagerPrivate::deviceCount(QInputDeviceManager::DeviceType type) const
45{
46 return m_deviceCount[type];
47}
48
49void QInputDeviceManagerPrivate::setDeviceCount(QInputDeviceManager::DeviceType type, int count)
50{
51 Q_Q(QInputDeviceManager);
52 if (m_deviceCount[type] != count) {
53 m_deviceCount[type] = count;
54 emit q->deviceListChanged(type);
55 }
56}
57
58void QInputDeviceManager::setCursorPos(const QPoint &pos)
59{
60 emit cursorPositionChangeRequested(pos);
61}
62
63/*!
64 \return the keyboard modifier state stored in the QInputDeviceManager object.
65
66 Keyboard input handlers are expected to keep this up-to-date via
67 setKeyboardModifiers().
68
69 Querying the state via this function (e.g. from a mouse handler that needs
70 to include the modifier state in mouse events) is the preferred alternative
71 over QGuiApplication::keyboardModifiers() since the latter may not report
72 the current state due to asynchronous QPA event processing.
73 */
74Qt::KeyboardModifiers QInputDeviceManager::keyboardModifiers() const
75{
76 Q_D(const QInputDeviceManager);
77 return d->keyboardModifiers;
78}
79
80void QInputDeviceManager::setKeyboardModifiers(Qt::KeyboardModifiers mods)
81{
82 Q_D(QInputDeviceManager);
83 d->keyboardModifiers = mods;
84}
85
86QT_END_NAMESPACE
87
88#include "moc_qinputdevicemanager_p.cpp"
89

source code of qtbase/src/gui/kernel/qinputdevicemanager.cpp