KWayland

compositor.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 "compositor.h"
7 #include "event_queue.h"
8 #include "region.h"
9 #include "surface.h"
10 #include "wayland_pointer_p.h"
11 // Qt
12 #include <QGuiApplication>
13 #include <QRegion>
14 #include <qpa/qplatformnativeinterface.h>
15 
16 #include <wayland-client-protocol.h>
17 
18 namespace KWayland
19 {
20 namespace Client
21 {
22 
23 class Q_DECL_HIDDEN Compositor::Private
24 {
25 public:
26  Private() = default;
27 
28  WaylandPointer<wl_compositor, wl_compositor_destroy> compositor;
29  EventQueue *queue = nullptr;
30 };
31 
33  : QObject(parent)
34  , d(new Private)
35 {
36 }
37 
38 Compositor::~Compositor()
39 {
40  release();
41 }
42 
44 {
45  QPlatformNativeInterface *native = qApp->platformNativeInterface();
46  if (!native) {
47  return nullptr;
48  }
49  wl_compositor *compositor = reinterpret_cast<wl_compositor*>(native->nativeResourceForIntegration(QByteArrayLiteral("compositor")));
50  if (!compositor) {
51  return nullptr;
52  }
53  Compositor *c = new Compositor(parent);
54  c->d->compositor.setup(compositor, true);
55  return c;
56 }
57 
58 void Compositor::setup(wl_compositor *compositor)
59 {
60  Q_ASSERT(compositor);
61  Q_ASSERT(!d->compositor);
62  d->compositor.setup(compositor);
63 }
64 
66 {
67  d->compositor.release();
68 }
69 
71 {
72  d->compositor.destroy();
73 }
74 
76 {
77  d->queue = queue;
78 }
79 
81 {
82  return d->queue;
83 }
84 
86 {
87  Q_ASSERT(isValid());
88  Surface *s = new Surface(parent);
89  auto w = wl_compositor_create_surface(d->compositor);
90  if (d->queue) {
91  d->queue->addProxy(w);
92  }
93  s->setup(w);
94  return s;
95 }
96 
98 {
99  return createRegion(QRegion(), parent);
100 }
101 
103 {
104  Q_ASSERT(isValid());
105  Region *r = new Region(region, parent);
106  auto w = wl_compositor_create_region(d->compositor);
107  if (d->queue) {
108  d->queue->addProxy(w);
109  }
110  r->setup(w);
111  return r;
112 }
113 
114 std::unique_ptr< Region > Compositor::createRegion(const QRegion &region)
115 {
116  return std::unique_ptr<Region>(createRegion(region, nullptr));
117 }
118 
119 Compositor::operator wl_compositor*() {
120  return d->compositor;
121 }
122 
123 Compositor::operator wl_compositor*() const {
124  return d->compositor;
125 }
126 
128 {
129  return d->compositor.isValid();
130 }
131 
132 }
133 }
void setup(wl_surface *surface)
Setup this Surface to manage the surface.
Definition: surface.cpp:121
Compositor(QObject *parent=nullptr)
Creates a new Compositor.
Definition: compositor.cpp:32
static Compositor * fromApplication(QObject *parent=nullptr)
Creates a Compositor for the used QGuiApplication.
Definition: compositor.cpp:43
Wrapper class for wl_event_queue interface.
Definition: event_queue.h:55
void destroy()
Destroys the data held by this Compositor.
Definition: compositor.cpp:70
Wrapper for the wl_compositor interface.
Definition: compositor.h:50
Surface * createSurface(QObject *parent=nullptr)
Creates and setup a new Surface with parent.
Definition: compositor.cpp:85
Wrapper for the wl_surface interface.
Definition: surface.h:44
void setEventQueue(EventQueue *queue)
Sets the queue to use for creating a Surface.
Definition: compositor.cpp:75
void setup(wl_compositor *compositor)
Setup this Compositor to manage the compositor.
Definition: compositor.cpp:58
Region * createRegion(QObject *parent=nullptr)
Creates and setup a new Region with parent.
Definition: compositor.cpp:97
void release()
Releases the wl_compositor interface.
Definition: compositor.cpp:65
QObject * parent() const const
Wrapper for the wl_region interface.
Definition: region.h:32
void setup(wl_region *region)
Setup this Surface to manage the region.
Definition: region.cpp:88
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Fri Aug 7 2020 22:48:17 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.