2020-08-02 22:22:19 +00:00
|
|
|
/*
|
|
|
|
KWin - the KDE window manager
|
|
|
|
This file is part of the KDE project.
|
2019-07-02 10:01:37 +00:00
|
|
|
|
2020-08-02 22:22:19 +00:00
|
|
|
SPDX-FileCopyrightText: 2015 Martin Flöser <mgraesslin@kde.org>
|
|
|
|
SPDX-FileCopyrightText: 2019 Vlad Zahorodnii <vlad.zahorodnii@kde.org>
|
2019-07-02 10:01:37 +00:00
|
|
|
|
2020-08-02 22:22:19 +00:00
|
|
|
SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
*/
|
2019-07-02 10:01:37 +00:00
|
|
|
|
|
|
|
#include "edid.h"
|
Decode full monitor vendor name from EDID using hwdata
Test Plan:
KScreen now shows "Dell Inc." instead of DEL and
"Eizo Nano Corporation" instead of ENC in output names, which
matches closer to what's written on my monitors.
Reviewers: graesslin, davidedmundson, #plasma
Reviewed By: davidedmundson, #plasma
Subscribers: apol, feverfew, ngraham, davidedmundson, mart, kwin, sebas
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D10041
2020-02-26 11:37:01 +00:00
|
|
|
#include "config-kwin.h"
|
|
|
|
|
|
|
|
#include <QFile>
|
fix: make hwdata truly a runtime dependency
Summary: Followup to comments in D10041
Reviewers: #plasma, ngraham, davidedmundson, zzag
Reviewed By: #plasma, ngraham, davidedmundson, zzag
Subscribers: iasensio, wstephenson, davidedmundson, zzag, ngraham, kwin, cgiboudeaux
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D27729
2020-03-17 13:27:05 +00:00
|
|
|
#include <QStandardPaths>
|
2019-07-02 10:01:37 +00:00
|
|
|
|
2021-03-31 11:22:23 +00:00
|
|
|
#include <KLocalizedString>
|
|
|
|
|
2019-07-02 10:01:37 +00:00
|
|
|
namespace KWin
|
|
|
|
{
|
|
|
|
|
|
|
|
static bool verifyHeader(const uint8_t *data)
|
|
|
|
{
|
|
|
|
if (data[0] != 0x0 || data[7] != 0x0) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return std::all_of(data + 1, data + 7,
|
|
|
|
[](uint8_t byte) { return byte == 0xff; });
|
|
|
|
}
|
|
|
|
|
|
|
|
static QSize parsePhysicalSize(const uint8_t *data)
|
|
|
|
{
|
|
|
|
// Convert physical size from centimeters to millimeters.
|
|
|
|
return QSize(data[0x15], data[0x16]) * 10;
|
|
|
|
}
|
|
|
|
|
Decode full monitor vendor name from EDID using hwdata
Test Plan:
KScreen now shows "Dell Inc." instead of DEL and
"Eizo Nano Corporation" instead of ENC in output names, which
matches closer to what's written on my monitors.
Reviewers: graesslin, davidedmundson, #plasma
Reviewed By: davidedmundson, #plasma
Subscribers: apol, feverfew, ngraham, davidedmundson, mart, kwin, sebas
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D10041
2020-02-26 11:37:01 +00:00
|
|
|
static QByteArray parsePnpId(const uint8_t *data)
|
2019-07-02 10:01:37 +00:00
|
|
|
{
|
Decode full monitor vendor name from EDID using hwdata
Test Plan:
KScreen now shows "Dell Inc." instead of DEL and
"Eizo Nano Corporation" instead of ENC in output names, which
matches closer to what's written on my monitors.
Reviewers: graesslin, davidedmundson, #plasma
Reviewed By: davidedmundson, #plasma
Subscribers: apol, feverfew, ngraham, davidedmundson, mart, kwin, sebas
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D10041
2020-02-26 11:37:01 +00:00
|
|
|
// Decode PNP ID from three 5 bit words packed into 2 bytes:
|
2019-07-02 10:01:37 +00:00
|
|
|
//
|
|
|
|
// | Byte | Bit |
|
|
|
|
// | | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
|
|
|
|
// ----------------------------------------
|
|
|
|
// | 1 | 0)| (4| 3 | 2 | 1 | 0)| (4| 3 |
|
|
|
|
// | | * | Character 1 | Char 2|
|
|
|
|
// ----------------------------------------
|
|
|
|
// | 2 | 2 | 1 | 0)| (4| 3 | 2 | 1 | 0)|
|
|
|
|
// | | Character2| Character 3 |
|
|
|
|
// ----------------------------------------
|
|
|
|
const uint offset = 0x8;
|
|
|
|
|
|
|
|
char pnpId[4];
|
|
|
|
pnpId[0] = 'A' + ((data[offset + 0] >> 2) & 0x1f) - 1;
|
|
|
|
pnpId[1] = 'A' + (((data[offset + 0] & 0x3) << 3) | ((data[offset + 1] >> 5) & 0x7)) - 1;
|
|
|
|
pnpId[2] = 'A' + (data[offset + 1] & 0x1f) - 1;
|
|
|
|
pnpId[3] = '\0';
|
|
|
|
|
|
|
|
return QByteArray(pnpId);
|
|
|
|
}
|
|
|
|
|
Decode full monitor vendor name from EDID using hwdata
Test Plan:
KScreen now shows "Dell Inc." instead of DEL and
"Eizo Nano Corporation" instead of ENC in output names, which
matches closer to what's written on my monitors.
Reviewers: graesslin, davidedmundson, #plasma
Reviewed By: davidedmundson, #plasma
Subscribers: apol, feverfew, ngraham, davidedmundson, mart, kwin, sebas
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D10041
2020-02-26 11:37:01 +00:00
|
|
|
|
|
|
|
static QByteArray parseEisaId(const uint8_t *data)
|
|
|
|
{
|
|
|
|
for (int i = 72; i <= 108; i += 18) {
|
|
|
|
// Skip the block if it isn't used as monitor descriptor.
|
|
|
|
if (data[i]) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (data[i + 1]) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// We have found the EISA ID, it's stored as ASCII.
|
|
|
|
if (data[i + 3] == 0xfe) {
|
|
|
|
return QByteArray(reinterpret_cast<const char *>(&data[i + 5]), 12).trimmed();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// If there isn't an ASCII EISA ID descriptor, try to decode PNP ID
|
|
|
|
return parsePnpId(data);
|
|
|
|
}
|
|
|
|
|
2019-07-02 10:01:37 +00:00
|
|
|
static QByteArray parseMonitorName(const uint8_t *data)
|
|
|
|
{
|
|
|
|
for (int i = 72; i <= 108; i += 18) {
|
|
|
|
// Skip the block if it isn't used as monitor descriptor.
|
|
|
|
if (data[i]) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (data[i + 1]) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// We have found the monitor name, it's stored as ASCII.
|
|
|
|
if (data[i + 3] == 0xfc) {
|
|
|
|
return QByteArray(reinterpret_cast<const char *>(&data[i + 5]), 12).trimmed();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return QByteArray();
|
|
|
|
}
|
|
|
|
|
|
|
|
static QByteArray parseSerialNumber(const uint8_t *data)
|
|
|
|
{
|
|
|
|
for (int i = 72; i <= 108; i += 18) {
|
|
|
|
// Skip the block if it isn't used as monitor descriptor.
|
|
|
|
if (data[i]) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (data[i + 1]) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// We have found the serial number, it's stored as ASCII.
|
|
|
|
if (data[i + 3] == 0xff) {
|
|
|
|
return QByteArray(reinterpret_cast<const char *>(&data[i + 5]), 12).trimmed();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Maybe there isn't an ASCII serial number descriptor, so use this instead.
|
|
|
|
const uint32_t offset = 0xc;
|
|
|
|
|
|
|
|
uint32_t serialNumber = data[offset + 0];
|
|
|
|
serialNumber |= uint32_t(data[offset + 1]) << 8;
|
|
|
|
serialNumber |= uint32_t(data[offset + 2]) << 16;
|
|
|
|
serialNumber |= uint32_t(data[offset + 3]) << 24;
|
|
|
|
if (serialNumber) {
|
|
|
|
return QByteArray::number(serialNumber);
|
|
|
|
}
|
|
|
|
|
|
|
|
return QByteArray();
|
|
|
|
}
|
|
|
|
|
Decode full monitor vendor name from EDID using hwdata
Test Plan:
KScreen now shows "Dell Inc." instead of DEL and
"Eizo Nano Corporation" instead of ENC in output names, which
matches closer to what's written on my monitors.
Reviewers: graesslin, davidedmundson, #plasma
Reviewed By: davidedmundson, #plasma
Subscribers: apol, feverfew, ngraham, davidedmundson, mart, kwin, sebas
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D10041
2020-02-26 11:37:01 +00:00
|
|
|
static QByteArray parseVendor(const uint8_t *data)
|
|
|
|
{
|
|
|
|
const auto pnpId = parsePnpId(data);
|
|
|
|
|
|
|
|
// Map to vendor name
|
fix: make hwdata truly a runtime dependency
Summary: Followup to comments in D10041
Reviewers: #plasma, ngraham, davidedmundson, zzag
Reviewed By: #plasma, ngraham, davidedmundson, zzag
Subscribers: iasensio, wstephenson, davidedmundson, zzag, ngraham, kwin, cgiboudeaux
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D27729
2020-03-17 13:27:05 +00:00
|
|
|
QFile pnpFile(QStandardPaths::locate(QStandardPaths::GenericDataLocation, QStringLiteral("hwdata/pnp.ids")));
|
Decode full monitor vendor name from EDID using hwdata
Test Plan:
KScreen now shows "Dell Inc." instead of DEL and
"Eizo Nano Corporation" instead of ENC in output names, which
matches closer to what's written on my monitors.
Reviewers: graesslin, davidedmundson, #plasma
Reviewed By: davidedmundson, #plasma
Subscribers: apol, feverfew, ngraham, davidedmundson, mart, kwin, sebas
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D10041
2020-02-26 11:37:01 +00:00
|
|
|
if (pnpFile.exists() && pnpFile.open(QIODevice::ReadOnly)) {
|
|
|
|
while (!pnpFile.atEnd()) {
|
|
|
|
const auto line = pnpFile.readLine();
|
|
|
|
if (line.startsWith(pnpId)) {
|
|
|
|
return line.mid(4).trimmed();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
fix: make hwdata truly a runtime dependency
Summary: Followup to comments in D10041
Reviewers: #plasma, ngraham, davidedmundson, zzag
Reviewed By: #plasma, ngraham, davidedmundson, zzag
Subscribers: iasensio, wstephenson, davidedmundson, zzag, ngraham, kwin, cgiboudeaux
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D27729
2020-03-17 13:27:05 +00:00
|
|
|
|
Decode full monitor vendor name from EDID using hwdata
Test Plan:
KScreen now shows "Dell Inc." instead of DEL and
"Eizo Nano Corporation" instead of ENC in output names, which
matches closer to what's written on my monitors.
Reviewers: graesslin, davidedmundson, #plasma
Reviewed By: davidedmundson, #plasma
Subscribers: apol, feverfew, ngraham, davidedmundson, mart, kwin, sebas
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D10041
2020-02-26 11:37:01 +00:00
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
2019-07-02 10:01:37 +00:00
|
|
|
Edid::Edid()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
Edid::Edid(const void *data, uint32_t size)
|
|
|
|
{
|
2020-10-26 17:29:33 +00:00
|
|
|
m_raw.resize(size);
|
|
|
|
memcpy(m_raw.data(), data, size);
|
|
|
|
|
2019-07-02 10:01:37 +00:00
|
|
|
const uint8_t *bytes = static_cast<const uint8_t *>(data);
|
|
|
|
|
|
|
|
if (size < 128) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!verifyHeader(bytes)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_physicalSize = parsePhysicalSize(bytes);
|
|
|
|
m_eisaId = parseEisaId(bytes);
|
|
|
|
m_monitorName = parseMonitorName(bytes);
|
|
|
|
m_serialNumber = parseSerialNumber(bytes);
|
Decode full monitor vendor name from EDID using hwdata
Test Plan:
KScreen now shows "Dell Inc." instead of DEL and
"Eizo Nano Corporation" instead of ENC in output names, which
matches closer to what's written on my monitors.
Reviewers: graesslin, davidedmundson, #plasma
Reviewed By: davidedmundson, #plasma
Subscribers: apol, feverfew, ngraham, davidedmundson, mart, kwin, sebas
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D10041
2020-02-26 11:37:01 +00:00
|
|
|
m_vendor = parseVendor(bytes);
|
2019-07-02 10:01:37 +00:00
|
|
|
|
|
|
|
m_isValid = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Edid::isValid() const
|
|
|
|
{
|
|
|
|
return m_isValid;
|
|
|
|
}
|
|
|
|
|
|
|
|
QSize Edid::physicalSize() const
|
|
|
|
{
|
|
|
|
return m_physicalSize;
|
|
|
|
}
|
|
|
|
|
|
|
|
QByteArray Edid::eisaId() const
|
|
|
|
{
|
|
|
|
return m_eisaId;
|
|
|
|
}
|
|
|
|
|
|
|
|
QByteArray Edid::monitorName() const
|
|
|
|
{
|
|
|
|
return m_monitorName;
|
|
|
|
}
|
|
|
|
|
|
|
|
QByteArray Edid::serialNumber() const
|
|
|
|
{
|
|
|
|
return m_serialNumber;
|
|
|
|
}
|
|
|
|
|
Decode full monitor vendor name from EDID using hwdata
Test Plan:
KScreen now shows "Dell Inc." instead of DEL and
"Eizo Nano Corporation" instead of ENC in output names, which
matches closer to what's written on my monitors.
Reviewers: graesslin, davidedmundson, #plasma
Reviewed By: davidedmundson, #plasma
Subscribers: apol, feverfew, ngraham, davidedmundson, mart, kwin, sebas
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D10041
2020-02-26 11:37:01 +00:00
|
|
|
QByteArray Edid::vendor() const
|
|
|
|
{
|
|
|
|
return m_vendor;
|
|
|
|
}
|
|
|
|
|
2020-10-26 17:29:33 +00:00
|
|
|
QByteArray Edid::raw() const
|
|
|
|
{
|
|
|
|
return m_raw;
|
|
|
|
}
|
|
|
|
|
2021-03-31 11:22:23 +00:00
|
|
|
QString Edid::manufacturerString() const
|
|
|
|
{
|
|
|
|
QString manufacturer;
|
|
|
|
if (!m_vendor.isEmpty()) {
|
|
|
|
manufacturer = QString::fromLatin1(m_vendor);
|
|
|
|
} else if (!m_eisaId.isEmpty()) {
|
|
|
|
manufacturer = QString::fromLatin1(m_eisaId);
|
|
|
|
}
|
|
|
|
return manufacturer;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString Edid::nameString() const
|
|
|
|
{
|
|
|
|
if (!m_monitorName.isEmpty()) {
|
|
|
|
QString m = QString::fromLatin1(m_monitorName);
|
|
|
|
if (!m_serialNumber.isEmpty()) {
|
|
|
|
m.append('/');
|
|
|
|
m.append(QString::fromLatin1(m_serialNumber));
|
|
|
|
}
|
|
|
|
return m;
|
|
|
|
} else if (!m_serialNumber.isEmpty()) {
|
|
|
|
return QString::fromLatin1(m_serialNumber);
|
|
|
|
} else {
|
|
|
|
return i18n("unknown");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-02 10:01:37 +00:00
|
|
|
} // namespace KWin
|