File indexing completed on 2024-12-22 05:09:24

0001 /*
0002     SPDX-FileCopyrightText: 2014 Martin Gräßlin <mgraesslin@kde.org>
0003 
0004     SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0005 */
0006 #include "subcompositor.h"
0007 #include "event_queue.h"
0008 #include "subsurface.h"
0009 #include "surface.h"
0010 #include "wayland_pointer_p.h"
0011 // Wayland
0012 #include <wayland-client-protocol.h>
0013 
0014 namespace KWayland
0015 {
0016 namespace Client
0017 {
0018 class Q_DECL_HIDDEN SubCompositor::Private
0019 {
0020 public:
0021     WaylandPointer<wl_subcompositor, wl_subcompositor_destroy> subCompositor;
0022     EventQueue *queue = nullptr;
0023 };
0024 
0025 SubCompositor::SubCompositor(QObject *parent)
0026     : QObject(parent)
0027     , d(new Private)
0028 {
0029 }
0030 
0031 SubCompositor::~SubCompositor()
0032 {
0033     release();
0034 }
0035 
0036 void SubCompositor::release()
0037 {
0038     d->subCompositor.release();
0039 }
0040 
0041 void SubCompositor::destroy()
0042 {
0043     d->subCompositor.destroy();
0044 }
0045 
0046 void SubCompositor::setup(wl_subcompositor *subcompositor)
0047 {
0048     Q_ASSERT(subcompositor);
0049     Q_ASSERT(!d->subCompositor.isValid());
0050     d->subCompositor.setup(subcompositor);
0051 }
0052 
0053 SubSurface *SubCompositor::createSubSurface(QPointer<Surface> surface, QPointer<Surface> parentSurface, QObject *parent)
0054 {
0055     Q_ASSERT(isValid());
0056     SubSurface *s = new SubSurface(surface, parentSurface, parent);
0057     auto w = wl_subcompositor_get_subsurface(d->subCompositor, *surface, *parentSurface);
0058     if (d->queue) {
0059         d->queue->addProxy(w);
0060     }
0061     s->setup(w);
0062     return s;
0063 }
0064 
0065 bool SubCompositor::isValid() const
0066 {
0067     return d->subCompositor.isValid();
0068 }
0069 
0070 SubCompositor::operator wl_subcompositor *()
0071 {
0072     return d->subCompositor;
0073 }
0074 
0075 SubCompositor::operator wl_subcompositor *() const
0076 {
0077     return d->subCompositor;
0078 }
0079 
0080 EventQueue *SubCompositor::eventQueue()
0081 {
0082     return d->queue;
0083 }
0084 
0085 void SubCompositor::setEventQueue(EventQueue *queue)
0086 {
0087     d->queue = queue;
0088 }
0089 
0090 }
0091 }
0092 
0093 #include "moc_subcompositor.cpp"