outputlocator: Return "Unknown" as screen name when we can't determine it

This slightly refactors the name generation in outputlocator to ensure
we don't add spaces when there's nothing to add a space to. It also
ensures that if we can't determine a proper name because all parts are
empty we return "Unknown" as name.
This commit is contained in:
Arjen Hiemstra 2022-08-17 13:01:36 +02:00 committed by Vlad Zahorodnii
parent 5aa7a48f93
commit a8e6184d3c
2 changed files with 21 additions and 4 deletions

View file

@ -8,6 +8,7 @@ target_link_libraries(kwin4_effect_outputlocator PRIVATE
kwineffects
Qt::DBus
Qt::Quick
KF5::I18n
)
install(DIRECTORY qml DESTINATION ${KDE_INSTALL_DATADIR}/kwin/effects/outputlocator)

View file

@ -8,6 +8,8 @@
#include <kwinoffscreenquickview.h>
#include <KLocalizedString>
#include <QDBusConnection>
#include <QQuickItem>
@ -20,11 +22,25 @@ static QString outputName(const EffectScreen *screen)
const bool shouldShowSerialNumber = std::any_of(screens.cbegin(), screens.cend(), [screen](const EffectScreen *other) {
return other != screen && other->manufacturer() == screen->manufacturer() && other->model() == screen->model();
});
QString name = screen->manufacturer() + QLatin1Char(' ') + screen->model();
if (shouldShowSerialNumber) {
name += QLatin1Char(' ') + screen->serialNumber();
QStringList parts;
if (!screen->manufacturer().isEmpty()) {
parts.append(screen->manufacturer());
}
if (!screen->model().isEmpty()) {
parts.append(screen->model());
}
if (shouldShowSerialNumber && !screen->serialNumber().isEmpty()) {
parts.append(screen->serialNumber());
}
if (parts.isEmpty()) {
return i18nc("@label", "Unknown");
} else {
return parts.join(QLatin1Char(' '));
}
return name;
}
OutputLocatorEffect::OutputLocatorEffect(QObject *parent)