Changeset View
Changeset View
Standalone View
Standalone View
effects/backgroundcontrast/contrast.cpp
Show All 19 Lines | |||||
20 | */ | 20 | */ | ||
21 | 21 | | |||
22 | #include "contrast.h" | 22 | #include "contrast.h" | ||
23 | #include "contrastshader.h" | 23 | #include "contrastshader.h" | ||
24 | // KConfigSkeleton | 24 | // KConfigSkeleton | ||
25 | 25 | | |||
26 | #include <QMatrix4x4> | 26 | #include <QMatrix4x4> | ||
27 | #include <QLinkedList> | 27 | #include <QLinkedList> | ||
28 | #include <QWindow> | ||||
28 | 29 | | |||
29 | #include <KWayland/Server/surface_interface.h> | 30 | #include <KWayland/Server/surface_interface.h> | ||
30 | #include <KWayland/Server/contrast_interface.h> | 31 | #include <KWayland/Server/contrast_interface.h> | ||
31 | #include <KWayland/Server/display.h> | 32 | #include <KWayland/Server/display.h> | ||
32 | 33 | | |||
33 | namespace KWin | 34 | namespace KWin | ||
34 | { | 35 | { | ||
35 | 36 | | |||
▲ Show 20 Lines • Show All 99 Lines • ▼ Show 20 Line(s) | 108 | { | |||
135 | 136 | | |||
136 | KWayland::Server::SurfaceInterface *surf = w->surface(); | 137 | KWayland::Server::SurfaceInterface *surf = w->surface(); | ||
137 | 138 | | |||
138 | if (surf && surf->contrast()) { | 139 | if (surf && surf->contrast()) { | ||
139 | region = surf->contrast()->region(); | 140 | region = surf->contrast()->region(); | ||
140 | m_colorMatrices[w] = colorMatrix(surf->contrast()->contrast(), surf->contrast()->intensity(), surf->contrast()->saturation()); | 141 | m_colorMatrices[w] = colorMatrix(surf->contrast()->contrast(), surf->contrast()->intensity(), surf->contrast()->saturation()); | ||
141 | } | 142 | } | ||
142 | 143 | | |||
144 | if (auto internal = w->internalWindow()) { | ||||
145 | const auto property = internal->property("kwin_background_region"); | ||||
146 | if (property.isValid()) { | ||||
147 | region = property.value<QRegion>(); | ||||
148 | bool ok = false; | ||||
149 | qreal contrast = internal->property("kwin_background_contrast").toReal(&ok); | ||||
150 | if (!ok) { | ||||
151 | contrast = 1.0; | ||||
152 | } | ||||
153 | qreal intensity = internal->property("kwin_background_intensity").toReal(&ok); | ||||
154 | if (!ok) { | ||||
155 | intensity = 1.0; | ||||
156 | } | ||||
157 | qreal saturation = internal->property("kwin_background_saturation").toReal(&ok); | ||||
158 | if (!ok) { | ||||
159 | saturation = 1.0; | ||||
160 | } | ||||
161 | m_colorMatrices[w] = colorMatrix(contrast, intensity, saturation); | ||||
162 | } | ||||
163 | } | ||||
164 | | ||||
143 | //!value.isNull() full window in X11 case, surf->contrast() | 165 | //!value.isNull() full window in X11 case, surf->contrast() | ||
144 | //valid, full window in wayland case | 166 | //valid, full window in wayland case | ||
145 | if (region.isEmpty() && (!value.isNull() || (surf && surf->contrast()))) { | 167 | if (region.isEmpty() && (!value.isNull() || (surf && surf->contrast()))) { | ||
146 | // Set the data to a dummy value. | 168 | // Set the data to a dummy value. | ||
147 | // This is needed to be able to distinguish between the value not | 169 | // This is needed to be able to distinguish between the value not | ||
148 | // being set, and being set to an empty region. | 170 | // being set, and being set to an empty region. | ||
149 | w->setData(WindowBackgroundContrastRole, 1); | 171 | w->setData(WindowBackgroundContrastRole, 1); | ||
150 | } else | 172 | } else | ||
151 | w->setData(WindowBackgroundContrastRole, region); | 173 | w->setData(WindowBackgroundContrastRole, region); | ||
152 | } | 174 | } | ||
153 | 175 | | |||
154 | void ContrastEffect::slotWindowAdded(EffectWindow *w) | 176 | void ContrastEffect::slotWindowAdded(EffectWindow *w) | ||
155 | { | 177 | { | ||
156 | KWayland::Server::SurfaceInterface *surf = w->surface(); | 178 | KWayland::Server::SurfaceInterface *surf = w->surface(); | ||
157 | 179 | | |||
158 | if (surf) { | 180 | if (surf) { | ||
159 | m_contrastChangedConnections[w] = connect(surf, &KWayland::Server::SurfaceInterface::contrastChanged, this, [this, w] () { | 181 | m_contrastChangedConnections[w] = connect(surf, &KWayland::Server::SurfaceInterface::contrastChanged, this, [this, w] () { | ||
160 | 182 | | |||
161 | if (w) { | 183 | if (w) { | ||
162 | updateContrastRegion(w); | 184 | updateContrastRegion(w); | ||
163 | } | 185 | } | ||
164 | }); | 186 | }); | ||
165 | } | 187 | } | ||
188 | | ||||
189 | if (auto internal = w->internalWindow()) { | ||||
190 | internal->installEventFilter(this); | ||||
191 | } | ||||
192 | | ||||
166 | updateContrastRegion(w); | 193 | updateContrastRegion(w); | ||
167 | } | 194 | } | ||
168 | 195 | | |||
196 | bool ContrastEffect::eventFilter(QObject *watched, QEvent *event) | ||||
197 | { | ||||
198 | auto internal = qobject_cast<QWindow*>(watched); | ||||
199 | if (internal && event->type() == QEvent::DynamicPropertyChange) { | ||||
200 | QDynamicPropertyChangeEvent *pe = static_cast<QDynamicPropertyChangeEvent*>(event); | ||||
201 | if (pe->propertyName() == "kwin_background_region" || | ||||
202 | pe->propertyName() == "kwin_background_contrast" || | ||||
203 | pe->propertyName() == "kwin_background_intensity" || | ||||
204 | pe->propertyName() == "kwin_background_saturation") { | ||||
205 | if (auto w = effects->findWindow(internal)) { | ||||
206 | updateContrastRegion(w); | ||||
207 | } | ||||
208 | } | ||||
209 | } | ||||
210 | return false; | ||||
211 | } | ||||
212 | | ||||
169 | void ContrastEffect::slotWindowDeleted(EffectWindow *w) | 213 | void ContrastEffect::slotWindowDeleted(EffectWindow *w) | ||
170 | { | 214 | { | ||
171 | if (m_contrastChangedConnections.contains(w)) { | 215 | if (m_contrastChangedConnections.contains(w)) { | ||
172 | disconnect(m_contrastChangedConnections[w]); | 216 | disconnect(m_contrastChangedConnections[w]); | ||
173 | m_contrastChangedConnections.remove(w); | 217 | m_contrastChangedConnections.remove(w); | ||
174 | m_colorMatrices.remove(w); | 218 | m_colorMatrices.remove(w); | ||
175 | } | 219 | } | ||
176 | } | 220 | } | ||
▲ Show 20 Lines • Show All 310 Lines • Show Last 20 Lines |