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)
master
Natalie Clarius 2 years ago
parent e1e9e89f34
commit 0b2c442196

@ -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,

@ -91,6 +91,7 @@ private:
bool wmclassWarning() const;
bool geometryWarning() const;
bool opacityWarning() const;
static const QHash<QString, QString> x11PropertyHash();
void updateVirtualDesktops();

Loading…
Cancel
Save