From 5963790b21ae9bfd10e425a3d0cf3f14fad14251 Mon Sep 17 00:00:00 2001 From: Vlad Zahorodnii Date: Mon, 16 Jan 2023 13:20:48 +0200 Subject: [PATCH] kcms/rules: Use window class and role with original casing The window rules kcm uses lower-case window class and role, but kwin can use window class and role with other casing, which will break the ExactMatch match rule. BUG: 464190 --- src/kcms/rules/kcmrules.cpp | 12 ++++++------ src/rules.cpp | 14 +++++++------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/kcms/rules/kcmrules.cpp b/src/kcms/rules/kcmrules.cpp index 49f4de9da2..d99e640a64 100644 --- a/src/kcms/rules/kcmrules.cpp +++ b/src/kcms/rules/kcmrules.cpp @@ -324,9 +324,9 @@ void KCMKWinRules::importFromFile(const QUrl &path) // Code adapted from original `findRule()` method in `kwin_rules_dialog::main.cpp` QModelIndex KCMKWinRules::findRuleWithProperties(const QVariantMap &info, bool wholeApp) const { - const QString wmclass_class = info.value("resourceClass").toString().toLower(); - const QString wmclass_name = info.value("resourceName").toString().toLower(); - const QString role = info.value("role").toString().toLower(); + const QString wmclass_class = info.value("resourceClass").toString(); + const QString wmclass_name = info.value("resourceName").toString(); + const QString role = info.value("role").toString(); const NET::WindowType type = static_cast(info.value("type").toInt()); const QString title = info.value("caption").toString(); const QString machine = info.value("clientMachine").toString(); @@ -409,9 +409,9 @@ QModelIndex KCMKWinRules::findRuleWithProperties(const QVariantMap &info, bool w // Code adapted from original `findRule()` method in `kwin_rules_dialog::main.cpp` void KCMKWinRules::fillSettingsFromProperties(RuleSettings *settings, const QVariantMap &info, bool wholeApp) const { - const QString wmclass_class = info.value("resourceClass").toString().toLower(); - const QString wmclass_name = info.value("resourceName").toString().toLower(); - const QString role = info.value("role").toString().toLower(); + const QString wmclass_class = info.value("resourceClass").toString(); + const QString wmclass_name = info.value("resourceName").toString(); + const QString role = info.value("role").toString(); const NET::WindowType type = static_cast(info.value("type").toInt()); const QString title = info.value("caption").toString(); const QString machine = info.value("clientMachine").toString(); diff --git a/src/rules.cpp b/src/rules.cpp index a441f2a851..02680ed8eb 100644 --- a/src/rules.cpp +++ b/src/rules.cpp @@ -120,9 +120,9 @@ void Rules::readFromSettings(const RuleSettings *settings) if (description.isEmpty()) { description = settings->descriptionLegacy(); } - READ_MATCH_STRING(wmclass, .toLower()); + READ_MATCH_STRING(wmclass, ); wmclasscomplete = settings->wmclasscomplete(); - READ_MATCH_STRING(windowrole, .toLower()); + READ_MATCH_STRING(windowrole, ); READ_MATCH_STRING(title, ); READ_MATCH_STRING(clientmachine, .toLower()); types = NET::WindowTypeMask(settings->types()); @@ -345,10 +345,10 @@ bool Rules::matchWMClass(const QString &match_class, const QString &match_name) if (wmclassmatch == RegExpMatch && !QRegularExpression(wmclass).match(cwmclass).hasMatch()) { return false; } - if (wmclassmatch == ExactMatch && wmclass != cwmclass) { + if (wmclassmatch == ExactMatch && cwmclass.compare(wmclass, Qt::CaseInsensitive) != 0) { // TODO Plasma 6: Make it case sensitive return false; } - if (wmclassmatch == SubstringMatch && !cwmclass.contains(wmclass)) { + if (wmclassmatch == SubstringMatch && !cwmclass.contains(wmclass, Qt::CaseInsensitive)) { // TODO Plasma 6: Make it case sensitive return false; } } @@ -361,10 +361,10 @@ bool Rules::matchRole(const QString &match_role) const if (windowrolematch == RegExpMatch && !QRegularExpression(windowrole).match(match_role).hasMatch()) { return false; } - if (windowrolematch == ExactMatch && windowrole != match_role) { + if (windowrolematch == ExactMatch && match_role.compare(windowrole, Qt::CaseInsensitive) != 0) { // TODO Plasma 6: Make it case sensitive return false; } - if (windowrolematch == SubstringMatch && !match_role.contains(windowrole)) { + if (windowrolematch == SubstringMatch && !match_role.contains(windowrole, Qt::CaseInsensitive)) { // TODO Plasma 6: Make it case sensitive return false; } } @@ -420,7 +420,7 @@ bool Rules::match(const Window *c) const if (!matchWMClass(c->resourceClass(), c->resourceName())) { return false; } - if (!matchRole(c->windowRole().toLower())) { + if (!matchRole(c->windowRole())) { return false; } if (!matchClientMachine(c->clientMachine()->hostName(), c->clientMachine()->isLocal())) {