Coverage Report

Created: 2026-05-31 06:50

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/qtbase/src/gui/kernel/qinputdevicemanager.cpp
Line
Count
Source
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
5
#include "qinputdevicemanager_p.h"
6
#include "qinputdevicemanager_p_p.h"
7
8
QT_BEGIN_NAMESPACE
9
10
QT_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
31
QInputDeviceManager::QInputDeviceManager(QObject *parent)
32
0
    : QObject(*new QInputDeviceManagerPrivate, parent)
33
0
{
34
0
    qRegisterMetaType<DeviceType>();
35
0
}
36
37
0
QInputDeviceManager::~QInputDeviceManager() = default;
38
39
int QInputDeviceManager::deviceCount(DeviceType type) const
40
0
{
41
0
    Q_D(const QInputDeviceManager);
42
0
    return d->deviceCount(type);
43
0
}
44
45
int QInputDeviceManagerPrivate::deviceCount(QInputDeviceManager::DeviceType type) const
46
0
{
47
0
    return m_deviceCount[type];
48
0
}
49
50
void QInputDeviceManagerPrivate::setDeviceCount(QInputDeviceManager::DeviceType type, int count)
51
0
{
52
0
    Q_Q(QInputDeviceManager);
53
0
    if (m_deviceCount[type] != count) {
54
0
        m_deviceCount[type] = count;
55
0
        emit q->deviceListChanged(type);
56
0
    }
57
0
}
58
59
void QInputDeviceManager::setCursorPos(const QPoint &pos)
60
0
{
61
0
    emit cursorPositionChangeRequested(pos);
62
0
}
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
 */
75
Qt::KeyboardModifiers QInputDeviceManager::keyboardModifiers() const
76
0
{
77
0
    Q_D(const QInputDeviceManager);
78
0
    return d->keyboardModifiers;
79
0
}
80
81
void QInputDeviceManager::setKeyboardModifiers(Qt::KeyboardModifiers mods)
82
0
{
83
    Q_D(QInputDeviceManager);
84
0
    d->keyboardModifiers = mods;
85
0
}
86
87
QT_END_NAMESPACE
88
89
#include "moc_qinputdevicemanager_p.cpp"