2007-11-27 19:40:25 +00:00
|
|
|
/********************************************************************
|
2007-04-29 17:35:43 +00:00
|
|
|
KWin - the KDE window manager
|
|
|
|
This file is part of the KDE project.
|
|
|
|
|
|
|
|
Copyright (C) 2007 Lubos Lunak <l.lunak@kde.org>
|
|
|
|
|
2007-11-27 19:40:25 +00:00
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*********************************************************************/
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
#include "fallapart.h"
|
|
|
|
#include <assert.h>
|
|
|
|
#include <math.h>
|
2014-03-17 15:24:10 +00:00
|
|
|
#include <KConfigGroup>
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
namespace KWin
|
|
|
|
{
|
|
|
|
|
2013-06-22 14:09:14 +00:00
|
|
|
bool FallApartEffect::supported()
|
|
|
|
{
|
2016-08-10 07:24:53 +00:00
|
|
|
return effects->isOpenGLCompositing() && effects->animationsSupported();
|
2013-06-22 14:09:14 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2010-09-07 21:52:51 +00:00
|
|
|
FallApartEffect::FallApartEffect()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
reconfigure(ReconfigureAll);
|
2012-01-29 11:29:24 +00:00
|
|
|
connect(effects, SIGNAL(windowClosed(KWin::EffectWindow*)), this, SLOT(slotWindowClosed(KWin::EffectWindow*)));
|
|
|
|
connect(effects, SIGNAL(windowDeleted(KWin::EffectWindow*)), this, SLOT(slotWindowDeleted(KWin::EffectWindow*)));
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2010-09-07 21:52:51 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
void FallApartEffect::reconfigure(ReconfigureFlags)
|
|
|
|
{
|
2013-07-23 05:02:52 +00:00
|
|
|
KConfigGroup conf = effects->effectConfig(QStringLiteral("FallApart"));
|
2011-01-30 14:34:42 +00:00
|
|
|
blockSize = qBound(1, conf.readEntry("BlockSize", 40), 100000);
|
|
|
|
}
|
2010-09-07 21:52:51 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
void FallApartEffect::prePaintScreen(ScreenPrePaintData& data, int time)
|
|
|
|
{
|
|
|
|
if (!windows.isEmpty())
|
2007-07-07 14:01:32 +00:00
|
|
|
data.mask |= PAINT_SCREEN_WITH_TRANSFORMED_WINDOWS;
|
|
|
|
effects->prePaintScreen(data, time);
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
void FallApartEffect::prePaintWindow(EffectWindow* w, WindowPrePaintData& data, int time)
|
|
|
|
{
|
|
|
|
if (windows.contains(w) && isRealWindow(w)) {
|
|
|
|
if (windows[ w ] < 1) {
|
|
|
|
windows[ w ] += time / animationTime(1000.);
|
2007-07-19 14:05:59 +00:00
|
|
|
data.setTransformed();
|
2011-01-30 14:34:42 +00:00
|
|
|
w->enablePainting(EffectWindow::PAINT_DISABLED_BY_DELETE);
|
2007-04-29 17:35:43 +00:00
|
|
|
// Request the window to be divided into cells
|
2011-01-30 14:34:42 +00:00
|
|
|
data.quads = data.quads.makeGrid(blockSize);
|
|
|
|
} else {
|
|
|
|
windows.remove(w);
|
2007-04-29 17:35:43 +00:00
|
|
|
w->unrefWindow();
|
|
|
|
}
|
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
effects->prePaintWindow(w, data, time);
|
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
void FallApartEffect::paintWindow(EffectWindow* w, int mask, QRegion region, WindowPaintData& data)
|
|
|
|
{
|
|
|
|
if (windows.contains(w) && isRealWindow(w)) {
|
2007-07-07 14:01:32 +00:00
|
|
|
WindowQuadList new_quads;
|
|
|
|
int cnt = 0;
|
2011-01-30 14:34:42 +00:00
|
|
|
foreach (WindowQuad quad, data.quads) { // krazy:exclude=foreach
|
2007-04-29 17:35:43 +00:00
|
|
|
// make fragments move in various directions, based on where
|
|
|
|
// they are (left pieces generally move to the left, etc.)
|
2011-01-30 14:34:42 +00:00
|
|
|
QPointF p1(quad[ 0 ].x(), quad[ 0 ].y());
|
2007-09-03 15:00:43 +00:00
|
|
|
double xdiff = 0;
|
2011-01-30 14:34:42 +00:00
|
|
|
if (p1.x() < w->width() / 2)
|
|
|
|
xdiff = -(w->width() / 2 - p1.x()) / w->width() * 100;
|
|
|
|
if (p1.x() > w->width() / 2)
|
|
|
|
xdiff = (p1.x() - w->width() / 2) / w->width() * 100;
|
2007-09-03 15:00:43 +00:00
|
|
|
double ydiff = 0;
|
2011-01-30 14:34:42 +00:00
|
|
|
if (p1.y() < w->height() / 2)
|
|
|
|
ydiff = -(w->height() / 2 - p1.y()) / w->height() * 100;
|
|
|
|
if (p1.y() > w->height() / 2)
|
|
|
|
ydiff = (p1.y() - w->height() / 2) / w->height() * 100;
|
2007-09-03 15:00:43 +00:00
|
|
|
double modif = windows[ w ] * windows[ w ] * 64;
|
2011-01-30 14:34:42 +00:00
|
|
|
srandom(cnt); // change direction randomly but consistently
|
|
|
|
xdiff += (rand() % 21 - 10);
|
|
|
|
ydiff += (rand() % 21 - 10);
|
|
|
|
for (int j = 0;
|
|
|
|
j < 4;
|
|
|
|
++j) {
|
|
|
|
quad[ j ].move(quad[ j ].x() + xdiff * modif, quad[ j ].y() + ydiff * modif);
|
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
// also make the fragments rotate around their center
|
2011-01-30 14:34:42 +00:00
|
|
|
QPointF center((quad[ 0 ].x() + quad[ 1 ].x() + quad[ 2 ].x() + quad[ 3 ].x()) / 4,
|
|
|
|
(quad[ 0 ].y() + quad[ 1 ].y() + quad[ 2 ].y() + quad[ 3 ].y()) / 4);
|
|
|
|
double adiff = (rand() % 720 - 360) / 360. * 2 * M_PI; // spin randomly
|
|
|
|
for (int j = 0;
|
|
|
|
j < 4;
|
|
|
|
++j) {
|
2007-09-03 15:00:43 +00:00
|
|
|
double x = quad[ j ].x() - center.x();
|
|
|
|
double y = quad[ j ].y() - center.y();
|
2011-01-30 14:34:42 +00:00
|
|
|
double angle = atan2(y, x);
|
2007-04-29 17:35:43 +00:00
|
|
|
angle += windows[ w ] * adiff;
|
2011-01-30 14:34:42 +00:00
|
|
|
double dist = sqrt(x * x + y * y);
|
|
|
|
x = dist * cos(angle);
|
|
|
|
y = dist * sin(angle);
|
|
|
|
quad[ j ].move(center.x() + x, center.y() + y);
|
2007-04-29 17:35:43 +00:00
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
new_quads.append(quad);
|
|
|
|
++cnt;
|
2007-04-29 17:35:43 +00:00
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
data.quads = new_quads;
|
2007-04-29 17:35:43 +00:00
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
effects->paintWindow(w, mask, region, data);
|
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
void FallApartEffect::postPaintScreen()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
if (!windows.isEmpty())
|
2007-04-29 17:35:43 +00:00
|
|
|
effects->addRepaintFull();
|
|
|
|
effects->postPaintScreen();
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
bool FallApartEffect::isRealWindow(EffectWindow* w)
|
|
|
|
{
|
2008-06-30 12:52:06 +00:00
|
|
|
// TODO: isSpecialWindow is rather generic, maybe tell windowtypes separately?
|
|
|
|
/*
|
2013-11-29 05:18:28 +00:00
|
|
|
qCDebug(KWINEFFECTS) << "--" << w->caption() << "--------------------------------";
|
|
|
|
qCDebug(KWINEFFECTS) << "Tooltip:" << w->isTooltip();
|
|
|
|
qCDebug(KWINEFFECTS) << "Toolbar:" << w->isToolbar();
|
|
|
|
qCDebug(KWINEFFECTS) << "Desktop:" << w->isDesktop();
|
|
|
|
qCDebug(KWINEFFECTS) << "Special:" << w->isSpecialWindow();
|
|
|
|
qCDebug(KWINEFFECTS) << "TopMenu:" << w->isTopMenu();
|
|
|
|
qCDebug(KWINEFFECTS) << "Notific:" << w->isNotification();
|
|
|
|
qCDebug(KWINEFFECTS) << "Splash:" << w->isSplash();
|
|
|
|
qCDebug(KWINEFFECTS) << "Normal:" << w->isNormalWindow();
|
2008-06-30 12:52:06 +00:00
|
|
|
*/
|
2011-01-30 14:34:42 +00:00
|
|
|
if (!w->isNormalWindow())
|
2008-06-30 12:52:06 +00:00
|
|
|
return false;
|
|
|
|
return true;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2008-06-30 12:52:06 +00:00
|
|
|
|
2011-02-27 08:25:45 +00:00
|
|
|
void FallApartEffect::slotWindowClosed(EffectWindow* c)
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
if (!isRealWindow(c))
|
2008-06-30 12:52:06 +00:00
|
|
|
return;
|
2013-01-11 09:06:14 +00:00
|
|
|
if (!c->isVisible())
|
2012-11-24 14:42:35 +00:00
|
|
|
return;
|
2011-01-30 14:34:42 +00:00
|
|
|
const void* e = c->data(WindowClosedGrabRole).value<void*>();
|
|
|
|
if (e && e != this)
|
2010-01-11 04:52:19 +00:00
|
|
|
return;
|
2007-04-29 17:35:43 +00:00
|
|
|
windows[ c ] = 0;
|
|
|
|
c->refWindow();
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2011-02-27 09:47:42 +00:00
|
|
|
void FallApartEffect::slotWindowDeleted(EffectWindow* c)
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
windows.remove(c);
|
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2011-08-27 09:21:31 +00:00
|
|
|
bool FallApartEffect::isActive() const
|
|
|
|
{
|
|
|
|
return !windows.isEmpty();
|
|
|
|
}
|
|
|
|
|
2007-04-29 17:35:43 +00:00
|
|
|
} // namespace
|