1
/********************************************************************
2
KWin - the KDE window manager
3
This file is part of the KDE project.
5
Copyright (C) 2006 Lubos Lunak <l.lunak@kde.org>
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.
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.
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
*********************************************************************/
21
#include "translucency.h"
23
#include <kconfiggroup.h>
28
KWIN_EFFECT(translucency, TranslucencyEffect)
30
TranslucencyEffect::TranslucencyEffect()
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*)));
42
void TranslucencyEffect::reconfigure(ReconfigureFlags)
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);
57
dropdownmenus = menus;
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));
66
// Repaint the screen just in case the user changed the inactive opacity
67
effects->addRepaintFull();
70
void TranslucencyEffect::prePaintWindow(EffectWindow* w, WindowPrePaintData& data, int time)
72
moveresize_timeline.setCurrentTime(moveresize_timeline.currentTime() + time);
73
activeinactive_timeline.setCurrentTime(activeinactive_timeline.currentTime() + time);
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
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();
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();
93
effects->prePaintWindow(w, data, time);
96
void TranslucencyEffect::paintWindow(EffectWindow* w, int mask, QRegion region, WindowPaintData& data)
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) {
105
if (w->isDesktop() || w->isDock()) {
106
effects->paintWindow(w, mask, region, data);
109
// Handling active and inactive windows
110
if (inactive != 1.0 && isInactive(w)) {
111
data.opacity *= inactive;
114
data.opacity *= (inactive + ((1.0 - inactive) * (1.0 - activeinactive_timeline.currentValue())));
115
if (activeinactive_timeline.currentValue() < 1.0)
120
if (!isInactive(w) && !w->isDesktop()) {
121
data.opacity *= (inactive + ((1.0 - inactive) * activeinactive_timeline.currentValue()));
122
if (activeinactive_timeline.currentValue() < 1.0)
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;
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) {
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)
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;
166
effects->paintWindow(w, mask, region, data);
169
bool TranslucencyEffect::isInactive(const EffectWindow* w) const
171
if (active == w || w->isDock() || !w->isManaged())
173
if (NULL != active && NULL != active->group())
174
if (active->group() == w->group())
176
if (!w->isNormalWindow() && !w->isDialog() && !w->isDock())
181
void TranslucencyEffect::slotWindowStartStopUserMovedResized(EffectWindow* w)
183
if (moveresize != 1.0) {
184
moveresize_timeline.setCurrentTime(0);
189
void TranslucencyEffect::slotWindowActivated(EffectWindow* w)
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();
200
active->addRepaintFull();
204
if (NULL != w->group()) {
205
// Repaint windows in new group
206
foreach (EffectWindow * tmp, w->group()->members())
207
tmp->addRepaintFull();