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

KDE's Doxygen guidelines are available online.