File indexing completed on 2024-12-22 05:09:21
0001 /* 0002 SPDX-FileCopyrightText: 2018 Marco Martin <notmart@gmail.com> 0003 0004 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL 0005 */ 0006 #ifndef KWAYLAND_CLIENT_PLASMAVIRTUALDESKTOP_H 0007 #define KWAYLAND_CLIENT_PLASMAVIRTUALDESKTOP_H 0008 0009 #include <QObject> 0010 0011 #include "KWayland/Client/kwaylandclient_export.h" 0012 0013 struct org_kde_plasma_virtual_desktop_management; 0014 struct org_kde_plasma_virtual_desktop; 0015 0016 namespace KWayland 0017 { 0018 namespace Client 0019 { 0020 class EventQueue; 0021 class PlasmaVirtualDesktop; 0022 0023 /** 0024 * @short Wrapper for the org_kde_plasma_virtual_desktop_management interface. 0025 * 0026 * This class provides a convenient wrapper for the org_kde_plasma_virtual_desktop_management interface. 0027 * 0028 * To use this class one needs to interact with the Registry. There are two 0029 * possible ways to create the PlasmaVirtualDesktopManagement interface: 0030 * @code 0031 * PlasmaVirtualDesktopManagement *c = registry->createPlasmaVirtualDesktopManagement(name, version); 0032 * @endcode 0033 * 0034 * This creates the PlasmaVirtualDesktopManagement and sets it up directly. As an alternative this 0035 * can also be done in a more low level way: 0036 * @code 0037 * PlasmaVirtualDesktopManagement *c = new PlasmaVirtualDesktopManagement; 0038 * c->setup(registry->bindPlasmaVirtualDesktopManagement(name, version)); 0039 * @endcode 0040 * 0041 * The PlasmaVirtualDesktopManagement can be used as a drop-in replacement for any org_kde_plasma_virtual_desktop_management 0042 * pointer as it provides matching cast operators. 0043 * @since 5.52 0044 * 0045 * @see Registry 0046 **/ 0047 class KWAYLANDCLIENT_EXPORT PlasmaVirtualDesktopManagement : public QObject 0048 { 0049 Q_OBJECT 0050 public: 0051 /** 0052 * Creates a new PlasmaVirtualDesktopManagement. 0053 * Note: after constructing the PlasmaVirtualDesktopManagement it is not yet valid and one needs 0054 * to call setup. In order to get a ready to use PlasmaVirtualDesktopManagement prefer using 0055 * Registry::createPlasmaVirtualDesktopManagement. 0056 **/ 0057 explicit PlasmaVirtualDesktopManagement(QObject *parent = nullptr); 0058 ~PlasmaVirtualDesktopManagement() override; 0059 0060 /** 0061 * Setup this PlasmaVirtualDesktopManagement to manage the @p plasmavirtualdesktopmanagement. 0062 * When using Registry::createPlasmaVirtualDesktopManagement there is no need to call this 0063 * method. 0064 **/ 0065 void setup(org_kde_plasma_virtual_desktop_management *plasmavirtualdesktopmanagement); 0066 /** 0067 * @returns @c true if managing a org_kde_plasma_virtual_desktop_management. 0068 **/ 0069 bool isValid() const; 0070 /** 0071 * Releases the org_kde_plasma_virtual_desktop_management interface. 0072 * After the interface has been released the PlasmaVirtualDesktopManagement instance is no 0073 * longer valid and can be setup with another org_kde_plasma_virtual_desktop_management interface. 0074 **/ 0075 void release(); 0076 /** 0077 * Destroys the data held by this PlasmaVirtualDesktopManagement. 0078 * This method is supposed to be used when the connection to the Wayland 0079 * server goes away. If the connection is not valid anymore, it's not 0080 * possible to call release anymore as that calls into the Wayland 0081 * connection and the call would fail. This method cleans up the data, so 0082 * that the instance can be deleted or set up to a new org_kde_plasma_virtual_desktop_management interface 0083 * once there is a new connection available. 0084 * 0085 * It is suggested to connect this method to ConnectionThread::connectionDied: 0086 * @code 0087 * connect(connection, &ConnectionThread::connectionDied, plasmavirtualdesktopmanagement, &PlasmaVirtualDesktopManagement::destroy); 0088 * @endcode 0089 * 0090 * @see release 0091 **/ 0092 void destroy(); 0093 0094 /** 0095 * Sets the @p queue to use for creating objects with this PlasmaVirtualDesktopManagement. 0096 **/ 0097 void setEventQueue(EventQueue *queue); 0098 0099 /** 0100 * @returns The event queue to use for creating objects with this PlasmaVirtualDesktopManagement. 0101 * The object is owned by the manager and the caller should not delete it. 0102 **/ 0103 EventQueue *eventQueue(); 0104 0105 /** 0106 * @returns the PlasmaVirtualDesktop representing the desktop id. 0107 * The PlasmaVirtualDesktop instance is guaranteed to be unique for each id. 0108 */ 0109 PlasmaVirtualDesktop *getVirtualDesktop(const QString &id); 0110 0111 /** 0112 * Requests for the desktop identified by id to be removed. 0113 * The server may or may not acconsent to the request. 0114 */ 0115 void requestRemoveVirtualDesktop(const QString &id); 0116 0117 /** 0118 * Ask the server to create a new virtual desktop, and position it at a specified position. 0119 * If the position is zero or less, it will be positioned at the beginning, 0120 * if the cosition is the count or more, it will be positioned at the end. 0121 * @param name The name we want for the desktop 0122 * @param position The position for the desktop to be created 0123 */ 0124 void requestCreateVirtualDesktop(const QString &name, quint32 position = std::numeric_limits<uint32_t>::max()); 0125 0126 /** 0127 * @returns All the existent virtual desktops 0128 */ 0129 QList<PlasmaVirtualDesktop *> desktops() const; 0130 0131 /** 0132 * @returns How many rows the virtual desktops should be laid out into 0133 * @since 5.55 0134 */ 0135 quint32 rows() const; 0136 0137 operator org_kde_plasma_virtual_desktop_management *(); 0138 operator org_kde_plasma_virtual_desktop_management *() const; 0139 0140 Q_SIGNALS: 0141 void removed(); 0142 0143 /** 0144 * Emitted when a new desktop has been added 0145 */ 0146 void desktopCreated(const QString &id, quint32 position); 0147 0148 /** 0149 * Emitted when a desktop has been removed 0150 */ 0151 void desktopRemoved(const QString &id); 0152 0153 /** 0154 * Emitted when the number of rows of virtual desktops has been changed by the server 0155 * @since 5.55 0156 */ 0157 void rowsChanged(quint32 rows); 0158 0159 /** 0160 * This event is sent after all other properties has been 0161 * sent after binding to the desktop manager object and after any 0162 * other property changes done after that. This allows 0163 * changes to the org_kde_plasma_virtual_desktop_management properties 0164 * to be seen as atomic, even if they happen via multiple events. 0165 */ 0166 void done(); 0167 0168 private: 0169 class Private; 0170 QScopedPointer<Private> d; 0171 }; 0172 0173 class KWAYLANDCLIENT_EXPORT PlasmaVirtualDesktop : public QObject 0174 { 0175 Q_OBJECT 0176 public: 0177 ~PlasmaVirtualDesktop() override; 0178 0179 /** 0180 * Setup this PlasmaVirtualDesktop to manage the @p plasmavirtualdesktop. 0181 * When using PlasmaVirtualDesktopManagement::createPlasmaVirtualDesktop there is no need to call this 0182 * method. 0183 **/ 0184 void setup(org_kde_plasma_virtual_desktop *plasmavirtualdesktop); 0185 0186 /** 0187 * @returns @c true if managing a org_kde_plasma_virtual_desktop. 0188 **/ 0189 bool isValid() const; 0190 0191 /** 0192 * Releases the org_kde_plasma_virtual_desktop interface. 0193 * After the interface has been released the PlasmaVirtualDesktop instance is no 0194 * longer valid and can be setup with another org_kde_plasma_virtual_desktop interface. 0195 **/ 0196 void release(); 0197 0198 /** 0199 * Destroys the data held by this PlasmaVirtualDesktop. 0200 * This method is supposed to be used when the connection to the Wayland 0201 * server goes away. If the connection is not valid anymore, it's not 0202 * possible to call release anymore as that calls into the Wayland 0203 * connection and the call would fail. This method cleans up the data, so 0204 * that the instance can be deleted or set up to a new org_kde_plasma_virtual_desktop interface 0205 * once there is a new connection available. 0206 * 0207 * It is suggested to connect this method to ConnectionThread::connectionDied: 0208 * @code 0209 * connect(connection, &ConnectionThread::connectionDied, plasmavirtualdesktop, &PlasmaVirtualDesktop::destroy); 0210 * @endcode 0211 * 0212 * @see release 0213 **/ 0214 void destroy(); 0215 0216 /** 0217 * Requests this desktop to be activated. 0218 * The server may or may not decide to consent to the request. 0219 */ 0220 void requestActivate(); 0221 0222 /** 0223 * @returns The unique id of this desktop. The format of the id is decided by the compositor 0224 */ 0225 QString id() const; 0226 0227 /** 0228 * @returns User readable name for the desktop. 0229 */ 0230 QString name() const; 0231 0232 /** 0233 * @returns True if the desktop is the active one. 0234 * when this property changes, activated or deactivated will be emitted. 0235 * @see activated 0236 * @see deactivated 0237 */ 0238 bool isActive() const; 0239 0240 operator org_kde_plasma_virtual_desktop *(); 0241 operator org_kde_plasma_virtual_desktop *() const; 0242 0243 Q_SIGNALS: 0244 /** 0245 * TODO: activeChanged(bool)? 0246 * Emitted when this desktop has been activated by the server 0247 */ 0248 void activated(); 0249 0250 /** 0251 * Emitted when this desktop has been activated by the server 0252 */ 0253 void deactivated(); 0254 0255 /** 0256 * This event is sent after all other properties has been 0257 * sent after binding to the desktop manager object and after any 0258 * other property changes done after that. This allows 0259 * changes to the org_kde_plasma_virtual_desktop properties 0260 * to be seen as atomic, even if they happen via multiple events. 0261 */ 0262 void done(); 0263 0264 /** 0265 * This virtual desktop has just been removed by the server: 0266 * This object itself is about to be deleted. All windows will 0267 * lose the association to this desktop. 0268 */ 0269 void removed(); 0270 0271 private: 0272 friend class PlasmaVirtualDesktopManagement; 0273 explicit PlasmaVirtualDesktop(QObject *parent = nullptr); 0274 class Private; 0275 QScopedPointer<Private> d; 0276 }; 0277 0278 } 0279 } 0280 0281 #endif