1 /********************************************************************
2 Copyright 2014 Martin Gräßlin <mgraesslin@kde.org>
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) version 3, or any
8 later version accepted by the membership of KDE e.V. (or its
9 successor approved by the membership of KDE e.V.), which shall
10 act as a proxy defined in Section 6 of version 3 of the license.
11
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public
18 License along with this library. If not, see <http://www.gnu.org/licenses/>.
19 *********************************************************************/
20 #include "region.h"
21
22 #include "compositor.h"
23 #include "display.h"
24
25 #include "wayland/resource.h"
26
27 #include <wayland-server.h>
28
29 namespace Wrapland::Server
30 {
31
32 class Region::Private : public Wayland::Resource<Region>
33 {
34 public:
35 Private(Client* client, uint32_t version, uint32_t id, Region* q);
36
37 QRegion qtRegion;
38
39 private:
40 static void addCallback(wl_client* wlClient,
41 wl_resource* wlResource,
42 int32_t x,
43 int32_t y,
44 int32_t width,
45 int32_t height);
46 static void subtractCallback(wl_client* wlClient,
47 wl_resource* wlResource,
48 int32_t x,
49 int32_t y,
50 int32_t width,
51 int32_t height);
52
53 static const struct wl_region_interface s_interface;
54 };
55
56 const struct wl_region_interface Region::Private::s_interface = {
57 destroyCallback,
58 addCallback,
59 subtractCallback,
60 };
61
Private(Client * client,uint32_t version,uint32_t id,Region * q)62 Region::Private::Private(Client* client, uint32_t version, uint32_t id, Region* q)
63 : Wayland::Resource<Region>(client, version, id, &wl_region_interface, &s_interface, q)
64 {
65 }
66
addCallback(wl_client * client,wl_resource * wlResource,int32_t x,int32_t y,int32_t width,int32_t height)67 void Region::Private::addCallback([[maybe_unused]] wl_client* client,
68 wl_resource* wlResource,
69 int32_t x,
70 int32_t y,
71 int32_t width,
72 int32_t height)
73 {
74 auto priv = handle(wlResource)->d_ptr;
75
76 priv->qtRegion = priv->qtRegion.united(QRect(x, y, width, height));
77 Q_EMIT priv->handle()->regionChanged(priv->qtRegion);
78 }
79
subtractCallback(wl_client * wlClient,wl_resource * wlResource,int32_t x,int32_t y,int32_t width,int32_t height)80 void Region::Private::subtractCallback([[maybe_unused]] wl_client* wlClient,
81 wl_resource* wlResource,
82 int32_t x,
83 int32_t y,
84 int32_t width,
85 int32_t height)
86 {
87 auto priv = handle(wlResource)->d_ptr;
88
89 if (priv->qtRegion.isEmpty()) {
90 return;
91 }
92 priv->qtRegion = priv->qtRegion.subtracted(QRect(x, y, width, height));
93 Q_EMIT priv->handle()->regionChanged(priv->qtRegion);
94 }
95
Region(Client * client,uint32_t version,uint32_t id)96 Region::Region(Client* client, uint32_t version, uint32_t id)
97 : QObject(nullptr)
98 , d_ptr(new Private(client, version, id, this))
99 {
100 }
101
region() const102 QRegion Region::region() const
103 {
104 return d_ptr->qtRegion;
105 }
106
get(void * native)107 Region* Region::get(void* native)
108 {
109 return Region::Private::handle(static_cast<wl_resource*>(native));
110 // d_ptr->resou
111 // return Private::get<Region>(native);
112 return nullptr;
113 }
114
client() const115 Client* Region::client() const
116 {
117 return d_ptr->client()->handle();
118 }
119
120 }
121