~focus-follows-mouse/ubuntu/precise/compiz/fix-883383

« back to all changes in this revision

Viewing changes to plugins/fade.c

  • Committer: Bazaar Package Importer
  • Author(s): Matthew Garrett
  • Date: 2006-02-13 00:35:45 UTC
  • Revision ID: james.westby@ubuntu.com-20060213003545-073n47r3fl1i4gul
Tags: upstream-0.0.2
Import upstream version 0.0.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright © 2005 Novell, Inc.
 
3
 *
 
4
 * Permission to use, copy, modify, distribute, and sell this software
 
5
 * and its documentation for any purpose is hereby granted without
 
6
 * fee, provided that the above copyright notice appear in all copies
 
7
 * and that both that copyright notice and this permission notice
 
8
 * appear in supporting documentation, and that the name of
 
9
 * Novell, Inc. not be used in advertising or publicity pertaining to
 
10
 * distribution of the software without specific, written prior permission.
 
11
 * Novell, Inc. makes no representations about the suitability of this
 
12
 * software for any purpose. It is provided "as is" without express or
 
13
 * implied warranty.
 
14
 *
 
15
 * NOVELL, INC. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
 
16
 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN
 
17
 * NO EVENT SHALL NOVELL, INC. BE LIABLE FOR ANY SPECIAL, INDIRECT OR
 
18
 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
 
19
 * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
 
20
 * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
 
21
 * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 
22
 *
 
23
 * Author: David Reveman <davidr@novell.com>
 
24
 */
 
25
 
 
26
#include <stdlib.h>
 
27
#include <string.h>
 
28
 
 
29
#include <compiz.h>
 
30
 
 
31
#define FADE_SPEED_DEFAULT    5.0f
 
32
#define FADE_SPEED_MIN        0.1f
 
33
#define FADE_SPEED_MAX       10.0f
 
34
#define FADE_SPEED_PRECISION  0.1f
 
35
 
 
36
static char *winType[] = {
 
37
    "Dock",
 
38
    "Toolbar",
 
39
    "Menu",
 
40
    "Utility",
 
41
    "Splash",
 
42
    "Normal",
 
43
    "Dialog",
 
44
    "ModalDialog",
 
45
    "Unknown"
 
46
};
 
47
#define N_WIN_TYPE (sizeof (winType) / sizeof (winType[0]))
 
48
 
 
49
static int displayPrivateIndex;
 
50
 
 
51
typedef struct _FadeDisplay {
 
52
    int             screenPrivateIndex;
 
53
    HandleEventProc handleEvent;
 
54
    int             displayModals;
 
55
} FadeDisplay;
 
56
 
 
57
#define FADE_SCREEN_OPTION_FADE_SPEED     0
 
58
#define FADE_SCREEN_OPTION_WINDOW_TYPE    1
 
59
#define FADE_SCREEN_OPTION_NUM            2
 
60
 
 
61
typedef struct _FadeScreen {
 
62
    int                    windowPrivateIndex;
 
63
    int                    fadeTime;
 
64
    int                    steps;
 
65
 
 
66
    CompOption opt[FADE_SCREEN_OPTION_NUM];
 
67
 
 
68
    PreparePaintScreenProc preparePaintScreen;
 
69
    PaintWindowProc        paintWindow;
 
70
    DamageWindowRectProc   damageWindowRect;
 
71
    FocusWindowProc        focusWindow;
 
72
 
 
73
    int wMask;
 
74
} FadeScreen;
 
75
 
 
76
typedef struct _FadeWindow {
 
77
    GLushort opacity;
 
78
    GLushort brightness;
 
79
    GLushort saturation;
 
80
 
 
81
    int dModal;
 
82
 
 
83
    int destroyCnt;
 
84
    int unmapCnt;
 
85
} FadeWindow;
 
86
 
 
87
#define GET_FADE_DISPLAY(d)                                  \
 
88
    ((FadeDisplay *) (d)->privates[displayPrivateIndex].ptr)
 
89
 
 
90
#define FADE_DISPLAY(d)                    \
 
91
    FadeDisplay *fd = GET_FADE_DISPLAY (d)
 
92
 
 
93
#define GET_FADE_SCREEN(s, fd)                                   \
 
94
    ((FadeScreen *) (s)->privates[(fd)->screenPrivateIndex].ptr)
 
95
 
 
96
#define FADE_SCREEN(s)                                                  \
 
97
    FadeScreen *fs = GET_FADE_SCREEN (s, GET_FADE_DISPLAY (s->display))
 
98
 
 
99
#define GET_FADE_WINDOW(w, fs)                                   \
 
100
    ((FadeWindow *) (w)->privates[(fs)->windowPrivateIndex].ptr)
 
101
 
 
102
#define FADE_WINDOW(w)                                       \
 
103
    FadeWindow *fw = GET_FADE_WINDOW  (w,                    \
 
104
                     GET_FADE_SCREEN  (w->screen,            \
 
105
                     GET_FADE_DISPLAY (w->screen->display)))
 
106
 
 
107
#define NUM_OPTIONS(s) (sizeof ((s)->opt) / sizeof (CompOption))
 
108
 
 
109
static CompOption *
 
110
fadeGetScreenOptions (CompScreen *screen,
 
111
                      int        *count)
 
112
{
 
113
    FADE_SCREEN (screen);
 
114
 
 
115
    *count = NUM_OPTIONS (fs);
 
116
    return fs->opt;
 
117
}
 
118
 
 
119
static Bool
 
120
fadeSetScreenOption (CompScreen      *screen,
 
121
                     char            *name,
 
122
                     CompOptionValue *value)
 
123
{
 
124
    CompOption *o;
 
125
    int        index;
 
126
 
 
127
    FADE_SCREEN (screen);
 
128
 
 
129
    o = compFindOption (fs->opt, NUM_OPTIONS (fs), name, &index);
 
130
    if (!o)
 
131
        return FALSE;
 
132
 
 
133
    switch (index) {
 
134
    case FADE_SCREEN_OPTION_FADE_SPEED:
 
135
        if (compSetFloatOption (o, value))
 
136
        {
 
137
            fs->fadeTime = 1000.0f / o->value.f;
 
138
            return TRUE;
 
139
        }
 
140
        break;
 
141
    case FADE_SCREEN_OPTION_WINDOW_TYPE:
 
142
        if (compSetOptionList (o, value))
 
143
        {
 
144
            fs->wMask = compWindowTypeMaskFromStringList (&o->value);
 
145
            fs->wMask &= ~CompWindowTypeDesktopMask;
 
146
            return TRUE;
 
147
        }
 
148
    default:
 
149
        break;
 
150
    }
 
151
 
 
152
    return FALSE;
 
153
}
 
154
 
 
155
static void
 
156
fadeScreenInitOptions (FadeScreen *fs)
 
157
{
 
158
    CompOption *o;
 
159
    int        i;
 
160
 
 
161
    o = &fs->opt[FADE_SCREEN_OPTION_FADE_SPEED];
 
162
    o->name             = "fade_speed";
 
163
    o->shortDesc        = "Fade Speed";
 
164
    o->longDesc         = "Window fade speed";
 
165
    o->type             = CompOptionTypeFloat;
 
166
    o->value.f          = FADE_SPEED_DEFAULT;
 
167
    o->rest.f.min       = FADE_SPEED_MIN;
 
168
    o->rest.f.max       = FADE_SPEED_MAX;
 
169
    o->rest.f.precision = FADE_SPEED_PRECISION;
 
170
 
 
171
    o = &fs->opt[FADE_SCREEN_OPTION_WINDOW_TYPE];
 
172
    o->name              = "window_types";
 
173
    o->shortDesc         = "Window Types";
 
174
    o->longDesc          = "Window types that should be fading";
 
175
    o->type              = CompOptionTypeList;
 
176
    o->value.list.type   = CompOptionTypeString;
 
177
    o->value.list.nValue = N_WIN_TYPE;
 
178
    o->value.list.value  = malloc (sizeof (CompOptionValue) * N_WIN_TYPE);
 
179
    for (i = 0; i < N_WIN_TYPE; i++)
 
180
        o->value.list.value[i].s = strdup (winType[i]);
 
181
    o->rest.s.string     = windowTypeString;
 
182
    o->rest.s.nString    = nWindowTypeString;
 
183
 
 
184
    fs->wMask = compWindowTypeMaskFromStringList (&o->value);
 
185
}
 
186
 
 
187
static void
 
188
fadePreparePaintScreen (CompScreen *s,
 
189
                        int        msSinceLastPaint)
 
190
{
 
191
    FADE_SCREEN (s);
 
192
 
 
193
    fs->steps = (msSinceLastPaint * OPAQUE) / fs->fadeTime;
 
194
    if (fs->steps < 12)
 
195
        fs->steps = 12;
 
196
 
 
197
    UNWRAP (fs, s, preparePaintScreen);
 
198
    (*s->preparePaintScreen) (s, msSinceLastPaint);
 
199
    WRAP (fs, s, preparePaintScreen, fadePreparePaintScreen);
 
200
}
 
201
 
 
202
static Bool
 
203
fadePaintWindow (CompWindow              *w,
 
204
                 const WindowPaintAttrib *attrib,
 
205
                 Region                  region,
 
206
                 unsigned int            mask)
 
207
{
 
208
    CompScreen *s = w->screen;
 
209
    Bool       status;
 
210
 
 
211
    FADE_SCREEN (s);
 
212
    FADE_WINDOW (w);
 
213
 
 
214
    if (!w->screen->canDoSlightlySaturated)
 
215
        fw->saturation = attrib->saturation;
 
216
 
 
217
    if (fw->opacity    != attrib->opacity    ||
 
218
        fw->brightness != attrib->brightness ||
 
219
        fw->saturation != attrib->saturation)
 
220
    {
 
221
        GLint opacity;
 
222
        GLint brightness;
 
223
        GLint saturation;
 
224
 
 
225
        opacity = fw->opacity;
 
226
        if (attrib->opacity > fw->opacity)
 
227
        {
 
228
            opacity = fw->opacity + fs->steps;
 
229
            if (opacity > attrib->opacity)
 
230
                opacity = attrib->opacity;
 
231
        }
 
232
        else if (attrib->opacity < fw->opacity)
 
233
        {
 
234
            if (w->type & CompWindowTypeUnknownMask)
 
235
                opacity = fw->opacity - (fs->steps >> 1);
 
236
            else
 
237
                opacity = fw->opacity - fs->steps;
 
238
 
 
239
            if (opacity < attrib->opacity)
 
240
                opacity = attrib->opacity;
 
241
        }
 
242
 
 
243
        brightness = fw->brightness;
 
244
        if (attrib->brightness > fw->brightness)
 
245
        {
 
246
            brightness = fw->brightness + (fs->steps / 12);
 
247
            if (brightness > attrib->brightness)
 
248
                brightness = attrib->brightness;
 
249
        }
 
250
        else if (attrib->brightness < fw->brightness)
 
251
        {
 
252
            brightness = fw->brightness - (fs->steps / 12);
 
253
            if (brightness < attrib->brightness)
 
254
                brightness = attrib->brightness;
 
255
        }
 
256
 
 
257
        saturation = fw->saturation;
 
258
        if (attrib->saturation > fw->saturation)
 
259
        {
 
260
            saturation = fw->saturation + (fs->steps / 6);
 
261
            if (saturation > attrib->saturation)
 
262
                saturation = attrib->saturation;
 
263
        }
 
264
        else if (attrib->saturation < fw->saturation)
 
265
        {
 
266
            saturation = fw->saturation - (fs->steps / 6);
 
267
            if (saturation < attrib->saturation)
 
268
                saturation = attrib->saturation;
 
269
        }
 
270
 
 
271
        if (opacity > 0)
 
272
        {
 
273
            WindowPaintAttrib fAttrib = *attrib;
 
274
 
 
275
            fAttrib.opacity    = opacity;
 
276
            fAttrib.brightness = brightness;
 
277
            fAttrib.saturation = saturation;
 
278
 
 
279
            UNWRAP (fs, s, paintWindow);
 
280
            status = (*s->paintWindow) (w, &fAttrib, region, mask);
 
281
            WRAP (fs, s, paintWindow, fadePaintWindow);
 
282
 
 
283
            if (status)
 
284
            {
 
285
                fw->opacity    = opacity;
 
286
                fw->brightness = brightness;
 
287
                fw->saturation = saturation;
 
288
 
 
289
                if (opacity    != attrib->opacity    ||
 
290
                    brightness != attrib->brightness ||
 
291
                    saturation != attrib->saturation)
 
292
                    addWindowDamage (w);
 
293
            }
 
294
        }
 
295
        else
 
296
        {
 
297
            fw->opacity = 0;
 
298
 
 
299
            while (fw->unmapCnt)
 
300
            {
 
301
                unmapWindow (w);
 
302
                fw->unmapCnt--;
 
303
            }
 
304
 
 
305
            while (fw->destroyCnt)
 
306
            {
 
307
                destroyWindow (w);
 
308
                fw->destroyCnt--;
 
309
            }
 
310
 
 
311
            return (mask & PAINT_WINDOW_SOLID_MASK) ? FALSE : TRUE;
 
312
        }
 
313
    }
 
314
    else
 
315
    {
 
316
        UNWRAP (fs, s, paintWindow);
 
317
        status = (*s->paintWindow) (w, attrib, region, mask);
 
318
        WRAP (fs, s, paintWindow, fadePaintWindow);
 
319
    }
 
320
 
 
321
    return status;
 
322
}
 
