File indexing completed on 2024-12-22 05:09:19
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 "event_queue.h" 0009 #include "region.h" 0010 #include "surface.h" 0011 #include "wayland_pointer_p.h" 0012 0013 #include <wayland-contrast-client-protocol.h> 0014 0015 namespace KWayland 0016 { 0017 namespace Client 0018 { 0019 class Q_DECL_HIDDEN ContrastManager::Private 0020 { 0021 public: 0022 Private() = default; 0023 0024 WaylandPointer<org_kde_kwin_contrast_manager, org_kde_kwin_contrast_manager_destroy> manager; 0025 EventQueue *queue = nullptr; 0026 }; 0027 0028 ContrastManager::ContrastManager(QObject *parent) 0029 : QObject(parent) 0030 , d(new Private) 0031 { 0032 } 0033 0034 ContrastManager::~ContrastManager() 0035 { 0036 release(); 0037 } 0038 0039 void ContrastManager::release() 0040 { 0041 d->manager.release(); 0042 } 0043 0044 void ContrastManager::destroy() 0045 { 0046 d->manager.destroy(); 0047 } 0048 0049 bool ContrastManager::isValid() const 0050 { 0051 return d->manager.isValid(); 0052 } 0053 0054 void ContrastManager::setup(org_kde_kwin_contrast_manager *manager) 0055 { 0056 Q_ASSERT(manager); 0057 Q_ASSERT(!d->manager); 0058 d->manager.setup(manager); 0059 } 0060 0061 void ContrastManager::setEventQueue(EventQueue *queue) 0062 { 0063 d->queue = queue; 0064 } 0065 0066 EventQueue *ContrastManager::eventQueue() 0067 { 0068 return d->queue; 0069 } 0070 0071 Contrast *ContrastManager::createContrast(Surface *surface, QObject *parent) 0072 { 0073 Q_ASSERT(isValid()); 0074 Contrast *s = new Contrast(parent); 0075 auto w = org_kde_kwin_contrast_manager_create(d->manager, *surface); 0076 if (d->queue) { 0077 d->queue->addProxy(w); 0078 } 0079 s->setup(w); 0080 return s; 0081 } 0082 0083 void ContrastManager::removeContrast(Surface *surface) 0084 { 0085 Q_ASSERT(isValid()); 0086 org_kde_kwin_contrast_manager_unset(d->manager, *surface); 0087 } 0088 0089 ContrastManager::operator org_kde_kwin_contrast_manager *() 0090 { 0091 return d->manager; 0092 } 0093 0094 ContrastManager::operator org_kde_kwin_contrast_manager *() const 0095 { 0096 return d->manager; 0097 } 0098 0099 class Contrast::Private 0100 { 0101 public: 0102 WaylandPointer<org_kde_kwin_contrast, org_kde_kwin_contrast_release> contrast; 0103 }; 0104 0105 Contrast::Contrast(QObject *parent) 0106 : QObject(parent) 0107 , d(new Private) 0108 { 0109 } 0110 0111 Contrast::~Contrast() 0112 { 0113 release(); 0114 } 0115 0116 void Contrast::release() 0117 { 0118 d->contrast.release(); 0119 } 0120 0121 void Contrast::setup(org_kde_kwin_contrast *contrast) 0122 { 0123 Q_ASSERT(contrast); 0124 Q_ASSERT(!d->contrast); 0125 d->contrast.setup(contrast); 0126 } 0127 0128 void Contrast::destroy() 0129 { 0130 d->contrast.destroy(); 0131 } 0132 0133 bool Contrast::isValid() const 0134 { 0135 return d->contrast.isValid(); 0136 } 0137 0138 void Contrast::commit() 0139 { 0140 Q_ASSERT(isValid()); 0141 org_kde_kwin_contrast_commit(d->contrast); 0142 } 0143 0144 void Contrast::setRegion(Region *region) 0145 { 0146 org_kde_kwin_contrast_set_region(d->contrast, *region); 0147 } 0148 0149 void Contrast::setContrast(qreal contrast) 0150 { 0151 org_kde_kwin_contrast_set_contrast(d->contrast, wl_fixed_from_double(contrast)); 0152 } 0153 0154 void Contrast::setIntensity(qreal intensity) 0155 { 0156 org_kde_kwin_contrast_set_intensity(d->contrast, wl_fixed_from_double(intensity)); 0157 } 0158 0159 void Contrast::setSaturation(qreal saturation) 0160 { 0161 org_kde_kwin_contrast_set_saturation(d->contrast, wl_fixed_from_double(saturation)); 0162 } 0163 0164 void Contrast::setFrost(QColor frost) 0165 { 0166 if (org_kde_kwin_contrast_get_version(d->contrast) < ORG_KDE_KWIN_CONTRAST_SET_FROST_SINCE_VERSION) { 0167 return; 0168 } 0169 0170 if (frost.isValid()) { 0171 org_kde_kwin_contrast_set_frost(d->contrast, frost.red(), frost.green(), frost.blue(), frost.alpha()); 0172 } else { 0173 org_kde_kwin_contrast_unset_frost(d->contrast); 0174 } 0175 } 0176 0177 Contrast::operator org_kde_kwin_contrast *() 0178 { 0179 return d->contrast; 0180 } 0181 0182 Contrast::operator org_kde_kwin_contrast *() const 0183 { 0184 return d->contrast; 0185 } 0186 0187 } 0188 } 0189 0190 #include "moc_contrast.cpp"