diff --git a/effects/coverswitch/coverswitch.h b/effects/coverswitch/coverswitch.h --- a/effects/coverswitch/coverswitch.h +++ b/effects/coverswitch/coverswitch.h @@ -25,7 +25,6 @@ #include #include #include -#include #include #include @@ -65,7 +64,7 @@ // for properties int configuredAnimationDuration() const { - return animationDuration; + return animationDuration.count(); } bool isAnimateSwitch() const { return animateSwitch; @@ -131,10 +130,10 @@ bool reflection; float mirrorColor[2][4]; bool windowTitle; - int animationDuration; + std::chrono::milliseconds animationDuration; bool stopRequested; bool startRequested; - QTimeLine timeLine; + TimeLine timeLine; QRect area; float zPosition; float scaleFactor; diff --git a/effects/coverswitch/coverswitch.cpp b/effects/coverswitch/coverswitch.cpp --- a/effects/coverswitch/coverswitch.cpp +++ b/effects/coverswitch/coverswitch.cpp @@ -88,14 +88,15 @@ void CoverSwitchEffect::reconfigure(ReconfigureFlags) { CoverSwitchConfig::self()->read(); - animationDuration = animationTime(200); + animationDuration = std::chrono::milliseconds( + animationTime(200)); animateSwitch = CoverSwitchConfig::animateSwitch(); animateStart = CoverSwitchConfig::animateStart(); animateStop = CoverSwitchConfig::animateStop(); reflection = CoverSwitchConfig::reflection(); windowTitle = CoverSwitchConfig::windowTitle(); zPosition = CoverSwitchConfig::zPosition(); - timeLine.setCurveShape(QTimeLine::EaseInOutCurve); + timeLine.setEasingCurve(QEasingCurve::InOutSine); timeLine.setDuration(animationDuration); // Defined outside the ui @@ -120,7 +121,7 @@ if (mActivated || stop || stopRequested) { data.mask |= Effect::PAINT_SCREEN_WITH_TRANSFORMED_WINDOWS; if (animation || start || stop) { - timeLine.setCurrentTime(timeLine.currentTime() + time); + timeLine.update(std::chrono::milliseconds(time)); } if (selected_window == NULL) abort(); @@ -211,9 +212,9 @@ }; // foreground if (start) { - mirrorColor[0][3] = timeLine.currentValue(); + mirrorColor[0][3] = timeLine.value(); } else if (stop) { - mirrorColor[0][3] = 1.0 - timeLine.currentValue(); + mirrorColor[0][3] = 1.0 - timeLine.value(); } else { mirrorColor[0][3] = 1.0; } @@ -274,21 +275,21 @@ if (windowTitle) { double opacity = 1.0; if (start) - opacity = timeLine.currentValue(); + opacity = timeLine.value(); else if (stop) - opacity = 1.0 - timeLine.currentValue(); + opacity = 1.0 - timeLine.value(); if (animation) - captionFrame->setCrossFadeProgress(timeLine.currentValue()); + captionFrame->setCrossFadeProgress(timeLine.value()); captionFrame->render(region, opacity); } } } void CoverSwitchEffect::postPaintScreen() { if ((mActivated && (animation || start)) || stop || stopRequested) { - if (timeLine.currentValue() == 1.0) { - timeLine.setCurrentTime(0); + if (timeLine.done()) { + timeLine.reset(); if (stop) { stop = false; effects->setActiveFullScreenEffect(0); @@ -360,7 +361,7 @@ paintFrontWindow(frontWindow, width, leftWindowCount, rightWindowCount, reflectedWindows); } else { if (direction == Right) { - if (timeLine.currentValue() < 0.5) { + if (timeLine.value() < 0.5) { // paint in normal way paintWindows(leftWindows, true, reflectedWindows); paintWindows(rightWindows, false, reflectedWindows); @@ -372,7 +373,7 @@ } } else { paintWindows(leftWindows, true, reflectedWindows); - if (timeLine.currentValue() < 0.5) { + if (timeLine.value() < 0.5) { paintWindows(rightWindows, false, reflectedWindows); paintFrontWindow(frontWindow, width, leftWindowCount, rightWindowCount, reflectedWindows); } else { @@ -393,18 +394,18 @@ if (mActivated || stop || stopRequested) { if (!(mask & PAINT_WINDOW_TRANSFORMED) && !w->isDesktop()) { if ((start || stop) && w->isDock()) { - data.setOpacity(1.0 - timeLine.currentValue()); + data.setOpacity(1.0 - timeLine.value()); if (stop) - data.setOpacity(timeLine.currentValue()); + data.setOpacity(timeLine.value()); } else return; } } if ((start || stop) && (!w->isOnCurrentDesktop() || w->isMinimized())) { if (stop) // Fade out windows not on the current desktop - data.setOpacity((1.0 - timeLine.currentValue())); + data.setOpacity(1.0 - timeLine.value()); else // Fade in Windows from other desktops when animation is started - data.setOpacity(timeLine.currentValue()); + data.setOpacity(timeLine.value()); } effects->paintWindow(w, mask, region, data); } @@ -541,12 +542,16 @@ } else if (start && scheduled_directions.isEmpty()) { start = false; stop = true; - timeLine.setCurrentTime(timeLine.duration() - timeLine.currentValue()); + timeLine.setElapsed(timeLine.duration() - timeLine.elapsed()); } else { stopRequested = true; } - } else + } else { effects->setActiveFullScreenEffect(0); + start = false; + animation = false; + timeLine.reset(); + } mActivated = false; effects->unrefTabBox(); effects->stopMouseInterception(this); @@ -614,39 +619,39 @@ data.setZTranslation(-zPosition); if (start) { if (w->isMinimized()) { - data.multiplyOpacity(timeLine.currentValue()); + data.multiplyOpacity(timeLine.value()); } else { - const QVector3D translation = data.translation() * timeLine.currentValue(); + const QVector3D translation = data.translation() * timeLine.value(); data.setXTranslation(translation.x()); data.setYTranslation(translation.y()); data.setZTranslation(translation.z()); if (effects->numScreens() > 1) { QRect clientRect = effects->clientArea(FullScreenArea, w->screen(), effects->currentDesktop()); QRect fullRect = effects->clientArea(FullArea, activeScreen, effects->currentDesktop()); if (w->screen() == activeScreen) { if (clientRect.width() != fullRect.width() && clientRect.x() != fullRect.x()) { - data.translate(- clientRect.x() * (1.0f - timeLine.currentValue())); + data.translate(- clientRect.x() * (1.0f - timeLine.value())); } if (clientRect.height() != fullRect.height() && clientRect.y() != fullRect.y()) { - data.translate(0.0, - clientRect.y() * (1.0f - timeLine.currentValue())); + data.translate(0.0, - clientRect.y() * (1.0f - timeLine.value())); } } else { if (clientRect.width() != fullRect.width() && clientRect.x() < area.x()) { - data.translate(- clientRect.width() * (1.0f - timeLine.currentValue())); + data.translate(- clientRect.width() * (1.0f - timeLine.value())); } if (clientRect.height() != fullRect.height() && clientRect.y() < area.y()) { - data.translate(0.0, - clientRect.height() * (1.0f - timeLine.currentValue())); + data.translate(0.0, - clientRect.height() * (1.0f - timeLine.value())); } } } - data.setRotationAngle(data.rotationAngle() * timeLine.currentValue()); + data.setRotationAngle(data.rotationAngle() * timeLine.value()); } } if (stop) { if (w->isMinimized() && w != effects->activeWindow()) { - data.multiplyOpacity((1.0 - timeLine.currentValue())); + data.multiplyOpacity(1.0 - timeLine.value()); } else { - const QVector3D translation = data.translation() * (1.0 - timeLine.currentValue()); + const QVector3D translation = data.translation() * (1.0 - timeLine.value()); data.setXTranslation(translation.x()); data.setYTranslation(translation.y()); data.setZTranslation(translation.z()); @@ -656,21 +661,21 @@ QRect fullRect = effects->clientArea(FullArea, activeScreen, effects->currentDesktop()); if (w->screen() == activeScreen) { if (clientRect.width() != fullRect.width() && clientRect.x() != fullRect.x()) { - data.translate(- clientRect.x() * timeLine.currentValue()); + data.translate(- clientRect.x() * timeLine.value()); } if (clientRect.height() != fullRect.height() && clientRect.y() != fullRect.y()) { - data.translate(0.0, - clientRect.y() * timeLine.currentValue()); + data.translate(0.0, - clientRect.y() * timeLine.value()); } } else { if (clientRect.width() != fullRect.width() && clientRect.x() < rect.x()) { - data.translate(- clientRect.width() * timeLine.currentValue()); + data.translate(- clientRect.width() * timeLine.value()); } if (clientRect.height() != fullRect.height() && clientRect.y() < area.y()) { - data.translate(0.0, - clientRect.height() * timeLine.currentValue()); + data.translate(0.0, - clientRect.height() * timeLine.value()); } } } - data.setRotationAngle(data.rotationAngle() * (1.0 - timeLine.currentValue())); + data.setRotationAngle(data.rotationAngle() * (1.0 - timeLine.value())); } } @@ -680,9 +685,9 @@ data.setModelViewMatrix(reflectionMatrix*data.modelViewMatrix()); data.setYTranslation(- area.height() - windowRect.y() - windowRect.height()); if (start) { - data.multiplyOpacity(timeLine.currentValue()); + data.multiplyOpacity(timeLine.value()); } else if (stop) { - data.multiplyOpacity(1.0 - timeLine.currentValue()); + data.multiplyOpacity(1.0 - timeLine.value()); } effects->drawWindow(w, PAINT_WINDOW_TRANSFORMED, @@ -720,27 +725,26 @@ // move to right distance = -frontWindow->geometry().width() * 0.5f + area.width() * 0.5f + (((float)screenSize.width() * 0.5 * scaleFactor) - (float)area.width() * 0.5f) / rightWindows; - data.translate(distance * timeLine.currentValue()); + data.translate(distance * timeLine.value()); data.setRotationAxis(Qt::YAxis); - data.setRotationAngle(-angle * timeLine.currentValue()); + data.setRotationAngle(-angle * timeLine.value()); data.setRotationOrigin(QVector3D(frontWindow->geometry().width(), 0.0, 0.0)); } else { // move to left distance = frontWindow->geometry().width() * 0.5f - area.width() * 0.5f + ((float)width * 0.5f - ((float)screenSize.width() * 0.5 * scaleFactor)) / leftWindows; float factor = 1.0; if (specialHandlingForward) factor = 2.0; - data.translate(distance * timeLine.currentValue() * factor); + data.translate(distance * timeLine.value() * factor); data.setRotationAxis(Qt::YAxis); - data.setRotationAngle(angle * timeLine.currentValue()); + data.setRotationAngle(angle * timeLine.value()); } } - if (specialHandlingForward) { - data.multiplyOpacity((1.0 - timeLine.currentValue() * 2.0)); - paintWindowCover(frontWindow, reflectedWindow, data); - } else - paintWindowCover(frontWindow, reflectedWindow, data); + if (specialHandlingForward && timeLine.value() < 0.5) { + data.multiplyOpacity(1.0 - timeLine.value() * 2.0); + } + paintWindowCover(frontWindow, reflectedWindow, data); } void CoverSwitchEffect::paintWindows(const EffectWindowList& windows, bool left, bool reflectedWindows, EffectWindow* additionalWindow) @@ -760,7 +764,7 @@ xTranslate = ((float)screenSize.width() * 0.5 * scaleFactor) - (float)width * 0.5f; // handling for additional window from other side // has to appear on this side after half of the time - if (animation && timeLine.currentValue() >= 0.5 && additionalWindow != NULL) { + if (animation && timeLine.value() >= 0.5 && additionalWindow != NULL) { WindowPaintData data(additionalWindow); if (effects->numScreens() > 1) { data.setProjectionMatrix(m_projectionMatrix); @@ -776,7 +780,7 @@ additionalWindow->geometry().x() - additionalWindow->geometry().width()); data.setRotationOrigin(QVector3D(additionalWindow->geometry().width(), 0.0, 0.0)); } - data.multiplyOpacity((timeLine.currentValue() - 0.5) * 2.0); + data.multiplyOpacity((timeLine.value() - 0.5) * 2.0); paintWindowCover(additionalWindow, reflectedWindows, data); } // normal behaviour @@ -801,26 +805,26 @@ if ((i == windowCount - 1) && left) { // right most window on left side -> move to front // have to move one window distance plus half the difference between the window and the desktop size - data.translate((xTranslate / windowCount + (width - window->geometry().width()) * 0.5f) * timeLine.currentValue()); - data.setRotationAngle(angle - angle * timeLine.currentValue()); + data.translate((xTranslate / windowCount + (width - window->geometry().width()) * 0.5f) * timeLine.value()); + data.setRotationAngle(angle - angle * timeLine.value()); } // right most window does not have to be moved else if (!left && (i == 0)); // do nothing else { // all other windows - move to next position - data.translate(xTranslate / windowCount * timeLine.currentValue()); + data.translate(xTranslate / windowCount * timeLine.value()); } } else { if ((i == windowCount - 1) && !left) { // left most window on right side -> move to front - data.translate(- (xTranslate / windowCount + (width - window->geometry().width()) * 0.5f) * timeLine.currentValue()); - data.setRotationAngle(angle - angle * timeLine.currentValue()); + data.translate(- (xTranslate / windowCount + (width - window->geometry().width()) * 0.5f) * timeLine.value()); + data.setRotationAngle(angle - angle * timeLine.value()); } // left most window does not have to be moved else if (i == 0 && left); // do nothing else { // all other windows - move to next position - data.translate(- xTranslate / windowCount * timeLine.currentValue()); + data.translate(- xTranslate / windowCount * timeLine.value()); } } } @@ -830,8 +834,8 @@ // make window most to edge transparent if animation if (animation && i == 0 && ((direction == Left && left) || (direction == Right && !left))) { // only for the first half of the animation - if (timeLine.currentValue() < 0.5) { - data.multiplyOpacity((1.0 - timeLine.currentValue() * 2.0)); + if (timeLine.value() < 0.5) { + data.multiplyOpacity((1.0 - timeLine.value() * 2.0)); paintWindowCover(window, reflectedWindows, data); } } else { @@ -915,6 +919,7 @@ effects->stopMouseInterception(this); } effects->setActiveFullScreenEffect(0); + timeLine.reset(); mActivated = false; stop = false; stopRequested = false;