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