Commit 843baeba authored by Roman Gilg's avatar Roman Gilg
Browse files

feat: access outputs controls through config control

Summary:
Compositing output controls for all outputs into config control objects allows
writing and reading values according to the retention setting.

Test Plan: Compiles.

Reviewers: #plasma

Subscribers: davidedmundson, plasma-devel

Tags: #plasma

Differential Revision: https://phabricator.kde.org/D26031
parent e977e313
......@@ -115,7 +115,6 @@ ControlConfig::ControlConfig(KScreen::ConfigPtr config, QObject *parent)
// As global outputs are indexed by a hash of their edid, which is not unique,
// to be able to tell apart multiple identical outputs, these need special treatment
{
QStringList allIds;
const auto outputs = config->outputs();
allIds.reserve(outputs.count());
......@@ -126,6 +125,9 @@ ControlConfig::ControlConfig(KScreen::ConfigPtr config, QObject *parent)
}
allIds << outputId;
}
for (auto output : outputs) {
m_outputsControls << new ControlOutput(output, this);
}
// TODO: this is same in Output::readInOutputs of the daemon. Combine?
......@@ -147,6 +149,19 @@ QString ControlConfig::filePath() const
return filePathFromHash(m_config->connectedOutputsHash());
}
bool ControlConfig::writeFile()
{
bool success = true;
for (auto *outputControl : m_outputsControls) {
if (getOutputRetention(outputControl->id(), outputControl->name())
== OutputRetention::Individual) {
continue;
}
success &= outputControl->writeFile();
}
return success && Control::writeFile();
}
bool ControlConfig::infoIsOutput(const QVariantMap &info, const QString &outputId, const QString &outputName) const
{
const QString outputIdInfo = info[QStringLiteral("id")].toString();
......@@ -236,6 +251,16 @@ void ControlConfig::setOutputs(QVariantList outputsInfo)
auto &infoMap = info();
infoMap[QStringLiteral("outputs")] = outputsInfo;
}
ControlOutput* ControlConfig::getOutputControl(const QString &outputId,
const QString &outputName) const
{
for (auto *control : m_outputsControls) {
if (control->id() == outputId && control->name() == outputName) {
return control;
}
}
return nullptr;
}
ControlOutput::ControlOutput(KScreen::OutputPtr output, QObject *parent)
: Control(parent)
......@@ -244,6 +269,16 @@ ControlOutput::ControlOutput(KScreen::OutputPtr output, QObject *parent)
readFile();
}
QString ControlOutput::id() const
{
return m_output->hashMd5();
}
QString ControlOutput::name() const
{
return m_output->name();
}
QString ControlOutput::dirPath() const
{
return Control::dirPath() % QStringLiteral("outputs/");
......
......@@ -38,7 +38,7 @@ public:
~Control() override = default;
bool writeFile();
virtual bool writeFile();
protected:
virtual QString dirPath() const;
......@@ -55,6 +55,8 @@ private:
QVariantMap m_info;
};
class ControlOutput;
class ControlConfig : public Control
{
Q_OBJECT
......@@ -69,13 +71,17 @@ public:
QString dirPath() const override;
QString filePath() const override;
bool writeFile() override;
private:
QVariantList getOutputs() const;
void setOutputs(QVariantList outputsInfo);
bool infoIsOutput(const QVariantMap &info, const QString &outputId, const QString &outputName) const;
ControlOutput* getOutputControl(const QString &outputId, const QString &outputName) const;
KScreen::ConfigPtr m_config;
QStringList m_duplicateOutputIds;
QVector<ControlOutput*> m_outputsControls;
};
class ControlOutput : public Control
......@@ -84,6 +90,9 @@ class ControlOutput : public Control
public:
explicit ControlOutput(KScreen::OutputPtr output, QObject *parent = nullptr);
QString id() const;
QString name() const;
// TODO: scale auto value
QString dirPath() 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