[kcm/kwinrules] Detect virtual desktops in Wayland
The list of virtual desktops is retrieved using a DBus method, instead of `KWindowSystem`, to make it work both in Wayland (as well as X11). FIXED-IN: 5.20 BUG: 416165master
parent
fdd9ed53d9
commit
bd5e34f5b4
|
@ -11,6 +11,7 @@ set(kwinrules_SRCS
|
|||
../../rules.cpp
|
||||
../../placement.cpp
|
||||
../../utils.cpp
|
||||
../../virtualdesktopsdbustypes.cpp
|
||||
kwinsrc.cpp
|
||||
optionsmodel.cpp
|
||||
ruleitem.cpp
|
||||
|
|
|
@ -119,7 +119,7 @@ RuleItem::Type RuleItem::type() const
|
|||
|
||||
QVariant RuleItem::value() const
|
||||
{
|
||||
if (m_type == Option) {
|
||||
if (m_options && m_type == Option) {
|
||||
return m_options->value();
|
||||
}
|
||||
return m_value;
|
||||
|
@ -127,7 +127,7 @@ QVariant RuleItem::value() const
|
|||
|
||||
void RuleItem::setValue(QVariant value)
|
||||
{
|
||||
if (m_type == Option) {
|
||||
if (m_options && m_type == Option) {
|
||||
m_options->setValue(value);
|
||||
}
|
||||
m_value = typedValue(value, m_type);
|
||||
|
|
|
@ -45,6 +45,9 @@ RulesModel::RulesModel(QObject *parent)
|
|||
qmlRegisterUncreatableType<RulesModel>("org.kde.kcms.kwinrules", 1, 0, "RulesModel",
|
||||
QStringLiteral("Do not create objects of type RulesModel"));
|
||||
|
||||
qDBusRegisterMetaType<KWin::DBusDesktopDataStruct>();
|
||||
qDBusRegisterMetaType<KWin::DBusDesktopDataVector>();
|
||||
|
||||
populateRuleList();
|
||||
}
|
||||
|
||||
|
@ -421,6 +424,10 @@ void RulesModel::populateRuleList()
|
|||
QIcon::fromTheme("virtual-desktops")));
|
||||
desktop->setOptionsData(virtualDesktopsModelData());
|
||||
|
||||
connect(this, &RulesModel::virtualDesktopsUpdated,
|
||||
this, [this] { m_rules["desktop"]->setOptionsData(virtualDesktopsModelData()); });
|
||||
updateVirtualDesktops();
|
||||
|
||||
#ifdef KWIN_BUILD_ACTIVITIES
|
||||
m_activities = new KActivities::Consumer(this);
|
||||
|
||||
|
@ -700,10 +707,10 @@ QList<OptionsModel::Data> RulesModel::windowTypesModelData() const
|
|||
QList<OptionsModel::Data> RulesModel::virtualDesktopsModelData() const
|
||||
{
|
||||
QList<OptionsModel::Data> modelData;
|
||||
for (int desktopId = 1; desktopId <= KWindowSystem::numberOfDesktops(); ++desktopId) {
|
||||
for (const DBusDesktopDataStruct &desktop : m_virtualDesktops) {
|
||||
modelData << OptionsModel::Data{
|
||||
desktopId,
|
||||
QString::number(desktopId).rightJustified(2) + QStringLiteral(": ") + KWindowSystem::desktopName(desktopId),
|
||||
desktop.position + 1, // "desktop" setting uses the desktop position (int) starting at 1
|
||||
QString::number(desktop.position + 1).rightJustified(2) + QStringLiteral(": ") + desktop.name,
|
||||
QIcon::fromTheme("virtual-desktops")
|
||||
};
|
||||
}
|
||||
|
@ -815,4 +822,32 @@ void RulesModel::selectX11Window()
|
|||
);
|
||||
}
|
||||
|
||||
void RulesModel::updateVirtualDesktops()
|
||||
{
|
||||
QDBusMessage message = QDBusMessage::createMethodCall(QStringLiteral("org.kde.KWin"),
|
||||
QStringLiteral("/VirtualDesktopManager"),
|
||||
QStringLiteral("org.freedesktop.DBus.Properties"),
|
||||
QStringLiteral("Get"));
|
||||
message.setArguments(QVariantList{
|
||||
QStringLiteral("org.kde.KWin.VirtualDesktopManager"),
|
||||
QStringLiteral("desktops")
|
||||
});
|
||||
|
||||
QDBusPendingReply<QVariant> async = QDBusConnection::sessionBus().asyncCall(message);
|
||||
|
||||
QDBusPendingCallWatcher *callWatcher = new QDBusPendingCallWatcher(async, this);
|
||||
connect(callWatcher, &QDBusPendingCallWatcher::finished, this,
|
||||
[this](QDBusPendingCallWatcher *self) {
|
||||
QDBusPendingReply<QVariant> reply = *self;
|
||||
self->deleteLater();
|
||||
if (!reply.isValid()) {
|
||||
return;
|
||||
}
|
||||
m_virtualDesktops = qdbus_cast<KWin::DBusDesktopDataVector>(reply.value());
|
||||
emit virtualDesktopsUpdated();
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
} //namespace
|
||||
|
|
|
@ -22,8 +22,9 @@
|
|||
#define KWIN_RULES_MODEL_H
|
||||
|
||||
#include "ruleitem.h"
|
||||
#include "rulesettings.h"
|
||||
#include <rules.h>
|
||||
#include <rulesettings.h>
|
||||
#include <virtualdesktopsdbustypes.h>
|
||||
|
||||
#include <QAbstractListModel>
|
||||
#include <QSortFilterProxyModel>
|
||||
|
@ -96,6 +97,8 @@ signals:
|
|||
void warningMessageChanged();
|
||||
void suggestionsChanged();
|
||||
|
||||
void virtualDesktopsUpdated();
|
||||
|
||||
private:
|
||||
void populateRuleList();
|
||||
bool wmclassWarning() const;
|
||||
|
@ -103,6 +106,7 @@ private:
|
|||
QString defaultDescription() const;
|
||||
|
||||
static const QHash<QString, QString> x11PropertyHash();
|
||||
void updateVirtualDesktops();
|
||||
|
||||
QList<OptionsModel::Data> windowTypesModelData() const;
|
||||
QList<OptionsModel::Data> virtualDesktopsModelData() const;
|
||||
|
@ -117,6 +121,7 @@ private slots:
|
|||
private:
|
||||
QList<RuleItem *> m_ruleList;
|
||||
QHash<QString, RuleItem *> m_rules;
|
||||
DBusDesktopDataVector m_virtualDesktops;
|
||||
#ifdef KWIN_BUILD_ACTIVITIES
|
||||
KActivities::Consumer *m_activities;
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue