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 "resource_p.h"
10 #include "surface_interface.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 class SlideManagerInterface::Private : public Global::Private
21 {
22 public:
23  Private(SlideManagerInterface *q, Display *d);
24 
25 private:
26  void bind(wl_client *client, uint32_t version, uint32_t id) override;
27  void createSlide(wl_client *client, wl_resource *resource, uint32_t id, wl_resource *surface);
28 
29  static void unbind(wl_resource *resource);
30  static Private *cast(wl_resource *r)
31  {
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 = {createCallback, unsetCallback};
48 #endif
49 
50 void SlideManagerInterface::Private::createCallback(wl_client *client, wl_resource *resource, uint32_t id, wl_resource *surface)
51 {
52  cast(resource)->createSlide(client, resource, id, surface);
53 }
54 
55 void SlideManagerInterface::Private::createSlide(wl_client *client, wl_resource *resource, uint32_t id, wl_resource *surface)
56 {
57  SurfaceInterface *s = SurfaceInterface::get(surface);
58  if (!s) {
59  return;
60  }
61 
62  SlideInterface *slide = new SlideInterface(q, resource);
63  slide->create(display->getConnection(client), wl_resource_get_version(resource), id);
64  if (!slide->resource()) {
65  wl_resource_post_no_memory(resource);
66  delete slide;
67  return;
68  }
69  s->d_func()->setSlide(QPointer<SlideInterface>(slide));
70 }
71 
72 void SlideManagerInterface::Private::unsetCallback(wl_client *client, wl_resource *resource, wl_resource *surface)
73 {
74  Q_UNUSED(client)
75  Q_UNUSED(resource)
76  Q_UNUSED(surface)
77  // TODO: implement
78 }
79 
80 SlideManagerInterface::Private::Private(SlideManagerInterface *q, Display *d)
81  : Global::Private(d, &org_kde_kwin_slide_manager_interface, s_version)
82  , q(q)
83 {
84 }
85 
86 void SlideManagerInterface::Private::bind(wl_client *client, uint32_t version, uint32_t id)
87 {
88  auto c = display->getConnection(client);
89  wl_resource *resource = c->createResource(&org_kde_kwin_slide_manager_interface, qMin(version, s_version), id);
90  if (!resource) {
91  wl_client_post_no_memory(client);
92  return;
93  }
94  wl_resource_set_implementation(resource, &s_interface, this, unbind);
95  // TODO: should we track?
96 }
97 
98 void SlideManagerInterface::Private::unbind(wl_resource *resource)
99 {
100  Q_UNUSED(resource)
101  // TODO: implement?
102 }
103 
104 SlideManagerInterface::SlideManagerInterface(Display *display, QObject *parent)
105  : Global(new Private(this, display), parent)
106 {
107 }
108 
109 SlideManagerInterface::~SlideManagerInterface() = default;
110 
111 class SlideInterface::Private : public Resource::Private
112 {
113 public:
114  Private(SlideInterface *q, SlideManagerInterface *c, wl_resource *parentResource);
115  ~Private() override;
116 
117  SlideInterface::Location pendingLocation;
118  SlideInterface::Location currentLocation;
119  uint32_t pendingOffset;
120  uint32_t currentOffset;
121 
122 private:
123  static void commitCallback(wl_client *client, wl_resource *resource);
124  static void setLocationCallback(wl_client *client, wl_resource *resource, uint32_t location);
125  static void setOffsetCallback(wl_client *client, wl_resource *resource, int32_t offset);
126 
127  SlideInterface *q_func()
128  {
129  return reinterpret_cast<SlideInterface *>(q);
130  }
131 
132  static const struct org_kde_kwin_slide_interface s_interface;
133 };
134 
135 #ifndef K_DOXYGEN
136 const struct org_kde_kwin_slide_interface SlideInterface::Private::s_interface = {commitCallback,
137  setLocationCallback,
138  setOffsetCallback,
139  resourceDestroyedCallback};
140 #endif
141 
142 void SlideInterface::Private::commitCallback(wl_client *client, wl_resource *resource)
143 {
144  Q_UNUSED(client)
145  Private *p = cast<Private>(resource);
146  p->currentLocation = p->pendingLocation;
147  p->currentOffset = p->pendingOffset;
148 }
149 
150 void SlideInterface::Private::setLocationCallback(wl_client *client, wl_resource *resource, uint32_t location)
151 {
152  Q_UNUSED(client)
153  Private *p = cast<Private>(resource);
154  p->pendingLocation = (SlideInterface::Location)location;
155 }
156 
157 void SlideInterface::Private::setOffsetCallback(wl_client *client, wl_resource *resource, int32_t offset)
158 {
159  Q_UNUSED(client)
160  Private *p = cast<Private>(resource);
161  p->pendingOffset = offset;
162 }
163 
164 SlideInterface::Private::Private(SlideInterface *q, SlideManagerInterface *c, wl_resource *parentResource)
165  : Resource::Private(q, c, parentResource, &org_kde_kwin_slide_interface, &s_interface)
166 {
167 }
168 
169 SlideInterface::Private::~Private() = default;
170 
171 SlideInterface::SlideInterface(SlideManagerInterface *parent, wl_resource *parentResource)
172  : Resource(new Private(this, parent, parentResource))
173 {
174 }
175 
176 SlideInterface::~SlideInterface() = default;
177 
178 SlideInterface::Location SlideInterface::location() const
179 {
180  Q_D();
181  return d->currentLocation;
182 }
183 
184 qint32 SlideInterface::offset() const
185 {
186  Q_D();
187  return d->currentOffset;
188 }
189 
190 SlideInterface::Private *SlideInterface::d_func() const
191 {
192  return reinterpret_cast<Private *>(d.data());
193 }
194 
195 }
196 }
static SurfaceInterface * get(wl_resource *native)
Q_D(Todo)
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Mon Jan 30 2023 03:56:24 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.