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 | // If offset is equal to -1, this effect will decide what offset to use | ||||
217 | // given edge of the screen, from which the window has to slide. | ||||
218 | // | ||||
219 | // If slide in duration is equal to 0 milliseconds, the default slide in | ||||
220 | // duration will be used. Same with the slide out duration. | ||||
221 | // | ||||
222 | // NOTE: If only slide in duration has been provided, then it will be | ||||
223 | // also used as slide out duration. I.e. if you provided only slide in | ||||
224 | // duration, then slide in duration == slide out duration. | ||||
214 | 225 | | |||
215 | if (data.length() < 1) { | 226 | const QByteArray rawAtomData = w->readProperty(m_atom, m_atom, 32); | ||
227 | | ||||
228 | if (rawAtomData.isEmpty()) { | ||||
216 | // Property was removed, thus also remove the effect for window | 229 | // Property was removed, thus also remove the effect for window | ||
217 | if (w->data(WindowClosedGrabRole).value<void *>() == this) { | 230 | if (w->data(WindowClosedGrabRole).value<void *>() == this) { | ||
218 | w->setData(WindowClosedGrabRole, QVariant()); | 231 | w->setData(WindowClosedGrabRole, QVariant()); | ||
219 | } | 232 | } | ||
220 | m_animations.remove(w); | 233 | m_animations.remove(w); | ||
221 | m_animationsData.remove(w); | 234 | m_animationsData.remove(w); | ||
222 | return; | 235 | return; | ||
223 | } | 236 | } | ||
224 | 237 | | |||
225 | const auto *d = reinterpret_cast<const uint32_t *>(data.data()); | 238 | // Offset and location are required. | ||
239 | if (static_cast<size_t>(rawAtomData.size()) < sizeof(uint32_t) * 2) { | ||||
240 | return; | ||||
241 | } | ||||
242 | | ||||
243 | const auto *atomData = reinterpret_cast<const uint32_t *>(rawAtomData.data()); | ||||
226 | AnimationData &animData = m_animationsData[w]; | 244 | AnimationData &animData = m_animationsData[w]; | ||
227 | animData.offset = d[0]; | 245 | animData.offset = atomData[0]; | ||
228 | 246 | | |||
229 | switch (d[1]) { | 247 | switch (atomData[1]) { | ||
230 | case 0: // West | 248 | case 0: // West | ||
231 | animData.location = Location::Left; | 249 | animData.location = Location::Left; | ||
232 | break; | 250 | break; | ||
233 | case 1: // North | 251 | case 1: // North | ||
234 | animData.location = Location::Top; | 252 | animData.location = Location::Top; | ||
235 | break; | 253 | break; | ||
236 | case 2: // East | 254 | case 2: // East | ||
237 | animData.location = Location::Right; | 255 | animData.location = Location::Right; | ||
238 | break; | 256 | break; | ||
239 | case 3: // South | 257 | case 3: // South | ||
240 | default: | 258 | default: | ||
241 | animData.location = Location::Bottom; | 259 | animData.location = Location::Bottom; | ||
242 | break; | 260 | break; | ||
243 | } | 261 | } | ||
244 | 262 | | |||
245 | //custom duration | 263 | if (static_cast<size_t>(rawAtomData.size()) >= sizeof(uint32_t) * 3) { | ||
246 | animData.slideLength = 0; | 264 | animData.slideInDuration = std::chrono::milliseconds(atomData[2]); | ||
247 | if (data.length() >= (int)(sizeof(uint32_t) * 3)) { | 265 | if (static_cast<size_t>(rawAtomData.size()) >= sizeof(uint32_t) * 4) { | ||
248 | animData.slideInDuration = std::chrono::milliseconds(d[2]); | 266 | 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 { | 267 | } else { | ||
253 | //custom fadeout | 268 | 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 | } | 269 | } | ||
261 | } else { | 270 | } else { | ||
262 | animData.slideInDuration = m_slideInDuration; | 271 | animData.slideInDuration = m_slideInDuration; | ||
263 | animData.slideOutDuration = m_slideOutDuration; | 272 | animData.slideOutDuration = m_slideOutDuration; | ||
264 | } | 273 | } | ||
265 | 274 | | |||
275 | if (static_cast<size_t>(rawAtomData.size()) >= sizeof(uint32_t) * 5) { | ||||
276 | animData.slideLength = atomData[4]; | ||||
277 | } else { | ||||
278 | animData.slideLength = 0; | ||||
279 | } | ||||
280 | | ||||
266 | setupAnimData(w); | 281 | setupAnimData(w); | ||
267 | } | 282 | } | ||
268 | 283 | | |||
269 | void SlidingPopupsEffect::setupAnimData(EffectWindow *w) | 284 | void SlidingPopupsEffect::setupAnimData(EffectWindow *w) | ||
270 | { | 285 | { | ||
271 | const QRect screenRect = effects->clientArea(FullScreenArea, w->screen(), effects->currentDesktop()); | 286 | const QRect screenRect = effects->clientArea(FullScreenArea, w->screen(), effects->currentDesktop()); | ||
272 | const QRect windowGeo = w->geometry(); | 287 | const QRect windowGeo = w->geometry(); | ||
273 | AnimationData &animData = m_animationsData[w]; | 288 | AnimationData &animData = m_animationsData[w]; | ||
Show All 27 Lines | 315 | case Location::Right: | |||
301 | animData.offset = qMax(screenRect.right() - windowGeo.right(), animData.offset); | 316 | animData.offset = qMax(screenRect.right() - windowGeo.right(), animData.offset); | ||
302 | break; | 317 | break; | ||
303 | case Location::Bottom: | 318 | case Location::Bottom: | ||
304 | default: | 319 | default: | ||
305 | animData.offset = qMax(screenRect.bottom() - windowGeo.bottom(), animData.offset); | 320 | animData.offset = qMax(screenRect.bottom() - windowGeo.bottom(), animData.offset); | ||
306 | break; | 321 | break; | ||
307 | } | 322 | } | ||
308 | 323 | | |||
324 | animData.slideInDuration = (animData.slideInDuration.count() != 0) | ||||
325 | ? animData.slideInDuration | ||||
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? | |||||
326 | : m_slideInDuration; | ||||
327 | | ||||
328 | animData.slideOutDuration = (animData.slideOutDuration.count() != 0) | ||||
329 | ? animData.slideOutDuration | ||||
330 | : m_slideOutDuration; | ||||
331 | | ||||
309 | // Grab the window, so other windowClosed effects will ignore it | 332 | // Grab the window, so other windowClosed effects will ignore it | ||
310 | w->setData(WindowClosedGrabRole, QVariant::fromValue(static_cast<void*>(this))); | 333 | w->setData(WindowClosedGrabRole, QVariant::fromValue(static_cast<void*>(this))); | ||
311 | } | 334 | } | ||
312 | 335 | | |||
313 | void SlidingPopupsEffect::slotWaylandSlideOnShowChanged(EffectWindow* w) | 336 | void SlidingPopupsEffect::slotWaylandSlideOnShowChanged(EffectWindow* w) | ||
314 | { | 337 | { | ||
315 | if (!w) { | 338 | if (!w) { | ||
316 | return; | 339 | return; | ||
▲ Show 20 Lines • Show All 103 Lines • Show Last 20 Lines |
what's the rationale behind this cap value?