323
 
 
324
static void
 
325
fadeAddDisplayModal (CompDisplay *d,
 
326
                     CompWindow  *w)
 
327
{
 
328
    FADE_DISPLAY (d);
 
329
    FADE_WINDOW (w);
 
330
 
 
331
    if (!(w->state & CompWindowStateDisplayModalMask))
 
332
        return;
 
333
 
 
334
    if (fw->dModal)
 
335
        return;
 
336
 
 
337
    fw->dModal = 1;
 
338
 
 
339
    fd->displayModals++;
 
340
    if (fd->displayModals == 1)
 
341
    {
 
342
        CompScreen *s;
 
343
 
 
344
        for (s = d->screens; s; s = s->next)
 
345
        {
 
346
            for (w = s->windows; w; w = w->next)
 
347
            {
 
348
                FADE_WINDOW (w);
 
349
 
 
350
                if (fw->dModal)
 
351
                    continue;
 
352
 
 
353
                w->paint.brightness = 0x8080;
 
354
                w->paint.saturation = 0;
 
355
            }
 
356
 
 
357
            damageScreen (s);
 
358
        }
 
359
    }
 
360
}
 
361
 
 
362
static void
 
363
fadeRemoveDisplayModal (CompDisplay *d,
 
364
                        CompWindow  *w)
 
365
{
 
366
    FADE_DISPLAY (d);
 
367
    FADE_WINDOW (w);
 
368
 
 
369
    if (!fw->dModal)
 
370
        return;
 
371
 
 
372
    fw->dModal = 0;
 
373
 
 
374
    fd->displayModals--;
 
375
    if (fd->displayModals == 0)
 
376
    {
 
377
        CompScreen *s;
 
378
 
 
379
        for (s = d->screens; s; s = s->next)
 
380
        {
 
381
            for (w = s->windows; w; w = w->next)
 
382
            {
 
383
                FADE_WINDOW (w);
 
384
 
 
385
                if (fw->dModal)
 
386
                    continue;
 
387
 
 
388
                if (w->alive)
 
389
                {
 
390
                    w->paint.brightness = w->brightness;
 
391
                    w->paint.saturation = w->saturation;
 
392
                }
 
393
            }
 
394
 
 
395
            damageScreen (s);
 
396
        }
 
397
    }
 
398
}
 
