Phosphor
Qt6 / Wayland library suite for window-management tools
Loading...
Searching...
No Matches
IVirtualDesktopBackend.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
6#include "phosphorworkspaces_export.h"
7
8#include <QList>
9#include <QObject>
10#include <QString>
11
12#include <functional>
13#include <optional>
14
15namespace PhosphorWorkspaces {
16
19{
20 int position = 0;
21 QString id;
22 QString name;
23};
24
42class PHOSPHORWORKSPACES_EXPORT IVirtualDesktopBackend : public QObject
43{
44 Q_OBJECT
45
46public:
48 struct Snapshot
49 {
50 QList<DesktopEntry> desktops;
52 QString currentId;
54 std::optional<int> rows;
55 };
56 using SnapshotCallback = std::function<void(std::optional<Snapshot> snapshot)>;
58 using AnswerCallback = std::function<void(bool answered)>;
59
60 explicit IVirtualDesktopBackend(QObject* parent = nullptr)
61 : QObject(parent)
62 {
63 }
64 ~IVirtualDesktopBackend() override = default;
65
68 virtual bool connectToSource() = 0;
72 virtual bool isReachable() const = 0;
75 virtual void subscribe() = 0;
76 virtual void unsubscribe() = 0;
77
81 virtual std::optional<Snapshot> readSnapshot() = 0;
84 virtual void readSnapshotAsync(SnapshotCallback done) = 0;
85
88 virtual void setCurrentDesktop(const QString& desktopId) = 0;
92 virtual void createDesktop(uint position, const QString& name, AnswerCallback done) = 0;
94 virtual void removeDesktop(const QString& desktopId, AnswerCallback done) = 0;
96 virtual void setDesktopName(const QString& desktopId, const QString& name) = 0;
97
98Q_SIGNALS:
99 void currentChanged(const QString& desktopId);
102 void countChanged(int count);
103 void desktopCreated(const QString& desktopId, int position, const QString& name);
106 void desktopCreatedUnreadable(const QString& desktopId);
108 void desktopDataChanged(const QString& desktopId, int position, const QString& name);
111 void desktopRemoved(const QString& desktopId);
113 void rowsChanged(int rows);
114};
115
116} // namespace PhosphorWorkspaces
std::function< void(std::optional< Snapshot > snapshot)> SnapshotCallback
Definition IVirtualDesktopBackend.h:56
void currentChanged(const QString &desktopId)
void desktopCreatedUnreadable(const QString &desktopId)
A desktop was created but its data could not be read.
void desktopCreated(const QString &desktopId, int position, const QString &name)
void countChanged(int count)
The desktop count, which closes a create, a remove or a resize: every desktop signal of the change we...
virtual void removeDesktop(const QString &desktopId, AnswerCallback done)=0
Remove a desktop. done as for createDesktop.
virtual void setCurrentDesktop(const QString &desktopId)=0
Switch to the desktop with this id, without waiting for the switch: it arrives as currentChanged.
void desktopRemoved(const QString &desktopId)
virtual void setDesktopName(const QString &desktopId, const QString &name)=0
Rename a desktop. The new name arrives as desktopDataChanged.
std::function< void(bool answered)> AnswerCallback
answered is false for an error or a timeout: a stall, not a refusal.
Definition IVirtualDesktopBackend.h:58
void desktopDataChanged(const QString &desktopId, int position, const QString &name)
A desktop was renamed or moved; position is its new one.
virtual void createDesktop(uint position, const QString &name, AnswerCallback done)=0
Create a desktop at a 0-based position.
virtual void readSnapshotAsync(SnapshotCallback done)=0
Read the whole list without blocking.
void rowsChanged(int rows)
The grid's row count changed (a reshape moves no desktop).
void desktopDataChangedUnreadable()
A desktop's data changed but could not be read.
virtual void subscribe()=0
Start and stop emitting the change signals.
virtual bool connectToSource()=0
Reach the compositor's desktops.
IVirtualDesktopBackend(QObject *parent=nullptr)
Definition IVirtualDesktopBackend.h:60
virtual std::optional< Snapshot > readSnapshot()=0
Read the whole list now, blocking the caller.
virtual bool isReachable() const =0
Whether a read can reach the desktops right now.
Definition WindowTrackingService.h:46
One desktop of a compositor's list: 0-based position, stable id, raw name.
Definition IVirtualDesktopBackend.h:19
int position
Definition IVirtualDesktopBackend.h:20
QString id
Definition IVirtualDesktopBackend.h:21
QString name
Definition IVirtualDesktopBackend.h:22
One whole desktop list, with the current desktop and the grid's rows.
Definition IVirtualDesktopBackend.h:49
std::optional< int > rows
The grid's row count, nullopt when the compositor did not say.
Definition IVirtualDesktopBackend.h:54
QList< DesktopEntry > desktops
Definition IVirtualDesktopBackend.h:50
QString currentId
The current desktop's id, empty when the compositor did not say.
Definition IVirtualDesktopBackend.h:52