KWayland

shadow.cpp
1 /*
2  SPDX-FileCopyrightText: 2015 Martin Gräßlin <[email protected]>
3 
4  SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
5 */
6 #include "shadow.h"
7 #include "event_queue.h"
8 #include "surface.h"
9 #include "wayland_pointer_p.h"
10 
11 #include <QMarginsF>
12 
13 #include <wayland-shadow-client-protocol.h>
14 
15 namespace KWayland
16 {
17 namespace Client
18 {
19 class Q_DECL_HIDDEN ShadowManager::Private
20 {
21 public:
22  Private() = default;
23 
24  WaylandPointer<org_kde_kwin_shadow_manager, org_kde_kwin_shadow_manager_destroy> manager;
25  EventQueue *queue = nullptr;
26 };
27 
29  : QObject(parent)
30  , d(new Private)
31 {
32 }
33 
34 ShadowManager::~ShadowManager()
35 {
36  release();
37 }
38 
40 {
41  d->manager.release();
42 }
43 
45 {
46  d->manager.destroy();
47 }
48 
50 {
51  return d->manager.isValid();
52 }
53 
54 void ShadowManager::setup(org_kde_kwin_shadow_manager *manager)
55 {
56  Q_ASSERT(manager);
57  Q_ASSERT(!d->manager);
58  d->manager.setup(manager);
59 }
60 
62 {
63  d->queue = queue;
64 }
65 
67 {
68  return d->queue;
69 }
70 
72 {
73  Q_ASSERT(isValid());
74  Shadow *s = new Shadow(parent);
75  auto w = org_kde_kwin_shadow_manager_create(d->manager, *surface);
76  if (d->queue) {
77  d->queue->addProxy(w);
78  }
79  s->setup(w);
80  return s;
81 }
82 
83 void ShadowManager::removeShadow(Surface *surface)
84 {
85  Q_ASSERT(isValid());
86  org_kde_kwin_shadow_manager_unset(d->manager, *surface);
87 }
88 
89 ShadowManager::operator org_kde_kwin_shadow_manager *()
90 {
91  return d->manager;
92 }
93 
94 ShadowManager::operator org_kde_kwin_shadow_manager *() const
95 {
96  return d->manager;
97 }
98 
99 class Shadow::Private
100 {
101 public:
102  WaylandPointer<org_kde_kwin_shadow, org_kde_kwin_shadow_destroy> shadow;
103 };
104 
105 Shadow::Shadow(QObject *parent)
106  : QObject(parent)
107  , d(new Private)
108 {
109 }
110 
111 Shadow::~Shadow()
112 {
113  release();
114 }
115 
117 {
118  d->shadow.release();
119 }
120 
121 void Shadow::setup(org_kde_kwin_shadow *shadow)
122 {
123  Q_ASSERT(shadow);
124  Q_ASSERT(!d->shadow);
125  d->shadow.setup(shadow);
126 }
127 
129 {
130  d->shadow.destroy();
131 }
132 
133 bool Shadow::isValid() const
134 {
135  return d->shadow.isValid();
136 }
137 
138 void Shadow::setOffsets(const QMarginsF &margins)
139 {
140  Q_ASSERT(isValid());
141  org_kde_kwin_shadow_set_left_offset(d->shadow, wl_fixed_from_double(margins.left()));
142  org_kde_kwin_shadow_set_top_offset(d->shadow, wl_fixed_from_double(margins.top()));
143  org_kde_kwin_shadow_set_right_offset(d->shadow, wl_fixed_from_double(margins.right()));
144  org_kde_kwin_shadow_set_bottom_offset(d->shadow, wl_fixed_from_double(margins.bottom()));
145 }
146 
147 void Shadow::commit()
148 {
149  Q_ASSERT(isValid());
150  org_kde_kwin_shadow_commit(d->shadow);
151 }
152 
153 // clang-format off
154 #ifndef K_DOXYGEN
155 #define attach( __PART__, __WAYLAND_PART__ ) \
156 void Shadow::attach##__PART__(wl_buffer *buffer) \
157 { \
158  Q_ASSERT(isValid()); \
159  org_kde_kwin_shadow_attach_##__WAYLAND_PART__(d->shadow, buffer); \
160 } \
161 void Shadow::attach##__PART__(Buffer *buffer) \
162 { \
163  if (!buffer) {\
164  return;\
165  }\
166  attach##__PART__(buffer->buffer()); \
167 } \
168 void Shadow::attach##__PART__(Buffer::Ptr buffer) \
169 { \
170  attach##__PART__(buffer.toStrongRef().data()); \
171 }
172 // clang-format on
173 
174 attach(Left, left) attach(TopLeft, top_left) attach(Top, top) attach(TopRight, top_right) attach(Right, right) attach(BottomRight, bottom_right)
175  attach(Bottom, bottom) attach(BottomLeft, bottom_left)
176 
177 #undef attach
178 #endif
179 
180  Shadow::operator org_kde_kwin_shadow *()
181 {
182  return d->shadow;
183 }
184 
185 Shadow::operator org_kde_kwin_shadow *() const
186 {
187  return d->shadow;
188 }
189 
190 }
191 }
qreal top() const const
Wrapper for the org_kde_kwin_shadow interface.
Definition: shadow.h:149
void setup(org_kde_kwin_shadow_manager *compositor)
Setup this ShadowManager to manage the compositor.
Definition: shadow.cpp:54
Shadow * createShadow(Surface *surface, QObject *parent=nullptr)
Creates and setup a new Shadow with parent.
Definition: shadow.cpp:71
Wrapper for the wl_surface interface.
Definition: surface.h:43
void destroy()
Destroys the data held by this Shadow.
Definition: shadow.cpp:128
void destroy()
Destroys the data held by this ShadowManager.
Definition: shadow.cpp:44
qreal left() const const
void release()
Releases the org_kde_kwin_shadow_manager interface.
Definition: shadow.cpp:39
Wrapper class for wl_event_queue interface.
Definition: event_queue.h:54
void release()
Releases the org_kde_kwin_shadow interface.
Definition: shadow.cpp:116
void setup(org_kde_kwin_shadow *shadow)
Setup this Shadow to manage the shadow.
Definition: shadow.cpp:121
bool isValid() const
Definition: shadow.cpp:133
void setEventQueue(EventQueue *queue)
Sets the queue to use for creating a Shadow.
Definition: shadow.cpp:61
ShadowManager(QObject *parent=nullptr)
Creates a new ShadowManager.
Definition: shadow.cpp:28
qreal right() const const
qreal bottom() const const
QObject * parent() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Mon Jan 30 2023 03:56:24 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.