KWayland
10 #include "wayland_pointer_p.h"
12 #include <QGuiApplication>
16 #include <wayland-client-protocol.h>
25 Surface::Private::Private(Surface *q)
30 Surface::Surface(
QObject *parent)
32 , d(new Private(this))
34 Private::s_surfaces <<
this;
39 Private::s_surfaces.removeAll(
this);
59 void Surface::Private::setup(wl_surface *s)
64 wl_surface_add_listener(s, &s_surfaceListener,
this);
67 void Surface::Private::frameCallback(
void *data, wl_callback *callback, uint32_t time)
70 auto s =
reinterpret_cast<Surface::Private *
>(data);
72 wl_callback_destroy(callback);
74 s->handleFrameCallback();
77 void Surface::Private::handleFrameCallback()
79 frameCallbackInstalled =
false;
80 Q_EMIT q->frameRendered();
84 const struct wl_callback_listener Surface::Private::s_listener = {frameCallback};
86 const struct wl_surface_listener Surface::Private::s_surfaceListener = {enterCallback, leaveCallback};
89 void Surface::Private::removeOutput(Output *o)
91 if (o && outputs.removeOne(o)) {
92 Q_EMIT q->outputLeft(o);
96 void Surface::Private::enterCallback(
void *data, wl_surface *surface, wl_output *output)
99 auto s =
reinterpret_cast<Surface::Private *
>(data);
108 Q_EMIT s->q->outputEntered(o);
111 void Surface::Private::leaveCallback(
void *data, wl_surface *surface, wl_output *output)
114 auto s =
reinterpret_cast<Surface::Private *
>(data);
118 void Surface::Private::setupFrameCallback()
120 Q_ASSERT(!frameCallbackInstalled);
121 wl_callback *callback = wl_surface_frame(surface);
122 wl_callback_add_listener(callback, &s_listener,
this);
123 frameCallbackInstalled =
true;
129 d->setupFrameCallback();
135 if (flag == CommitFlag::FrameCallback) {
138 wl_surface_commit(d->surface);
143 for (
const QRect &rect : region) {
151 wl_surface_damage(d->surface, rect.
x(), rect.
y(), rect.
width(), rect.
height());
156 for (
const QRect &r : region) {
164 wl_surface_damage_buffer(d->surface, rect.
x(), rect.
y(), rect.
width(), rect.
height());
170 wl_surface_attach(d->surface, buffer, offset.
x(), offset.
y());
175 attachBuffer(buffer ? buffer->buffer() :
nullptr, offset);
187 wl_surface_set_input_region(d->surface, *region);
189 wl_surface_set_input_region(d->surface,
nullptr);
197 wl_surface_set_opaque_region(d->surface, *region);
199 wl_surface_set_opaque_region(d->surface,
nullptr);
203 void Surface::setSize(
const QSize &size)
205 if (d->size == size) {
209 Q_EMIT sizeChanged(d->size);
214 auto it = std::find_if(Private::s_surfaces.constBegin(), Private::s_surfaces.constEnd(), [native](
Surface *s) {
215 return s->d->surface == native;
217 if (it != Private::s_surfaces.constEnd()) {
225 return Private::s_surfaces;
230 return d->surface.isValid();
233 QSize Surface::size()
const
238 Surface::operator wl_surface *()
243 Surface::operator wl_surface *()
const
250 wl_surface *s = *
this;
251 return wl_proxy_get_id(
reinterpret_cast<wl_proxy *
>(s));
262 wl_surface_set_buffer_scale(d->surface,
scale);
Wrapper for the wl_surface interface.
static Output * get(wl_output *native)
static Surface * get(wl_surface *native)
void setInputRegion(const Region *region=nullptr)
Sets the input region to region.
QVector< Output * > outputs() const
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
Wrapper class for wl_buffer interface.
void setScale(qint32 scale)
The purpose of this method is to allow to supply higher resolution buffer data for use on high resolu...
static const QList< Surface * > & all()
All Surfaces which are currently created.
void destroy()
Destroys the data held by this Surface.
void setup(wl_surface *surface)
Setup this Surface to manage the surface.
void release()
Releases the wl_surface interface.
CommitFlag
Flags to be added to commit.
void setOpaqueRegion(const Region *region=nullptr)
Sets the opaque region to region.
void removed()
The corresponding global for this interface on the Registry got removed.
void damageBuffer(const QRect &rect)
Mark rect in buffer coordinates as damaged for the next frame.
void damage(const QRect &rect)
Mark rect as damaged for the next frame.
QSharedPointer< T > toStrongRef() const const
void attachBuffer(wl_buffer *buffer, const QPoint &offset=QPoint())
Attaches the buffer to this Surface for the next frame.
void setupFrameCallback()
Registers a frame rendered callback.
Wrapper for the wl_region interface.
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Wed Feb 8 2023 03:59:22 by
doxygen 1.8.17 written
by
Dimitri van Heesch, © 1997-2006
KDE's Doxygen guidelines are available online.