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

« back to all changes in this revision

Viewing changes to kwin/effects/dimscreen/dimscreen.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) 2008, 2009 Martin Gräßlin <kde@martin-graesslin.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
#include "dimscreen.h"
 
21
 
 
22
#include <kwinglutils.h>
 
23
 
 
24
namespace KWin
 
25
{
 
26
 
 
27
KWIN_EFFECT(dimscreen, DimScreenEffect)
 
28
 
 
29
DimScreenEffect::DimScreenEffect()
 
30
    : mActivated(false)
 
31
    , activateAnimation(false)
 
32
    , deactivateAnimation(false)
 
33
{
 
34
    reconfigure(ReconfigureAll);
 
35
    connect(effects, SIGNAL(windowActivated(EffectWindow*)), this, SLOT(slotWindowActivated(EffectWindow*)));
 
36
}
 
37
 
 
38
DimScreenEffect::~DimScreenEffect()
 
39
{
 
40
}
 
41
 
 
42
void DimScreenEffect::reconfigure(ReconfigureFlags)
 
43
{
 
44
    timeline.setDuration(animationTime(250));
 
45
}
 
46
 
 
47
void DimScreenEffect::prePaintScreen(ScreenPrePaintData& data, int time)
 
48
{
 
49
    if (mActivated && activateAnimation && !effects->activeFullScreenEffect())
 
50
        timeline.setCurrentTime(timeline.currentTime() + time);
 
51
    if (mActivated && deactivateAnimation)
 
52
        timeline.setCurrentTime(timeline.currentTime() - time);
 
53
    if (mActivated && effects->activeFullScreenEffect())
 
54
        timeline.setCurrentTime(timeline.currentTime() - time);
 
55
    if (mActivated && !activateAnimation && !deactivateAnimation && !effects->activeFullScreenEffect() && timeline.currentValue() != 1.0)
 
56
        timeline.setCurrentTime(timeline.currentTime() + time);
 
57
    effects->prePaintScreen(data, time);
 
58
}
 
59
 
 
60
void DimScreenEffect::postPaintScreen()
 
61
{
 
62
    if (mActivated) {
 
63
        if (activateAnimation && timeline.currentValue() == 1.0) {
 
64
            activateAnimation = false;
 
65
            effects->addRepaintFull();
 
66
        }
 
67
        if (deactivateAnimation && timeline.currentValue() == 0.0) {
 
68
            deactivateAnimation = false;
 
69
            mActivated = false;
 
70
            effects->addRepaintFull();
 
71
        }
 
72
        // still animating
 
73
        if (timeline.currentValue() > 0.0 && timeline.currentValue() < 1.0)
 
74
            effects->addRepaintFull();
 
75
    }
 
76
    effects->postPaintScreen();
 
77
}
 
78
 
 
79
void DimScreenEffect::paintWindow(EffectWindow *w, int mask, QRegion region, WindowPaintData &data)
 
80
{
 
81
    if (mActivated && (w != window) && w->isManaged()) {
 
82
        data.brightness *= (1.0 - 0.33 * timeline.currentValue());
 
83
        data.saturation *= (1.0 - 0.33 * timeline.currentValue());
 
84
    }
 
85
    effects->paintWindow(w, mask, region, data);
 
86
}
 
87
 
 
88
void DimScreenEffect::slotWindowActivated(EffectWindow *w)
 
89
{
 
90
    if (!w) return;
 
91
    QStringList check;
 
92
    check << "kdesu kdesu";
 
93
    check << "kdesudo kdesudo";
 
94
    check << "polkit-kde-manager polkit-kde-manager";
 
95
    check << "polkit-kde-authentication-agent-1 polkit-kde-authentication-agent-1";
 
96
    check << "pinentry pinentry";
 
97
    if (check.contains(w->windowClass())) {
 
98
        mActivated = true;
 
99
        activateAnimation = true;
 
100
        deactivateAnimation = false;
 
101
        window = w;
 
102
        effects->addRepaintFull();
 
103
    } else {
 
104
        if (mActivated) {
 
105
            activateAnimation = false;
 
106
            deactivateAnimation = true;
 
107
            effects->addRepaintFull();
 
108
        }
 
109
    }
 
110
}
 
111
} // namespace