KWayland

region_interface.cpp
1 /*
2  SPDX-FileCopyrightText: 2014 Martin Gräßlin <[email protected]>
3 
4  SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
5 */
6 #include "region_interface.h"
7 #include "resource_p.h"
8 #include "compositor_interface.h"
9 // Wayland
10 #include <wayland-server.h>
11 
12 namespace KWayland
13 {
14 namespace Server
15 {
16 
17 class RegionInterface::Private : public Resource::Private
18 {
19 public:
20  Private(CompositorInterface *compositor, RegionInterface *q, wl_resource *parentResource);
21  ~Private();
22  QRegion qtRegion;
23 
24 private:
25  RegionInterface *q_func() {
26  return reinterpret_cast<RegionInterface*>(q);
27  }
28  void add(const QRect &rect);
29  void subtract(const QRect &rect);
30 
31  static void addCallback(wl_client *client, wl_resource *r, int32_t x, int32_t y, int32_t width, int32_t height);
32  static void subtractCallback(wl_client *client, wl_resource *r, int32_t x, int32_t y, int32_t width, int32_t height);
33 
34  static const struct wl_region_interface s_interface;
35 };
36 
37 #ifndef K_DOXYGEN
38 const struct wl_region_interface RegionInterface::Private::s_interface = {
39  resourceDestroyedCallback,
40  addCallback,
41  subtractCallback
42 };
43 #endif
44 
45 RegionInterface::Private::Private(CompositorInterface *compositor, RegionInterface *q, wl_resource *parentResource)
46  : Resource::Private(q, compositor, parentResource, &wl_region_interface, &s_interface)
47 {
48 }
49 
50 RegionInterface::Private::~Private() = default;
51 
52 void RegionInterface::Private::add(const QRect &rect)
53 {
54  qtRegion = qtRegion.united(rect);
55  Q_Q(RegionInterface);
56  emit q->regionChanged(qtRegion);
57 }
58 
59 void RegionInterface::Private::subtract(const QRect &rect)
60 {
61  if (qtRegion.isEmpty()) {
62  return;
63  }
64  qtRegion = qtRegion.subtracted(rect);
65  Q_Q(RegionInterface);
66  emit q->regionChanged(qtRegion);
67 }
68 
69 void RegionInterface::Private::addCallback(wl_client *client, wl_resource *r, int32_t x, int32_t y, int32_t width, int32_t height)
70 {
71  Q_UNUSED(client)
72  cast<Private>(r)->add(QRect(x, y, width, height));
73 }
74 
75 void RegionInterface::Private::subtractCallback(wl_client *client, wl_resource *r, int32_t x, int32_t y, int32_t width, int32_t height)
76 {
77  Q_UNUSED(client)
78  cast<Private>(r)->subtract(QRect(x, y, width, height));
79 }
80 
81 RegionInterface::RegionInterface(CompositorInterface *parent, wl_resource *parentResource)
82  : Resource(new Private(parent, this, parentResource))
83 {
84 }
85 
86 RegionInterface::~RegionInterface() = default;
87 
88 QRegion RegionInterface::region() const
89 {
90  Q_D();
91  return d->qtRegion;
92 }
93 
94 RegionInterface *RegionInterface::get(wl_resource *native)
95 {
96  return Private::get<RegionInterface>(native);
97 }
98 
99 RegionInterface::Private *RegionInterface::d_func() const
100 {
101  return reinterpret_cast<Private*>(d.data());
102 }
103 
104 }
105 }
KIOFILEWIDGETS_EXPORT void add(const QString &fileClass, const QString &directory)
wl_resource * parentResource() const
Definition: resource.cpp:93
Resource for the wl_region.
void subtract(const QRect &rect)
Subtracts rect from this Region.
Definition: region.cpp:112
T * data() const const
ClientConnection * client()
Definition: resource.cpp:78
QObject * parent() const const
void add(const QRect &rect)
Adds the rect to this Region.
Definition: region.cpp:100
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Fri Aug 7 2020 22:48:19 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.