Commit b1428d13 authored by Daniel Vrátil's avatar Daniel Vrátil 🤖

Wayland: add support for output type detection

Summary:
We can share the same "guessing" code with the XRandR backend here in order to
detect what type the output is (depending on having some of the well-known
connection types like HDMI, DP, etc. in its name).

The main benefit of this change is that we can know detect built-in laptop
screens on Wayland.

Reviewers: sebas, davidedmundson

Reviewed By: sebas

Subscribers: plasma-devel

Tags: #plasma

Differential Revision: https://phabricator.kde.org/D9908
parent daf10794
......@@ -4,6 +4,7 @@ set(wayland_SRCS
waylandconfig.cpp
waylandoutput.cpp
waylandscreen.cpp
../utils.cpp
)
add_library(KSC_KWayland MODULE ${wayland_SRCS})
......
......@@ -19,6 +19,7 @@
#include "waylandoutput.h"
#include "waylandbackend.h"
#include "waylandconfig.h"
#include "../utils.h"
#include <mode.h>
#include <edid.h>
......@@ -169,6 +170,7 @@ void WaylandOutput::updateKScreenOutput(KScreen::OutputPtr &output)
output->setPreferredModes(preferredModeIds);
output->setModes(modeList);
output->setScale(m_output->scale());
output->setType(Utils::guessOutputType(m_output->model(), m_output->model()));
}
QString WaylandOutput::modeName(const KWayland::Client::OutputDevice::Mode &m) const
......
/*************************************************************************************
* Copyright 2018 Daniel Vrátil <dvratil@kde.org> *
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public *
* License as published by the Free Software Foundation; either *
* version 2.1 of the License, or (at your option) any later version. *
* *
* This library is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
* Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU Lesser General Public *
* License along with this library; if not, write to the Free Software *
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA *
*************************************************************************************/
#include "utils.h"
#include <QVector>
KScreen::Output::Type Utils::guessOutputType(const QString &type, const QString &name)
{
static const auto embedded = { QLatin1String("LVDS"),
QLatin1String("IDP"),
QLatin1String("EDP"),
QLatin1String("LCD") };
for (const QLatin1String &pre : embedded) {
if (name.toUpper().startsWith(pre)) {
return KScreen::Output::Panel;
}
}
if (type.contains("VGA")) {
return KScreen::Output::VGA;
} else if (type.contains("DVI")) {
return KScreen::Output::DVI;
} else if (type.contains("DVI-I")) {
return KScreen::Output::DVII;
} else if (type.contains("DVI-A")) {
return KScreen::Output::DVIA;
} else if (type.contains("DVI-D")) {
return KScreen::Output::DVID;
} else if (type.contains("HDMI")) {
return KScreen::Output::HDMI;
} else if (type.contains("Panel")) {
return KScreen::Output::Panel;
} else if (type.contains("TV-Composite")) {
return KScreen::Output::TVComposite;
} else if (type.contains("TV-SVideo")) {
return KScreen::Output::TVSVideo;
} else if (type.contains("TV-Component")) {
return KScreen::Output::TVComponent;
} else if (type.contains("TV-SCART")) {
return KScreen::Output::TVSCART;
} else if (type.contains("TV-C4")) {
return KScreen::Output::TVC4;
} else if (type.contains("TV")) {
return KScreen::Output::TV;
} else if (type.contains("DisplayPort") || type.startsWith("DP")) {
return KScreen::Output::DisplayPort;
} else if (type.contains("unknown")) {
return KScreen::Output::Unknown;
} else {
return KScreen::Output::Unknown;
}
}
/*************************************************************************************
* Copyright 2018 Daniel Vrátil <dvratil@kde.org> *
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public *
* License as published by the Free Software Foundation; either *
* version 2.1 of the License, or (at your option) any later version. *
* *
* This library is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
* Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU Lesser General Public *
* License along with this library; if not, write to the Free Software *
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA *
*************************************************************************************/
#ifndef KSCREEN_BACKEND_UTILS_H_
#define KSCREEN_BACKEND_UTILS_H_
#include <kscreen/output.h>
namespace Utils {
KScreen::Output::Type guessOutputType(const QString &type, const QString &name);
}
#endif
......@@ -11,6 +11,7 @@ set(xrandr_SRCS
xrandrscreen.cpp
../xcbwrapper.cpp
../xcbeventlistener.cpp
../utils.cpp
)
add_library(KSC_XRandR MODULE ${xrandr_SRCS})
......
......@@ -23,6 +23,7 @@
#include "xrandr.h"
#include "output.h"
#include "config.h"
#include "../utils.h"
#include <QRect>
......@@ -259,53 +260,7 @@ KScreen::Output::Type XRandROutput::fetchOutputType(xcb_randr_output_t outputId,
type = name.toLocal8Bit();
}
static const QVector<QLatin1String> embedded{QLatin1String("LVDS"),
QLatin1String("IDP"),
QLatin1String("EDP"),
QLatin1String("LCD")};
for (const QLatin1String &pre : embedded) {
if (name.toUpper().startsWith(pre)) {
return KScreen::Output::Panel;
}
}
if (type.contains("VGA")) {
return KScreen::Output::VGA;
} else if (type.contains("DVI")) {
return KScreen::Output::DVI;
} else if (type.contains("DVI-I")) {
return KScreen::Output::DVII;
} else if (type.contains("DVI-A")) {
return KScreen::Output::DVIA;
} else if (type.contains("DVI-D")) {
return KScreen::Output::DVID;
} else if (type.contains("HDMI")) {
return KScreen::Output::HDMI;
} else if (type.contains("Panel")) {
return KScreen::Output::Panel;
} else if (type.contains("TV-Composite")) {
return KScreen::Output::TVComposite;
} else if (type.contains("TV-SVideo")) {
return KScreen::Output::TVSVideo;
} else if (type.contains("TV-Component")) {
return KScreen::Output::TVComponent;
} else if (type.contains("TV-SCART")) {
return KScreen::Output::TVSCART;
} else if (type.contains("TV-C4")) {
return KScreen::Output::TVC4;
} else if (type.contains("TV")) {
return KScreen::Output::TV;
} else if (type.contains("DisplayPort") || type.startsWith("DP")) {
return KScreen::Output::DisplayPort;
} else if (type.contains("unknown")) {
return KScreen::Output::Unknown;
} else {
// qCDebug(KSCREEN_XRANDR) << "Output Type not translated:" << type;
}
return KScreen::Output::Unknown;
return Utils::guessOutputType(type, name);
}
QByteArray XRandROutput::typeFromProperty(xcb_randr_output_t outputId)
......
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