Commit 98f53fa4 authored by Méven Car's avatar Méven Car
Browse files

Display output serial number when there is other with same model/vendor

BUG: 446486
parent 27d916be
Pipeline #106136 failed with stage
in 59 seconds
......@@ -10,12 +10,12 @@
#include <KLocalizedString>
QString Utils::outputName(const KScreen::OutputPtr &output)
QString Utils::outputName(const KScreen::OutputPtr &output, bool shouldShowSerialNumber)
{
return outputName(output.data());
return outputName(output.data(), shouldShowSerialNumber);
}
QString Utils::outputName(const KScreen::Output *output)
QString Utils::outputName(const KScreen::Output *output, bool shouldShowSerialNumber)
{
if (output->type() == KScreen::Output::Panel) {
return i18n("Laptop Screen");
......@@ -31,6 +31,9 @@ QString Utils::outputName(const KScreen::Output *output)
if (!output->edid()->name().isEmpty()) {
name += output->edid()->name() + QLatin1Char(' ');
}
if (!output->edid()->serial().isEmpty() && shouldShowSerialNumber) {
name += output->edid()->serial();
}
if (!name.trimmed().isEmpty()) {
return name;
}
......
......@@ -15,8 +15,8 @@
namespace Utils
{
QString outputName(const KScreen::Output *output);
QString outputName(const KScreen::OutputPtr &output);
QString outputName(const KScreen::Output *output, bool shouldShowSerialNumber = false);
QString outputName(const KScreen::OutputPtr &output, bool shouldShowSerialNumber = false);
QString sizeToString(const QSize &size);
}
......
......@@ -7,6 +7,7 @@
#include "../common/utils.h"
#include <kscreen/edid.h>
#include <kscreen/output.h>
#include <QQuickItem>
......@@ -60,7 +61,15 @@ OutputIdentifier::OutputIdentifier(KScreen::ConfigPtr config, QObject *parent)
} else {
logicalSize = deviceSize / view->effectiveDevicePixelRatio();
}
rootObj->setProperty("outputName", Utils::outputName(output));
bool shouldShowSerialNumber = false;
if (output->edid()) {
shouldShowSerialNumber = std::any_of(outputs.cbegin(), outputs.cend(), [output](const auto &other) {
return other->id() != output->id() // avoid same output
&& other->edid() && other->edid()->name() == output->edid()->name() && other->edid()->vendor() == output->edid()->vendor();
});
}
rootObj->setProperty("outputName", Utils::outputName(output, shouldShowSerialNumber));
rootObj->setProperty("modeName", Utils::sizeToString(deviceSize));
view->setProperty("screenSize", QRect(output->pos(), logicalSize));
m_views << view;
......
......@@ -6,6 +6,7 @@
#include "output_model.h"
#include "../common/utils.h"
#include "kscreen/edid.h"
#include "config_handler.h"
......@@ -34,8 +35,17 @@ QVariant OutputModel::data(const QModelIndex &index, int role) const
const KScreen::OutputPtr &output = m_outputs[index.row()].ptr;
switch (role) {
case Qt::DisplayRole:
return Utils::outputName(output);
case Qt::DisplayRole: {
bool shouldShowSerialNumber = false;
if (output->edid()) {
shouldShowSerialNumber = std::any_of(m_outputs.cbegin(), m_outputs.cend(), [output](const OutputModel::Output &other) {
return other.ptr->id() != output->id() // avoid same output
&& other.ptr->edid() && other.ptr->edid()->name() == output->edid()->name() // model
&& other.ptr->edid()->vendor() == output->edid()->vendor();
});
}
return Utils::outputName(output, shouldShowSerialNumber);
}
case EnabledRole:
return output->isEnabled();
case InternalRole:
......
......@@ -81,7 +81,7 @@ void Osd::showGenericOsd(const QString &icon, const QString &text)
showOsd();
}
void Osd::showOutputIdentifier(const KScreen::OutputPtr &output)
void Osd::showOutputIdentifier(const KScreen::OutputPtr &output, bool shouldShouldSerialNumber)
{
if (!initOsd()) {
return;
......@@ -97,7 +97,7 @@ void Osd::showOutputIdentifier(const KScreen::OutputPtr &output)
}
rootObject->setProperty("itemSource", QStringLiteral("OutputIdentifier.qml"));
rootObject->setProperty("modeName", Utils::sizeToString(realSize));
rootObject->setProperty("outputName", Utils::outputName(output));
rootObject->setProperty("outputName", Utils::outputName(output, shouldShouldSerialNumber));
showOsd();
}
......
......@@ -34,7 +34,7 @@ public:
~Osd() override;
void showGenericOsd(const QString &icon, const QString &text);
void showOutputIdentifier(const KScreen::OutputPtr &output);
void showOutputIdentifier(const KScreen::OutputPtr &output, bool shouldShouldSerialNumber);
void showActionSelector();
void hideOsd();
......
......@@ -9,6 +9,7 @@
#include "osd.h"
#include <KScreen/Config>
#include <KScreen/EDID>
#include <KScreen/GetConfigOperation>
#include <KScreen/Output>
......@@ -79,7 +80,8 @@ void OsdManager::slotIdentifyOutputs(KScreen::ConfigOperation *op)
const KScreen::ConfigPtr config = qobject_cast<KScreen::GetConfigOperation *>(op)->config();
Q_FOREACH (const KScreen::OutputPtr &output, config->outputs()) {
const auto outputs = config->outputs();
for (const KScreen::OutputPtr &output : outputs) {
if (!output->isConnected() || !output->isEnabled() || !output->currentMode()) {
continue;
}
......@@ -88,7 +90,15 @@ void OsdManager::slotIdentifyOutputs(KScreen::ConfigOperation *op)
osd = new KScreen::Osd(output, this);
m_osds.insert(output->name(), osd);
}
osd->showOutputIdentifier(output);
bool shouldShowSerialNumber = false;
if (output->edid()) {
shouldShowSerialNumber = std::any_of(outputs.cbegin(), outputs.cend(), [output](const auto &other) {
return other->id() != output->id() // avoid same output
&& other->edid() && other->edid()->name() == output->edid()->name() && other->edid()->vendor() == output->edid()->vendor();
});
}
osd->showOutputIdentifier(output, shouldShowSerialNumber);
}
m_cleanupTimer->start();
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment