kwin/effects/slidingpopups/slidingpopups.h
Vlad Zagorodniy 653cea5f49 [effects/slidingpopups] Overhaul the animations data struct
Summary:
The existing Data struct has some serious problems:

(a) naming is not intuitive, SlideInterface uses more cleaner terminology
    so let's use that (and because Wayland is the future);

(b) fadeInTime and fadeOutTime should be slideInDuration and slideOutDuration
    respectively. The Sliding popups effect doesn't fade windows, it slides
    them;

(c) mWindowsData should be m_animationsData because other parts of this
    effect refer to it as "anim data"(e.g. setupAnimData).

This effect uses its own Location enum class instead of KWayland::
Server::SlideInterface::Location because it would be better to not
depend on platform specific data structures.

As a side effect, this change also fixes QHash abuse. The Sliding popups
effect is still hashing windows twice in prePaintWindow and paintWindow.
But I think that's acceptable because usually there would be only one
active sliding window.

CCBUG: 331118

Reviewers: #kwin, davidedmundson

Reviewed By: #kwin, davidedmundson

Subscribers: davidedmundson, kwin

Tags: #kwin

Differential Revision: https://phabricator.kde.org/D14301
2018-08-14 11:55:07 +03:00

115 lines
3 KiB
C++

/********************************************************************
KWin - the KDE window manager
This file is part of the KDE project.
Copyright (C) 2009 Marco Martin notmart@gmail.com
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*********************************************************************/
#ifndef KWIN_SLIDINGPOPUPS_H
#define KWIN_SLIDINGPOPUPS_H
// Include with base class for effects.
#include <kwineffects.h>
namespace KWin
{
class SlidingPopupsEffect
: public Effect
{
Q_OBJECT
Q_PROPERTY(int slideInDuration READ slideInDuration)
Q_PROPERTY(int slideOutDuration READ slideOutDuration)
public:
SlidingPopupsEffect();
~SlidingPopupsEffect();
virtual void prePaintWindow(EffectWindow* w, WindowPrePaintData& data, int time);
virtual void paintWindow(EffectWindow* w, int mask, QRegion region, WindowPaintData& data);
virtual void postPaintWindow(EffectWindow* w);
virtual void reconfigure(ReconfigureFlags flags);
virtual bool isActive() const;
int requestedEffectChainPosition() const override {
return 40;
}
static bool supported();
// TODO react also on virtual desktop changes
int slideInDuration() const;
int slideOutDuration() const;
public Q_SLOTS:
void slotWindowAdded(KWin::EffectWindow *c);
void slotWindowDeleted(KWin::EffectWindow *w);
void slotPropertyNotify(KWin::EffectWindow *w, long a);
void slotWaylandSlideOnShowChanged(EffectWindow* w);
void slideIn(EffectWindow *w);
void slideOut(EffectWindow *w);
private:
void setupAnimData(EffectWindow *w);
long mAtom;
int mSlideLength;
std::chrono::milliseconds m_slideInDuration;
std::chrono::milliseconds m_slideOutDuration;
enum class AnimationKind {
In,
Out
};
struct Animation {
AnimationKind kind;
TimeLine timeLine;
};
QHash<const EffectWindow*, Animation> m_animations;
enum class Location {
Left,
Top,
Right,
Bottom
};
struct AnimationData {
int offset;
Location location;
std::chrono::milliseconds slideInDuration;
std::chrono::milliseconds slideOutDuration;
int slideLength;
};
QHash<const EffectWindow*, AnimationData> m_animationsData;
};
inline int SlidingPopupsEffect::slideInDuration() const
{
return m_slideInDuration.count();
}
inline int SlidingPopupsEffect::slideOutDuration() const
{
return m_slideOutDuration.count();
}
} // namespace
#endif