From 0b2c442196b7f3099afad947177810433eb1d38b Mon Sep 17 00:00:00 2001 From: Natalie Clarius Date: Thu, 9 Feb 2023 21:36:24 +0000 Subject: [PATCH] kcms/rules: add warning for low opacity Once upon a time, in a moment of acute stupidity, I accidentally created a window rule making all windows completely transparent. I meant to go for 0% transparency when really the slider said 0% opacity. And once you've made the very window to change this setting invisible, the only way to fix that mistake is to log into a TTY or different DE and find the config file to edit manually. Since I've since seen several KRedditors fall into the same trap: Show a warning when active or inactive opacity is set to ~~<= 15%~~ < 25%. ![warning](/uploads/0b1178bf5782bff3b4293a0031bb4fca/warning.png) --- src/kcms/rules/rulesmodel.cpp | 38 ++++++++++++++++++++++++++--------- src/kcms/rules/rulesmodel.h | 1 + 2 files changed, 30 insertions(+), 9 deletions(-) diff --git a/src/kcms/rules/rulesmodel.cpp b/src/kcms/rules/rulesmodel.cpp index 4d823784d9..99328afffa 100644 --- a/src/kcms/rules/rulesmodel.cpp +++ b/src/kcms/rules/rulesmodel.cpp @@ -247,6 +247,10 @@ QStringList RulesModel::warningMessages() const m_rules["ignoregeometry"]->name()); } + if (opacityWarning()) { + messages << i18n("Readability may be impaired with extremely low opacity values. At 0%, the window becomes invisible."); + } + return messages; } @@ -282,6 +286,21 @@ bool RulesModel::geometryWarning() const return (!ignoregeometry && (initialPos || initialSize || initialPlacement)); } +bool RulesModel::opacityWarning() const +{ + auto opacityActive = m_rules["opacityactive"]; + const bool lowOpacityActive = opacityActive->isEnabled() + && opacityActive->policy() != Rules::Unused && opacityActive->policy() != Rules::DontAffect + && opacityActive->value().toInt() < 25; + + auto opacityInactive = m_rules["opacityinactive"]; + const bool lowOpacityInactive = opacityInactive->isEnabled() + && opacityActive->policy() != Rules::Unused && opacityActive->policy() != Rules::DontAffect + && opacityInactive->value().toInt() < 25; + + return lowOpacityActive || lowOpacityInactive; +} + RuleSettings *RulesModel::settings() const { return m_settings; @@ -577,15 +596,16 @@ void RulesModel::populateRuleList() QIcon::fromTheme("preferences-desktop-theme"))); decocolor->setOptionsData(colorSchemesModelData()); - addRule(new RuleItem(QLatin1String("opacityactive"), - RulePolicy::ForceRule, RuleItem::Percentage, - i18n("Active opacity"), i18n("Appearance & Fixes"), - QIcon::fromTheme("edit-opacity"))); - - addRule(new RuleItem(QLatin1String("opacityinactive"), - RulePolicy::ForceRule, RuleItem::Percentage, - i18n("Inactive opacity"), i18n("Appearance & Fixes"), - QIcon::fromTheme("edit-opacity"))); + auto opacityactive = addRule(new RuleItem(QLatin1String("opacityactive"), + RulePolicy::ForceRule, RuleItem::Percentage, + i18n("Active opacity"), i18n("Appearance & Fixes"), + QIcon::fromTheme("edit-opacity"))); + opacityactive->setFlag(RuleItem::AffectsWarning); + auto opacityinactive = addRule(new RuleItem(QLatin1String("opacityinactive"), + RulePolicy::ForceRule, RuleItem::Percentage, + i18n("Inactive opacity"), i18n("Appearance & Fixes"), + QIcon::fromTheme("edit-opacity"))); + opacityinactive->setFlag(RuleItem::AffectsWarning); auto fsplevel = addRule(new RuleItem(QLatin1String("fsplevel"), RulePolicy::ForceRule, RuleItem::Option, diff --git a/src/kcms/rules/rulesmodel.h b/src/kcms/rules/rulesmodel.h index ad700309f9..4900af47ee 100644 --- a/src/kcms/rules/rulesmodel.h +++ b/src/kcms/rules/rulesmodel.h @@ -91,6 +91,7 @@ private: bool wmclassWarning() const; bool geometryWarning() const; + bool opacityWarning() const; static const QHash x11PropertyHash(); void updateVirtualDesktops();