KWinRules KCM Redesign
Summary:
Replacement KCM to configure kwin rules, using a QML-based UI.
After some work on the task T12729, it is almost feature-par with the previous module, and adapted to the recent move to KConfigXT.
Test Plan:
{F8208046}
{F8208047}
Reviewers: #plasma, #kwin, #vdg, ngraham, davidedmundson, zzag
Reviewed By: #plasma, #kwin, #vdg, ngraham, davidedmundson, zzag
Subscribers: ngraham, davidedmundson, hchain, broulik, zzag, kwin
Tags: #kwin, #vdg
Differential Revision: https://phabricator.kde.org/D28152
2020-04-20 20:01:55 +00:00
|
|
|
/*
|
2020-08-02 22:22:19 +00:00
|
|
|
SPDX-FileCopyrightText: 2020 Ismael Asensio <isma.af@gmail.com>
|
|
|
|
|
|
|
|
SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
|
|
|
|
*/
|
KWinRules KCM Redesign
Summary:
Replacement KCM to configure kwin rules, using a QML-based UI.
After some work on the task T12729, it is almost feature-par with the previous module, and adapted to the recent move to KConfigXT.
Test Plan:
{F8208046}
{F8208047}
Reviewers: #plasma, #kwin, #vdg, ngraham, davidedmundson, zzag
Reviewed By: #plasma, #kwin, #vdg, ngraham, davidedmundson, zzag
Subscribers: ngraham, davidedmundson, hchain, broulik, zzag, kwin
Tags: #kwin, #vdg
Differential Revision: https://phabricator.kde.org/D28152
2020-04-20 20:01:55 +00:00
|
|
|
|
|
|
|
#include "ruleitem.h"
|
|
|
|
|
|
|
|
|
|
|
|
namespace KWin
|
|
|
|
{
|
|
|
|
|
|
|
|
RuleItem::RuleItem(const QString &key,
|
|
|
|
const RulePolicy::Type policyType,
|
|
|
|
const RuleItem::Type type,
|
|
|
|
const QString &name,
|
|
|
|
const QString §ion,
|
|
|
|
const QIcon &icon,
|
|
|
|
const QString &description)
|
|
|
|
: m_key(key)
|
|
|
|
, m_type(type)
|
|
|
|
, m_name(name)
|
|
|
|
, m_section(section)
|
|
|
|
, m_icon(icon)
|
|
|
|
, m_description(description)
|
|
|
|
, m_flags(NoFlags)
|
|
|
|
, m_enabled(false)
|
|
|
|
, m_policy(new RulePolicy(policyType))
|
|
|
|
, m_options(nullptr)
|
2020-06-24 17:38:30 +00:00
|
|
|
, m_optionsMask(0U - 1)
|
KWinRules KCM Redesign
Summary:
Replacement KCM to configure kwin rules, using a QML-based UI.
After some work on the task T12729, it is almost feature-par with the previous module, and adapted to the recent move to KConfigXT.
Test Plan:
{F8208046}
{F8208047}
Reviewers: #plasma, #kwin, #vdg, ngraham, davidedmundson, zzag
Reviewed By: #plasma, #kwin, #vdg, ngraham, davidedmundson, zzag
Subscribers: ngraham, davidedmundson, hchain, broulik, zzag, kwin
Tags: #kwin, #vdg
Differential Revision: https://phabricator.kde.org/D28152
2020-04-20 20:01:55 +00:00
|
|
|
{
|
|
|
|
reset();
|
|
|
|
}
|
|
|
|
|
|
|
|
RuleItem::~RuleItem()
|
|
|
|
{
|
|
|
|
delete m_policy;
|
|
|
|
delete m_options;
|
|
|
|
}
|
|
|
|
|
|
|
|
void RuleItem::reset()
|
|
|
|
{
|
|
|
|
m_enabled = hasFlag(AlwaysEnabled) | hasFlag(StartEnabled);
|
2020-06-24 17:38:30 +00:00
|
|
|
m_value = typedValue(QVariant());
|
KWinRules KCM Redesign
Summary:
Replacement KCM to configure kwin rules, using a QML-based UI.
After some work on the task T12729, it is almost feature-par with the previous module, and adapted to the recent move to KConfigXT.
Test Plan:
{F8208046}
{F8208047}
Reviewers: #plasma, #kwin, #vdg, ngraham, davidedmundson, zzag
Reviewed By: #plasma, #kwin, #vdg, ngraham, davidedmundson, zzag
Subscribers: ngraham, davidedmundson, hchain, broulik, zzag, kwin
Tags: #kwin, #vdg
Differential Revision: https://phabricator.kde.org/D28152
2020-04-20 20:01:55 +00:00
|
|
|
m_suggestedValue = QVariant();
|
|
|
|
m_policy->resetValue();
|
|
|
|
if (m_options) {
|
|
|
|
m_options->resetValue();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
QString RuleItem::key() const
|
|
|
|
{
|
|
|
|
return m_key;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString RuleItem::name() const
|
|
|
|
{
|
|
|
|
return m_name;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString RuleItem::section() const
|
|
|
|
{
|
|
|
|
return m_section;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString RuleItem::iconName() const
|
|
|
|
{
|
|
|
|
return m_icon.name();
|
|
|
|
}
|
|
|
|
|
|
|
|
QIcon RuleItem::icon() const
|
|
|
|
{
|
|
|
|
return m_icon;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString RuleItem::description() const
|
|
|
|
{
|
|
|
|
return m_description;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool RuleItem::isEnabled() const
|
|
|
|
{
|
|
|
|
return m_enabled;
|
|
|
|
}
|
|
|
|
|
|
|
|
void RuleItem::setEnabled(bool enabled)
|
|
|
|
{
|
[kcm/kwinrules] Detect also window complete class
Summary:
When detecting the properties of a window, now it shows and lets the user select the window complete class.
If this property is selected in the overlay, `Window class` takes the whole class value, and the option `Match window whole class` is set.
This adds back a feature the old kcm was offering.
BUG: 421542
FIXED-IN: 5.20
Test Plan:
- `Detect window properties` and pick a firefox window
- The property selector shows: `Window class: navigator` and `Whole window class: navigator firefox`
- Selecting the latter set the properties as per summary
{F8334118}
Reviewers: ngraham, #kwin, #plasma, meven
Reviewed By: ngraham, #kwin, #plasma, meven
Subscribers: broulik, davidedmundson, meven, anthonyfieroni, zzag, kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D29791
2020-05-28 21:41:39 +00:00
|
|
|
m_enabled = (enabled && !hasFlag(SuggestionOnly)) || hasFlag(AlwaysEnabled);
|
KWinRules KCM Redesign
Summary:
Replacement KCM to configure kwin rules, using a QML-based UI.
After some work on the task T12729, it is almost feature-par with the previous module, and adapted to the recent move to KConfigXT.
Test Plan:
{F8208046}
{F8208047}
Reviewers: #plasma, #kwin, #vdg, ngraham, davidedmundson, zzag
Reviewed By: #plasma, #kwin, #vdg, ngraham, davidedmundson, zzag
Subscribers: ngraham, davidedmundson, hchain, broulik, zzag, kwin
Tags: #kwin, #vdg
Differential Revision: https://phabricator.kde.org/D28152
2020-04-20 20:01:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool RuleItem::hasFlag(RuleItem::Flags flag) const
|
|
|
|
{
|
|
|
|
return m_flags.testFlag(flag);
|
|
|
|
}
|
|
|
|
|
|
|
|
void RuleItem::setFlag(RuleItem::Flags flag, bool active)
|
|
|
|
{
|
|
|
|
m_flags.setFlag(flag, active);
|
|
|
|
}
|
|
|
|
|
|
|
|
RuleItem::Type RuleItem::type() const
|
|
|
|
{
|
|
|
|
return m_type;
|
|
|
|
}
|
|
|
|
|
|
|
|
QVariant RuleItem::value() const
|
|
|
|
{
|
2020-05-17 01:34:21 +00:00
|
|
|
if (m_options && m_type == Option) {
|
KWinRules KCM Redesign
Summary:
Replacement KCM to configure kwin rules, using a QML-based UI.
After some work on the task T12729, it is almost feature-par with the previous module, and adapted to the recent move to KConfigXT.
Test Plan:
{F8208046}
{F8208047}
Reviewers: #plasma, #kwin, #vdg, ngraham, davidedmundson, zzag
Reviewed By: #plasma, #kwin, #vdg, ngraham, davidedmundson, zzag
Subscribers: ngraham, davidedmundson, hchain, broulik, zzag, kwin
Tags: #kwin, #vdg
Differential Revision: https://phabricator.kde.org/D28152
2020-04-20 20:01:55 +00:00
|
|
|
return m_options->value();
|
|
|
|
}
|
|
|
|
return m_value;
|
|
|
|
}
|
|
|
|
|
|
|
|
void RuleItem::setValue(QVariant value)
|
|
|
|
{
|
2020-05-17 01:34:21 +00:00
|
|
|
if (m_options && m_type == Option) {
|
KWinRules KCM Redesign
Summary:
Replacement KCM to configure kwin rules, using a QML-based UI.
After some work on the task T12729, it is almost feature-par with the previous module, and adapted to the recent move to KConfigXT.
Test Plan:
{F8208046}
{F8208047}
Reviewers: #plasma, #kwin, #vdg, ngraham, davidedmundson, zzag
Reviewed By: #plasma, #kwin, #vdg, ngraham, davidedmundson, zzag
Subscribers: ngraham, davidedmundson, hchain, broulik, zzag, kwin
Tags: #kwin, #vdg
Differential Revision: https://phabricator.kde.org/D28152
2020-04-20 20:01:55 +00:00
|
|
|
m_options->setValue(value);
|
|
|
|
}
|
2020-06-24 17:38:30 +00:00
|
|
|
m_value = typedValue(value);
|
KWinRules KCM Redesign
Summary:
Replacement KCM to configure kwin rules, using a QML-based UI.
After some work on the task T12729, it is almost feature-par with the previous module, and adapted to the recent move to KConfigXT.
Test Plan:
{F8208046}
{F8208047}
Reviewers: #plasma, #kwin, #vdg, ngraham, davidedmundson, zzag
Reviewed By: #plasma, #kwin, #vdg, ngraham, davidedmundson, zzag
Subscribers: ngraham, davidedmundson, hchain, broulik, zzag, kwin
Tags: #kwin, #vdg
Differential Revision: https://phabricator.kde.org/D28152
2020-04-20 20:01:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QVariant RuleItem::suggestedValue() const
|
|
|
|
{
|
|
|
|
return m_suggestedValue;
|
|
|
|
}
|
|
|
|
|
2020-10-27 20:57:02 +00:00
|
|
|
void RuleItem::setSuggestedValue(QVariant value)
|
KWinRules KCM Redesign
Summary:
Replacement KCM to configure kwin rules, using a QML-based UI.
After some work on the task T12729, it is almost feature-par with the previous module, and adapted to the recent move to KConfigXT.
Test Plan:
{F8208046}
{F8208047}
Reviewers: #plasma, #kwin, #vdg, ngraham, davidedmundson, zzag
Reviewed By: #plasma, #kwin, #vdg, ngraham, davidedmundson, zzag
Subscribers: ngraham, davidedmundson, hchain, broulik, zzag, kwin
Tags: #kwin, #vdg
Differential Revision: https://phabricator.kde.org/D28152
2020-04-20 20:01:55 +00:00
|
|
|
{
|
2020-06-24 17:38:30 +00:00
|
|
|
m_suggestedValue = value.isNull() ? QVariant() : typedValue(value);
|
KWinRules KCM Redesign
Summary:
Replacement KCM to configure kwin rules, using a QML-based UI.
After some work on the task T12729, it is almost feature-par with the previous module, and adapted to the recent move to KConfigXT.
Test Plan:
{F8208046}
{F8208047}
Reviewers: #plasma, #kwin, #vdg, ngraham, davidedmundson, zzag
Reviewed By: #plasma, #kwin, #vdg, ngraham, davidedmundson, zzag
Subscribers: ngraham, davidedmundson, hchain, broulik, zzag, kwin
Tags: #kwin, #vdg
Differential Revision: https://phabricator.kde.org/D28152
2020-04-20 20:01:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QVariant RuleItem::options() const
|
|
|
|
{
|
|
|
|
if (!m_options) {
|
|
|
|
return QVariant();
|
|
|
|
}
|
|
|
|
return QVariant::fromValue(m_options);
|
|
|
|
}
|
|
|
|
|
|
|
|
void RuleItem::setOptionsData(const QList<OptionsModel::Data> &data)
|
|
|
|
{
|
2020-12-26 18:24:34 +00:00
|
|
|
if (m_type != Option && m_type != OptionList && m_type != NetTypes) {
|
|
|
|
return;
|
|
|
|
}
|
KWinRules KCM Redesign
Summary:
Replacement KCM to configure kwin rules, using a QML-based UI.
After some work on the task T12729, it is almost feature-par with the previous module, and adapted to the recent move to KConfigXT.
Test Plan:
{F8208046}
{F8208047}
Reviewers: #plasma, #kwin, #vdg, ngraham, davidedmundson, zzag
Reviewed By: #plasma, #kwin, #vdg, ngraham, davidedmundson, zzag
Subscribers: ngraham, davidedmundson, hchain, broulik, zzag, kwin
Tags: #kwin, #vdg
Differential Revision: https://phabricator.kde.org/D28152
2020-04-20 20:01:55 +00:00
|
|
|
if (!m_options) {
|
|
|
|
m_options = new OptionsModel();
|
|
|
|
}
|
|
|
|
m_options->updateModelData(data);
|
|
|
|
m_options->setValue(m_value);
|
2020-06-24 17:38:30 +00:00
|
|
|
|
|
|
|
if (m_type == NetTypes) {
|
|
|
|
m_optionsMask = 0;
|
|
|
|
for (const OptionsModel::Data &dataItem : data) {
|
|
|
|
m_optionsMask += 1 << dataItem.value.toUInt();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
uint RuleItem::optionsMask() const
|
|
|
|
{
|
|
|
|
return m_optionsMask;
|
KWinRules KCM Redesign
Summary:
Replacement KCM to configure kwin rules, using a QML-based UI.
After some work on the task T12729, it is almost feature-par with the previous module, and adapted to the recent move to KConfigXT.
Test Plan:
{F8208046}
{F8208047}
Reviewers: #plasma, #kwin, #vdg, ngraham, davidedmundson, zzag
Reviewed By: #plasma, #kwin, #vdg, ngraham, davidedmundson, zzag
Subscribers: ngraham, davidedmundson, hchain, broulik, zzag, kwin
Tags: #kwin, #vdg
Differential Revision: https://phabricator.kde.org/D28152
2020-04-20 20:01:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int RuleItem::policy() const
|
|
|
|
{
|
|
|
|
return m_policy->value();
|
|
|
|
}
|
|
|
|
|
|
|
|
void RuleItem::setPolicy(int policy)
|
|
|
|
{
|
|
|
|
m_policy->setValue(policy);
|
|
|
|
}
|
|
|
|
|
|
|
|
RulePolicy::Type RuleItem::policyType() const
|
|
|
|
{
|
|
|
|
return m_policy->type();
|
|
|
|
}
|
|
|
|
|
|
|
|
QVariant RuleItem::policyModel() const
|
|
|
|
{
|
|
|
|
return QVariant::fromValue(m_policy);
|
|
|
|
}
|
|
|
|
|
|
|
|
QString RuleItem::policyKey() const
|
|
|
|
{
|
|
|
|
return m_policy->policyKey(m_key);
|
|
|
|
}
|
|
|
|
|
2020-06-24 17:38:30 +00:00
|
|
|
QVariant RuleItem::typedValue(const QVariant &value) const
|
KWinRules KCM Redesign
Summary:
Replacement KCM to configure kwin rules, using a QML-based UI.
After some work on the task T12729, it is almost feature-par with the previous module, and adapted to the recent move to KConfigXT.
Test Plan:
{F8208046}
{F8208047}
Reviewers: #plasma, #kwin, #vdg, ngraham, davidedmundson, zzag
Reviewed By: #plasma, #kwin, #vdg, ngraham, davidedmundson, zzag
Subscribers: ngraham, davidedmundson, hchain, broulik, zzag, kwin
Tags: #kwin, #vdg
Differential Revision: https://phabricator.kde.org/D28152
2020-04-20 20:01:55 +00:00
|
|
|
{
|
2020-06-24 17:38:30 +00:00
|
|
|
switch (type()) {
|
KWinRules KCM Redesign
Summary:
Replacement KCM to configure kwin rules, using a QML-based UI.
After some work on the task T12729, it is almost feature-par with the previous module, and adapted to the recent move to KConfigXT.
Test Plan:
{F8208046}
{F8208047}
Reviewers: #plasma, #kwin, #vdg, ngraham, davidedmundson, zzag
Reviewed By: #plasma, #kwin, #vdg, ngraham, davidedmundson, zzag
Subscribers: ngraham, davidedmundson, hchain, broulik, zzag, kwin
Tags: #kwin, #vdg
Differential Revision: https://phabricator.kde.org/D28152
2020-04-20 20:01:55 +00:00
|
|
|
case Undefined:
|
|
|
|
case Option:
|
|
|
|
return value;
|
|
|
|
case Boolean:
|
|
|
|
return value.toBool();
|
|
|
|
case Integer:
|
|
|
|
case Percentage:
|
|
|
|
return value.toInt();
|
2020-06-19 18:56:12 +00:00
|
|
|
case NetTypes: {
|
2020-06-24 17:38:30 +00:00
|
|
|
const uint typesMask = value.toUInt() & optionsMask(); // filter by the allowed mask in the model
|
|
|
|
if (typesMask == 0 || typesMask == optionsMask()) { // if no types or all of them are selected
|
|
|
|
return 0U - 1; // return an all active mask (NET:AllTypesMask)
|
KWinRules KCM Redesign
Summary:
Replacement KCM to configure kwin rules, using a QML-based UI.
After some work on the task T12729, it is almost feature-par with the previous module, and adapted to the recent move to KConfigXT.
Test Plan:
{F8208046}
{F8208047}
Reviewers: #plasma, #kwin, #vdg, ngraham, davidedmundson, zzag
Reviewed By: #plasma, #kwin, #vdg, ngraham, davidedmundson, zzag
Subscribers: ngraham, davidedmundson, hchain, broulik, zzag, kwin
Tags: #kwin, #vdg
Differential Revision: https://phabricator.kde.org/D28152
2020-04-20 20:01:55 +00:00
|
|
|
}
|
2020-06-24 17:38:30 +00:00
|
|
|
return typesMask;
|
2020-06-19 18:56:12 +00:00
|
|
|
}
|
2020-10-22 12:35:14 +00:00
|
|
|
case Point: {
|
|
|
|
const QPoint point = value.toPoint();
|
|
|
|
return (point == invalidPoint) ? QPoint(0, 0) : point;
|
|
|
|
}
|
[kcm/kwinrules] Fix size properties not being stored
Summary:
Use `QSize`/`QPoint` to handle and store coordinate values (size and position)
Previously, the rules model stored the "coordinate" type properties as a
`QString` with format `x, y`.
This fails when setting the properties to the config schema, as it requires
a proper `QPoint` or `QSize` value, specially the latter which can't be
convert from such a string.
BUG: 421055
FIXED-IN: 5.19.0
Test Plan:
- Add a new rule and set its position and size properties
- Hitting apply stores the right values in `~\.config\kwinrulesrc`
- Close the kcm and reopen, the values are loaded
- Property detection still works for size and position
Please note that there is a pre-existing bug of some position/sizes not being
applied to the windows in some cases, when using `Apply Initially`.
Better try using the `Force` policy.
Reviewers: ngraham, #kwin, #plasma, zzag
Reviewed By: #kwin, #plasma, zzag
Subscribers: zzag, ltoscano, yurchor, kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D29764
2020-05-14 20:46:15 +00:00
|
|
|
case Size:
|
|
|
|
return value.toSize();
|
KWinRules KCM Redesign
Summary:
Replacement KCM to configure kwin rules, using a QML-based UI.
After some work on the task T12729, it is almost feature-par with the previous module, and adapted to the recent move to KConfigXT.
Test Plan:
{F8208046}
{F8208047}
Reviewers: #plasma, #kwin, #vdg, ngraham, davidedmundson, zzag
Reviewed By: #plasma, #kwin, #vdg, ngraham, davidedmundson, zzag
Subscribers: ngraham, davidedmundson, hchain, broulik, zzag, kwin
Tags: #kwin, #vdg
Differential Revision: https://phabricator.kde.org/D28152
2020-04-20 20:01:55 +00:00
|
|
|
case String:
|
|
|
|
return value.toString().trimmed();
|
|
|
|
case Shortcut:
|
|
|
|
return value.toString();
|
2020-12-26 18:24:34 +00:00
|
|
|
case OptionList:
|
|
|
|
return value.toStringList();
|
KWinRules KCM Redesign
Summary:
Replacement KCM to configure kwin rules, using a QML-based UI.
After some work on the task T12729, it is almost feature-par with the previous module, and adapted to the recent move to KConfigXT.
Test Plan:
{F8208046}
{F8208047}
Reviewers: #plasma, #kwin, #vdg, ngraham, davidedmundson, zzag
Reviewed By: #plasma, #kwin, #vdg, ngraham, davidedmundson, zzag
Subscribers: ngraham, davidedmundson, hchain, broulik, zzag, kwin
Tags: #kwin, #vdg
Differential Revision: https://phabricator.kde.org/D28152
2020-04-20 20:01:55 +00:00
|
|
|
}
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
} //namespace
|
|
|
|
|