diff --git a/src/config.h b/src/config.h --- a/src/config.h +++ b/src/config.h @@ -115,6 +115,18 @@ */ ConfigPtr clone() const; + /** + * Returns an identifying hash for this config in regards to its + * connected outputs. + * + * The hash is calculated with a sorted combination of all + * connected output hashes. + * + * @return sorted hash combination of all connected outputs + * @since 5.15 + */ + QString connectedOutputsHash() const; + ScreenPtr screen() const; void setScreen(const ScreenPtr &screen); diff --git a/src/config.cpp b/src/config.cpp --- a/src/config.cpp +++ b/src/config.cpp @@ -25,6 +25,8 @@ #include #include +#include +#include using namespace KScreen; @@ -219,6 +221,19 @@ return newConfig; } +QString Config::connectedOutputsHash() const +{ + QStringList hashedOutputs; + + const auto outputs = connectedOutputs(); + for (const OutputPtr &output : outputs) { + hashedOutputs << output->hash(); + } + std::sort(hashedOutputs.begin(), hashedOutputs.end()); + const auto hash = QCryptographicHash::hash(hashedOutputs.join(QString()).toLatin1(), + QCryptographicHash::Md5); + return QString::fromLatin1(hash.toHex()); +} ScreenPtr Config::screen() const { diff --git a/src/output.h b/src/output.h --- a/src/output.h +++ b/src/output.h @@ -98,6 +98,17 @@ QString name() const; void setName(const QString& name); + /** + * Returns an identifying hash for this output. + * + * The hash is calculated either via the edid hash or if no + * edid is available by the output name. + * + * @return identifying hash of this output + * @since 5.15 + */ + QString hash() const; + Type type() const; void setType(Type type); diff --git a/src/output.cpp b/src/output.cpp --- a/src/output.cpp +++ b/src/output.cpp @@ -210,6 +210,14 @@ Q_EMIT outputChanged(); } +QString Output::hash() const +{ + if (edid() && edid()->isValid()) { + return edid()->hash(); + } + return name(); +} + Output::Type Output::type() const { return d->type;