From ac19d657ae0eeadf068c99c7de7b2e5045955b42 Mon Sep 17 00:00:00 2001 From: Ivailo Monev Date: Thu, 10 Aug 2023 11:28:51 +0300 Subject: [PATCH] kwin: ensure there are no duplicate rules because KStandardDirs::findAllResources() will return local and global rules thus if there is a global and local rule file with the same name there would be duplicates, using KStandardDirs::NoDuplicates flag will not solve that because the rules are merged into the main kwinrulesrc config Signed-off-by: Ivailo Monev --- kwin/rules.cpp | 15 ++++++++++++++- kwin/rules.h | 1 + .../desktop/plasma_desktop_containment.kwinrules | 2 +- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/kwin/rules.cpp b/kwin/rules.cpp index a2c43a18..d651d5b7 100644 --- a/kwin/rules.cpp +++ b/kwin/rules.cpp @@ -134,6 +134,7 @@ static int limit0to4(int i) void Rules::readFromCfg(const KConfigGroup& cfg) { + ruleid = cfg.readEntry("id", QByteArray()); description = cfg.readEntry("Description"); if (description.isEmpty()) // capitalized first, lowercase for backwards compatibility description = cfg.readEntry("description"); @@ -232,6 +233,7 @@ void Rules::readFromCfg(const KConfigGroup& cfg) void Rules::write(KConfigGroup& cfg) const { + cfg.writeEntry("id", ruleid); cfg.writeEntry("Description", description); // always write wmclass WRITE_MATCH_STRING(wmclass, (const char*), true); @@ -972,21 +974,32 @@ void RuleBook::edit(Client* c, bool whole_app) void RuleBook::load() { deleteAll(); + QList ruleids; KConfig cfg("kwinrulesrc", KConfig::NoGlobals); int count = cfg.group("General").readEntry("count", 0); for (int i = 1; i <= count; ++i) { KConfigGroup cg(&cfg, QString::number(i)); + const QByteArray id = cg.readEntry("id", QByteArray()); + if (ruleids.contains(id)) { + continue; + } Rules* rule = new Rules(cg); m_rules.append(rule); + ruleids.append(id); } const QStringList kwinrules = KGlobal::dirs()->findAllResources("data", "kwin/default_rules/*.kwinrules"); foreach (const QString &kwinrule, kwinrules) { KConfig cfg(kwinrule, KConfig::NoGlobals); - int count = cfg.group("General").readEntry("count", 0); + count = cfg.group("General").readEntry("count", 0); for (int i = 1; i <= count; ++i) { KConfigGroup cg(&cfg, QString::number(i)); + const QByteArray id = cg.readEntry("id", QByteArray()); + if (ruleids.contains(id)) { + continue; + } Rules* rule = new Rules(cg); m_rules.append(rule); + ruleids.append(id); } } } diff --git a/kwin/rules.h b/kwin/rules.h index 7b42a422..91a912f0 100644 --- a/kwin/rules.h +++ b/kwin/rules.h @@ -199,6 +199,7 @@ private: static bool checkForceStop(ForceRule rule); #endif int temporary_state; // e.g. for kstart + QByteArray ruleid; QString description; QByteArray wmclass; StringMatch wmclassmatch; diff --git a/plasma/containments/desktop/plasma_desktop_containment.kwinrules b/plasma/containments/desktop/plasma_desktop_containment.kwinrules index c79725b3..ad014e1b 100644 --- a/plasma/containments/desktop/plasma_desktop_containment.kwinrules +++ b/plasma/containments/desktop/plasma_desktop_containment.kwinrules @@ -11,4 +11,4 @@ types=32 wmclass=plasma wmclasscomplete=false wmclassmatch=1 - +id=191497c49c1ad8700a041a08f204df2e6a6a2a97