File indexing completed on 2024-11-10 04:57:23

0001 /*
0002     KWin - the KDE window manager
0003     This file is part of the KDE project.
0004 
0005     SPDX-FileCopyrightText: 2020 Vlad Zahorodnii <vlad.zahorodnii@kde.org>
0006 
0007     SPDX-License-Identifier: GPL-2.0-or-later
0008 */
0009 
0010 #include "subsurfacemonitor.h"
0011 
0012 #include "wayland/subcompositor.h"
0013 #include "wayland/surface.h"
0014 
0015 namespace KWin
0016 {
0017 
0018 SubSurfaceMonitor::SubSurfaceMonitor(SurfaceInterface *surface, QObject *parent)
0019     : QObject(parent)
0020 {
0021     registerSurface(surface);
0022 }
0023 
0024 void SubSurfaceMonitor::registerSubSurface(SubSurfaceInterface *subSurface)
0025 {
0026     SurfaceInterface *surface = subSurface->surface();
0027 
0028     connect(subSurface, &SubSurfaceInterface::positionChanged,
0029             this, &SubSurfaceMonitor::subSurfaceMoved);
0030     connect(surface, &SurfaceInterface::sizeChanged,
0031             this, &SubSurfaceMonitor::subSurfaceResized);
0032     connect(surface, &SurfaceInterface::mapped,
0033             this, &SubSurfaceMonitor::subSurfaceMapped);
0034     connect(surface, &SurfaceInterface::unmapped,
0035             this, &SubSurfaceMonitor::subSurfaceUnmapped);
0036     connect(surface, &SurfaceInterface::bufferSizeChanged,
0037             this, &SubSurfaceMonitor::subSurfaceBufferSizeChanged);
0038     connect(surface, &SurfaceInterface::committed,
0039             this, [this, subSurface]() {
0040                 Q_EMIT subSurfaceCommitted(subSurface);
0041             });
0042 
0043     registerSurface(surface);
0044 }
0045 
0046 void SubSurfaceMonitor::unregisterSubSurface(SubSurfaceInterface *subSurface)
0047 {
0048     SurfaceInterface *surface = subSurface->surface();
0049     if (!surface) {
0050         return;
0051     }
0052 
0053     disconnect(subSurface, nullptr, this, nullptr);
0054 
0055     unregisterSurface(surface);
0056 }
0057 
0058 void SubSurfaceMonitor::registerSurface(SurfaceInterface *surface)
0059 {
0060     connect(surface, &SurfaceInterface::childSubSurfaceAdded,
0061             this, &SubSurfaceMonitor::subSurfaceAdded);
0062     connect(surface, &SurfaceInterface::childSubSurfaceRemoved,
0063             this, &SubSurfaceMonitor::subSurfaceRemoved);
0064     connect(surface, &SurfaceInterface::childSubSurfaceAdded,
0065             this, &SubSurfaceMonitor::registerSubSurface);
0066     connect(surface, &SurfaceInterface::childSubSurfaceRemoved,
0067             this, &SubSurfaceMonitor::unregisterSubSurface);
0068 
0069     const QList<SubSurfaceInterface *> below = surface->below();
0070     for (SubSurfaceInterface *childSubSurface : below) {
0071         registerSubSurface(childSubSurface);
0072     }
0073 
0074     const QList<SubSurfaceInterface *> above = surface->above();
0075     for (SubSurfaceInterface *childSubSurface : above) {
0076         registerSubSurface(childSubSurface);
0077     }
0078 }
0079 
0080 void SubSurfaceMonitor::unregisterSurface(SurfaceInterface *surface)
0081 {
0082     disconnect(surface, nullptr, this, nullptr);
0083 }
0084 
0085 } // namespace KWin
0086 
0087 #include "moc_subsurfacemonitor.cpp"