KWayland

slide_interface.cpp
1 /*
2  SPDX-FileCopyrightText: 2015 Marco Martin <[email protected]>
3 
4  SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
5 */
6 #include "slide_interface.h"
7 #include "display.h"
8 #include "global_p.h"
9 #include "surface_interface.h"
10 #include "resource_p.h"
11 #include "surface_interface_p.h"
12 
13 #include <wayland-server.h>
14 #include <wayland-slide-server-protocol.h>
15 
16 namespace KWayland
17 {
18 namespace Server
19 {
20 
21 class SlideManagerInterface::Private : public Global::Private
22 {
23 public:
24  Private(SlideManagerInterface *q, Display *d);
25 
26 private:
27  void bind(wl_client *client, uint32_t version, uint32_t id) override;
28  void createSlide(wl_client *client, wl_resource *resource, uint32_t id, wl_resource *surface);
29 
30  static void unbind(wl_resource *resource);
31  static Private *cast(wl_resource *r) {
32  return reinterpret_cast<Private*>(wl_resource_get_user_data(r));
33  }
34 
35  static void createCallback(wl_client *client, wl_resource *resource, uint32_t id, wl_resource * surface);
36  static void unsetCallback(wl_client *client, wl_resource *resource, wl_resource * surface);
37 
38  SlideManagerInterface *q;
39  static const struct org_kde_kwin_slide_manager_interface s_interface;
40  //initializing here doesn't link
41  static const quint32 s_version;
42 };
43 
44 const quint32 SlideManagerInterface::Private::s_version = 1;
45 
46 #ifndef K_DOXYGEN
47 const struct org_kde_kwin_slide_manager_interface SlideManagerInterface::Private::s_interface = {
48  createCallback,
49  unsetCallback
50 };
51 #endif
52 
53 void SlideManagerInterface::Private::createCallback(wl_client *client, wl_resource *resource, uint32_t id, wl_resource * surface)
54 {
55  cast(resource)->createSlide(client, resource, id, surface);
56 }
57 
58 void SlideManagerInterface::Private::createSlide(wl_client *client, wl_resource *resource, uint32_t id, wl_resource * surface)
59 {
60  SurfaceInterface *s = SurfaceInterface::get(surface);
61  if (!s) {
62  return;
63  }
64 
65  SlideInterface *slide = new SlideInterface(q, resource);
66  slide->create(display->getConnection(client), wl_resource_get_version(resource), id);
67  if (!slide->resource()) {
68  wl_resource_post_no_memory(resource);
69  delete slide;
70  return;
71  }
72  s->d_func()->setSlide(QPointer<SlideInterface>(slide));
73 }
74 
75 void SlideManagerInterface::Private::unsetCallback(wl_client *client, wl_resource *resource, wl_resource * surface)
76 {
77  Q_UNUSED(client)
78  Q_UNUSED(resource)
79  Q_UNUSED(surface)
80  // TODO: implement
81 }
82 
83 SlideManagerInterface::Private::Private(SlideManagerInterface *q, Display *d)
84  : Global::Private(d, &org_kde_kwin_slide_manager_interface, s_version)
85  , q(q)
86 {
87 }
88 
89 void SlideManagerInterface::Private::bind(wl_client *client, uint32_t version, uint32_t id)
90 {
91  auto c = display->getConnection(client);
92  wl_resource *resource = c->createResource(&org_kde_kwin_slide_manager_interface, qMin(version, s_version), id);
93  if (!resource) {
94  wl_client_post_no_memory(client);
95  return;
96  }
97  wl_resource_set_implementation(resource, &s_interface, this, unbind);
98  // TODO: should we track?
99 }
100 
101 void SlideManagerInterface::Private::unbind(wl_resource *resource)
102 {
103  Q_UNUSED(resource)
104  // TODO: implement?
105 }
106 
107 SlideManagerInterface::SlideManagerInterface(Display *display, QObject *parent)
108  : Global(new Private(this, display), parent)
109 {
110 }
111 
112 SlideManagerInterface::~SlideManagerInterface() = default;
113 
114 class SlideInterface::Private : public Resource::Private
115 {
116 public:
117  Private(SlideInterface *q, SlideManagerInterface *c, wl_resource *parentResource);
118  ~Private();
119 
120  SlideInterface::Location pendingLocation;
121  SlideInterface::Location currentLocation;
122  uint32_t pendingOffset;
123  uint32_t currentOffset;
124 
125 private:
126  static void commitCallback(wl_client *client, wl_resource *resource);
127  static void setLocationCallback(wl_client *client, wl_resource *resource, uint32_t location);
128  static void setOffsetCallback(wl_client *client, wl_resource *resource, int32_t offset);
129 
130  SlideInterface *q_func() {
131  return reinterpret_cast<SlideInterface *>(q);
132  }
133 
134  static const struct org_kde_kwin_slide_interface s_interface;
135 };
136 
137 #ifndef K_DOXYGEN
138 const struct org_kde_kwin_slide_interface SlideInterface::Private::s_interface = {
139  commitCallback,
140  setLocationCallback,
141  setOffsetCallback,
142  resourceDestroyedCallback
143 };
144 #endif
145 
146 void SlideInterface::Private::commitCallback(wl_client *client, wl_resource *resource)
147 {
148  Q_UNUSED(client)
149  Private *p = cast<Private>(resource);
150  p->currentLocation = p->pendingLocation;
151  p->currentOffset = p->pendingOffset;
152 }
153 
154 void SlideInterface::Private::setLocationCallback(wl_client *client, wl_resource *resource, uint32_t location)
155 {
156  Q_UNUSED(client)
157  Private *p = cast<Private>(resource);
158  p->pendingLocation = (SlideInterface::Location)location;
159 }
160 
161 void SlideInterface::Private::setOffsetCallback(wl_client *client, wl_resource *resource, int32_t offset)
162 {
163  Q_UNUSED(client)
164  Private *p = cast<Private>(resource);
165  p->pendingOffset = offset;
166 }
167 
168 SlideInterface::Private::Private(SlideInterface *q, SlideManagerInterface *c, wl_resource *parentResource)
169  : Resource::Private(q, c, parentResource, &org_kde_kwin_slide_interface, &s_interface)
170 {
171 }
172 
173 SlideInterface::Private::~Private() = default;
174 
175 SlideInterface::SlideInterface(SlideManagerInterface *parent, wl_resource *parentResource)
176  : Resource(new Private(this, parent, parentResource))
177 {
178 }
179 
180 SlideInterface::~SlideInterface() = default;
181 
182 
183 SlideInterface::Location SlideInterface::location() const
184 {
185  Q_D();
186  return d->currentLocation;
187 }
188 
189 qint32 SlideInterface::offset() const
190 {
191  Q_D();
192  return d->currentOffset;
193 }
194 
195 SlideInterface::Private *SlideInterface::d_func() const
196 {
197  return reinterpret_cast<Private*>(d.data());
198 }
199 
200 }
201 }
202 
ClientConnection * getConnection(wl_client *client)
Gets the ClientConnection for the given client.
Definition: display.cpp:592
static SurfaceInterface * get(wl_resource *native)
T * data() const const
wl_resource * createResource(const wl_interface *interface, quint32 version, quint32 id)
Creates a new wl_resource for the provided interface.
Display * display()
Definition: global.cpp:79
QObject * parent() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Fri Aug 7 2020 22:48:20 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.