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
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
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
14QT_BEGIN_NAMESPACE
15
16using namespace Qt::StringLiterals;
17
19
21{
22 static QBasicMutex mutex;
23 QMutexLocker locker(&mutex);
24 if (!s_outputMapping)
26
27 return s_outputMapping;
28}
29
31{
32 return false;
33}
34
36{
37 Q_UNUSED(deviceNode);
38 return QString();
39}
40
41#ifdef Q_OS_WEBOS
42QWindow *QOutputMapping::windowForDeviceNode(const QString &deviceNode)
43{
44 Q_UNUSED(deviceNode);
45 return nullptr;
46}
47
48void 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
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
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
120QT_END_NAMESPACE
QString screenNameForDeviceNode(const QString &deviceNode) override
static QOutputMapping * get()
virtual QString screenNameForDeviceNode(const QString &deviceNode)
virtual bool load()
static QOutputMapping * s_outputMapping