[plasma/kwin/Plasma/6.6] src/kcms/common: kcms/effects: Take into account system-wide defaults
Nate Graham <[email protected]>
| Newsgroups | gmane.comp.kde.cvs |
|---|---|
| Message-ID | <[email protected]> |
Git commit 0b064a9d4f3441cc85fdeeefc73b2cd3162ee081 by Nate Graham. Committed on 17/07/2026 at 15:03. Pushed by ngraham into branch 'Plasma/6.6'. kcms/effects: Take into account system-wide defaults It's possible to provide system-wide default values in /etc/xdg/kwinrc We need to take these into account when writing values and handling the defaults button. When writing a value that matches the system-wide default, use revertToDefault(). When pressing the defaults button, reset to the system-wide default (cherry picked from commit ed1ee4fda4deae010624bf01efa5b7a44669d7cb) Co-authored-by: Nicolas Fella <[email protected]> M +52 -10 src/kcms/common/effectsmodel.cpp M +2 -0 src/kcms/common/effectsmodel.h https://invent.kde.org/plasma/kwin/-/commit/0b064a9d4f3441cc85fdeeefc73b2cd3162ee081 diff --git a/src/kcms/common/effectsmodel.cpp b/src/kcms/common/effectsmodel.cpp index cf0d089f935..f2767ea1b61 100644 --- a/src/kcms/common/effectsmodel.cpp +++ b/src/kcms/common/effectsmodel.cpp @@ -70,6 +70,7 @@ static EffectsModel::Status effectStatus(bool enabled) EffectsModel::EffectsModel(QObject *parent) : QAbstractItemModel(parent) + , m_config(KSharedConfig::openConfig("kwinrc")) { } @@ -376,7 +377,7 @@ void EffectsModel::loadPluginEffects(const KConfigGroup &kwinConfig) void EffectsModel::load(LoadOptions options) { - KConfigGroup kwinConfig(KSharedConfig::openConfig("kwinrc"), QStringLiteral("Plugins")); + KConfigGroup kwinConfig(m_config, QStringLiteral("Plugins")); m_pendingEffects.clear(); loadBuiltInEffects(kwinConfig); @@ -476,6 +477,14 @@ void EffectsModel::load(LoadOptions options) } } +bool EffectsModel::isEnabledSystemWide(KConfigGroup &config, const QString &key) const +{ + config.config()->setReadDefaults(true); + const bool enabled = config.readEntry(key, false); + config.config()->setReadDefaults(false); + return enabled; +} + void EffectsModel::setExcludeExclusiveGroups(const QStringList &exclusiveGroups) { m_excludeExclusiveGroups = exclusiveGroups; @@ -493,7 +502,7 @@ void EffectsModel::updateEffectStatus(const QModelIndex &rowIndex, Status effect void EffectsModel::save() { - KConfigGroup kwinConfig(KSharedConfig::openConfig("kwinrc"), QStringLiteral("Plugins")); + KConfigGroup kwinConfig(m_config, QStringLiteral("Plugins")); for (EffectData &effect : m_effects) { if (!effect.changed) { @@ -505,13 +514,24 @@ void EffectsModel::save() const QString key = effect.serviceName + QStringLiteral("Enabled"); const bool shouldEnable = (effect.status != Status::Disabled); - const bool restoreToDefault = effect.enabledByDefaultFunction - ? effect.status == Status::EnabledUndeterminded - : shouldEnable == effect.enabledByDefault; - if (restoreToDefault) { - kwinConfig.deleteEntry(key, KConfig::Notify); + if (kwinConfig.hasDefault(key)) { + if (shouldEnable == isEnabledSystemWide(kwinConfig, key)) { + kwinConfig.revertToDefault(key, KConfig::Notify); + } else { + kwinConfig.writeEntry(key, shouldEnable, KConfig::Notify); + } + } else if (effect.enabledByDefaultFunction) { + if (effect.status == Status::EnabledUndeterminded) { + kwinConfig.revertToDefault(key, KConfig::Notify); + } else { + kwinConfig.writeEntry(key, shouldEnable, KConfig::Notify); + } } else { - kwinConfig.writeEntry(key, shouldEnable, KConfig::Notify); + if (shouldEnable == effect.enabledByDefault) { + kwinConfig.revertToDefault(key, KConfig::Notify); + } else { + kwinConfig.writeEntry(key, shouldEnable, KConfig::Notify); + } } } @@ -521,7 +541,13 @@ void EffectsModel::save() void EffectsModel::defaults(const QModelIndex &index) { const auto &effect = m_effects.at(index.row()); - if (effect.enabledByDefaultFunction && effect.status != Status::EnabledUndeterminded) { + KConfigGroup kwinConfig(m_config, QStringLiteral("Plugins")); + const QString key = effect.serviceName + "Enabled"; + + if (kwinConfig.hasDefault(key)) { + const bool enabled = isEnabledSystemWide(kwinConfig, key); + updateEffectStatus(index, enabled ? Status::Enabled : Status::Disabled); + } else if (effect.enabledByDefaultFunction && effect.status != Status::EnabledUndeterminded) { updateEffectStatus(index, Status::EnabledUndeterminded); } else if (static_cast<bool>(effect.status) != effect.enabledByDefault) { updateEffectStatus(index, effect.enabledByDefault ? Status::Enabled : Status::Disabled); @@ -538,12 +564,28 @@ void EffectsModel::defaults() bool EffectsModel::isDefaults(const QModelIndex &index) const { const auto &effect = m_effects.at(index.row()); + + KConfigGroup kwinConfig(m_config, QStringLiteral("Plugins")); + const QString enabledKey = QStringLiteral("%1Enabled").arg(effect.serviceName); + if (effect.enabledByDefaultFunction && effect.status != Status::EnabledUndeterminded) { return false; } - if (static_cast<bool>(effect.status) != effect.enabledByDefault) { + + bool enabledByDefault = effect.enabledByDefault; + + if (kwinConfig.hasDefault(enabledKey)) { + enabledByDefault = isEnabledSystemWide(kwinConfig, enabledKey); + } + + if (effect.status == Status::Disabled && enabledByDefault) { return false; } + + if (effect.status == Status::Enabled && !enabledByDefault) { + return false; + } + return true; } diff --git a/src/kcms/common/effectsmodel.h b/src/kcms/common/effectsmodel.h index e3fd1c1dd1e..11c785cdc7b 100644 --- a/src/kcms/common/effectsmodel.h +++ b/src/kcms/common/effectsmodel.h @@ -273,12 +273,14 @@ private: void loadBuiltInEffects(const KConfigGroup &kwinConfig); void loadJavascriptEffects(const KConfigGroup &kwinConfig); void loadPluginEffects(const KConfigGroup &kwinConfig); + bool isEnabledSystemWide(KConfigGroup &config, const QString &key) const; QList<EffectData> m_effects; QList<EffectData> m_pendingEffects; QStringList m_excludeExclusiveGroups; QStringList m_excludeEffects; int m_lastSerial = -1; + KSharedConfig::Ptr m_config; Q_DISABLE_COPY(EffectsModel) };