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

« back to all changes in this revision

Viewing changes to kwin/effects/translucency/translucency.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) 2006 Lubos Lunak <l.lunak@kde.org>
 
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 "translucency.h"
 
22
 
 
23
#include <kconfiggroup.h>
 
24
 
 
25
namespace KWin
 
26
{
 
27
 
 
28
KWIN_EFFECT(translucency, TranslucencyEffect)
 
29
 
 
30
TranslucencyEffect::TranslucencyEffect()
 
31
    : fadeout(NULL)
 
32
    , current(NULL)
 
33
    , previous(NULL)
 
34
{
 
35
    reconfigure(ReconfigureAll);
 
36
    active = effects->activeWindow();
 
37
    connect(effects, SIGNAL(windowActivated(EffectWindow*)), this, SLOT(slotWindowActivated(EffectWindow*)));
 
38
    connect(effects, SIGNAL(windowStartUserMovedResized(EffectWindow*)), this, SLOT(slotWindowStartStopUserMovedResized(EffectWindow*)));
 
39
    connect(effects, SIGNAL(windowFinishUserMovedResized(EffectWindow*)), this, SLOT(slotWindowStartStopUserMovedResized(EffectWindow*)));
 
40
}
 
41
 
 
42
void TranslucencyEffect::reconfigure(ReconfigureFlags)
 
43
{
 
44
    KConfigGroup conf = effects->effectConfig("Translucency");
 
45
    decoration = conf.readEntry("Decoration", 1.0);
 
46
    moveresize = conf.readEntry("MoveResize", 0.8);
 
47
    dialogs = conf.readEntry("Dialogs", 1.0);
 
48
    inactive = conf.readEntry("Inactive", 1.0);
 
49
    comboboxpopups = conf.readEntry("ComboboxPopups", 1.0);
 
50
    menus = conf.readEntry("Menus", 1.0);
 
51
    individualmenuconfig = conf.readEntry("IndividualMenuConfig", false);
 
52
    if (individualmenuconfig) {
 
53
        dropdownmenus = conf.readEntry("DropdownMenus", 1.0);
 
54
        popupmenus = conf.readEntry("PopupMenus", 1.0);
 
55
        tornoffmenus = conf.readEntry("TornOffMenus", 1.0);
 
56
    } else {
 
57
        dropdownmenus = menus;
 
58
        popupmenus = menus;
 
59
        tornoffmenus = menus;
 
60
    }
 
61
    moveresize_timeline.setCurveShape(QTimeLine::EaseInOutCurve);
 
62
    moveresize_timeline.setDuration(animationTime(conf, "Duration", 800));
 
63
    activeinactive_timeline.setCurveShape(QTimeLine::EaseInOutCurve);
 
64
    activeinactive_timeline.setDuration(animationTime(conf, "Duration", 800));
 
65
 
 
66
    // Repaint the screen just in case the user changed the inactive opacity
 
67
    effects->addRepaintFull();
 
68
}
 
69
 
 
70
void TranslucencyEffect::prePaintWindow(EffectWindow* w, WindowPrePaintData& data, int time)
 
71
{
 
72
    moveresize_timeline.setCurrentTime(moveresize_timeline.currentTime() + time);
 
73
    activeinactive_timeline.setCurrentTime(activeinactive_timeline.currentTime() + time);
 
74
 
 
75
    if (decoration != 1.0 && w->hasDecoration()) {
 
76
        data.mask |= PAINT_WINDOW_TRANSLUCENT;
 
77
        // don't clear PAINT_WINDOW_OPAQUE, contents are not affected
 
78
        data.clip &= w->contentsRect().translated(w->pos());  // decoration cannot clip
 
79
    }
 
80
    if (inactive != 1.0 && isInactive(w))
 
81
        data.setTranslucent();
 
82
    if ((moveresize != 1.0 && (w->isUserMove() || w->isUserResize()))
 
83
            || (dialogs != 1.0 && w->isDialog())) {
 
84
        data.setTranslucent();
 
85
    }
 
86
    if ((dropdownmenus != 1.0 && w->isDropdownMenu())
 
87
            || (popupmenus != 1.0 && w->isPopupMenu())
 
88
            || (tornoffmenus != 1.0 && w->isMenu())
 
89
            || (comboboxpopups != 1.0 && w->isComboBox())) {
 
90
        data.setTranslucent();
 
91
    }
 
92
 
 
93
    effects->prePaintWindow(w, data, time);
 
94
}
 
95
 
 
96
void TranslucencyEffect::paintWindow(EffectWindow* w, int mask, QRegion region, WindowPaintData& data)
 
97
{
 
98
    // We keep track of the windows that was last active so we know
 
99
    // which one to fade out and which ones to paint as fully inactive
 
100
    if (w == active && w != current) {
 
101
        previous = current;
 
102
        current = w;
 
103
    }
 
104
 
 
105
    if (w->isDesktop() || w->isDock()) {
 
106
        effects->paintWindow(w, mask, region, data);
 
107
        return;
 
108
    }
 
109
    // Handling active and inactive windows
 
110
    if (inactive != 1.0 && isInactive(w)) {
 
111
        data.opacity *= inactive;
 
112
 
 
113
        if (w == previous) {
 
114
            data.opacity *= (inactive + ((1.0 - inactive) * (1.0 - activeinactive_timeline.currentValue())));
 
115
            if (activeinactive_timeline.currentValue() < 1.0)
 
116
                w->addRepaintFull();
 
117
        }
 
118
    } else {
 
119
        // Fading in
 
120
        if (!isInactive(w) && !w->isDesktop()) {
 
121
            data.opacity *= (inactive + ((1.0 - inactive) * activeinactive_timeline.currentValue()));
 
122
            if (activeinactive_timeline.currentValue() < 1.0)
 
123
                w->addRepaintFull();
 
124
        }
 
125
        // decoration and dialogs
 
126
        if (decoration != 1.0 && w->hasDecoration())
 
127
            data.decoration_opacity *= decoration;
 
128
        if (dialogs != 1.0 && w->isDialog())
 
129
            data.opacity *= dialogs;
 
130
 
 
131
        // Handling moving and resizing
 
132
        if (moveresize != 1.0 && !w->isDesktop() && !w->isDock()) {
 
133
            double progress = moveresize_timeline.currentValue();
 
134
            if (w->isUserMove() || w->isUserResize()) {
 
135
                // Fading to translucent
 
136
                data.opacity *= (moveresize + ((1.0 - moveresize) * (1.0 - progress)));
 
137
                if (progress < 1.0 && progress > 0.0) {
 
138
                    w->addRepaintFull();
 
139
                    if (fadeout != w)
 
140
                        fadeout = w;
 
141
                }
 
142
            } else {
 
143
                // Fading back to more opaque
 
144
                if (w == fadeout && !w->isUserMove() && !w->isUserResize()) {
 
145
                    data.opacity *= (moveresize + ((1.0 - moveresize) * (progress)));
 
146
                    if (progress == 1.0 || progress == 0.0)
 
147
                        fadeout = NULL;
 
148
                    else
 
149
                        w->addRepaintFull();
 
150
 
 
151
                }
 
152
            }
 
153
        }
 
154
 
 
155
        // Menus and combos
 
156
        if (dropdownmenus != 1.0 && w->isDropdownMenu())
 
157
            data.opacity *= dropdownmenus;
 
158
        if (popupmenus != 1.0 && w->isPopupMenu())
 
159
            data.opacity *= popupmenus;
 
160
        if (tornoffmenus != 1.0 && w->isMenu())
 
161
            data.opacity *= tornoffmenus;
 
162
        if (comboboxpopups != 1.0 && w->isComboBox())
 
163
            data.opacity *= comboboxpopups;
 
164
 
 
165
    }
 
166
    effects->paintWindow(w, mask, region, data);
 
167
}
 
168
 
 
169
bool TranslucencyEffect::isInactive(const EffectWindow* w) const
 
170
{
 
171
    if (active == w || w->isDock() || !w->isManaged())
 
172
        return false;
 
173
    if (NULL != active && NULL != active->group())
 
174
        if (active->group() == w->group())
 
175
            return false;
 
176
    if (!w->isNormalWindow() && !w->isDialog() && !w->isDock())
 
177
        return false;
 
178
    return true;
 
179
}
 
180
 
 
181
void TranslucencyEffect::slotWindowStartStopUserMovedResized(EffectWindow* w)
 
182
{
 
183
    if (moveresize != 1.0) {
 
184
        moveresize_timeline.setCurrentTime(0);
 
185
        w->addRepaintFull();
 
186
    }
 
187
}
 
188
 
 
189
void TranslucencyEffect::slotWindowActivated(EffectWindow* w)
 
190
{
 
191
    if (inactive != 1.0) {
 
192
        activeinactive_timeline.setCurrentTime(0);
 
193
        if (NULL != active && active != w) {
 
194
            if ((NULL == w || w->group() != active->group()) &&
 
195
                    NULL != active->group()) {
 
196
                // Active group has changed. so repaint old group
 
197
                foreach (EffectWindow * tmp, active->group()->members())
 
198
                tmp->addRepaintFull();
 
199
            } else
 
200
                active->addRepaintFull();
 
201
        }
 
202
 
 
203
        if (NULL != w) {
 
204
            if (NULL != w->group()) {
 
205
                // Repaint windows in new group
 
206
                foreach (EffectWindow * tmp, w->group()->members())
 
207
                tmp->addRepaintFull();
 
208
            } else
 
209
                w->addRepaintFull();
 
210
        }
 
211
    }
 
212
    active = w;
 
213
}
 
214
 
 
215
} // namespace