6
#include <composite/composite.h>
7
#include <opengl/opengl.h>
9
#include <boost/foreach.hpp>
10
#define foreach BOOST_FOREACH
12
#include <animation/animation.h>
14
#include "animation_options.h"
16
typedef std::vector<CompWindow *> CompWindowVector;
17
typedef std::vector<ExtensionPluginInfo *> ExtensionPluginVector;
18
typedef std::vector<AnimEffect> AnimEffectVector;
24
RestackInfo (CompWindow *wRestacked,
27
CompWindow *wOldAbove,
30
CompWindow *wRestacked, *wStart, *wEnd, *wOldAbove;
37
IdValuePair () : pluginInfo (0), optionId (-1), value () {}
39
bool matchesPluginOption (ExtensionPluginInfo *pluginInfo,
42
const ExtensionPluginInfo *pluginInfo;
44
CompOption::Value value;
47
typedef std::vector<IdValuePair> IdValuePairVector;
54
IdValuePairVector pairs;
57
typedef std::vector<OptionSet> OptionSetVector;
72
AnimEffectVector effects;
75
extern AnimEffect AnimEffectNone;
76
extern AnimEffect AnimEffectRandom;
77
extern AnimEffect AnimEffectCurvedFold;
78
extern AnimEffect AnimEffectDodge;
79
extern AnimEffect AnimEffectDream;
80
extern AnimEffect AnimEffectFade;
81
extern AnimEffect AnimEffectFocusFade;
82
extern AnimEffect AnimEffectGlide1;
83
extern AnimEffect AnimEffectGlide2;
84
extern AnimEffect AnimEffectHorizontalFolds;
85
extern AnimEffect AnimEffectMagicLamp;
86
extern AnimEffect AnimEffectMagicLampWavy;
87
extern AnimEffect AnimEffectRollUp;
88
extern AnimEffect AnimEffectSidekick;
89
extern AnimEffect AnimEffectWave;
90
extern AnimEffect AnimEffectZoom;
92
#define NUM_EFFECTS 16
94
extern int customOptionOptionIds[AnimEventNum];
96
typedef struct _PluginEventInfo
98
const char *pluginName;
99
const char *activateEventName;
104
WatchedPluginSwitcher = 0,
109
WatchedPluginFadedesktop,
110
WatchedScreenPluginNum
111
} WatchedScreenPlugin;
115
WatchedPluginKDECompat,
116
WatchedWindowPluginNum
117
} WatchedWindowPlugin;
119
// This must have the value of the first "effect setting" above
120
// in PrivateAnimScreenOptions
121
#define NUM_NONEFFECT_OPTIONS AnimationOptions::CurvedFoldAmpMult
124
class ExtensionPluginAnimation : public ExtensionPluginInfo
127
ExtensionPluginAnimation (const CompString &name,
128
unsigned int nEffects,
130
CompOption::Vector *effectOptions,
131
unsigned int firstEffectOptionIndex);
132
~ExtensionPluginAnimation ();
134
// Overriden methods from ExtensionPluginInfo
135
void postPreparePaintGeneral ();
136
void prePreparePaintGeneral ();
137
void handleRestackNotify (AnimWindow *aw);
138
// Always reset stacking related info when a window is opened, closed,
139
// minimized, or unminimized.
140
void preInitiateOpenAnim (AnimWindow *aw);
141
void preInitiateCloseAnim (AnimWindow *aw);
142
void preInitiateMinimizeAnim (AnimWindow *aw);
143
void preInitiateUnminimizeAnim (AnimWindow *aw);
144
void initPersistentData (AnimWindow *aw);
145
void destroyPersistentData (AnimWindow *aw);
146
void postUpdateEventEffects (AnimEvent e,
148
void cleanUpAnimation (bool closing,
150
void postStartupCountdown ();
153
void handleSingleRestack (AnimWindow *aw);
154
void prePaintWindowsBackToFront ();
155
bool paintShouldSkipWindow (CompWindow *w);
156
const CompWindowList & getWindowPaintList ();
157
void resetStackingInfo ();
158
static CompWindow *getBottommostInExtendedFocusChain (CompWindow *wStartPoint);
159
static CompWindow *getBottommostInRestackChain (CompWindow *wStartPoint);
161
bool markNewCopy (CompWindow *w);
162
CompWindow * walkFirst ();
163
CompWindow * walkNext (CompWindow *w);
164
void incrementCurRestackAnimCount ();
165
void decrementCurRestackAnimCount ();
166
bool wontCreateCircularChain (CompWindow *wCur, CompWindow *wNext);
168
static void cleanUpParentChildChainItem (AnimWindow *aw);
169
static bool relevantForRestackAnim (CompWindow *w);
171
/// Is restackInfo still good?
172
static bool restackInfoStillGood (RestackInfo *restackInfo);
174
void updateLastClientList ();
176
/// A window was restacked this paint round.
177
bool mAWinWasRestackedJustNow;
180
CompWindowVector mLastClientList; ///< Last known stacking order
181
CompWindowVector mPrevClientList; ///< The stacking order before mLastClientList
182
int mRestackAnimCount; ///< Count of how many windows are currently involved in
183
///< animations that require walker (dodge & focus fade).
184
std::vector<AnimWindow *> mRestackedWindows;
186
CompWindowList mWindowList;
189
class PrivateAnimScreen :
190
public ScreenInterface,
191
public CompositeScreenInterface,
192
public GLScreenInterface,
193
public AnimationOptions
195
friend class PrivateAnimWindow;
196
friend class AnimWindow;
199
CompositeScreen *cScreen;
204
struct timeval mLastRedrawTime;
205
bool mLastRedrawTimeFresh;
207
bool mPluginActive[WatchedScreenPluginNum];
208
int mSwitcherPostWait;
210
///< To mark windows as "created" if they were opened before compiz
211
///< was started and to prevent already opened windows from doing
214
Window mLastActiveWindow; ///< Last known active window
216
bool mAnimInProgress; ///< Is an animation currently being played?
217
bool mStartingNewPaintRound; ///< Is a new round of glPaints starting?
218
bool mPrePaintWindowsBackToFrontEnabled;
220
EffectSet mRandomEffects[AnimEventNum];
222
OptionSets mEventOptionSets[AnimEventNum];
224
// Effect extension plugins
225
ExtensionPluginVector mExtensionPlugins;
227
// Possible effects for each event
228
AnimEffectVector mEventEffectsAllowed[AnimEventNum];
230
// List of chosen effects for each event
231
EffectSet mEventEffects[AnimEventNum];
235
Window mActiveWindow;
236
CompMatch mNeverAnimateMatch;
238
void updateEventEffects (AnimEvent e,
240
bool callPost = true);
241
void updateAllEventEffects ();
243
void updateOptionSets (AnimEvent e);
244
void updateOptionSet (OptionSet *os, const char *optNamesValuesOrig);
246
void activateEvent (bool activating);
247
bool isWinVisible (CompWindow *w);
248
AnimEvent getCorrespondingAnimEvent (AnimationOptions::Options optionId);
249
void eventMatchesChanged (CompOption *opt, AnimationOptions::Options num);
250
void eventOptionsChanged (CompOption *opt, AnimationOptions::Options num);
251
void eventEffectsChanged (CompOption *opt, AnimationOptions::Options num);
252
void eventRandomEffectsChanged (CompOption *opt, AnimationOptions::Options num);
254
CompRect getIcon (CompWindow *w, bool alwaysUseMouse);
255
void updateAnimStillInProgress ();
257
bool isAnimEffectInList (AnimEffect theEffect,
258
EffectSet &effectList);
259
bool isAnimEffectPossibleForEvent (AnimEffect theEffect,
263
PrivateAnimScreen (CompScreen *s, AnimScreen *);
264
~PrivateAnimScreen ();
267
void initiateOpenAnim (PrivateAnimWindow *aw);
268
void initiateCloseAnim (PrivateAnimWindow *aw);
269
void initiateMinimizeAnim (PrivateAnimWindow *aw);
270
void initiateUnminimizeAnim (PrivateAnimWindow *aw);
271
void initiateShadeAnim (PrivateAnimWindow *aw);
272
void initiateUnshadeAnim (PrivateAnimWindow *aw);
273
bool initiateFocusAnim (PrivateAnimWindow *aw);
275
/// Is a restacking animation currently possible?
276
bool isRestackAnimPossible ();
278
void initAnimationList ();
279
bool isAnimEffectPossible (AnimEffect theEffect);
280
inline CompOutput &output () { return *mOutput; }
281
AnimEffect getActualEffect (AnimEffect effect,
282
AnimEvent animEvent);
283
bool shouldIgnoreWindowForAnim (CompWindow *w, bool checkPixmap);
284
OptionSet *getOptionSetForSelectedRow (PrivateAnimWindow *aw,
286
void addExtension (ExtensionPluginInfo *extensionPluginInfo,
287
bool shouldInitPersistentData);
288
void removeExtension (ExtensionPluginInfo *extensionPluginInfo);
289
AnimEffect getMatchingAnimSelection (CompWindow *w,
292
bool otherPluginsActive ();
294
void enablePrePaintWindowsBackToFront (bool enabled);
295
void prePaintWindowsBackToFront ();
297
// CompositeScreenInterface methods
298
void preparePaint (int);
300
const CompWindowList & getWindowPaintList ();
302
// GLScreenInterface methods
303
bool glPaintOutput (const GLScreenPaintAttrib &,
309
// ScreenInterface methods
310
void handleCompizEvent (const char * plugin, const char *event,
311
CompOption::Vector &options);
314
class PrivateAnimWindow :
315
public WindowInterface,
316
public GLWindowInterface
318
friend class PrivateAnimScreen;
319
friend class AnimWindow;
322
PrivateAnimWindow (CompWindow *, AnimWindow *aw);
323
~PrivateAnimWindow ();
325
void createFocusAnimation (AnimEffect effect, int duration);
326
inline void setShaded (bool shaded) { mNowShaded = shaded; }
327
inline Animation *curAnimation () { return mCurAnimation; }
328
inline PrivateAnimScreen *paScreen () { return mPAScreen; }
329
inline AnimWindow *aWindow () { return mAWindow; }
330
inline Box &BB () { return mBB; }
331
inline int curAnimSelectionRow () { return mCurAnimSelectionRow; }
333
void damageThisAndLastStepRegion ();
334
void postAnimationCleanUp ();
335
void copyResetStepRegion ();
341
AnimWindow *mAWindow;
343
PrivateAnimScreen *mPAScreen;
346
unsigned int mNewState;
348
Animation *mCurAnimation;
350
bool mUnshadePending;
351
bool mEventNotOpenClose;
361
int mCurAnimSelectionRow;
362
int mPrevAnimSelectionRow; ///< For the case when one event interrupts another
364
Box mBB; ///< Bounding box of area to be damaged
366
CompRegion mStepRegion; ///< Region to damage this step
367
CompRegion mLastStepRegion; ///< Region damaged last step
369
bool mPluginActive[WatchedWindowPluginNum];
372
unsigned int getState ();
373
void updateSelectionRow (unsigned int i);
374
void postAnimationCleanUpPrev (bool closing, bool clearMatchingRow);
375
void postAnimationCleanUpCustom (bool closing,
377
bool clearMatchingRow);
378
void reverseAnimation ();
379
void enablePainting (bool enabling);
381
void notifyAnimation (bool activation);
383
// WindowInterface methods
384
void resizeNotify (int dx, int dy, int dwidth, int dheight);
385
void moveNotify (int dx, int dy, bool immediate);
386
void windowNotify (CompWindowNotify n);
387
void grabNotify (int x, int y, unsigned int state, unsigned int mask);
388
void ungrabNotify ();
390
// GLWindowInterface methods
391
bool glPaint (const GLWindowPaintAttrib &, const GLMatrix &,
392
const CompRegion &, unsigned int);
393
void glAddGeometry (const GLTexture::MatrixList &,
394
const CompRegion &, const CompRegion &,
395
unsigned int = MAXSHORT, unsigned int = MAXSHORT);
396
void glDrawTexture (GLTexture *texture, GLFragment::Attrib &,
398
void glDrawGeometry ();
405
RollUpAnim (CompWindow *w,
406
WindowEvent curWindowEvent,
408
const AnimEffect info,
409
const CompRect &icon);
411
static const float kDurationFactor;
417
class MagicLampAnim :
421
MagicLampAnim (CompWindow *w,
422
WindowEvent curWindowEvent,
424
const AnimEffect info,
425
const CompRect &icon);
426
virtual ~MagicLampAnim ();
430
GridModel::GridObject *mTopLeftCornerObject;
431
GridModel::GridObject *mBottomLeftCornerObject;
435
void updateBB (CompOutput &output);
436
inline bool stepRegionUsed () { return true; }
437
void adjustPointerIconSize ();
439
virtual bool hasMovingEnd ();
440
virtual void filterTargetX (float &targetX, float x) { }
443
class MagicLampWavyAnim :
447
MagicLampWavyAnim (CompWindow *w,
448
WindowEvent curWindowEvent,
450
const AnimEffect info,
451
const CompRect &icon);
452
~MagicLampWavyAnim ();
462
unsigned int mNumWaves;
466
void updateBB (CompOutput &output);
467
inline bool stepRegionUsed () { return false; }
468
void adjustPointerIconSize ();
470
bool hasMovingEnd ();
471
void filterTargetX (float &targetX, float x);
478
SidekickAnim (CompWindow *w,
479
WindowEvent curWindowEvent,
481
const AnimEffect info,
482
const CompRect &icon);
486
float getSpringiness ();
487
bool isZoomFromCenter ();
488
inline bool hasExtraTransform () { return true; }
489
void applyExtraTransform (float progress);
490
inline bool shouldAvoidParallelogramLook () { return true; }
494
public GridTransformAnim
497
WaveAnim (CompWindow *w,
498
WindowEvent curWindowEvent,
500
const AnimEffect info,
501
const CompRect &icon);
503
void adjustDuration ();
505
inline bool using3D () { return true; }
508
static const float kMinDuration;
515
GlideAnim (CompWindow *w,
516
WindowEvent curWindowEvent,
518
const AnimEffect info,
519
const CompRect &icon);
522
void prePaintWindow ();
523
inline bool postPaintWindowUsed () { return true; }
524
void postPaintWindow ();
525
void adjustDuration ();
527
void applyTransform ();
528
float getFadeProgress ();
530
float getProgress ();
531
virtual void getParams (float *finalDistFac,
535
float glideModRotAngle; ///< The angle of rotation, modulo 360.
542
Glide2Anim (CompWindow *w,
543
WindowEvent curWindowEvent,
545
const AnimEffect info,
546
const CompRect &icon);
549
void getParams (float *finalDistFac,
554
class RestackPersistentData;
557
virtual public Animation
560
RestackAnim (CompWindow *w,
561
WindowEvent curWindowEvent,
563
const AnimEffect info,
564
const CompRect &icon);
565
void cleanUp (bool closing,
567
bool initiateRestackAnim (int duration);
568
inline bool moveUpdate () { return false; }
569
static bool onSameRestackChain (CompWindow *wSubject, CompWindow *wOther);
571
/// Find union of restack chain (group)
572
static CompRegion unionRestackChain (CompWindow *w);
574
virtual bool paintedElsewhere () { return false; }
577
// Overridable methods
578
virtual void processCandidate (CompWindow *candidateWin,
579
CompWindow *subjectWin,
580
CompRegion &candidateAndSubjectIntersection,
581
int &numSelectedCandidates) {}
582
virtual void postInitiateRestackAnim (int numSelectedCandidates,
589
bool overNewCopy (); ///< Is glPaint on the copy at the new position?
591
RestackPersistentData *mRestackData;
594
class RestackPersistentData :
595
public PersistentData
597
friend class ExtensionPluginAnimation;
598
friend class RestackAnim;
599
friend class FocusFadeAnim;
600
friend class DodgeAnim;
603
RestackPersistentData ();
604
~RestackPersistentData ();
607
inline RestackInfo *restackInfo () { return mRestackInfo; }
608
void resetRestackInfo (bool alsoResetChain = false);
609
void setRestackInfo (CompWindow *wRestacked,
612
CompWindow *wOldAbove,
614
void getHostedOnWin (CompWindow *wGuest, CompWindow *wHost);
616
RestackInfo *mRestackInfo; ///< restack info if window was restacked this paint round
617
CompWindow *mWinToBePaintedBeforeThis; ///< Window which should be painted before this
618
CompWindow *mWinThisIsPaintedBefore; ///< the inverse relation of mWinToBePaintedBeforeThis
619
CompWindow *mMoreToBePaintedPrev;
620
CompWindow *mMoreToBePaintedNext; ///< doubly linked list for windows underneath that
621
///< raise together with this one
622
bool mConfigureNotified; ///< was mConfigureNotified before restack check
623
CompWindow *mWinPassingThrough; ///< win. passing through this one during focus effect
624
bool mWalkerOverNewCopy; ///< whether walker is on the copy at the new pos.
625
int mVisitCount; ///< how many times walker/glPaint has visited this window
626
bool mIsSecondary; ///< whether this is one of the secondary (non-topmost) in its restack chain
629
class FocusFadeAnim :
634
FocusFadeAnim (CompWindow *w,
635
WindowEvent curWindowEvent,
637
const AnimEffect info,
638
const CompRect &icon);
639
void updateAttrib (GLWindowPaintAttrib &attrib);
640
void cleanUp (bool closing,
644
void processCandidate (CompWindow *candidateWin,
645
CompWindow *subjectWin,
646
CompRegion &candidateAndSubjectIntersection,
647
int &numSelectedCandidates);
648
GLushort computeOpacity (GLushort opacityInt);
653
DodgeDirectionUp = 0,
657
DodgeDirectionXY, // movement possibly in both X and Y (for subjects)
661
class DodgePersistentData;
668
DodgeAnim (CompWindow *w,
669
WindowEvent curWindowEvent,
671
const AnimEffect info,
672
const CompRect &icon);
673
void cleanUp (bool closing,
675
static int getDodgeAmount (CompRect &rect,
679
void updateTransform (GLMatrix &wTransform);
680
bool shouldDamageWindowOnStart ();
681
void updateBB (CompOutput &output);
682
void postPreparePaint ();
683
void calculateDodgeAmounts ();
687
void processCandidate (CompWindow *candidateWin,
688
CompWindow *subjectWin,
689
CompRegion &candidateAndSubjectIntersection,
690
int &numSelectedCandidates);
691
void postInitiateRestackAnim (int numSelectedCandidates,
696
bool paintedElsewhere ();
697
void applyDodgeTransform ();
698
float dodgeProgress ();
699
void updateDodgerDodgeAmount ();
701
DodgePersistentData *mDodgeData;
703
CompWindow *mDodgeSubjectWin;///< The window being dodged
704
float mDodgeMaxAmountX; ///< max # pixels it should dodge
705
///< (neg. value dodges leftward)
706
float mDodgeMaxAmountY; ///< max # pixels it should dodge
707
///< (neg. value dodges upward)
708
DodgeDirection mDodgeDirection;
712
class DodgePersistentData :
713
public PersistentData
715
friend class ExtensionPluginAnimation;
716
friend class DodgeAnim;
719
DodgePersistentData ();
722
int dodgeOrder; ///< dodge order (used temporarily)
724
// TODO mov the below members into DodgeAnim
725
bool isDodgeSubject; ///< true if this window is the cause of dodging
726
bool skipPostPrepareScreen;
727
CompWindow *dodgeChainStart;///< for the subject window
728
CompWindow *dodgeChainPrev; ///< for dodging windows
729
CompWindow *dodgeChainNext; ///< for dodging windows
736
DreamAnim (CompWindow *w,
737
WindowEvent curWindowEvent,
739
const AnimEffect info,
740
const CompRect &icon);
745
void adjustDuration ();
746
float getFadeProgress ();
749
static const float kDurationFactor;
756
FoldAnim (CompWindow *w,
757
WindowEvent curWindowEvent,
759
const AnimEffect info,
760
const CompRect &icon);
762
inline bool using3D () { return true; }
763
float getFadeProgress ();
764
void updateWindowAttrib (GLWindowPaintAttrib &attrib);
767
class CurvedFoldAnim :
771
CurvedFoldAnim (CompWindow *w,
772
WindowEvent curWindowEvent,
774
const AnimEffect info,
775
const CompRect &icon);
779
void updateBB (CompOutput &output);
781
float getObjectZ (GridAnim::GridModel *mModel,
782
float forwardProgress,
784
float relDistToCenter,
788
class HorizontalFoldsAnim :
792
HorizontalFoldsAnim (CompWindow *w,
793
WindowEvent curWindowEvent,
795
const AnimEffect info,
796
const CompRect &icon);
801
float getObjectZ (GridAnim::GridModel *mModel,
802
float forwardProgress,
804
float relDistToFoldCenter,