effects/slide: Use an enum to describe current state

This commit is contained in:
Vlad Zahorodnii 2022-05-03 09:25:02 +03:00
parent 4cb3ab09ed
commit 4513b4830f
2 changed files with 27 additions and 22 deletions

View file

@ -98,7 +98,7 @@ void SlideEffect::prePaintScreen(ScreenPrePaintData &data, std::chrono::millisec
m_lastPresentTime = presentTime;
m_timeLine.update(timeDelta);
if (!m_gestureActive) { // When animating
if (m_state == State::ActiveAnimation) {
m_currentPosition = m_startPos + (m_endPos - m_startPos) * m_timeLine.value();
}
@ -306,7 +306,7 @@ void SlideEffect::paintWindow(EffectWindow *w, int mask, QRegion region, WindowP
void SlideEffect::postPaintScreen()
{
if (m_timeLine.done() && !m_gestureActive) {
if (m_state == State::ActiveAnimation && m_timeLine.done()) {
finishedSwitching();
}
@ -361,7 +361,7 @@ void SlideEffect::startAnimation(int old, int current, EffectWindow *movingWindo
}
// Set up animation
m_active = true;
m_state = State::ActiveAnimation;
m_timeLine.reset();
m_startPos = m_currentPosition;
@ -390,7 +390,7 @@ void SlideEffect::startAnimation(int old, int current, EffectWindow *movingWindo
void SlideEffect::finishedSwitching()
{
if (!m_active) {
if (m_state == State::Inactive) {
return;
}
const EffectWindowList windows = effects->stackingOrder();
@ -406,7 +406,7 @@ void SlideEffect::finishedSwitching()
m_paintCtx.fullscreenWindows.clear();
m_movingWindow = nullptr;
m_active = false;
m_state = State::Inactive;
m_lastPresentTime = std::chrono::milliseconds::zero();
effects->setActiveFullScreenEffect(nullptr);
m_currentPosition = effects->desktopGridCoords(effects->currentDesktop());
@ -419,7 +419,6 @@ void SlideEffect::desktopChanged(int old, int current, EffectWindow *with)
return;
}
m_gestureActive = false;
startAnimation(old, current, with);
}
@ -429,7 +428,7 @@ void SlideEffect::desktopChanging(uint old, QPointF desktopOffset, EffectWindow
return;
}
m_gestureActive = true;
m_state = State::ActiveGesture;
m_movingWindow = with;
const bool wrap = effects->optionRollOverDesktops();
@ -445,7 +444,6 @@ void SlideEffect::desktopChanging(uint old, QPointF desktopOffset, EffectWindow
m_currentPosition = moveInsideDesktopGrid(m_currentPosition);
}
m_active = true;
effects->setActiveFullScreenEffect(this);
effects->addRepaintFull();
}
@ -456,7 +454,6 @@ void SlideEffect::desktopChangingCancelled()
return;
}
m_gestureActive = false;
startAnimation(effects->currentDesktop(), effects->currentDesktop(), nullptr);
}
@ -479,7 +476,7 @@ QPointF SlideEffect::moveInsideDesktopGrid(QPointF p)
void SlideEffect::windowAdded(EffectWindow *w)
{
if (!m_active) {
if (m_state == State::Inactive) {
return;
}
if (shouldElevate(w)) {
@ -492,7 +489,7 @@ void SlideEffect::windowAdded(EffectWindow *w)
void SlideEffect::windowDeleted(EffectWindow *w)
{
if (!m_active) {
if (m_state == State::Inactive) {
return;
}
if (w == m_movingWindow) {

View file

@ -64,15 +64,8 @@ public:
void prePaintWindow(EffectWindow *w, WindowPrePaintData &data, std::chrono::milliseconds presentTime) override;
void paintWindow(EffectWindow *w, int mask, QRegion region, WindowPaintData &data) override;
bool isActive() const override
{
return m_active;
}
int requestedEffectChainPosition() const override
{
return 50;
}
bool isActive() const override;
int requestedEffectChainPosition() const override;
static bool supported();
@ -109,7 +102,13 @@ private:
bool m_slideBackground;
int m_fullAnimationDuration; // Miliseconds for 1 complete desktop switch
bool m_active = false;
enum class State {
Inactive,
ActiveAnimation,
ActiveGesture,
};
State m_state = State::Inactive;
TimeLine m_timeLine;
// When the desktop isn't desktopChanging(), these two variables are used to control the animation path.
@ -119,7 +118,6 @@ private:
EffectWindow *m_movingWindow = nullptr;
std::chrono::milliseconds m_lastPresentTime = std::chrono::milliseconds::zero();
bool m_gestureActive = false; // If we're currently animating a gesture
QPointF m_currentPosition; // Should always be kept up to date with where on the grid we're seeing.
struct
@ -162,6 +160,16 @@ inline bool SlideEffect::slideBackground() const
return m_slideBackground;
}
inline bool SlideEffect::isActive() const
{
return m_state != State::Inactive;
}
inline int SlideEffect::requestedEffectChainPosition() const
{
return 50;
}
} // namespace KWin
#endif