1/*
2 SPDX-FileCopyrightText: 2015 Martin Gräßlin <mgraesslin@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
5*/
6#ifndef KWAYLAND_SHADOW_H
7#define KWAYLAND_SHADOW_H
8
9#include "buffer.h"
10
11#include <QObject>
12#include <QPoint>
13#include <QSize>
14
15#include "KWayland/Client/kwaylandclient_export.h"
16
17struct wl_buffer;
18struct org_kde_kwin_shadow;
19struct org_kde_kwin_shadow_manager;
20
21class QMarginsF;
22
23namespace KWayland
24{
25namespace Client
26{
27class EventQueue;
28class Shadow;
29class Surface;
30
31/**
32 * @short Wrapper for the org_kde_kwin_shadow_manager interface.
33 *
34 * This class provides a convenient wrapper for the org_kde_kwin_shadow_manager interface.
35 *
36 * To use this class one needs to interact with the Registry. There are two
37 * possible ways to create the ShadowManager interface:
38 * @code
39 * ShadowManager *s = registry->createShadowManager(name, version);
40 * @endcode
41 *
42 * This creates the ShadowManager and sets it up directly. As an alternative this
43 * can also be done in a more low level way:
44 * @code
45 * ShadowManager *s = new ShadowManager;
46 * s->setup(registry->bindShadowManager(name, version));
47 * @endcode
48 *
49 * The ShadowManager can be used as a drop-in replacement for any org_kde_kwin_shadow_manager
50 * pointer as it provides matching cast operators.
51 *
52 * @see Registry
53 * @since 5.4
54 **/
55class KWAYLANDCLIENT_EXPORT ShadowManager : public QObject
56{
57 Q_OBJECT
58public:
59 /**
60 * Creates a new ShadowManager.
61 * Note: after constructing the ShadowManager it is not yet valid and one needs
62 * to call setup. In order to get a ready to use ShadowManager prefer using
63 * Registry::createShadowManager.
64 **/
65 explicit ShadowManager(QObject *parent = nullptr);
66 ~ShadowManager() override;
67
68 /**
69 * @returns @c true if managing a org_kde_kwin_shadow_manager.
70 **/
71 bool isValid() const;
72 /**
73 * Setup this ShadowManager to manage the @p compositor.
74 * When using Registry::createShadowManager there is no need to call this
75 * method.
76 **/
77 void setup(org_kde_kwin_shadow_manager *compositor);
78 /**
79 * Releases the org_kde_kwin_shadow_manager interface.
80 * After the interface has been released the ShadowManager instance is no
81 * longer valid and can be setup with another org_kde_kwin_shadow_manager interface.
82 **/
83 void release();
84 /**
85 * Destroys the data held by this ShadowManager.
86 * This method is supposed to be used when the connection to the Wayland
87 * server goes away. If the connection is not valid anymore, it's not
88 * possible to call release anymore as that calls into the Wayland
89 * connection and the call would fail. This method cleans up the data, so
90 * that the instance can be deleted or set up to a new org_kde_kwin_shadow_manager interface
91 * once there is a new connection available.
92 *
93 * This method is automatically invoked when the Registry which created this
94 * Shadow gets destroyed.
95 *
96 * @see release
97 **/
98 void destroy();
99
100 /**
101 * Sets the @p queue to use for creating a Shadow.
102 **/
103 void setEventQueue(EventQueue *queue);
104 /**
105 * @returns The event queue to use for creating a Shadow.
106 **/
107 EventQueue *eventQueue();
108
109 /**
110 * Creates and setup a new Shadow with @p parent.
111 * @param parent The parent to pass to the Shadow.
112 * @returns The new created Shadow
113 **/
114 Shadow *createShadow(Surface *surface, QObject *parent = nullptr);
115 void removeShadow(Surface *surface);
116
117 operator org_kde_kwin_shadow_manager *();
118 operator org_kde_kwin_shadow_manager *() const;
119
120Q_SIGNALS:
121 /**
122 * The corresponding global for this interface on the Registry got removed.
123 *
124 * This signal gets only emitted if the Compositor got created by
125 * Registry::createShadowManager
126 *
127 * @since 5.5
128 **/
129 void removed();
130
131private:
132 class Private;
133 QScopedPointer<Private> d;
134};
135
136/**
137 * @short Wrapper for the org_kde_kwin_shadow interface.
138 *
139 * This class is a convenient wrapper for the org_kde_kwin_shadow interface.
140 * To create a Shadow call Compositor::createShadow.
141 *
142 * The main purpose of this class is to setup the next frame which
143 * should be rendered. Therefore it provides methods to add damage
144 * and to attach a new Buffer and to finalize the frame by calling
145 * commit.
146 *
147 * @see Compositor
148 **/
149class KWAYLANDCLIENT_EXPORT Shadow : public QObject
150{
151 Q_OBJECT
152public:
153 ~Shadow() override;
154
155 /**
156 * Setup this Shadow to manage the @p shadow.
157 * When using Compositor::createSurface there is no need to call this
158 * method.
159 **/
160 void setup(org_kde_kwin_shadow *shadow);
161 /**
162 * Releases the org_kde_kwin_shadow interface.
163 * After the interface has been released the Shadow instance is no
164 * longer valid and can be setup with another org_kde_kwin_shadow interface.
165 **/
166 void release();
167 /**
168 * Destroys the data held by this Shadow.
169 * This method is supposed to be used when the connection to the Wayland
170 * server goes away. If the connection is not valid anymore, it's not
171 * possible to call release anymore as that calls into the Wayland
172 * connection and the call would fail. This method cleans up the data, so
173 * that the instance can be deleted or set up to a new org_kde_kwin_shadow interface
174 * once there is a new connection available.
175 *
176 * It is suggested to connect this method to ConnectionThread::connectionDied:
177 * @code
178 * connect(connection, &ConnectionThread::connectionDied, shadow, &Shadow::destroy);
179 * @endcode
180 *
181 * @see release
182 **/
183 void destroy();
184 /**
185 * @returns @c true if managing a org_kde_kwin_shadow.
186 **/
187 bool isValid() const;
188
189 void commit();
190 void attachLeft(wl_buffer *buffer);
191 void attachLeft(Buffer *buffer);
192 void attachLeft(Buffer::Ptr buffer);
193 void attachTopLeft(wl_buffer *buffer);
194 void attachTopLeft(Buffer *buffer);
195 void attachTopLeft(Buffer::Ptr buffer);
196 void attachTop(wl_buffer *buffer);
197 void attachTop(Buffer *buffer);
198 void attachTop(Buffer::Ptr buffer);
199 void attachTopRight(wl_buffer *buffer);
200 void attachTopRight(Buffer *buffer);
201 void attachTopRight(Buffer::Ptr buffer);
202 void attachRight(wl_buffer *buffer);
203 void attachRight(Buffer *buffer);
204 void attachRight(Buffer::Ptr buffer);
205 void attachBottomRight(wl_buffer *buffer);
206 void attachBottomRight(Buffer *buffer);
207 void attachBottomRight(Buffer::Ptr buffer);
208 void attachBottom(wl_buffer *buffer);
209 void attachBottom(Buffer *buffer);
210 void attachBottom(Buffer::Ptr buffer);
211 void attachBottomLeft(wl_buffer *buffer);
212 void attachBottomLeft(Buffer *buffer);
213 void attachBottomLeft(Buffer::Ptr buffer);
214 void setOffsets(const QMarginsF &margins);
215
216 operator org_kde_kwin_shadow *();
217 operator org_kde_kwin_shadow *() const;
218
219private:
220 friend class ShadowManager;
221 explicit Shadow(QObject *parent = nullptr);
222 class Private;
223 QScopedPointer<Private> d;
224};
225
226}
227}
228
229#endif
230

source code of kwayland/src/client/shadow.h