[kcm/kwinrules] Fix types property for NET::AllTypesMask

When the user selects all of the types or none of them, the "types"
property must be set to a special value (`NET::AllTypesMask = -1`),
different than the sum of all the flags together.

This re-implements this behaviour as the old KCM, fixing some heuristics
that prevented finding the rule corresponding to the current window.

The enum name that handles this property has been changed to `NetTypes`
to make it more explicit.

BUG: 423214
FIXED-IN: 5.19.3

TEST PLAN:
1. Open the `Application specific settings` on a window via menu
2. Select every "Window Type" (or none of them)
3. Give the rule a different name than the default and save
4. Open it again and check that the same rule is found
This commit is contained in:
Ismael Asensio 2020-06-19 20:56:12 +02:00 committed by Nate Graham
parent 578ede2dd7
commit 8b9472e0bf
5 changed files with 14 additions and 12 deletions

View file

@ -225,7 +225,7 @@ ScrollViewKCM {
return i18nc("Size (width, height)", "(%1, %2)", value.width, value.height); return i18nc("Size (width, height)", "(%1, %2)", value.width, value.height);
case RuleItem.Option: case RuleItem.Option:
return options.textOfValue(value); return options.textOfValue(value);
case RuleItem.FlagsOption: case RuleItem.NetTypes:
var selectedValue = value.toString(2).length - 1; var selectedValue = value.toString(2).length - 1;
return options.textOfValue(selectedValue); return options.textOfValue(selectedValue);
} }

View file

@ -43,7 +43,7 @@ Loader {
case RuleItem.String: return stringEditor case RuleItem.String: return stringEditor
case RuleItem.Integer: return integerEditor case RuleItem.Integer: return integerEditor
case RuleItem.Option: return optionEditor case RuleItem.Option: return optionEditor
case RuleItem.FlagsOption: return flagsEditor case RuleItem.NetTypes: return netTypesEditor
case RuleItem.Percentage: return percentageEditor case RuleItem.Percentage: return percentageEditor
case RuleItem.Point: return coordinateEditor case RuleItem.Point: return coordinateEditor
case RuleItem.Size: return coordinateEditor case RuleItem.Size: return coordinateEditor
@ -113,12 +113,13 @@ Loader {
} }
Component { Component {
id: flagsEditor id: netTypesEditor
OptionsComboBox { OptionsComboBox {
flat: true flat: true
model: ruleOptions model: ruleOptions
multipleChoice: true multipleChoice: true
selectionMask: ruleValue // If NET::AllTypesMask (-1), select everything
selectionMask: (ruleValue == -1) ? 0x3BF : ruleValue
onActivated: { onActivated: {
valueEditor.valueEdited(selectionMask); valueEditor.valueEdited(selectionMask);
} }

View file

@ -157,7 +157,7 @@ QVariant RuleItem::options() const
void RuleItem::setOptionsData(const QList<OptionsModel::Data> &data) void RuleItem::setOptionsData(const QList<OptionsModel::Data> &data)
{ {
if (!m_options) { if (!m_options) {
if (m_type != Option && m_type != FlagsOption) { if (m_type != Option && m_type != NetTypes) {
return; return;
} }
m_options = new OptionsModel(); m_options = new OptionsModel();
@ -202,12 +202,13 @@ QVariant RuleItem::typedValue(const QVariant &value, const RuleItem::Type type)
case Integer: case Integer:
case Percentage: case Percentage:
return value.toInt(); return value.toInt();
case FlagsOption: case NetTypes: {
// HACK: Currently, the only user of this is "types" property const int usefulTypes = value.toInt() & 0x3BF; // remove NET::Override=0x040 (deprecated)
if (value.toInt() == -1) { //NET:AllTypesMask if (usefulTypes == 0 || usefulTypes == 0x3BF) { // if no flags or all of them are selected
return 0x3FF - 0x040; //All possible flags minus NET::Override (deprecated) return -1; // return NET:AllTypesMask
} }
return value.toInt(); return value.toInt();
}
case Point: case Point:
return value.toPoint(); return value.toPoint();
case Size: case Size:

View file

@ -41,7 +41,7 @@ public:
String, String,
Integer, Integer,
Option, Option,
FlagsOption, NetTypes,
Percentage, Percentage,
Point, Point,
Size, Size,

View file

@ -373,7 +373,7 @@ void RulesModel::populateRuleList()
wmclasscomplete->setFlag(RuleItem::AlwaysEnabled); wmclasscomplete->setFlag(RuleItem::AlwaysEnabled);
auto types = addRule(new RuleItem(QLatin1String("types"), auto types = addRule(new RuleItem(QLatin1String("types"),
RulePolicy::NoPolicy, RuleItem::FlagsOption, RulePolicy::NoPolicy, RuleItem::NetTypes,
i18n("Window types"), i18n("Window matching"), i18n("Window types"), i18n("Window matching"),
QIcon::fromTheme("window-duplicate"))); QIcon::fromTheme("window-duplicate")));
types->setOptionsData(windowTypesModelData()); types->setOptionsData(windowTypesModelData());
@ -660,7 +660,7 @@ void RulesModel::setWindowProperties(const QVariantMap &info, bool forceValue)
if (window_type == NET::Unknown) { if (window_type == NET::Unknown) {
window_type = NET::Normal; window_type = NET::Normal;
} }
m_rules["types"]->setSuggestedValue(1 << window_type, forceValue); m_rules["types"]->setSuggestedValue(1 << window_type);
const QString wmsimpleclass = info.value("resourceClass").toString(); const QString wmsimpleclass = info.value("resourceClass").toString();
const QString wmcompleteclass = QStringLiteral("%1 %2").arg(info.value("resourceName").toString(), const QString wmcompleteclass = QStringLiteral("%1 %2").arg(info.value("resourceName").toString(),