| 1 | /* |
| 2 | SPDX-FileCopyrightText: 2018 David Edmundson <kde@davidedmundson.co.uk> |
| 3 | |
| 4 | SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL |
| 5 | */ |
| 6 | #ifndef KWAYLAND_CLIENT_XDG_DECORATION_UNSTABLE_V1_H |
| 7 | #define KWAYLAND_CLIENT_XDG_DECORATION_UNSTABLE_V1_H |
| 8 | |
| 9 | #include <QObject> |
| 10 | |
| 11 | #include "KWayland/Client/kwaylandclient_export.h" |
| 12 | |
| 13 | struct zxdg_decoration_manager_v1; |
| 14 | struct zxdg_toplevel_decoration_v1; |
| 15 | |
| 16 | namespace KWayland |
| 17 | { |
| 18 | namespace Client |
| 19 | { |
| 20 | class EventQueue; |
| 21 | class XdgDecoration; |
| 22 | class XdgShellSurface; |
| 23 | |
| 24 | /** |
| 25 | * @short Wrapper for the zxdg_decoration_manager_v1 interface. |
| 26 | * |
| 27 | * This class provides a convenient wrapper for the zxdg_decoration_manager_v1 interface. |
| 28 | * |
| 29 | * To use this class one needs to interact with the Registry. There are two |
| 30 | * possible ways to create the XdgDecorationManager interface: |
| 31 | * @code |
| 32 | * XdgDecorationManager *c = registry->createXdgDecorationManager(name, version); |
| 33 | * @endcode |
| 34 | * |
| 35 | * This creates the XdgDecorationManager and sets it up directly. As an alternative this |
| 36 | * can also be done in a more low level way: |
| 37 | * @code |
| 38 | * XdgDecorationManager *c = new XdgDecorationManager; |
| 39 | * c->setup(registry->bindXdgDecorationManager(name, version)); |
| 40 | * @endcode |
| 41 | * |
| 42 | * The XdgDecorationManager can be used as a drop-in replacement for any zxdg_decoration_manager_v1 |
| 43 | * pointer as it provides matching cast operators. |
| 44 | * |
| 45 | * If you use the QtWayland QPA you do not need to use this class. |
| 46 | * |
| 47 | * @see Registry |
| 48 | * @since 5.54 |
| 49 | **/ |
| 50 | class KWAYLANDCLIENT_EXPORT XdgDecorationManager : public QObject |
| 51 | { |
| 52 | Q_OBJECT |
| 53 | public: |
| 54 | /** |
| 55 | * Creates a new XdgDecorationManager. |
| 56 | * Note: after constructing the XdgDecorationManager it is not yet valid and one needs |
| 57 | * to call setup. In order to get a ready to use XdgDecorationManager prefer using |
| 58 | * Registry::createXdgDecorationManager. |
| 59 | **/ |
| 60 | explicit XdgDecorationManager(QObject *parent = nullptr); |
| 61 | ~XdgDecorationManager() override; |
| 62 | |
| 63 | /** |
| 64 | * Setup this XdgDecorationManager to manage the @p xdgdecorationmanager. |
| 65 | * When using Registry::createXdgDecorationManager there is no need to call this |
| 66 | * method. |
| 67 | **/ |
| 68 | void setup(zxdg_decoration_manager_v1 *xdgdecorationmanager); |
| 69 | /** |
| 70 | * @returns @c true if managing a zxdg_decoration_manager_v1. |
| 71 | **/ |
| 72 | bool isValid() const; |
| 73 | /** |
| 74 | * Releases the zxdg_decoration_manager_v1 interface. |
| 75 | * After the interface has been released the XdgDecorationManager instance is no |
| 76 | * longer valid and can be setup with another zxdg_decoration_manager_v1 interface. |
| 77 | **/ |
| 78 | void release(); |
| 79 | /** |
| 80 | * Destroys the data held by this XdgDecorationManager. |
| 81 | * This method is supposed to be used when the connection to the Wayland |
| 82 | * server goes away. If the connection is not valid anymore, it's not |
| 83 | * possible to call release anymore as that calls into the Wayland |
| 84 | * connection and the call would fail. This method cleans up the data, so |
| 85 | * that the instance can be deleted or set up to a new zxdg_decoration_manager_v1 interface |
| 86 | * once there is a new connection available. |
| 87 | * |
| 88 | * It is suggested to connect this method to ConnectionThread::connectionDied: |
| 89 | * @code |
| 90 | * connect(connection, &ConnectionThread::connectionDied, xdgdecorationmanager, &XdgDecorationManager::destroy); |
| 91 | * @endcode |
| 92 | * |
| 93 | * @see release |
| 94 | **/ |
| 95 | void destroy(); |
| 96 | |
| 97 | /** |
| 98 | * Sets the @p queue to use for creating objects with this XdgDecorationManager. |
| 99 | **/ |
| 100 | void setEventQueue(EventQueue *queue); |
| 101 | /** |
| 102 | * @returns The event queue to use for creating objects with this XdgDecorationManager. |
| 103 | **/ |
| 104 | EventQueue *eventQueue(); |
| 105 | |
| 106 | XdgDecoration *getToplevelDecoration(XdgShellSurface *toplevel, QObject *parent = nullptr); |
| 107 | |
| 108 | operator zxdg_decoration_manager_v1 *(); |
| 109 | operator zxdg_decoration_manager_v1 *() const; |
| 110 | |
| 111 | Q_SIGNALS: |
| 112 | /** |
| 113 | * The corresponding global for this interface on the Registry got removed. |
| 114 | * |
| 115 | * This signal gets only emitted if the XdgDecorationManager got created by |
| 116 | * Registry::createXdgDecorationManager |
| 117 | **/ |
| 118 | void removed(); |
| 119 | |
| 120 | private: |
| 121 | class Private; |
| 122 | QScopedPointer<Private> d; |
| 123 | }; |
| 124 | |
| 125 | class KWAYLANDCLIENT_EXPORT XdgDecoration : public QObject |
| 126 | { |
| 127 | Q_OBJECT |
| 128 | public: |
| 129 | enum class Mode { |
| 130 | ClientSide, |
| 131 | ServerSide, |
| 132 | }; |
| 133 | |
| 134 | Q_ENUM(Mode) |
| 135 | |
| 136 | ~XdgDecoration() override; |
| 137 | |
| 138 | /** |
| 139 | * Setup this XdgDecoration to manage the @p xdgdecoration. |
| 140 | * When using XdgDecorationManager::createXdgDecoration there is no need to call this |
| 141 | * method. |
| 142 | **/ |
| 143 | void setup(zxdg_toplevel_decoration_v1 *xdgdecoration); |
| 144 | /** |
| 145 | * @returns @c true if managing a zxdg_toplevel_decoration_v1. |
| 146 | **/ |
| 147 | bool isValid() const; |
| 148 | /** |
| 149 | * Releases the zxdg_toplevel_decoration_v1 interface. |
| 150 | * After the interface has been released the XdgDecoration instance is no |
| 151 | * longer valid and can be setup with another zxdg_toplevel_decoration_v1 interface. |
| 152 | **/ |
| 153 | void release(); |
| 154 | /** |
| 155 | * Destroys the data held by this XdgDecoration. |
| 156 | * This method is supposed to be used when the connection to the Wayland |
| 157 | * server goes away. If the connection is not valid anymore, it's not |
| 158 | * possible to call release anymore as that calls into the Wayland |
| 159 | * connection and the call would fail. This method cleans up the data, so |
| 160 | * that the instance can be deleted or set up to a new zxdg_toplevel_decoration_v1 interface |
| 161 | * once there is a new connection available. |
| 162 | * |
| 163 | * It is suggested to connect this method to ConnectionThread::connectionDied: |
| 164 | * @code |
| 165 | * connect(connection, &ConnectionThread::connectionDied, xdgdecoration, &XdgDecoration::destroy); |
| 166 | * @endcode |
| 167 | * |
| 168 | * @see release |
| 169 | **/ |
| 170 | void destroy(); |
| 171 | |
| 172 | /** |
| 173 | * @brief Request that the server puts us in a given mode. The compositor will respond with a modeChange |
| 174 | * The compositor may ignore this request. |
| 175 | */ |
| 176 | void setMode(Mode mode); |
| 177 | |
| 178 | /** |
| 179 | * @brief Unset our requested mode. The compositor can then configure this surface with the default mode |
| 180 | */ |
| 181 | void unsetMode(); |
| 182 | |
| 183 | /** |
| 184 | * The mode configured by the server. |
| 185 | */ |
| 186 | Mode mode() const; |
| 187 | |
| 188 | operator zxdg_toplevel_decoration_v1 *(); |
| 189 | operator zxdg_toplevel_decoration_v1 *() const; |
| 190 | |
| 191 | Q_SIGNALS: |
| 192 | void modeChanged(KWayland::Client::XdgDecoration::Mode mode); |
| 193 | |
| 194 | private: |
| 195 | friend class XdgDecorationManager; |
| 196 | explicit XdgDecoration(QObject *parent = nullptr); |
| 197 | class Private; |
| 198 | QScopedPointer<Private> d; |
| 199 | }; |
| 200 | |
| 201 | } |
| 202 | } |
| 203 | |
| 204 | #endif |
| 205 | |