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 "compositor_interface.h"
8 #include "resource_p.h"
9 // Wayland
10 #include <wayland-server.h>
11 
12 namespace KWayland
13 {
14 namespace Server
15 {
16 class RegionInterface::Private : public Resource::Private
17 {
18 public:
19  Private(CompositorInterface *compositor, RegionInterface *q, wl_resource *parentResource);
20  ~Private() override;
21  QRegion qtRegion;
22 
23 private:
24  RegionInterface *q_func()
25  {
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 = {resourceDestroyedCallback, addCallback, subtractCallback};
39 #endif
40 
41 RegionInterface::Private::Private(CompositorInterface *compositor, RegionInterface *q, wl_resource *parentResource)
42  : Resource::Private(q, compositor, parentResource, &wl_region_interface, &s_interface)
43 {
44 }
45 
46 RegionInterface::Private::~Private() = default;
47 
48 void RegionInterface::Private::add(const QRect &rect)
49 {
50  qtRegion = qtRegion.united(rect);
51  Q_Q(RegionInterface);
52  Q_EMIT q->regionChanged(qtRegion);
53 }
54 
55 void RegionInterface::Private::subtract(const QRect &rect)
56 {
57  if (qtRegion.isEmpty()) {
58  return;
59  }
60  qtRegion = qtRegion.subtracted(rect);
61  Q_Q(RegionInterface);
62  Q_EMIT q->regionChanged(qtRegion);
63 }
64 
65 void RegionInterface::Private::addCallback(wl_client *client, wl_resource *r, int32_t x, int32_t y, int32_t width, int32_t height)
66 {
67  Q_UNUSED(client)
68  cast<Private>(r)->add(QRect(x, y, width, height));
69 }
70 
71 void RegionInterface::Private::subtractCallback(wl_client *client, wl_resource *r, int32_t x, int32_t y, int32_t width, int32_t height)
72 {
73  Q_UNUSED(client)
74  cast<Private>(r)->subtract(QRect(x, y, width, height));
75 }
76 
77 RegionInterface::RegionInterface(CompositorInterface *parent, wl_resource *parentResource)
78  : Resource(new Private(parent, this, parentResource))
79 {
80 }
81 
82 RegionInterface::~RegionInterface() = default;
83 
84 QRegion RegionInterface::region() const
85 {
86  Q_D();
87  return d->qtRegion;
88 }
89 
91 {
92  return Private::get<RegionInterface>(native);
93 }
94 
95 RegionInterface::Private *RegionInterface::d_func() const
96 {
97  return reinterpret_cast<Private *>(d.data());
98 }
99 
100 }
101 }
wl_resource * parentResource() const
Definition: resource.cpp:91
ClientConnection * client()
Definition: resource.cpp:76
Resource for the wl_region.
KGuiItem add()
Q_D(Todo)
virtual QVariant get(ScriptableExtension *callerPrincipal, quint64 objId, const QString &propName)
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.