KWayland

xdgdecoration.cpp
1 /*
2  SPDX-FileCopyrightText: 2018 David Edmundson <[email protected]>
3 
4  SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
5 */
6 #include "xdgdecoration.h"
7 
8 #include "event_queue.h"
9 #include "wayland_pointer_p.h"
10 #include "xdgshell.h"
11 
12 #include <QDebug>
13 
14 #include "wayland-xdg-decoration-unstable-v1-client-protocol.h"
15 
16 namespace KWayland
17 {
18 namespace Client
19 {
20 
21 class Q_DECL_HIDDEN XdgDecorationManager::Private
22 {
23 public:
24  Private() = default;
25 
26  void setup(zxdg_decoration_manager_v1 *arg);
27 
28  WaylandPointer<zxdg_decoration_manager_v1, zxdg_decoration_manager_v1_destroy> xdgdecorationmanager;
29  EventQueue *queue = nullptr;
30 };
31 
33  : QObject(parent)
34  , d(new Private)
35 {
36 }
37 
38 void XdgDecorationManager::Private::setup(zxdg_decoration_manager_v1 *arg)
39 {
40  Q_ASSERT(arg);
41  Q_ASSERT(!xdgdecorationmanager);
42  xdgdecorationmanager.setup(arg);
43 }
44 
45 XdgDecorationManager::~XdgDecorationManager()
46 {
47  release();
48 }
49 
50 void XdgDecorationManager::setup(zxdg_decoration_manager_v1 *xdgdecorationmanager)
51 {
52  d->setup(xdgdecorationmanager);
53 }
54 
56 {
57  d->xdgdecorationmanager.release();
58 }
59 
61 {
62  d->xdgdecorationmanager.destroy();
63 }
64 
65 XdgDecorationManager::operator zxdg_decoration_manager_v1*() {
66  return d->xdgdecorationmanager;
67 }
68 
69 XdgDecorationManager::operator zxdg_decoration_manager_v1*() const {
70  return d->xdgdecorationmanager;
71 }
72 
74 {
75  return d->xdgdecorationmanager.isValid();
76 }
77 
79 {
80  d->queue = queue;
81 }
82 
84 {
85  return d->queue;
86 }
87 
88 XdgDecoration *XdgDecorationManager::getToplevelDecoration(XdgShellSurface *toplevel, QObject *parent)
89 {
90  Q_ASSERT(isValid());
91  xdg_toplevel *toplevel_resource = *toplevel;
92  if (!toplevel_resource) { //i.e using XDGShellV5
93  qWarning() << "Trying to create an XdgDecoration without an XDGShell stable toplevel object";
94  return nullptr;
95  }
96  auto p = new XdgDecoration(parent);
97  auto w = zxdg_decoration_manager_v1_get_toplevel_decoration(d->xdgdecorationmanager, toplevel_resource);
98  if (d->queue) {
99  d->queue->addProxy(w);
100  }
101  p->setup(w);
102  return p;
103 }
104 
105 class Q_DECL_HIDDEN XdgDecoration::Private
106 {
107 public:
108  Private(XdgDecoration *q);
109 
110  void setup(zxdg_toplevel_decoration_v1 *arg);
111 
112  WaylandPointer<zxdg_toplevel_decoration_v1, zxdg_toplevel_decoration_v1_destroy> xdgdecoration;
113 
114  XdgDecoration::Mode m_mode = XdgDecoration::Mode::ClientSide;
115 private:
116  XdgDecoration *q;
117 
118 private:
119  static void configureCallback(void *data, zxdg_toplevel_decoration_v1 *zxdg_toplevel_decoration_v1, uint32_t mode);
120 
121  static const zxdg_toplevel_decoration_v1_listener s_listener;
122 };
123 
124 const zxdg_toplevel_decoration_v1_listener XdgDecoration::Private::s_listener = {
125  configureCallback
126 };
127 
128 void XdgDecoration::Private::configureCallback(void *data, zxdg_toplevel_decoration_v1 *zxdg_toplevel_decoration_v1, uint32_t m)
129 {
130  auto p = reinterpret_cast<XdgDecoration::Private*>(data);
131  Q_ASSERT(p->xdgdecoration == zxdg_toplevel_decoration_v1);
132  switch (m) {
133  case ZXDG_TOPLEVEL_DECORATION_V1_MODE_CLIENT_SIDE:
134  p->m_mode = XdgDecoration::Mode::ClientSide;
135  break;
136  case ZXDG_TOPLEVEL_DECORATION_V1_MODE_SERVER_SIDE:
137  p->m_mode = XdgDecoration::Mode::ServerSide;
138  break;
139  }
140  emit p->q->modeChanged(p->m_mode);
141 }
142 
143 XdgDecoration::Private::Private(XdgDecoration *q)
144  : q(q)
145 {
146 }
147 
148 XdgDecoration::XdgDecoration(QObject *parent)
149  : QObject(parent)
150  , d(new Private(this))
151 {
152 }
153 
154 void XdgDecoration::Private::setup(zxdg_toplevel_decoration_v1 *arg)
155 {
156  Q_ASSERT(arg);
157  Q_ASSERT(!xdgdecoration);
158  xdgdecoration.setup(arg);
159  zxdg_toplevel_decoration_v1_add_listener(xdgdecoration, &s_listener, this);
160 }
161 
162 XdgDecoration::~XdgDecoration()
163 {
164  release();
165 }
166 
167 void XdgDecoration::setup(zxdg_toplevel_decoration_v1 *xdgdecoration)
168 {
169  d->setup(xdgdecoration);
170 }
171 
172 void XdgDecoration::release()
173 {
174  d->xdgdecoration.release();
175 }
176 
177 void XdgDecoration::destroy()
178 {
179  d->xdgdecoration.destroy();
180 }
181 
182 XdgDecoration::operator zxdg_toplevel_decoration_v1*() {
183  return d->xdgdecoration;
184 }
185 
186 XdgDecoration::operator zxdg_toplevel_decoration_v1*() const {
187  return d->xdgdecoration;
188 }
189 
190 bool XdgDecoration::isValid() const
191 {
192  return d->xdgdecoration.isValid();
193 }
194 
195 void XdgDecoration::setMode(XdgDecoration::Mode mode)
196 {
197  Q_ASSERT(isValid());
198  uint32_t mode_raw;
199  switch (mode) {
200  case XdgDecoration::Mode::ClientSide:
201  mode_raw = ZXDG_TOPLEVEL_DECORATION_V1_MODE_CLIENT_SIDE;
202  break;
203  default:
204  mode_raw = ZXDG_TOPLEVEL_DECORATION_V1_MODE_SERVER_SIDE;
205  break;
206  }
207  zxdg_toplevel_decoration_v1_set_mode(d->xdgdecoration, mode_raw);
208 }
209 
210 void XdgDecoration::unsetMode()
211 {
212  Q_ASSERT(isValid());
213  zxdg_toplevel_decoration_v1_unset_mode(d->xdgdecoration);
214 }
215 
216 XdgDecoration::Mode XdgDecoration::mode() const
217 {
218  return d->m_mode;
219 }
220 
221 
222 }
223 }
224 
Wrapper class for wl_event_queue interface.
Definition: event_queue.h:55
void setup(zxdg_decoration_manager_v1 *xdgdecorationmanager)
Setup this XdgDecorationManager to manage the xdgdecorationmanager.
void setEventQueue(EventQueue *queue)
Sets the queue to use for creating objects with this XdgDecorationManager.
void release()
Releases the zxdg_decoration_manager_v1 interface.
QObject(QObject *parent)
void destroy()
Destroys the data held by this XdgDecorationManager.
XdgDecorationManager(QObject *parent=nullptr)
Creates a new XdgDecorationManager.
QObject * parent() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Fri Jul 10 2020 22:48:35 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.