KWin
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Static Public Member Functions | Protected Types | Protected Member Functions | List of all members
KWin::AnimationEffect Class Reference

#include <animationeffect.h>

Inheritance diagram for KWin::AnimationEffect:
KWin::CrossFadeEffect KWin::Effect KWin::HighlightWindowEffect KWin::ScriptedEffect ScriptedEffectWithDebugSpy

Public Types

enum  Anchor {
  Left = 1 << 0 , Top = 1 << 1 , Right = 1 << 2 , Bottom = 1 << 3 ,
  Horizontal = Left | Right , Vertical = Top | Bottom , Mouse = 1 << 4
}
 
enum  Attribute {
  Opacity = 0 , Brightness , Saturation , Scale ,
  Rotation , Position , Size , Translation ,
  Clip , Generic , CrossFadePrevious , Shader ,
  ShaderUniform , NonFloatBase = Position
}
 
enum  MetaType {
  SourceAnchor , TargetAnchor , RelativeSourceX , RelativeSourceY ,
  RelativeTargetX , RelativeTargetY , Axis
}
 
enum  Direction { Forward , Backward }
 
enum  TerminationFlag { DontTerminate = 0x00 , TerminateAtSource = 0x01 , TerminateAtTarget = 0x02 }
 
- Public Types inherited from KWin::Effect
enum  {
  PAINT_WINDOW_OPAQUE = 1 << 0 , PAINT_WINDOW_TRANSLUCENT = 1 << 1 , PAINT_WINDOW_TRANSFORMED = 1 << 2 , PAINT_SCREEN_REGION = 1 << 3 ,
  PAINT_SCREEN_TRANSFORMED = 1 << 4 , PAINT_SCREEN_WITH_TRANSFORMED_WINDOWS = 1 << 5 , PAINT_SCREEN_BACKGROUND_FIRST = 1 << 6
}
 
enum  Feature {
  Nothing = 0 , ScreenInversion , Blur , Contrast ,
  HighlightWindows
}
 
enum  ReconfigureFlag { ReconfigureAll = 1 << 0 }
 

Public Member Functions

 AnimationEffect ()
 
 ~AnimationEffect () override
 
bool isActive () const override
 
QString debug (const QString &parameter) const override
 
void prePaintWindow (EffectWindow *w, WindowPrePaintData &data, std::chrono::milliseconds presentTime) override
 
void paintWindow (const RenderTarget &renderTarget, const RenderViewport &viewport, EffectWindow *w, int mask, QRegion region, WindowPaintData &data) override
 
void postPaintScreen () override
 
- Public Member Functions inherited from KWin::CrossFadeEffect
 CrossFadeEffect (QObject *parent=nullptr)
 
 ~CrossFadeEffect () override
 
void drawWindow (const RenderTarget &renderTarget, const RenderViewport &viewport, EffectWindow *window, int mask, const QRegion &region, WindowPaintData &data) override
 
void redirect (EffectWindow *window)
 
void unredirect (EffectWindow *window)
 
void setShader (EffectWindow *window, GLShader *shader)
 
- Public Member Functions inherited from KWin::Effect
 Effect (QObject *parent=nullptr)
 
 ~Effect () override
 
virtual void reconfigure (ReconfigureFlags flags)
 
virtual void prePaintScreen (ScreenPrePaintData &data, std::chrono::milliseconds presentTime)
 
virtual void paintScreen (const RenderTarget &renderTarget, const RenderViewport &viewport, int mask, const QRegion &region, Output *screen)
 
virtual void postPaintWindow (EffectWindow *w)
 
virtual bool provides (Feature)
 
virtual bool perform (Feature feature, const QVariantList &arguments)
 
virtual void windowInputMouseEvent (QEvent *e)
 
virtual void grabbedKeyboardEvent (QKeyEvent *e)
 
virtual int requestedEffectChainPosition () const
 
virtual bool touchDown (qint32 id, const QPointF &pos, std::chrono::microseconds time)
 
virtual bool touchMotion (qint32 id, const QPointF &pos, std::chrono::microseconds time)
 
virtual bool touchUp (qint32 id, std::chrono::microseconds time)
 
virtual bool tabletToolEvent (QTabletEvent *event)
 
virtual bool tabletToolButtonEvent (uint button, bool pressed, quint64 tabletToolId)
 
virtual bool tabletPadButtonEvent (uint button, bool pressed, void *tabletPadId)
 
virtual bool tabletPadStripEvent (int number, int position, bool isFinger, void *tabletPadId)
 
virtual bool tabletPadRingEvent (int number, int position, bool isFinger, void *tabletPadId)
 
template<typename T >
int animationTime (int defaultDuration)
 
virtual bool blocksDirectScanout () const
 

Static Public Member Functions

static int metaData (MetaType type, uint meta)
 
static void setMetaData (MetaType type, uint value, uint &meta)
 
static qreal qecGaussian (qreal progress)
 
static qint64 clock ()
 
- Static Public Member Functions inherited from KWin::CrossFadeEffect
static bool supported ()
 
- Static Public Member Functions inherited from KWin::Effect
static QPointF cursorPos ()
 
static double animationTime (const KConfigGroup &cfg, const QString &key, int defaultTime)
 
static double animationTime (int defaultTime)
 
static double interpolate (double x, double y, double a)
 
static void setPositionTransformations (WindowPaintData &data, QRect &region, EffectWindow *w, const QRect &r, Qt::AspectRatioMode aspect)
 

Protected Types

typedef QMap< EffectWindow *, QPair< QList< AniData >, QRect > > AniMap
 

Protected Member Functions

quint64 animate (EffectWindow *w, Attribute a, uint meta, int ms, const FPx2 &to, const QEasingCurve &curve=QEasingCurve(), int delay=0, const FPx2 &from=FPx2(), bool fullScreen=false, bool keepAlive=true, GLShader *shader=nullptr)
 
quint64 set (EffectWindow *w, Attribute a, uint meta, int ms, const FPx2 &to, const QEasingCurve &curve=QEasingCurve(), int delay=0, const FPx2 &from=FPx2(), bool fullScreen=false, bool keepAlive=true, GLShader *shader=nullptr)
 
bool retarget (quint64 animationId, FPx2 newTarget, int newRemainingTime=-1)
 
bool freezeInTime (quint64 animationId, qint64 frozenTime)
 
bool redirect (quint64 animationId, Direction direction, TerminationFlags terminationFlags=TerminateAtSource)
 
bool complete (quint64 animationId)
 
virtual void animationEnded (EffectWindow *w, Attribute a, uint meta)
 
bool cancel (quint64 animationId)
 
virtual void genericAnimation (EffectWindow *w, WindowPaintData &data, float progress, uint meta)
 
AniMap state () const
 

Additional Inherited Members

- Public Slots inherited from KWin::Effect
virtual bool borderActivated (ElectricBorder border)
 

Detailed Description

Base class for animation effects.

AnimationEffect serves as a base class for animation effects. It makes easier implementing animated transitions, without having to worry about low-level specific stuff, e.g. referencing and unreferencing deleted windows, scheduling repaints for the next frame, etc.

Each animation animates one specific attribute, e.g. size, position, scale, etc. You can provide your own implementation of the Generic attribute if none of the standard attributes(e.g. size, position, etc) satisfy your requirements.

Since
4.8

Definition at line 194 of file animationeffect.h.

Member Typedef Documentation

◆ AniMap

typedef QMap<EffectWindow *, QPair<QList<AniData>, QRect> > KWin::AnimationEffect::AniMap
protected

Definition at line 501 of file animationeffect.h.

Member Enumeration Documentation

◆ Anchor

Enumerator
Left 
Top 
Right 
Bottom 
Horizontal 
Vertical 
Mouse 

Definition at line 199 of file animationeffect.h.

◆ Attribute

Enumerator
Opacity 
Brightness 
Saturation 
Scale 
Rotation 
Position 
Size 
Translation 
Clip 
Generic 
CrossFadePrevious 
Shader 

Performs an animation with a provided shader. The float uniform animationProgress is set to the current progress of the animation.

ShaderUniform 

Like Shader, but additionally allows to animate a float uniform passed to the shader. The uniform location must be provided as metadata.

NonFloatBase 

Definition at line 208 of file animationeffect.h.

◆ Direction

This enum type is used to specify the direction of the animation.

Since
5.15
Enumerator
Forward 

The animation goes from source to target.

Backward 

The animation goes from target to source.

Definition at line 248 of file animationeffect.h.

◆ MetaType

Enumerator
SourceAnchor 
TargetAnchor 
RelativeSourceX 
RelativeSourceY 
RelativeTargetX 
RelativeTargetY 
Axis 

Definition at line 234 of file animationeffect.h.

◆ TerminationFlag

This enum type is used to specify when the animation should be terminated.

Since
5.15
Enumerator
DontTerminate 

Don't terminate the animation when it reaches source or target position.

TerminateAtSource 

Terminate the animation when it reaches the source position. An animation can reach the source position if its direction was changed to go backward (from target to source).

TerminateAtTarget 

Terminate the animation when it reaches the target position. If this flag is not set, then the animation will be persistent.

Definition at line 259 of file animationeffect.h.

Constructor & Destructor Documentation

◆ AnimationEffect()

KWin::AnimationEffect::AnimationEffect ( )

Constructs AnimationEffect.

Whenever you intend to connect to the EffectsHandler::windowClosed() signal, do so when reimplementing the constructor. Do not add private slots named _windowClosed or _windowDeleted! The AnimationEffect connects them right after the construction.

If you shadow the _windowDeleted slot (it doesn't matter that it's a private slot), this will lead to segfaults.

If you shadow _windowClosed or connect your slot to EffectsHandler::windowClosed() after _windowClosed was connected, animations for closing windows will fail.

Definition at line 50 of file animationeffect.cpp.

◆ ~AnimationEffect()

KWin::AnimationEffect::~AnimationEffect ( )
override

Definition at line 62 of file animationeffect.cpp.

Member Function Documentation

◆ animate()

quint64 KWin::AnimationEffect::animate ( EffectWindow * w,
Attribute a,
uint meta,
int ms,
const FPx2 & to,
const QEasingCurve & curve = QEasingCurve(),
int delay = 0,
const FPx2 & from = FPx2(),
bool fullScreen = false,
bool keepAlive = true,
GLShader * shader = nullptr )
inlineprotected

Starts an animated transition of any supported attribute.

Parameters
wThe animated window.
aThe animated attribute.
metaBasically a wildcard to carry various extra information, e.g. the anchor, relativity or rotation axis. You will probably use it when performing Generic animations.
msHow long the transition will last.
toThe target value. FPx2 is an agnostic two component float type (like QPointF or QSizeF, but without requiring to be either and supporting an invalid state).
curveHow the animation progresses, e.g. Linear progresses constantly while Exponential start slow and becomes very fast in the end.
delayWhen the animation will start compared to "now" (the window will remain at the "from" position until then).
fromThe starting value, the default is invalid, ie. the attribute for the window is not transformed in the beginning.
fullScreenSets this effect as the active full screen effect for the duration of the animation.
keepAliveWhether closed windows should be kept alive during animation.
shaderOptional shader to use to render the window.
Returns
An ID that you can use to cancel a running animation.
Since
4.8

Definition at line 376 of file animationeffect.h.

◆ animationEnded()

void KWin::AnimationEffect::animationEnded ( EffectWindow * w,
Attribute a,
uint meta )
protectedvirtual

Called whenever an animation ends.

You can reimplement this method to keep a constant transformation for the window (i.e. keep it at some opacity or position) or to start another animation.

Parameters
wThe animated window.
aThe animated attribute.
metaOriginally supplied metadata to animate() or set().
Since
4.8

Reimplemented in KWin::ScriptedEffect.

Definition at line 436 of file animationeffect.cpp.

◆ cancel()

bool KWin::AnimationEffect::cancel ( quint64 animationId)
protected

Cancels a running animation.

Parameters
animationIdThe id of the animation.
Returns
true if the animation was found (and canceled), false otherwise.
Note
There is NO animated reset of the original value. You'll have to provide that with a second animation.
This will eventually release a Deleted window as well.
If you intend to run another animation on the (Deleted) window, you have to do that before cancelling the old animation (to keep the window around).
Since
4.11

