File indexing completed on 2024-05-19 16:34:58
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_interface.h" 0013 #include "wayland/surface_interface.h" 0014 0015 using namespace KWaylandServer; 0016 0017 namespace KWin 0018 { 0019 0020 SubSurfaceMonitor::SubSurfaceMonitor(SurfaceInterface *surface, QObject *parent) 0021 : QObject(parent) 0022 { 0023 registerSurface(surface); 0024 } 0025 0026 void SubSurfaceMonitor::registerSubSurface(SubSurfaceInterface *subSurface) 0027 { 0028 SurfaceInterface *surface = subSurface->surface(); 0029 0030 connect(subSurface, &SubSurfaceInterface::positionChanged, 0031 this, &SubSurfaceMonitor::subSurfaceMoved); 0032 connect(surface, &SurfaceInterface::sizeChanged, 0033 this, &SubSurfaceMonitor::subSurfaceResized); 0034 connect(surface, &SurfaceInterface::mapped, 0035 this, &SubSurfaceMonitor::subSurfaceMapped); 0036 connect(surface, &SurfaceInterface::unmapped, 0037 this, &SubSurfaceMonitor::subSurfaceUnmapped); 0038 connect(surface, &SurfaceInterface::surfaceToBufferMatrixChanged, 0039 this, &SubSurfaceMonitor::subSurfaceSurfaceToBufferMatrixChanged); 0040 connect(surface, &SurfaceInterface::bufferSizeChanged, 0041 this, &SubSurfaceMonitor::subSurfaceBufferSizeChanged); 0042 connect(surface, &SurfaceInterface::committed, 0043 this, [this, subSurface]() { 0044 Q_EMIT subSurfaceCommitted(subSurface); 0045 }); 0046 0047 registerSurface(surface); 0048 } 0049 0050 void SubSurfaceMonitor::unregisterSubSurface(SubSurfaceInterface *subSurface) 0051 { 0052 SurfaceInterface *surface = subSurface->surface(); 0053 if (!surface) { 0054 return; 0055 } 0056 0057 disconnect(subSurface, nullptr, this, nullptr); 0058 0059 unregisterSurface(surface); 0060 } 0061 0062 void SubSurfaceMonitor::registerSurface(SurfaceInterface *surface) 0063 { 0064 connect(surface, &SurfaceInterface::childSubSurfaceAdded, 0065 this, &SubSurfaceMonitor::subSurfaceAdded); 0066 connect(surface, &SurfaceInterface::childSubSurfaceRemoved, 0067 this, &SubSurfaceMonitor::subSurfaceRemoved); 0068 connect(surface, &SurfaceInterface::childSubSurfaceAdded, 0069 this, &SubSurfaceMonitor::registerSubSurface); 0070 connect(surface, &SurfaceInterface::childSubSurfaceRemoved, 0071 this, &SubSurfaceMonitor::unregisterSubSurface); 0072 0073 const QList<SubSurfaceInterface *> below = surface->below(); 0074 for (SubSurfaceInterface *childSubSurface : below) { 0075 registerSubSurface(childSubSurface); 0076 } 0077 0078 const QList<SubSurfaceInterface *> above = surface->above(); 0079 for (SubSurfaceInterface *childSubSurface : above) { 0080 registerSubSurface(childSubSurface); 0081 } 0082 } 0083 0084 void SubSurfaceMonitor::unregisterSurface(SurfaceInterface *surface) 0085 { 0086 disconnect(surface, nullptr, this, nullptr); 0087 } 0088 0089 } // namespace KWin