File indexing completed on 2024-12-22 05:09:25
0001 /* 0002 SPDX-FileCopyrightText: 2018 David Edmundson <kde@davidedmundson.co.uk> 0003 0004 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL 0005 */ 0006 #ifndef KWAYLAND_CLIENT_XDG_DECORATION_UNSTABLE_V1_H 0007 #define KWAYLAND_CLIENT_XDG_DECORATION_UNSTABLE_V1_H 0008 0009 #include <QObject> 0010 0011 #include "KWayland/Client/kwaylandclient_export.h" 0012 0013 struct zxdg_decoration_manager_v1; 0014 struct zxdg_toplevel_decoration_v1; 0015 0016 namespace KWayland 0017 { 0018 namespace Client 0019 { 0020 class EventQueue; 0021 class XdgDecoration; 0022 class XdgShellSurface; 0023 0024 /** 0025 * @short Wrapper for the zxdg_decoration_manager_v1 interface. 0026 * 0027 * This class provides a convenient wrapper for the zxdg_decoration_manager_v1 interface. 0028 * 0029 * To use this class one needs to interact with the Registry. There are two 0030 * possible ways to create the XdgDecorationManager interface: 0031 * @code 0032 * XdgDecorationManager *c = registry->createXdgDecorationManager(name, version); 0033 * @endcode 0034 * 0035 * This creates the XdgDecorationManager and sets it up directly. As an alternative this 0036 * can also be done in a more low level way: 0037 * @code 0038 * XdgDecorationManager *c = new XdgDecorationManager; 0039 * c->setup(registry->bindXdgDecorationManager(name, version)); 0040 * @endcode 0041 * 0042 * The XdgDecorationManager can be used as a drop-in replacement for any zxdg_decoration_manager_v1 0043 * pointer as it provides matching cast operators. 0044 * 0045 * If you use the QtWayland QPA you do not need to use this class. 0046 * 0047 * @see Registry 0048 * @since 5.54 0049 **/ 0050 class KWAYLANDCLIENT_EXPORT XdgDecorationManager : public QObject 0051 { 0052 Q_OBJECT 0053 public: 0054 /** 0055 * Creates a new XdgDecorationManager. 0056 * Note: after constructing the XdgDecorationManager it is not yet valid and one needs 0057 * to call setup. In order to get a ready to use XdgDecorationManager prefer using 0058 * Registry::createXdgDecorationManager. 0059 **/ 0060 explicit XdgDecorationManager(QObject *parent = nullptr); 0061 ~XdgDecorationManager() override; 0062 0063 /** 0064 * Setup this XdgDecorationManager to manage the @p xdgdecorationmanager. 0065 * When using Registry::createXdgDecorationManager there is no need to call this 0066 * method. 0067 **/ 0068 void setup(zxdg_decoration_manager_v1 *xdgdecorationmanager); 0069 /** 0070 * @returns @c true if managing a zxdg_decoration_manager_v1. 0071 **/ 0072 bool isValid() const; 0073 /** 0074 * Releases the zxdg_decoration_manager_v1 interface. 0075 * After the interface has been released the XdgDecorationManager instance is no 0076 * longer valid and can be setup with another zxdg_decoration_manager_v1 interface. 0077 **/ 0078 void release(); 0079 /** 0080 * Destroys the data held by this XdgDecorationManager. 0081 * This method is supposed to be used when the connection to the Wayland 0082 * server goes away. If the connection is not valid anymore, it's not 0083 * possible to call release anymore as that calls into the Wayland 0084 * connection and the call would fail. This method cleans up the data, so 0085 * that the instance can be deleted or set up to a new zxdg_decoration_manager_v1 interface 0086 * once there is a new connection available. 0087 * 0088 * It is suggested to connect this method to ConnectionThread::connectionDied: 0089 * @code 0090 * connect(connection, &ConnectionThread::connectionDied, xdgdecorationmanager, &XdgDecorationManager::destroy); 0091 * @endcode 0092 * 0093 * @see release 0094 **/ 0095 void destroy(); 0096 0097 /** 0098 * Sets the @p queue to use for creating objects with this XdgDecorationManager. 0099 **/ 0100 void setEventQueue(EventQueue *queue); 0101 /** 0102 * @returns The event queue to use for creating objects with this XdgDecorationManager. 0103 **/ 0104 EventQueue *eventQueue(); 0105 0106 XdgDecoration *getToplevelDecoration(XdgShellSurface *toplevel, QObject *parent = nullptr); 0107 0108 operator zxdg_decoration_manager_v1 *(); 0109 operator zxdg_decoration_manager_v1 *() const; 0110 0111 Q_SIGNALS: 0112 /** 0113 * The corresponding global for this interface on the Registry got removed. 0114 * 0115 * This signal gets only emitted if the XdgDecorationManager got created by 0116 * Registry::createXdgDecorationManager 0117 **/ 0118 void removed(); 0119 0120 private: 0121 class Private; 0122 QScopedPointer<Private> d; 0123 }; 0124 0125 class KWAYLANDCLIENT_EXPORT XdgDecoration : public QObject 0126 { 0127 Q_OBJECT 0128 public: 0129 enum class Mode { 0130 ClientSide, 0131 ServerSide, 0132 }; 0133 0134 Q_ENUM(Mode) 0135 0136 ~XdgDecoration() override; 0137 0138 /** 0139 * Setup this XdgDecoration to manage the @p xdgdecoration. 0140 * When using XdgDecorationManager::createXdgDecoration there is no need to call this 0141 * method. 0142 **/ 0143 void setup(zxdg_toplevel_decoration_v1 *xdgdecoration); 0144 /** 0145 * @returns @c true if managing a zxdg_toplevel_decoration_v1. 0146 **/ 0147 bool isValid() const; 0148 /** 0149 * Releases the zxdg_toplevel_decoration_v1 interface. 0150 * After the interface has been released the XdgDecoration instance is no 0151 * longer valid and can be setup with another zxdg_toplevel_decoration_v1 interface. 0152 **/ 0153 void release(); 0154 /** 0155 * Destroys the data held by this XdgDecoration. 0156 * This method is supposed to be used when the connection to the Wayland 0157 * server goes away. If the connection is not valid anymore, it's not 0158 * possible to call release anymore as that calls into the Wayland 0159 * connection and the call would fail. This method cleans up the data, so 0160 * that the instance can be deleted or set up to a new zxdg_toplevel_decoration_v1 interface 0161 * once there is a new connection available. 0162 * 0163 * It is suggested to connect this method to ConnectionThread::connectionDied: 0164 * @code 0165 * connect(connection, &ConnectionThread::connectionDied, xdgdecoration, &XdgDecoration::destroy); 0166 * @endcode 0167 * 0168 * @see release 0169 **/ 0170 void destroy(); 0171 0172 /** 0173 * @brief Request that the server puts us in a given mode. The compositor will respond with a modeChange 0174 * The compositor may ignore this request. 0175 */ 0176 void setMode(Mode mode); 0177 0178 /** 0179 * @brief Unset our requested mode. The compositor can then configure this surface with the default mode 0180 */ 0181 void unsetMode(); 0182 0183 /** 0184 * The mode configured by the server. 0185 */ 0186 Mode mode() const; 0187 0188 operator zxdg_toplevel_decoration_v1 *(); 0189 operator zxdg_toplevel_decoration_v1 *() const; 0190 0191 Q_SIGNALS: 0192 void modeChanged(KWayland::Client::XdgDecoration::Mode mode); 0193 0194 private: 0195 friend class XdgDecorationManager; 0196 explicit XdgDecoration(QObject *parent = nullptr); 0197 class Private; 0198 QScopedPointer<Private> d; 0199 }; 0200 0201 } 0202 } 0203 0204 #endif