Definition at line 407 of file animationeffect.cpp.

◆ clock()

static qint64 KWin::AnimationEffect::clock ( )
inlinestatic
Since
4.8

Definition at line 345 of file animationeffect.h.

◆ complete()

bool KWin::AnimationEffect::complete ( quint64 animationId)
protected

Fast-forwards the animation to the target position.

Parameters
animationIdThe id of the animation.
Returns
true if the animation was fast-forwarded successfully, otherwise false.
Since
5.15

Definition at line 381 of file animationeffect.cpp.

◆ debug()

QString KWin::AnimationEffect::debug ( const QString & parameter) const
overridevirtual

Reimplement this method to provide online debugging. This could be as trivial as printing specific detail information about the effect state but could also be used to move the effect in and out of a special debug modes, clear bogus data, etc. Notice that the functions is const by intent! Whenever you alter the state of the object due to random user input, you should do so with greatest care, hence const_cast<> your object - signalling "let me alone, i know what i'm doing"

Parameters
parameterA freeform string user input for your effect to interpret.
Since
4.11

Reimplemented from KWin::Effect.

Definition at line 997 of file animationeffect.cpp.

◆ freezeInTime()

bool KWin::AnimationEffect::freezeInTime ( quint64 animationId,
qint64 frozenTime )
protected

Definition at line 322 of file animationeffect.cpp.

◆ genericAnimation()

void KWin::AnimationEffect::genericAnimation ( EffectWindow * w,
WindowPaintData & data,
float progress,
uint meta )
protectedvirtual

Called whenever animation that transforms Generic attribute needs to be painted.

You should reimplement this method if you transform Generic attribute. meta can be used to support more than one additional animations.

Parameters
wThe animated window.
dataThe paint data.
progressCurrent progress value.
metaThe metadata.
Since
4.8

Definition at line 440 of file animationeffect.cpp.

◆ isActive()

bool KWin::AnimationEffect::isActive ( ) const
overridevirtual

Overwrite this method to indicate whether your effect will be doing something in the next frame to be rendered. If the method returns false the effect will be excluded from the chained methods in the next rendered frame.

This method is called always directly before the paint loop begins. So it is totally fine to e.g. react on a window event, issue a repaint to trigger an animation and change a flag to indicate that this method returns true.

As the method is called each frame, you should not perform complex calculations. Best use just a boolean flag.

The default implementation of this method returns true.

Since
4.8

Reimplemented from KWin::Effect.

Definition at line 86 of file animationeffect.cpp.

◆ metaData()

int KWin::AnimationEffect::metaData ( MetaType type,
uint meta )
static

Gets stored metadata.

Metadata can be used to store some extra information, for example rotation axis, etc. The first 24 bits are reserved for the AnimationEffect class, you can use the last 8 bits for custom hints. In case when you transform a Generic attribute, all 32 bits are yours and you can use them as you want and read them in your genericAnimation() implementation.

Parameters
typeThe type of the metadata.
metaWhere the metadata is stored.
Returns
Stored metadata.
Since
4.8

Definition at line 756 of file animationeffect.cpp.

◆ paintWindow()

void KWin::AnimationEffect::paintWindow ( const RenderTarget & renderTarget,
const RenderViewport & viewport,
EffectWindow * w,
int mask,
QRegion region,
WindowPaintData & data )
overridevirtual

This is the main method for painting windows. In this method you can:

  • do various transformations
  • change opacity of the window
  • change brightness and/or saturation, if it's supported

In OpenGL based compositing, the frameworks ensures that the context is current when this method is invoked.

Reimplemented from KWin::Effect.

Definition at line 522 of file animationeffect.cpp.

◆ postPaintScreen()

void KWin::AnimationEffect::postPaintScreen ( )
overridevirtual

Called after all the painting has been finished. In this method you can:

  • schedule next repaint in case of animations You shouldn't paint anything here.

In OpenGL based compositing, the frameworks ensures that the context is current when this method is invoked.

Reimplemented from KWin::Effect.

Definition at line 652 of file animationeffect.cpp.