399
 
 
400
static void
 
401
fadeHandleEvent (CompDisplay *d,
 
402
                 XEvent      *event)
 
403
{
 
404
    CompWindow *w;
 
405
 
 
406
    FADE_DISPLAY (d);
 
407
 
 
408
    switch (event->type) {
 
409
    case DestroyNotify:
 
410
        w = findWindowAtDisplay (d, event->xdestroywindow.window);
 
411
        if (w)
 
412
        {
 
413
            FADE_SCREEN (w->screen);
 
414
 
 
415
            if (w->texture.pixmap && (fs->wMask & w->type))
 
416
            {
 
417
                FADE_WINDOW (w);
 
418
 
 
419
                w->paint.opacity = 0;
 
420
 
 
421
                fw->destroyCnt++;
 
422
                w->destroyRefCnt++;
 
423
 
 
424
                addWindowDamage (w);
 
425
            }
 
426
 
 
427
            fadeRemoveDisplayModal (d, w);
 
428
        }
 
429
        break;
 
430
    case UnmapNotify:
 
431
        w = findWindowAtDisplay (d, event->xunmap.window);
 
432
        if (w)
 
433
        {
 
434
            FADE_SCREEN (w->screen);
 
435
 
 
436
            if (w->texture.pixmap && (fs->wMask & w->type))
 
437
            {
 
438
                FADE_WINDOW (w);
 
439
 
 
440
                w->paint.opacity = 0;
 
441
 
 
442
                fw->unmapCnt++;
 
443
                w->unmapRefCnt++;
 
444
 
 
445
                addWindowDamage (w);
 
446
            }
 
447
 
 
448
            fadeRemoveDisplayModal (d, w);
 
449
        }
 
450
        break;
 
451
    case MapNotify:
 
452
        w = findWindowAtDisplay (d, event->xunmap.window);
 
453
        if (w)
 
454
        {
 
455
            FADE_WINDOW (w);
 
456
 
 
457
            if (!(w->type & CompWindowTypeDesktopMask))
 
458
                w->paint.opacity = getWindowProp32 (d, w->id,
 
459
                                                    d->winOpacityAtom,
 
460
                                                    OPAQUE);
 
461
 
 
462
            while (fw->unmapCnt)
 
463
            {
 
464
                unmapWindow (w);
 
465
                fw->unmapCnt--;
 
466
            }
 
467
 
 
468
            if (w->state & CompWindowStateDisplayModalMask)
 
469
                fadeAddDisplayModal (d, w);
 
470
        }
 
471
    default:
 
472
        break;
 
473
    }
 
474
 
 
475
    UNWRAP (fd, d, handleEvent);
 
476
    (*d->handleEvent) (d, event);
 
477
    WRAP (fd, d, handleEvent, fadeHandleEvent);
 
478
 
 
479
    switch (event->type) {
 
480
    case PropertyNotify:
 
481
        if (event->xproperty.atom == d->winStateAtom)
 
482
        {
 
483
            w = findWindowAtDisplay (d, event->xproperty.window);
 
484
            if (w && w->attrib.map_state == IsViewable)
 
485
            {
 
486
                if (w->state & CompWindowStateDisplayModalMask)
 
487
                    fadeAddDisplayModal (d, w);
 
488
                else
 
489
                    fadeRemoveDisplayModal (d, w);
 
490
            }
 
491
        }
 
492
        break;
 
493
    }
 
494
}
 
495
 
 
496
static Bool
 
497
fadeDamageWindowRect (CompWindow *w,
 
498
                      Bool       initial,
 
499
                      BoxPtr     rect)
 
