Changeset View
Changeset View
Standalone View
Standalone View
effects/slidingpopups/slidingpopups.cpp
Show First 20 Lines • Show All 198 Lines • ▼ Show 20 Line(s) | |||||
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 atom) | ||
208 | { | 208 | { | ||
209 | if (!w || a != m_atom || m_atom == XCB_ATOM_NONE) { | 209 | if (!w || atom != m_atom || m_atom == XCB_ATOM_NONE) { | ||
210 | return; | 210 | return; | ||
211 | } | 211 | } | ||
212 | 212 | | |||
213 | QByteArray data = w->readProperty(m_atom, m_atom, 32); | 213 | // _KDE_SLIDE atom format(each field is an uint32_t): | ||
214 | // <offset> <location> [<slide in duration>] [<slide out duration>] [<slide length>] | ||||
215 | // | ||||
216 | // NOTE: If only slide in duration has been provided, then it will be | ||||
217 | // also used as slide out duration. I.e. if you provided only slide in | ||||
218 | // duration, then slide in duration == slide out duration. | ||||
214 | 219 | | |||
215 | if (data.length() < 1) { | 220 | const QByteArray rawAtomData = w->readProperty(m_atom, m_atom, 32); | ||
221 | | ||||
222 | if (rawAtomData.isEmpty()) { | ||||
216 | // Property was removed, thus also remove the effect for window | 223 | // Property was removed, thus also remove the effect for window | ||
217 | if (w->data(WindowClosedGrabRole).value<void *>() == this) { | 224 | if (w->data(WindowClosedGrabRole).value<void *>() == this) { | ||
218 | w->setData(WindowClosedGrabRole, QVariant()); | 225 | w->setData(WindowClosedGrabRole, QVariant()); | ||
219 | } | 226 | } | ||
220 | m_animations.remove(w); | 227 | m_animations.remove(w); | ||
221 | m_animationsData.remove(w); | 228 | m_animationsData.remove(w); | ||
222 | return; | 229 | return; | ||
223 | } | 230 | } | ||
224 | 231 | | |||
225 | const auto *d = reinterpret_cast<const uint32_t *>(data.data()); | 232 | // Offset and location are required. | ||
233 | if (static_cast<size_t>(rawAtomData.size()) < sizeof(uint32_t) * 2) { | ||||
234 | return; | ||||
235 | } | ||||
236 | | ||||
237 | const auto *atomData = reinterpret_cast<const uint32_t *>(rawAtomData.data()); | ||||
226 | AnimationData &animData = m_animationsData[w]; | 238 | AnimationData &animData = m_animationsData[w]; | ||
227 | animData.offset = d[0]; | 239 | animData.offset = atomData[0]; | ||
228 | 240 | | |||
229 | switch (d[1]) { | 241 | switch (atomData[1]) { | ||
230 | case 0: // West | 242 | case 0: // West | ||
231 | animData.location = Location::Left; | 243 | animData.location = Location::Left; | ||
232 | break; | 244 | break; | ||
233 | case 1: // North | 245 | case 1: // North | ||
234 | animData.location = Location::Top; | 246 | animData.location = Location::Top; | ||
235 | break; | 247 | break; | ||
236 | case 2: // East | 248 | case 2: // East | ||
237 | animData.location = Location::Right; | 249 | animData.location = Location::Right; | ||
238 | break; | 250 | break; | ||
239 | case 3: // South | 251 | case 3: // South | ||
240 | default: | 252 | default: | ||
241 | animData.location = Location::Bottom; | 253 | animData.location = Location::Bottom; | ||
242 | break; | 254 | break; | ||
243 | } | 255 | } | ||
244 | 256 | | |||
245 | //custom duration | 257 | if (static_cast<size_t>(rawAtomData.size()) >= sizeof(uint32_t) * 3) { | ||
246 | animData.slideLength = 0; | 258 | animData.slideInDuration = std::chrono::milliseconds(atomData[2]); | ||
247 | if (data.length() >= (int)(sizeof(uint32_t) * 3)) { | 259 | if (static_cast<size_t>(rawAtomData.size()) >= sizeof(uint32_t) * 4) { | ||
248 | animData.slideInDuration = std::chrono::milliseconds(d[2]); | 260 | animData.slideOutDuration = std::chrono::milliseconds(atomData[3]); | ||
249 | if (data.length() >= (int)(sizeof(uint32_t) * 4)) { | | |||
250 | //custom fadein | | |||
251 | animData.slideOutDuration = std::chrono::milliseconds(d[3]); | | |||
252 | } else { | 261 | } else { | ||
253 | //custom fadeout | 262 | animData.slideOutDuration = animData.slideInDuration; | ||
254 | animData.slideOutDuration = std::chrono::milliseconds(d[2]); | | |||
255 | } | | |||
256 | | ||||
257 | //do we want an actual slide? | | |||
258 | if (data.length() >= (int)(sizeof(uint32_t) * 5)) { | | |||
259 | animData.slideLength = d[4]; | | |||
260 | } | 263 | } | ||
261 | } else { | 264 | } else { | ||
262 | animData.slideInDuration = m_slideInDuration; | 265 | animData.slideInDuration = m_slideInDuration; | ||
263 | animData.slideOutDuration = m_slideOutDuration; | 266 | animData.slideOutDuration = m_slideOutDuration; | ||
264 | } | 267 | } | ||
265 | 268 | | |||
269 | if (static_cast<size_t>(rawAtomData.size()) >= sizeof(uint32_t) * 5) { | ||||
270 | animData.slideLength = atomData[4]; | ||||
271 | } else { | ||||
272 | animData.slideLength = 0; | ||||
273 | } | ||||
274 | | ||||
266 | setupAnimData(w); | 275 | setupAnimData(w); | ||
267 | } | 276 | } | ||
268 | 277 | | |||
269 | void SlidingPopupsEffect::setupAnimData(EffectWindow *w) | 278 | void SlidingPopupsEffect::setupAnimData(EffectWindow *w) | ||
270 | { | 279 | { | ||
271 | const QRect screenRect = effects->clientArea(FullScreenArea, w->screen(), effects->currentDesktop()); | 280 | const QRect screenRect = effects->clientArea(FullScreenArea, w->screen(), effects->currentDesktop()); | ||
272 | const QRect windowGeo = w->geometry(); | 281 | const QRect windowGeo = w->geometry(); | ||
273 | AnimationData &animData = m_animationsData[w]; | 282 | AnimationData &animData = m_animationsData[w]; | ||
Show All 27 Lines | 309 | case Location::Right: | |||
301 | animData.offset = qMax(screenRect.right() - windowGeo.right(), animData.offset); | 310 | animData.offset = qMax(screenRect.right() - windowGeo.right(), animData.offset); | ||
302 | break; | 311 | break; | ||
303 | case Location::Bottom: | 312 | case Location::Bottom: | ||
304 | default: | 313 | default: | ||
305 | animData.offset = qMax(screenRect.bottom() - windowGeo.bottom(), animData.offset); | 314 | animData.offset = qMax(screenRect.bottom() - windowGeo.bottom(), animData.offset); | ||
306 | break; | 315 | break; | ||
307 | } | 316 | } | ||
308 | 317 | | |||
318 | animData.slideInDuration = std::chrono::milliseconds( | ||||
319 | qMax(animData.slideInDuration.count(), 1l)); | ||||
davidedmundson: what's the rationale behind this cap value? | |||||
If I understand your question correctly, you ask why we don't allow to use "0" as a duration? TimeLine will later divide the number number of elapsed milliseconds by this duration (d->elapsed / d->duration), so we have to prevent division by 0. Also, maybe, in this case, we could do something similar to what we do in reconfigure(), e.g. animData.slideInDuration = (animData.slideInDuration().count() != 0) ? animData.slideInDuration : m_slideInDuration; zzag: If I understand your question correctly, you ask why we don't allow to use "0" as a duration? | |||||
320 | | ||||
321 | animData.slideOutDuration = std::chrono::milliseconds( | ||||
322 | qMax(animData.slideOutDuration.count(), 1l)); | ||||
323 | | ||||
309 | // Grab the window, so other windowClosed effects will ignore it | 324 | // Grab the window, so other windowClosed effects will ignore it | ||
310 | w->setData(WindowClosedGrabRole, QVariant::fromValue(static_cast<void*>(this))); | 325 | w->setData(WindowClosedGrabRole, QVariant::fromValue(static_cast<void*>(this))); | ||
311 | } | 326 | } | ||
312 | 327 | | |||
313 | void SlidingPopupsEffect::slotWaylandSlideOnShowChanged(EffectWindow* w) | 328 | void SlidingPopupsEffect::slotWaylandSlideOnShowChanged(EffectWindow* w) | ||
314 | { | 329 | { | ||
315 | if (!w) { | 330 | if (!w) { | ||
316 | return; | 331 | return; | ||
▲ Show 20 Lines • Show All 103 Lines • Show Last 20 Lines |
what's the rationale behind this cap value?