Commit 19e6756f authored by Roman Gilg's avatar Roman Gilg
Browse files

feat: control replication

Summary:
Adds API to read and write the replication source of an output to the control
file. This allows to remember specifically which output was the replication
source for another one since the windowing system might only get position
and size information about the replica-relation. This is the case on X11 and
will likely be handled in a similar way on Wayland.

Test Plan: Compiles.

Reviewers: #plasma

Subscribers: plasma-devel

Tags: #plasma

Differential Revision: https://phabricator.kde.org/D26220
parent 602904ae
......@@ -344,6 +344,76 @@ void ControlConfig::setAutoRotate(const QString &outputId, const QString &output
setOutputAutoRotate();
}
KScreen::OutputPtr ControlConfig::getReplicationSource(const KScreen::OutputPtr &output) const
{
return getReplicationSource(output->hashMd5(), output->name());
}
KScreen::OutputPtr ControlConfig::getReplicationSource(const QString &outputId,
const QString &outputName) const
{
const QVariantList outputsInfo = getOutputs();
for (const auto variantInfo : outputsInfo) {
const QVariantMap info = variantInfo.toMap();
if (!infoIsOutput(info, outputId, outputName)) {
continue;
}
const QString sourceHash = info[QStringLiteral("replicate-hash")].toString();
const QString sourceName = info[QStringLiteral("replicate-name")].toString();
if (sourceHash.isEmpty() && sourceName.isEmpty()) {
// Common case when the replication source has been unset.
return nullptr;
}
for (auto output : m_config->outputs()) {
if (output->hashMd5() == sourceHash && output->name() == sourceName) {
return output;
}
}
// No match.
return nullptr;
}
// Info for output not found.
return nullptr;
}
void ControlConfig::setReplicationSource(const KScreen::OutputPtr &output,
const KScreen::OutputPtr &source)
{
setReplicationSource(output->hashMd5(), output->name(), source);
}
void ControlConfig::setReplicationSource(const QString &outputId, const QString &outputName,
const KScreen::OutputPtr &source)
{
QList<QVariant>::iterator it;
QVariantList outputsInfo = getOutputs();
const QString sourceHash = source->hashMd5();
const QString sourceName = source->name();
for (it = outputsInfo.begin(); it != outputsInfo.end(); ++it) {
QVariantMap outputInfo = (*it).toMap();
if (!infoIsOutput(outputInfo, outputId, outputName)) {
continue;
}
outputInfo[QStringLiteral("replicate-hash")] = sourceHash;
outputInfo[QStringLiteral("replicate-name")] = sourceName;
*it = outputInfo;
setOutputs(outputsInfo);
// TODO: shall we set this information also as new global value (like with auto-rotate)?
return;
}
// no entry yet, create one
auto outputInfo = createOutputInfo(outputId, outputName);
outputInfo[QStringLiteral("replicate-hash")] = sourceHash;
outputInfo[QStringLiteral("replicate-name")] = sourceName;
outputsInfo << outputInfo;
setOutputs(outputsInfo);
// TODO: shall we set this information also as new global value (like with auto-rotate)?
}
QVariantList ControlConfig::getOutputs() const
{
return constInfo()[QStringLiteral("outputs")].toList();
......
......@@ -82,6 +82,13 @@ public:
void setAutoRotate(const KScreen::OutputPtr &output, bool value);
void setAutoRotate(const QString &outputId, const QString &outputName, bool value);
KScreen::OutputPtr getReplicationSource(const KScreen::OutputPtr &output) const;
KScreen::OutputPtr getReplicationSource(const QString &outputId,
const QString &outputName) const;
void setReplicationSource(const KScreen::OutputPtr &output, const KScreen::OutputPtr &source);
void setReplicationSource(const QString &outputId, const QString &outputName,
const KScreen::OutputPtr &source);
QString dirPath() const override;
QString filePath() const override;
......
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