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