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

KDE's Doxygen guidelines are available online.