Phosphor
Qt6 / Wayland library suite for window-management tools
Loading...
Searching...
No Matches
KWinVirtualDesktopBackend.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2026 fuddlesworth
2// SPDX-License-Identifier: LGPL-2.1-or-later
3
4#pragma once
5
7#include <PhosphorWorkspaces/Plasma/phosphorworkspacesplasma_export.h>
8
9QT_BEGIN_NAMESPACE
10class QDBusArgument;
11class QDBusInterface;
12class QDBusMessage;
13QT_END_NAMESPACE
14
15namespace PhosphorWorkspaces {
16
25class PHOSPHORWORKSPACESPLASMA_EXPORT KWinVirtualDesktopBackend : public IVirtualDesktopBackend
26{
27 Q_OBJECT
28
29public:
30 explicit KWinVirtualDesktopBackend(QObject* parent = nullptr);
32
34 bool connectToSource() override;
36 bool isReachable() const override;
37 void subscribe() override;
38 void unsubscribe() override;
39 std::optional<Snapshot> readSnapshot() override;
41 void setCurrentDesktop(const QString& desktopId) override;
42 void createDesktop(uint position, const QString& name, AnswerCallback done) override;
43 void removeDesktop(const QString& desktopId, AnswerCallback done) override;
44 void setDesktopName(const QString& desktopId, const QString& name) override;
45
46private Q_SLOTS:
47 // KWin's signals off the bus. The parameter types are the wire types:
48 // QDBusConnection::connect matches a slot against the message's signature,
49 // so a slot declared `int` for KWin's `u` registers successfully and is
50 // then NEVER invoked.
51 void onCurrentChanged(const QString& desktopId);
52 void onCountChanged(uint count);
55 void onDesktopCreated(const QDBusMessage& message);
56 void onDesktopRemoved(const QString& desktopId);
57 void onRowsChanged(uint rows);
59 void onDesktopDataChanged(const QDBusMessage& message);
60
61private:
64 static QList<DesktopEntry> readDesktopArray(const QDBusArgument& arg);
65
66 QDBusInterface* m_interface = nullptr;
67 bool m_subscribed = false;
68};
69
70} // namespace PhosphorWorkspaces
std::function< void(std::optional< Snapshot > snapshot)> SnapshotCallback
Definition IVirtualDesktopBackend.h:56
std::function< void(bool answered)> AnswerCallback
answered is false for an error or a timeout: a stall, not a refusal.
Definition IVirtualDesktopBackend.h:58
IVirtualDesktopBackend(QObject *parent=nullptr)
Definition IVirtualDesktopBackend.h:60
bool connectToSource() override
Probe KWin's interface. False on a session without KWin.
void setDesktopName(const QString &desktopId, const QString &name) override
Rename a desktop. The new name arrives as desktopDataChanged.
void removeDesktop(const QString &desktopId, AnswerCallback done) override
Remove a desktop. done as for createDesktop.
void createDesktop(uint position, const QString &name, AnswerCallback done) override
Create a desktop at a 0-based position.
bool isReachable() const override
KWin's service is on the bus (QDBusInterface follows its owner).
void readSnapshotAsync(SnapshotCallback done) override
Read the whole list without blocking.
KWinVirtualDesktopBackend(QObject *parent=nullptr)
void subscribe() override
Start and stop emitting the change signals.
void setCurrentDesktop(const QString &desktopId) override
Switch to the desktop with this id, without waiting for the switch: it arrives as currentChanged.
std::optional< Snapshot > readSnapshot() override
Read the whole list now, blocking the caller.
Definition WindowTrackingService.h:46