Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
Loading...
Searching...
No Matches
qoutputmapping.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
4
#
include
"qoutputmapping_p.h"
5
#
include
<
QFile
>
6
#
include
<
QFileInfo
>
7
#
include
<
QVariantMap
>
8
#
include
<
QJsonDocument
>
9
#
include
<
QJsonObject
>
10
#
include
<
QJsonArray
>
11
12
QT_BEGIN_NAMESPACE
13
14
using
namespace
Qt::StringLiterals;
15
16
static
QOutputMapping
*
s_outputMapping
=
nullptr
;
17
18
QOutputMapping
*
QOutputMapping
::
get
()
19
{
20
if
(!
s_outputMapping
)
21
s_outputMapping
=
new
QDefaultOutputMapping
;
22
23
return
s_outputMapping
;
24
}
25
26
bool
QOutputMapping
::
load
()
27
{
28
return
false
;
29
}
30
31
QString
QOutputMapping
::
screenNameForDeviceNode
(
const
QString &deviceNode)
32
{
33
Q_UNUSED(deviceNode);
34
return
QString();
35
}
36
37
#
ifdef
Q_OS_WEBOS
38
QWindow *QOutputMapping::windowForDeviceNode(
const
QString &deviceNode)
39
{
40
Q_UNUSED(deviceNode);
41
return
nullptr
;
42
}
43
44
void
QOutputMapping::set(QOutputMapping *mapping)
45
{
46
if
(s_outputMapping)
47
delete
s_outputMapping;
48
49
s_outputMapping = mapping;
50
}
51
#
endif
// Q_OS_WEBOS
52
53
bool
QDefaultOutputMapping
::
load
()
54
{
55
static
QString configFile = qEnvironmentVariable(
"QT_QPA_EGLFS_KMS_CONFIG"
);
56
if
(configFile.isEmpty())
57
return
false
;
58
59
QFile file(configFile);
60
if
(!file.open(QFile::ReadOnly)) {
61
qWarning(
"touch input support: Failed to open %ls"
, qUtf16Printable(configFile));
62
return
false
;
63
}
64
65
const
QJsonDocument doc = QJsonDocument::fromJson(file.readAll());
66
if
(!doc.isObject()) {
67
qWarning(
"touch input support: Failed to parse %ls"
, qUtf16Printable(configFile));
68
return
false
;
69
}
70
71
// What we are interested is the virtualIndex and touchDevice properties for
72
// each element in the outputs array.
73
const
QJsonArray outputs = doc.object().value(
"outputs"_L1
).toArray();
74
for
(
int
i = 0; i < outputs.size(); ++i) {
75
const
QVariantMap output = outputs.at(i).toObject().toVariantMap();
76
if
(!output.contains(QStringLiteral(
"touchDevice"
)))
77
continue
;
78
if
(!output.contains(QStringLiteral(
"name"
))) {
79
qWarning(
"evdevtouch: Output %d specifies touchDevice but not name, this is wrong"
, i);
80
continue
;
81
}
82
QFileInfo deviceNode(output.value(QStringLiteral(
"touchDevice"
)).toString());
83
const
QString &screenName = output.value(QStringLiteral(
"name"
)).toString();
84
// Key on the canonical path so that a symlinked node, e.g. one under
85
// /dev/input/by-id, matches the node the input handler was given.
86
QString key = deviceNode.canonicalFilePath();
87
if
(key.isEmpty()) {
88
qWarning(
"touch input support: Cannot resolve touchDevice %ls of output %ls"
,
89
qUtf16Printable(deviceNode.filePath()), qUtf16Printable(screenName));
90
key = deviceNode.filePath();
91
}
92
m_screenTable.insert(key, screenName);
93
}
94
95
return
true
;
96
}
97
98
QString
QDefaultOutputMapping
::
screenNameForDeviceNode
(
const
QString &deviceNode)
99
{
100
const
QString canonical = QFileInfo(deviceNode).canonicalFilePath();
101
if
(!canonical.isEmpty()) {
102
auto
it = m_screenTable.constFind(canonical);
103
if
(it != m_screenTable.constEnd())
104
return
*it;
105
}
106
return
m_screenTable.value(deviceNode);
107
}
108
109
QT_END_NAMESPACE
QDefaultOutputMapping
Definition
qoutputmapping_p.h:42
QDefaultOutputMapping::screenNameForDeviceNode
QString screenNameForDeviceNode(const QString &deviceNode) override
Definition
qoutputmapping.cpp:98
QDefaultOutputMapping::load
bool load() override
Definition
qoutputmapping.cpp:53
QOutputMapping
Definition
qoutputmapping_p.h:27
QOutputMapping::get
static QOutputMapping * get()
Definition
qoutputmapping.cpp:18
QOutputMapping::screenNameForDeviceNode
virtual QString screenNameForDeviceNode(const QString &deviceNode)
Definition
qoutputmapping.cpp:31
QOutputMapping::load
virtual bool load()
Definition
qoutputmapping.cpp:26
QT_BEGIN_NAMESPACE
Combined button and popup list for selecting options.
Definition
qsequentialanimationgroup.cpp:47
s_outputMapping
static QOutputMapping * s_outputMapping
Definition
qoutputmapping.cpp:16
qtbase
src
platformsupport
input
shared
qoutputmapping.cpp
Generated on
for Qt by
1.18.0