~ubuntu-branches/ubuntu/utopic/kde-workspace/utopic-proposed

« back to all changes in this revision

Viewing changes to kwin/effects/fadedesktop/fadedesktop.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Michał Zając
  • Date: 2011-07-09 08:31:15 UTC
  • Revision ID: james.westby@ubuntu.com-20110709083115-ohyxn6z93mily9fc
Tags: upstream-4.6.90
Import upstream version 4.6.90

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/********************************************************************
 
2
 KWin - the KDE window manager
 
3
 This file is part of the KDE project.
 
4
 
 
5
Copyright (C) 2009 Lucas Murray <lmurray@undefinedfire.com>
 
6
 
 
7
This program is free software; you can redistribute it and/or modify
 
8
it under the terms of the GNU General Public License as published by
 
9
the Free Software Foundation; either version 2 of the License, or
 
10
(at your option) any later version.
 
11
 
 
12
This program is distributed in the hope that it will be useful,
 
13
but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
15
GNU General Public License for more details.
 
16
 
 
17
You should have received a copy of the GNU General Public License
 
18
along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
19
*********************************************************************/
 
20
 
 
21
#include "fadedesktop.h"
 
22
 
 
23
#include <math.h>
 
24
 
 
25
namespace KWin
 
26
{
 
27
 
 
28
KWIN_EFFECT(fadedesktop, FadeDesktopEffect)
 
29
 
 
30
FadeDesktopEffect::FadeDesktopEffect()
 
31
    : m_fading(false)
 
32
{
 
33
    connect(effects, SIGNAL(desktopChanged(int,int)), this, SLOT(slotDesktopChanged(int)));
 
34
    m_timeline.setCurveShape(QTimeLine::LinearCurve);
 
35
    reconfigure(ReconfigureAll);
 
36
}
 
37
 
 
38
void FadeDesktopEffect::reconfigure(ReconfigureFlags)
 
39
{
 
40
    m_timeline.setDuration(animationTime(250));
 
41
}
 
42
 
 
43
void FadeDesktopEffect::prePaintScreen(ScreenPrePaintData &data, int time)
 
44
{
 
45
    if (m_fading) {
 
46
        m_timeline.setCurrentTime(m_timeline.currentTime() + time);
 
47
 
 
48
        // PAINT_SCREEN_BACKGROUND_FIRST is needed because screen will be actually painted more than once,
 
49
        // so with normal screen painting second screen paint would erase parts of the first paint
 
50
        if (m_timeline.currentValue() != 1.0)
 
51
            data.mask |= PAINT_SCREEN_TRANSFORMED | PAINT_SCREEN_BACKGROUND_FIRST;
 
52
        else {
 
53
            m_fading = false;
 
54
            m_timeline.setCurrentTime(0);
 
55
            foreach (EffectWindow * w, effects->stackingOrder()) {
 
56
                w->setData(WindowForceBlurRole, QVariant(false));
 
57
            }
 
58
            effects->setActiveFullScreenEffect(NULL);
 
59
        }
 
60
    }
 
61
    effects->prePaintScreen(data, time);
 
62
}
 
63
 
 
64
void FadeDesktopEffect::postPaintScreen()
 
65
{
 
66
    if (m_fading)
 
67
        effects->addRepaintFull();
 
68
    effects->postPaintScreen();
 
69
}
 
70
 
 
71
void FadeDesktopEffect::prePaintWindow(EffectWindow *w, WindowPrePaintData &data, int time)
 
72
{
 
73
    if (m_fading) {
 
74
        if (w->isOnDesktop(m_oldDesktop))
 
75
            w->enablePainting(EffectWindow::PAINT_DISABLED_BY_DESKTOP);
 
76
        data.setTranslucent();
 
77
    }
 
78
    effects->prePaintWindow(w, data, time);
 
79
}
 
80
 
 
81
void FadeDesktopEffect::paintWindow(EffectWindow *w, int mask, QRegion region, WindowPaintData &data)
 
82
{
 
83
    if (m_fading && !(w->isOnCurrentDesktop() && w->isOnDesktop(m_oldDesktop))) {
 
84
        if (w->isOnDesktop(m_oldDesktop))
 
85
            data.opacity *= 1 - m_timeline.currentValue();
 
86
        else
 
87
            data.opacity *= m_timeline.currentValue();
 
88
    }
 
89
    effects->paintWindow(w, mask, region, data);
 
90
}
 
91
 
 
92
void FadeDesktopEffect::slotDesktopChanged(int old)
 
93
{
 
94
    if (effects->activeFullScreenEffect() && effects->activeFullScreenEffect() != this)
 
95
        return;
 
96
 
 
97
    // TODO: Fix glitches when fading while a previous fade is still happening
 
98
 
 
99
    effects->setActiveFullScreenEffect(this);
 
100
    m_fading = true;
 
101
    m_timeline.setCurrentTime(0);
 
102
    m_oldDesktop = old;
 
103
    foreach (EffectWindow * w, effects->stackingOrder()) {
 
104
        w->setData(WindowForceBlurRole, QVariant(true));
 
105
    }
 
106
 
 
107
    effects->addRepaintFull();
 
108
}
 
109
 
 
110
} // namespace
 
111
 
 
112
#include "fadedesktop.moc"