Changeset View
Changeset View
Standalone View
Standalone View
effects/backgroundcontrast/contrast.cpp
Show First 20 Lines • Show All 52 Lines • ▼ Show 20 Line(s) | 39 | { | |||
---|---|---|---|---|---|
53 | } else { | 53 | } else { | ||
54 | net_wm_contrast_region = 0; | 54 | net_wm_contrast_region = 0; | ||
55 | } | 55 | } | ||
56 | 56 | | |||
57 | connect(effects, SIGNAL(windowAdded(KWin::EffectWindow*)), this, SLOT(slotWindowAdded(KWin::EffectWindow*))); | 57 | connect(effects, SIGNAL(windowAdded(KWin::EffectWindow*)), this, SLOT(slotWindowAdded(KWin::EffectWindow*))); | ||
58 | connect(effects, SIGNAL(windowDeleted(KWin::EffectWindow*)), this, SLOT(slotWindowDeleted(KWin::EffectWindow*))); | 58 | connect(effects, SIGNAL(windowDeleted(KWin::EffectWindow*)), this, SLOT(slotWindowDeleted(KWin::EffectWindow*))); | ||
59 | connect(effects, SIGNAL(propertyNotify(KWin::EffectWindow*,long)), this, SLOT(slotPropertyNotify(KWin::EffectWindow*,long))); | 59 | connect(effects, SIGNAL(propertyNotify(KWin::EffectWindow*,long)), this, SLOT(slotPropertyNotify(KWin::EffectWindow*,long))); | ||
60 | connect(effects, SIGNAL(screenGeometryChanged(QSize)), this, SLOT(slotScreenGeometryChanged())); | 60 | connect(effects, SIGNAL(screenGeometryChanged(QSize)), this, SLOT(slotScreenGeometryChanged())); | ||
61 | connect(effects, &EffectsHandler::xcbConnectionChanged, this, | ||||
62 | [this] { | ||||
63 | if (shader && shader->isValid()) { | ||||
davidedmundson: we should only announce this
if ((shader && shader->isValid())
| |||||
64 | net_wm_contrast_region = effects->announceSupportProperty(s_contrastAtomName, this); | ||||
65 | } | ||||
66 | } | ||||
67 | ); | ||||
61 | 68 | | |||
62 | // Fetch the contrast regions for all windows | 69 | // Fetch the contrast regions for all windows | ||
63 | foreach (EffectWindow *window, effects->stackingOrder()) | 70 | foreach (EffectWindow *window, effects->stackingOrder()) | ||
64 | updateContrastRegion(window); | 71 | updateContrastRegion(window); | ||
65 | } | 72 | } | ||
66 | 73 | | |||
67 | ContrastEffect::~ContrastEffect() | 74 | ContrastEffect::~ContrastEffect() | ||
68 | { | 75 | { | ||
Show All 18 Lines | 91 | if (!shader || !shader->isValid()) { | |||
87 | m_contrastManager = nullptr; | 94 | m_contrastManager = nullptr; | ||
88 | } | 95 | } | ||
89 | } | 96 | } | ||
90 | 97 | | |||
91 | void ContrastEffect::updateContrastRegion(EffectWindow *w) | 98 | void ContrastEffect::updateContrastRegion(EffectWindow *w) | ||
92 | { | 99 | { | ||
93 | QRegion region; | 100 | QRegion region; | ||
94 | float colorTransform[16]; | 101 | float colorTransform[16]; | ||
102 | QByteArray value; | ||||
95 | 103 | | |||
96 | const QByteArray value = w->readProperty(net_wm_contrast_region, net_wm_contrast_region, 32); | 104 | if (net_wm_contrast_region != XCB_ATOM_NONE) { | ||
105 | value = w->readProperty(net_wm_contrast_region, net_wm_contrast_region, 32); | ||||
97 | 106 | | |||
98 | if (value.size() > 0 && !((value.size() - (16 * sizeof(uint32_t))) % ((4 * sizeof(uint32_t))))) { | 107 | if (value.size() > 0 && !((value.size() - (16 * sizeof(uint32_t))) % ((4 * sizeof(uint32_t))))) { | ||
99 | const uint32_t *cardinals = reinterpret_cast<const uint32_t*>(value.constData()); | 108 | const uint32_t *cardinals = reinterpret_cast<const uint32_t*>(value.constData()); | ||
100 | const float *floatCardinals = reinterpret_cast<const float*>(value.constData()); | 109 | const float *floatCardinals = reinterpret_cast<const float*>(value.constData()); | ||
101 | unsigned int i = 0; | 110 | unsigned int i = 0; | ||
102 | for (; i < ((value.size() - (16 * sizeof(uint32_t)))) / sizeof(uint32_t);) { | 111 | for (; i < ((value.size() - (16 * sizeof(uint32_t)))) / sizeof(uint32_t);) { | ||
103 | int x = cardinals[i++]; | 112 | int x = cardinals[i++]; | ||
104 | int y = cardinals[i++]; | 113 | int y = cardinals[i++]; | ||
105 | int w = cardinals[i++]; | 114 | int w = cardinals[i++]; | ||
106 | int h = cardinals[i++]; | 115 | int h = cardinals[i++]; | ||
107 | region += QRect(x, y, w, h); | 116 | region += QRect(x, y, w, h); | ||
108 | } | 117 | } | ||
109 | 118 | | |||
110 | for (unsigned int j = 0; j < 16; ++j) { | 119 | for (unsigned int j = 0; j < 16; ++j) { | ||
111 | colorTransform[j] = floatCardinals[i + j]; | 120 | colorTransform[j] = floatCardinals[i + j]; | ||
112 | } | 121 | } | ||
113 | 122 | | |||
114 | QMatrix4x4 colorMatrix(colorTransform); | 123 | QMatrix4x4 colorMatrix(colorTransform); | ||
115 | m_colorMatrices[w] = colorMatrix; | 124 | m_colorMatrices[w] = colorMatrix; | ||
116 | } | 125 | } | ||
126 | } | ||||
117 | 127 | | |||
118 | KWayland::Server::SurfaceInterface *surf = w->surface(); | 128 | KWayland::Server::SurfaceInterface *surf = w->surface(); | ||
119 | 129 | | |||
120 | if (surf && surf->contrast()) { | 130 | if (surf && surf->contrast()) { | ||
121 | region = surf->contrast()->region(); | 131 | region = surf->contrast()->region(); | ||
122 | m_colorMatrices[w] = colorMatrix(surf->contrast()->contrast(), surf->contrast()->intensity(), surf->contrast()->saturation()); | 132 | m_colorMatrices[w] = colorMatrix(surf->contrast()->contrast(), surf->contrast()->intensity(), surf->contrast()->saturation()); | ||
123 | } | 133 | } | ||
124 | 134 | | |||
Show All 29 Lines | 163 | if (m_contrastChangedConnections.contains(w)) { | |||
154 | disconnect(m_contrastChangedConnections[w]); | 164 | disconnect(m_contrastChangedConnections[w]); | ||
155 | m_contrastChangedConnections.remove(w); | 165 | m_contrastChangedConnections.remove(w); | ||
156 | m_colorMatrices.remove(w); | 166 | m_colorMatrices.remove(w); | ||
157 | } | 167 | } | ||
158 | } | 168 | } | ||
159 | 169 | | |||
160 | void ContrastEffect::slotPropertyNotify(EffectWindow *w, long atom) | 170 | void ContrastEffect::slotPropertyNotify(EffectWindow *w, long atom) | ||
161 | { | 171 | { | ||
162 | if (w && atom == net_wm_contrast_region) { | 172 | if (w && atom == net_wm_contrast_region && net_wm_contrast_region != XCB_ATOM_NONE) { | ||
163 | updateContrastRegion(w); | 173 | updateContrastRegion(w); | ||
164 | } | 174 | } | ||
165 | } | 175 | } | ||
166 | 176 | | |||
167 | QMatrix4x4 ContrastEffect::colorMatrix(qreal contrast, qreal intensity, qreal saturation) | 177 | QMatrix4x4 ContrastEffect::colorMatrix(qreal contrast, qreal intensity, qreal saturation) | ||
168 | { | 178 | { | ||
169 | QMatrix4x4 satMatrix; //saturation | 179 | QMatrix4x4 satMatrix; //saturation | ||
170 | QMatrix4x4 intMatrix; //intensity | 180 | QMatrix4x4 intMatrix; //intensity | ||
▲ Show 20 Lines • Show All 298 Lines • Show Last 20 Lines |
we should only announce this
if ((shader && shader->isValid())