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 0005 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL 0006 */ 0007 #include "contrast.h" 0008 #include "display.h" 0009 #include "region_p.h" 0010 #include "surface_p.h" 0011 0012 #include <qwayland-server-contrast.h> 0013 0014 namespace KWin 0015 { 0016 static const quint32 s_version = 2; 0017 0018 class ContrastManagerInterfacePrivate : public QtWaylandServer::org_kde_kwin_contrast_manager 0019 { 0020 public: 0021 ContrastManagerInterfacePrivate(ContrastManagerInterface *q, Display *display); 0022 0023 ContrastManagerInterface *q; 0024 0025 protected: 0026 void org_kde_kwin_contrast_manager_destroy_global() override; 0027 void org_kde_kwin_contrast_manager_create(Resource *resource, uint32_t id, wl_resource *surface) override; 0028 void org_kde_kwin_contrast_manager_unset(Resource *resource, wl_resource *surface) override; 0029 }; 0030 0031 ContrastManagerInterfacePrivate::ContrastManagerInterfacePrivate(ContrastManagerInterface *q, Display *display) 0032 : QtWaylandServer::org_kde_kwin_contrast_manager(*display, s_version) 0033 , q(q) 0034 { 0035 } 0036 0037 void ContrastManagerInterfacePrivate::org_kde_kwin_contrast_manager_destroy_global() 0038 { 0039 delete q; 0040 } 0041 0042 void ContrastManagerInterfacePrivate::org_kde_kwin_contrast_manager_create(Resource *resource, uint32_t id, wl_resource *surface) 0043 { 0044 SurfaceInterface *s = SurfaceInterface::get(surface); 0045 if (!s) { 0046 wl_resource_post_error(resource->handle, 0, "Invalid surface"); 0047 return; 0048 } 0049 0050 wl_resource *contrast_resource = wl_resource_create(resource->client(), &org_kde_kwin_contrast_interface, resource->version(), id); 0051 if (!contrast_resource) { 0052 wl_client_post_no_memory(resource->client()); 0053 return; 0054 } 0055 auto contrast = new ContrastInterface(contrast_resource); 0056 SurfaceInterfacePrivate *surfacePrivate = SurfaceInterfacePrivate::get(s); 0057 surfacePrivate->setContrast(contrast); 0058 } 0059 0060 void ContrastManagerInterfacePrivate::org_kde_kwin_contrast_manager_unset(Resource *resource, wl_resource *surface) 0061 { 0062 SurfaceInterface *s = SurfaceInterface::get(surface); 0063 if (!s) { 0064 wl_resource_post_error(resource->handle, 0, "Invalid surface"); 0065 return; 0066 } 0067 SurfaceInterfacePrivate *surfacePrivate = SurfaceInterfacePrivate::get(s); 0068 surfacePrivate->setContrast(QPointer<ContrastInterface>()); 0069 } 0070 0071 ContrastManagerInterface::ContrastManagerInterface(Display *display, QObject *parent) 0072 : QObject(parent) 0073 , d(new ContrastManagerInterfacePrivate(this, display)) 0074 { 0075 } 0076 0077 ContrastManagerInterface::~ContrastManagerInterface() 0078 { 0079 } 0080 0081 void ContrastManagerInterface::remove() 0082 { 0083 d->globalRemove(); 0084 } 0085 0086 class ContrastInterfacePrivate : public QtWaylandServer::org_kde_kwin_contrast 0087 { 0088 public: 0089 ContrastInterfacePrivate(ContrastInterface *_q, wl_resource *resource); 0090 0091 QRegion pendingRegion; 0092 QRegion currentRegion; 0093 qreal pendingContrast; 0094 qreal currentContrast; 0095 qreal pendingIntensity; 0096 qreal currentIntensity; 0097 qreal pendingSaturation; 0098 qreal currentSaturation; 0099 QColor currentFrost; 0100 QColor pendingFrost; 0101 ContrastInterface *q; 0102 0103 protected: 0104 void org_kde_kwin_contrast_commit(Resource *resource) override; 0105 void org_kde_kwin_contrast_set_region(Resource *resource, wl_resource *region) override; 0106 void org_kde_kwin_contrast_set_contrast(Resource *resource, wl_fixed_t contrast) override; 0107 void org_kde_kwin_contrast_set_intensity(Resource *resource, wl_fixed_t intensity) override; 0108 void org_kde_kwin_contrast_set_saturation(Resource *resource, wl_fixed_t saturation) override; 0109 void org_kde_kwin_contrast_set_frost(Resource *resource, int r, int g, int b, int a) override; 0110 void org_kde_kwin_contrast_unset_frost(Resource *resource) override; 0111 void org_kde_kwin_contrast_release(Resource *resource) override; 0112 void org_kde_kwin_contrast_destroy_resource(Resource *resource) override; 0113 }; 0114 0115 void ContrastInterfacePrivate::org_kde_kwin_contrast_commit(Resource *resource) 0116 { 0117 currentRegion = pendingRegion; 0118 currentContrast = pendingContrast; 0119 currentIntensity = pendingIntensity; 0120 currentSaturation = pendingSaturation; 0121 currentFrost = pendingFrost; 0122 } 0123 0124 void ContrastInterfacePrivate::org_kde_kwin_contrast_set_region(Resource *resource, wl_resource *region) 0125 { 0126 RegionInterface *r = RegionInterface::get(region); 0127 if (r) { 0128 pendingRegion = r->region(); 0129 } else { 0130 pendingRegion = QRegion(); 0131 } 0132 } 0133 0134 void ContrastInterfacePrivate::org_kde_kwin_contrast_set_contrast(Resource *resource, wl_fixed_t contrast) 0135 { 0136 pendingContrast = wl_fixed_to_double(contrast); 0137 } 0138 0139 void ContrastInterfacePrivate::org_kde_kwin_contrast_set_intensity(Resource *resource, wl_fixed_t intensity) 0140 { 0141 pendingIntensity = wl_fixed_to_double(intensity); 0142 } 0143 0144 void ContrastInterfacePrivate::org_kde_kwin_contrast_set_saturation(Resource *resource, wl_fixed_t saturation) 0145 { 0146 pendingSaturation = wl_fixed_to_double(saturation); 0147 } 0148 0149 void ContrastInterfacePrivate::org_kde_kwin_contrast_set_frost(Resource *resource, int r, int g, int b, int a) 0150 { 0151 pendingFrost = QColor(r, g, b, a); 0152 } 0153 0154 void ContrastInterfacePrivate::org_kde_kwin_contrast_unset_frost(Resource *resource) 0155 { 0156 pendingFrost = {}; 0157 } 0158 0159 void ContrastInterfacePrivate::org_kde_kwin_contrast_release(Resource *resource) 0160 { 0161 wl_resource_destroy(resource->handle); 0162 } 0163 0164 void ContrastInterfacePrivate::org_kde_kwin_contrast_destroy_resource(Resource *resource) 0165 { 0166 delete q; 0167 } 0168 0169 ContrastInterfacePrivate::ContrastInterfacePrivate(ContrastInterface *_q, wl_resource *resource) 0170 : QtWaylandServer::org_kde_kwin_contrast(resource) 0171 , q(_q) 0172 { 0173 } 0174 0175 ContrastInterface::ContrastInterface(wl_resource *resource) 0176 : QObject() 0177 , d(new ContrastInterfacePrivate(this, resource)) 0178 { 0179 } 0180 0181 ContrastInterface::~ContrastInterface() = default; 0182 0183 QRegion ContrastInterface::region() const 0184 { 0185 return d->currentRegion; 0186 } 0187 0188 qreal ContrastInterface::contrast() const 0189 { 0190 return d->currentContrast; 0191 } 0192 0193 qreal ContrastInterface::intensity() const 0194 { 0195 return d->currentIntensity; 0196 } 0197 0198 qreal ContrastInterface::saturation() const 0199 { 0200 return d->currentSaturation; 0201 } 0202 0203 QColor ContrastInterface::frost() const 0204 { 0205 return d->currentFrost; 0206 } 0207 0208 } 0209 0210 #include "moc_contrast.cpp"