From 2da599c670896b002ccec2e026d6862b1d291104 Mon Sep 17 00:00:00 2001 From: Vlad Zahorodnii Date: Sat, 30 Apr 2022 21:07:05 +0300 Subject: [PATCH] effects/desktopgrid: Make termination code less error prone The desktop grid effect can be deactivated in postPaintScreen() without delaying finish(). --- src/effects/desktopgrid/desktopgrid.cpp | 44 ++++++++++++------------- 1 file changed, 21 insertions(+), 23 deletions(-) diff --git a/src/effects/desktopgrid/desktopgrid.cpp b/src/effects/desktopgrid/desktopgrid.cpp index 885e9e7866..43ec0040a3 100644 --- a/src/effects/desktopgrid/desktopgrid.cpp +++ b/src/effects/desktopgrid/desktopgrid.cpp @@ -232,14 +232,6 @@ void DesktopGridEffect::prePaintScreen(ScreenPrePaintData &data, std::chrono::mi lastPresentTime = presentTime; if (timelineRunning) { timeline.setCurrentTime(timeline.currentTime() + (timeline.direction() == QTimeLine::Forward ? time : -time)); - - if ((timeline.currentTime() <= 0 && timeline.direction() == QTimeLine::Backward)) { - timelineRunning = false; - // defer until the event loop to finish - QTimer::singleShot(0, [this]() { - finish(); - }); - } } for (int i = 0; i < effects->numberOfDesktops(); i++) { auto item = hoverTimeline[i]; @@ -340,21 +332,27 @@ void DesktopGridEffect::postPaintScreen() { bool resetLastPresentTime = true; - if (timelineRunning || activated ? timeline.currentValue() != 1 : timeline.currentValue() != 0) { - effects->addRepaintFull(); // Repaint during zoom - resetLastPresentTime = false; - } - if (isUsingPresentWindows() && isMotionManagerMovingWindows()) { - effects->addRepaintFull(); - resetLastPresentTime = false; - } - if (activated) { - for (int i = 0; i < effects->numberOfDesktops(); i++) { - if (hoverTimeline[i]->currentValue() != 0.0 && hoverTimeline[i]->currentValue() != 1.0) { - // Repaint during soft highlighting - effects->addRepaintFull(); - resetLastPresentTime = false; - break; + const bool finished = timelineRunning && (timeline.currentTime() <= 0 && timeline.direction() == QTimeLine::Backward); + if (finished) { + timelineRunning = false; + finish(); + } else { + if (timelineRunning || activated ? timeline.currentValue() != 1 : timeline.currentValue() != 0) { + effects->addRepaintFull(); // Repaint during zoom + resetLastPresentTime = false; + } + if (isUsingPresentWindows() && isMotionManagerMovingWindows()) { + effects->addRepaintFull(); + resetLastPresentTime = false; + } + if (activated) { + for (int i = 0; i < effects->numberOfDesktops(); i++) { + if (hoverTimeline[i]->currentValue() != 0.0 && hoverTimeline[i]->currentValue() != 1.0) { + // Repaint during soft highlighting + effects->addRepaintFull(); + resetLastPresentTime = false; + break; + } } } }