6 #include "shadow_interface.h"
7 #include "buffer_interface.h"
10 #include "resource_p.h"
11 #include "surface_interface_p.h"
13 #include <wayland-server.h>
14 #include <wayland-shadow-server-protocol.h>
20 class ShadowManagerInterface::Private :
public Global::Private
23 Private(ShadowManagerInterface *q, Display *d);
26 void bind(wl_client *client, uint32_t version, uint32_t
id)
override;
27 void createShadow(wl_client *client, wl_resource *resource, uint32_t
id, wl_resource *surface);
29 static void createCallback(wl_client *client, wl_resource *resource, uint32_t
id, wl_resource *surface);
30 static void unsetCallback(wl_client *client, wl_resource *resource, wl_resource *surface);
31 static void destroyCallback(wl_client *client, wl_resource *resource);
32 static void unbind(wl_resource *resource);
33 static Private *cast(wl_resource *r)
35 return reinterpret_cast<Private *
>(wl_resource_get_user_data(r));
38 ShadowManagerInterface *q;
39 static const struct org_kde_kwin_shadow_manager_interface s_interface;
40 static const quint32 s_version;
43 const quint32 ShadowManagerInterface::Private::s_version = 2;
46 const struct org_kde_kwin_shadow_manager_interface ShadowManagerInterface::Private::s_interface = {createCallback, unsetCallback, destroyCallback};
49 ShadowManagerInterface::Private::Private(ShadowManagerInterface *q, Display *d)
50 : Global::Private(d, &org_kde_kwin_shadow_manager_interface, s_version)
55 void ShadowManagerInterface::Private::bind(wl_client *client, uint32_t version, uint32_t
id)
57 auto c = display->getConnection(client);
58 wl_resource *resource = c->createResource(&org_kde_kwin_shadow_manager_interface, qMin(version, s_version),
id);
60 wl_client_post_no_memory(client);
63 wl_resource_set_implementation(resource, &s_interface,
this, unbind);
67 void ShadowManagerInterface::Private::unbind(wl_resource *resource)
73 void ShadowManagerInterface::Private::destroyCallback(wl_client *client, wl_resource *resource)
76 wl_resource_destroy(resource);
79 void ShadowManagerInterface::Private::createCallback(wl_client *client, wl_resource *resource, uint32_t
id, wl_resource *surface)
81 cast(resource)->createShadow(client, resource,
id, surface);
84 void ShadowManagerInterface::Private::createShadow(wl_client *client, wl_resource *resource, uint32_t
id, wl_resource *surface)
91 ShadowInterface *shadow =
new ShadowInterface(q, resource);
92 shadow->create(display->getConnection(client), wl_resource_get_version(resource),
id);
93 if (!shadow->resource()) {
94 wl_resource_post_no_memory(resource);
101 void ShadowManagerInterface::Private::unsetCallback(wl_client *client, wl_resource *resource, wl_resource *surface)
112 ShadowManagerInterface::ShadowManagerInterface(Display *display,
QObject *parent)
113 : Global(new Private(this, display), parent)
117 ShadowManagerInterface::~ShadowManagerInterface() =
default;
119 class ShadowInterface::Private :
public Resource::Private
122 Private(ShadowInterface *q, ShadowManagerInterface *c, wl_resource *parentResource);
129 TopLeftBuffer = 1 << 1,
131 TopRightBuffer = 1 << 3,
132 RightBuffer = 1 << 4,
133 BottomRightBuffer = 1 << 5,
134 BottomBuffer = 1 << 6,
135 BottomLeftBuffer = 1 << 7,
138 BufferInterface *
left =
nullptr;
139 BufferInterface *topLeft =
nullptr;
140 BufferInterface *top =
nullptr;
141 BufferInterface *topRight =
nullptr;
142 BufferInterface *
right =
nullptr;
143 BufferInterface *bottomRight =
nullptr;
144 BufferInterface *bottom =
nullptr;
145 BufferInterface *bottomLeft =
nullptr;
147 Flags flags = Flags::None;
154 void attach(State::Flags flag, wl_resource *buffer);
155 ShadowInterface *q_func()
157 return reinterpret_cast<ShadowInterface *
>(q);
160 static void commitCallback(wl_client *client, wl_resource *resource);
161 static void attachLeftCallback(wl_client *client, wl_resource *resource, wl_resource *buffer);
162 static void attachTopLeftCallback(wl_client *client, wl_resource *resource, wl_resource *buffer);
163 static void attachTopCallback(wl_client *client, wl_resource *resource, wl_resource *buffer);
164 static void attachTopRightCallback(wl_client *client, wl_resource *resource, wl_resource *buffer);
165 static void attachRightCallback(wl_client *client, wl_resource *resource, wl_resource *buffer);
166 static void attachBottomRightCallback(wl_client *client, wl_resource *resource, wl_resource *buffer);
167 static void attachBottomCallback(wl_client *client, wl_resource *resource, wl_resource *buffer);
168 static void attachBottomLeftCallback(wl_client *client, wl_resource *resource, wl_resource *buffer);
169 static void offsetLeftCallback(wl_client *client, wl_resource *resource, wl_fixed_t offset);
170 static void offsetTopCallback(wl_client *client, wl_resource *resource, wl_fixed_t offset);
171 static void offsetRightCallback(wl_client *client, wl_resource *resource, wl_fixed_t offset);
172 static void offsetBottomCallback(wl_client *client, wl_resource *resource, wl_fixed_t offset);
174 static const struct org_kde_kwin_shadow_interface s_interface;
178 const struct org_kde_kwin_shadow_interface ShadowInterface::Private::s_interface = {commitCallback,
180 attachTopLeftCallback,
182 attachTopRightCallback,
184 attachBottomRightCallback,
185 attachBottomCallback,
186 attachBottomLeftCallback,
190 offsetBottomCallback,
191 resourceDestroyedCallback};
194 void ShadowInterface::Private::commitCallback(wl_client *client, wl_resource *resource)
197 cast<Private>(resource)->commit();
200 void ShadowInterface::Private::commit()
203 #define BUFFER( __FLAG__, __PART__ ) \
204 if (pending.flags & State::Flags::__FLAG__##Buffer) { \
205 if (current.__PART__) { \
206 current.__PART__->unref(); \
208 if (pending.__PART__) { \
209 pending.__PART__->ref(); \
211 current.__PART__ = pending.__PART__; \
214 BUFFER(TopLeft, topLeft)
216 BUFFER(TopRight, topRight)
218 BUFFER(BottomRight, bottomRight)
219 BUFFER(Bottom, bottom)
220 BUFFER(BottomLeft, bottomLeft)
223 if (pending.flags & State::Offset) {
224 current.offset = pending.offset;
229 void ShadowInterface::Private::attach(ShadowInterface::Private::State::Flags flag, wl_resource *buffer)
234 [
this](BufferInterface *buffer) {
235 #define PENDING( __PART__ ) \
236 if (pending.__PART__ == buffer) { \
237 pending.__PART__ = nullptr; \
249 #define CURRENT( __PART__ ) \
250 if (current.__PART__ == buffer) { \
251 current.__PART__->unref(); \
252 current.__PART__ = nullptr; \
267 case State::LeftBuffer:
270 case State::TopLeftBuffer:
273 case State::TopBuffer:
276 case State::TopRightBuffer:
277 pending.topRight = b;
279 case State::RightBuffer:
282 case State::BottomRightBuffer:
283 pending.bottomRight = b;
285 case State::BottomBuffer:
288 case State::BottomLeftBuffer:
289 pending.bottomLeft = b;
295 pending.flags = State::Flags(pending.flags | flag);
298 #define ATTACH( __PART__ ) \
299 void ShadowInterface::Private::attach##__PART__##Callback(wl_client *client, wl_resource *resource, wl_resource *buffer) \
302 Private *p = cast<Private>(resource); \
303 p->attach(State::__PART__##Buffer, buffer); \
317 #define OFFSET( __PART__ ) \
318 void ShadowInterface::Private::offset##__PART__##Callback(wl_client *client, wl_resource *resource, wl_fixed_t offset) \
322 Private *p = cast<Private>(resource); \
323 p->pending.flags = State::Flags(p->pending.flags | State::Offset); \
324 p->pending.offset.set##__PART__(wl_fixed_to_double(offset)); \
334 ShadowInterface::Private::Private(ShadowInterface *q, ShadowManagerInterface *c, wl_resource *parentResource)
335 :
Resource::Private(q, c, parentResource, &org_kde_kwin_shadow_interface, &s_interface)
339 ShadowInterface::Private::~Private()
341 #define CURRENT( __PART__ ) \
342 if (current.__PART__) { \
343 current.__PART__->unref(); \
356 ShadowInterface::ShadowInterface(ShadowManagerInterface *parent, wl_resource *parentResource)
357 :
Resource(new Private(this, parent, parentResource))
361 ShadowInterface::~ShadowInterface() =
default;
363 QMarginsF ShadowInterface::offset()
const
366 return d->current.offset;
369 #define BUFFER( __PART__ ) \
370 BufferInterface *ShadowInterface::__PART__() const \
373 return d->current.__PART__; \
386 ShadowInterface::Private *ShadowInterface::d_func()
const
388 return reinterpret_cast<Private *
>(d.data());