1
/********************************************************************
2
KWin - the KDE window manager
3
This file is part of the KDE project.
5
Copyright (C) 2007 Philip Falkner <philip.falkner@gmail.com>
6
Copyright (C) 2009 Martin Gräßlin <kde@martin-graesslin.com>
8
This program is free software; you can redistribute it and/or modify
9
it under the terms of the GNU General Public License as published by
10
the Free Software Foundation; either version 2 of the License, or
11
(at your option) any later version.
13
This program is distributed in the hope that it will be useful,
14
but WITHOUT ANY WARRANTY; without even the implied warranty of
15
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
GNU General Public License for more details.
18
You should have received a copy of the GNU General Public License
19
along with this program. If not, see <http://www.gnu.org/licenses/>.
20
*********************************************************************/
24
#include <kconfiggroup.h>
25
#include <QtCore/QTimeLine>
27
// Effect is based on fade effect by Philip Falkner
32
KWIN_EFFECT(sheet, SheetEffect)
33
KWIN_EFFECT_SUPPORTED(sheet, SheetEffect::supported())
35
static const int IsSheetWindow = 0x22A982D5;
37
SheetEffect::SheetEffect()
39
reconfigure(ReconfigureAll);
40
connect(effects, SIGNAL(windowAdded(EffectWindow*)), this, SLOT(slotWindowAdded(EffectWindow*)));
41
connect(effects, SIGNAL(windowClosed(EffectWindow*)), this, SLOT(slotWindowClosed(EffectWindow*)));
42
connect(effects, SIGNAL(windowDeleted(EffectWindow*)), this, SLOT(slotWindowDeleted(EffectWindow*)));
45
bool SheetEffect::supported()
47
return effects->compositingType() == OpenGLCompositing;
50
void SheetEffect::reconfigure(ReconfigureFlags)
52
KConfigGroup conf = effects->effectConfig("Sheet");
53
duration = animationTime(conf, "AnimationTime", 500);
56
void SheetEffect::prePaintScreen(ScreenPrePaintData& data, int time)
58
if (!windows.isEmpty()) {
59
data.mask |= PAINT_SCREEN_WITH_TRANSFORMED_WINDOWS;
62
effects->prePaintScreen(data, time);
65
void SheetEffect::prePaintWindow(EffectWindow* w, WindowPrePaintData& data, int time)
67
InfoMap::iterator info = windows.find(w);
68
if (info != windows.end()) {
69
data.setTransformed();
71
info->timeLine->setCurrentTime(info->timeLine->currentTime() + screenTime);
72
else if (info->closed) {
73
info->timeLine->setCurrentTime(info->timeLine->currentTime() - screenTime);
75
w->enablePainting(EffectWindow::PAINT_DISABLED_BY_DELETE);
79
effects->prePaintWindow(w, data, time);
81
// if the window isn't to be painted, then let's make sure
82
// to track its progress
83
if (info != windows.end() && !w->isPaintingEnabled() && !effects->activeFullScreenEffect())
87
void SheetEffect::paintWindow(EffectWindow* w, int mask, QRegion region, WindowPaintData& data)
89
InfoMap::const_iterator info = windows.constFind(w);
90
if (info != windows.constEnd()) {
91
const double progress = info->timeLine->currentValue();
93
rot.axis = RotationData::XAxis;
94
rot.angle = 60.0 * (1.0 - progress);
96
data.yScale *= progress;
97
data.zScale *= progress;
98
data.yTranslate -= (w->y() - info->parentY) * (1.0 - progress);
100
effects->paintWindow(w, mask, region, data);
103
void SheetEffect::postPaintWindow(EffectWindow* w)
105
InfoMap::iterator info = windows.find(w);
106
if (info != windows.end()) {
107
if (info->added && info->timeLine->currentValue() == 1.0) {
109
effects->addRepaintFull();
110
} else if (info->closed && info->timeLine->currentValue() == 0.0) {
111
info->closed = false;
116
effects->addRepaintFull();
118
if (info->added || info->closed)
121
effects->postPaintWindow(w);
124
void SheetEffect::slotWindowAdded(EffectWindow* w)
126
if (!isSheetWindow(w))
128
w->setData(IsSheetWindow, true);
130
InfoMap::iterator it = windows.find(w);
131
WindowInfo *info = (it == windows.end()) ? &windows[w] : &it.value();
133
info->closed = false;
134
info->deleted = false;
135
delete info->timeLine;
136
info->timeLine = new QTimeLine(duration);
137
const EffectWindowList stack = effects->stackingOrder();
139
foreach (EffectWindow * window, stack) {
140
if (window->findModal() == w) {
141
info->parentY = window->y();
148
void SheetEffect::slotWindowClosed(EffectWindow* w)
150
if (!isSheetWindow(w))
155
InfoMap::iterator it = windows.find(w);
156
WindowInfo *info = (it == windows.end()) ? &windows[w] : &it.value();
159
info->deleted = true;
160
delete info->timeLine;
161
info->timeLine = new QTimeLine(duration);
162
info->timeLine->setCurrentTime(duration);
166
const EffectWindowList stack = effects->stackingOrder();
167
foreach (EffectWindow * window, stack) {
168
if (window->findModal() == w) {
169
info->parentY = window->y();
179
void SheetEffect::slotWindowDeleted(EffectWindow* w)
184
bool SheetEffect::isSheetWindow(EffectWindow* w)
186
return (w->isModal() || w->data(IsSheetWindow).toBool());
189
SheetEffect::WindowInfo::WindowInfo()
198
SheetEffect::WindowInfo::~WindowInfo()