~lbrulet-8/compiz-plugins-main/fix-876591

« back to all changes in this revision

Viewing changes to .pc/01_fix_ghost_windows.patch/animation/src/animation.cpp

  • Committer: Package Import Robot
  • Author(s): Didier Roche
  • Date: 2011-09-28 14:20:00 UTC
  • mfrom: (1.1.9 upstream)
  • Revision ID: package-import@ubuntu.com-20110928142000-p14f004r9mpvlo5e
Tags: 1:0.9.6-0ubuntu1
* New upstream release:
  - Maximizing a window causes compiz to hang (LP: #860257)
  - snap movements can cause infinite loops in window movements (LP: #860646)
* Remove debian/patches/01_fix_ghost_windows.patch which is part of the new 
  upstream release
* debian/control:
  - fix overwrite with natty compiz-plugins (LP: #859632)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/**
2
 
 * Animation plugin for compiz/beryl
3
 
 *
4
 
 * animation.c
5
 
 *
6
 
 * Copyright : (C) 2006 Erkin Bahceci
7
 
 * E-mail    : erkinbah@gmail.com
8
 
 *
9
 
 * Based on Wobbly and Minimize plugins by
10
 
 *           : David Reveman
11
 
 * E-mail    : davidr@novell.com>
12
 
 *
13
 
 * Airplane added by : Carlo Palma
14
 
 * E-mail            : carlopalma@salug.it
15
 
 * Based on code originally written by Mark J. Kilgard
16
 
 *
17
 
 * Beam-Up added by : Florencio Guimaraes
18
 
 * E-mail           : florencio@nexcorp.com.br
19
 
 *
20
 
 * Fold and Skewer added by : Tomasz Kolodziejski
21
 
 * E-mail                   : tkolodziejski@gmail.com
22
 
 *
23
 
 * Hexagon tessellator added by : Mike Slegeir
24
 
 * E-mail                       : mikeslegeir@mail.utexas.edu>
25
 
 *
26
 
 * Particle system added by : (C) 2006 Dennis Kasprzyk
27
 
 * E-mail                   : onestone@beryl-project.org
28
 
 *
29
 
 * This program is free software; you can redistribute it and/or
30
 
 * modify it under the terms of the GNU General Public License
31
 
 * as published by the Free Software Foundation; either version 2
32
 
 * of the License, or (at your option) any later version.
33
 
 *
34
 
 * This program is distributed in the hope that it will be useful,
35
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
36
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
37
 
 * GNU General Public License for more details.
38
 
 *
39
 
 * You should have received a copy of the GNU General Public License
40
 
 * along with this program; if not, write to the Free Software
41
 
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
42
 
 **/
43
 
 
44
 
/*
45
 
 * TODO:
46
 
 *
47
 
 * - Custom bounding box update function for Airplane
48
 
 *
49
 
 * - Auto direction option: Close in opposite direction of opening
50
 
 * - Proper side surface normals for lighting
51
 
 * - decoration shadows
52
 
 *   - shadow quad generation
53
 
 *   - shadow texture coords (from clip tex. matrices)
54
 
 *   - draw shadows
55
 
 *   - fade in shadows
56
 
 *
57
 
 * - Voronoi tessellation
58
 
 * - Brick tessellation
59
 
 * - Triangle tessellation
60
 
 * - Hexagonal tessellation
61
 
 *
62
 
 * Effects:
63
 
 * - Circular action for tornado type fx
64
 
 * - Tornado 3D (especially for minimize)
65
 
 * - Helix 3D (hor. strips descend while they rotate and fade in)
66
 
 * - Glass breaking 3D
67
 
 *   - Gaussian distr. points (for gradually increasing polygon size
68
 
 *                           starting from center or near mouse pointer)
69
 
 *   - Drawing cracks
70
 
 *   - Gradual cracking
71
 
 *
72
 
 * - fix slowness during transparent cube with <100 opacity
73
 
 * - fix occasional wrong side color in some windows
74
 
 * - fix on top windows and panels
75
 
 *   (These two only matter for viewing during Rotate Cube.
76
 
 *    All windows should be painted with depth test on
77
 
 *    like 3d-plugin does)
78
 
 * - play better with rotate (fix cube face drawn on top of polygons
79
 
 *   after 45 deg. rotation)
80
 
 *
81
 
 */
82
 
 
83
 
#include <GL/glu.h>
84
 
#include <core/atoms.h>
85
 
#include <sys/time.h>
86
 
#include <assert.h>
87
 
#include "private.h"
88
 
 
89
 
class AnimPluginVTable :
90
 
    public CompPlugin::VTableForScreenAndWindow<AnimScreen, AnimWindow>
91
 
{
92
 
public:
93
 
    bool init ();
94
 
    void fini ();
95
 
};
96
 
 
97
 
COMPIZ_PLUGIN_20090315 (animation, AnimPluginVTable);
98
 
 
99
 
#define FAKE_ICON_SIZE 4
100
 
 
101
 
const char *eventNames[AnimEventNum] =
102
 
{"Open", "Close", "Minimize", "Shade", "Focus"};
103
 
 
104
 
int chosenEffectOptionIds[AnimEventNum] =
105
 
{
106
 
    AnimationOptions::OpenEffects,
107
 
    AnimationOptions::CloseEffects,
108
 
    AnimationOptions::MinimizeEffects,
109
 
    AnimationOptions::ShadeEffects,
110
 
    AnimationOptions::FocusEffects
111
 
};
112
 
 
113
 
int randomEffectOptionIds[AnimEventNum] =
114
 
{
115
 
    AnimationOptions::OpenRandomEffects,
116
 
    AnimationOptions::CloseRandomEffects,
117
 
    AnimationOptions::MinimizeRandomEffects,
118
 
    AnimationOptions::ShadeRandomEffects,
119
 
    -1
120
 
};
121
 
 
122
 
int customOptionOptionIds[AnimEventNum] =
123
 
{
124
 
    AnimationOptions::OpenOptions,
125
 
    AnimationOptions::CloseOptions,
126
 
    AnimationOptions::MinimizeOptions,
127
 
    AnimationOptions::ShadeOptions,
128
 
    AnimationOptions::FocusOptions
129
 
};
130
 
 
131
 
int matchOptionIds[AnimEventNum] =
132
 
{
133
 
    AnimationOptions::OpenMatches,
134
 
    AnimationOptions::CloseMatches,
135
 
    AnimationOptions::MinimizeMatches,
136
 
    AnimationOptions::ShadeMatches,
137
 
    AnimationOptions::FocusMatches
138
 
};
139
 
 
140
 
int durationOptionIds[AnimEventNum] =
141
 
{
142
 
    AnimationOptions::OpenDurations,
143
 
    AnimationOptions::CloseDurations,
144
 
    AnimationOptions::MinimizeDurations,
145
 
    AnimationOptions::ShadeDurations,
146
 
    AnimationOptions::FocusDurations
147
 
};
148
 
 
149
 
// Bind each effect in the list of chosen effects for every event, to the
150
 
// corresponding animation effect (i.e. effect with that name) if it is
151
 
// provided by a plugin, otherwise set it to None.
152
 
void
153
 
PrivateAnimScreen::updateEventEffects (AnimEvent e,
154
 
                                       bool forRandom,
155
 
                                       bool callPost)
156
 
{
157
 
    CompOption::Value::Vector *listVal;
158
 
    EffectSet *effectSet;
159
 
    if (forRandom)
160
 
    {
161
 
        listVal = &getOptions ()[(unsigned)randomEffectOptionIds[e]].value ().
162
 
            list ();
163
 
        effectSet = &mRandomEffects[e];
164
 
    }
165
 
    else
166
 
    {
167
 
        listVal = &getOptions ()[(unsigned)chosenEffectOptionIds[e]].value ().
168
 
            list ();
169
 
        effectSet = &mEventEffects[e];
170
 
    }
171
 
    unsigned int n = listVal->size ();
172
 
 
173
 
    effectSet->effects.clear ();
174
 
    effectSet->effects.reserve (n);
175
 
 
176
 
    AnimEffectVector &eventEffectsAllowed = mEventEffectsAllowed[e];
177
 
 
178
 
    for (unsigned int r = 0; r < n; r++) // for each row
179
 
    {
180
 
        const CompString &animName = (*listVal)[r].s ();
181
 
 
182
 
        // Find the animation effect with matching name
183
 
        AnimEffectVector::iterator it =
184
 
            find_if (eventEffectsAllowed.begin (),
185
 
                     eventEffectsAllowed.end (),
186
 
                     boost::bind (&AnimEffectInfo::matchesEffectName,
187
 
                                  _1, animName));
188
 
 
189
 
        effectSet->effects.push_back (it == eventEffectsAllowed.end () ?
190
 
                                      AnimEffectNone : *it);
191
 
    }
192
 
 
193
 
    if (callPost)
194
 
    {
195
 
        foreach (ExtensionPluginInfo *extPlugin, mExtensionPlugins)
196
 
            extPlugin->postUpdateEventEffects (e, forRandom);
197
 
    }
198
 
}
199
 
 
200
 
void
201
 
PrivateAnimScreen::updateAllEventEffects ()
202
 
{
203
 
    // for each anim event
204
 
    for (int e = 0; e < AnimEventNum; e++)
205
 
        updateEventEffects ((AnimEvent)e, false);
206
 
 
207
 
    // for each anim event except focus
208
 
    for (int e = 0; e < AnimEventNum - 1; e++)
209
 
        updateEventEffects ((AnimEvent)e, true);
210
 
}
211
 
 
212
 
bool
213
 
PrivateAnimScreen::isAnimEffectInList (AnimEffect theEffect,
214
 
                                       EffectSet &effectList)
215
 
{
216
 
    for (unsigned int i = 0; i < effectList.effects.size (); i++)
217
 
        if (effectList.effects[i] == theEffect)
218
 
            return true;
219
 
    return false;
220
 
}
221
 
 
222
 
bool
223
 
PrivateAnimScreen::isAnimEffectPossibleForEvent (AnimEffect theEffect,
224
 
                                                 AnimEvent event)
225
 
{
226
 
    // Check all rows to see if the effect is chosen there
227
 
    unsigned int nRows = mEventEffects[event].effects.size ();
228
 
    for (unsigned int i = 0; i < nRows; i++)
229
 
    {
230
 
        AnimEffect chosenEffect = mEventEffects[event].effects[i];
231
 
        // if chosen directly
232
 
        if (chosenEffect == theEffect)
233
 
            return true;
234
 
        // if chosen in random pool
235
 
        if (mRandomEffects[event].effects.size () &&
236
 
            chosenEffect == AnimEffectRandom &&
237
 
            isAnimEffectInList (theEffect, mRandomEffects[event]))
238
 
            return true;
239
 
    }
240
 
    return false;
241
 
}
242
 
 
243
 
bool
244
 
PrivateAnimScreen::isAnimEffectPossible (AnimEffect theEffect)
245
 
{
246
 
    for (int e = 0; e < AnimEventNum; e++)
247
 
        if (isAnimEffectPossibleForEvent (theEffect, (AnimEvent)e))
248
 
            return true;
249
 
    return false;
250
 
}
251
 
 
252
 
bool
253
 
PrivateAnimScreen::isRestackAnimPossible ()
254
 
{
255
 
    // Check all rows to see if the chosen effect is a restack animation
256
 
    unsigned int nRows = mEventEffects[AnimEventFocus].effects.size ();
257
 
 
258
 
    for (unsigned int i = 0; i < nRows; i++)
259
 
    {
260
 
        AnimEffect chosenEffect = mEventEffects[(unsigned)AnimEventFocus].
261
 
            effects[i];
262
 
        if (chosenEffect->isRestackAnim)
263
 
            return true;
264
 
    }
265
 
    return false;
266
 
}
267
 
 
268
 
bool
269
 
AnimScreen::isRestackAnimPossible ()
270
 
{
271
 
    return priv->isRestackAnimPossible ();
272
 
}
273
 
 
274
 
// Extension functions
275
 
 
276
 
void
277
 
AnimScreen::addExtension (ExtensionPluginInfo *extensionPluginInfo)
278
 
{
279
 
    priv->addExtension (extensionPluginInfo, true);
280
 
}
281
 
 
282
 
void
283
 
PrivateAnimScreen::addExtension (ExtensionPluginInfo *extensionPluginInfo,
284
 
                                 bool shouldInitPersistentData)
285
 
{
286
 
    mExtensionPlugins.push_back (extensionPluginInfo);
287
 
 
288
 
    unsigned int nPluginEffects = extensionPluginInfo->nEffects;
289
 
 
290
 
    bool eventEffectsNeedUpdate[AnimEventNum] =
291
 
        {false, false, false, false, false};
292
 
 
293
 
    // Put this plugin's effects into mEventEffects and
294
 
    // mEventEffectsAllowed
295
 
    for (unsigned int j = 0; j < nPluginEffects; j++)
296
 
    {
297
 
        const AnimEffect effect = extensionPluginInfo->effects[j];
298
 
 
299
 
        // Update allowed effects for each event
300
 
        for (int e = 0; e < AnimEventNum; e++)
301
 
        {
302
 
            if (effect->usedForEvents[e])
303
 
            {
304
 
                mEventEffectsAllowed[e].push_back (effect);
305
 
                eventEffectsNeedUpdate[e] = true;
306
 
            }
307
 
        }
308
 
    }
309
 
 
310
 
    for (int e = 0; e < AnimEventNum; e++)
311
 
        if (eventEffectsNeedUpdate[e])
312
 
        {
313
 
            updateEventEffects ((AnimEvent)e, false, false);
314
 
            if (e != AnimEventFocus)
315
 
                updateEventEffects ((AnimEvent)e, true, false);
316
 
        }
317
 
 
318
 
    if (shouldInitPersistentData)
319
 
    {
320
 
        // Initialize persistent window data for the extension plugin
321
 
        foreach (CompWindow *w, ::screen->windows ())
322
 
        {
323
 
            AnimWindow *aw = AnimWindow::get (w);
324
 
            extensionPluginInfo->initPersistentData (aw);
325
 
        }
326
 
    }
327
 
}
328
 
 
329
 
void
330
 
AnimScreen::removeExtension (ExtensionPluginInfo *extensionPluginInfo)
331
 
{
332
 
    priv->removeExtension (extensionPluginInfo);
333
 
}
334
 
 
335
 
void
336
 
PrivateAnimScreen::removeExtension (ExtensionPluginInfo *extensionPluginInfo)
337
 
{
338
 
    // Stop all ongoing animations
339
 
    foreach (CompWindow *w, ::screen->windows ())
340
 
    {
341
 
        PrivateAnimWindow *aw = AnimWindow::get (w)->priv;
342
 
        if (aw->curAnimation ())
343
 
            aw->postAnimationCleanUp ();
344
 
    }
345
 
 
346
 
    // Find the matching plugin and delete it
347
 
 
348
 
    ExtensionPluginVector::iterator it = find (mExtensionPlugins.begin (),
349
 
                                               mExtensionPlugins.end (),
350
 
                                               extensionPluginInfo);
351
 
 
352
 
    if (it == mExtensionPlugins.end ())
353
 
        return; // couldn't find that extension plugin
354
 
 
355
 
    mExtensionPlugins.erase (it);
356
 
 
357
 
    if (extensionPluginInfo->nEffects == 0)
358
 
        return; // no animation effects -> we're done here
359
 
 
360
 
 
361
 
    // Also delete the "allowed effect" entries for that plugin
362
 
 
363
 
    for (int e = 0; e < AnimEventNum; e++)
364
 
    {
365
 
        AnimEffectVector &eventEffectsAllowed = mEventEffectsAllowed[e];
366
 
 
367
 
        // Find the first animation effect with matching name
368
 
        AnimEffectVector::iterator itBeginEffect =
369
 
            find_if (eventEffectsAllowed.begin (),
370
 
                     eventEffectsAllowed.end (),
371
 
                     boost::bind (&AnimEffectInfo::matchesPluginName,
372
 
                                  _1, extensionPluginInfo->name));
373
 
 
374
 
        if (itBeginEffect == eventEffectsAllowed.end ())
375
 
            continue; // plugin didn't provide any effects for this event
376
 
 
377
 
        // Find the first animation effect with non-matching name,
378
 
        // starting with itBeginEffect
379
 
        AnimEffectVector::iterator itEndEffect =
380
 
            find_if (itBeginEffect,
381
 
                     eventEffectsAllowed.end (),
382
 
                     boost::bind (&AnimEffectInfo::matchesPluginName,
383
 
                                  _1, extensionPluginInfo->name) == false);
384
 
 
385
 
        eventEffectsAllowed.erase (itBeginEffect, itEndEffect);
386
 
 
387
 
        // Update event effects to complete removal
388
 
        updateEventEffects ((AnimEvent)e, false);
389
 
        if (e != AnimEventFocus)
390
 
            updateEventEffects ((AnimEvent)e, true);
391
 
    }
392
 
 
393
 
    // Destroy persistent window data for the extension plugin
394
 
    foreach (CompWindow *w, ::screen->windows ())
395
 
    {
396
 
        AnimWindow *aw = AnimWindow::get (w);
397
 
        extensionPluginInfo->destroyPersistentData (aw);
398
 
    }
399
 
}
400
 
 
401
 
ExtensionPluginInfo::ExtensionPluginInfo (const CompString &name,
402
 
                                          unsigned int nEffects,
403
 
                                          AnimEffect *effects,
404
 
                                          CompOption::Vector *effectOptions,
405
 
                                          unsigned int firstEffectOptionIndex) :
406
 
    name (name),
407
 
    nEffects (nEffects),
408
 
    effects (effects),
409
 
    effectOptions (effectOptions),
410
 
    firstEffectOptionIndex (firstEffectOptionIndex)
411
 
{
412
 
}
413
 
 
414
 
// End of extension functions
415
 
 
416
 
Animation::Animation (CompWindow *w,
417
 
                      WindowEvent curWindowEvent,
418
 
                      float duration,
419
 
                      const AnimEffect info,
420
 
                      const CompRect &icon) :
421
 
    mWindow (w),
422
 
    mAWindow (AnimWindow::get (w)),
423
 
    mTotalTime (duration),
424
 
    mRemainingTime (duration),
425
 
    mTimeElapsedWithinTimeStep (0),
426
 
    mOverrideProgressDir (0),
427
 
    mCurPaintAttrib (GLWindow::defaultPaintAttrib),
428
 
    mStoredOpacity (CompositeWindow::get (w)->opacity ()),
429
 
    mCurWindowEvent (curWindowEvent),
430
 
    mInitialized (false), // store window opacity
431
 
    mInfo (info),
432
 
    mIcon (icon)
433
 
{
434
 
    if (curWindowEvent == WindowEventShade ||
435
 
        curWindowEvent == WindowEventUnshade)
436
 
    {
437
 
        mDecorTopHeight = w->output ().top;
438
 
        mDecorBottomHeight = w->output ().bottom;
439
 
    }
440
 
 
441
 
    texturesCache = new GLTexture::List (GLWindow::get (w)->textures ());
442
 
    PrivateAnimScreen *as = mAWindow->priv->paScreen ();
443
 
 
444
 
    mTimestep = as->optionGetTimeStep ();
445
 
}
446
 
 
447
 
Animation::~Animation ()
448
 
{
449
 
    delete texturesCache;
450
 
}
451
 
 
452
 
CompOption::Value &
453
 
Animation::optVal (unsigned int optionId)
454
 
{
455
 
    return mAWindow->pluginOptVal (getExtensionPluginInfo (), optionId, this);
456
 
}
457
 
 
458
 
/// Play the animation effect backwards from where it left off.
459
 
void
460
 
Animation::reverse ()
461
 
{
462
 
    mRemainingTime = mTotalTime - mRemainingTime;
463
 
 
464
 
    // avoid window remains
465
 
    if (mRemainingTime <= 0)
466
 
        mRemainingTime = 1;
467
 
 
468
 
    switch (mCurWindowEvent) // the old event
469
 
    {
470
 
    case WindowEventOpen:
471
 
        mCurWindowEvent = WindowEventClose;
472
 
        break;
473
 
    case WindowEventClose:
474
 
        mCurWindowEvent = WindowEventOpen;
475
 
        break;
476
 
    case WindowEventMinimize:
477
 
        mCurWindowEvent = WindowEventUnminimize;
478
 
        break;
479
 
    case WindowEventUnminimize:
480
 
        mCurWindowEvent = WindowEventMinimize;
481
 
        break;
482
 
    case WindowEventShade:
483
 
        mCurWindowEvent = WindowEventUnshade;
484
 
        break;
485
 
    case WindowEventUnshade:
486
 
        mCurWindowEvent = WindowEventShade;
487
 
        break;
488
 
    default:
489
 
        break;
490
 
    }
491
 
 
492
 
    // 1: forward, 2: backward  (3 - progressDir is opposite direction)
493
 
    int progressDir = 1;
494
 
 
495
 
    switch (mCurWindowEvent) // the new event
496
 
    {
497
 
    case WindowEventClose:
498
 
    case WindowEventMinimize:
499
 
    case WindowEventShade:
500
 
        progressDir = 2;
501
 
        break;
502
 
    default:
503
 
        break;
504
 
    }
505
 
 
506
 
    if (mOverrideProgressDir == 0)
507
 
        mOverrideProgressDir = progressDir;
508
 
    else if (mOverrideProgressDir == 3 - progressDir)
509
 
        mOverrideProgressDir = 0; // disable override
510
 
}
511
 
 
512
 
PartialWindowAnim::PartialWindowAnim (CompWindow *w,
513
 
                                      WindowEvent curWindowEvent,
514
 
                                      float duration,
515
 
                                      const AnimEffect info,
516
 
                                      const CompRect &icon) :
517
 
    Animation::Animation (w, curWindowEvent, duration, info, icon),
518
 
    mUseDrawRegion (false),
519
 
    mDrawRegion ()
520
 
{
521
 
}
522
 
 
523
 
void
524
 
PrivateAnimWindow::updateSelectionRow (unsigned int r)
525
 
{
526
 
    mPrevAnimSelectionRow = mCurAnimSelectionRow;
527
 
    mCurAnimSelectionRow = (int)r;
528
 
}
529
 
 
530
 
// Assumes events in the metadata are in
531
 
// [Open, Close, Minimize, Focus, Shade] order
532
 
// and effects among those are in alphabetical order
533
 
// but with "(Event) None" first and "(Event) Random" last.
534
 
AnimEffect
535
 
PrivateAnimScreen::getMatchingAnimSelection (CompWindow *w,
536
 
                                             AnimEvent e,
537
 
                                             int *duration)
538
 
{
539
 
    PrivateAnimWindow *aw = AnimWindow::get (w)->priv;
540
 
 
541
 
    EffectSet *eventEffects = &mEventEffects[e];
542
 
    CompOption::Value &valMatch =
543
 
        getOptions ()[(unsigned)matchOptionIds[e]].value ();
544
 
    CompOption::Value &valDuration =
545
 
        getOptions ()[(unsigned)durationOptionIds[e]].value ();
546
 
    CompOption::Value &valCustomOptions =
547
 
        getOptions ()[(unsigned)customOptionOptionIds[e]].value ();
548
 
 
549
 
    unsigned int nRows = valMatch.list ().size ();
550
 
    if (nRows != eventEffects->effects.size () ||
551
 
        nRows != valDuration.list ().size () ||
552
 
        nRows != valCustomOptions.list ().size ())
553
 
    {
554
 
        compLogMessage ("animation", CompLogLevelError,
555
 
                        "Animation settings mismatch in \"Animation "
556
 
                        "Selection\" list for %s event.", eventNames[e]);
557
 
        return AnimEffectNone;
558
 
    }
559
 
 
560
 
    // Find the first row that matches this window for this event
561
 
    for (unsigned int i = 0; i < nRows; i++)
562
 
    {
563
 
        if (!valMatch.list ()[i].match ().evaluate (w))
564
 
            continue;
565
 
 
566
 
        aw->updateSelectionRow (i);
567
 
 
568
 
        if (duration)
569
 
            *duration = valDuration.list ()[i].i ();
570
 
 
571
 
        AnimEffect effect = eventEffects->effects[i];
572
 
 
573
 
        return (effect ? effect : AnimEffectNone);
574
 
    }
575
 
 
576
 
    return AnimEffectNone;
577
 
}
578
 
 
579
 
AnimEffect
580
 
PrivateAnimScreen::getActualEffect (AnimEffect effect,
581
 
                                    AnimEvent animEvent)
582
 
{
583
 
    bool allRandom = optionGetAllRandom ();
584
 
    AnimEffectVector *randomEffects = &mRandomEffects[animEvent].effects;
585
 
    unsigned int nRandomEffects = randomEffects->size ();
586
 
    unsigned int nFirstRandomEffect = 0;
587
 
 
588
 
    if ((effect == AnimEffectRandom) || allRandom)
589
 
    {
590
 
        if (nRandomEffects == 0) // no random animation selected, assume "all"
591
 
        {
592
 
            randomEffects = &mEventEffectsAllowed[animEvent];
593
 
 
594
 
            // exclude None and Random
595
 
            nFirstRandomEffect = 2;
596
 
            nRandomEffects = randomEffects->size () - 2;
597
 
        }
598
 
        unsigned int index = nFirstRandomEffect +
599
 
            (unsigned int)(nRandomEffects * (double)rand () / RAND_MAX);
600
 
        return (*randomEffects)[index];
601
 
    }
602
 
    else
603
 
        return effect;
604
 
}
605
 
 
606
 
/// Converts animation direction (up, down, left, right, random, auto)
607
 
/// to an actual direction (up, down, left, or right).
608
 
AnimDirection
609
 
Animation::getActualAnimDirection (AnimDirection dir,
610
 
                                   bool openDir)
611
 
{
612
 
    if (dir == AnimDirectionRandom)
613
 
    {
614
 
        dir = (AnimDirection)(rand () % 4);
615
 
    }
616
 
    else if (dir == AnimDirectionAuto)
617
 
    {
618
 
        CompRect outRect (mAWindow->savedRectsValid () ?
619
 
                          mAWindow->savedOutRect () :
620
 
                          mWindow->outputRect ());
621
 
 
622
 
        // away from icon
623
 
        int centerX = outRect.x () + outRect.width () / 2 ;
624
 
        int centerY = outRect.y () + outRect.height () / 2 ;
625
 
        float relDiffX = ((float)centerX - mIcon.x ()) / outRect.width ();
626
 
        float relDiffY = ((float)centerY - mIcon.y ()) / outRect.height ();
627
 
 
628
 
        if (openDir)
629
 
        {
630
 
            if (mCurWindowEvent == WindowEventMinimize ||
631
 
                mCurWindowEvent == WindowEventUnminimize)
632
 
                // min/unmin. should always result in +/- y direction
633
 
                dir = (mIcon.y () < (int)::screen->height () - mIcon.y ()) ?
634
 
                    AnimDirectionDown : AnimDirectionUp;
635
 
            else if (fabs (relDiffY) > fabs (relDiffX))
636
 
                dir = relDiffY > 0 ? AnimDirectionDown : AnimDirectionUp;
637
 
            else
638
 
                dir = relDiffX > 0 ? AnimDirectionRight : AnimDirectionLeft;
639
 
        }
640
 
        else
641
 
        {
642
 
            if (mCurWindowEvent == WindowEventMinimize ||
643
 
                mCurWindowEvent == WindowEventUnminimize)
644
 
                // min/unmin. should always result in +/- y direction
645
 
                dir = (mIcon.y () < (int)::screen->height () - mIcon.y ()) ?
646
 
                    AnimDirectionUp : AnimDirectionDown;
647
 
            else if (fabs (relDiffY) > fabs (relDiffX))
648
 
                dir = relDiffY > 0 ? AnimDirectionUp : AnimDirectionDown;
649
 
            else
650
 
                dir = relDiffX > 0 ? AnimDirectionLeft : AnimDirectionRight;
651
 
        }
652
 
    }
653
 
    return dir;
654
 
}
655
 
 
656
 
float
657
 
Animation::progressLinear ()
658
 
{
659
 
    float forwardProgress =
660
 
        1 - mRemainingTime / (mTotalTime - mTimestep);
661
 
    forwardProgress = MIN (forwardProgress, 1);
662
 
    forwardProgress = MAX (forwardProgress, 0);
663
 
 
664
 
    if (mCurWindowEvent == WindowEventOpen ||
665
 
        mCurWindowEvent == WindowEventUnminimize ||
666
 
        mCurWindowEvent == WindowEventUnshade ||
667
 
        mCurWindowEvent == WindowEventFocus)
668
 
        forwardProgress = 1 - forwardProgress;
669
 
 
670
 
    return forwardProgress;
671
 
}
672
 
 
673
 
float
674
 
Animation::progressEaseInEaseOut ()
675
 
{
676
 
    float forwardProgress =
677
 
        1 - mRemainingTime / (mTotalTime - mTimestep);
678
 
    forwardProgress = MIN (forwardProgress, 1);
679
 
    forwardProgress = MAX (forwardProgress, 0);
680
 
 
681
 
    // Apply sigmoid and normalize
682
 
    forwardProgress =
683
 
        (sigmoid (forwardProgress) - sigmoid (0)) /
684
 
        (sigmoid (1) - sigmoid (0));
685
 
 
686
 
    if (mCurWindowEvent == WindowEventOpen ||
687
 
        mCurWindowEvent == WindowEventUnminimize ||
688
 
        mCurWindowEvent == WindowEventUnshade ||
689
 
        mCurWindowEvent == WindowEventFocus)
690
 
        forwardProgress = 1 - forwardProgress;
691
 
 
692
 
    return forwardProgress;
693
 
}
694
 
 
695
 
/// Gives some acceleration (when closing a window)
696
 
/// or deceleration (when opening a window).
697
 
/// Applies a sigmoid with slope s,
698
 
/// where minx and maxx are the
699
 
/// starting and ending points on the sigmoid.
700
 
float
701
 
Animation::progressDecelerateCustom (float progress, float minx, float maxx)
702
 
{
703
 
    float x = 1 - progress;
704
 
    float s = 8;
705
 
 
706
 
    return
707
 
        1 - ((sigmoid2 (minx + (x * (maxx - minx)), s) - sigmoid2 (minx, s)) /
708
 
             (sigmoid2 (maxx, s) - sigmoid2 (minx, s)));
709
 
}
710
 
 
711
 
float
712
 
Animation::progressDecelerate (float progress)
713
 
{
714
 
    return progressDecelerateCustom (progress, 0.5, 0.75);
715
 
}
716
 
 
717
 
BoxPtr
718
 
AnimWindow::BB ()
719
 
{
720
 
    return &priv->mBB;
721
 
}
722
 
 
723
 
CompRegion &
724
 
AnimWindow::stepRegion ()
725
 
{
726
 
    return priv->mStepRegion;
727
 
}
728
 
 
729
 
void
730
 
PrivateAnimWindow::copyResetStepRegion ()
731
 
{
732
 
    mLastStepRegion = mStepRegion;
733
 
 
734
 
    // Reset bounding box for current step
735
 
    mBB.x1 = mBB.y1 = MAXSHORT;
736
 
    mBB.x2 = mBB.y2 = MINSHORT;
737
 
}
738
 
 
739
 
void
740
 
AnimWindow::expandBBWithBox (Box &source)
741
 
{
742
 
    Box &target = priv->BB ();
743
 
 
744
 
    if (source.x1 < target.x1)
745
 
        target.x1 = source.x1;
746
 
    if (source.x2 > target.x2)
747
 
        target.x2 = source.x2;
748
 
    if (source.y1 < target.y1)
749
 
        target.y1 = source.y1;
750
 
    if (source.y2 > target.y2)
751
 
        target.y2 = source.y2;
752
 
}
753
 
 
754
 
void
755
 
AnimWindow::expandBBWithPoint (float fx, float fy)
756
 
{
757
 
    Box &target = priv->BB ();
758
 
 
759
 
    short x = MAX (MIN (fx, MAXSHORT - 1), MINSHORT);
760
 
    short y = MAX (MIN (fy, MAXSHORT - 1), MINSHORT);
761
 
 
762
 
    if (target.x1 == MAXSHORT)
763
 
    {
764
 
        target.x1 = x;
765
 
        target.y1 = y;
766
 
        target.x2 = x + 1;
767
 
        target.y2 = y + 1;
768
 
        return;
769
 
    }
770
 
    if (x < target.x1)
771
 
        target.x1 = x;
772
 
    else if (x > target.x2)
773
 
        target.x2 = x;
774
 
 
775
 
    if (y < target.y1)
776
 
        target.y1 = y;
777
 
    else if (y > target.y2)
778
 
        target.y2 = y;
779
 
}
780
 
 
781
 
/// This will work for zoom-like 2D transforms,
782
 
/// but not for glide-like 3D transforms.
783
 
void
784
 
AnimWindow::expandBBWithPoint2DTransform (GLVector &coords,
785
 
                                          GLMatrix &transformMat)
786
 
{
787
 
    GLVector coordsTransformed = transformMat * coords;
788
 
    expandBBWithPoint (coordsTransformed[GLVector::x],
789
 
                       coordsTransformed[GLVector::y]);
790
 
}
791
 
 
792
 
/// Either points or objects should be non-0.
793
 
bool
794
 
AnimWindow::expandBBWithPoints3DTransform (CompOutput     &output,
795
 
                                           GLMatrix       &transform,
796
 
                                           const float    *points,
797
 
                                           GridAnim::GridModel::GridObject *objects,
798
 
                                           unsigned int   nPoints)
799
 
{
800
 
    GLdouble dModel[16];
801
 
    GLdouble dProjection[16];
802
 
    GLdouble x, y, z;
803
 
    for (unsigned int i = 0; i < 16; i++)
804
 
    {
805
 
        dModel[i] = transform[i];
806
 
        dProjection[i] = GLScreen::get (::screen)->projectionMatrix ()[i];
807
 
    }
808
 
    GLint viewport[4] =
809
 
        {output.region ()->extents.x1,
810
 
         output.region ()->extents.y1,
811
 
         output.width (),
812
 
         output.height ()};
813
 
 
814
 
    if (points) // use points
815
 
    {
816
 
        for (; nPoints; nPoints--, points += 3)
817
 
        {
818
 
            if (!gluProject (points[0], points[1], points[2],
819
 
                             dModel, dProjection, viewport,
820
 
                             &x, &y, &z))
821
 
                return false;
822
 
 
823
 
            expandBBWithPoint (x + 0.5, (::screen->height () - y) + 0.5);
824
 
        }
825
 
    }
826
 
    else // use grid model objects
827
 
    {
828
 
        GridAnim::GridModel::GridObject *object = objects;
829
 
        for (; nPoints; nPoints--, object++)
830
 
        {
831
 
            if (!gluProject (object->position ().x (),
832
 
                             object->position ().y (),
833
 
                             object->position ().z (),
834
 
                             dModel, dProjection, viewport,
835
 
                             &x, &y, &z))
836
 
                return false;
837
 
 
838
 
            expandBBWithPoint (x + 0.5, (::screen->height () - y) + 0.5);
839
 
        }
840
 
    }
841
 
    return true;
842
 
}
843
 
 
844
 
void
845
 
AnimWindow::expandBBWithWindow ()
846
 
{
847
 
    CompRect outRect (savedRectsValid () ?
848
 
                      savedOutRect () :
849
 
                      mWindow->outputRect ());
850
 
    Box windowBox = {
851
 
        outRect.x (), outRect.x () + outRect.width (),
852
 
        outRect.y (), outRect.y () + outRect.height ()
853
 
    };
854
 
    expandBBWithBox (windowBox);
855
 
}
856
 
 
857
 
void
858
 
AnimWindow::expandBBWithScreen ()
859
 
{
860
 
    Box screenBox = {0, ::screen->width (),
861
 
                     0, ::screen->height ()};
862
 
    expandBBWithBox (screenBox);
863
 
}
864
 
 
865
 
void
866
 
Animation::prepareTransform (CompOutput &output,
867
 
                             GLMatrix &resultTransform,
868
 
                             GLMatrix &transform)
869
 
{
870
 
    GLMatrix sTransform;
871
 
    sTransform.toScreenSpace (&output, -DEFAULT_Z_CAMERA);
872
 
    resultTransform = sTransform * transform;
873
 
}
874
 
 
875
 
void
876
 
AnimWindow::resetStepRegionWithBB ()
877
 
{
878
 
    // Have a 1 pixel margin to prevent occasional 1 pixel line artifact
879
 
    CompRegion region (priv->mBB.x1 - 1,
880
 
                       priv->mBB.y1 - 1,
881
 
                       priv->mBB.x2 - priv->mBB.x1 + 2,
882
 
                       priv->mBB.y2 - priv->mBB.y1 + 2);
883
 
    priv->mStepRegion = region;
884
 
}
885
 
 
886
 
/// Damage the union of window's bounding box
887
 
/// before and after animStepFunc does its job.
888
 
void
889
 
PrivateAnimWindow::damageThisAndLastStepRegion ()
890
 
{
891
 
    // Find union of the regions for this step and last step
892
 
    CompRegion totalRegionToDamage (mStepRegion + mLastStepRegion);
893
 
 
894
 
    mPAScreen->cScreen->damageRegion (totalRegionToDamage);
895
 
}
896
 
 
897
 
CompOutput &
898
 
AnimScreen::output ()
899
 
{
900
 
    return priv->output ();
901
 
}
902
 
 
903
 
bool
904
 
AnimScreen::getMousePointerXY (short *x, short *y)
905
 
{
906
 
    Window w1, w2;
907
 
    int xp, yp, xj, yj;
908
 
    unsigned int m;
909
 
 
910
 
    if (XQueryPointer
911
 
        (::screen->dpy (), ::screen->root (), &w1, &w2, &xj, &yj, &xp, &yp, &m))
912
 
    {
913
 
        *x = xp;
914
 
        *y = yp;
915
 
        return true;
916
 
    }
917
 
    return false;
918
 
}
919
 
 
920
 
unsigned int
921
 
PrivateAnimWindow::getState ()
922
 
{
923
 
    Atom actual;
924
 
    int result, format;
925
 
    unsigned long n, left;
926
 
    unsigned char *data;
927
 
    unsigned int retval = WithdrawnState;
928
 
 
929
 
    result = XGetWindowProperty (::screen->dpy (), mWindow->id (),
930
 
                                 Atoms::wmState, 0L,
931
 
                                 1L, false,
932
 
                                 Atoms::wmState,
933
 
                                 &actual, &format, &n, &left, &data);
934
 
 
935
 
    if (result == Success && data)
936
 
    {
937
 
        if (n)
938
 
            memcpy (&retval, data, sizeof (int));
939
 
 
940
 
        XFree ((void *)data);
941
 
    }
942
 
 
943
 
    return retval;
944
 
}
945
 
 
946
 
CompOption::Vector &
947
 
AnimScreen::getOptions ()
948
 
{
949
 
    return priv->getOptions ();
950
 
}
951
 
 
952
 
bool
953
 
AnimScreen::setOption (const CompString  &name,
954
 
                       CompOption::Value &value)
955
 
{
956
 
    return priv->setOption (name, value);
957
 
}
958
 
 
959
 
void
960
 
PrivateAnimScreen::eventMatchesChanged (CompOption                *opt,
961
 
                                        AnimationOptions::Options num)
962
 
{
963
 
    if (mExtensionPlugins.size () == 0)
964
 
        initAnimationList ();
965
 
    foreach (CompOption::Value &val, opt->value ().list ())
966
 
        val.match ().update ();
967
 
}
968
 
 
969
 
void
970
 
PrivateAnimScreen::eventOptionsChanged (CompOption                *opt,
971
 
                                        AnimationOptions::Options num)
972
 
{
973
 
    if (mExtensionPlugins.size () == 0)
974
 
        initAnimationList ();
975
 
    updateOptionSets (getCorrespondingAnimEvent (num));
976
 
}
977
 
 
978
 
void
979
 
PrivateAnimScreen::eventEffectsChanged (CompOption                *opt,
980
 
                                        AnimationOptions::Options num)
981
 
{
982
 
    if (mExtensionPlugins.size () == 0)
983
 
        initAnimationList ();
984
 
    updateEventEffects (getCorrespondingAnimEvent (num), false);
985
 
}
986
 
 
987
 
void
988
 
PrivateAnimScreen::eventRandomEffectsChanged (CompOption                *opt,
989
 
                                              AnimationOptions::Options num)
990
 
{
991
 
    if (mExtensionPlugins.size () == 0)
992
 
        initAnimationList ();
993
 
    updateEventEffects (getCorrespondingAnimEvent (num), true);
994
 
}
995
 
 
996
 
void
997
 
PrivateAnimWindow::postAnimationCleanUpCustom (bool closing,
998
 
                                               bool destructing,
999
 
                                               bool clearMatchingRow)
1000
 
{
1001
 
    bool shouldDamageWindow = false;
1002
 
    
1003
 
    notifyAnimation (false);
1004
 
 
1005
 
    if (mCurAnimation)
1006
 
    {
1007
 
        if (mCurAnimation->shouldDamageWindowOnEnd ())
1008
 
            shouldDamageWindow = true;
1009
 
    }
1010
 
    enablePainting (false);
1011
 
 
1012
 
    if (shouldDamageWindow)
1013
 
        mAWindow->expandBBWithWindow ();
1014
 
 
1015
 
    if (shouldDamageWindow ||
1016
 
        (mCurAnimation &&
1017
 
         !mCurAnimation->stepRegionUsed () &&
1018
 
         mAWindow->BB ()->x1 != MAXSHORT)) // BB intialized
1019
 
        mAWindow->resetStepRegionWithBB ();
1020
 
 
1021
 
    damageThisAndLastStepRegion ();
1022
 
 
1023
 
    if (mCurAnimation)
1024
 
    {
1025
 
        mCurAnimation->cleanUp (closing, destructing);
1026
 
        delete mCurAnimation;
1027
 
        mCurAnimation = 0;
1028
 
    }
1029
 
 
1030
 
    mBB.x1 = mBB.y1 = MAXSHORT;
1031
 
    mBB.x2 = mBB.y2 = MINSHORT;
1032
 
 
1033
 
    mState = mNewState;
1034
 
 
1035
 
    if (clearMatchingRow)
1036
 
        mCurAnimSelectionRow = -1;
1037
 
 
1038
 
    mFinishingAnim = true;
1039
 
    if (!destructing)
1040
 
    {
1041
 
        mIgnoreDamage = true;
1042
 
        while (mUnmapCnt > 0)
1043
 
        {
1044
 
            mWindow->unmap ();
1045
 
            mUnmapCnt--;
1046
 
        }
1047
 
        if (mUnmapCnt < 0)
1048
 
            mUnmapCnt = 0;
1049
 
        mIgnoreDamage = false;
1050
 
    }
1051
 
 
1052
 
    while (mDestroyCnt)
1053
 
    {
1054
 
        mWindow->destroy ();
1055
 
        mDestroyCnt--;
1056
 
    }
1057
 
    mFinishingAnim = false;
1058
 
 
1059
 
    foreach (ExtensionPluginInfo *extPlugin, mPAScreen->mExtensionPlugins)
1060
 
        extPlugin->cleanUpAnimation (closing, destructing);
1061
 
}
1062
 
 
1063
 
void
1064
 
AnimWindow::postAnimationCleanUp ()
1065
 
{
1066
 
    priv->postAnimationCleanUp ();
1067
 
}
1068
 
 
1069
 
void
1070
 
PrivateAnimWindow::postAnimationCleanUp ()
1071
 
{
1072
 
    if (mCurAnimation->curWindowEvent () == WindowEventClose)
1073
 
        postAnimationCleanUpCustom (true, false, true);
1074
 
    else
1075
 
        postAnimationCleanUpCustom (false, false, true);
1076
 
}
1077
 
 
1078
 
void
1079
 
PrivateAnimWindow::postAnimationCleanUpPrev (bool closing,
1080
 
                                             bool clearMatchingRow)
1081
 
{
1082
 
    int curAnimSelectionRow = mCurAnimSelectionRow;
1083
 
    // Use previous event's anim selection row
1084
 
    mCurAnimSelectionRow = mPrevAnimSelectionRow;
1085
 
 
1086
 
    postAnimationCleanUpCustom (closing, false, clearMatchingRow);
1087
 
 
1088
 
    // Restore current event's anim selection row
1089
 
    mCurAnimSelectionRow = curAnimSelectionRow;
1090
 
}
1091
 
 
1092
 
void
1093
 
PrivateAnimScreen::activateEvent (bool activating)
1094
 
{
1095
 
    if (activating)
1096
 
    {
1097
 
        if (mAnimInProgress)
1098
 
            return;
1099
 
    }
1100
 
    else
1101
 
    {
1102
 
        // Animations have finished for all windows
1103
 
        // (Keep preparePaint enabled)
1104
 
 
1105
 
        cScreen->getWindowPaintListSetEnabled (this, false);
1106
 
        enablePrePaintWindowsBackToFront (false);
1107
 
    }
1108
 
    cScreen->donePaintSetEnabled (this, activating);
1109
 
    gScreen->glPaintOutputSetEnabled (this, activating);
1110
 
 
1111
 
    mAnimInProgress = activating;
1112
 
 
1113
 
    CompOption::Vector o (0);
1114
 
 
1115
 
    o.push_back (CompOption ("root", CompOption::TypeInt));
1116
 
    o.push_back (CompOption ("active", CompOption::TypeBool));
1117
 
 
1118
 
    o[0].value ().set ((int) ::screen->root ());
1119
 
    o[1].value ().set (activating);
1120
 
 
1121
 
    ::screen->handleCompizEvent ("animation", "activate", o);
1122
 
}
1123
 
 
1124
 
void
1125
 
PrivateAnimWindow::notifyAnimation (bool activation)
1126
 
{
1127
 
    CompOption::Vector o (0);
1128
 
    
1129
 
    if (!mCurAnimation)
1130
 
        return;
1131
 
    
1132
 
    o.push_back (CompOption ("root", CompOption::TypeInt));
1133
 
    o.push_back (CompOption ("window", CompOption::TypeInt));
1134
 
    o.push_back (CompOption ("type", CompOption::TypeString));
1135
 
    o.push_back (CompOption ("active", CompOption::TypeBool));
1136
 
    
1137
 
    o[0].value ().set ((int) ::screen->root ());
1138
 
    o[1].value ().set ((int) mWindow->id ());
1139
 
        
1140
 
    switch (mCurAnimation->curWindowEvent ())
1141
 
    {
1142
 
        case WindowEventOpen:
1143
 
            o[2].value ().set ("open");
1144
 
            break;
1145
 
        case WindowEventClose:
1146
 
            o[2].value ().set ("close");
1147
 
            break;
1148
 
        case WindowEventMinimize:
1149
 
            o[2].value ().set ("minimize");
1150
 
            break;
1151
 
        case WindowEventUnminimize:
1152
 
            o[2].value ().set ("unminimize");
1153
 
            break;
1154
 
        case WindowEventShade:
1155
 
            o[2].value ().set ("shade");
1156
 
            break;
1157
 
        case WindowEventUnshade:
1158
 
            o[2].value ().set ("unshade");
1159
 
            break;
1160
 
        case WindowEventFocus:
1161
 
            o[2].value ().set ("focus");
1162
 
            break;
1163
 
        case WindowEventNum:
1164
 
        case WindowEventNone:
1165
 
        default:
1166
 
            o[2].value ().set ("none");
1167
 
            break;
1168
 
    }
1169
 
    
1170
 
    o[3].value ().set (activation);
1171
 
 
1172
 
    screen->handleCompizEvent ("animation", "window_animation", o);
1173
 
}
1174
 
 
1175
 
bool
1176
 
PrivateAnimScreen::otherPluginsActive ()
1177
 
{
1178
 
    for (int i = 0; i < WatchedScreenPluginNum; i++)
1179
 
        if (mPluginActive[i])
1180
 
            return true;
1181
 
    return false;
1182
 
}
1183
 
 
1184
 
bool
1185
 
Animation::shouldSkipFrame (int msSinceLastPaintActual)
1186
 
{
1187
 
    mTimeElapsedWithinTimeStep += msSinceLastPaintActual;
1188
 
    if (mTimeElapsedWithinTimeStep < mTimestep) // if timestep not yet completed
1189
 
        return true;
1190
 
 
1191
 
    mTimeElapsedWithinTimeStep = fmod (mTimeElapsedWithinTimeStep, mTimestep);
1192
 
    return false;
1193
 
}
1194
 
 
1195
 
bool
1196
 
Animation::advanceTime (int msSinceLastPaint)
1197
 
{
1198
 
    mRemainingTime -= msSinceLastPaint;
1199
 
    mRemainingTime = MAX (mRemainingTime, 0); // avoid sub-zero values
1200
 
 
1201
 
    mTimeSinceLastPaint = msSinceLastPaint;
1202
 
 
1203
 
    return (mRemainingTime > 0);
1204
 
}
1205
 
 
1206
 
void
1207
 
PrivateAnimScreen::preparePaint (int msSinceLastPaint)
1208
 
{
1209
 
    // Check and update "switcher post wait" counter
1210
 
    if (mSwitcherPostWait > 0)
1211
 
    {
1212
 
        mSwitcherPostWait++;
1213
 
        if (mSwitcherPostWait > 5) // wait over
1214
 
        {
1215
 
            mSwitcherPostWait = 0;
1216
 
 
1217
 
            // Reset stacking related info since it will
1218
 
            // cause problems because of the restacking
1219
 
            // just done by Switcher.
1220
 
            ExtensionPluginAnimation *extPlugin =
1221
 
                static_cast<ExtensionPluginAnimation *> (mExtensionPlugins[0]);
1222
 
            extPlugin->resetStackingInfo ();
1223
 
        }
1224
 
    }
1225
 
 
1226
 
    foreach (ExtensionPluginInfo *extPlugin, mExtensionPlugins)
1227
 
        extPlugin->prePreparePaintGeneral ();
1228
 
 
1229
 
    if (mAnimInProgress)
1230
 
    {   
1231
 
        int msSinceLastPaintActual;
1232
 
 
1233
 
        struct timeval curTime;
1234
 
        gettimeofday (&curTime, 0);
1235
 
 
1236
 
        if (mLastRedrawTimeFresh)
1237
 
        {
1238
 
            msSinceLastPaintActual = TIMEVALDIFF (&curTime, &mLastRedrawTime);
1239
 
            // handle clock rollback
1240
 
            if (msSinceLastPaintActual < 0)
1241
 
                msSinceLastPaintActual = 0;
1242
 
        }
1243
 
        else
1244
 
            msSinceLastPaintActual = 20; // assume 20 ms passed
1245
 
 
1246
 
        mLastRedrawTime = curTime; // Store current time for next time
1247
 
        mLastRedrawTimeFresh = true;
1248
 
 
1249
 
        bool animStillInProgress = false;
1250
 
 
1251
 
        foreach (CompWindow *w, ::screen->windows ())
1252
 
        {
1253
 
            AnimWindow *animWin = AnimWindow::get (w);
1254
 
            PrivateAnimWindow *aw = animWin->priv;
1255
 
            Animation *curAnim = aw->curAnimation ();
1256
 
 
1257
 
            if (curAnim)
1258
 
            {           
1259
 
                if (!curAnim->initialized ())
1260
 
                    curAnim->init ();
1261
 
 
1262
 
                if (curAnim->prePreparePaint (msSinceLastPaint))
1263
 
                    animStillInProgress = true;
1264
 
 
1265
 
                /* TODO optimize grid model by reusing one GridModel
1266
 
                if (aw->com.mModel &&
1267
 
                    (aw->com.mModel->winWidth != outRect.width () ||
1268
 
                     aw->com.mModel->winHeight != outRect.height ()))
1269
 
                {
1270
 
                    // mModel needs update
1271
 
                    // re-create mModel
1272
 
                    if (!animEnsureModel (w))
1273
 
                    {
1274
 
                        // Abort this window's animation
1275
 
                        postAnimationCleanUp (w);
1276
 
                        continue;
1277
 
                    }
1278
 
                }*/
1279
 
 
1280
 
                bool animShouldSkipFrame =
1281
 
                    (curAnim->shouldSkipFrame (msSinceLastPaintActual) &&
1282
 
                     // Skip only if we're not on the first animation frame
1283
 
                     curAnim->initialized ());
1284
 
 
1285
 
                // Skip only if we're not on the last animation frame
1286
 
                animShouldSkipFrame &=
1287
 
                    curAnim->advanceTime (msSinceLastPaint);
1288
 
 
1289
 
                if (!animShouldSkipFrame)
1290
 
                {
1291
 
                    if (curAnim->updateBBUsed ())
1292
 
                    {
1293
 
                        aw->copyResetStepRegion ();
1294
 
 
1295
 
                        if (!curAnim->initialized () &&
1296
 
                            curAnim->shouldDamageWindowOnStart ())
1297
 
                            aw->aWindow ()->expandBBWithWindow ();
1298
 
                    }
1299
 
 
1300
 
                    if (!curAnim->initialized ())
1301
 
                        curAnim->setInitialized ();
1302
 
 
1303
 
                    curAnim->step ();
1304
 
 
1305
 
                    if (curAnim->updateBBUsed ())
1306
 
                    {
1307
 
                        foreach (CompOutput &output, ::screen->outputDevs ())
1308
 
                            curAnim->updateBB (output);
1309
 
 
1310
 
                        if (!curAnim->stepRegionUsed () &&
1311
 
                            aw->BB ().x1 != MAXSHORT) // BB initialized
1312
 
                        {
1313
 
                            // BB is used instead of step region,
1314
 
                            // so reset step region here with BB.
1315
 
                            animWin->resetStepRegionWithBB ();
1316
 
                        }
1317
 
                        if (!(cScreen->damageMask () &
1318
 
                              COMPOSITE_SCREEN_DAMAGE_ALL_MASK))
1319
 
                            aw->damageThisAndLastStepRegion ();
1320
 
                    }
1321
 
                }
1322
 
 
1323
 
                bool finished = (curAnim->remainingTime () <= 0);
1324
 
                if (finished) // Animation is done
1325
 
                {
1326
 
                    aw->notifyAnimation (false);
1327
 
                    aw->postAnimationCleanUp ();
1328
 
                }
1329
 
                else
1330
 
                    animStillInProgress = true;
1331
 
            }
1332
 
        }
1333
 
 
1334
 
        foreach (CompWindow *w, ::screen->windows ())
1335
 
        {
1336
 
            PrivateAnimWindow *aw = AnimWindow::get (w)->priv;
1337
 
            if (aw->curAnimation ())
1338
 
                aw->curAnimation ()->postPreparePaint ();
1339
 
        }
1340
 
 
1341
 
        if (!animStillInProgress)
1342
 
        {
1343
 
            activateEvent (false);
1344
 
            mLastRedrawTimeFresh = false;
1345
 
 
1346
 
            // Reset stacking related info after all animations are done.
1347
 
            ExtensionPluginAnimation *extPlugin =
1348
 
                static_cast<ExtensionPluginAnimation *> (mExtensionPlugins[0]);
1349
 
            extPlugin->resetStackingInfo ();
1350
 
        }
1351
 
    }
1352
 
 
1353
 
    foreach (ExtensionPluginInfo *extPlugin, mExtensionPlugins)
1354
 
        extPlugin->postPreparePaintGeneral ();
1355
 
 
1356
 
    cScreen->preparePaint (msSinceLastPaint);
1357
 
 
1358
 
    if (mStartCountdown)
1359
 
    {
1360
 
        mStartCountdown--;
1361
 
        if (!mStartCountdown)
1362
 
        {
1363
 
            foreach (ExtensionPluginInfo *extPlugin, mExtensionPlugins)
1364
 
                extPlugin->postStartupCountdown ();
1365
 
        }
1366
 
    }
1367
 
}
1368
 
 
1369
 
void
1370
 
PrivateAnimScreen::donePaint ()
1371
 
{
1372
 
    assert (mAnimInProgress);
1373
 
 
1374
 
    cScreen->damagePending ();
1375
 
 
1376
 
    cScreen->donePaint ();
1377
 
}
1378
 
 
1379
 
void
1380
 
PrivateAnimWindow::enablePainting (bool enabling)
1381
 
{
1382
 
    gWindow->glPaintSetEnabled (this, enabling);
1383
 
    gWindow->glAddGeometrySetEnabled (this, enabling);
1384
 
    gWindow->glDrawGeometrySetEnabled (this, enabling);
1385
 
    gWindow->glDrawTextureSetEnabled (this, enabling);
1386
 
}
1387
 
 
1388
 
void
1389
 
PrivateAnimWindow::glAddGeometry (const GLTexture::MatrixList &matrix,
1390
 
                                  const CompRegion            &region,
1391
 
                                  const CompRegion            &clip,
1392
 
                                  unsigned int                maxGridWidth,
1393
 
                                  unsigned int                maxGridHeight)
1394
 
{
1395
 
    // if window is being animated
1396
 
    if (mCurAnimation)
1397
 
    {
1398
 
        if (mCurAnimation->initialized ())
1399
 
            mCurAnimation->addGeometry (matrix, region, clip,
1400
 
                                        maxGridWidth, maxGridHeight);
1401
 
    }
1402
 
    else
1403
 
    {
1404
 
        gWindow->glAddGeometry (matrix, region, clip,
1405
 
                                maxGridWidth, maxGridHeight);
1406
 
    }
1407
 
}
1408
 
 
1409
 
bool
1410
 
Animation::shouldDamageWindowOnStart ()
1411
 
{
1412
 
    return (mCurWindowEvent == WindowEventClose ||
1413
 
            mCurWindowEvent == WindowEventMinimize ||
1414
 
            mCurWindowEvent == WindowEventShade);
1415
 
}
1416
 
 
1417
 
bool
1418
 
Animation::shouldDamageWindowOnEnd ()
1419
 
{
1420
 
    return (mCurWindowEvent == WindowEventOpen ||
1421
 
            mCurWindowEvent == WindowEventUnminimize ||
1422
 
            mCurWindowEvent == WindowEventUnshade);
1423
 
}
1424
 
 
1425
 
void
1426
 
Animation::addGeometry (const GLTexture::MatrixList &matrix,
1427
 
                        const CompRegion            &region,
1428
 
                        const CompRegion            &clip,
1429
 
                        unsigned int                maxGridWidth,
1430
 
                        unsigned int                maxGridHeight)
1431
 
{
1432
 
    mAWindow->priv->gWindow->glAddGeometry (matrix, region, clip,
1433
 
                                            maxGridWidth, maxGridHeight);
1434
 
}
1435
 
 
1436
 
void
1437
 
PartialWindowAnim::addGeometry (const GLTexture::MatrixList &matrix,
1438
 
                                const CompRegion            &region,
1439
 
                                const CompRegion            &clip,
1440
 
                                unsigned int                maxGridWidth,
1441
 
                                unsigned int                maxGridHeight)
1442
 
{
1443
 
    if (mUseDrawRegion)
1444
 
    {
1445
 
        CompRegion awRegion (region.intersected (mDrawRegion));
1446
 
        Animation::addGeometry (matrix, awRegion, clip,
1447
 
                                maxGridWidth, maxGridHeight);
1448
 
    }
1449
 
    else
1450
 
    {
1451
 
        Animation::addGeometry (matrix, region, clip,
1452
 
                                maxGridWidth, maxGridHeight);
1453
 
    }
1454
 
}
1455
 
 
1456
 
void
1457
 
PrivateAnimWindow::glDrawTexture (GLTexture          *texture,
1458
 
                                  GLFragment::Attrib &attrib,
1459
 
                                  unsigned int       mask)
1460
 
{
1461
 
    if (mCurAnimation)
1462
 
    {
1463
 
        mCurAnimation->setCurPaintAttrib (attrib);
1464
 
    }
1465
 
 
1466
 
    gWindow->glDrawTexture (texture, attrib, mask);
1467
 
}
1468
 
 
1469
 
void
1470
 
PrivateAnimWindow::glDrawGeometry ()
1471
 
{
1472
 
    if (mCurAnimation)
1473
 
    {
1474
 
        if (mCurAnimation->initialized ())
1475
 
            mCurAnimation->drawGeometry ();
1476
 
    }
1477
 
    else
1478
 
    {
1479
 
        gWindow->glDrawGeometry ();
1480
 
    }
1481
 
}
1482
 
 
1483
 
void
1484
 
Animation::drawTexture (GLTexture          *texture,
1485
 
                        GLFragment::Attrib &attrib,
1486
 
                        unsigned int       mask)
1487
 
{
1488
 
    mCurPaintAttrib = attrib;
1489
 
}
1490
 
 
1491
 
void
1492
 
Animation::drawGeometry ()
1493
 
{
1494
 
    mAWindow->priv->gWindow->glDrawGeometry ();
1495
 
}
1496
 
 
1497
 
bool
1498
 
PrivateAnimWindow::glPaint (const GLWindowPaintAttrib &attrib,
1499
 
                            const GLMatrix &transform,
1500
 
                            const CompRegion &region, unsigned int mask)
1501
 
{
1502
 
    bool status;
1503
 
 
1504
 
    // Is this the first glPaint call this round
1505
 
    // without the mask PAINT_WINDOW_OCCLUSION_DETECTION_MASK?
1506
 
    if (mPAScreen->mStartingNewPaintRound &&
1507
 
        !(mask & PAINT_WINDOW_OCCLUSION_DETECTION_MASK))
1508
 
    {
1509
 
        mPAScreen->mStartingNewPaintRound = false;
1510
 
 
1511
 
        // Back-to-front painting of windows is starting now.
1512
 
        if (mPAScreen->mPrePaintWindowsBackToFrontEnabled)
1513
 
            mPAScreen->prePaintWindowsBackToFront ();
1514
 
    }
1515
 
 
1516
 
    assert (mCurAnimation);
1517
 
 
1518
 
    foreach (ExtensionPluginInfo *extPlugin, mPAScreen->mExtensionPlugins)
1519
 
    {
1520
 
        if (extPlugin->paintShouldSkipWindow (mWindow))
1521
 
            return false;
1522
 
    }
1523
 
 
1524
 
    if (mCurAnimation->curWindowEvent () == WindowEventFocus &&
1525
 
        mPAScreen->otherPluginsActive ())
1526
 
    {
1527
 
        postAnimationCleanUp ();
1528
 
        return gWindow->glPaint (attrib, transform, region, mask);
1529
 
    }
1530
 
 
1531
 
    GLWindowPaintAttrib wAttrib = attrib;
1532
 
    GLMatrix wTransform (transform.getMatrix ());
1533
 
 
1534
 
    /* TODO check if this is still necessary
1535
 
    if (mCurAnimation->addCustomGeometryFunc)
1536
 
    {
1537
 
        // Use slightly smaller brightness to force core
1538
 
        // to handle <max saturation case with <max brightness.
1539
 
        // Otherwise polygon effects show fully unsaturated colors
1540
 
        // in that case.
1541
 
        wAttrib.brightness = MAX (0, wAttrib.brightness - 1);
1542
 
    } */
1543
 
 
1544
 
    //w->indexCount = 0; // TODO check if this is still necessary
1545
 
 
1546
 
    // TODO: should only happen for distorting effects
1547
 
    mask |= PAINT_WINDOW_TRANSFORMED_MASK;
1548
 
 
1549
 
    wAttrib.xScale = 1.0f;
1550
 
    wAttrib.yScale = 1.0f;
1551
 
 
1552
 
    mCurAnimation->updateAttrib (wAttrib);
1553
 
    mCurAnimation->updateTransform (wTransform);
1554
 
    mCurAnimation->prePaintWindow ();
1555
 
 
1556
 
    if (mCurAnimation->paintWindowUsed ())
1557
 
        status = mCurAnimation->paintWindow (gWindow, wAttrib, wTransform, region, mask);
1558
 
    else
1559
 
        status = gWindow->glPaint (wAttrib, wTransform, region, mask);
1560
 
 
1561
 
    if (mCurAnimation->postPaintWindowUsed ())
1562
 
    {
1563
 
        // Transform to make post-paint coincide with the window
1564
 
        glPushMatrix ();
1565
 
        glLoadMatrixf (wTransform.getMatrix ());
1566
 
 
1567
 
        mCurAnimation->postPaintWindow ();
1568
 
 
1569
 
        glPopMatrix ();
1570
 
    }
1571
 
 
1572
 
    return status;
1573
 
}
1574
 
 
1575
 
/// This is enabled only during restack animations.
1576
 
const CompWindowList &
1577
 
PrivateAnimScreen::getWindowPaintList ()
1578
 
{
1579
 
    ExtensionPluginAnimation *extPlugin =
1580
 
        static_cast<ExtensionPluginAnimation *> (mExtensionPlugins[0]);
1581
 
    return extPlugin->getWindowPaintList ();
1582
 
}
1583
 
 
1584
 
/// This is enabled only during restack animations.
1585
 
void
1586
 
PrivateAnimScreen::prePaintWindowsBackToFront ()
1587
 
{
1588
 
    assert (mAnimInProgress);
1589
 
 
1590
 
    ExtensionPluginAnimation *extPlugin =
1591
 
        static_cast<ExtensionPluginAnimation *> (mExtensionPlugins[0]);
1592
 
    extPlugin->prePaintWindowsBackToFront ();
1593
 
}
1594
 
 
1595
 
void
1596
 
PrivateAnimScreen::enablePrePaintWindowsBackToFront (bool enabled)
1597
 
{
1598
 
    mPrePaintWindowsBackToFrontEnabled = enabled;
1599
 
}
1600
 
 
1601
 
void
1602
 
AnimScreen::enableCustomPaintList (bool enabled)
1603
 
{
1604
 
    priv->cScreen->getWindowPaintListSetEnabled (priv, enabled);
1605
 
    priv->enablePrePaintWindowsBackToFront (enabled);
1606
 
}
1607
 
 
1608
 
static const PluginEventInfo watchedScreenPlugins[] =
1609
 
{
1610
 
    {"switcher", "activate"},
1611
 
    {"ring", "activate"},
1612
 
    {"shift", "activate"},
1613
 
    {"scale", "activate"},
1614
 
    {"group", "tabChangeActivate"},
1615
 
    {"fadedesktop", "activate"}
1616
 
};
1617
 
 
1618
 
static const PluginEventInfo watchedWindowPlugins[] =
1619
 
{
1620
 
    {"kdecompat", "slide"},
1621
 
};
1622
 
 
1623
 
void
1624
 
PrivateAnimScreen::handleCompizEvent (const char         *pluginName,
1625
 
                                      const char         *eventName,
1626
 
                                      CompOption::Vector &options)
1627
 
{
1628
 
    ::screen->handleCompizEvent (pluginName, eventName, options);
1629
 
 
1630
 
    for (int i = 0; i < WatchedScreenPluginNum; i++)
1631
 
        if (strcmp (pluginName, watchedScreenPlugins[i].pluginName) == 0)
1632
 
        {
1633
 
            if (strcmp (eventName, 
1634
 
                        watchedScreenPlugins[i].activateEventName) == 0)
1635
 
            {
1636
 
                mPluginActive[i] =
1637
 
                    CompOption::getBoolOptionNamed (options, "active", false);
1638
 
 
1639
 
                if (!mPluginActive[i] &&
1640
 
                    (i == WatchedPluginSwitcher ||
1641
 
                     i == WatchedPluginRing ||
1642
 
                     i == WatchedPluginShift ||
1643
 
                     i == WatchedPluginScale))
1644
 
                {
1645
 
                    mSwitcherPostWait = 1;
1646
 
                }
1647
 
            }
1648
 
            break;
1649
 
        }
1650
 
 
1651
 
    for (int i = 0; i < WatchedWindowPluginNum; i++)
1652
 
        if (strcmp (pluginName,
1653
 
                    watchedWindowPlugins[i].pluginName) == 0)
1654
 
        {
1655
 
            if (strcmp (eventName,
1656
 
                        watchedWindowPlugins[i].activateEventName) == 0)
1657
 
            {
1658
 
                Window xid = CompOption::getIntOptionNamed (options,
1659
 
                                                            "window",
1660
 
                                                             0);
1661
 
                CompWindow *w = screen->findWindow (xid);
1662
 
 
1663
 
                if (w)
1664
 
                {
1665
 
                    AnimWindow *aw = AnimWindow::get (w);
1666
 
                    PrivateAnimWindow *pw = aw->priv;
1667
 
                    pw->mPluginActive[i] = CompOption::getBoolOptionNamed (
1668
 
                                                                    options,
1669
 
                                                                    "active",
1670
 
                                                                    false);
1671
 
                }
1672
 
            }
1673
 
            break;
1674
 
        }
1675
 
}
1676
 
 
1677
 
/// Returns true for windows that don't have a pixmap or certain properties,
1678
 
/// like the dimming layer of gksudo and x-session-manager.
1679
 
inline bool
1680
 
PrivateAnimScreen::shouldIgnoreWindowForAnim (CompWindow *w, bool checkPixmap)
1681
 
{
1682
 
    AnimWindow *aw = AnimWindow::get (w);
1683
 
 
1684
 
    for (int i = 0; i < WatchedWindowPluginNum; i++)
1685
 
        if (aw->priv->mPluginActive[i])
1686
 
            return true;
1687
 
 
1688
 
    return ((checkPixmap && !CompositeWindow::get (w)->pixmap ()) ||
1689
 
            mNeverAnimateMatch.evaluate (w));
1690
 
}
1691
 
 
1692
 
void
1693
 
PrivateAnimWindow::reverseAnimation ()
1694
 
{
1695
 
    mCurAnimation->reverse ();
1696
 
 
1697
 
    // Inflict the pending unmaps
1698
 
    while (mUnmapCnt > 0)
1699
 
    {
1700
 
        mWindow->unmap ();
1701
 
        mUnmapCnt--;
1702
 
    }
1703
 
    if (mUnmapCnt < 0)
1704
 
        mUnmapCnt = 0;
1705
 
}
1706
 
 
1707
 
void
1708
 
PrivateAnimScreen::initiateCloseAnim (PrivateAnimWindow *aw)
1709
 
{
1710
 
    CompWindow *w = aw->mWindow;
1711
 
 
1712
 
    foreach (ExtensionPluginInfo *extPlugin, mExtensionPlugins)
1713
 
        extPlugin->preInitiateCloseAnim (aw->mAWindow);
1714
 
 
1715
 
    if (shouldIgnoreWindowForAnim (w, true))
1716
 
        return;
1717
 
    int duration = 200;
1718
 
    AnimEffect chosenEffect =
1719
 
        getMatchingAnimSelection (w, AnimEventClose, &duration);
1720
 
 
1721
 
    aw->mState = NormalState;
1722
 
    aw->mNewState = WithdrawnState;
1723
 
 
1724
 
    if (chosenEffect != AnimEffectNone)
1725
 
    {
1726
 
        bool startingNew = true;
1727
 
        WindowEvent curWindowEvent = WindowEventNone;
1728
 
 
1729
 
        if (aw->curAnimation ())
1730
 
            curWindowEvent = aw->curAnimation ()->curWindowEvent ();
1731
 
 
1732
 
        if (curWindowEvent != WindowEventNone)
1733
 
        {
1734
 
            if (curWindowEvent == WindowEventOpen)
1735
 
            {
1736
 
                startingNew = false;
1737
 
                aw->reverseAnimation ();
1738
 
            }
1739
 
            /* TODO check if necessary
1740
 
            else if (aw->com.curWindowEvent == WindowEventClose)
1741
 
            {
1742
 
                if (aw->com.animOverrideProgressDir == 2)
1743
 
                {
1744
 
                    aw->com.animRemainingTime = tmpSteps;
1745
 
                    startingNew = false;
1746
 
                }
1747
 
            }*/
1748
 
            else
1749
 
            {
1750
 
                aw->postAnimationCleanUpPrev (true, false);
1751
 
            }
1752
 
        }
1753
 
 
1754
 
        if (startingNew)
1755
 
        {
1756
 
            AnimEffect effectToBePlayed =
1757
 
                getActualEffect (chosenEffect, AnimEventClose);
1758
 
 
1759
 
            // handle empty random effect list
1760
 
            if (effectToBePlayed && effectToBePlayed == AnimEffectNone)
1761
 
            {
1762
 
                aw->mState = aw->mNewState;
1763
 
                return;
1764
 
            }
1765
 
 
1766
 
            aw->mCurAnimation =
1767
 
                effectToBePlayed->create (w, WindowEventClose, duration,
1768
 
                                          effectToBePlayed, getIcon (w, true));
1769
 
            aw->mCurAnimation->adjustPointerIconSize ();
1770
 
            aw->enablePainting (true);
1771
 
        }
1772
 
 
1773
 
        activateEvent (true);
1774
 
        aw->notifyAnimation (true);
1775
 
 
1776
 
        // Increment 3 times to make sure close animation works
1777
 
        // (e.g. for popup menus).
1778
 
        for (int i = 0; i < 3; i++)
1779
 
        {
1780
 
            aw->mUnmapCnt++;
1781
 
            w->incrementUnmapReference ();
1782
 
        }
1783
 
        cScreen->damagePending ();
1784
 
    }
1785
 
    /* TODO check if necessary
1786
 
    else if (AnimEffectNone !=
1787
 
             getMatchingAnimSelection (w, AnimEventOpen, &duration))
1788
 
    {
1789
 
        // stop the current animation and prevent it from rewinding
1790
 
 
1791
 
        if (aw->com.animRemainingTime > 0 &&
1792
 
            aw->com.curWindowEvent != WindowEventOpen)
1793
 
        {
1794
 
            aw->com.animRemainingTime = 0;
1795
 
        }
1796
 
        if ((aw->com.curWindowEvent != WindowEventNone) &&
1797
 
            (aw->com.curWindowEvent != WindowEventClose))
1798
 
        {
1799
 
            postAnimationCleanUp (w);
1800
 
        }
1801
 
        // set some properties to make sure this window will use the
1802
 
        // correct open effect the next time it's "opened"
1803
 
 
1804
 
        activateEvent (w->screen, true);
1805
 
        aw->com.curWindowEvent = WindowEventClose;
1806
 
 
1807
 
        aw->mUnmapCnt++;
1808
 
        w->incrementUnmapRefCnt ();
1809
 
 
1810
 
        damagePendingOnScreen (w->screen);
1811
 
    }*/
1812
 
    else
1813
 
        aw->mState = aw->mNewState;
1814
 
 
1815
 
    // Make sure non-animated closing windows get a damage.
1816
 
    if (!aw->curAnimation ())
1817
 
    {
1818
 
        aw->mAWindow->expandBBWithWindow ();
1819
 
    }
1820
 
}
1821
 
 
1822
 
CompRect
1823
 
PrivateAnimScreen::getIcon (CompWindow *w, bool alwaysUseMouse)
1824
 
{
1825
 
    CompRect icon;
1826
 
 
1827
 
    if (!alwaysUseMouse)
1828
 
    {
1829
 
        icon = w->iconGeometry ();
1830
 
    }
1831
 
    if (alwaysUseMouse ||
1832
 
        (icon.x () == 0 &&
1833
 
         icon.y () == 0 &&
1834
 
         icon.width () == 0 &&
1835
 
         icon.height () == 0)) // that is, couldn't get icon from window
1836
 
    {
1837
 
        // Minimize to mouse pointer if there is no
1838
 
        // window list or if the window skips taskbar
1839
 
        short x, y;
1840
 
        if (!aScreen->getMousePointerXY (&x, &y))
1841
 
        {
1842
 
            // Use screen center if can't get mouse coords
1843
 
            x = ::screen->width () / 2;
1844
 
            y = ::screen->height () / 2;
1845
 
        }
1846
 
        icon.setX (x);
1847
 
        icon.setY (y);
1848
 
        icon.setWidth (FAKE_ICON_SIZE);
1849
 
        icon.setHeight (FAKE_ICON_SIZE);
1850
 
    }
1851
 
 
1852
 
    return icon;
1853
 
}
1854
 
 
1855
 
void
1856
 
PrivateAnimScreen::initiateMinimizeAnim (PrivateAnimWindow *aw)
1857
 
{
1858
 
    CompWindow *w = aw->mWindow;
1859
 
 
1860
 
    if (aw->mWindow->destroyed ())
1861
 
        return;
1862
 
 
1863
 
    // Store window geometry for use during animation.
1864
 
    aw->mAWindow->mSavedInRect = w->inputRect ();
1865
 
    aw->mAWindow->mSavedOutRect = w->outputRect ();
1866
 
    aw->mAWindow->mSavedOutExtents = w->output ();
1867
 
    aw->mAWindow->mSavedWinRect = w->geometry ();
1868
 
    aw->mAWindow->mSavedRectsValid = true;
1869
 
 
1870
 
    aw->mNewState = IconicState;
1871
 
 
1872
 
    foreach (ExtensionPluginInfo *extPlugin, mExtensionPlugins)
1873
 
        extPlugin->preInitiateMinimizeAnim (aw->mAWindow);
1874
 
 
1875
 
    int duration = 200;
1876
 
    AnimEffect chosenEffect =
1877
 
        getMatchingAnimSelection (w, AnimEventMinimize, &duration);
1878
 
 
1879
 
    if (chosenEffect != AnimEffectNone)
1880
 
    {
1881
 
        bool startingNew = true;
1882
 
        WindowEvent curWindowEvent = WindowEventNone;
1883
 
 
1884
 
        if (aw->curAnimation ())
1885
 
            curWindowEvent = aw->curAnimation ()->curWindowEvent ();
1886
 
 
1887
 
        if (curWindowEvent != WindowEventNone)
1888
 
        {
1889
 
            if (curWindowEvent != WindowEventUnminimize)
1890
 
            {
1891
 
                aw->postAnimationCleanUpPrev (false, false);
1892
 
            }
1893
 
            else
1894
 
            {
1895
 
                startingNew = false;
1896
 
                aw->reverseAnimation ();
1897
 
            }
1898
 
        }
1899
 
 
1900
 
        if (startingNew)
1901
 
        {
1902
 
            AnimEffect effectToBePlayed =
1903
 
                getActualEffect (chosenEffect, AnimEventMinimize);
1904
 
 
1905
 
            // handle empty random effect list
1906
 
            if (effectToBePlayed == AnimEffectNone)
1907
 
            {
1908
 
                aw->mState = aw->mNewState;
1909
 
                return;
1910
 
            }
1911
 
 
1912
 
            aw->mCurAnimation =
1913
 
                effectToBePlayed->create (w, WindowEventMinimize, duration,
1914
 
                                          effectToBePlayed, getIcon (w, false));
1915
 
            aw->enablePainting (true);
1916
 
        }
1917
 
 
1918
 
        activateEvent (true);
1919
 
        aw->notifyAnimation (true);
1920
 
 
1921
 
        cScreen->damagePending ();
1922
 
    }
1923
 
    else
1924
 
        aw->mState = aw->mNewState;
1925
 
}
1926
 
 
1927
 
void
1928
 
PrivateAnimScreen::initiateShadeAnim (PrivateAnimWindow *aw)
1929
 
{
1930
 
    CompWindow *w = aw->mWindow;
1931
 
 
1932
 
    int duration = 200;
1933
 
    AnimEffect chosenEffect =
1934
 
        getMatchingAnimSelection (w, AnimEventShade, &duration);
1935
 
 
1936
 
    aw->setShaded (true);
1937
 
 
1938
 
    if (chosenEffect != AnimEffectNone)
1939
 
    {
1940
 
        bool startingNew = true;
1941
 
        WindowEvent curWindowEvent = WindowEventNone;
1942
 
        if (aw->curAnimation ())
1943
 
            curWindowEvent = aw->curAnimation ()->curWindowEvent ();
1944
 
 
1945
 
        if (curWindowEvent != WindowEventNone)
1946
 
        {
1947
 
            if (curWindowEvent != WindowEventUnshade)
1948
 
            {
1949
 
                aw->postAnimationCleanUpPrev (false, false);
1950
 
            }
1951
 
            else
1952
 
            {
1953
 
                startingNew = false;
1954
 
                aw->reverseAnimation ();
1955
 
            }
1956
 
        }
1957
 
 
1958
 
        if (startingNew)
1959
 
        {
1960
 
            AnimEffect effectToBePlayed =
1961
 
                getActualEffect (chosenEffect, AnimEventShade);
1962
 
 
1963
 
            // handle empty random effect list
1964
 
            if (effectToBePlayed == AnimEffectNone)
1965
 
                return;
1966
 
 
1967
 
            aw->mCurAnimation =
1968
 
                effectToBePlayed->create (w, WindowEventShade, duration,
1969
 
                                          effectToBePlayed, getIcon (w, false));
1970
 
            aw->enablePainting (true);
1971
 
        }
1972
 
 
1973
 
        activateEvent (true);
1974
 
        aw->notifyAnimation (true);
1975
 
 
1976
 
        aw->mUnmapCnt++;
1977
 
        w->incrementUnmapReference ();
1978
 
 
1979
 
        cScreen->damagePending ();
1980
 
    }
1981
 
}
1982
 
 
1983
 
void
1984
 
PrivateAnimScreen::initiateOpenAnim (PrivateAnimWindow *aw)
1985
 
{
1986
 
    CompWindow *w = aw->mWindow;
1987
 
 
1988
 
    int duration = 200;
1989
 
    AnimEffect chosenEffect;
1990
 
 
1991
 
    aw->mNewState = NormalState;
1992
 
 
1993
 
    foreach (ExtensionPluginInfo *extPlugin, mExtensionPlugins)
1994
 
        extPlugin->preInitiateOpenAnim (aw->mAWindow);
1995
 
 
1996
 
    WindowEvent curWindowEvent = WindowEventNone;
1997
 
    if (aw->curAnimation ())
1998
 
        curWindowEvent = aw->curAnimation ()->curWindowEvent ();
1999
 
 
2000
 
    if (!shouldIgnoreWindowForAnim (w, false) &&
2001
 
        (AnimEffectNone !=
2002
 
         (chosenEffect =
2003
 
          getMatchingAnimSelection (w, AnimEventOpen, &duration)) ||
2004
 
         // reversing case
2005
 
         curWindowEvent == WindowEventClose))
2006
 
    {
2007
 
        bool startingNew = true;
2008
 
        bool playEffect = true;
2009
 
 
2010
 
        if (curWindowEvent != WindowEventNone)
2011
 
        {
2012
 
            if (curWindowEvent != WindowEventClose)
2013
 
            {
2014
 
                aw->postAnimationCleanUpPrev (false, false);
2015
 
            }
2016
 
            else
2017
 
            {
2018
 
                startingNew = false;
2019
 
                aw->reverseAnimation ();
2020
 
            }
2021
 
        }
2022
 
 
2023
 
        if (startingNew)
2024
 
        {
2025
 
            AnimEffect effectToBePlayed =
2026
 
                getActualEffect (chosenEffect, AnimEventOpen);
2027
 
 
2028
 
            // handle empty random effect list
2029
 
            if (effectToBePlayed == AnimEffectNone)
2030
 
                playEffect = false;
2031
 
 
2032
 
            if (playEffect)
2033
 
            {
2034
 
                aw->mCurAnimation =
2035
 
                    effectToBePlayed->create (w, WindowEventOpen, duration,
2036
 
                                              effectToBePlayed,
2037
 
                                              getIcon (w, true));
2038
 
                aw->mCurAnimation->adjustPointerIconSize ();
2039
 
                aw->enablePainting (true);
2040
 
            }
2041
 
        }
2042
 
 
2043
 
        if (playEffect)
2044
 
        {
2045
 
            activateEvent (true);
2046
 
            aw->notifyAnimation (true);
2047
 
            cScreen->damagePending ();
2048
 
        }
2049
 
    }
2050
 
}
2051
 
 
2052
 
void
2053
 
PrivateAnimScreen::initiateUnminimizeAnim (PrivateAnimWindow *aw)
2054
 
{
2055
 
    CompWindow *w = aw->mWindow;
2056
 
 
2057
 
    if (aw->mWindow->destroyed ())
2058
 
        return;
2059
 
 
2060
 
    aw->mAWindow->mSavedRectsValid = false;
2061
 
 
2062
 
    int duration = 200;
2063
 
    AnimEffect chosenEffect =
2064
 
        getMatchingAnimSelection (w, AnimEventMinimize, &duration);
2065
 
 
2066
 
    aw->mNewState = NormalState;
2067
 
 
2068
 
    if (chosenEffect != AnimEffectNone &&
2069
 
        !mPluginActive[3]) // fadedesktop
2070
 
    {
2071
 
        bool startingNew = true;
2072
 
        bool playEffect = true;
2073
 
 
2074
 
        foreach (ExtensionPluginInfo *extPlugin, mExtensionPlugins)
2075
 
            extPlugin->preInitiateUnminimizeAnim (aw->mAWindow);
2076
 
 
2077
 
        // TODO Refactor the rest? (almost the same in other initiateX methods)
2078
 
        WindowEvent curWindowEvent = WindowEventNone;
2079
 
        if (aw->curAnimation ())
2080
 
            curWindowEvent = aw->curAnimation ()->curWindowEvent ();
2081
 
 
2082
 
        if (curWindowEvent != WindowEventNone)
2083
 
        {
2084
 
            if (curWindowEvent != WindowEventMinimize)
2085
 
            {
2086
 
                aw->postAnimationCleanUpPrev (false, false);
2087
 
            }
2088
 
            else
2089
 
            {
2090
 
                startingNew = false;
2091
 
                aw->reverseAnimation ();
2092
 
            }
2093
 
        }
2094
 
 
2095
 
        if (startingNew)
2096
 
        {
2097
 
            AnimEffect effectToBePlayed =
2098
 
                getActualEffect (chosenEffect, AnimEventMinimize);
2099
 
 
2100
 
            // handle empty random effect list
2101
 
            if (effectToBePlayed == AnimEffectNone)
2102
 
                playEffect = false;
2103
 
 
2104
 
            if (playEffect)
2105
 
            {
2106
 
                aw->mCurAnimation =
2107
 
                    effectToBePlayed->create (w, WindowEventUnminimize,
2108
 
                                              duration, effectToBePlayed,
2109
 
                                              getIcon (w, false));
2110
 
                aw->enablePainting (true);
2111
 
            }
2112
 
        }
2113
 
 
2114
 
        if (playEffect)
2115
 
        {
2116
 
            activateEvent (true);
2117
 
            aw->notifyAnimation (true);
2118
 
            cScreen->damagePending ();
2119
 
        }
2120
 
    }
2121
 
}
2122
 
 
2123
 
void
2124
 
PrivateAnimScreen::initiateUnshadeAnim (PrivateAnimWindow *aw)
2125
 
{
2126
 
    CompWindow *w = aw->mWindow;
2127
 
 
2128
 
    aw->mAWindow->mSavedRectsValid = false;
2129
 
 
2130
 
    aw->setShaded (false);
2131
 
 
2132
 
    aw->mNewState = NormalState;
2133
 
 
2134
 
    int duration = 200;
2135
 
    AnimEffect chosenEffect =
2136
 
        getMatchingAnimSelection (w, AnimEventShade, &duration);
2137
 
 
2138
 
    if (chosenEffect != AnimEffectNone)
2139
 
    {
2140
 
        bool startingNew = true;
2141
 
        bool playEffect = true;
2142
 
 
2143
 
        WindowEvent curWindowEvent = WindowEventNone;
2144
 
        if (aw->curAnimation ())
2145
 
            curWindowEvent = aw->curAnimation ()->curWindowEvent ();
2146
 
 
2147
 
        if (curWindowEvent != WindowEventNone)
2148
 
        {
2149
 
            if (curWindowEvent != WindowEventShade)
2150
 
            {
2151
 
                aw->postAnimationCleanUpPrev (false, false);
2152
 
            }
2153
 
            else
2154
 
            {
2155
 
                startingNew = false;
2156
 
                aw->reverseAnimation ();
2157
 
            }
2158
 
        }
2159
 
 
2160
 
        if (startingNew)
2161
 
        {
2162
 
            AnimEffect effectToBePlayed =
2163
 
                getActualEffect (chosenEffect, AnimEventShade);
2164
 
 
2165
 
            // handle empty random effect list
2166
 
            if (effectToBePlayed == AnimEffectNone)
2167
 
                playEffect = false;
2168
 
 
2169
 
            if (playEffect)
2170
 
            {
2171
 
                aw->mCurAnimation =
2172
 
                    effectToBePlayed->create (w, WindowEventUnshade,
2173
 
                                              duration, effectToBePlayed,
2174
 
                                              getIcon (w, false));
2175
 
                aw->enablePainting (true);
2176
 
            }
2177
 
        }
2178
 
 
2179
 
        if (playEffect)
2180
 
        {
2181
 
            activateEvent (true);
2182
 
            aw->notifyAnimation (true);
2183
 
            cScreen->damagePending ();
2184
 
        }
2185
 
    }
2186
 
}
2187
 
 
2188
 
bool
2189
 
PrivateAnimScreen::initiateFocusAnim (PrivateAnimWindow *aw)
2190
 
{
2191
 
    CompWindow *w = aw->mWindow;
2192
 
    int duration = 200;
2193
 
 
2194
 
    if (aw->curAnimation () || otherPluginsActive () ||
2195
 
        // Check the "switcher post-wait" counter that effectively prevents
2196
 
        // focus animation to be initiated when the zoom option value is low
2197
 
        // in Switcher.
2198
 
        mSwitcherPostWait)
2199
 
        return false;
2200
 
 
2201
 
    AnimEffect chosenEffect =
2202
 
        getMatchingAnimSelection (w, AnimEventFocus, &duration);
2203
 
 
2204
 
    if (chosenEffect != AnimEffectNone)
2205
 
    {
2206
 
        aw->createFocusAnimation (chosenEffect, duration);
2207
 
 
2208
 
        if (chosenEffect->isRestackAnim &&
2209
 
            !(dynamic_cast<RestackAnim *> (aw->mCurAnimation)->
2210
 
              initiateRestackAnim (duration)))
2211
 
        {
2212
 
            aw->postAnimationCleanUp ();
2213
 
            return false;
2214
 
        }
2215
 
 
2216
 
        activateEvent (true);
2217
 
        aw->notifyAnimation (true);
2218
 
        cScreen->damagePending ();
2219
 
        return true;
2220
 
    }
2221
 
    return false;
2222
 
}
2223
 
 
2224
 
void
2225
 
PrivateAnimWindow::resizeNotify (int dx,
2226
 
                                 int dy,
2227
 
                                 int dwidth,
2228
 
                                 int dheight)
2229
 
{
2230
 
    if (mUnshadePending)
2231
 
    {
2232
 
        mUnshadePending = false;
2233
 
        mPAScreen->initiateUnshadeAnim (this);
2234
 
    }
2235
 
    else if (mCurAnimation && mCurAnimation->inProgress () &&
2236
 
        // Don't let transient window open anim be interrupted with a resize notify
2237
 
        !(mCurAnimation->curWindowEvent () == WindowEventOpen &&
2238
 
          (mWindow->wmType () &
2239
 
           (CompWindowTypeDropdownMenuMask |
2240
 
            CompWindowTypePopupMenuMask |
2241
 
            CompWindowTypeMenuMask |
2242
 
            CompWindowTypeTooltipMask |
2243
 
            CompWindowTypeNotificationMask |
2244
 
            CompWindowTypeComboMask |
2245
 
            CompWindowTypeDndMask))) &&
2246
 
        // Ignore resize with dx=0, dy=0, dwidth=0, dheight=0
2247
 
        !(dx == 0 && dy == 0 && dwidth == 0 && dheight == 0) &&
2248
 
        !mCurAnimation->resizeUpdate (dx, dy, dwidth, dheight))
2249
 
    {
2250
 
        postAnimationCleanUp ();
2251
 
        mPAScreen->updateAnimStillInProgress ();
2252
 
    }
2253
 
 
2254
 
    mWindow->resizeNotify (dx, dy, dwidth, dheight);
2255
 
}
2256
 
 
2257
 
void
2258
 
PrivateAnimScreen::updateAnimStillInProgress ()
2259
 
{
2260
 
    bool animStillInProgress = false;
2261
 
    foreach (CompWindow *w, ::screen->windows ())
2262
 
    {
2263
 
        PrivateAnimWindow *aw = AnimWindow::get (w)->priv;
2264
 
        if (aw->curAnimation () &&
2265
 
            aw->curAnimation ()->inProgress ())
2266
 
        {
2267
 
            animStillInProgress = true;
2268
 
            break;
2269
 
        }
2270
 
        else
2271
 
        {
2272
 
            aw->notifyAnimation (false);
2273
 
        }
2274
 
    }
2275
 
 
2276
 
    if (!animStillInProgress)
2277
 
        activateEvent (false);
2278
 
}
2279
 
 
2280
 
void
2281
 
PrivateAnimWindow::moveNotify (int  dx,
2282
 
                               int  dy,
2283
 
                               bool immediate)
2284
 
{
2285
 
    if (mCurAnimation && mCurAnimation->inProgress () &&
2286
 
        (mGrabbed || !mCurAnimation->moveUpdate (dx, dy)))
2287
 
    {
2288
 
        // Stop the animation
2289
 
        postAnimationCleanUp ();
2290
 
        mPAScreen->updateAnimStillInProgress ();
2291
 
    }
2292
 
 
2293
 
    mWindow->moveNotify (dx, dy, immediate);
2294
 
}
2295
 
 
2296
 
void
2297
 
PrivateAnimWindow::grabNotify (int          x,
2298
 
                               int          y,
2299
 
                               unsigned int state,
2300
 
                               unsigned int mask)
2301
 
{
2302
 
    mGrabbed = true;
2303
 
 
2304
 
    mWindow->grabNotify (x, y, state, mask);
2305
 
}
2306
 
 
2307
 
void
2308
 
PrivateAnimWindow::ungrabNotify ()
2309
 
{
2310
 
    mGrabbed = false;
2311
 
 
2312
 
    mWindow->ungrabNotify ();
2313
 
}
2314
 
 
2315
 
bool
2316
 
PrivateAnimScreen::glPaintOutput (const GLScreenPaintAttrib &attrib,
2317
 
                                  const GLMatrix            &matrix,
2318
 
                                  const CompRegion          &region,
2319
 
                                  CompOutput                *output,
2320
 
                                  unsigned int               mask)
2321
 
{
2322
 
    assert (mAnimInProgress);
2323
 
 
2324
 
    mStartingNewPaintRound = true;
2325
 
 
2326
 
    foreach (ExtensionPluginInfo *extPlugin, mExtensionPlugins)
2327
 
        extPlugin->prePaintOutput (output);
2328
 
 
2329
 
    mask |= PAINT_SCREEN_WITH_TRANSFORMED_WINDOWS_MASK;
2330
 
 
2331
 
    mOutput = output;
2332
 
 
2333
 
    return gScreen->glPaintOutput (attrib, matrix, region, output, mask);
2334
 
}
2335
 
 
2336
 
AnimEffectInfo::AnimEffectInfo (const char *name,
2337
 
                                bool usedO, bool usedC, bool usedM,
2338
 
                                bool usedS, bool usedF,
2339
 
                                CreateAnimFunc create,
2340
 
                                bool isRestackAnim) :
2341
 
    name (name),
2342
 
    create (create),
2343
 
    isRestackAnim (isRestackAnim)
2344
 
{
2345
 
    usedForEvents[AnimEventOpen] = usedO;
2346
 
    usedForEvents[AnimEventClose] = usedC;
2347
 
    usedForEvents[AnimEventMinimize] = usedM;
2348
 
    usedForEvents[AnimEventShade] = usedS;
2349
 
    usedForEvents[AnimEventFocus] = usedF;
2350
 
}
2351
 
 
2352
 
bool
2353
 
AnimEffectInfo::matchesEffectName (const CompString &animName)
2354
 
{
2355
 
    return (0 == strcasecmp (animName.c_str (), name));
2356
 
}
2357
 
 
2358
 
bool
2359
 
AnimEffectInfo::matchesPluginName (const CompString &pluginName)
2360
 
{
2361
 
    return (0 == strncmp (pluginName.c_str (), name, pluginName.length ()));
2362
 
}
2363
 
 
2364
 
AnimEffect animEffects[NUM_EFFECTS];
2365
 
 
2366
 
ExtensionPluginAnimation animExtensionPluginInfo (CompString ("animation"),
2367
 
                                                  NUM_EFFECTS, animEffects, 0,
2368
 
                                                  NUM_NONEFFECT_OPTIONS);
2369
 
ExtensionPluginInfo *
2370
 
Animation::getExtensionPluginInfo ()
2371
 
{
2372
 
    return &animExtensionPluginInfo;
2373
 
}
2374
 
 
2375
 
AnimEffect AnimEffectNone;
2376
 
AnimEffect AnimEffectRandom;
2377
 
AnimEffect AnimEffectCurvedFold;
2378
 
AnimEffect AnimEffectDodge;
2379
 
AnimEffect AnimEffectDream;
2380
 
AnimEffect AnimEffectFade;
2381
 
AnimEffect AnimEffectFocusFade;
2382
 
AnimEffect AnimEffectGlide1;
2383
 
AnimEffect AnimEffectGlide2;
2384
 
AnimEffect AnimEffectHorizontalFolds;
2385
 
AnimEffect AnimEffectMagicLamp;
2386
 
AnimEffect AnimEffectMagicLampWavy;
2387
 
AnimEffect AnimEffectRollUp;
2388
 
AnimEffect AnimEffectSidekick;
2389
 
AnimEffect AnimEffectWave;
2390
 
AnimEffect AnimEffectZoom;
2391
 
 
2392
 
PrivateAnimScreen::PrivateAnimScreen (CompScreen *s, AnimScreen *as) :
2393
 
    cScreen (CompositeScreen::get (s)),
2394
 
    gScreen (GLScreen::get (s)),
2395
 
    aScreen (as),
2396
 
    mLastRedrawTimeFresh (false),
2397
 
    mSwitcherPostWait (0),
2398
 
    mStartCountdown (20), // start the countdown
2399
 
    mLastActiveWindow (0),
2400
 
    mAnimInProgress (false),
2401
 
    mStartingNewPaintRound (false),
2402
 
    mPrePaintWindowsBackToFrontEnabled (false),
2403
 
    mOutput (0)
2404
 
{
2405
 
    for (int i = 0; i < WatchedScreenPluginNum; i++)
2406
 
        mPluginActive[i] = false;
2407
 
 
2408
 
    // Never animate screen-dimming layer of logout window and gksu.
2409
 
    mNeverAnimateMatch |= "title=gksu";
2410
 
    mNeverAnimateMatch |= "title=x-session-manager";
2411
 
    mNeverAnimateMatch |= "title=gnome-session";
2412
 
    mNeverAnimateMatch.update ();
2413
 
 
2414
 
    // Set-up option notifiers
2415
 
 
2416
 
#define MATCHES_BIND    \
2417
 
    boost::bind (&PrivateAnimScreen::eventMatchesChanged, this, _1, _2)
2418
 
#define OPTIONS_BIND    \
2419
 
    boost::bind (&PrivateAnimScreen::eventOptionsChanged, this, _1, _2)
2420
 
#define EFFECTS_BIND    \
2421
 
    boost::bind (&PrivateAnimScreen::eventEffectsChanged, this, _1, _2)
2422
 
#define RANDOM_EFFECTS_BIND    \
2423
 
    boost::bind (&PrivateAnimScreen::eventRandomEffectsChanged, this, _1, _2)
2424
 
 
2425
 
    optionSetOpenMatchesNotify (MATCHES_BIND);
2426
 
    optionSetCloseMatchesNotify (MATCHES_BIND);
2427
 
    optionSetMinimizeMatchesNotify (MATCHES_BIND);
2428
 
    optionSetFocusMatchesNotify (MATCHES_BIND);
2429
 
    optionSetShadeMatchesNotify (MATCHES_BIND);
2430
 
 
2431
 
    optionSetOpenOptionsNotify (OPTIONS_BIND);
2432
 
    optionSetCloseOptionsNotify (OPTIONS_BIND);
2433
 
    optionSetMinimizeOptionsNotify (OPTIONS_BIND);
2434
 
    optionSetFocusOptionsNotify (OPTIONS_BIND);
2435
 
    optionSetShadeOptionsNotify (OPTIONS_BIND);
2436
 
 
2437
 
    optionSetOpenEffectsNotify (EFFECTS_BIND);
2438
 
    optionSetCloseEffectsNotify (EFFECTS_BIND);
2439
 
    optionSetMinimizeEffectsNotify (EFFECTS_BIND);
2440
 
    optionSetFocusEffectsNotify (EFFECTS_BIND);
2441
 
    optionSetShadeEffectsNotify (EFFECTS_BIND);
2442
 
 
2443
 
    optionSetOpenRandomEffectsNotify (RANDOM_EFFECTS_BIND);
2444
 
    optionSetCloseRandomEffectsNotify (RANDOM_EFFECTS_BIND);
2445
 
    optionSetMinimizeRandomEffectsNotify (RANDOM_EFFECTS_BIND);
2446
 
    optionSetShadeRandomEffectsNotify (RANDOM_EFFECTS_BIND);
2447
 
 
2448
 
    ScreenInterface::setHandler (::screen);
2449
 
    CompositeScreenInterface::setHandler (cScreen, false);
2450
 
    GLScreenInterface::setHandler (gScreen, false);
2451
 
}
2452
 
 
2453
 
PrivateAnimScreen::~PrivateAnimScreen ()
2454
 
{
2455
 
    if (mAnimInProgress)
2456
 
        activateEvent (false);
2457
 
 
2458
 
    for (int i = 0; i < NUM_EFFECTS; i++)
2459
 
        delete animEffects[i];
2460
 
}
2461
 
 
2462
 
void
2463
 
PrivateAnimScreen::initAnimationList ()
2464
 
{
2465
 
    int i = 0;
2466
 
    animEffects[i++] = AnimEffectNone =
2467
 
        new AnimEffectInfo ("animation:None",
2468
 
                            true, true, true, true, true, 0);
2469
 
    animEffects[i++] = AnimEffectRandom =
2470
 
        new AnimEffectInfo ("animation:Random",
2471
 
                            true, true, true, true, false, 0);
2472
 
    animEffects[i++] = AnimEffectCurvedFold =
2473
 
        new AnimEffectInfo ("animation:Curved Fold",
2474
 
                            true, true, true, true, false,
2475
 
                            &createAnimation<CurvedFoldAnim>);
2476
 
    animEffects[i++] = AnimEffectDodge =
2477
 
        new AnimEffectInfo ("animation:Dodge",
2478
 
                            false, false, false, false, true,
2479
 
                            &createAnimation<DodgeAnim>,
2480
 
                            true);
2481
 
    animEffects[i++] = AnimEffectDream =
2482
 
        new AnimEffectInfo ("animation:Dream",
2483
 
                            true, true, true, false, false,
2484
 
                            &createAnimation<DreamAnim>);
2485
 
    animEffects[i++] = AnimEffectFade =
2486
 
        new AnimEffectInfo ("animation:Fade",
2487
 
                            true, true, true, false, false,
2488
 
                            &createAnimation<FadeAnim>);
2489
 
    animEffects[i++] = AnimEffectFocusFade =
2490
 
        new AnimEffectInfo ("animation:Focus Fade",
2491
 
                            false, false, false, false, true,
2492
 
                            &createAnimation<FocusFadeAnim>,
2493
 
                            true);
2494
 
    animEffects[i++] = AnimEffectGlide1 =
2495
 
        new AnimEffectInfo ("animation:Glide 1",
2496
 
                            true, true, true, false, false,
2497
 
                            &createAnimation<GlideAnim>);
2498
 
    animEffects[i++] = AnimEffectGlide2 =
2499
 
        new AnimEffectInfo ("animation:Glide 2",
2500
 
                            true, true, true, false, false,
2501
 
                            &createAnimation<Glide2Anim>);
2502
 
    animEffects[i++] = AnimEffectHorizontalFolds =
2503
 
        new AnimEffectInfo ("animation:Horizontal Folds",
2504
 
                            true, true, true, true, false,
2505
 
                            &createAnimation<HorizontalFoldsAnim>);
2506
 
    animEffects[i++] = AnimEffectMagicLamp =
2507
 
        new AnimEffectInfo ("animation:Magic Lamp",
2508
 
                            true, true, true, false, false,
2509
 
                            &createAnimation<MagicLampAnim>);
2510
 
    animEffects[i++] = AnimEffectMagicLampWavy =
2511
 
        new AnimEffectInfo ("animation:Magic Lamp Wavy",
2512
 
                            true, true, true, false, false,
2513
 
                            &createAnimation<MagicLampWavyAnim>);
2514
 
    animEffects[i++] = AnimEffectRollUp =
2515
 
        new AnimEffectInfo ("animation:Roll Up",
2516
 
                            false, false, false, true, false,
2517
 
                            &createAnimation<RollUpAnim>);
2518
 
    animEffects[i++] = AnimEffectSidekick =
2519
 
        new AnimEffectInfo ("animation:Sidekick",
2520
 
                            true, true, true, false, false,
2521
 
                            &createAnimation<SidekickAnim>);
2522
 
    animEffects[i++] = AnimEffectWave =
2523
 
        new AnimEffectInfo ("animation:Wave",
2524
 
                            true, true, true, false, true,
2525
 
                            &createAnimation<WaveAnim>);
2526
 
    animEffects[i++] = AnimEffectZoom =
2527
 
        new AnimEffectInfo ("animation:Zoom",
2528
 
                            true, true, true, false, false,
2529
 
                            &createAnimation<ZoomAnim>);
2530
 
 
2531
 
    animExtensionPluginInfo.effectOptions = &getOptions ();
2532
 
 
2533
 
    // Extends itself with the basic set of animation effects.
2534
 
    addExtension (&animExtensionPluginInfo, false);
2535
 
 
2536
 
    for (int e = 0; e < AnimEventNum; e++) // for each anim event
2537
 
        updateOptionSets ((AnimEvent)e);
2538
 
 
2539
 
    updateAllEventEffects ();
2540
 
 
2541
 
    cScreen->preparePaintSetEnabled (this, true);
2542
 
}
2543
 
 
2544
 
PrivateAnimWindow::PrivateAnimWindow (CompWindow *w,
2545
 
                                      AnimWindow *aw) :
2546
 
    gWindow (GLWindow::get (w)),
2547
 
    mWindow (w),
2548
 
    mAWindow (aw),
2549
 
    mPAScreen (AnimScreen::get (::screen)->priv),
2550
 
    mCurAnimation (0),
2551
 
    mUnshadePending (false),
2552
 
    mEventNotOpenClose (false),
2553
 
    mNowShaded (false),
2554
 
    mGrabbed (false),
2555
 
    mUnmapCnt (0),
2556
 
    mDestroyCnt (0),
2557
 
    mIgnoreDamage (false),
2558
 
    mFinishingAnim (false),
2559
 
    mCurAnimSelectionRow (-1)
2560
 
{
2561
 
    mBB.x1 = mBB.y1 = MAXSHORT;
2562
 
    mBB.x2 = mBB.y2 = MINSHORT;
2563
 
 
2564
 
    for (int i = 0; i < WatchedWindowPluginNum; i++)
2565
 
        mPluginActive[i] = false;
2566
 
 
2567
 
    if (w->minimized ())
2568
 
    {
2569
 
        mState = mNewState = IconicState;
2570
 
    }
2571
 
    else if (w->shaded ())
2572
 
    {
2573
 
        mState = mNewState = NormalState;
2574
 
        mNowShaded = true;
2575
 
    }
2576
 
    else
2577
 
    {
2578
 
        mState = mNewState = getState ();
2579
 
    }
2580
 
 
2581
 
    WindowInterface::setHandler (mWindow, true);
2582
 
    GLWindowInterface::setHandler (gWindow, false);
2583
 
}
2584
 
 
2585
 
PrivateAnimWindow::~PrivateAnimWindow ()
2586
 
{
2587
 
    notifyAnimation (false);
2588
 
    postAnimationCleanUpCustom (false, true, true);
2589
 
}
2590
 
 
2591
 
void
2592
 
PrivateAnimWindow::windowNotify (CompWindowNotify n)
2593
 
{
2594
 
    switch (n)
2595
 
    {
2596
 
        case CompWindowNotifyEnterShowDesktopMode:
2597
 
        case CompWindowNotifyMinimize:
2598
 
            mPAScreen->initiateMinimizeAnim (this);
2599
 
            mEventNotOpenClose = true;
2600
 
            break;
2601
 
        case CompWindowNotifyShade:
2602
 
            mPAScreen->initiateShadeAnim (this);
2603
 
            mEventNotOpenClose = true;
2604
 
            break;
2605
 
        case CompWindowNotifyLeaveShowDesktopMode:
2606
 
        case CompWindowNotifyUnminimize:
2607
 
            mPAScreen->initiateUnminimizeAnim (this);
2608
 
            mEventNotOpenClose = true;
2609
 
            break;
2610
 
        case CompWindowNotifyUnshade:
2611
 
            if (mNowShaded &&
2612
 
                mCurAnimation &&
2613
 
                mCurAnimation->curWindowEvent () == WindowEventShade)
2614
 
                mPAScreen->initiateUnshadeAnim (this); // reverse the shade anim
2615
 
            break;
2616
 
        case CompWindowNotifyClose:
2617
 
            if (!(mCurAnimation &&
2618
 
                  (mCurAnimation->curWindowEvent () == WindowEventClose ||
2619
 
                   mCurAnimation->curWindowEvent () == WindowEventUnminimize)))
2620
 
                mPAScreen->initiateCloseAnim (this);
2621
 
            break;
2622
 
        case CompWindowNotifyShow:
2623
 
        case CompWindowNotifyBeforeMap:
2624
 
            // Prevent dialog disappearing when a dialog is reopened during
2625
 
            // its close animation.
2626
 
            if (mCurAnimation &&
2627
 
                mCurAnimation->curWindowEvent () == WindowEventClose)
2628
 
            {
2629
 
                mPAScreen->initiateOpenAnim (this);
2630
 
                mEventNotOpenClose = false;
2631
 
            }
2632
 
            break;
2633
 
        case CompWindowNotifyMap:
2634
 
            if (mNowShaded)
2635
 
                mUnshadePending = true;
2636
 
            else if (!mUnshadePending &&
2637
 
                     !mEventNotOpenClose &&
2638
 
                     !mPAScreen->mStartCountdown &&
2639
 
                     !(mCurAnimation &&
2640
 
                       (mCurAnimation->curWindowEvent () ==
2641
 
                        WindowEventUnminimize ||
2642
 
                        mCurAnimation->curWindowEvent () == WindowEventOpen)))
2643
 
                mPAScreen->initiateOpenAnim (this);
2644
 
            mEventNotOpenClose = false;
2645
 
            break;
2646
 
        case CompWindowNotifyBeforeUnmap:
2647
 
            if (mCurAnimation && mCurAnimation->curWindowEvent () == WindowEventMinimize)
2648
 
            {
2649
 
                mUnmapCnt++;
2650
 
                mWindow->incrementUnmapReference ();
2651
 
            }
2652
 
            break;
2653
 
        case CompWindowNotifyBeforeDestroy:
2654
 
            if (!mFinishingAnim)
2655
 
            {
2656
 
                int duration;
2657
 
 
2658
 
                if (mPAScreen->shouldIgnoreWindowForAnim (mWindow, true))
2659
 
                    break;
2660
 
 
2661
 
                if (AnimEffectNone ==
2662
 
                    mPAScreen->getMatchingAnimSelection (mWindow,
2663
 
                                                         AnimEventClose,
2664
 
                                                         &duration))
2665
 
                    break;
2666
 
 
2667
 
                mDestroyCnt++;
2668
 
                mWindow->incrementDestroyReference ();
2669
 
            }
2670
 
            break;
2671
 
        case CompWindowNotifyUnreparent:
2672
 
            if (!mFinishingAnim)
2673
 
            {
2674
 
                if (mPAScreen->shouldIgnoreWindowForAnim (mWindow, false))
2675
 
                    break;
2676
 
            }
2677
 
            break;
2678
 
        case CompWindowNotifyFocusChange:
2679
 
            if (!mPAScreen->mLastActiveWindow ||
2680
 
                mPAScreen->mLastActiveWindow != mWindow->id ())
2681
 
            {
2682
 
                mPAScreen->mLastActiveWindow = mWindow->id ();
2683
 
 
2684
 
                if (mPAScreen->mStartCountdown) // Don't animate at startup
2685
 
                    break;
2686
 
 
2687
 
                int duration = 200;
2688
 
                AnimEffect chosenEffect =
2689
 
                    mPAScreen->getMatchingAnimSelection (mWindow,
2690
 
                                                         AnimEventFocus,
2691
 
                                                         &duration);
2692
 
 
2693
 
                if (chosenEffect &&
2694
 
                    chosenEffect != AnimEffectNone &&
2695
 
                    !chosenEffect->isRestackAnim)
2696
 
                    mPAScreen->initiateFocusAnim (this);
2697
 
            }
2698
 
 
2699
 
            break;
2700
 
        case CompWindowNotifyRestack:
2701
 
        {
2702
 
            // Prevent menu disappearing when a menu is reopened during
2703
 
            // its close animation. In that case a restack notify is thrown
2704
 
            // for menus.
2705
 
            if (mCurAnimation &&
2706
 
                mCurAnimation->curWindowEvent () == WindowEventClose)
2707
 
            {
2708
 
                mPAScreen->initiateOpenAnim (this);
2709
 
                mEventNotOpenClose = false;
2710
 
                break;
2711
 
            }
2712
 
 
2713
 
            // Handle CompWindowNotifyRestack only when necessary.
2714
 
            if (!mPAScreen->isRestackAnimPossible ())
2715
 
                break;
2716
 
 
2717
 
            if (mPAScreen->mStartCountdown) // Don't animate at startup
2718
 
                break;
2719
 
 
2720
 
            foreach (ExtensionPluginInfo *extPlugin,
2721
 
                     mPAScreen->mExtensionPlugins)
2722
 
                extPlugin->handleRestackNotify (mAWindow);
2723
 
 
2724
 
            break;
2725
 
        }
2726
 
        default:
2727
 
            break;
2728
 
    }
2729
 
 
2730
 
    mWindow->windowNotify (n);
2731
 
}
2732
 
 
2733
 
Animation *
2734
 
AnimWindow::curAnimation ()
2735
 
{
2736
 
    return priv->curAnimation ();
2737
 
}
2738
 
 
2739
 
AnimEffect
2740
 
AnimScreen::getMatchingAnimSelection (CompWindow *w,
2741
 
                                      AnimEvent e,
2742
 
                                      int *duration)
2743
 
{
2744
 
    return priv->getMatchingAnimSelection (w, e, duration);
2745
 
}
2746
 
 
2747
 
bool
2748
 
AnimScreen::otherPluginsActive ()
2749
 
{
2750
 
    return priv->otherPluginsActive ();
2751
 
}
2752
 
 
2753
 
bool
2754
 
AnimScreen::isAnimEffectPossible (AnimEffect theEffect)
2755
 
{
2756
 
    return priv->isAnimEffectPossible (theEffect);
2757
 
}
2758
 
 
2759
 
bool
2760
 
AnimScreen::initiateFocusAnim (AnimWindow *aw)
2761
 
{
2762
 
    return priv->initiateFocusAnim (aw->priv);
2763
 
}
2764
 
 
2765
 
/// If duration is 0, it should be set to a positive value later.
2766
 
void
2767
 
AnimWindow::createFocusAnimation (AnimEffect effect, int duration)
2768
 
{
2769
 
    priv->createFocusAnimation (effect, duration);
2770
 
}
2771
 
 
2772
 
void
2773
 
AnimWindow::deletePersistentData (const char *name)
2774
 
{
2775
 
    PersistentDataMap::iterator itData =
2776
 
        persistentData.find (name);
2777
 
    if (itData != persistentData.end ()) // if found
2778
 
    {
2779
 
        delete itData->second;
2780
 
        persistentData.erase (itData);
2781
 
    }
2782
 
}
2783
 
 
2784
 
void
2785
 
PrivateAnimWindow::createFocusAnimation (AnimEffect effect, int duration)
2786
 
{
2787
 
    mCurAnimation =
2788
 
        effect->create (mWindow, WindowEventFocus,
2789
 
                        duration,
2790
 
                        effect,
2791
 
                        CompRect ());
2792
 
    enablePainting (true);
2793
 
}
2794
 
 
2795
 
AnimScreen::AnimScreen (CompScreen *s) :
2796
 
    PluginClassHandler<AnimScreen, CompScreen, ANIMATION_ABI> (s),
2797
 
    priv (new PrivateAnimScreen (s, this))
2798
 
{
2799
 
    priv->initAnimationList ();
2800
 
}
2801
 
 
2802
 
AnimScreen::~AnimScreen ()
2803
 
{
2804
 
    delete priv;
2805
 
}
2806
 
 
2807
 
AnimWindow::AnimWindow (CompWindow *w) :
2808
 
    PluginClassHandler<AnimWindow, CompWindow, ANIMATION_ABI> (w),
2809
 
    mWindow (w),
2810
 
    priv (new PrivateAnimWindow (w, this)),
2811
 
    mSavedRectsValid (false)
2812
 
{
2813
 
    foreach (ExtensionPluginInfo *extPlugin, priv->mPAScreen->mExtensionPlugins)
2814
 
        extPlugin->initPersistentData (this);
2815
 
}
2816
 
 
2817
 
AnimWindow::~AnimWindow ()
2818
 
{
2819
 
    delete priv;
2820
 
 
2821
 
    // Destroy each persistent data object
2822
 
    PersistentDataMap::iterator itData = persistentData.begin ();
2823
 
    for (; itData != persistentData.end (); itData++)
2824
 
        delete itData->second;
2825
 
 
2826
 
    persistentData.clear ();
2827
 
}
2828
 
 
2829
 
bool
2830
 
AnimPluginVTable::init ()
2831
 
{
2832
 
    if (!CompPlugin::checkPluginABI ("core", CORE_ABIVERSION) |
2833
 
        !CompPlugin::checkPluginABI ("composite", COMPIZ_COMPOSITE_ABI) |
2834
 
        !CompPlugin::checkPluginABI ("opengl", COMPIZ_OPENGL_ABI))
2835
 
         return false;
2836
 
 
2837
 
    CompPrivate p;
2838
 
    p.uval = ANIMATION_ABI;
2839
 
    ::screen->storeValue ("animation_ABI", p);
2840
 
 
2841
 
    return true;
2842
 
}
2843
 
 
2844
 
void
2845
 
AnimPluginVTable::fini ()
2846
 
{
2847
 
    ::screen->eraseValue ("animation_ABI");
2848
 
}
2849