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

KDE's Doxygen guidelines are available online.