◆ prePaintWindow()

void KWin::AnimationEffect::prePaintWindow ( EffectWindow * w,
WindowPrePaintData & data,
std::chrono::milliseconds presentTime )
overridevirtual

Called for every window before the actual paint pass In this method you can:

  • enable or disable painting of the window (e.g. enable paiting of minimized window)
  • set window to be painted with translucency
  • set window to be transformed
  • request the window to be divided into multiple parts

In OpenGL based compositing, the frameworks ensures that the context is current when this method is invoked.

presentTime specifies the expected monotonic time when the rendered frame will be displayed on the screen.

Reimplemented from KWin::Effect.

Definition at line 487 of file animationeffect.cpp.

◆ qecGaussian()

static qreal KWin::AnimationEffect::qecGaussian ( qreal progress)
inlinestatic

Gaussian (bumper) animation curve for QEasingCurve.

Since
4.8

Definition at line 335 of file animationeffect.h.

◆ redirect()

bool KWin::AnimationEffect::redirect ( quint64 animationId,
Direction direction,
TerminationFlags terminationFlags = TerminateAtSource )
protected

Changes the direction of the animation.

Parameters
animationIdThe id of the animation.
directionThe new direction of the animation.
terminationFlagsWhether the animation should be terminated when it reaches the source position after its direction was changed to go backward. Currently, TerminationFlag::TerminateAtTarget has no effect.
Returns
true if the direction of the animation was changed successfully, otherwise false.
Since
5.15

Definition at line 347 of file animationeffect.cpp.

◆ retarget()

bool KWin::AnimationEffect::retarget ( quint64 animationId,
FPx2 newTarget,
int newRemainingTime = -1 )
protected

Changes the target (but not type or curve) of a running animation.

Please use cancel() to cancel an animation rather than altering it.

Parameters
animationIdThe id of the animation to be retargetted.
newTargetThe new target.
newRemainingTimeThe new duration of the transition. By default (-1), the remaining time remains unchanged.
Returns
true if the animation was retargetted successfully, false otherwise.
Note
You can NOT retarget an animation that just has just ended!
Since
5.6

Definition at line 291 of file animationeffect.cpp.

◆ set()

quint64 KWin::AnimationEffect::set ( EffectWindow * w,
Attribute a,
uint meta,
int ms,
const FPx2 & to,
const QEasingCurve & curve = QEasingCurve(),
int delay = 0,
const FPx2 & from = FPx2(),
bool fullScreen = false,
bool keepAlive = true,
GLShader * shader = nullptr )
inlineprotected

Starts a persistent animated transition of any supported attribute.

This method is equal to animate() with one important difference: the target value for the attribute is kept until you call cancel().

Parameters
wThe animated window.
aThe animated attribute.
metaBasically a wildcard to carry various extra information, e.g. the anchor, relativity or rotation axis. You will probably use it when performing Generic animations.
msHow long the transition will last.
toThe target value. FPx2 is an agnostic two component float type (like QPointF or QSizeF, but without requiring to be either and supporting an invalid state).
curveHow the animation progresses, e.g. Linear progresses constantly while Exponential start slow and becomes very fast in the end.
delayWhen the animation will start compared to "now" (the window will remain at the "from" position until then).
fromThe starting value, the default is invalid, ie. the attribute for the window is not transformed in the beginning.
fullScreenSets this effect as the active full screen effect for the duration of the animation.
keepAliveWhether closed windows should be kept alive during animation.
shaderOptional shader to use to render the window.
Returns
An ID that you need to use to cancel this manipulation.
Since
4.11

Definition at line 409 of file animationeffect.h.

◆ setMetaData()

void KWin::AnimationEffect::setMetaData ( MetaType type,
uint value,
uint & meta )
static

Sets metadata.

Parameters
typeThe type of the metadata.
valueThe data to be stored.
metaWhere the metadata will be stored.
Since
4.8

Definition at line 777 of file animationeffect.cpp.

◆ state()

AnimationEffect::AniMap KWin::AnimationEffect::state ( ) const
protected

Definition at line 1020 of file animationeffect.cpp.


The documentation for this class was generated from the following files: