From e8545fdb37a490cb702703865100ec9f1a12b0e9 Mon Sep 17 00:00:00 2001 From: Ismael Asensio Date: Mon, 5 Dec 2022 22:56:53 +0100 Subject: [PATCH] kcms/rules: Notify when a window does not provide a class Some applications do not provide a window class according to the spec (WM_CLASS on X11, appId on Wayland), so KWin cannot "detect" this property. In those cases, notify the user that this is a bug within the application (so it is not confused for a KWin misbehavior) and also prevent setting a wrong description. BUG: 462644 FIXED-IN: 5.27 --- src/kcmkwin/kwinrules/kcmrules.cpp | 8 ++++++-- src/kcmkwin/kwinrules/rulesmodel.cpp | 11 +++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/kcmkwin/kwinrules/kcmrules.cpp b/src/kcmkwin/kwinrules/kcmrules.cpp index 6610ca5931..49f4de9da2 100644 --- a/src/kcmkwin/kwinrules/kcmrules.cpp +++ b/src/kcmkwin/kwinrules/kcmrules.cpp @@ -419,7 +419,9 @@ void KCMKWinRules::fillSettingsFromProperties(RuleSettings *settings, const QVar settings->setDefaults(); if (wholeApp) { - settings->setDescription(i18n("Application settings for %1", wmclass_class)); + if (!wmclass_class.isEmpty()) { + settings->setDescription(i18n("Application settings for %1", wmclass_class)); + } // TODO maybe exclude some types? If yes, then also exclude them when searching. settings->setTypes(NET::AllTypesMask); settings->setTitlematch(Rules::UnimportantMatch); @@ -439,7 +441,9 @@ void KCMKWinRules::fillSettingsFromProperties(RuleSettings *settings, const QVar return; } - settings->setDescription(i18n("Window settings for %1", wmclass_class)); + if (!wmclass_class.isEmpty()) { + settings->setDescription(i18n("Window settings for %1", wmclass_class)); + } if (type == NET::Unknown) { settings->setTypes(NET::NormalMask); } else { diff --git a/src/kcmkwin/kwinrules/rulesmodel.cpp b/src/kcmkwin/kwinrules/rulesmodel.cpp index 78894fa665..4d823784d9 100644 --- a/src/kcmkwin/kwinrules/rulesmodel.cpp +++ b/src/kcmkwin/kwinrules/rulesmodel.cpp @@ -697,6 +697,17 @@ void RulesModel::setSuggestedProperties(const QVariantMap &info) const QString wmcompleteclass = QStringLiteral("%1 %2").arg(info.value("resourceName").toString(), info.value("resourceClass").toString()); + // This window is not providing the class according to spec (WM_CLASS on X11, appId on Wayland) + // Notify the user that this is a bug within the application, so there's nothing we can do + if (wmsimpleclass.isEmpty()) { + Q_EMIT showErrorMessage(i18n("Window class not available"), + xi18nc("@info", "This application is not providing a class for the window, " + "so KWin cannot use it to match and apply any rules. " + "If you still want to apply some rules to it, " + "try to match other properties like the window title instead." + "Please consider reporting this bug to the application's developers.")); + } + m_rules["wmclass"]->setSuggestedValue(wmsimpleclass); m_rules["wmclasshelper"]->setSuggestedValue(wmcompleteclass);