Qt 6.x
The Qt SDK
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
13
14using namespace Qt::StringLiterals;
15
17
19{
20 if (!s_outputMapping)
22
23 return s_outputMapping;
24}
25
27{
28 return false;
29}
30
32{
33 Q_UNUSED(deviceNode);
34 return QString();
35}
36
37#ifdef Q_OS_WEBOS
38QWindow *QOutputMapping::windowForDeviceNode(const QString &deviceNode)
39{
40 Q_UNUSED(deviceNode);
41 return nullptr;
42}
43
44void QOutputMapping::set(QOutputMapping *mapping)
45{
47 delete s_outputMapping;
48
50}
51#endif // Q_OS_WEBOS
52
54{
55 static QByteArray configFile = qgetenv("QT_QPA_EGLFS_KMS_CONFIG");
56 if (configFile.isEmpty())
57 return false;
58
59 QFile file(QString::fromUtf8(configFile));
61 qWarning("touch input support: Failed to open %s", configFile.constData());
62 return false;
63 }
64
66 if (!doc.isObject()) {
67 qWarning("touch input support: Failed to parse %s", configFile.constData());
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 m_screenTable.insert(deviceNode.canonicalFilePath(), screenName);
85 }
86
87 return true;
88}
89
91{
92 return m_screenTable.value(deviceNode);
93}
94
\inmodule QtCore
Definition qbytearray.h:57
const char * constData() const noexcept
Returns a pointer to the const data stored in the byte array.
Definition qbytearray.h:122
bool isEmpty() const noexcept
Returns true if the byte array has size 0; otherwise returns false.
Definition qbytearray.h:106
QString screenNameForDeviceNode(const QString &deviceNode) override
\inmodule QtCore \reentrant
Definition qfileinfo.h:22
QString canonicalFilePath() const
Returns the canonical path including the file name, i.e.
\inmodule QtCore
Definition qfile.h:93
bool open(OpenMode flags) override
Opens the file using OpenMode mode, returning true if successful; otherwise false.
Definition qfile.cpp:881
T value(const Key &key) const noexcept
Definition qhash.h:1044
iterator insert(const Key &key, const T &value)
Inserts a new item with the key and a value of value.
Definition qhash.h:1283
QByteArray readAll()
Reads all remaining data from the device, and returns it as a byte array.
\inmodule QtCore\reentrant
Definition qjsonarray.h:18
qsizetype size() const
Returns the number of values stored in the array.
QJsonValue at(qsizetype i) const
Returns a QJsonValue representing the value for index i.
\inmodule QtCore\reentrant
QJsonObject object() const
Returns the QJsonObject contained in the document.
bool isObject() const
Returns true if the document contains an object.
static QJsonDocument fromJson(const QByteArray &json, QJsonParseError *error=nullptr)
Parses json as a UTF-8 encoded JSON document, and creates a QJsonDocument from it.
QVariantMap toVariantMap() const
Converts this object to a QVariantMap.
QJsonValue value(const QString &key) const
Returns a QJsonValue representing the value for the key key.
QJsonObject toObject() const
This is an overloaded member function, provided for convenience. It differs from the above function o...
QJsonArray toArray() const
This is an overloaded member function, provided for convenience. It differs from the above function o...
static QOutputMapping * get()
virtual QString screenNameForDeviceNode(const QString &deviceNode)
virtual bool load()
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:127
static QString fromUtf8(QByteArrayView utf8)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition qstring.cpp:5857
\inmodule QtGui
Definition qwindow.h:63
Combined button and popup list for selecting options.
#define qWarning
Definition qlogging.h:162
GLenum GLenum GLenum GLenum mapping
static QOutputMapping * s_outputMapping
#define QStringLiteral(str)
Q_CORE_EXPORT QByteArray qgetenv(const char *varName)
#define Q_UNUSED(x)
QT_BEGIN_NAMESPACE typedef uchar * output
QFile file
[0]
char * toString(const MyType &t)
[31]