Commit 6eda92a0 authored by Ismael Asensio's avatar Ismael Asensio

kcm/kwinrules: Detect and suggest activities from a window

Add the activities info to the list of properties provided by
the `queryWindowInfo()` dBus method, and suggest them to the
user when inspecting a given window.

An empty activity list means "All Activities" (null UUID)
Also get the null UUID value instead of having it hardcoded.
parent 8a79f38d
......@@ -208,7 +208,10 @@ QVariantMap clientToVariantMap(const AbstractClient *c)
{QStringLiteral("skipPager"), c->skipPager()},
{QStringLiteral("skipSwitcher"), c->skipSwitcher()},
{QStringLiteral("maximizeHorizontal"), c->maximizeMode() & MaximizeHorizontal},
{QStringLiteral("maximizeVertical"), c->maximizeMode() & MaximizeVertical}
{QStringLiteral("maximizeVertical"), c->maximizeMode() & MaximizeVertical},
#ifdef KWIN_BUILD_ACTIVITIES
{QStringLiteral("activities"), c->activities()},
#endif
};
}
}
......
......@@ -253,6 +253,8 @@ ScrollViewKCM {
case RuleItem.NetTypes:
var selectedValue = value.toString(2).length - 1;
return options.textOfValue(selectedValue);
case RuleItem.OptionList:
return Array.from(value, item => options.textOfValue(item) ).join(", ");
}
return value;
}
......
......@@ -117,18 +117,11 @@ Loader {
Component {
id: optionListEditor
OptionsComboBox {
id: optionListCombo
flat: true
model: ruleOptions
multipleChoice: true
selectionMask: {
let mask = 0
for (let i = 0; i < count; i++) {
if (ruleValue.includes(model.data(model.index(i,0), Qt.UserRole))) {
mask += 1 << i
}
}
return mask
}
onActivated: {
let selectionList = []
for (let i = 0; i < count; i++) {
......@@ -138,6 +131,24 @@ Loader {
}
valueEditor.valueEdited(selectionList);
}
function updateSelectionMask() {
selectionMask = 0
for (let i = 0; i < count; i++) {
if (ruleValue.includes(model.data(model.index(i,0), Qt.UserRole))) {
selectionMask += 1 << i
}
}
}
onModelChanged: updateSelectionMask()
Component.onCompleted: updateSelectionMask()
Connections {
target: valueEditor
function onRuleValueChanged() {
optionListCombo.updateSelectionMask()
}
}
}
}
......
......@@ -7,6 +7,10 @@
#include "rulesmodel.h"
#ifdef KWIN_BUILD_ACTIVITIES
#include "activities.h"
#endif
#include <QFileInfo>
#include <QIcon>
#include <QQmlEngine>
......@@ -686,6 +690,12 @@ void RulesModel::setSuggestedProperties(const QVariantMap &info)
m_rules["wmclass"]->setSuggestedValue(wmsimpleclass);
m_rules["wmclasshelper"]->setSuggestedValue(wmcompleteclass);
#ifdef KWIN_BUILD_ACTIVITIES
const QStringList activities = info.value("activities").toStringList();
m_rules["activity"]->setSuggestedValue(activities.isEmpty() ? QStringList{ Activities::nullUuid() }
: activities);
#endif
const auto ruleForProperty = x11PropertyHash();
for (QString &property : info.keys()) {
if (!ruleForProperty.contains(property)) {
......@@ -739,9 +749,8 @@ QList<OptionsModel::Data> RulesModel::activitiesModelData() const
#ifdef KWIN_BUILD_ACTIVITIES
QList<OptionsModel::Data> modelData;
// NULL_ID from kactivities/src/lib/core/consumer.cpp
modelData << OptionsModel::Data{
QString::fromLatin1("00000000-0000-0000-0000-000000000000"),
Activities::nullUuid(),
i18n("All Activities"),
QIcon::fromTheme("activities")
};
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment