Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit 49d9553f authored by Eike Hein's avatar Eike Hein

Use KWin's D-Bus interface to get desktop layout rows on Wayland

Summary:
While I think mixing IPC systems in this class is not the way to go
long-term, we have a strong desire to ship a complete user experience
for virtual desktops on Wayland in 5.15. As D17691 has been delayed
and did not make the Frameworks 5 release we can depend on for 5.15,
this is Plan B.

Reviewers: #plasma, davidedmundson, mart

Subscribers: plasma-devel

Tags: #plasma

Differential Revision: https://phabricator.kde.org/D18290
parent 79196d70
......@@ -27,6 +27,10 @@ License along with this library. If not, see <http://www.gnu.org/licenses/>.
#include <KWindowSystem>
#include <QDBusConnection>
#include <QDBusPendingCall>
#include <QDBusPendingCallWatcher>
#include <QDBusPendingReply>
#include <QDBusServiceWatcher>
#include <config-X11.h>
......@@ -197,14 +201,23 @@ void VirtualDesktopInfo::XWindowPrivate::requestRemoveDesktop(quint32 position)
}
#endif
static const QString s_serviceName(QStringLiteral("org.kde.KWin"));
static const QString s_virtualDesktopsInterface(QStringLiteral("org.kde.KWin.VirtualDesktopManager"));
static const QString s_virtDesktopsPath(QStringLiteral("/VirtualDesktopManager"));
static const QString s_fdoPropertiesInterface(QStringLiteral("org.freedesktop.DBus.Properties"));
class Q_DECL_HIDDEN VirtualDesktopInfo::WaylandPrivate : public VirtualDesktopInfo::Private
{
Q_OBJECT
public:
WaylandPrivate(VirtualDesktopInfo *q);
QVariant currentVirtualDesktop;
QStringList virtualDesktops;
uint cachedDesktopLayoutRows = 0;
KWayland::Client::PlasmaVirtualDesktopManagement *virtualDesktopManagement = nullptr;
QDBusServiceWatcher *kwinServiceWatcher = nullptr;
void init() override;
void addDesktop(const QString &id, quint32 position);
......@@ -217,6 +230,9 @@ public:
void requestActivate(const QVariant &desktop) override;
void requestCreateDesktop(quint32 position) override;
void requestRemoveDesktop(quint32 position) override;
public Q_SLOTS:
void handleDesktopLayoutRowsChanged(uint rows);
};
VirtualDesktopInfo::WaylandPrivate::WaylandPrivate(VirtualDesktopInfo *q)
......@@ -270,6 +286,61 @@ void VirtualDesktopInfo::WaylandPrivate::init()
);
registry->setup();
kwinServiceWatcher = new QDBusServiceWatcher(s_serviceName,
QDBusConnection::sessionBus(), QDBusServiceWatcher::WatchForOwnerChange);
QObject::connect(kwinServiceWatcher, &QDBusServiceWatcher::serviceRegistered,
this, [this]() {
QDBusConnection::sessionBus().connect(
s_serviceName,
s_virtDesktopsPath,
s_virtualDesktopsInterface,
QStringLiteral("rowsChanged"),
this,
SLOT(handleDesktopLayoutRowsChanged(uint)));
});
QObject::connect(kwinServiceWatcher, &QDBusServiceWatcher::serviceUnregistered,
this, [this]() {
QDBusConnection::sessionBus().disconnect(
s_serviceName,
s_virtDesktopsPath,
s_virtualDesktopsInterface,
QStringLiteral("rowsChanged"),
this,
SLOT(handleDesktopLayoutRowsChanged(uint)));
}
);
QDBusConnection::sessionBus().connect(
s_serviceName,
s_virtDesktopsPath,
s_virtualDesktopsInterface,
QStringLiteral("rowsChanged"),
this,
SLOT(handleDesktopLayoutRowsChanged(uint)));
auto callFinished = [this](QDBusPendingCallWatcher *call) {
QDBusPendingReply<QVariant> reply = *call;
handleDesktopLayoutRowsChanged(reply.value().toUInt());
call->deleteLater();
};
auto call = QDBusMessage::createMethodCall(
s_serviceName,
s_virtDesktopsPath,
s_fdoPropertiesInterface,
QStringLiteral("Get"));
call.setArguments({s_virtualDesktopsInterface, QStringLiteral("rows")});
QDBusPendingCall pending = QDBusConnection::sessionBus().asyncCall(call);
const QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(pending, this);
QObject::connect(watcher, &QDBusPendingCallWatcher::finished, this, callFinished);
}
void VirtualDesktopInfo::WaylandPrivate::addDesktop(const QString &id, quint32 position)
......@@ -342,9 +413,7 @@ QStringList VirtualDesktopInfo::WaylandPrivate::desktopNames() const
int VirtualDesktopInfo::WaylandPrivate::desktopLayoutRows() const
{
// TODO FIXME: We don't have virtual desktop layout information in the Wayland
// protocol yet.
return 0;
return (int)cachedDesktopLayoutRows;
}
void VirtualDesktopInfo::WaylandPrivate::requestActivate(const QVariant &desktop)
......@@ -374,6 +443,15 @@ void VirtualDesktopInfo::WaylandPrivate::requestRemoveDesktop(quint32 position)
virtualDesktopManagement->requestRemoveVirtualDesktop(virtualDesktops.at(position));
}
void VirtualDesktopInfo::WaylandPrivate::handleDesktopLayoutRowsChanged(uint rows)
{
if (cachedDesktopLayoutRows != rows) {
cachedDesktopLayoutRows = rows;
emit desktopLayoutRowsChanged();
}
}
VirtualDesktopInfo::Private* VirtualDesktopInfo::d = nullptr;
VirtualDesktopInfo::VirtualDesktopInfo(QObject *parent) : QObject(parent)
......
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