2008-04-18 12:01:47 +00:00
|
|
|
/*****************************************************************
|
|
|
|
KWin - the KDE window manager
|
|
|
|
This file is part of the KDE project.
|
|
|
|
|
|
|
|
Copyright (C) 2008 Cédric Borgese <cedric.borgese@gmail.com>
|
|
|
|
|
|
|
|
You can Freely distribute this program under the GNU General Public
|
|
|
|
License. See the file "COPYING" for the exact licensing terms.
|
|
|
|
******************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
#include "wobblywindows.h"
|
2012-09-12 17:26:59 +00:00
|
|
|
#include "wobblywindowsconfig.h"
|
2008-04-18 12:01:47 +00:00
|
|
|
|
2019-07-09 19:19:26 +00:00
|
|
|
#include <cmath>
|
2008-04-18 12:01:47 +00:00
|
|
|
|
|
|
|
//#define COMPUTE_STATS
|
|
|
|
|
|
|
|
// if you enable it and run kwin in a terminal from the session it manages,
|
|
|
|
// be sure to redirect the output of kwin in a file or
|
|
|
|
// you'll propably get deadlocks.
|
|
|
|
//#define VERBOSE_MODE
|
|
|
|
|
|
|
|
#if defined COMPUTE_STATS && !defined VERBOSE_MODE
|
|
|
|
# ifdef __GNUC__
|
|
|
|
# warning "You enable COMPUTE_STATS without VERBOSE_MODE, computed stats will not be printed."
|
|
|
|
# endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
namespace KWin
|
|
|
|
{
|
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
struct ParameterSet {
|
2008-04-24 21:22:52 +00:00
|
|
|
qreal stiffness;
|
|
|
|
qreal drag;
|
|
|
|
qreal move_factor;
|
|
|
|
|
|
|
|
qreal xTesselation;
|
|
|
|
qreal yTesselation;
|
|
|
|
|
|
|
|
qreal minVelocity;
|
|
|
|
qreal maxVelocity;
|
|
|
|
qreal stopVelocity;
|
|
|
|
qreal minAcceleration;
|
|
|
|
qreal maxAcceleration;
|
|
|
|
qreal stopAcceleration;
|
|
|
|
|
|
|
|
bool moveEffectEnabled;
|
|
|
|
bool openEffectEnabled;
|
|
|
|
bool closeEffectEnabled;
|
|
|
|
};
|
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
static const ParameterSet set_0 = {
|
2008-09-26 05:27:57 +00:00
|
|
|
0.15,
|
|
|
|
0.80,
|
|
|
|
0.10,
|
2008-04-24 21:22:52 +00:00
|
|
|
20.0,
|
|
|
|
20.0,
|
|
|
|
0.0,
|
|
|
|
1000.0,
|
2008-05-20 21:52:11 +00:00
|
|
|
0.5,
|
2008-04-24 21:22:52 +00:00
|
|
|
0.0,
|
|
|
|
1000.0,
|
2008-05-20 21:52:11 +00:00
|
|
|
0.5,
|
2008-04-24 21:22:52 +00:00
|
|
|
true,
|
|
|
|
false,
|
|
|
|
false
|
|
|
|
};
|
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
static const ParameterSet set_1 = {
|
2008-09-26 05:27:57 +00:00
|
|
|
0.10,
|
2008-04-24 21:22:52 +00:00
|
|
|
0.85,
|
2008-09-26 05:27:57 +00:00
|
|
|
0.10,
|
2008-04-24 21:22:52 +00:00
|
|
|
20.0,
|
|
|
|
20.0,
|
|
|
|
0.0,
|
|
|
|
1000.0,
|
2008-05-20 21:52:11 +00:00
|
|
|
0.5,
|
2008-04-24 21:22:52 +00:00
|
|
|
0.0,
|
|
|
|
1000.0,
|
2008-05-20 21:52:11 +00:00
|
|
|
0.5,
|
2008-04-24 21:22:52 +00:00
|
|
|
true,
|
|
|
|
false,
|
|
|
|
false
|
|
|
|
};
|
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
static const ParameterSet set_2 = {
|
2008-04-24 21:22:52 +00:00
|
|
|
0.06,
|
2008-09-26 05:27:57 +00:00
|
|
|
0.90,
|
|
|
|
0.10,
|
2008-04-24 21:22:52 +00:00
|
|
|
20.0,
|
|
|
|
20.0,
|
|
|
|
0.0,
|
|
|
|
1000.0,
|
2008-05-20 21:52:11 +00:00
|
|
|
0.5,
|
2008-04-24 21:22:52 +00:00
|
|
|
0.0,
|
|
|
|
1000.0,
|
2008-05-20 21:52:11 +00:00
|
|
|
0.5,
|
2008-04-24 21:22:52 +00:00
|
|
|
true,
|
|
|
|
false,
|
|
|
|
false
|
|
|
|
};
|
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
static const ParameterSet set_3 = {
|
2008-04-24 21:22:52 +00:00
|
|
|
0.03,
|
|
|
|
0.92,
|
2008-09-26 05:27:57 +00:00
|
|
|
0.20,
|
2008-04-24 21:22:52 +00:00
|
|
|
20.0,
|
|
|
|
20.0,
|
|
|
|
0.0,
|
|
|
|
1000.0,
|
2008-05-20 21:52:11 +00:00
|
|
|
0.5,
|
2008-04-24 21:22:52 +00:00
|
|
|
0.0,
|
|
|
|
1000.0,
|
2008-05-20 21:52:11 +00:00
|
|
|
0.5,
|
2008-04-24 21:22:52 +00:00
|
|
|
true,
|
|
|
|
false,
|
|
|
|
false
|
|
|
|
};
|
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
static const ParameterSet set_4 = {
|
2008-05-20 21:52:11 +00:00
|
|
|
0.01,
|
|
|
|
0.97,
|
|
|
|
0.25,
|
2008-04-24 21:22:52 +00:00
|
|
|
20.0,
|
|
|
|
20.0,
|
|
|
|
0.0,
|
|
|
|
1000.0,
|
2008-05-20 21:52:11 +00:00
|
|
|
0.5,
|
2008-04-24 21:22:52 +00:00
|
|
|
0.0,
|
|
|
|
1000.0,
|
2008-05-20 21:52:11 +00:00
|
|
|
0.5,
|
2008-04-24 21:22:52 +00:00
|
|
|
true,
|
|
|
|
false,
|
|
|
|
false
|
|
|
|
};
|
|
|
|
|
2008-10-02 08:13:25 +00:00
|
|
|
static const ParameterSet pset[5] = { set_0, set_1, set_2, set_3, set_4 };
|
2008-04-24 21:22:52 +00:00
|
|
|
|
2008-04-18 12:01:47 +00:00
|
|
|
WobblyWindowsEffect::WobblyWindowsEffect()
|
2008-10-02 09:27:32 +00:00
|
|
|
{
|
2016-12-02 19:27:43 +00:00
|
|
|
initConfig<WobblyWindowsConfig>();
|
2011-01-30 14:34:42 +00:00
|
|
|
reconfigure(ReconfigureAll);
|
2019-01-01 20:48:53 +00:00
|
|
|
connect(effects, &EffectsHandler::windowAdded, this, &WobblyWindowsEffect::slotWindowAdded);
|
|
|
|
connect(effects, &EffectsHandler::windowClosed, this, &WobblyWindowsEffect::slotWindowClosed);
|
|
|
|
connect(effects, &EffectsHandler::windowStartUserMovedResized, this, &WobblyWindowsEffect::slotWindowStartUserMovedResized);
|
|
|
|
connect(effects, &EffectsHandler::windowStepUserMovedResized, this, &WobblyWindowsEffect::slotWindowStepUserMovedResized);
|
|
|
|
connect(effects, &EffectsHandler::windowFinishUserMovedResized, this, &WobblyWindowsEffect::slotWindowFinishUserMovedResized);
|
|
|
|
connect(effects, &EffectsHandler::windowMaximizedStateChanged, this, &WobblyWindowsEffect::slotWindowMaximizeStateChanged);
|
2016-10-31 10:22:24 +00:00
|
|
|
connect(effects, &EffectsHandler::windowDataChanged, this, &WobblyWindowsEffect::cancelWindowGrab);
|
2008-10-02 09:27:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
WobblyWindowsEffect::~WobblyWindowsEffect()
|
|
|
|
{
|
2011-01-30 14:34:42 +00:00
|
|
|
if (!windows.empty()) {
|
2008-10-02 09:27:32 +00:00
|
|
|
// we should be empty at this point...
|
|
|
|
// emit a warning and clean the list.
|
2013-11-29 05:18:28 +00:00
|
|
|
qCDebug(KWINEFFECTS) << "Windows list not empty. Left items : " << windows.count();
|
2008-10-02 09:27:32 +00:00
|
|
|
QHash< const EffectWindow*, WindowWobblyInfos >::iterator i;
|
2011-01-30 14:34:42 +00:00
|
|
|
for (i = windows.begin(); i != windows.end(); ++i) {
|
2008-10-02 09:27:32 +00:00
|
|
|
freeWobblyInfo(i.value());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
void WobblyWindowsEffect::reconfigure(ReconfigureFlags)
|
2008-04-18 12:01:47 +00:00
|
|
|
{
|
2014-03-25 15:29:03 +00:00
|
|
|
WobblyWindowsConfig::self()->read();
|
2008-04-18 12:01:47 +00:00
|
|
|
|
2012-09-12 17:26:59 +00:00
|
|
|
QString settingsMode = WobblyWindowsConfig::settings();
|
2013-07-23 05:02:52 +00:00
|
|
|
if (settingsMode != QStringLiteral("Custom")) {
|
2012-09-12 17:26:59 +00:00
|
|
|
unsigned int wobblynessLevel = WobblyWindowsConfig::wobblynessLevel();
|
2011-01-30 14:34:42 +00:00
|
|
|
if (wobblynessLevel > 4) {
|
2013-11-29 05:18:28 +00:00
|
|
|
qCDebug(KWINEFFECTS) << "Wrong value for \"WobblynessLevel\" : " << wobblynessLevel;
|
2008-04-24 21:22:52 +00:00
|
|
|
wobblynessLevel = 4;
|
|
|
|
}
|
|
|
|
setParameterSet(pset[wobblynessLevel]);
|
2011-01-30 14:34:42 +00:00
|
|
|
|
2012-09-12 17:26:59 +00:00
|
|
|
if (WobblyWindowsConfig::advancedMode()) {
|
|
|
|
m_stiffness = WobblyWindowsConfig::stiffness() / 100.0;
|
|
|
|
m_drag = WobblyWindowsConfig::drag() / 100.0;
|
|
|
|
m_move_factor = WobblyWindowsConfig::moveFactor() / 100.0;
|
2008-09-06 14:50:02 +00:00
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
} else { // Custom method, read all values from config file.
|
2012-09-12 17:26:59 +00:00
|
|
|
m_stiffness = WobblyWindowsConfig::stiffness() / 100.0;
|
|
|
|
m_drag = WobblyWindowsConfig::drag() / 100.0;
|
|
|
|
m_move_factor = WobblyWindowsConfig::moveFactor() / 100.0;
|
|
|
|
|
|
|
|
m_xTesselation = WobblyWindowsConfig::xTesselation();
|
|
|
|
m_yTesselation = WobblyWindowsConfig::yTesselation();
|
|
|
|
|
|
|
|
m_minVelocity = WobblyWindowsConfig::minVelocity();
|
|
|
|
m_maxVelocity = WobblyWindowsConfig::maxVelocity();
|
|
|
|
m_stopVelocity = WobblyWindowsConfig::stopVelocity();
|
|
|
|
m_minAcceleration = WobblyWindowsConfig::minAcceleration();
|
|
|
|
m_maxAcceleration = WobblyWindowsConfig::maxAcceleration();
|
|
|
|
m_stopAcceleration = WobblyWindowsConfig::stopAcceleration();
|
|
|
|
|
|
|
|
m_moveEffectEnabled = WobblyWindowsConfig::moveEffect();
|
|
|
|
m_openEffectEnabled = WobblyWindowsConfig::openEffect();
|
2008-04-24 21:22:52 +00:00
|
|
|
// disable close effect by default for now as it doesn't do what I want.
|
2012-09-12 17:26:59 +00:00
|
|
|
m_closeEffectEnabled = WobblyWindowsConfig::closeEffect();
|
2008-04-24 21:22:52 +00:00
|
|
|
}
|
2008-04-18 19:04:00 +00:00
|
|
|
|
2012-09-12 17:26:59 +00:00
|
|
|
m_moveWobble = WobblyWindowsConfig::moveWobble();
|
|
|
|
m_resizeWobble = WobblyWindowsConfig::resizeWobble();
|
2008-09-04 15:09:22 +00:00
|
|
|
|
2008-04-18 12:01:47 +00:00
|
|
|
#if defined VERBOSE_MODE
|
2013-11-29 05:18:28 +00:00
|
|
|
qCDebug(KWINEFFECTS) << "Parameters :\n" <<
|
2011-01-30 14:34:42 +00:00
|
|
|
"move : " << m_moveEffectEnabled << ", open : " << m_openEffectEnabled << ", close : " << m_closeEffectEnabled << "\n"
|
|
|
|
"grid(" << m_stiffness << ", " << m_drag << ", " << m_move_factor << ")\n" <<
|
|
|
|
"velocity(" << m_minVelocity << ", " << m_maxVelocity << ", " << m_stopVelocity << ")\n" <<
|
|
|
|
"acceleration(" << m_minAcceleration << ", " << m_maxAcceleration << ", " << m_stopAcceleration << ")\n" <<
|
|
|
|
"tesselation(" << m_xTesselation << ", " << m_yTesselation << ")";
|
2008-04-18 12:01:47 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2009-02-15 10:34:46 +00:00
|
|
|
bool WobblyWindowsEffect::supported()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2016-08-10 07:24:53 +00:00
|
|
|
return effects->isOpenGLCompositing() && effects->animationsSupported();
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2008-04-18 13:06:29 +00:00
|
|
|
|
2008-10-02 08:13:25 +00:00
|
|
|
void WobblyWindowsEffect::setParameterSet(const ParameterSet& pset)
|
2008-04-24 21:22:52 +00:00
|
|
|
{
|
|
|
|
m_stiffness = pset.stiffness;
|
|
|
|
m_drag = pset.drag;
|
|
|
|
m_move_factor = pset.move_factor;
|
|
|
|
|
|
|
|
m_xTesselation = pset.xTesselation;
|
|
|
|
m_yTesselation = pset.yTesselation;
|
|
|
|
|
|
|
|
m_minVelocity = pset.minVelocity;
|
|
|
|
m_maxVelocity = pset.maxVelocity;
|
|
|
|
m_stopVelocity = pset.stopVelocity;
|
|
|
|
m_minAcceleration = pset.minAcceleration;
|
|
|
|
m_maxAcceleration = pset.maxAcceleration;
|
|
|
|
m_stopAcceleration = pset.stopAcceleration;
|
|
|
|
|
|
|
|
m_moveEffectEnabled = pset.moveEffectEnabled;
|
|
|
|
m_openEffectEnabled = pset.openEffectEnabled;
|
|
|
|
m_closeEffectEnabled = pset.closeEffectEnabled;
|
|
|
|
}
|
|
|
|
|
2008-04-18 12:01:47 +00:00
|
|
|
void WobblyWindowsEffect::setVelocityThreshold(qreal m_minVelocity)
|
|
|
|
{
|
|
|
|
this->m_minVelocity = m_minVelocity;
|
|
|
|
}
|
|
|
|
|
|
|
|
void WobblyWindowsEffect::setMoveFactor(qreal factor)
|
|
|
|
{
|
|
|
|
m_move_factor = factor;
|
|
|
|
}
|
|
|
|
|
2008-04-20 12:29:20 +00:00
|
|
|
void WobblyWindowsEffect::setStiffness(qreal stiffness)
|
2008-04-18 12:01:47 +00:00
|
|
|
{
|
2008-04-20 12:29:20 +00:00
|
|
|
m_stiffness = stiffness;
|
2008-04-18 12:01:47 +00:00
|
|
|
}
|
|
|
|
|
2008-04-20 12:29:20 +00:00
|
|
|
void WobblyWindowsEffect::setDrag(qreal drag)
|
2008-04-18 12:01:47 +00:00
|
|
|
{
|
2008-04-20 12:29:20 +00:00
|
|
|
m_drag = drag;
|
2008-04-18 12:01:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void WobblyWindowsEffect::prePaintScreen(ScreenPrePaintData& data, int time)
|
|
|
|
{
|
|
|
|
// We need to mark the screen windows as transformed. Otherwise the whole
|
|
|
|
// screen won't be repainted, resulting in artefacts.
|
|
|
|
// Could we just set a subset of the screen to be repainted ?
|
2011-01-30 14:34:42 +00:00
|
|
|
if (windows.count() != 0) {
|
2010-08-04 18:19:01 +00:00
|
|
|
m_updateRegion = QRegion();
|
|
|
|
}
|
2008-04-18 12:01:47 +00:00
|
|
|
|
|
|
|
effects->prePaintScreen(data, time);
|
|
|
|
}
|
|
|
|
const qreal maxTime = 10.0;
|
|
|
|
void WobblyWindowsEffect::prePaintWindow(EffectWindow* w, WindowPrePaintData& data, int time)
|
|
|
|
{
|
2011-01-30 14:34:42 +00:00
|
|
|
if (windows.contains(w)) {
|
2008-04-18 12:01:47 +00:00
|
|
|
data.setTransformed();
|
|
|
|
data.quads = data.quads.makeRegularGrid(m_xTesselation, m_yTesselation);
|
|
|
|
bool stop = false;
|
|
|
|
qreal updateTime = time;
|
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
while (!stop && (updateTime > maxTime)) {
|
2008-04-18 12:01:47 +00:00
|
|
|
#if defined VERBOSE_MODE
|
2013-11-29 05:18:28 +00:00
|
|
|
qCDebug(KWINEFFECTS) << "loop time " << updateTime << " / " << time;
|
2008-04-18 12:01:47 +00:00
|
|
|
#endif
|
|
|
|
stop = !updateWindowWobblyDatas(w, maxTime);
|
|
|
|
updateTime -= maxTime;
|
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
if (!stop && updateTime > 0) {
|
2008-04-18 12:01:47 +00:00
|
|
|
updateWindowWobblyDatas(w, updateTime);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
effects->prePaintWindow(w, data, time);
|
|
|
|
}
|
|
|
|
|
|
|
|
void WobblyWindowsEffect::paintWindow(EffectWindow* w, int mask, QRegion region, WindowPaintData& data)
|
|
|
|
{
|
2015-05-12 19:23:56 +00:00
|
|
|
if (!(mask & PAINT_SCREEN_TRANSFORMED) && windows.contains(w)) {
|
2008-04-18 12:01:47 +00:00
|
|
|
WindowWobblyInfos& wwi = windows[w];
|
|
|
|
int tx = w->geometry().x();
|
|
|
|
int ty = w->geometry().y();
|
2010-08-04 18:19:01 +00:00
|
|
|
double left = 0.0;
|
|
|
|
double top = 0.0;
|
|
|
|
double right = w->width();
|
|
|
|
double bottom = w->height();
|
2011-01-30 14:34:42 +00:00
|
|
|
for (int i = 0; i < data.quads.count(); ++i) {
|
|
|
|
for (int j = 0; j < 4; ++j) {
|
2008-04-18 12:01:47 +00:00
|
|
|
WindowVertex& v = data.quads[i][j];
|
|
|
|
Pair oldPos = {tx + v.x(), ty + v.y()};
|
|
|
|
Pair newPos = computeBezierPoint(wwi, oldPos);
|
|
|
|
v.move(newPos.x - tx, newPos.y - ty);
|
|
|
|
}
|
2010-08-04 18:19:01 +00:00
|
|
|
left = qMin(left, data.quads[i].left());
|
|
|
|
top = qMin(top, data.quads[i].top());
|
|
|
|
right = qMax(right, data.quads[i].right());
|
|
|
|
bottom = qMax(bottom, data.quads[i].bottom());
|
2008-04-18 12:01:47 +00:00
|
|
|
}
|
2018-10-05 07:19:57 +00:00
|
|
|
QRectF dirtyRect(
|
|
|
|
left * data.xScale() + w->x() + data.xTranslation(),
|
|
|
|
top * data.yScale() + w->y() + data.yTranslation(),
|
|
|
|
(right - left + 1.0) * data.xScale(),
|
|
|
|
(bottom - top + 1.0) * data.yScale());
|
|
|
|
// Expand the dirty region by 1px to fix potential round/floor issues.
|
|
|
|
dirtyRect.adjust(-1.0, -1.0, 1.0, 1.0);
|
|
|
|
m_updateRegion = m_updateRegion.united(dirtyRect.toRect());
|
2008-04-18 12:01:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Call the next effect.
|
|
|
|
effects->paintWindow(w, mask, region, data);
|
|
|
|
}
|
|
|
|
|
|
|
|
void WobblyWindowsEffect::postPaintScreen()
|
|
|
|
{
|
2011-01-30 14:34:42 +00:00
|
|
|
if (!windows.isEmpty()) {
|
2008-04-18 12:01:47 +00:00
|
|
|
effects->addRepaint(m_updateRegion);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Call the next effect.
|
|
|
|
effects->postPaintScreen();
|
|
|
|
}
|
|
|
|
|
2011-03-13 11:41:30 +00:00
|
|
|
void WobblyWindowsEffect::slotWindowStartUserMovedResized(EffectWindow *w)
|
2008-04-18 12:01:47 +00:00
|
|
|
{
|
2009-03-02 20:18:35 +00:00
|
|
|
if (!m_moveEffectEnabled || w->isSpecialWindow())
|
|
|
|
return;
|
2008-04-18 12:01:47 +00:00
|
|
|
|
2011-03-13 11:41:30 +00:00
|
|
|
if ((w->isUserMove() && m_moveWobble) || (w->isUserResize() && m_resizeWobble)) {
|
|
|
|
startMovedResized(w);
|
2008-04-18 12:01:47 +00:00
|
|
|
}
|
2011-03-13 11:41:30 +00:00
|
|
|
}
|
2009-03-02 20:18:35 +00:00
|
|
|
|
2011-03-13 11:41:30 +00:00
|
|
|
void WobblyWindowsEffect::slotWindowStepUserMovedResized(EffectWindow *w, const QRect &geometry)
|
|
|
|
{
|
2012-05-24 09:15:24 +00:00
|
|
|
Q_UNUSED(geometry)
|
2011-03-13 11:41:30 +00:00
|
|
|
if (windows.contains(w)) {
|
|
|
|
WindowWobblyInfos& wwi = windows[w];
|
|
|
|
QRect rect = w->geometry();
|
|
|
|
if (rect.y() != wwi.resize_original_rect.y()) wwi.can_wobble_top = true;
|
|
|
|
if (rect.x() != wwi.resize_original_rect.x()) wwi.can_wobble_left = true;
|
|
|
|
if (rect.right() != wwi.resize_original_rect.right()) wwi.can_wobble_right = true;
|
|
|
|
if (rect.bottom() != wwi.resize_original_rect.bottom()) wwi.can_wobble_bottom = true;
|
2008-04-18 12:01:47 +00:00
|
|
|
}
|
2011-03-13 11:41:30 +00:00
|
|
|
}
|
2009-02-14 22:42:09 +00:00
|
|
|
|
2011-03-13 11:41:30 +00:00
|
|
|
void WobblyWindowsEffect::slotWindowFinishUserMovedResized(EffectWindow *w)
|
|
|
|
{
|
2011-01-30 14:34:42 +00:00
|
|
|
if (windows.contains(w)) {
|
2009-02-14 22:42:09 +00:00
|
|
|
WindowWobblyInfos& wwi = windows[w];
|
2011-03-13 11:41:30 +00:00
|
|
|
wwi.status = Free;
|
2009-02-14 22:42:09 +00:00
|
|
|
QRect rect = w->geometry();
|
2011-01-30 14:34:42 +00:00
|
|
|
if (rect.y() != wwi.resize_original_rect.y()) wwi.can_wobble_top = true;
|
|
|
|
if (rect.x() != wwi.resize_original_rect.x()) wwi.can_wobble_left = true;
|
|
|
|
if (rect.right() != wwi.resize_original_rect.right()) wwi.can_wobble_right = true;
|
|
|
|
if (rect.bottom() != wwi.resize_original_rect.bottom()) wwi.can_wobble_bottom = true;
|
2009-02-14 22:42:09 +00:00
|
|
|
}
|
2008-04-18 12:01:47 +00:00
|
|
|
}
|
|
|
|
|
2011-03-13 08:48:51 +00:00
|
|
|
void WobblyWindowsEffect::slotWindowMaximizeStateChanged(EffectWindow *w, bool horizontal, bool vertical)
|
|
|
|
{
|
2012-05-24 09:15:24 +00:00
|
|
|
Q_UNUSED(horizontal)
|
|
|
|
Q_UNUSED(vertical)
|
2012-03-19 21:45:50 +00:00
|
|
|
if (w->isUserMove() || !m_moveEffectEnabled || w->isSpecialWindow())
|
2011-03-13 08:48:51 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
if (m_moveWobble && m_resizeWobble) {
|
|
|
|
stepMovedResized(w);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (windows.contains(w)) {
|
|
|
|
WindowWobblyInfos& wwi = windows[w];
|
|
|
|
QRect rect = w->geometry();
|
|
|
|
if (rect.y() != wwi.resize_original_rect.y()) wwi.can_wobble_top = true;
|
|
|
|
if (rect.x() != wwi.resize_original_rect.x()) wwi.can_wobble_left = true;
|
|
|
|
if (rect.right() != wwi.resize_original_rect.right()) wwi.can_wobble_right = true;
|
|
|
|
if (rect.bottom() != wwi.resize_original_rect.bottom()) wwi.can_wobble_bottom = true;
|
|
|
|
}
|
|
|
|
}
|
2009-03-02 20:18:35 +00:00
|
|
|
|
|
|
|
void WobblyWindowsEffect::startMovedResized(EffectWindow* w)
|
|
|
|
{
|
2011-01-30 14:34:42 +00:00
|
|
|
if (!windows.contains(w)) {
|
2009-03-02 20:18:35 +00:00
|
|
|
WindowWobblyInfos new_wwi;
|
|
|
|
initWobblyInfo(new_wwi, w->geometry());
|
|
|
|
windows[w] = new_wwi;
|
|
|
|
}
|
|
|
|
|
|
|
|
WindowWobblyInfos& wwi = windows[w];
|
|
|
|
wwi.status = Moving;
|
|
|
|
const QRectF& rect = w->geometry();
|
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
qreal x_increment = rect.width() / (wwi.width - 1.0);
|
|
|
|
qreal y_increment = rect.height() / (wwi.height - 1.0);
|
2009-03-02 20:18:35 +00:00
|
|
|
|
2012-11-26 09:27:02 +00:00
|
|
|
Pair picked = {static_cast<qreal>(cursorPos().x()), static_cast<qreal>(cursorPos().y())};
|
2009-03-02 20:18:35 +00:00
|
|
|
int indx = (picked.x - rect.x()) / x_increment + 0.5;
|
|
|
|
int indy = (picked.y - rect.y()) / y_increment + 0.5;
|
2011-01-30 14:34:42 +00:00
|
|
|
int pickedPointIndex = indy * wwi.width + indx;
|
|
|
|
if (pickedPointIndex < 0) {
|
2013-11-29 05:18:28 +00:00
|
|
|
qCDebug(KWINEFFECTS) << "Picked index == " << pickedPointIndex << " with (" << cursorPos().x() << "," << cursorPos().y() << ")";
|
2009-03-02 20:18:35 +00:00
|
|
|
pickedPointIndex = 0;
|
2011-01-30 14:34:42 +00:00
|
|
|
} else if (static_cast<unsigned int>(pickedPointIndex) > wwi.count - 1) {
|
2013-11-29 05:18:28 +00:00
|
|
|
qCDebug(KWINEFFECTS) << "Picked index == " << pickedPointIndex << " with (" << cursorPos().x() << "," << cursorPos().y() << ")";
|
2009-03-02 20:18:35 +00:00
|
|
|
pickedPointIndex = wwi.count - 1;
|
|
|
|
}
|
|
|
|
#if defined VERBOSE_MODE
|
2013-11-29 05:18:28 +00:00
|
|
|
qCDebug(KWINEFFECTS) << "Original Picked point -- x : " << picked.x << " - y : " << picked.y;
|
2009-03-02 20:18:35 +00:00
|
|
|
#endif
|
|
|
|
wwi.constraint[pickedPointIndex] = true;
|
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
if (w->isUserResize()) {
|
2009-03-02 20:18:35 +00:00
|
|
|
// on a resize, do not allow any edges to wobble until it has been moved from
|
|
|
|
// its original location
|
|
|
|
wwi.can_wobble_top = wwi.can_wobble_left = wwi.can_wobble_right = wwi.can_wobble_bottom = false;
|
|
|
|
wwi.resize_original_rect = w->geometry();
|
2011-01-30 14:34:42 +00:00
|
|
|
} else {
|
2009-03-02 20:18:35 +00:00
|
|
|
wwi.can_wobble_top = wwi.can_wobble_left = wwi.can_wobble_right = wwi.can_wobble_bottom = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void WobblyWindowsEffect::stepMovedResized(EffectWindow* w)
|
|
|
|
{
|
|
|
|
QRect new_geometry = w->geometry();
|
2011-01-30 14:34:42 +00:00
|
|
|
if (!windows.contains(w)) {
|
2009-03-02 20:18:35 +00:00
|
|
|
WindowWobblyInfos new_wwi;
|
|
|
|
initWobblyInfo(new_wwi, new_geometry);
|
|
|
|
windows[w] = new_wwi;
|
|
|
|
}
|
|
|
|
|
|
|
|
WindowWobblyInfos& wwi = windows[w];
|
|
|
|
wwi.status = Free;
|
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
QRect maximized_area = effects->clientArea(MaximizeArea, w);
|
|
|
|
bool throb_direction_out = (new_geometry.top() == maximized_area.top() && new_geometry.bottom() == maximized_area.bottom()) ||
|
|
|
|
(new_geometry.left() == maximized_area.left() && new_geometry.right() == maximized_area.right());
|
2009-03-02 20:18:35 +00:00
|
|
|
qreal magnitude = throb_direction_out ? 10 : -30; // a small throb out when maximized, a larger throb inwards when restored
|
2011-01-30 14:34:42 +00:00
|
|
|
for (unsigned int j = 0; j < wwi.height; ++j) {
|
|
|
|
for (unsigned int i = 0; i < wwi.width; ++i) {
|
|
|
|
Pair v = { magnitude*(i / qreal(wwi.width - 1) - 0.5), magnitude*(j / qreal(wwi.height - 1) - 0.5) };
|
2009-03-02 20:18:35 +00:00
|
|
|
wwi.velocity[j*wwi.width+i] = v;
|
|
|
|
}
|
|
|
|
}
|
2009-08-25 19:36:52 +00:00
|
|
|
|
|
|
|
// constrain the middle of the window, so that any asymetry wont cause it to drift off-center
|
2011-01-30 14:34:42 +00:00
|
|
|
for (unsigned int j = 1; j < wwi.height - 1; ++j) {
|
|
|
|
for (unsigned int i = 1; i < wwi.width - 1; ++i) {
|
2009-08-25 19:36:52 +00:00
|
|
|
wwi.constraint[j*wwi.width+i] = true;
|
|
|
|
}
|
|
|
|
}
|
2009-03-02 20:18:35 +00:00
|
|
|
}
|
|
|
|
|
2011-02-25 21:06:02 +00:00
|
|
|
void WobblyWindowsEffect::slotWindowAdded(EffectWindow* w)
|
2008-04-18 17:43:00 +00:00
|
|
|
{
|
2016-10-31 10:22:24 +00:00
|
|
|
if (m_openEffectEnabled && w->data(WindowAddedGrabRole).value<void*>() == nullptr) {
|
2011-01-30 14:34:42 +00:00
|
|
|
if (windows.contains(w)) {
|
2008-04-18 19:04:00 +00:00
|
|
|
// could this happen ??
|
|
|
|
WindowWobblyInfos& wwi = windows[w];
|
|
|
|
wobblyOpenInit(wwi);
|
2011-01-30 14:34:42 +00:00
|
|
|
} else {
|
2008-04-18 19:04:00 +00:00
|
|
|
WindowWobblyInfos new_wwi;
|
|
|
|
initWobblyInfo(new_wwi, w->geometry());
|
|
|
|
wobblyOpenInit(new_wwi);
|
|
|
|
windows[w] = new_wwi;
|
|
|
|
}
|
2008-04-18 17:43:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-02-27 08:25:45 +00:00
|
|
|
void WobblyWindowsEffect::slotWindowClosed(EffectWindow* w)
|
2008-04-18 12:01:47 +00:00
|
|
|
{
|
2011-01-30 14:34:42 +00:00
|
|
|
if (windows.contains(w)) {
|
2008-04-18 12:01:47 +00:00
|
|
|
WindowWobblyInfos& wwi = windows[w];
|
2011-01-30 14:34:42 +00:00
|
|
|
if (m_closeEffectEnabled) {
|
2008-04-18 19:04:00 +00:00
|
|
|
wobblyCloseInit(wwi, w);
|
|
|
|
w->refWindow();
|
2011-01-30 14:34:42 +00:00
|
|
|
} else {
|
2008-04-18 19:04:00 +00:00
|
|
|
freeWobblyInfo(wwi);
|
|
|
|
windows.remove(w);
|
2011-01-30 14:34:42 +00:00
|
|
|
if (windows.isEmpty())
|
2009-07-30 08:14:08 +00:00
|
|
|
effects->addRepaintFull();
|
2008-04-18 19:04:00 +00:00
|
|
|
}
|
2016-10-31 10:22:24 +00:00
|
|
|
} else if (m_closeEffectEnabled && w->data(WindowClosedGrabRole).value<void*>() == nullptr) {
|
2008-04-18 19:04:00 +00:00
|
|
|
WindowWobblyInfos new_wwi;
|
|
|
|
initWobblyInfo(new_wwi, w->geometry());
|
|
|
|
wobblyCloseInit(new_wwi, w);
|
|
|
|
windows[w] = new_wwi;
|
|
|
|
w->refWindow();
|
|
|
|
}
|
2008-04-18 17:43:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void WobblyWindowsEffect::wobblyOpenInit(WindowWobblyInfos& wwi) const
|
|
|
|
{
|
2011-01-30 14:34:42 +00:00
|
|
|
Pair middle = { (wwi.origin[0].x + wwi.origin[15].x) / 2, (wwi.origin[0].y + wwi.origin[15].y) / 2 };
|
2008-04-18 17:43:00 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
for (unsigned int j = 0; j < 4; ++j) {
|
|
|
|
for (unsigned int i = 0; i < 4; ++i) {
|
|
|
|
unsigned int idx = j * 4 + i;
|
2008-04-18 17:43:00 +00:00
|
|
|
wwi.constraint[idx] = false;
|
2011-01-30 14:34:42 +00:00
|
|
|
wwi.position[idx].x = (wwi.position[idx].x + 3 * middle.x) / 4;
|
|
|
|
wwi.position[idx].y = (wwi.position[idx].y + 3 * middle.y) / 4;
|
2008-04-18 17:43:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
wwi.status = Openning;
|
2009-02-14 22:42:09 +00:00
|
|
|
wwi.can_wobble_top = wwi.can_wobble_left = wwi.can_wobble_right = wwi.can_wobble_bottom = true;
|
2008-04-18 17:43:00 +00:00
|
|
|
}
|
|
|
|
|
2008-04-18 19:04:00 +00:00
|
|
|
void WobblyWindowsEffect::wobblyCloseInit(WindowWobblyInfos& wwi, EffectWindow* w) const
|
2008-04-18 17:43:00 +00:00
|
|
|
{
|
2008-04-18 19:04:00 +00:00
|
|
|
const QRectF& rect = w->geometry();
|
|
|
|
QPointF center = rect.center();
|
2011-01-30 14:34:42 +00:00
|
|
|
int x1 = (rect.x() + 3 * center.x()) / 4;
|
|
|
|
int x2 = (rect.x() + rect.width() + 3 * center.x()) / 4;
|
|
|
|
int y1 = (rect.y() + 3 * center.y()) / 4;
|
|
|
|
int y2 = (rect.y() + rect.height() + 3 * center.y()) / 4;
|
2008-04-18 19:04:00 +00:00
|
|
|
wwi.closeRect.setCoords(x1, y1, x2, y2);
|
|
|
|
|
2008-04-18 17:43:00 +00:00
|
|
|
// for closing, not yet used...
|
2011-01-30 14:34:42 +00:00
|
|
|
for (unsigned int j = 0; j < 4; ++j) {
|
|
|
|
for (unsigned int i = 0; i < 4; ++i) {
|
|
|
|
unsigned int idx = j * 4 + i;
|
2008-04-18 17:43:00 +00:00
|
|
|
wwi.constraint[idx] = false;
|
|
|
|
}
|
2008-04-18 12:01:47 +00:00
|
|
|
}
|
2008-04-18 17:43:00 +00:00
|
|
|
wwi.status = Closing;
|
2008-04-18 12:01:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void WobblyWindowsEffect::initWobblyInfo(WindowWobblyInfos& wwi, QRect geometry) const
|
|
|
|
{
|
2011-01-30 14:34:42 +00:00
|
|
|
wwi.count = 4 * 4;
|
2008-04-18 12:01:47 +00:00
|
|
|
wwi.width = 4;
|
|
|
|
wwi.height = 4;
|
|
|
|
|
|
|
|
wwi.bezierWidth = m_xTesselation;
|
|
|
|
wwi.bezierHeight = m_yTesselation;
|
|
|
|
wwi.bezierCount = m_xTesselation * m_yTesselation;
|
|
|
|
|
|
|
|
wwi.origin = new Pair[wwi.count];
|
|
|
|
wwi.position = new Pair[wwi.count];
|
|
|
|
wwi.velocity = new Pair[wwi.count];
|
|
|
|
wwi.acceleration = new Pair[wwi.count];
|
|
|
|
wwi.buffer = new Pair[wwi.count];
|
|
|
|
wwi.constraint = new bool[wwi.count];
|
|
|
|
|
|
|
|
wwi.bezierSurface = new Pair[wwi.bezierCount];
|
|
|
|
|
2008-04-18 17:43:00 +00:00
|
|
|
wwi.status = Moving;
|
2008-04-18 12:01:47 +00:00
|
|
|
|
|
|
|
qreal x = geometry.x(), y = geometry.y();
|
|
|
|
qreal width = geometry.width(), height = geometry.height();
|
|
|
|
|
|
|
|
Pair initValue = {x, y};
|
|
|
|
static const Pair nullPair = {0.0, 0.0};
|
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
qreal x_increment = width / (wwi.width - 1.0);
|
|
|
|
qreal y_increment = height / (wwi.height - 1.0);
|
2008-04-18 12:01:47 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
for (unsigned int j = 0; j < 4; ++j) {
|
|
|
|
for (unsigned int i = 0; i < 4; ++i) {
|
|
|
|
unsigned int idx = j * 4 + i;
|
2008-04-18 12:01:47 +00:00
|
|
|
wwi.origin[idx] = initValue;
|
|
|
|
wwi.position[idx] = initValue;
|
|
|
|
wwi.velocity[idx] = nullPair;
|
|
|
|
wwi.constraint[idx] = false;
|
2011-01-30 14:34:42 +00:00
|
|
|
if (i != 4 - 2) { // x grid count - 2, i.e. not the last point
|
2008-04-18 12:01:47 +00:00
|
|
|
initValue.x += x_increment;
|
2011-01-30 14:34:42 +00:00
|
|
|
} else {
|
2008-04-18 12:01:47 +00:00
|
|
|
initValue.x = width + x;
|
|
|
|
}
|
|
|
|
initValue.x = initValue.x;
|
|
|
|
}
|
|
|
|
initValue.x = x;
|
|
|
|
initValue.x = initValue.x;
|
2011-01-30 14:34:42 +00:00
|
|
|
if (j != 4 - 2) { // y grid count - 2, i.e. not the last point
|
2008-04-18 12:01:47 +00:00
|
|
|
initValue.y += y_increment;
|
2011-01-30 14:34:42 +00:00
|
|
|
} else {
|
2008-04-18 12:01:47 +00:00
|
|
|
initValue.y = height + y;
|
|
|
|
}
|
|
|
|
initValue.y = initValue.y;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void WobblyWindowsEffect::freeWobblyInfo(WindowWobblyInfos& wwi) const
|
|
|
|
{
|
2008-05-20 21:17:49 +00:00
|
|
|
delete[] wwi.origin;
|
|
|
|
delete[] wwi.position;
|
|
|
|
delete[] wwi.velocity;
|
|
|
|
delete[] wwi.acceleration;
|
|
|
|
delete[] wwi.buffer;
|
|
|
|
delete[] wwi.constraint;
|
|
|
|
|
|
|
|
delete[] wwi.bezierSurface;
|
2008-04-18 12:01:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
WobblyWindowsEffect::Pair WobblyWindowsEffect::computeBezierPoint(const WindowWobblyInfos& wwi, Pair point) const
|
|
|
|
{
|
|
|
|
// compute the input value
|
|
|
|
Pair topleft = wwi.origin[0];
|
|
|
|
Pair bottomright = wwi.origin[wwi.count-1];
|
|
|
|
|
|
|
|
qreal tx = (point.x - topleft.x) / (bottomright.x - topleft.x);
|
|
|
|
qreal ty = (point.y - topleft.y) / (bottomright.y - topleft.y);
|
|
|
|
|
2008-11-27 21:50:04 +00:00
|
|
|
// compute polynomial coeff
|
2008-04-18 12:01:47 +00:00
|
|
|
|
|
|
|
qreal px[4];
|
2011-01-30 14:34:42 +00:00
|
|
|
px[0] = (1 - tx) * (1 - tx) * (1 - tx);
|
|
|
|
px[1] = 3 * (1 - tx) * (1 - tx) * tx;
|
|
|
|
px[2] = 3 * (1 - tx) * tx * tx;
|
|
|
|
px[3] = tx * tx * tx;
|
2008-04-18 12:01:47 +00:00
|
|
|
|
|
|
|
qreal py[4];
|
2011-01-30 14:34:42 +00:00
|
|
|
py[0] = (1 - ty) * (1 - ty) * (1 - ty);
|
|
|
|
py[1] = 3 * (1 - ty) * (1 - ty) * ty;
|
|
|
|
py[2] = 3 * (1 - ty) * ty * ty;
|
|
|
|
py[3] = ty * ty * ty;
|
2008-04-18 12:01:47 +00:00
|
|
|
|
|
|
|
Pair res = {0.0, 0.0};
|
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
for (unsigned int j = 0; j < 4; ++j) {
|
|
|
|
for (unsigned int i = 0; i < 4; ++i) {
|
2008-04-18 12:01:47 +00:00
|
|
|
// this assume the grid is 4*4
|
|
|
|
res.x += px[i] * py[j] * wwi.position[i + j * wwi.width].x;
|
|
|
|
res.y += px[i] * py[j] * wwi.position[i + j * wwi.width].y;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
2008-11-27 21:50:04 +00:00
|
|
|
|
2008-04-18 12:01:47 +00:00
|
|
|
namespace
|
|
|
|
{
|
|
|
|
|
|
|
|
static inline void fixVectorBounds(WobblyWindowsEffect::Pair& vec, qreal min, qreal max)
|
|
|
|
{
|
2011-01-30 14:34:42 +00:00
|
|
|
if (fabs(vec.x) < min) {
|
2008-04-18 12:01:47 +00:00
|
|
|
vec.x = 0.0;
|
2011-01-30 14:34:42 +00:00
|
|
|
} else if (fabs(vec.x) > max) {
|
|
|
|
if (vec.x > 0.0) {
|
2008-04-18 12:01:47 +00:00
|
|
|
vec.x = max;
|
2011-01-30 14:34:42 +00:00
|
|
|
} else {
|
2008-04-18 12:01:47 +00:00
|
|
|
vec.x = -max;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
if (fabs(vec.y) < min) {
|
2008-04-18 12:01:47 +00:00
|
|
|
vec.y = 0.0;
|
2011-01-30 14:34:42 +00:00
|
|
|
} else if (fabs(vec.y) > max) {
|
|
|
|
if (vec.y > 0.0) {
|
2008-04-18 12:01:47 +00:00
|
|
|
vec.y = max;
|
2011-01-30 14:34:42 +00:00
|
|
|
} else {
|
2008-04-18 12:01:47 +00:00
|
|
|
vec.y = -max;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-31 15:58:57 +00:00
|
|
|
#if defined COMPUTE_STATS
|
2008-04-18 12:01:47 +00:00
|
|
|
static inline void computeVectorBounds(WobblyWindowsEffect::Pair& vec, WobblyWindowsEffect::Pair& bound)
|
|
|
|
{
|
2011-01-30 14:34:42 +00:00
|
|
|
if (fabs(vec.x) < bound.x) {
|
2008-04-18 12:01:47 +00:00
|
|
|
bound.x = fabs(vec.x);
|
2011-01-30 14:34:42 +00:00
|
|
|
} else if (fabs(vec.x) > bound.y) {
|
2008-04-18 12:01:47 +00:00
|
|
|
bound.y = fabs(vec.x);
|
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
if (fabs(vec.y) < bound.x) {
|
2008-04-18 12:01:47 +00:00
|
|
|
bound.x = fabs(vec.y);
|
2011-01-30 14:34:42 +00:00
|
|
|
} else if (fabs(vec.y) > bound.y) {
|
2008-04-18 12:01:47 +00:00
|
|
|
bound.y = fabs(vec.y);
|
|
|
|
}
|
|
|
|
}
|
2017-07-31 15:58:57 +00:00
|
|
|
#endif
|
2008-04-18 12:01:47 +00:00
|
|
|
|
|
|
|
} // close the anonymous namespace
|
|
|
|
|
|
|
|
bool WobblyWindowsEffect::updateWindowWobblyDatas(EffectWindow* w, qreal time)
|
|
|
|
{
|
2008-04-18 19:04:00 +00:00
|
|
|
QRectF rect = w->geometry();
|
2008-04-18 12:01:47 +00:00
|
|
|
WindowWobblyInfos& wwi = windows[w];
|
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
if (wwi.status == Closing) {
|
2008-04-18 19:04:00 +00:00
|
|
|
rect = wwi.closeRect;
|
|
|
|
}
|
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
qreal x_length = rect.width() / (wwi.width - 1.0);
|
|
|
|
qreal y_length = rect.height() / (wwi.height - 1.0);
|
2008-04-18 12:01:47 +00:00
|
|
|
|
|
|
|
#if defined VERBOSE_MODE
|
2013-11-29 05:18:28 +00:00
|
|
|
qCDebug(KWINEFFECTS) << "time " << time;
|
|
|
|
qCDebug(KWINEFFECTS) << "increment x " << x_length << " // y" << y_length;
|
2008-04-18 12:01:47 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
Pair origine = {rect.x(), rect.y()};
|
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
for (unsigned int j = 0; j < wwi.height; ++j) {
|
|
|
|
for (unsigned int i = 0; i < wwi.width; ++i) {
|
2008-04-18 12:01:47 +00:00
|
|
|
wwi.origin[wwi.width*j + i] = origine;
|
2011-01-30 14:34:42 +00:00
|
|
|
if (i != wwi.width - 2) {
|
2008-04-18 12:01:47 +00:00
|
|
|
origine.x += x_length;
|
2011-01-30 14:34:42 +00:00
|
|
|
} else {
|
2008-04-18 12:01:47 +00:00
|
|
|
origine.x = rect.width() + rect.x();
|
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2008-04-18 12:01:47 +00:00
|
|
|
origine.x = rect.x();
|
2011-01-30 14:34:42 +00:00
|
|
|
if (j != wwi.height - 2) {
|
2008-04-18 12:01:47 +00:00
|
|
|
origine.y += y_length;
|
2011-01-30 14:34:42 +00:00
|
|
|
} else {
|
2008-04-18 12:01:47 +00:00
|
|
|
origine.y = rect.height() + rect.y();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Pair neibourgs[4];
|
|
|
|
Pair acceleration;
|
|
|
|
|
|
|
|
qreal acc_sum = 0.0;
|
|
|
|
qreal vel_sum = 0.0;
|
|
|
|
|
|
|
|
// compute acceleration, velocity and position for each point
|
|
|
|
|
|
|
|
// for corners
|
|
|
|
|
|
|
|
// top-left
|
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
if (wwi.constraint[0]) {
|
2008-04-18 12:01:47 +00:00
|
|
|
Pair window_pos = wwi.origin[0];
|
|
|
|
Pair current_pos = wwi.position[0];
|
|
|
|
Pair move = {window_pos.x - current_pos.x, window_pos.y - current_pos.y};
|
2008-04-20 12:29:20 +00:00
|
|
|
Pair accel = {move.x*m_stiffness, move.y*m_stiffness};
|
2008-04-18 12:01:47 +00:00
|
|
|
wwi.acceleration[0] = accel;
|
2011-01-30 14:34:42 +00:00
|
|
|
} else {
|
2008-04-18 12:01:47 +00:00
|
|
|
Pair& pos = wwi.position[0];
|
|
|
|
neibourgs[0] = wwi.position[1];
|
|
|
|
neibourgs[1] = wwi.position[wwi.width];
|
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
acceleration.x = ((neibourgs[0].x - pos.x) - x_length) * m_stiffness + (neibourgs[1].x - pos.x) * m_stiffness;
|
|
|
|
acceleration.y = ((neibourgs[1].y - pos.y) - y_length) * m_stiffness + (neibourgs[0].y - pos.y) * m_stiffness;
|
2008-04-18 12:01:47 +00:00
|
|
|
|
|
|
|
acceleration.x /= 2;
|
|
|
|
acceleration.y /= 2;
|
|
|
|
|
|
|
|
wwi.acceleration[0] = acceleration;
|
|
|
|
}
|
|
|
|
|
|
|
|
// top-right
|
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
if (wwi.constraint[wwi.width-1]) {
|
2008-04-18 12:01:47 +00:00
|
|
|
Pair window_pos = wwi.origin[wwi.width-1];
|
|
|
|
Pair current_pos = wwi.position[wwi.width-1];
|
|
|
|
Pair move = {window_pos.x - current_pos.x, window_pos.y - current_pos.y};
|
2008-04-20 12:29:20 +00:00
|
|
|
Pair accel = {move.x*m_stiffness, move.y*m_stiffness};
|
2008-04-18 12:01:47 +00:00
|
|
|
wwi.acceleration[wwi.width-1] = accel;
|
2011-01-30 14:34:42 +00:00
|
|
|
} else {
|
2008-04-18 12:01:47 +00:00
|
|
|
Pair& pos = wwi.position[wwi.width-1];
|
|
|
|
neibourgs[0] = wwi.position[wwi.width-2];
|
|
|
|
neibourgs[1] = wwi.position[2*wwi.width-1];
|
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
acceleration.x = (x_length - (pos.x - neibourgs[0].x)) * m_stiffness + (neibourgs[1].x - pos.x) * m_stiffness;
|
|
|
|
acceleration.y = ((neibourgs[1].y - pos.y) - y_length) * m_stiffness + (neibourgs[0].y - pos.y) * m_stiffness;
|
2008-04-18 12:01:47 +00:00
|
|
|
|
|
|
|
acceleration.x /= 2;
|
|
|
|
acceleration.y /= 2;
|
|
|
|
|
|
|
|
wwi.acceleration[wwi.width-1] = acceleration;
|
|
|
|
}
|
|
|
|
|
|
|
|
// bottom-left
|
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
if (wwi.constraint[wwi.width*(wwi.height-1)]) {
|
2008-04-18 12:01:47 +00:00
|
|
|
Pair window_pos = wwi.origin[wwi.width*(wwi.height-1)];
|
|
|
|
Pair current_pos = wwi.position[wwi.width*(wwi.height-1)];
|
|
|
|
Pair move = {window_pos.x - current_pos.x, window_pos.y - current_pos.y};
|
2008-04-20 12:29:20 +00:00
|
|
|
Pair accel = {move.x*m_stiffness, move.y*m_stiffness};
|
2008-04-18 12:01:47 +00:00
|
|
|
wwi.acceleration[wwi.width*(wwi.height-1)] = accel;
|
2011-01-30 14:34:42 +00:00
|
|
|
} else {
|
2008-04-18 12:01:47 +00:00
|
|
|
Pair& pos = wwi.position[wwi.width*(wwi.height-1)];
|
|
|
|
neibourgs[0] = wwi.position[wwi.width*(wwi.height-1)+1];
|
|
|
|
neibourgs[1] = wwi.position[wwi.width*(wwi.height-2)];
|
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
acceleration.x = ((neibourgs[0].x - pos.x) - x_length) * m_stiffness + (neibourgs[1].x - pos.x) * m_stiffness;
|
|
|
|
acceleration.y = (y_length - (pos.y - neibourgs[1].y)) * m_stiffness + (neibourgs[0].y - pos.y) * m_stiffness;
|
2008-04-18 12:01:47 +00:00
|
|
|
|
|
|
|
acceleration.x /= 2;
|
|
|
|
acceleration.y /= 2;
|
|
|
|
|
|
|
|
wwi.acceleration[wwi.width*(wwi.height-1)] = acceleration;
|
|
|
|
}
|
|
|
|
|
|
|
|
// bottom-right
|
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
if (wwi.constraint[wwi.count-1]) {
|
2008-04-18 12:01:47 +00:00
|
|
|
Pair window_pos = wwi.origin[wwi.count-1];
|
|
|
|
Pair current_pos = wwi.position[wwi.count-1];
|
|
|
|
Pair move = {window_pos.x - current_pos.x, window_pos.y - current_pos.y};
|
2008-04-20 12:29:20 +00:00
|
|
|
Pair accel = {move.x*m_stiffness, move.y*m_stiffness};
|
2008-04-18 12:01:47 +00:00
|
|
|
wwi.acceleration[wwi.count-1] = accel;
|
2011-01-30 14:34:42 +00:00
|
|
|
} else {
|
2008-04-18 12:01:47 +00:00
|
|
|
Pair& pos = wwi.position[wwi.count-1];
|
|
|
|
neibourgs[0] = wwi.position[wwi.count-2];
|
|
|
|
neibourgs[1] = wwi.position[wwi.width*(wwi.height-1)-1];
|
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
acceleration.x = (x_length - (pos.x - neibourgs[0].x)) * m_stiffness + (neibourgs[1].x - pos.x) * m_stiffness;
|
|
|
|
acceleration.y = (y_length - (pos.y - neibourgs[1].y)) * m_stiffness + (neibourgs[0].y - pos.y) * m_stiffness;
|
2008-04-18 12:01:47 +00:00
|
|
|
|
|
|
|
acceleration.x /= 2;
|
|
|
|
acceleration.y /= 2;
|
|
|
|
|
|
|
|
wwi.acceleration[wwi.count-1] = acceleration;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// for borders
|
|
|
|
|
|
|
|
// top border
|
2011-01-30 14:34:42 +00:00
|
|
|
for (unsigned int i = 1; i < wwi.width - 1; ++i) {
|
|
|
|
if (wwi.constraint[i]) {
|
2008-04-18 12:01:47 +00:00
|
|
|
Pair window_pos = wwi.origin[i];
|
|
|
|
Pair current_pos = wwi.position[i];
|
|
|
|
Pair move = {window_pos.x - current_pos.x, window_pos.y - current_pos.y};
|
2008-04-20 12:29:20 +00:00
|
|
|
Pair accel = {move.x*m_stiffness, move.y*m_stiffness};
|
2008-04-18 12:01:47 +00:00
|
|
|
wwi.acceleration[i] = accel;
|
2011-01-30 14:34:42 +00:00
|
|
|
} else {
|
2008-04-18 12:01:47 +00:00
|
|
|
Pair& pos = wwi.position[i];
|
|
|
|
neibourgs[0] = wwi.position[i-1];
|
|
|
|
neibourgs[1] = wwi.position[i+1];
|
|
|
|
neibourgs[2] = wwi.position[i+wwi.width];
|
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
acceleration.x = (x_length - (pos.x - neibourgs[0].x)) * m_stiffness + ((neibourgs[1].x - pos.x) - x_length) * m_stiffness + (neibourgs[2].x - pos.x) * m_stiffness;
|
|
|
|
acceleration.y = ((neibourgs[2].y - pos.y) - y_length) * m_stiffness + (neibourgs[0].y - pos.y) * m_stiffness + (neibourgs[1].y - pos.y) * m_stiffness;
|
2008-04-18 12:01:47 +00:00
|
|
|
|
|
|
|
acceleration.x /= 3;
|
|
|
|
acceleration.y /= 3;
|
|
|
|
|
|
|
|
wwi.acceleration[i] = acceleration;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// bottom border
|
2011-01-30 14:34:42 +00:00
|
|
|
for (unsigned int i = wwi.width * (wwi.height - 1) + 1; i < wwi.count - 1; ++i) {
|
|
|
|
if (wwi.constraint[i]) {
|
2008-04-18 12:01:47 +00:00
|
|
|
Pair window_pos = wwi.origin[i];
|
|
|
|
Pair current_pos = wwi.position[i];
|
|
|
|
Pair move = {window_pos.x - current_pos.x, window_pos.y - current_pos.y};
|
2008-04-20 12:29:20 +00:00
|
|
|
Pair accel = {move.x*m_stiffness, move.y*m_stiffness};
|
2008-04-18 12:01:47 +00:00
|
|
|
wwi.acceleration[i] = accel;
|
2011-01-30 14:34:42 +00:00
|
|
|
} else {
|
2008-04-18 12:01:47 +00:00
|
|
|
Pair& pos = wwi.position[i];
|
|
|
|
neibourgs[0] = wwi.position[i-1];
|
|
|
|
neibourgs[1] = wwi.position[i+1];
|
|
|
|
neibourgs[2] = wwi.position[i-wwi.width];
|
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
acceleration.x = (x_length - (pos.x - neibourgs[0].x)) * m_stiffness + ((neibourgs[1].x - pos.x) - x_length) * m_stiffness + (neibourgs[2].x - pos.x) * m_stiffness;
|
|
|
|
acceleration.y = (y_length - (pos.y - neibourgs[2].y)) * m_stiffness + (neibourgs[0].y - pos.y) * m_stiffness + (neibourgs[1].y - pos.y) * m_stiffness;
|
2008-04-18 12:01:47 +00:00
|
|
|
|
|
|
|
acceleration.x /= 3;
|
|
|
|
acceleration.y /= 3;
|
|
|
|
|
|
|
|
wwi.acceleration[i] = acceleration;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// left border
|
2011-01-30 14:34:42 +00:00
|
|
|
for (unsigned int i = wwi.width; i < wwi.width*(wwi.height - 1); i += wwi.width) {
|
|
|
|
if (wwi.constraint[i]) {
|
2008-04-18 12:01:47 +00:00
|
|
|
Pair window_pos = wwi.origin[i];
|
|
|
|
Pair current_pos = wwi.position[i];
|
|
|
|
Pair move = {window_pos.x - current_pos.x, window_pos.y - current_pos.y};
|
2008-04-20 12:29:20 +00:00
|
|
|
Pair accel = {move.x*m_stiffness, move.y*m_stiffness};
|
2008-04-18 12:01:47 +00:00
|
|
|
wwi.acceleration[i] = accel;
|
2011-01-30 14:34:42 +00:00
|
|
|
} else {
|
2008-04-18 12:01:47 +00:00
|
|
|
Pair& pos = wwi.position[i];
|
|
|
|
neibourgs[0] = wwi.position[i+1];
|
|
|
|
neibourgs[1] = wwi.position[i-wwi.width];
|
|
|
|
neibourgs[2] = wwi.position[i+wwi.width];
|
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
acceleration.x = ((neibourgs[0].x - pos.x) - x_length) * m_stiffness + (neibourgs[1].x - pos.x) * m_stiffness + (neibourgs[2].x - pos.x) * m_stiffness;
|
|
|
|
acceleration.y = (y_length - (pos.y - neibourgs[1].y)) * m_stiffness + ((neibourgs[2].y - pos.y) - y_length) * m_stiffness + (neibourgs[0].y - pos.y) * m_stiffness;
|
2008-04-18 12:01:47 +00:00
|
|
|
|
|
|
|
acceleration.x /= 3;
|
|
|
|
acceleration.y /= 3;
|
|
|
|
|
|
|
|
wwi.acceleration[i] = acceleration;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// right border
|
2011-01-30 14:34:42 +00:00
|
|
|
for (unsigned int i = 2 * wwi.width - 1; i < wwi.count - 1; i += wwi.width) {
|
|
|
|
if (wwi.constraint[i]) {
|
2008-04-18 12:01:47 +00:00
|
|
|
Pair window_pos = wwi.origin[i];
|
|
|
|
Pair current_pos = wwi.position[i];
|
|
|
|
Pair move = {window_pos.x - current_pos.x, window_pos.y - current_pos.y};
|
2008-04-20 12:29:20 +00:00
|
|
|
Pair accel = {move.x*m_stiffness, move.y*m_stiffness};
|
2008-04-18 12:01:47 +00:00
|
|
|
wwi.acceleration[i] = accel;
|
2011-01-30 14:34:42 +00:00
|
|
|
} else {
|
2008-04-18 12:01:47 +00:00
|
|
|
Pair& pos = wwi.position[i];
|
|
|
|
neibourgs[0] = wwi.position[i-1];
|
|
|
|
neibourgs[1] = wwi.position[i-wwi.width];
|
|
|
|
neibourgs[2] = wwi.position[i+wwi.width];
|
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
acceleration.x = (x_length - (pos.x - neibourgs[0].x)) * m_stiffness + (neibourgs[1].x - pos.x) * m_stiffness + (neibourgs[2].x - pos.x) * m_stiffness;
|
|
|
|
acceleration.y = (y_length - (pos.y - neibourgs[1].y)) * m_stiffness + ((neibourgs[2].y - pos.y) - y_length) * m_stiffness + (neibourgs[0].y - pos.y) * m_stiffness;
|
2008-04-18 12:01:47 +00:00
|
|
|
|
|
|
|
acceleration.x /= 3;
|
|
|
|
acceleration.y /= 3;
|
|
|
|
|
|
|
|
wwi.acceleration[i] = acceleration;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// for the inner points
|
2011-01-30 14:34:42 +00:00
|
|
|
for (unsigned int j = 1; j < wwi.height - 1; ++j) {
|
|
|
|
for (unsigned int i = 1; i < wwi.width - 1; ++i) {
|
|
|
|
unsigned int index = i + j * wwi.width;
|
|
|
|
|
|
|
|
if (wwi.constraint[index]) {
|
|
|
|
Pair window_pos = wwi.origin[index];
|
|
|
|
Pair current_pos = wwi.position[index];
|
|
|
|
Pair move = {window_pos.x - current_pos.x, window_pos.y - current_pos.y};
|
|
|
|
Pair accel = {move.x*m_stiffness, move.y*m_stiffness};
|
|
|
|
wwi.acceleration[index] = accel;
|
|
|
|
} else {
|
2008-04-18 12:01:47 +00:00
|
|
|
Pair& pos = wwi.position[index];
|
|
|
|
neibourgs[0] = wwi.position[index-1];
|
|
|
|
neibourgs[1] = wwi.position[index+1];
|
|
|
|
neibourgs[2] = wwi.position[index-wwi.width];
|
|
|
|
neibourgs[3] = wwi.position[index+wwi.width];
|
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
acceleration.x = ((neibourgs[0].x - pos.x) - x_length) * m_stiffness +
|
|
|
|
(x_length - (pos.x - neibourgs[1].x)) * m_stiffness +
|
|
|
|
(neibourgs[2].x - pos.x) * m_stiffness +
|
|
|
|
(neibourgs[3].x - pos.x) * m_stiffness;
|
|
|
|
acceleration.y = (y_length - (pos.y - neibourgs[2].y)) * m_stiffness +
|
|
|
|
((neibourgs[3].y - pos.y) - y_length) * m_stiffness +
|
|
|
|
(neibourgs[0].y - pos.y) * m_stiffness +
|
|
|
|
(neibourgs[1].y - pos.y) * m_stiffness;
|
2008-04-18 12:01:47 +00:00
|
|
|
|
|
|
|
acceleration.x /= 4;
|
|
|
|
acceleration.y /= 4;
|
|
|
|
|
|
|
|
wwi.acceleration[index] = acceleration;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-09-26 05:27:57 +00:00
|
|
|
heightRingLinearMean(&wwi.acceleration, wwi);
|
2008-04-18 12:01:47 +00:00
|
|
|
|
|
|
|
#if defined COMPUTE_STATS
|
|
|
|
Pair accBound = {m_maxAcceleration, m_minAcceleration};
|
|
|
|
Pair velBound = {m_maxVelocity, m_minVelocity};
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// compute the new velocity of each vertex.
|
2011-01-30 14:34:42 +00:00
|
|
|
for (unsigned int i = 0; i < wwi.count; ++i) {
|
2008-04-18 12:01:47 +00:00
|
|
|
Pair acc = wwi.acceleration[i];
|
|
|
|
fixVectorBounds(acc, m_minAcceleration, m_maxAcceleration);
|
|
|
|
|
|
|
|
#if defined COMPUTE_STATS
|
|
|
|
computeVectorBounds(acc, accBound);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
Pair& vel = wwi.velocity[i];
|
2011-01-30 14:34:42 +00:00
|
|
|
vel.x = acc.x * time + vel.x * m_drag;
|
|
|
|
vel.y = acc.y * time + vel.y * m_drag;
|
2008-04-18 12:01:47 +00:00
|
|
|
|
|
|
|
acc_sum += fabs(acc.x) + fabs(acc.y);
|
|
|
|
}
|
|
|
|
|
2008-09-26 05:27:57 +00:00
|
|
|
heightRingLinearMean(&wwi.velocity, wwi);
|
2008-04-18 12:01:47 +00:00
|
|
|
|
|
|
|
// compute the new pos of each vertex.
|
2011-01-30 14:34:42 +00:00
|
|
|
for (unsigned int i = 0; i < wwi.count; ++i) {
|
2008-04-18 12:01:47 +00:00
|
|
|
Pair& pos = wwi.position[i];
|
|
|
|
Pair& vel = wwi.velocity[i];
|
|
|
|
|
|
|
|
fixVectorBounds(vel, m_minVelocity, m_maxVelocity);
|
|
|
|
#if defined COMPUTE_STATS
|
|
|
|
computeVectorBounds(vel, velBound);
|
|
|
|
#endif
|
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
pos.x += vel.x * time * m_move_factor;
|
|
|
|
pos.y += vel.y * time * m_move_factor;
|
2008-04-18 12:01:47 +00:00
|
|
|
|
|
|
|
vel_sum += fabs(vel.x) + fabs(vel.y);
|
|
|
|
|
|
|
|
#if defined VERBOSE_MODE
|
2011-01-30 14:34:42 +00:00
|
|
|
if (wwi.constraint[i]) {
|
2013-11-29 05:18:28 +00:00
|
|
|
qCDebug(KWINEFFECTS) << "Constraint point ** vel : " << vel.x << "," << vel.y << " ** move : " << vel.x*time << "," << vel.y*time;
|
2008-04-18 12:01:47 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
if (!wwi.can_wobble_top) {
|
|
|
|
for (unsigned int i = 0; i < wwi.width; ++i)
|
|
|
|
for (unsigned j = 0; j < wwi.width - 1; ++j)
|
2009-02-14 22:42:09 +00:00
|
|
|
wwi.position[i+wwi.width*j].y = wwi.origin[i+wwi.width*j].y;
|
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
if (!wwi.can_wobble_bottom) {
|
|
|
|
for (unsigned int i = wwi.width * (wwi.height - 1); i < wwi.count; ++i)
|
|
|
|
for (unsigned j = 0; j < wwi.width - 1; ++j)
|
2009-02-14 22:42:09 +00:00
|
|
|
wwi.position[i-wwi.width*j].y = wwi.origin[i-wwi.width*j].y;
|
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
if (!wwi.can_wobble_left) {
|
|
|
|
for (unsigned int i = 0; i < wwi.count; i += wwi.width)
|
|
|
|
for (unsigned j = 0; j < wwi.width - 1; ++j)
|
2009-02-14 22:42:09 +00:00
|
|
|
wwi.position[i+j].x = wwi.origin[i+j].x;
|
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
if (!wwi.can_wobble_right) {
|
|
|
|
for (unsigned int i = wwi.width - 1; i < wwi.count; i += wwi.width)
|
|
|
|
for (unsigned j = 0; j < wwi.width - 1; ++j)
|
2009-02-14 22:42:09 +00:00
|
|
|
wwi.position[i-j].x = wwi.origin[i-j].x;
|
|
|
|
}
|
|
|
|
|
2008-04-18 12:01:47 +00:00
|
|
|
#if defined VERBOSE_MODE
|
|
|
|
# if defined COMPUTE_STATS
|
2013-11-29 05:18:28 +00:00
|
|
|
qCDebug(KWINEFFECTS) << "Acceleration bounds (" << accBound.x << ", " << accBound.y << ")";
|
|
|
|
qCDebug(KWINEFFECTS) << "Velocity bounds (" << velBound.x << ", " << velBound.y << ")";
|
2008-04-18 12:01:47 +00:00
|
|
|
# endif
|
2013-11-29 05:18:28 +00:00
|
|
|
qCDebug(KWINEFFECTS) << "sum_acc : " << acc_sum << " *** sum_vel :" << vel_sum;
|
2008-04-18 12:01:47 +00:00
|
|
|
#endif
|
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
if (wwi.status != Moving && acc_sum < m_stopAcceleration && vel_sum < m_stopVelocity) {
|
|
|
|
if (wwi.status == Closing) {
|
2008-04-18 19:04:00 +00:00
|
|
|
w->unrefWindow();
|
|
|
|
}
|
2008-05-20 21:17:49 +00:00
|
|
|
freeWobblyInfo(wwi);
|
|
|
|
windows.remove(w);
|
2011-01-30 14:34:42 +00:00
|
|
|
if (windows.isEmpty())
|
2009-07-30 08:14:08 +00:00
|
|
|
effects->addRepaintFull();
|
2008-04-18 12:01:47 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2009-09-26 07:50:04 +00:00
|
|
|
void WobblyWindowsEffect::heightRingLinearMean(Pair** data_pointer, WindowWobblyInfos& wwi)
|
2008-04-21 23:25:03 +00:00
|
|
|
{
|
2009-09-26 07:50:04 +00:00
|
|
|
Pair* data = *data_pointer;
|
2008-04-21 23:25:03 +00:00
|
|
|
Pair neibourgs[8];
|
|
|
|
|
|
|
|
// for corners
|
|
|
|
|
|
|
|
// top-left
|
|
|
|
{
|
|
|
|
Pair& res = wwi.buffer[0];
|
2009-09-26 07:50:04 +00:00
|
|
|
Pair vit = data[0];
|
|
|
|
neibourgs[0] = data[1];
|
|
|
|
neibourgs[1] = data[wwi.width];
|
|
|
|
neibourgs[2] = data[wwi.width+1];
|
2008-04-21 23:25:03 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
res.x = (neibourgs[0].x + neibourgs[1].x + neibourgs[2].x + 3.0 * vit.x) / 6.0;
|
|
|
|
res.y = (neibourgs[0].y + neibourgs[1].y + neibourgs[2].y + 3.0 * vit.y) / 6.0;
|
2008-04-21 23:25:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// top-right
|
|
|
|
{
|
|
|
|
Pair& res = wwi.buffer[wwi.width-1];
|
2009-09-26 07:50:04 +00:00
|
|
|
Pair vit = data[wwi.width-1];
|
|
|
|
neibourgs[0] = data[wwi.width-2];
|
|
|
|
neibourgs[1] = data[2*wwi.width-1];
|
|
|
|
neibourgs[2] = data[2*wwi.width-2];
|
2008-04-21 23:25:03 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
res.x = (neibourgs[0].x + neibourgs[1].x + neibourgs[2].x + 3.0 * vit.x) / 6.0;
|
|
|
|
res.y = (neibourgs[0].y + neibourgs[1].y + neibourgs[2].y + 3.0 * vit.y) / 6.0;
|
2008-04-21 23:25:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// bottom-left
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2008-04-21 23:25:03 +00:00
|
|
|
Pair& res = wwi.buffer[wwi.width*(wwi.height-1)];
|
2009-09-26 07:50:04 +00:00
|
|
|
Pair vit = data[wwi.width*(wwi.height-1)];
|
|
|
|
neibourgs[0] = data[wwi.width*(wwi.height-1)+1];
|
|
|
|
neibourgs[1] = data[wwi.width*(wwi.height-2)];
|
|
|
|
neibourgs[2] = data[wwi.width*(wwi.height-2)+1];
|
2008-04-21 23:25:03 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
res.x = (neibourgs[0].x + neibourgs[1].x + neibourgs[2].x + 3.0 * vit.x) / 6.0;
|
|
|
|
res.y = (neibourgs[0].y + neibourgs[1].y + neibourgs[2].y + 3.0 * vit.y) / 6.0;
|
2008-04-21 23:25:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// bottom-right
|
|
|
|
{
|
|
|
|
Pair& res = wwi.buffer[wwi.count-1];
|
2009-09-26 07:50:04 +00:00
|
|
|
Pair vit = data[wwi.count-1];
|
|
|
|
neibourgs[0] = data[wwi.count-2];
|
|
|
|
neibourgs[1] = data[wwi.width*(wwi.height-1)-1];
|
|
|
|
neibourgs[2] = data[wwi.width*(wwi.height-1)-2];
|
2008-04-21 23:25:03 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
res.x = (neibourgs[0].x + neibourgs[1].x + neibourgs[2].x + 3.0 * vit.x) / 6.0;
|
|
|
|
res.y = (neibourgs[0].y + neibourgs[1].y + neibourgs[2].y + 3.0 * vit.y) / 6.0;
|
2008-04-21 23:25:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// for borders
|
|
|
|
|
|
|
|
// top border
|
2011-01-30 14:34:42 +00:00
|
|
|
for (unsigned int i = 1; i < wwi.width - 1; ++i) {
|
2008-04-21 23:25:03 +00:00
|
|
|
Pair& res = wwi.buffer[i];
|
2009-09-26 07:50:04 +00:00
|
|
|
Pair vit = data[i];
|
|
|
|
neibourgs[0] = data[i-1];
|
|
|
|
neibourgs[1] = data[i+1];
|
|
|
|
neibourgs[2] = data[i+wwi.width];
|
|
|
|
neibourgs[3] = data[i+wwi.width-1];
|
|
|
|
neibourgs[4] = data[i+wwi.width+1];
|
2008-04-21 23:25:03 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
res.x = (neibourgs[0].x + neibourgs[1].x + neibourgs[2].x + neibourgs[3].x + neibourgs[4].x + 5.0 * vit.x) / 10.0;
|
|
|
|
res.y = (neibourgs[0].y + neibourgs[1].y + neibourgs[2].y + neibourgs[3].y + neibourgs[4].y + 5.0 * vit.y) / 10.0;
|
2008-04-21 23:25:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// bottom border
|
2011-01-30 14:34:42 +00:00
|
|
|
for (unsigned int i = wwi.width * (wwi.height - 1) + 1; i < wwi.count - 1; ++i) {
|
2008-04-21 23:25:03 +00:00
|
|
|
Pair& res = wwi.buffer[i];
|
2009-09-26 07:50:04 +00:00
|
|
|
Pair vit = data[i];
|
|
|
|
neibourgs[0] = data[i-1];
|
|
|
|
neibourgs[1] = data[i+1];
|
|
|
|
neibourgs[2] = data[i-wwi.width];
|
|
|
|
neibourgs[3] = data[i-wwi.width-1];
|
|
|
|
neibourgs[4] = data[i-wwi.width+1];
|
2008-04-21 23:25:03 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
res.x = (neibourgs[0].x + neibourgs[1].x + neibourgs[2].x + neibourgs[3].x + neibourgs[4].x + 5.0 * vit.x) / 10.0;
|
|
|
|
res.y = (neibourgs[0].y + neibourgs[1].y + neibourgs[2].y + neibourgs[3].y + neibourgs[4].y + 5.0 * vit.y) / 10.0;
|
2008-04-21 23:25:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// left border
|
2011-01-30 14:34:42 +00:00
|
|
|
for (unsigned int i = wwi.width; i < wwi.width*(wwi.height - 1); i += wwi.width) {
|
2008-04-21 23:25:03 +00:00
|
|
|
Pair& res = wwi.buffer[i];
|
2009-09-26 07:50:04 +00:00
|
|
|
Pair vit = data[i];
|
|
|
|
neibourgs[0] = data[i+1];
|
|
|
|
neibourgs[1] = data[i-wwi.width];
|
|
|
|
neibourgs[2] = data[i+wwi.width];
|
|
|
|
neibourgs[3] = data[i-wwi.width+1];
|
|
|
|
neibourgs[4] = data[i+wwi.width+1];
|
2008-04-21 23:25:03 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
res.x = (neibourgs[0].x + neibourgs[1].x + neibourgs[2].x + neibourgs[3].x + neibourgs[4].x + 5.0 * vit.x) / 10.0;
|
|
|
|
res.y = (neibourgs[0].y + neibourgs[1].y + neibourgs[2].y + neibourgs[3].y + neibourgs[4].y + 5.0 * vit.y) / 10.0;
|
2008-04-21 23:25:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// right border
|
2011-01-30 14:34:42 +00:00
|
|
|
for (unsigned int i = 2 * wwi.width - 1; i < wwi.count - 1; i += wwi.width) {
|
2008-04-21 23:25:03 +00:00
|
|
|
Pair& res = wwi.buffer[i];
|
2009-09-26 07:50:04 +00:00
|
|
|
Pair vit = data[i];
|
|
|
|
neibourgs[0] = data[i-1];
|
|
|
|
neibourgs[1] = data[i-wwi.width];
|
|
|
|
neibourgs[2] = data[i+wwi.width];
|
|
|
|
neibourgs[3] = data[i-wwi.width-1];
|
|
|
|
neibourgs[4] = data[i+wwi.width-1];
|
2008-04-21 23:25:03 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
res.x = (neibourgs[0].x + neibourgs[1].x + neibourgs[2].x + neibourgs[3].x + neibourgs[4].x + 5.0 * vit.x) / 10.0;
|
|
|
|
res.y = (neibourgs[0].y + neibourgs[1].y + neibourgs[2].y + neibourgs[3].y + neibourgs[4].y + 5.0 * vit.y) / 10.0;
|
2008-04-21 23:25:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// for the inner points
|
2011-01-30 14:34:42 +00:00
|
|
|
for (unsigned int j = 1; j < wwi.height - 1; ++j) {
|
|
|
|
for (unsigned int i = 1; i < wwi.width - 1; ++i) {
|
|
|
|
unsigned int index = i + j * wwi.width;
|
2008-04-21 23:25:03 +00:00
|
|
|
|
|
|
|
Pair& res = wwi.buffer[index];
|
2009-09-26 07:50:04 +00:00
|
|
|
Pair& vit = data[index];
|
|
|
|
neibourgs[0] = data[index-1];
|
|
|
|
neibourgs[1] = data[index+1];
|
|
|
|
neibourgs[2] = data[index-wwi.width];
|
|
|
|
neibourgs[3] = data[index+wwi.width];
|
|
|
|
neibourgs[4] = data[index-wwi.width-1];
|
|
|
|
neibourgs[5] = data[index-wwi.width+1];
|
|
|
|
neibourgs[6] = data[index+wwi.width-1];
|
|
|
|
neibourgs[7] = data[index+wwi.width+1];
|
2008-04-21 23:25:03 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
res.x = (neibourgs[0].x + neibourgs[1].x + neibourgs[2].x + neibourgs[3].x + neibourgs[4].x + neibourgs[5].x + neibourgs[6].x + neibourgs[7].x + 8.0 * vit.x) / 16.0;
|
|
|
|
res.y = (neibourgs[0].y + neibourgs[1].y + neibourgs[2].y + neibourgs[3].y + neibourgs[4].y + neibourgs[5].y + neibourgs[6].y + neibourgs[7].y + 8.0 * vit.y) / 16.0;
|
2008-04-21 23:25:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-09-26 07:50:04 +00:00
|
|
|
Pair* tmp = data;
|
|
|
|
*data_pointer = wwi.buffer;
|
2008-04-21 23:25:03 +00:00
|
|
|
wwi.buffer = tmp;
|
|
|
|
}
|
|
|
|
|
2016-10-31 10:22:24 +00:00
|
|
|
|
|
|
|
void WobblyWindowsEffect::cancelWindowGrab(KWin::EffectWindow *w, int grabRole)
|
|
|
|
{
|
|
|
|
if (grabRole == WindowAddedGrabRole) {
|
|
|
|
if (w->data(WindowAddedGrabRole).value<void*>() != this) {
|
|
|
|
auto it = windows.find(w);
|
|
|
|
if (it != windows.end()) {
|
|
|
|
freeWobblyInfo(it.value());
|
|
|
|
windows.erase(it);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (grabRole == WindowClosedGrabRole) {
|
|
|
|
if (w->data(WindowClosedGrabRole).value<void*>() != this) {
|
|
|
|
auto it = windows.find(w);
|
|
|
|
if (it != windows.end()) {
|
|
|
|
if (it.value().status == Closing) {
|
|
|
|
w->unrefWindow();
|
|
|
|
}
|
|
|
|
freeWobblyInfo(it.value());
|
|
|
|
windows.erase(it);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-08-27 09:21:31 +00:00
|
|
|
bool WobblyWindowsEffect::isActive() const
|
|
|
|
{
|
|
|
|
return !windows.isEmpty();
|
|
|
|
}
|
2008-04-18 12:01:47 +00:00
|
|
|
|
|
|
|
} // namespace KWin
|
|
|
|
|