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) 2006 Lubos Lunak <l.lunak@kde.org>
|
2009-02-21 04:53:13 +00:00
|
|
|
Copyright (C) 2009 Lucas Murray <lmurray@undefinedfire.com>
|
2007-04-29 17:35:43 +00:00
|
|
|
|
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 "kwineffects.h"
|
|
|
|
|
2008-05-07 14:43:13 +00:00
|
|
|
#include "kwinxrenderutils.h"
|
2007-09-02 18:20:36 +00:00
|
|
|
|
2007-05-29 11:46:12 +00:00
|
|
|
#include <QtDBus/QtDBus>
|
|
|
|
#include <QVariant>
|
|
|
|
#include <QList>
|
2008-04-18 23:57:05 +00:00
|
|
|
#include <QtCore/QTimeLine>
|
2007-09-02 18:20:36 +00:00
|
|
|
#include <QtGui/QFontMetrics>
|
|
|
|
#include <QtGui/QPainter>
|
|
|
|
#include <QtGui/QPixmap>
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2007-05-29 11:46:12 +00:00
|
|
|
#include <kdebug.h>
|
|
|
|
#include <ksharedconfig.h>
|
2009-02-22 13:04:16 +00:00
|
|
|
#include <kstandarddirs.h>
|
2007-10-05 22:21:25 +00:00
|
|
|
#include <kconfiggroup.h>
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
|
2008-01-03 15:22:19 +00:00
|
|
|
#ifdef KWIN_HAVE_XRENDER_COMPOSITING
|
2007-09-02 18:20:36 +00:00
|
|
|
#include <X11/extensions/Xrender.h>
|
2008-02-28 13:15:39 +00:00
|
|
|
#include <X11/extensions/Xfixes.h>
|
2008-03-03 21:12:48 +00:00
|
|
|
#endif
|
2007-09-02 18:20:36 +00:00
|
|
|
|
2007-04-29 17:35:43 +00:00
|
|
|
namespace KWin
|
|
|
|
{
|
|
|
|
|
2007-07-19 13:32:46 +00:00
|
|
|
void WindowPrePaintData::setTranslucent()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2007-07-19 13:32:46 +00:00
|
|
|
mask |= Effect::PAINT_WINDOW_TRANSLUCENT;
|
|
|
|
mask &= ~Effect::PAINT_WINDOW_OPAQUE;
|
|
|
|
clip = QRegion(); // cannot clip, will be transparent
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-07-19 13:32:46 +00:00
|
|
|
|
2007-07-19 14:05:59 +00:00
|
|
|
void WindowPrePaintData::setTransformed()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2007-07-19 14:05:59 +00:00
|
|
|
mask |= Effect::PAINT_WINDOW_TRANSFORMED;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
WindowPaintData::WindowPaintData(EffectWindow* w)
|
|
|
|
: opacity(w->opacity())
|
|
|
|
, contents_opacity(1.0)
|
|
|
|
, decoration_opacity(1.0)
|
|
|
|
, xScale(1)
|
|
|
|
, yScale(1)
|
|
|
|
, zScale(1)
|
|
|
|
, xTranslate(0)
|
|
|
|
, yTranslate(0)
|
|
|
|
, zTranslate(0)
|
|
|
|
, saturation(1)
|
|
|
|
, brightness(1)
|
|
|
|
, shader(NULL)
|
|
|
|
, rotation(NULL)
|
|
|
|
{
|
2007-08-08 14:42:06 +00:00
|
|
|
quads = w->buildQuads();
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
ScreenPaintData::ScreenPaintData()
|
2011-01-30 14:34:42 +00:00
|
|
|
: xScale(1)
|
|
|
|
, yScale(1)
|
|
|
|
, zScale(1)
|
|
|
|
, xTranslate(0)
|
|
|
|
, yTranslate(0)
|
|
|
|
, zTranslate(0)
|
|
|
|
, rotation(NULL)
|
|
|
|
{
|
|
|
|
}
|
2008-08-04 14:07:45 +00:00
|
|
|
|
|
|
|
RotationData::RotationData()
|
2011-01-30 14:34:42 +00:00
|
|
|
: axis(ZAxis)
|
|
|
|
, angle(0.0)
|
|
|
|
, xRotationPoint(0.0)
|
|
|
|
, yRotationPoint(0.0)
|
|
|
|
, zRotationPoint(0.0)
|
|
|
|
{
|
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
//****************************************
|
|
|
|
// Effect
|
|
|
|
//****************************************
|
|
|
|
|
|
|
|
Effect::Effect()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
Effect::~Effect()
|
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 Effect::reconfigure(ReconfigureFlags)
|
|
|
|
{
|
|
|
|
}
|
2008-10-02 09:27:32 +00:00
|
|
|
|
2009-09-02 02:30:22 +00:00
|
|
|
void* Effect::proxy()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2009-02-06 10:15:06 +00:00
|
|
|
return NULL;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2009-02-06 10:15:06 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
void Effect::windowInputMouseEvent(Window, QEvent*)
|
|
|
|
{
|
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
void Effect::grabbedKeyboardEvent(QKeyEvent*)
|
|
|
|
{
|
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
bool Effect::borderActivated(ElectricBorder)
|
|
|
|
{
|
2007-04-29 17:35:43 +00:00
|
|
|
return false;
|
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 Effect::prePaintScreen(ScreenPrePaintData& data, int time)
|
|
|
|
{
|
|
|
|
effects->prePaintScreen(data, time);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Effect::paintScreen(int mask, QRegion region, ScreenPaintData& data)
|
|
|
|
{
|
|
|
|
effects->paintScreen(mask, region, data);
|
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
void Effect::postPaintScreen()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2007-04-29 17:35:43 +00:00
|
|
|
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
|
|
|
void Effect::prePaintWindow(EffectWindow* w, WindowPrePaintData& data, int time)
|
|
|
|
{
|
|
|
|
effects->prePaintWindow(w, data, time);
|
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
void Effect::paintWindow(EffectWindow* w, int mask, QRegion region, WindowPaintData& data)
|
|
|
|
{
|
|
|
|
effects->paintWindow(w, mask, region, data);
|
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
void Effect::postPaintWindow(EffectWindow* w)
|
|
|
|
{
|
|
|
|
effects->postPaintWindow(w);
|
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
void Effect::paintEffectFrame(KWin::EffectFrame* frame, QRegion region, double opacity, double frameOpacity)
|
|
|
|
{
|
|
|
|
effects->paintEffectFrame(frame, region, opacity, frameOpacity);
|
|
|
|
}
|
2010-07-24 16:29:16 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
bool Effect::provides(Feature)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
void Effect::drawWindow(EffectWindow* w, int mask, QRegion region, WindowPaintData& data)
|
|
|
|
{
|
|
|
|
effects->drawWindow(w, mask, region, data);
|
|
|
|
}
|
2008-10-17 10:30:43 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
void Effect::buildQuads(EffectWindow* w, WindowQuadList& quadList)
|
|
|
|
{
|
|
|
|
effects->buildQuads(w, quadList);
|
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
void Effect::setPositionTransformations(WindowPaintData& data, QRect& region, EffectWindow* w,
|
|
|
|
const QRect& r, Qt::AspectRatioMode aspect)
|
|
|
|
{
|
2007-04-29 17:35:43 +00:00
|
|
|
QSize size = w->size();
|
2011-01-30 14:34:42 +00:00
|
|
|
size.scale(r.size(), aspect);
|
|
|
|
data.xScale = size.width() / double(w->width());
|
|
|
|
data.yScale = size.height() / double(w->height());
|
|
|
|
int width = int(w->width() * data.xScale);
|
|
|
|
int height = int(w->height() * data.yScale);
|
|
|
|
int x = r.x() + (r.width() - width) / 2;
|
|
|
|
int y = r.y() + (r.height() - height) / 2;
|
|
|
|
region = QRect(x, y, width, height);
|
2007-04-29 17:35:43 +00:00
|
|
|
data.xTranslate = x - w->x();
|
|
|
|
data.yTranslate = y - w->y();
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
int Effect::displayWidth()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2007-04-29 17:35:43 +00:00
|
|
|
return KWin::displayWidth();
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
int Effect::displayHeight()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2007-04-29 17:35:43 +00:00
|
|
|
return KWin::displayHeight();
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
QPoint Effect::cursorPos()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2007-04-29 17:35:43 +00:00
|
|
|
return effects->cursorPos();
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
double Effect::animationTime(const KConfigGroup& cfg, const QString& key, int defaultTime)
|
|
|
|
{
|
|
|
|
int time = cfg.readEntry(key, 0);
|
|
|
|
return time != 0 ? time : qMax(defaultTime * effects->animationTimeFactor(), 1.);
|
|
|
|
}
|
2008-08-30 07:25:54 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
double Effect::animationTime(int defaultTime)
|
|
|
|
{
|
|
|
|
// at least 1ms, otherwise 0ms times can break some things
|
|
|
|
return qMax(defaultTime * effects->animationTimeFactor(), 1.);
|
|
|
|
}
|
2008-08-30 07:25:54 +00:00
|
|
|
|
2007-04-29 17:35:43 +00:00
|
|
|
//****************************************
|
|
|
|
// EffectsHandler
|
|
|
|
//****************************************
|
|
|
|
|
|
|
|
EffectsHandler::EffectsHandler(CompositingType type)
|
2011-01-30 14:34:42 +00:00
|
|
|
: current_paint_screen(0)
|
|
|
|
, current_paint_window(0)
|
|
|
|
, current_draw_window(0)
|
|
|
|
, current_build_quads(0)
|
|
|
|
, compositing_type(type)
|
|
|
|
{
|
|
|
|
if (compositing_type == NoCompositing)
|
2007-04-29 17:35:43 +00:00
|
|
|
return;
|
|
|
|
KWin::effects = this;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
EffectsHandler::~EffectsHandler()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2007-04-29 17:35:43 +00:00
|
|
|
// All effects should already be unloaded by Impl dtor
|
2011-01-30 14:34:42 +00:00
|
|
|
assert(loaded_effects.count() == 0);
|
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
Window EffectsHandler::createInputWindow(Effect* e, const QRect& r, const QCursor& cursor)
|
|
|
|
{
|
|
|
|
return createInputWindow(e, r.x(), r.y(), r.width(), r.height(), cursor);
|
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
Window EffectsHandler::createFullScreenInputWindow(Effect* e, const QCursor& cursor)
|
|
|
|
{
|
|
|
|
return createInputWindow(e, 0, 0, displayWidth(), displayHeight(), cursor);
|
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2007-07-26 07:51:16 +00:00
|
|
|
CompositingType EffectsHandler::compositingType() const
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2007-07-26 07:51:16 +00:00
|
|
|
return compositing_type;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-07-26 07:51:16 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
void EffectsHandler::sendReloadMessage(const QString& effectname)
|
|
|
|
{
|
2008-10-02 09:27:32 +00:00
|
|
|
QDBusMessage message = QDBusMessage::createMethodCall("org.kde.kwin", "/KWin", "org.kde.KWin", "reconfigureEffect");
|
2007-05-29 11:46:12 +00:00
|
|
|
message << QString("kwin4_effect_" + effectname);
|
|
|
|
QDBusConnection::sessionBus().send(message);
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-05-29 11:46:12 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
KConfigGroup EffectsHandler::effectConfig(const QString& effectname)
|
|
|
|
{
|
|
|
|
KSharedConfig::Ptr kwinconfig = KSharedConfig::openConfig("kwinrc", KConfig::NoGlobals);
|
|
|
|
return kwinconfig->group("Effect-" + effectname);
|
|
|
|
}
|
2007-05-29 11:46:12 +00:00
|
|
|
|
2007-04-29 17:35:43 +00:00
|
|
|
EffectsHandler* effects = 0;
|
|
|
|
|
|
|
|
|
|
|
|
//****************************************
|
|
|
|
// EffectWindow
|
|
|
|
//****************************************
|
|
|
|
|
|
|
|
EffectWindow::EffectWindow()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
EffectWindow::~EffectWindow()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2011-04-24 12:20:47 +00:00
|
|
|
bool EffectWindow::isOnCurrentActivity() const
|
|
|
|
{
|
|
|
|
return isOnActivity(effects->currentActivity());
|
|
|
|
}
|
|
|
|
|
2007-04-29 17:35:43 +00:00
|
|
|
bool EffectWindow::isOnCurrentDesktop() const
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
return isOnDesktop(effects->currentDesktop());
|
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
bool EffectWindow::isOnDesktop(int d) const
|
|
|
|
{
|
2007-04-29 17:35:43 +00:00
|
|
|
return desktop() == d || isOnAllDesktops();
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2007-07-19 13:32:46 +00:00
|
|
|
bool EffectWindow::hasDecoration() const
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
return contentsRect() != QRect(0, 0, width(), height());
|
|
|
|
}
|
2007-07-19 13:32:46 +00:00
|
|
|
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
//****************************************
|
|
|
|
// EffectWindowGroup
|
|
|
|
//****************************************
|
|
|
|
|
|
|
|
EffectWindowGroup::~EffectWindowGroup()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2007-11-24 13:43:52 +00:00
|
|
|
//****************************************
|
|
|
|
// GlobalShortcutsEditor
|
|
|
|
//****************************************
|
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
GlobalShortcutsEditor::GlobalShortcutsEditor(QWidget *parent) :
|
|
|
|
KShortcutsEditor(parent, GlobalAction)
|
|
|
|
{
|
|
|
|
}
|
2007-11-24 13:43:52 +00:00
|
|
|
|
2007-07-07 14:01:32 +00:00
|
|
|
/***************************************************************
|
|
|
|
WindowQuad
|
|
|
|
***************************************************************/
|
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
WindowQuad WindowQuad::makeSubQuad(double x1, double y1, double x2, double y2) const
|
|
|
|
{
|
|
|
|
assert(x1 < x2 && y1 < y2 && x1 >= left() && x2 <= right() && y1 >= top() && y2 <= bottom());
|
2007-07-19 16:11:27 +00:00
|
|
|
#ifndef NDEBUG
|
2011-01-30 14:34:42 +00:00
|
|
|
if (isTransformed())
|
|
|
|
kFatal(1212) << "Splitting quads is allowed only in pre-paint calls!" ;
|
2007-07-19 16:11:27 +00:00
|
|
|
#endif
|
2011-01-30 14:34:42 +00:00
|
|
|
WindowQuad ret(*this);
|
2007-07-19 14:56:25 +00:00
|
|
|
// vertices are clockwise starting from topleft
|
2007-07-07 14:01:32 +00:00
|
|
|
ret.verts[ 0 ].px = x1;
|
|
|
|
ret.verts[ 3 ].px = x1;
|
|
|
|
ret.verts[ 1 ].px = x2;
|
|
|
|
ret.verts[ 2 ].px = x2;
|
|
|
|
ret.verts[ 0 ].py = y1;
|
|
|
|
ret.verts[ 1 ].py = y1;
|
|
|
|
ret.verts[ 2 ].py = y2;
|
|
|
|
ret.verts[ 3 ].py = y2;
|
2007-07-19 14:53:37 +00:00
|
|
|
// original x/y are supposed to be the same, no transforming is done here
|
|
|
|
ret.verts[ 0 ].ox = x1;
|
|
|
|
ret.verts[ 3 ].ox = x1;
|
|
|
|
ret.verts[ 1 ].ox = x2;
|
|
|
|
ret.verts[ 2 ].ox = x2;
|
|
|
|
ret.verts[ 0 ].oy = y1;
|
|
|
|
ret.verts[ 1 ].oy = y1;
|
|
|
|
ret.verts[ 2 ].oy = y2;
|
|
|
|
ret.verts[ 3 ].oy = y2;
|
2007-09-03 15:00:43 +00:00
|
|
|
double my_tleft = verts[ 0 ].tx;
|
|
|
|
double my_tright = verts[ 2 ].tx;
|
|
|
|
double my_ttop = verts[ 0 ].ty;
|
|
|
|
double my_tbottom = verts[ 2 ].ty;
|
2011-01-30 14:34:42 +00:00
|
|
|
double tleft = (x1 - left()) / (right() - left()) * (my_tright - my_tleft) + my_tleft;
|
|
|
|
double tright = (x2 - left()) / (right() - left()) * (my_tright - my_tleft) + my_tleft;
|
|
|
|
double ttop = (y1 - top()) / (bottom() - top()) * (my_tbottom - my_ttop) + my_ttop;
|
|
|
|
double tbottom = (y2 - top()) / (bottom() - top()) * (my_tbottom - my_ttop) + my_ttop;
|
2007-07-07 14:01:32 +00:00
|
|
|
ret.verts[ 0 ].tx = tleft;
|
|
|
|
ret.verts[ 3 ].tx = tleft;
|
|
|
|
ret.verts[ 1 ].tx = tright;
|
|
|
|
ret.verts[ 2 ].tx = tright;
|
|
|
|
ret.verts[ 0 ].ty = ttop;
|
|
|
|
ret.verts[ 1 ].ty = ttop;
|
|
|
|
ret.verts[ 2 ].ty = tbottom;
|
|
|
|
ret.verts[ 3 ].ty = tbottom;
|
|
|
|
return ret;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-07-07 14:01:32 +00:00
|
|
|
|
2007-07-19 15:55:04 +00:00
|
|
|
bool WindowQuad::smoothNeeded() const
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2007-07-19 15:55:04 +00:00
|
|
|
// smoothing is needed if the width or height of the quad does not match the original size
|
2007-09-03 15:00:43 +00:00
|
|
|
double width = verts[ 1 ].ox - verts[ 0 ].ox;
|
|
|
|
double height = verts[ 2 ].oy - verts[ 1 ].oy;
|
2011-01-30 14:34:42 +00:00
|
|
|
return(verts[ 1 ].px - verts[ 0 ].px != width || verts[ 2 ].px - verts[ 3 ].px != width
|
|
|
|
|| verts[ 2 ].py - verts[ 1 ].py != height || verts[ 3 ].py - verts[ 0 ].py != height);
|
|
|
|
}
|
2007-07-19 15:55:04 +00:00
|
|
|
|
2007-07-07 14:01:32 +00:00
|
|
|
/***************************************************************
|
|
|
|
WindowQuadList
|
|
|
|
***************************************************************/
|
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
WindowQuadList WindowQuadList::splitAtX(double x) const
|
|
|
|
{
|
2007-07-07 14:01:32 +00:00
|
|
|
WindowQuadList ret;
|
2011-01-30 14:34:42 +00:00
|
|
|
foreach (const WindowQuad & quad, *this) {
|
2007-07-19 16:11:27 +00:00
|
|
|
#ifndef NDEBUG
|
2011-01-30 14:34:42 +00:00
|
|
|
if (quad.isTransformed())
|
|
|
|
kFatal(1212) << "Splitting quads is allowed only in pre-paint calls!" ;
|
2007-07-19 16:11:27 +00:00
|
|
|
#endif
|
2007-07-07 14:01:32 +00:00
|
|
|
bool wholeleft = true;
|
|
|
|
bool wholeright = true;
|
2011-01-30 14:34:42 +00:00
|
|
|
for (int i = 0;
|
|
|
|
i < 4;
|
|
|
|
++i) {
|
|
|
|
if (quad[ i ].x() < x)
|
2007-07-07 14:01:32 +00:00
|
|
|
wholeright = false;
|
2011-01-30 14:34:42 +00:00
|
|
|
if (quad[ i ].x() > x)
|
2007-07-07 14:01:32 +00:00
|
|
|
wholeleft = false;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
|
|
|
if (wholeleft || wholeright) { // is whole in one split part
|
|
|
|
ret.append(quad);
|
2007-07-07 14:01:32 +00:00
|
|
|
continue;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
|
|
|
if (quad.left() == quad.right()) { // quad has no size
|
|
|
|
ret.append(quad);
|
2008-12-16 20:48:34 +00:00
|
|
|
continue;
|
2007-07-07 14:01:32 +00:00
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
ret.append(quad.makeSubQuad(quad.left(), quad.top(), x, quad.bottom()));
|
|
|
|
ret.append(quad.makeSubQuad(x, quad.top(), quad.right(), quad.bottom()));
|
2007-07-07 14:01:32 +00:00
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
return ret;
|
|
|
|
}
|
2007-07-07 14:01:32 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
WindowQuadList WindowQuadList::splitAtY(double y) const
|
|
|
|
{
|
2007-07-07 14:01:32 +00:00
|
|
|
WindowQuadList ret;
|
2011-01-30 14:34:42 +00:00
|
|
|
foreach (const WindowQuad & quad, *this) {
|
2007-07-19 16:11:27 +00:00
|
|
|
#ifndef NDEBUG
|
2011-01-30 14:34:42 +00:00
|
|
|
if (quad.isTransformed())
|
|
|
|
kFatal(1212) << "Splitting quads is allowed only in pre-paint calls!" ;
|
2007-07-19 16:11:27 +00:00
|
|
|
#endif
|
2007-07-07 14:01:32 +00:00
|
|
|
bool wholetop = true;
|
|
|
|
bool wholebottom = true;
|
2011-01-30 14:34:42 +00:00
|
|
|
for (int i = 0;
|
|
|
|
i < 4;
|
|
|
|
++i) {
|
|
|
|
if (quad[ i ].y() < y)
|
2007-07-07 14:01:32 +00:00
|
|
|
wholebottom = false;
|
2011-01-30 14:34:42 +00:00
|
|
|
if (quad[ i ].y() > y)
|
2007-07-07 14:01:32 +00:00
|
|
|
wholetop = false;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
|
|
|
if (wholetop || wholebottom) { // is whole in one split part
|
|
|
|
ret.append(quad);
|
2007-07-07 14:01:32 +00:00
|
|
|
continue;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
|
|
|
if (quad.top() == quad.bottom()) { // quad has no size
|
|
|
|
ret.append(quad);
|
2008-12-16 20:48:34 +00:00
|
|
|
continue;
|
2007-07-07 14:01:32 +00:00
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
ret.append(quad.makeSubQuad(quad.left(), quad.top(), quad.right(), y));
|
|
|
|
ret.append(quad.makeSubQuad(quad.left(), y, quad.right(), quad.bottom()));
|
2007-07-07 14:01:32 +00:00
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
return ret;
|
|
|
|
}
|
2007-07-07 14:01:32 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
WindowQuadList WindowQuadList::makeGrid(int maxquadsize) const
|
|
|
|
{
|
|
|
|
if (empty())
|
2007-07-07 14:01:32 +00:00
|
|
|
return *this;
|
|
|
|
// find the bounding rectangle
|
2007-09-03 15:00:43 +00:00
|
|
|
double left = first().left();
|
|
|
|
double right = first().right();
|
|
|
|
double top = first().top();
|
|
|
|
double bottom = first().bottom();
|
2011-01-30 14:34:42 +00:00
|
|
|
foreach (const WindowQuad & quad, *this) {
|
2007-07-19 16:11:27 +00:00
|
|
|
#ifndef NDEBUG
|
2011-01-30 14:34:42 +00:00
|
|
|
if (quad.isTransformed())
|
|
|
|
kFatal(1212) << "Splitting quads is allowed only in pre-paint calls!" ;
|
2007-07-19 16:11:27 +00:00
|
|
|
#endif
|
2011-01-30 14:34:42 +00:00
|
|
|
left = qMin(left, quad.left());
|
|
|
|
right = qMax(right, quad.right());
|
|
|
|
top = qMin(top, quad.top());
|
|
|
|
bottom = qMax(bottom, quad.bottom());
|
|
|
|
}
|
2007-07-07 14:01:32 +00:00
|
|
|
WindowQuadList ret;
|
2011-01-30 14:34:42 +00:00
|
|
|
for (double x = left;
|
|
|
|
x < right;
|
|
|
|
x += maxquadsize) {
|
|
|
|
for (double y = top;
|
|
|
|
y < bottom;
|
|
|
|
y += maxquadsize) {
|
|
|
|
foreach (const WindowQuad & quad, *this) {
|
|
|
|
if (QRectF(QPointF(quad.left(), quad.top()), QPointF(quad.right(), quad.bottom()))
|
|
|
|
.intersects(QRectF(x, y, maxquadsize, maxquadsize))) {
|
|
|
|
ret.append(quad.makeSubQuad(qMax(x, quad.left()), qMax(y, quad.top()),
|
|
|
|
qMin(quad.right(), x + maxquadsize), qMin(quad.bottom(), y + maxquadsize)));
|
2007-07-07 14:01:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
return ret;
|
|
|
|
}
|
2007-07-07 14:01:32 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
WindowQuadList WindowQuadList::makeRegularGrid(int xSubdivisions, int ySubdivisions) const
|
|
|
|
{
|
|
|
|
if (empty())
|
2008-03-02 22:28:50 +00:00
|
|
|
return *this;
|
|
|
|
// find the bounding rectangle
|
|
|
|
double left = first().left();
|
|
|
|
double right = first().right();
|
|
|
|
double top = first().top();
|
|
|
|
double bottom = first().bottom();
|
2011-01-30 14:34:42 +00:00
|
|
|
foreach (const WindowQuad & quad, *this) {
|
2008-03-02 22:28:50 +00:00
|
|
|
#ifndef NDEBUG
|
2011-01-30 14:34:42 +00:00
|
|
|
if (quad.isTransformed())
|
|
|
|
kFatal(1212) << "Splitting quads is allowed only in pre-paint calls!" ;
|
2008-03-02 22:28:50 +00:00
|
|
|
#endif
|
2011-01-30 14:34:42 +00:00
|
|
|
left = qMin(left, quad.left());
|
|
|
|
right = qMax(right, quad.right());
|
|
|
|
top = qMin(top, quad.top());
|
|
|
|
bottom = qMax(bottom, quad.bottom());
|
|
|
|
}
|
2008-03-02 22:28:50 +00:00
|
|
|
|
|
|
|
double xincrement = (right - left) / xSubdivisions;
|
|
|
|
double yincrement = (bottom - top) / ySubdivisions;
|
|
|
|
WindowQuadList ret;
|
2011-01-30 14:34:42 +00:00
|
|
|
for (double y = top;
|
|
|
|
y < bottom;
|
|
|
|
y += yincrement) {
|
|
|
|
for (double x = left;
|
|
|
|
x < right;
|
|
|
|
x += xincrement) {
|
|
|
|
foreach (const WindowQuad & quad, *this) {
|
|
|
|
if (QRectF(QPointF(quad.left(), quad.top()), QPointF(quad.right(), quad.bottom()))
|
|
|
|
.intersects(QRectF(x, y, xincrement, yincrement))) {
|
|
|
|
ret.append(quad.makeSubQuad(qMax(x, quad.left()), qMax(y, quad.top()),
|
|
|
|
qMin(quad.right(), x + xincrement), qMin(quad.bottom(), y + yincrement)));
|
2008-03-02 22:28:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
return ret;
|
|
|
|
}
|
2008-03-02 22:28:50 +00:00
|
|
|
|
2011-06-16 18:33:06 +00:00
|
|
|
void WindowQuadList::makeArrays(float** vertices, float** texcoords, const QSizeF& size, bool yInverted) const
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2010-11-14 19:49:00 +00:00
|
|
|
*vertices = new float[ count() * 6 * 2 ];
|
|
|
|
*texcoords = new float[ count() * 6 * 2 ];
|
2007-07-07 14:01:32 +00:00
|
|
|
float* vpos = *vertices;
|
|
|
|
float* tpos = *texcoords;
|
2011-01-30 14:34:42 +00:00
|
|
|
for (int i = 0;
|
|
|
|
i < count();
|
|
|
|
++i) {
|
|
|
|
*vpos++ = at(i)[ 1 ].x();
|
|
|
|
*vpos++ = at(i)[ 1 ].y();
|
|
|
|
*vpos++ = at(i)[ 0 ].x();
|
|
|
|
*vpos++ = at(i)[ 0 ].y();
|
|
|
|
*vpos++ = at(i)[ 3 ].x();
|
|
|
|
*vpos++ = at(i)[ 3 ].y();
|
|
|
|
*vpos++ = at(i)[ 3 ].x();
|
|
|
|
*vpos++ = at(i)[ 3 ].y();
|
|
|
|
*vpos++ = at(i)[ 2 ].x();
|
|
|
|
*vpos++ = at(i)[ 2 ].y();
|
|
|
|
*vpos++ = at(i)[ 1 ].x();
|
|
|
|
*vpos++ = at(i)[ 1 ].y();
|
|
|
|
|
2011-06-16 18:33:06 +00:00
|
|
|
if (yInverted) {
|
|
|
|
*tpos++ = at(i)[ 1 ].tx / size.width();
|
|
|
|
*tpos++ = at(i)[ 1 ].ty / size.height();
|
|
|
|
*tpos++ = at(i)[ 0 ].tx / size.width();
|
|
|
|
*tpos++ = at(i)[ 0 ].ty / size.height();
|
|
|
|
*tpos++ = at(i)[ 3 ].tx / size.width();
|
|
|
|
*tpos++ = at(i)[ 3 ].ty / size.height();
|
|
|
|
*tpos++ = at(i)[ 3 ].tx / size.width();
|
|
|
|
*tpos++ = at(i)[ 3 ].ty / size.height();
|
|
|
|
*tpos++ = at(i)[ 2 ].tx / size.width();
|
|
|
|
*tpos++ = at(i)[ 2 ].ty / size.height();
|
|
|
|
*tpos++ = at(i)[ 1 ].tx / size.width();
|
|
|
|
*tpos++ = at(i)[ 1 ].ty / size.height();
|
|
|
|
} else {
|
|
|
|
*tpos++ = at(i)[ 1 ].tx / size.width();
|
|
|
|
*tpos++ = 1.0f - at(i)[ 1 ].ty / size.height();
|
|
|
|
*tpos++ = at(i)[ 0 ].tx / size.width();
|
|
|
|
*tpos++ = 1.0f - at(i)[ 0 ].ty / size.height();
|
|
|
|
*tpos++ = at(i)[ 3 ].tx / size.width();
|
|
|
|
*tpos++ = 1.0f - at(i)[ 3 ].ty / size.height();
|
|
|
|
*tpos++ = at(i)[ 3 ].tx / size.width();
|
|
|
|
*tpos++ = 1.0f - at(i)[ 3 ].ty / size.height();
|
|
|
|
*tpos++ = at(i)[ 2 ].tx / size.width();
|
|
|
|
*tpos++ = 1.0f - at(i)[ 2 ].ty / size.height();
|
|
|
|
*tpos++ = at(i)[ 1 ].tx / size.width();
|
|
|
|
*tpos++ = 1.0f - at(i)[ 1 ].ty / size.height();
|
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
WindowQuadList WindowQuadList::select(WindowQuadType type) const
|
|
|
|
{
|
|
|
|
foreach (const WindowQuad & q, *this) {
|
|
|
|
if (q.type() != type) { // something else than ones to select, make a copy and filter
|
2007-07-19 10:07:49 +00:00
|
|
|
WindowQuadList ret;
|
2011-01-30 14:34:42 +00:00
|
|
|
foreach (const WindowQuad & q, *this) {
|
|
|
|
if (q.type() == type)
|
|
|
|
ret.append(q);
|
2007-07-19 10:07:49 +00:00
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
return ret;
|
2007-07-19 10:07:49 +00:00
|
|
|
}
|
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
return *this; // nothing to filter out
|
|
|
|
}
|
2007-07-19 10:07:49 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
WindowQuadList WindowQuadList::filterOut(WindowQuadType type) const
|
|
|
|
{
|
|
|
|
foreach (const WindowQuad & q, *this) {
|
|
|
|
if (q.type() == type) { // something to filter out, make a copy and filter
|
2007-07-18 15:01:59 +00:00
|
|
|
WindowQuadList ret;
|
2011-01-30 14:34:42 +00:00
|
|
|
foreach (const WindowQuad & q, *this) {
|
|
|
|
if (q.type() != type)
|
|
|
|
ret.append(q);
|
2007-07-18 15:01:59 +00:00
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
return ret;
|
2007-07-18 15:01:59 +00:00
|
|
|
}
|
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
return *this; // nothing to filter out
|
|
|
|
}
|
2007-07-18 15:01:59 +00:00
|
|
|
|
2007-07-07 14:01:32 +00:00
|
|
|
bool WindowQuadList::smoothNeeded() const
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
foreach (const WindowQuad & q, *this)
|
|
|
|
if (q.smoothNeeded())
|
|
|
|
return true;
|
2007-07-19 15:55:04 +00:00
|
|
|
return false;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2008-09-18 15:26:17 +00:00
|
|
|
bool WindowQuadList::isTransformed() const
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
foreach (const WindowQuad & q, *this)
|
|
|
|
if (q.isTransformed())
|
|
|
|
return true;
|
2008-09-18 15:26:17 +00:00
|
|
|
return false;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2008-09-18 15:26:17 +00:00
|
|
|
|
2008-02-25 11:32:21 +00:00
|
|
|
/***************************************************************
|
|
|
|
PaintClipper
|
|
|
|
***************************************************************/
|
|
|
|
|
|
|
|
QStack< QRegion >* PaintClipper::areas = NULL;
|
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
PaintClipper::PaintClipper(const QRegion& allowed_area)
|
|
|
|
: area(allowed_area)
|
|
|
|
{
|
|
|
|
push(area);
|
|
|
|
}
|
2008-02-25 11:32:21 +00:00
|
|
|
|
|
|
|
PaintClipper::~PaintClipper()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
pop(area);
|
|
|
|
}
|
2008-02-25 11:32:21 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
void PaintClipper::push(const QRegion& allowed_area)
|
|
|
|
{
|
|
|
|
if (allowed_area == infiniteRegion()) // don't push these
|
2008-02-25 11:32:21 +00:00
|
|
|
return;
|
2011-01-30 14:34:42 +00:00
|
|
|
if (areas == NULL)
|
2008-02-25 11:32:21 +00:00
|
|
|
areas = new QStack< QRegion >;
|
2011-01-30 14:34:42 +00:00
|
|
|
areas->push(allowed_area);
|
|
|
|
}
|
2008-02-25 11:32:21 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
void PaintClipper::pop(const QRegion& allowed_area)
|
|
|
|
{
|
|
|
|
if (allowed_area == infiniteRegion())
|
2008-02-25 11:32:21 +00:00
|
|
|
return;
|
2011-01-30 14:34:42 +00:00
|
|
|
Q_ASSERT(areas != NULL);
|
|
|
|
Q_ASSERT(areas->top() == allowed_area);
|
2008-02-25 11:32:21 +00:00
|
|
|
areas->pop();
|
2011-01-30 14:34:42 +00:00
|
|
|
if (areas->isEmpty()) {
|
2008-02-25 11:32:21 +00:00
|
|
|
delete areas;
|
|
|
|
areas = NULL;
|
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2008-02-25 11:32:21 +00:00
|
|
|
|
|
|
|
bool PaintClipper::clip()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2008-02-25 11:32:21 +00:00
|
|
|
return areas != NULL;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2008-02-25 11:32:21 +00:00
|
|
|
|
|
|
|
QRegion PaintClipper::paintArea()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
assert(areas != NULL); // can be called only with clip() == true
|
|
|
|
QRegion ret = QRegion(0, 0, displayWidth(), displayHeight());
|
|
|
|
foreach (const QRegion & r, *areas)
|
|
|
|
ret &= r;
|
2008-02-25 11:32:21 +00:00
|
|
|
return ret;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2008-02-25 11:32:21 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
struct PaintClipper::Iterator::Data {
|
|
|
|
Data() : index(0) {}
|
2008-02-25 11:32:21 +00:00
|
|
|
int index;
|
|
|
|
#ifdef KWIN_HAVE_OPENGL_COMPOSITING
|
|
|
|
QVector< QRect > rects;
|
|
|
|
#endif
|
2011-01-30 14:34:42 +00:00
|
|
|
};
|
2008-02-25 11:32:21 +00:00
|
|
|
|
|
|
|
PaintClipper::Iterator::Iterator()
|
2011-01-30 14:34:42 +00:00
|
|
|
: data(new Data)
|
|
|
|
{
|
2008-02-25 11:32:21 +00:00
|
|
|
#ifdef KWIN_HAVE_OPENGL_COMPOSITING
|
2011-01-30 14:34:42 +00:00
|
|
|
if (clip() && effects->compositingType() == OpenGLCompositing) {
|
2008-02-25 11:32:21 +00:00
|
|
|
data->rects = paintArea().rects();
|
|
|
|
data->index = -1;
|
|
|
|
next(); // move to the first one
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2008-02-25 11:32:21 +00:00
|
|
|
#endif
|
|
|
|
#ifdef KWIN_HAVE_XRENDER_COMPOSITING
|
2011-01-30 14:34:42 +00:00
|
|
|
if (clip() && effects->compositingType() == XRenderCompositing) {
|
|
|
|
XserverRegion region = toXserverRegion(paintArea());
|
|
|
|
XFixesSetPictureClipRegion(display(), effects->xrenderBufferPicture(), 0, 0, region);
|
|
|
|
XFixesDestroyRegion(display(), region); // it's ref-counted
|
2008-02-25 11:32:21 +00:00
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
#endif
|
|
|
|
}
|
2008-02-25 11:32:21 +00:00
|
|
|
|
|
|
|
PaintClipper::Iterator::~Iterator()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2008-02-25 11:32:21 +00:00
|
|
|
#ifdef KWIN_HAVE_XRENDER_COMPOSITING
|
2011-01-30 14:34:42 +00:00
|
|
|
if (clip() && effects->compositingType() == XRenderCompositing)
|
|
|
|
XFixesSetPictureClipRegion(display(), effects->xrenderBufferPicture(), 0, 0, None);
|
2008-02-25 11:32:21 +00:00
|
|
|
#endif
|
|
|
|
delete data;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2008-02-25 11:32:21 +00:00
|
|
|
|
|
|
|
bool PaintClipper::Iterator::isDone()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
if (!clip())
|
2008-02-25 11:32:21 +00:00
|
|
|
return data->index == 1; // run once
|
|
|
|
#ifdef KWIN_HAVE_OPENGL_COMPOSITING
|
2011-01-30 14:34:42 +00:00
|
|
|
if (effects->compositingType() == OpenGLCompositing)
|
2008-02-25 11:32:21 +00:00
|
|
|
return data->index >= data->rects.count(); // run once per each area
|
|
|
|
#endif
|
|
|
|
#ifdef KWIN_HAVE_XRENDER_COMPOSITING
|
2011-01-30 14:34:42 +00:00
|
|
|
if (effects->compositingType() == XRenderCompositing)
|
2008-02-25 11:32:21 +00:00
|
|
|
return data->index == 1; // run once
|
|
|
|
#endif
|
2008-06-27 12:06:29 +00:00
|
|
|
abort();
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2008-02-25 11:32:21 +00:00
|
|
|
|
|
|
|
void PaintClipper::Iterator::next()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2008-02-25 11:32:21 +00:00
|
|
|
data->index++;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2008-02-25 11:32:21 +00:00
|
|
|
|
|
|
|
QRect PaintClipper::Iterator::boundingRect() const
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
if (!clip())
|
2008-02-25 11:32:21 +00:00
|
|
|
return infiniteRegion();
|
|
|
|
#ifdef KWIN_HAVE_OPENGL_COMPOSITING
|
2011-01-30 14:34:42 +00:00
|
|
|
if (effects->compositingType() == OpenGLCompositing)
|
2008-02-25 11:32:21 +00:00
|
|
|
return data->rects[ data->index ];
|
|
|
|
#endif
|
|
|
|
#ifdef KWIN_HAVE_XRENDER_COMPOSITING
|
2011-01-30 14:34:42 +00:00
|
|
|
if (effects->compositingType() == XRenderCompositing)
|
2008-02-25 11:32:21 +00:00
|
|
|
return paintArea().boundingRect();
|
|
|
|
#endif
|
2008-06-27 12:06:29 +00:00
|
|
|
abort();
|
2008-07-07 20:56:56 +00:00
|
|
|
return infiniteRegion();
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2008-02-25 11:32:21 +00:00
|
|
|
|
2009-02-04 15:10:20 +00:00
|
|
|
/***************************************************************
|
|
|
|
Motion1D
|
|
|
|
***************************************************************/
|
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
Motion1D::Motion1D(double initial, double strength, double smoothness)
|
|
|
|
: Motion<double>(initial, strength, smoothness)
|
|
|
|
{
|
|
|
|
}
|
2009-02-04 15:10:20 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
Motion1D::Motion1D(const Motion1D &other)
|
|
|
|
: Motion<double>(other)
|
|
|
|
{
|
|
|
|
}
|
2009-02-04 15:10:20 +00:00
|
|
|
|
|
|
|
Motion1D::~Motion1D()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
}
|
2009-02-04 15:10:20 +00:00
|
|
|
|
|
|
|
/***************************************************************
|
|
|
|
Motion2D
|
|
|
|
***************************************************************/
|
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
Motion2D::Motion2D(QPointF initial, double strength, double smoothness)
|
|
|
|
: Motion<QPointF>(initial, strength, smoothness)
|
|
|
|
{
|
|
|
|
}
|
2009-02-04 15:10:20 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
Motion2D::Motion2D(const Motion2D &other)
|
|
|
|
: Motion<QPointF>(other)
|
|
|
|
{
|
|
|
|
}
|
2009-02-04 15:10:20 +00:00
|
|
|
|
|
|
|
Motion2D::~Motion2D()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
}
|
2009-02-04 15:10:20 +00:00
|
|
|
|
2008-09-22 13:03:00 +00:00
|
|
|
/***************************************************************
|
|
|
|
WindowMotionManager
|
|
|
|
***************************************************************/
|
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
WindowMotionManager::WindowMotionManager(bool useGlobalAnimationModifier)
|
|
|
|
: m_useGlobalAnimationModifier(useGlobalAnimationModifier)
|
2009-12-14 08:48:54 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
// TODO: Allow developer to modify motion attributes
|
|
|
|
} // TODO: What happens when the window moves by an external force?
|
2008-09-22 13:03:00 +00:00
|
|
|
|
|
|
|
WindowMotionManager::~WindowMotionManager()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
}
|
2008-09-22 13:03:00 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
void WindowMotionManager::manage(EffectWindow *w)
|
|
|
|
{
|
|
|
|
if (m_managedWindows.contains(w))
|
2008-09-22 13:03:00 +00:00
|
|
|
return;
|
|
|
|
|
2009-02-04 15:10:20 +00:00
|
|
|
double strength = 0.08;
|
|
|
|
double smoothness = 4.0;
|
2011-01-30 14:34:42 +00:00
|
|
|
if (m_useGlobalAnimationModifier && effects->animationTimeFactor()) {
|
|
|
|
// If the factor is == 0 then we just skip the calculation completely
|
2009-02-04 15:10:20 +00:00
|
|
|
strength = 0.08 / effects->animationTimeFactor();
|
|
|
|
smoothness = effects->animationTimeFactor() * 4.0;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2008-09-22 13:03:00 +00:00
|
|
|
|
2011-04-25 23:00:37 +00:00
|
|
|
WindowMotion &motion = m_managedWindows[ w ];
|
|
|
|
motion.translation.setStrength(strength);
|
|
|
|
motion.translation.setSmoothness(smoothness);
|
|
|
|
motion.scale.setStrength(strength * 1.33);
|
|
|
|
motion.scale.setSmoothness(smoothness / 2.0);
|
2008-09-22 13:03:00 +00:00
|
|
|
|
2011-04-25 23:00:37 +00:00
|
|
|
motion.translation.setValue(w->pos());
|
|
|
|
motion.scale.setValue(QPointF(1.0, 1.0));
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2008-09-22 13:03:00 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
void WindowMotionManager::unmanage(EffectWindow *w)
|
|
|
|
{
|
|
|
|
m_movingWindowsSet.remove(w);
|
|
|
|
m_managedWindows.remove(w);
|
|
|
|
}
|
2008-09-22 13:03:00 +00:00
|
|
|
|
|
|
|
void WindowMotionManager::unmanageAll()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2008-09-22 13:03:00 +00:00
|
|
|
m_managedWindows.clear();
|
2009-12-14 08:48:54 +00:00
|
|
|
m_movingWindowsSet.clear();
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2008-09-22 13:03:00 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
void WindowMotionManager::calculate(int time)
|
|
|
|
{
|
|
|
|
if (!effects->animationTimeFactor()) {
|
|
|
|
// Just skip it completely if the user wants no animation
|
2009-12-14 08:48:54 +00:00
|
|
|
m_movingWindowsSet.clear();
|
2008-09-22 13:03:00 +00:00
|
|
|
QHash<EffectWindow*, WindowMotion>::iterator it = m_managedWindows.begin();
|
2011-01-30 14:34:42 +00:00
|
|
|
for (; it != m_managedWindows.end(); it++) {
|
2008-09-22 13:03:00 +00:00
|
|
|
WindowMotion *motion = &it.value();
|
|
|
|
motion->translation.finish();
|
|
|
|
motion->scale.finish();
|
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2008-09-22 13:03:00 +00:00
|
|
|
|
|
|
|
QHash<EffectWindow*, WindowMotion>::iterator it = m_managedWindows.begin();
|
2011-01-30 14:34:42 +00:00
|
|
|
for (; it != m_managedWindows.end(); it++) {
|
2008-09-22 13:03:00 +00:00
|
|
|
WindowMotion *motion = &it.value();
|
2011-04-25 23:00:37 +00:00
|
|
|
EffectWindow *window = it.key();
|
|
|
|
int stopped = 0;
|
2008-09-22 13:03:00 +00:00
|
|
|
|
|
|
|
// TODO: What happens when distance() == 0 but we are still moving fast?
|
|
|
|
// TODO: Motion needs to be calculated from the window's center
|
|
|
|
|
2011-04-25 23:00:37 +00:00
|
|
|
Motion2D *trans = &motion->translation;
|
|
|
|
if (trans->distance().isNull())
|
|
|
|
++stopped;
|
|
|
|
else {
|
2011-01-30 14:34:42 +00:00
|
|
|
// Still moving
|
2011-04-25 23:00:37 +00:00
|
|
|
trans->calculate(time);
|
2011-06-20 19:56:56 +00:00
|
|
|
const short fx = trans->target().x() <= trans->startValue().x() ? -1 : 1;
|
|
|
|
const short fy = trans->target().y() <= trans->startValue().y() ? -1 : 1;
|
2011-04-25 23:00:37 +00:00
|
|
|
if (trans->distance().x()*fx/0.5 < 1.0 && trans->velocity().x()*fx/0.2 < 1.0 &&
|
|
|
|
trans->distance().y()*fy/0.5 < 1.0 && trans->velocity().y()*fy/0.2 < 1.0) {
|
2011-01-30 14:34:42 +00:00
|
|
|
// Hide tiny oscillations
|
2008-09-22 13:03:00 +00:00
|
|
|
motion->translation.finish();
|
2011-04-25 23:00:37 +00:00
|
|
|
++stopped;
|
2008-09-22 13:03:00 +00:00
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2008-09-22 13:03:00 +00:00
|
|
|
|
2011-04-25 23:00:37 +00:00
|
|
|
Motion2D *scale = &motion->scale;
|
|
|
|
if (scale->distance().isNull())
|
|
|
|
++stopped;
|
|
|
|
else {
|
2011-01-30 14:34:42 +00:00
|
|
|
// Still scaling
|
2011-04-25 23:00:37 +00:00
|
|
|
scale->calculate(time);
|
|
|
|
const short fx = scale->target().x() < 1.0 ? -1 : 1;
|
|
|
|
const short fy = scale->target().y() < 1.0 ? -1 : 1;
|
|
|
|
if (scale->distance().x()*fx/0.001 < 1.0 && scale->velocity().x()*fx/0.05 < 1.0 &&
|
|
|
|
scale->distance().y()*fy/0.001 < 1.0 && scale->velocity().y()*fy/0.05 < 1.0) {
|
2011-01-30 14:34:42 +00:00
|
|
|
// Hide tiny oscillations
|
2008-09-22 13:03:00 +00:00
|
|
|
motion->scale.finish();
|
2011-04-25 23:00:37 +00:00
|
|
|
++stopped;
|
2008-09-22 13:03:00 +00:00
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2008-09-22 13:03:00 +00:00
|
|
|
|
|
|
|
// We just finished this window's motion
|
2011-04-25 23:00:37 +00:00
|
|
|
if (stopped == 2)
|
2011-01-30 14:34:42 +00:00
|
|
|
m_movingWindowsSet.remove(it.key());
|
2008-09-22 13:03:00 +00:00
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2008-09-22 13:03:00 +00:00
|
|
|
|
2008-09-29 02:25:02 +00:00
|
|
|
void WindowMotionManager::reset()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2011-04-25 23:00:37 +00:00
|
|
|
QHash<EffectWindow*, WindowMotion>::iterator it = m_managedWindows.begin();
|
|
|
|
for (; it != m_managedWindows.end(); it++) {
|
|
|
|
WindowMotion *motion = &it.value();
|
|
|
|
EffectWindow *window = it.key();
|
|
|
|
motion->translation.setTarget(window->pos());
|
|
|
|
motion->translation.finish();
|
|
|
|
motion->scale.setTarget(QPointF(1.0, 1.0));
|
|
|
|
motion->scale.finish();
|
2008-09-29 02:25:02 +00:00
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2008-09-29 02:25:02 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
void WindowMotionManager::reset(EffectWindow *w)
|
|
|
|
{
|
2011-04-25 23:00:37 +00:00
|
|
|
QHash<EffectWindow*, WindowMotion>::iterator it = m_managedWindows.find(w);
|
|
|
|
if (it == m_managedWindows.end())
|
2008-09-29 02:25:02 +00:00
|
|
|
return;
|
|
|
|
|
2011-04-25 23:00:37 +00:00
|
|
|
WindowMotion *motion = &it.value();
|
|
|
|
motion->translation.setTarget(w->pos());
|
|
|
|
motion->translation.finish();
|
|
|
|
motion->scale.setTarget(QPointF(1.0, 1.0));
|
|
|
|
motion->scale.finish();
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2008-09-29 02:25:02 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
void WindowMotionManager::apply(EffectWindow *w, WindowPaintData &data)
|
|
|
|
{
|
2011-04-25 23:00:37 +00:00
|
|
|
QHash<EffectWindow*, WindowMotion>::iterator it = m_managedWindows.find(w);
|
|
|
|
if (it == m_managedWindows.end())
|
2008-09-22 13:03:00 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
// TODO: Take into account existing scale so that we can work with multiple managers (E.g. Present windows + grid)
|
2011-04-25 23:00:37 +00:00
|
|
|
WindowMotion *motion = &it.value();
|
|
|
|
data.xTranslate += motion->translation.value().x() - w->x();
|
|
|
|
data.yTranslate += motion->translation.value().y() - w->y();
|
|
|
|
data.xScale *= motion->scale.value().x();
|
|
|
|
data.yScale *= motion->scale.value().y();
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2008-09-22 13:03:00 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
void WindowMotionManager::moveWindow(EffectWindow *w, QPoint target, double scale, double yScale)
|
|
|
|
{
|
2011-04-25 23:00:37 +00:00
|
|
|
QHash<EffectWindow*, WindowMotion>::iterator it = m_managedWindows.find(w);
|
|
|
|
if (it == m_managedWindows.end())
|
2008-09-22 13:03:00 +00:00
|
|
|
abort(); // Notify the effect author that they did something wrong
|
|
|
|
|
2011-04-25 23:00:37 +00:00
|
|
|
WindowMotion *motion = &it.value();
|
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
if (yScale == 0.0)
|
2008-09-22 13:03:00 +00:00
|
|
|
yScale = scale;
|
2011-01-30 14:34:42 +00:00
|
|
|
QPointF scalePoint(scale, yScale);
|
2008-09-22 13:03:00 +00:00
|
|
|
|
2011-04-25 23:00:37 +00:00
|
|
|
if (motion->translation.value() == target && motion->scale.value() == scalePoint)
|
2008-09-22 13:03:00 +00:00
|
|
|
return; // Window already at that position
|
|
|
|
|
2011-04-25 23:00:37 +00:00
|
|
|
motion->translation.setTarget(target);
|
|
|
|
motion->scale.setTarget(scalePoint);
|
2008-09-22 13:03:00 +00:00
|
|
|
|
2009-12-14 08:48:54 +00:00
|
|
|
m_movingWindowsSet << w;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2008-09-22 13:03:00 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
QRectF WindowMotionManager::transformedGeometry(EffectWindow *w) const
|
|
|
|
{
|
2011-04-25 23:00:37 +00:00
|
|
|
QHash<EffectWindow*, WindowMotion>::const_iterator it = m_managedWindows.constFind(w);
|
|
|
|
if (it == m_managedWindows.end())
|
|
|
|
return w->geometry();
|
|
|
|
|
|
|
|
const WindowMotion *motion = &it.value();
|
2011-01-30 14:34:42 +00:00
|
|
|
QRectF geometry(w->geometry());
|
2008-09-22 13:03:00 +00:00
|
|
|
|
|
|
|
// TODO: Take into account existing scale so that we can work with multiple managers (E.g. Present windows + grid)
|
2011-04-25 23:00:37 +00:00
|
|
|
geometry.moveTo(motion->translation.value());
|
|
|
|
geometry.setWidth(geometry.width() * motion->scale.value().x());
|
|
|
|
geometry.setHeight(geometry.height() * motion->scale.value().y());
|
2008-09-22 13:03:00 +00:00
|
|
|
|
|
|
|
return geometry;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2008-09-22 13:03:00 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
void WindowMotionManager::setTransformedGeometry(EffectWindow *w, const QRectF &geometry)
|
|
|
|
{
|
2011-04-25 23:00:37 +00:00
|
|
|
QHash<EffectWindow*, WindowMotion>::iterator it = m_managedWindows.find(w);
|
|
|
|
if (it == m_managedWindows.end())
|
|
|
|
return;
|
|
|
|
WindowMotion *motion = &it.value();
|
|
|
|
motion->translation.setValue(geometry.topLeft());
|
|
|
|
motion->scale.setValue(QPointF(geometry.width() / qreal(w->width()), geometry.height() / qreal(w->height())));
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2010-03-18 09:27:01 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
QRectF WindowMotionManager::targetGeometry(EffectWindow *w) const
|
|
|
|
{
|
2011-04-25 23:00:37 +00:00
|
|
|
QHash<EffectWindow*, WindowMotion>::const_iterator it = m_managedWindows.constFind(w);
|
|
|
|
if (it == m_managedWindows.end())
|
|
|
|
return w->geometry();
|
|
|
|
|
|
|
|
const WindowMotion *motion = &it.value();
|
2011-01-30 14:34:42 +00:00
|
|
|
QRectF geometry(w->geometry());
|
2009-02-22 13:04:16 +00:00
|
|
|
|
|
|
|
// TODO: Take into account existing scale so that we can work with multiple managers (E.g. Present windows + grid)
|
2011-04-25 23:00:37 +00:00
|
|
|
geometry.moveTo(motion->translation.target());
|
|
|
|
geometry.setWidth(geometry.width() * motion->scale.target().x());
|
|
|
|
geometry.setHeight(geometry.height() * motion->scale.target().y());
|
2009-02-22 13:04:16 +00:00
|
|
|
|
|
|
|
return geometry;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2009-02-22 13:04:16 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
EffectWindow* WindowMotionManager::windowAtPoint(QPoint point, bool useStackingOrder) const
|
|
|
|
{
|
|
|
|
Q_UNUSED(useStackingOrder);
|
2008-09-22 13:03:00 +00:00
|
|
|
// TODO: Stacking order uses EffectsHandler::stackingOrder() then filters by m_managedWindows
|
2009-12-08 08:37:01 +00:00
|
|
|
QHash< EffectWindow*, WindowMotion >::ConstIterator it = m_managedWindows.constBegin();
|
2011-01-30 14:34:42 +00:00
|
|
|
while (it != m_managedWindows.constEnd()) {
|
|
|
|
if (transformedGeometry(it.key()).contains(point))
|
2009-12-08 08:37:01 +00:00
|
|
|
return it.key();
|
|
|
|
++it;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2008-09-22 13:03:00 +00:00
|
|
|
|
|
|
|
return NULL;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2008-09-22 13:03:00 +00:00
|
|
|
|
2010-08-07 14:08:34 +00:00
|
|
|
/***************************************************************
|
|
|
|
EffectFramePrivate
|
|
|
|
***************************************************************/
|
|
|
|
class EffectFramePrivate
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
EffectFramePrivate();
|
|
|
|
~EffectFramePrivate();
|
2010-08-07 14:08:34 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
bool crossFading;
|
|
|
|
qreal crossFadeProgress;
|
|
|
|
};
|
2010-08-07 14:08:34 +00:00
|
|
|
|
|
|
|
EffectFramePrivate::EffectFramePrivate()
|
2011-01-30 14:34:42 +00:00
|
|
|
: crossFading(false)
|
|
|
|
, crossFadeProgress(1.0)
|
|
|
|
{
|
|
|
|
}
|
2010-08-07 14:08:34 +00:00
|
|
|
|
|
|
|
EffectFramePrivate::~EffectFramePrivate()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
}
|
2010-08-07 14:08:34 +00:00
|
|
|
|
2009-02-21 04:53:13 +00:00
|
|
|
/***************************************************************
|
|
|
|
EffectFrame
|
|
|
|
***************************************************************/
|
2010-07-18 16:32:37 +00:00
|
|
|
EffectFrame::EffectFrame()
|
2011-01-30 14:34:42 +00:00
|
|
|
: d(new EffectFramePrivate)
|
|
|
|
{
|
|
|
|
}
|
2009-02-21 04:53:13 +00:00
|
|
|
|
|
|
|
EffectFrame::~EffectFrame()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2010-08-07 14:08:34 +00:00
|
|
|
delete d;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2010-08-07 14:08:34 +00:00
|
|
|
|
|
|
|
qreal EffectFrame::crossFadeProgress() const
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2010-08-07 14:08:34 +00:00
|
|
|
return d->crossFadeProgress;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2010-08-07 14:08:34 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
void EffectFrame::setCrossFadeProgress(qreal progress)
|
|
|
|
{
|
2010-08-07 14:08:34 +00:00
|
|
|
d->crossFadeProgress = progress;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2010-08-07 14:08:34 +00:00
|
|
|
|
|
|
|
bool EffectFrame::isCrossFade() const
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2010-08-07 14:08:34 +00:00
|
|
|
return d->crossFading;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2010-08-07 14:08:34 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
void EffectFrame::enableCrossFade(bool enable)
|
|
|
|
{
|
2010-08-07 14:08:34 +00:00
|
|
|
d->crossFading = enable;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2009-02-21 04:53:13 +00:00
|
|
|
|
2007-04-29 17:35:43 +00:00
|
|
|
} // namespace
|
2011-02-25 19:25:21 +00:00
|
|
|
|
|
|
|
#include "kwineffects.moc"
|