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

0001 /*
0002     SPDX-FileCopyrightText: 2015 Martin Gräßlin <mgraesslin@kde.org>
0003     SPDX-FileCopyrightText: 2015 Marco Martin <mart@kde.org>
0004     SPDX-FileCopyrightText: 2020 David Edmundson <davidedmundson@kde.org>
0005 
0006     SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0007 */
0008 #include "blur.h"
0009 #include "display.h"
0010 #include "region_p.h"
0011 #include "surface_p.h"
0012 
0013 #include "qwayland-server-blur.h"
0014 
0015 namespace KWin
0016 {
0017 static const quint32 s_version = 1;
0018 
0019 class BlurManagerInterfacePrivate : public QtWaylandServer::org_kde_kwin_blur_manager
0020 {
0021 public:
0022     BlurManagerInterfacePrivate(BlurManagerInterface *q, Display *d);
0023 
0024     BlurManagerInterface *q;
0025 
0026 protected:
0027     void org_kde_kwin_blur_manager_destroy_global() override;
0028     void org_kde_kwin_blur_manager_create(Resource *resource, uint32_t id, wl_resource *surface) override;
0029     void org_kde_kwin_blur_manager_unset(Resource *resource, wl_resource *surface) override;
0030 };
0031 
0032 BlurManagerInterfacePrivate::BlurManagerInterfacePrivate(BlurManagerInterface *_q, Display *d)
0033     : QtWaylandServer::org_kde_kwin_blur_manager(*d, s_version)
0034     , q(_q)
0035 {
0036 }
0037 
0038 void BlurManagerInterfacePrivate::org_kde_kwin_blur_manager_destroy_global()
0039 {
0040     delete q;
0041 }
0042 
0043 void BlurManagerInterfacePrivate::org_kde_kwin_blur_manager_unset(Resource *resource, wl_resource *surface)
0044 {
0045     SurfaceInterface *s = SurfaceInterface::get(surface);
0046     if (!s) {
0047         return;
0048     }
0049     SurfaceInterfacePrivate *surfacePrivate = SurfaceInterfacePrivate::get(s);
0050     surfacePrivate->setBlur(QPointer<BlurInterface>());
0051 }
0052 
0053 void BlurManagerInterfacePrivate::org_kde_kwin_blur_manager_create(Resource *resource, uint32_t id, wl_resource *surface)
0054 {
0055     SurfaceInterface *s = SurfaceInterface::get(surface);
0056     if (!s) {
0057         wl_resource_post_error(resource->handle, 0, "Invalid  surface");
0058         return;
0059     }
0060     wl_resource *blur_resource = wl_resource_create(resource->client(), &org_kde_kwin_blur_interface, resource->version(), id);
0061     if (!blur_resource) {
0062         wl_client_post_no_memory(resource->client());
0063         return;
0064     }
0065     auto blur = new BlurInterface(blur_resource);
0066     SurfaceInterfacePrivate *surfacePrivate = SurfaceInterfacePrivate::get(s);
0067     surfacePrivate->setBlur(blur);
0068 }
0069 
0070 BlurManagerInterface::BlurManagerInterface(Display *display, QObject *parent)
0071     : QObject(parent)
0072     , d(new BlurManagerInterfacePrivate(this, display))
0073 {
0074 }
0075 
0076 BlurManagerInterface::~BlurManagerInterface()
0077 {
0078 }
0079 
0080 void BlurManagerInterface::remove()
0081 {
0082     d->globalRemove();
0083 }
0084 
0085 class BlurInterfacePrivate : public QtWaylandServer::org_kde_kwin_blur
0086 {
0087 public:
0088     BlurInterfacePrivate(BlurInterface *q, wl_resource *resource);
0089     QRegion pendingRegion;
0090     QRegion currentRegion;
0091 
0092     BlurInterface *q;
0093 
0094 protected:
0095     void org_kde_kwin_blur_destroy_resource(Resource *resource) override;
0096     void org_kde_kwin_blur_commit(Resource *resource) override;
0097     void org_kde_kwin_blur_set_region(Resource *resource, wl_resource *region) override;
0098     void org_kde_kwin_blur_release(Resource *resource) override;
0099 };
0100 
0101 void BlurInterfacePrivate::org_kde_kwin_blur_commit(Resource *resource)
0102 {
0103     currentRegion = pendingRegion;
0104 }
0105 
0106 void BlurInterfacePrivate::org_kde_kwin_blur_set_region(Resource *resource, wl_resource *region)
0107 {
0108     RegionInterface *r = RegionInterface::get(region);
0109     if (r) {
0110         pendingRegion = r->region();
0111     } else {
0112         pendingRegion = QRegion();
0113     }
0114 }
0115 
0116 void BlurInterfacePrivate::org_kde_kwin_blur_release(Resource *resource)
0117 {
0118     wl_resource_destroy(resource->handle);
0119 }
0120 
0121 void BlurInterfacePrivate::org_kde_kwin_blur_destroy_resource(Resource *resource)
0122 {
0123     delete q;
0124 }
0125 
0126 BlurInterfacePrivate::BlurInterfacePrivate(BlurInterface *_q, wl_resource *resource)
0127     : QtWaylandServer::org_kde_kwin_blur(resource)
0128     , q(_q)
0129 {
0130 }
0131 
0132 BlurInterface::BlurInterface(wl_resource *resource)
0133     : QObject()
0134     , d(new BlurInterfacePrivate(this, resource))
0135 {
0136 }
0137 
0138 BlurInterface::~BlurInterface() = default;
0139 
0140 QRegion BlurInterface::region()
0141 {
0142     return d->currentRegion;
0143 }
0144 
0145 }
0146 
0147 #include "moc_blur.cpp"