KWayland

subsurface.cpp
1 /*
2  SPDX-FileCopyrightText: 2014 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 "subsurface.h"
7 #include "surface.h"
8 #include "wayland_pointer_p.h"
9 // Wayland
10 #include <wayland-client-protocol.h>
11 
12 namespace KWayland
13 {
14 namespace Client
15 {
16 
17 class Q_DECL_HIDDEN SubSurface::Private
18 {
19 public:
20  Private(QPointer<Surface> surface, QPointer<Surface> parentSurface, SubSurface *q);
21  void setup(wl_subsurface *subsurface);
22 
23  WaylandPointer<wl_subsurface, wl_subsurface_destroy> subSurface;
24  QPointer<Surface> surface;
25  QPointer<Surface> parentSurface;
26  Mode mode = Mode::Synchronized;
27  QPoint pos = QPoint(0, 0);
28 
29  static SubSurface *cast(wl_subsurface *native);
30 
31 private:
32  SubSurface *q;
33 };
34 
35 SubSurface::Private::Private(QPointer< Surface > surface, QPointer< Surface > parentSurface, SubSurface *q)
36  : surface(surface)
37  , parentSurface(parentSurface)
38  , q(q)
39 {
40 }
41 
42 void SubSurface::Private::setup(wl_subsurface *subsurface)
43 {
44  Q_ASSERT(subsurface);
45  Q_ASSERT(!subSurface.isValid());
46  subSurface.setup(subsurface);
47  wl_subsurface_set_user_data(subsurface, this);
48 }
49 
50 SubSurface *SubSurface::Private::cast(wl_subsurface *native)
51 {
52  return reinterpret_cast<Private*>(wl_subsurface_get_user_data(native))->q;
53 }
54 
55 SubSurface::SubSurface(QPointer< Surface > surface, QPointer< Surface > parentSurface, QObject *parent)
56  : QObject(parent)
57  , d(new Private(surface, parentSurface, this))
58 {
59 }
60 
61 SubSurface::~SubSurface()
62 {
63  release();
64 }
65 
66 void SubSurface::setup(wl_subsurface *subsurface)
67 {
68  d->setup(subsurface);
69 }
70 
71 void SubSurface::destroy()
72 {
73  d->subSurface.destroy();
74 }
75 
76 void SubSurface::release()
77 {
78  d->subSurface.release();
79 }
80 
81 bool SubSurface::isValid() const
82 {
83  return d->subSurface.isValid();
84 }
85 
86 QPointer< Surface > SubSurface::surface() const
87 {
88  return d->surface;
89 }
90 
91 QPointer< Surface > SubSurface::parentSurface() const
92 {
93  return d->parentSurface;
94 }
95 
96 void SubSurface::setMode(SubSurface::Mode mode)
97 {
98  if (mode == d->mode) {
99  return;
100  }
101  d->mode = mode;
102  switch (d->mode) {
103  case Mode::Synchronized:
104  wl_subsurface_set_sync(d->subSurface);
105  break;
106  case Mode::Desynchronized:
107  wl_subsurface_set_desync(d->subSurface);
108  break;
109  }
110 }
111 
112 SubSurface::Mode SubSurface::mode() const
113 {
114  return d->mode;
115 }
116 
117 void SubSurface::setPosition(const QPoint &pos)
118 {
119  if (pos == d->pos) {
120  return;
121  }
122  d->pos = pos;
123  wl_subsurface_set_position(d->subSurface, pos.x(), pos.y());
124 }
125 
126 QPoint SubSurface::position() const
127 {
128  return d->pos;
129 }
130 
131 void SubSurface::raise()
132 {
133  placeAbove(d->parentSurface);
134 }
135 
136 void SubSurface::placeAbove(QPointer< SubSurface > sibling)
137 {
138  if (sibling.isNull()) {
139  return;
140  }
141  placeAbove(sibling->surface());
142 }
143 
144 void SubSurface::placeAbove(QPointer< Surface > sibling)
145 {
146  if (sibling.isNull()) {
147  return;
148  }
149  wl_subsurface_place_above(d->subSurface, *sibling);
150 }
151 
152 void SubSurface::lower()
153 {
154  placeBelow(d->parentSurface);
155 }
156 
157 void SubSurface::placeBelow(QPointer< Surface > sibling)
158 {
159  if (sibling.isNull()) {
160  return;
161  }
162  wl_subsurface_place_below(d->subSurface, *sibling);
163 }
164 
165 void SubSurface::placeBelow(QPointer< SubSurface > sibling)
166 {
167  if (sibling.isNull()) {
168  return;
169  }
170  placeBelow(sibling->surface());
171 }
172 
173 QPointer< SubSurface > SubSurface::get(wl_subsurface *native)
174 {
175  return QPointer<SubSurface>(Private::cast(native));
176 }
177 
178 SubSurface::operator wl_subsurface*() const
179 {
180  return d->subSurface;
181 }
182 
183 SubSurface::operator wl_subsurface*()
184 {
185  return d->subSurface;
186 }
187 
188 }
189 }
int x() const const
int y() const const
Mode
Operation Mode on how the Surface&#39;s commit should behave.
Definition: subsurface.h:80
bool isNull() const const
QObject * parent() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Aug 3 2020 22:49:42 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.