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