KWaylandServer

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 "surface_interface_p.h"
9 
10 #include <qwayland-server-slide.h>
11 
12 namespace KWaylandServer
13 {
14 static const quint32 s_version = 1;
15 
16 class SlideManagerInterfacePrivate : public QtWaylandServer::org_kde_kwin_slide_manager
17 {
18 public:
19  SlideManagerInterfacePrivate(SlideManagerInterface *_q, Display *display);
20 
21  SlideManagerInterface *q;
22 
23 protected:
24  void org_kde_kwin_slide_manager_destroy_global() override;
25  void org_kde_kwin_slide_manager_create(Resource *resource, uint32_t id, wl_resource *surface) override;
26  void org_kde_kwin_slide_manager_unset(Resource *resource, wl_resource *surface) override;
27 };
28 
29 void SlideManagerInterfacePrivate::org_kde_kwin_slide_manager_destroy_global()
30 {
31  delete q;
32 }
33 
34 void SlideManagerInterfacePrivate::org_kde_kwin_slide_manager_create(Resource *resource, uint32_t id, wl_resource *surface)
35 {
36  SurfaceInterface *s = SurfaceInterface::get(surface);
37  if (!s) {
38  wl_resource_post_error(resource->handle, 0, "Invalid surface");
39  return;
40  }
41 
42  wl_resource *slide_resource = wl_resource_create(resource->client(), &org_kde_kwin_slide_interface, resource->version(), id);
43  if (!slide_resource) {
44  wl_client_post_no_memory(resource->client());
45  return;
46  }
47 
48  auto slide = new SlideInterface(q, slide_resource);
49  SurfaceInterfacePrivate *surfacePrivate = SurfaceInterfacePrivate::get(s);
50  surfacePrivate->setSlide(QPointer<SlideInterface>(slide));
51 }
52 
53 void SlideManagerInterfacePrivate::org_kde_kwin_slide_manager_unset(Resource *resource, wl_resource *surface)
54 {
55  SurfaceInterface *s = SurfaceInterface::get(surface);
56  if (!s) {
57  wl_resource_post_error(resource->handle, 0, "Invalid surface");
58  return;
59  }
60  SurfaceInterfacePrivate *surfacePrivate = SurfaceInterfacePrivate::get(s);
61  surfacePrivate->setSlide(QPointer<SlideInterface>());
62 }
63 
64 SlideManagerInterfacePrivate::SlideManagerInterfacePrivate(SlideManagerInterface *_q, Display *display)
65  : QtWaylandServer::org_kde_kwin_slide_manager(*display, s_version)
66  , q(_q)
67 {
68 }
69 
70 SlideManagerInterface::SlideManagerInterface(Display *display, QObject *parent)
71  : QObject(parent)
72  , d(new SlideManagerInterfacePrivate(this, display))
73 {
74 }
75 
76 SlideManagerInterface::~SlideManagerInterface()
77 {
78 }
79 
80 void SlideManagerInterface::remove()
81 {
82  d->globalRemove();
83 }
84 
85 class SlideInterfacePrivate : public QtWaylandServer::org_kde_kwin_slide
86 {
87 public:
88  SlideInterfacePrivate(SlideInterface *_q, wl_resource *resource);
89 
90  SlideInterface::Location pendingLocation;
91  SlideInterface::Location currentLocation;
92  uint32_t pendingOffset;
93  uint32_t currentOffset;
94  SlideInterface *q;
95 
96 protected:
97  void org_kde_kwin_slide_commit(Resource *resource) override;
98  void org_kde_kwin_slide_set_location(Resource *resource, uint32_t location) override;
99  void org_kde_kwin_slide_set_offset(Resource *resource, int32_t offset) override;
100  void org_kde_kwin_slide_release(Resource *resource) override;
101  void org_kde_kwin_slide_destroy_resource(Resource *resource) override;
102 };
103 
104 void SlideInterfacePrivate::org_kde_kwin_slide_commit(Resource *resource)
105 {
106  Q_UNUSED(resource)
107  currentLocation = pendingLocation;
108  currentOffset = pendingOffset;
109 }
110 
111 void SlideInterfacePrivate::org_kde_kwin_slide_set_location(Resource *resource, uint32_t location)
112 {
113  Q_UNUSED(resource)
114  pendingLocation = (SlideInterface::Location)location;
115 }
116 
117 void SlideInterfacePrivate::org_kde_kwin_slide_set_offset(Resource *resource, int32_t offset)
118 {
119  Q_UNUSED(resource)
120  pendingOffset = offset;
121 }
122 
123 void SlideInterfacePrivate::org_kde_kwin_slide_release(Resource *resource)
124 {
125  wl_resource_destroy(resource->handle);
126 }
127 
128 void SlideInterfacePrivate::org_kde_kwin_slide_destroy_resource(Resource *resource)
129 {
130  Q_UNUSED(resource)
131  delete q;
132 }
133 
134 SlideInterfacePrivate::SlideInterfacePrivate(SlideInterface *_q, wl_resource *resource)
135  : QtWaylandServer::org_kde_kwin_slide(resource)
136  , q(_q)
137 {
138 }
139 
140 SlideInterface::SlideInterface(SlideManagerInterface *manager, wl_resource *resource)
141  : QObject(manager)
142  , d(new SlideInterfacePrivate(this, resource))
143 {
144 }
145 
146 SlideInterface::~SlideInterface() = default;
147 
148 SlideInterface::Location SlideInterface::location() const
149 {
150  return d->currentLocation;
151 }
152 
153 qint32 SlideInterface::offset() const
154 {
155  return d->currentOffset;
156 }
157 
158 }
static SurfaceInterface * get(wl_resource *native)
QObject * parent() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Sat Oct 23 2021 23:08:28 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.