Changeset View
Changeset View
Standalone View
Standalone View
effects/slidingpopups/slidingpopups.cpp
Show All 33 Lines | |||||
34 | SlidingPopupsEffect::SlidingPopupsEffect() | 34 | SlidingPopupsEffect::SlidingPopupsEffect() | ||
35 | { | 35 | { | ||
36 | initConfig<SlidingPopupsConfig>(); | 36 | initConfig<SlidingPopupsConfig>(); | ||
37 | KWayland::Server::Display *display = effects->waylandDisplay(); | 37 | KWayland::Server::Display *display = effects->waylandDisplay(); | ||
38 | if (display) { | 38 | if (display) { | ||
39 | display->createSlideManager(this)->create(); | 39 | display->createSlideManager(this)->create(); | ||
40 | } | 40 | } | ||
41 | 41 | | |||
42 | mSlideLength = QFontMetrics(qApp->font()).height() * 8; | 42 | m_slideLength = QFontMetrics(qApp->font()).height() * 8; | ||
43 | 43 | | |||
44 | mAtom = effects->announceSupportProperty("_KDE_SLIDE", this); | 44 | m_atom = effects->announceSupportProperty("_KDE_SLIDE", this); | ||
45 | connect(effects, &EffectsHandler::windowAdded, this, &SlidingPopupsEffect::slotWindowAdded); | 45 | connect(effects, &EffectsHandler::windowAdded, this, &SlidingPopupsEffect::slotWindowAdded); | ||
46 | connect(effects, &EffectsHandler::windowClosed, this, &SlidingPopupsEffect::slideOut); | 46 | connect(effects, &EffectsHandler::windowClosed, this, &SlidingPopupsEffect::slideOut); | ||
47 | connect(effects, &EffectsHandler::windowDeleted, this, &SlidingPopupsEffect::slotWindowDeleted); | 47 | connect(effects, &EffectsHandler::windowDeleted, this, &SlidingPopupsEffect::slotWindowDeleted); | ||
48 | connect(effects, &EffectsHandler::propertyNotify, this, &SlidingPopupsEffect::slotPropertyNotify); | 48 | connect(effects, &EffectsHandler::propertyNotify, this, &SlidingPopupsEffect::slotPropertyNotify); | ||
49 | connect(effects, &EffectsHandler::windowShown, this, &SlidingPopupsEffect::slideIn); | 49 | connect(effects, &EffectsHandler::windowShown, this, &SlidingPopupsEffect::slideIn); | ||
50 | connect(effects, &EffectsHandler::windowHidden, this, &SlidingPopupsEffect::slideOut); | 50 | connect(effects, &EffectsHandler::windowHidden, this, &SlidingPopupsEffect::slideOut); | ||
51 | connect(effects, &EffectsHandler::xcbConnectionChanged, this, | 51 | connect(effects, &EffectsHandler::xcbConnectionChanged, this, | ||
52 | [this] { | 52 | [this] { | ||
53 | mAtom = effects->announceSupportProperty(QByteArrayLiteral("_KDE_SLIDE"), this); | 53 | m_atom = effects->announceSupportProperty(QByteArrayLiteral("_KDE_SLIDE"), this); | ||
54 | } | 54 | } | ||
55 | ); | 55 | ); | ||
56 | reconfigure(ReconfigureAll); | 56 | reconfigure(ReconfigureAll); | ||
57 | } | 57 | } | ||
58 | 58 | | |||
59 | SlidingPopupsEffect::~SlidingPopupsEffect() | 59 | SlidingPopupsEffect::~SlidingPopupsEffect() | ||
60 | { | 60 | { | ||
61 | } | 61 | } | ||
Show All 24 Lines | 69 | { | |||
86 | auto dataIt = m_animationsData.begin(); | 86 | auto dataIt = m_animationsData.begin(); | ||
87 | while (dataIt != m_animationsData.end()) { | 87 | while (dataIt != m_animationsData.end()) { | ||
88 | (*dataIt).slideInDuration = m_slideInDuration; | 88 | (*dataIt).slideInDuration = m_slideInDuration; | ||
89 | (*dataIt).slideOutDuration = m_slideOutDuration; | 89 | (*dataIt).slideOutDuration = m_slideOutDuration; | ||
90 | ++dataIt; | 90 | ++dataIt; | ||
91 | } | 91 | } | ||
92 | } | 92 | } | ||
93 | 93 | | |||
94 | void SlidingPopupsEffect::prePaintWindow(EffectWindow* w, WindowPrePaintData& data, int time) | 94 | void SlidingPopupsEffect::prePaintWindow(EffectWindow *w, WindowPrePaintData &data, int time) | ||
95 | { | 95 | { | ||
96 | auto animationIt = m_animations.find(w); | 96 | auto animationIt = m_animations.find(w); | ||
97 | if (animationIt == m_animations.end()) { | 97 | if (animationIt == m_animations.end()) { | ||
98 | effects->prePaintWindow(w, data, time); | 98 | effects->prePaintWindow(w, data, time); | ||
99 | return; | 99 | return; | ||
100 | } | 100 | } | ||
101 | 101 | | |||
102 | (*animationIt).timeLine.update(std::chrono::milliseconds(time)); | 102 | (*animationIt).timeLine.update(std::chrono::milliseconds(time)); | ||
103 | data.setTransformed(); | 103 | data.setTransformed(); | ||
104 | w->enablePainting(EffectWindow::PAINT_DISABLED | EffectWindow::PAINT_DISABLED_BY_DELETE); | 104 | w->enablePainting(EffectWindow::PAINT_DISABLED | EffectWindow::PAINT_DISABLED_BY_DELETE); | ||
105 | 105 | | |||
106 | effects->prePaintWindow(w, data, time); | 106 | effects->prePaintWindow(w, data, time); | ||
107 | } | 107 | } | ||
108 | 108 | | |||
109 | void SlidingPopupsEffect::paintWindow(EffectWindow* w, int mask, QRegion region, WindowPaintData& data) | 109 | void SlidingPopupsEffect::paintWindow(EffectWindow *w, int mask, QRegion region, WindowPaintData &data) | ||
110 | { | 110 | { | ||
111 | auto animationIt = m_animations.constFind(w); | 111 | auto animationIt = m_animations.constFind(w); | ||
112 | if (animationIt == m_animations.constEnd()) { | 112 | if (animationIt == m_animations.constEnd()) { | ||
113 | effects->paintWindow(w, mask, region, data); | 113 | effects->paintWindow(w, mask, region, data); | ||
114 | return; | 114 | return; | ||
115 | } | 115 | } | ||
116 | 116 | | |||
117 | const AnimationData &animData = m_animationsData[w]; | 117 | const AnimationData &animData = m_animationsData[w]; | ||
118 | const int slideLength = (animData.slideLength > 0) ? animData.slideLength : mSlideLength; | 118 | const int slideLength = (animData.slideLength > 0) ? animData.slideLength : m_slideLength; | ||
119 | 119 | | |||
120 | const QRect screenRect = effects->clientArea(FullScreenArea, w->screen(), w->desktop()); | 120 | const QRect screenRect = effects->clientArea(FullScreenArea, w->screen(), w->desktop()); | ||
121 | int splitPoint = 0; | 121 | int splitPoint = 0; | ||
122 | const QRect geo = w->expandedGeometry(); | 122 | const QRect geo = w->expandedGeometry(); | ||
123 | const qreal t = (*animationIt).timeLine.value(); | 123 | const qreal t = (*animationIt).timeLine.value(); | ||
124 | 124 | | |||
125 | switch(animData.location) { | 125 | switch (animData.location) { | ||
126 | case Location::Left: | 126 | case Location::Left: | ||
127 | if (slideLength < geo.width()) { | 127 | if (slideLength < geo.width()) { | ||
128 | data.multiplyOpacity(t); | 128 | data.multiplyOpacity(t); | ||
129 | } | 129 | } | ||
130 | data.translate(-interpolate(qMin(geo.width(), slideLength), 0.0, t)); | 130 | data.translate(-interpolate(qMin(geo.width(), slideLength), 0.0, t)); | ||
131 | splitPoint = geo.width() - (geo.x() + geo.width() - screenRect.x() - animData.offset); | 131 | splitPoint = geo.width() - (geo.x() + geo.width() - screenRect.x() - animData.offset); | ||
132 | region = QRegion(geo.x() + splitPoint, geo.y(), geo.width() - splitPoint, geo.height()); | 132 | region = QRegion(geo.x() + splitPoint, geo.y(), geo.width() - splitPoint, geo.height()); | ||
133 | break; | 133 | break; | ||
Show All 21 Lines | 151 | default: | |||
155 | data.translate(0.0, interpolate(qMin(geo.height(), slideLength), 0.0, t)); | 155 | data.translate(0.0, interpolate(qMin(geo.height(), slideLength), 0.0, t)); | ||
156 | splitPoint = screenRect.y() + screenRect.height() - geo.y() - animData.offset; | 156 | splitPoint = screenRect.y() + screenRect.height() - geo.y() - animData.offset; | ||
157 | region = QRegion(geo.x(), geo.y(), geo.width(), splitPoint); | 157 | region = QRegion(geo.x(), geo.y(), geo.width(), splitPoint); | ||
158 | } | 158 | } | ||
159 | 159 | | |||
160 | effects->paintWindow(w, mask, region, data); | 160 | effects->paintWindow(w, mask, region, data); | ||
161 | } | 161 | } | ||
162 | 162 | | |||
163 | void SlidingPopupsEffect::postPaintWindow(EffectWindow* w) | 163 | void SlidingPopupsEffect::postPaintWindow(EffectWindow *w) | ||
164 | { | 164 | { | ||
165 | auto animationIt = m_animations.find(w); | 165 | auto animationIt = m_animations.find(w); | ||
166 | if (animationIt != m_animations.end()) { | 166 | if (animationIt != m_animations.end()) { | ||
167 | if ((*animationIt).timeLine.done()) { | 167 | if ((*animationIt).timeLine.done()) { | ||
168 | if (w->isDeleted()) { | 168 | if (w->isDeleted()) { | ||
169 | w->unrefWindow(); | 169 | w->unrefWindow(); | ||
170 | } else { | 170 | } else { | ||
171 | w->setData(WindowForceBackgroundContrastRole, QVariant()); | 171 | w->setData(WindowForceBackgroundContrastRole, QVariant()); | ||
172 | w->setData(WindowForceBlurRole, QVariant()); | 172 | w->setData(WindowForceBlurRole, QVariant()); | ||
173 | } | 173 | } | ||
174 | m_animations.erase(animationIt); | 174 | m_animations.erase(animationIt); | ||
175 | } | 175 | } | ||
176 | w->addRepaintFull(); | 176 | w->addRepaintFull(); | ||
177 | } | 177 | } | ||
178 | 178 | | |||
179 | effects->postPaintWindow(w); | 179 | effects->postPaintWindow(w); | ||
180 | } | 180 | } | ||
181 | 181 | | |||
182 | void SlidingPopupsEffect::slotWindowAdded(EffectWindow *w) | 182 | void SlidingPopupsEffect::slotWindowAdded(EffectWindow *w) | ||
183 | { | 183 | { | ||
184 | //X11 | 184 | //X11 | ||
185 | if (mAtom != XCB_ATOM_NONE) { | 185 | if (m_atom != XCB_ATOM_NONE) { | ||
186 | slotPropertyNotify(w, mAtom); | 186 | slotPropertyNotify(w, m_atom); | ||
187 | } | 187 | } | ||
188 | 188 | | |||
189 | //Wayland | 189 | //Wayland | ||
190 | if (auto surf = w->surface()) { | 190 | if (auto surf = w->surface()) { | ||
191 | slotWaylandSlideOnShowChanged(w); | 191 | slotWaylandSlideOnShowChanged(w); | ||
192 | connect(surf, &KWayland::Server::SurfaceInterface::slideOnShowHideChanged, this, [this, surf] { | 192 | connect(surf, &KWayland::Server::SurfaceInterface::slideOnShowHideChanged, this, [this, surf] { | ||
193 | slotWaylandSlideOnShowChanged(effects->findWindow(surf)); | 193 | slotWaylandSlideOnShowChanged(effects->findWindow(surf)); | ||
194 | }); | 194 | }); | ||
195 | } | 195 | } | ||
196 | 196 | | |||
197 | slideIn(w); | 197 | slideIn(w); | ||
198 | } | 198 | } | ||
199 | 199 | | |||
200 | void SlidingPopupsEffect::slotWindowDeleted(EffectWindow* w) | 200 | void SlidingPopupsEffect::slotWindowDeleted(EffectWindow *w) | ||
201 | { | 201 | { | ||
202 | m_animations.remove(w); | 202 | m_animations.remove(w); | ||
203 | m_animationsData.remove(w); | 203 | m_animationsData.remove(w); | ||
204 | effects->addRepaint(w->expandedGeometry()); | 204 | effects->addRepaint(w->expandedGeometry()); | ||
205 | } | 205 | } | ||
206 | 206 | | |||
207 | void SlidingPopupsEffect::slotPropertyNotify(EffectWindow* w, long a) | 207 | void SlidingPopupsEffect::slotPropertyNotify(EffectWindow *w, long a) | ||
208 | { | 208 | { | ||
209 | if (!w || a != mAtom || mAtom == XCB_ATOM_NONE) | 209 | if (!w || a != m_atom || m_atom == XCB_ATOM_NONE) { | ||
210 | return; | 210 | return; | ||
211 | } | ||||
211 | 212 | | |||
212 | QByteArray data = w->readProperty(mAtom, mAtom, 32); | 213 | QByteArray data = w->readProperty(m_atom, m_atom, 32); | ||
213 | 214 | | |||
214 | if (data.length() < 1) { | 215 | if (data.length() < 1) { | ||
215 | // Property was removed, thus also remove the effect for window | 216 | // Property was removed, thus also remove the effect for window | ||
216 | if (w->data(WindowClosedGrabRole).value<void *>() == this) { | 217 | if (w->data(WindowClosedGrabRole).value<void *>() == this) { | ||
217 | w->setData(WindowClosedGrabRole, QVariant()); | 218 | w->setData(WindowClosedGrabRole, QVariant()); | ||
218 | } | 219 | } | ||
219 | m_animations.remove(w); | 220 | m_animations.remove(w); | ||
220 | m_animationsData.remove(w); | 221 | m_animationsData.remove(w); | ||
221 | return; | 222 | return; | ||
222 | } | 223 | } | ||
223 | 224 | | |||
224 | auto* d = reinterpret_cast< uint32_t* >(data.data()); | 225 | const auto *d = reinterpret_cast<const uint32_t *>(data.data()); | ||
225 | AnimationData &animData = m_animationsData[w]; | 226 | AnimationData &animData = m_animationsData[w]; | ||
226 | animData.offset = d[ 0 ]; | 227 | animData.offset = d[0]; | ||
227 | 228 | | |||
228 | switch (d[1]) { | 229 | switch (d[1]) { | ||
229 | case 0: // West | 230 | case 0: // West | ||
230 | animData.location = Location::Left; | 231 | animData.location = Location::Left; | ||
231 | break; | 232 | break; | ||
232 | case 1: // North | 233 | case 1: // North | ||
233 | animData.location = Location::Top; | 234 | animData.location = Location::Top; | ||
234 | break; | 235 | break; | ||
235 | case 2: // East | 236 | case 2: // East | ||
236 | animData.location = Location::Right; | 237 | animData.location = Location::Right; | ||
237 | break; | 238 | break; | ||
238 | case 3: // South | 239 | case 3: // South | ||
239 | default: | 240 | default: | ||
240 | animData.location = Location::Bottom; | 241 | animData.location = Location::Bottom; | ||
241 | break; | 242 | break; | ||
242 | } | 243 | } | ||
243 | 244 | | |||
244 | //custom duration | 245 | //custom duration | ||
245 | animData.slideLength = 0; | 246 | animData.slideLength = 0; | ||
246 | if (data.length() >= (int)(sizeof(uint32_t) * 3)) { | 247 | if (data.length() >= (int)(sizeof(uint32_t) * 3)) { | ||
247 | animData.slideInDuration = std::chrono::milliseconds(d[2]); | 248 | animData.slideInDuration = std::chrono::milliseconds(d[2]); | ||
248 | if (data.length() >= (int)(sizeof(uint32_t) * 4)) | 249 | if (data.length() >= (int)(sizeof(uint32_t) * 4)) { | ||
249 | //custom fadein | 250 | //custom fadein | ||
250 | animData.slideOutDuration = std::chrono::milliseconds(d[3]); | 251 | animData.slideOutDuration = std::chrono::milliseconds(d[3]); | ||
251 | else | 252 | } else { | ||
252 | //custom fadeout | 253 | //custom fadeout | ||
253 | animData.slideOutDuration = std::chrono::milliseconds(d[2]); | 254 | animData.slideOutDuration = std::chrono::milliseconds(d[2]); | ||
255 | } | ||||
254 | 256 | | |||
255 | //do we want an actual slide? | 257 | //do we want an actual slide? | ||
256 | if (data.length() >= (int)(sizeof(uint32_t) * 5)) | 258 | if (data.length() >= (int)(sizeof(uint32_t) * 5)) { | ||
257 | animData.slideLength = d[4]; | 259 | animData.slideLength = d[4]; | ||
260 | } | ||||
258 | } else { | 261 | } else { | ||
259 | animData.slideInDuration = m_slideInDuration; | 262 | animData.slideInDuration = m_slideInDuration; | ||
260 | animData.slideOutDuration = m_slideOutDuration; | 263 | animData.slideOutDuration = m_slideOutDuration; | ||
261 | } | 264 | } | ||
262 | 265 | | |||
263 | setupAnimData(w); | 266 | setupAnimData(w); | ||
264 | } | 267 | } | ||
265 | 268 | | |||
▲ Show 20 Lines • Show All 151 Lines • Show Last 20 Lines |