500
{
 
501
    Bool status;
 
502
 
 
503
    FADE_SCREEN (w->screen);
 
504
 
 
505
    if (initial)
 
506
    {
 
507
        FADE_WINDOW (w);
 
508
 
 
509
        if (fs->wMask & w->type)
 
510
            fw->opacity = 0;
 
511
        else
 
512
            fw->opacity = w->paint.opacity;
 
513
    }
 
514
 
 
515
    UNWRAP (fs, w->screen, damageWindowRect);
 
516
    status = (*w->screen->damageWindowRect) (w, initial, rect);
 
517
    WRAP (fs, w->screen, damageWindowRect, fadeDamageWindowRect);
 
518
 
 
519
    return status;
 
520
}
 
521
 
 
522
static Bool
 
523
fadeFocusWindow (CompWindow *w)
 
524
{
 
525
    Bool status;
 
526
 
 
527
    FADE_SCREEN (w->screen);
 
528
    FADE_WINDOW (w);
 
529
 
 
530
    if (fw->destroyCnt || fw->unmapCnt)
 
531
        return FALSE;
 
532
 
 
533
    UNWRAP (fs, w->screen, focusWindow);
 
534
    status = (*w->screen->focusWindow) (w);
 
535
    WRAP (fs, w->screen, focusWindow, fadeFocusWindow);
 
536
 
 
537
    return status;
 
538
}
 
539
 
 
540
static Bool
 
541
fadeInitDisplay (CompPlugin  *p,
 
542
                 CompDisplay *d)
 
543
{
 
544
    FadeDisplay *fd;
 
545
 
 
546
    fd = malloc (sizeof (FadeDisplay));
 
547
    if (!fd)
 
548
        return FALSE;
 
549
 
 
550
    fd->screenPrivateIndex = allocateScreenPrivateIndex (d);
 
551
    if (fd->screenPrivateIndex < 0)
 
552
    {
 
553
        free (fd);
 
554
        return FALSE;
 
555
    }
 
556
 
 
557
    fd->displayModals = 0;
 
558
 
 
559
    WRAP (fd, d, handleEvent, fadeHandleEvent);
 
560
 
 
561
    d->privates[displayPrivateIndex].ptr = fd;
 
562
 
 
563
    return TRUE;
 
564
}
 
565
 
 
566
static void
 
567
fadeFiniDisplay (CompPlugin *p,
 
568
                 CompDisplay *d)
 
569
{
 
570
    FADE_DISPLAY (d);
 
571
 
 
572
    freeScreenPrivateIndex (d, fd->screenPrivateIndex);
 
573
 
 
574
    UNWRAP (fd, d, handleEvent);
 
575
 
 
576
    free (fd);
 
577
}
 
578
 
 
579
static Bool
 
580
fadeInitScreen (CompPlugin *p,
 
581
                CompScreen *s)
 
582
{
 
583
    FadeScreen *fs;
 
584
 
 
585
    FADE_DISPLAY (s->display);
 
586
 
 
587
    fs = malloc (sizeof (FadeScreen));
 
588
    if (!fs)
 
589
        return FALSE;
 
590
 
 
591
    fs->windowPrivateIndex = allocateWindowPrivateIndex (s);
 
592
    if (fs->windowPrivateIndex < 0)
 
593
    {
 
594
        free (fs);
 
595
        return FALSE;
 
596
    }
 
597
 
 
598
    fs->steps    = 0;
 
599
    fs->fadeTime = 1000.0f / FADE_SPEED_DEFAULT;
 
600
 
 
601
    fadeScreenInitOptions (fs);
 
602
 
 
603
    WRAP (fs, s, preparePaintScreen, fadePreparePaintScreen);
 
604
    WRAP (fs, s, paintWindow, fadePaintWindow);
 
605
    WRAP (fs, s, damageWindowRect, fadeDamageWindowRect);
 
606
    WRAP (fs, s, focusWindow, fadeFocusWindow);
 
607
 
 
608
    s->privates[fd->screenPrivateIndex].ptr = fs;
 
609
 
 
610
    return TRUE;
 
611
}
 
612
 
 
613
static void
 
614
fadeFiniScreen (CompPlugin *p,
 
615
                CompScreen *s)
 
616
{
 
617
    FADE_SCREEN (s);
 
618
 
 
619
    freeWindowPrivateIndex (s, fs->windowPrivateIndex);
 
620
 
 
621
    UNWRAP (fs, s, preparePaintScreen);
 
622
    UNWRAP (fs, s, paintWindow);
 
623
    UNWRAP (fs, s, damageWindowRect);
 
624
    UNWRAP (fs, s, focusWindow);
 
625
 
 
626
    free (fs);
 
627
}
 
628
 
 
629
static Bool
 
630
fadeInitWindow (CompPlugin *p,
 
631
                CompWindow *w)
 
632
{
 
633
    FadeWindow *fw;
 
634
 
 
635
    FADE_SCREEN (w->screen);
 
636
 
 
637
    fw = malloc (sizeof (FadeWindow));
 
638
    if (!fw)
 
639
        return FALSE;
 
640
 
 
641
    fw->opacity    = w->paint.opacity;
 
642
    fw->brightness = w->paint.brightness;
 
643
    fw->saturation = w->paint.saturation;
 
644
 
 
645
    fw->dModal = 0;
 
646
 
 
647
    fw->destroyCnt = 0;
 
648
    fw->unmapCnt   = 0;
 
649
 
 
650
    w->privates[fs->windowPrivateIndex].ptr = fw;
 
651
 
 
652
    if (w->attrib.map_state == IsViewable)
 
653
    {
 
654
        if (w->state & CompWindowStateDisplayModalMask)
 
655
            fadeAddDisplayModal (w->screen->display, w);
 
656
    }
 
657
 
 
658
    return TRUE;
 
659
}
 
660
 
 
661
static void
 
662
fadeFiniWindow (CompPlugin *p,
 
663
                CompWindow *w)
 
664
{
 
665
    FADE_WINDOW (w);
 
666
 
 
667
    fadeRemoveDisplayModal (w->screen->display, w);
 
668
 
 
669
    while (fw->unmapCnt--)
 
670
        unmapWindow (w);
 
671
 
 
672
    while (fw->destroyCnt--)
 
673
        destroyWindow (w);
 
674
 
 
675
    free (fw);
 
676
}
 
677
 
 
678
static Bool
 
679
fadeInit (CompPlugin *p)
 
680
{
 
681
    displayPrivateIndex = allocateDisplayPrivateIndex ();
 
682
    if (displayPrivateIndex < 0)
 
683
        return FALSE;
 
684
 
 
685
    return TRUE;
 
686
}
 
687
 
 
688
static void
 
689
fadeFini (CompPlugin *p)
 
690
{
 
691
    if (displayPrivateIndex >= 0)
 
692
        freeDisplayPrivateIndex (displayPrivateIndex);
 
693
}
 
694
 
 
695
CompPluginDep fadeDeps[] = {
 
696
    { CompPluginRuleBefore, "cube" },
 
697
    { CompPluginRuleBefore, "expose" }
 
698
};
 
699
 
 
700
static CompPluginVTable fadeVTable = {
 
701
    "fade",
 
702
    "Fading Windows",
 
703
    "Fade in windows when mapped and fade out windows when unmapped",
 
704
    fadeInit,
 
705
    fadeFini,
 
706
    fadeInitDisplay,
 
707
    fadeFiniDisplay,
 
708
    fadeInitScreen,
 
709
    fadeFiniScreen,
 
710
    fadeInitWindow,
 
711
    fadeFiniWindow,
 
712
    0, /* GetDisplayOptions */
 
713
    0, /* SetDisplayOption */
 
714
    fadeGetScreenOptions,
 
715
    fadeSetScreenOption,
 
716
    fadeDeps,
 
717
    sizeof (fadeDeps) / sizeof (fadeDeps[0])
 
718
};
 
719
 
 
720
CompPluginVTable *
 
721
getCompPluginInfo (void)
 
722
{
 
723
    return &fadeVTable;
 
724
}