2009-06-25 14:41:45 +00:00
|
|
|
/********************************************************************
|
|
|
|
KWin - the KDE window manager
|
|
|
|
This file is part of the KDE project.
|
|
|
|
|
|
|
|
Copyright (C) 2009 Martin Gräßlin <kde@martin-graesslin.com>
|
|
|
|
|
|
|
|
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/>.
|
|
|
|
*********************************************************************/
|
|
|
|
|
|
|
|
#include "resize.h"
|
|
|
|
|
2010-12-08 17:39:36 +00:00
|
|
|
#include <kwinglutils.h>
|
2009-06-25 14:41:45 +00:00
|
|
|
#ifdef KWIN_HAVE_XRENDER_COMPOSITING
|
|
|
|
#include <X11/Xlib.h>
|
|
|
|
#include <X11/extensions/Xrender.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <KColorScheme>
|
2011-02-17 18:35:08 +00:00
|
|
|
#include <KDE/KConfigGroup>
|
2009-06-25 14:41:45 +00:00
|
|
|
|
2012-05-28 10:00:31 +00:00
|
|
|
#include <QtGui/QVector2D>
|
|
|
|
|
2009-06-25 14:41:45 +00:00
|
|
|
namespace KWin
|
|
|
|
{
|
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
KWIN_EFFECT(resize, ResizeEffect)
|
2009-06-25 14:41:45 +00:00
|
|
|
|
|
|
|
ResizeEffect::ResizeEffect()
|
2011-01-30 14:34:42 +00:00
|
|
|
: m_active(false)
|
|
|
|
, m_resizeWindow(0)
|
|
|
|
{
|
|
|
|
reconfigure(ReconfigureAll);
|
2012-01-29 11:29:24 +00:00
|
|
|
connect(effects, SIGNAL(windowStartUserMovedResized(KWin::EffectWindow*)), this, SLOT(slotWindowStartUserMovedResized(KWin::EffectWindow*)));
|
|
|
|
connect(effects, SIGNAL(windowStepUserMovedResized(KWin::EffectWindow*,QRect)), this, SLOT(slotWindowStepUserMovedResized(KWin::EffectWindow*,QRect)));
|
|
|
|
connect(effects, SIGNAL(windowFinishUserMovedResized(KWin::EffectWindow*)), this, SLOT(slotWindowFinishUserMovedResized(KWin::EffectWindow*)));
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2009-06-25 14:41:45 +00:00
|
|
|
|
|
|
|
ResizeEffect::~ResizeEffect()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
}
|
2009-06-25 14:41:45 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
void ResizeEffect::prePaintScreen(ScreenPrePaintData& data, int time)
|
|
|
|
{
|
|
|
|
if (m_active) {
|
2009-06-25 14:41:45 +00:00
|
|
|
data.mask |= PAINT_SCREEN_WITH_TRANSFORMED_WINDOWS;
|
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
effects->prePaintScreen(data, time);
|
|
|
|
}
|
2009-06-25 14:41:45 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
void ResizeEffect::prePaintWindow(EffectWindow* w, WindowPrePaintData& data, int time)
|
|
|
|
{
|
|
|
|
if (m_active && w == m_resizeWindow)
|
2010-04-25 18:40:04 +00:00
|
|
|
data.mask |= PAINT_WINDOW_TRANSFORMED;
|
2011-01-30 14:34:42 +00:00
|
|
|
effects->prePaintWindow(w, data, time);
|
|
|
|
}
|
2010-04-25 18:40:04 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
void ResizeEffect::paintWindow(EffectWindow* w, int mask, QRegion region, WindowPaintData& data)
|
|
|
|
{
|
|
|
|
if (m_active && w == m_resizeWindow) {
|
|
|
|
if (m_features & TextureScale) {
|
2012-05-28 12:45:46 +00:00
|
|
|
data += (m_currentGeometry.topLeft() - m_originalGeometry.topLeft());
|
2012-05-28 10:00:31 +00:00
|
|
|
data *= QVector2D(m_currentGeometry.width()/m_originalGeometry.width(),
|
|
|
|
m_currentGeometry.height()/m_originalGeometry.height());
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
|
|
|
effects->paintWindow(w, mask, region, data);
|
2010-04-25 18:40:04 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
if (m_features & Outline) {
|
|
|
|
QRegion intersection = m_originalGeometry.intersected(m_currentGeometry);
|
|
|
|
QRegion paintRegion = QRegion(m_originalGeometry).united(m_currentGeometry).subtracted(intersection);
|
2010-04-25 18:40:04 +00:00
|
|
|
float alpha = 0.8f;
|
2011-01-30 14:34:42 +00:00
|
|
|
QColor color = KColorScheme(QPalette::Normal, KColorScheme::Selection).background().color();
|
2009-06-25 14:41:45 +00:00
|
|
|
|
2010-12-08 17:39:36 +00:00
|
|
|
if (effects->compositingType() == OpenGLCompositing) {
|
2010-12-11 14:58:52 +00:00
|
|
|
GLVertexBuffer *vbo = GLVertexBuffer::streamingBuffer();
|
|
|
|
vbo->reset();
|
|
|
|
vbo->setUseColor(true);
|
2010-12-11 09:28:37 +00:00
|
|
|
if (ShaderManager::instance()->isValid()) {
|
|
|
|
ShaderManager::instance()->pushShader(ShaderManager::ColorShader);
|
2010-12-08 17:39:36 +00:00
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
glEnable(GL_BLEND);
|
|
|
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
2010-12-08 17:39:36 +00:00
|
|
|
color.setAlphaF(alpha);
|
2010-12-11 14:58:52 +00:00
|
|
|
vbo->setColor(color);
|
2010-12-08 17:39:36 +00:00
|
|
|
QVector<float> verts;
|
2011-01-30 14:34:42 +00:00
|
|
|
verts.reserve(paintRegion.rects().count() * 12);
|
|
|
|
foreach (const QRect & r, paintRegion.rects()) {
|
2010-12-08 17:39:36 +00:00
|
|
|
verts << r.x() + r.width() << r.y();
|
|
|
|
verts << r.x() << r.y();
|
|
|
|
verts << r.x() << r.y() + r.height();
|
|
|
|
verts << r.x() << r.y() + r.height();
|
|
|
|
verts << r.x() + r.width() << r.y() + r.height();
|
|
|
|
verts << r.x() + r.width() << r.y();
|
2009-06-25 14:41:45 +00:00
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
vbo->setData(verts.count() / 2, 2, verts.data(), NULL);
|
2010-12-11 14:58:52 +00:00
|
|
|
vbo->render(GL_TRIANGLES);
|
2010-12-11 09:28:37 +00:00
|
|
|
if (ShaderManager::instance()->isValid()) {
|
|
|
|
ShaderManager::instance()->popShader();
|
2010-12-08 17:39:36 +00:00
|
|
|
}
|
|
|
|
glDisable(GL_BLEND);
|
|
|
|
}
|
2009-06-25 14:41:45 +00:00
|
|
|
|
|
|
|
#ifdef KWIN_HAVE_XRENDER_COMPOSITING
|
2011-01-30 14:34:42 +00:00
|
|
|
if (effects->compositingType() == XRenderCompositing) {
|
2010-04-25 18:40:04 +00:00
|
|
|
XRenderColor col;
|
2011-01-30 14:34:42 +00:00
|
|
|
col.alpha = int(alpha * 0xffff);
|
|
|
|
col.red = int(alpha * 0xffff * color.red() / 255);
|
|
|
|
col.green = int(alpha * 0xffff * color.green() / 255);
|
|
|
|
col.blue = int(alpha * 0xffff * color.blue() / 255);
|
|
|
|
foreach (const QRect & r, paintRegion.rects())
|
|
|
|
XRenderFillRectangle(display(), PictOpOver, effects->xrenderBufferPicture(),
|
|
|
|
&col, r.x(), r.y(), r.width(), r.height());
|
2010-04-25 18:40:04 +00:00
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
#endif
|
2009-06-25 14:41:45 +00:00
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
} else
|
|
|
|
effects->paintWindow(w, mask, region, data);
|
|
|
|
}
|
2010-04-25 18:40:04 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
void ResizeEffect::reconfigure(ReconfigureFlags)
|
|
|
|
{
|
2010-04-25 18:40:04 +00:00
|
|
|
KConfigGroup conf = effects->effectConfig("Resize");
|
|
|
|
m_features = 0;
|
2011-01-30 14:34:42 +00:00
|
|
|
if (conf.readEntry("TextureScale", true))
|
2010-04-25 18:40:04 +00:00
|
|
|
m_features |= TextureScale;
|
2011-01-30 14:34:42 +00:00
|
|
|
if (conf.readEntry("Outline", false))
|
2010-04-25 18:40:04 +00:00
|
|
|
m_features |= Outline;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2009-06-25 14:41:45 +00:00
|
|
|
|
2011-03-13 11:41:30 +00:00
|
|
|
void ResizeEffect::slotWindowStartUserMovedResized(EffectWindow *w)
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2011-03-13 11:41:30 +00:00
|
|
|
if (w->isUserResize() && !w->isUserMove()) {
|
2009-06-25 14:41:45 +00:00
|
|
|
m_active = true;
|
|
|
|
m_resizeWindow = w;
|
2010-04-25 18:40:04 +00:00
|
|
|
m_originalGeometry = w->geometry();
|
2009-10-30 14:22:33 +00:00
|
|
|
m_currentGeometry = w->geometry();
|
2009-06-25 14:41:45 +00:00
|
|
|
w->addRepaintFull();
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2011-03-13 11:41:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ResizeEffect::slotWindowFinishUserMovedResized(EffectWindow *w)
|
|
|
|
{
|
|
|
|
if (m_active && w == m_resizeWindow) {
|
2009-06-25 14:41:45 +00:00
|
|
|
m_active = false;
|
|
|
|
m_resizeWindow = NULL;
|
|
|
|
effects->addRepaintFull();
|
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2009-06-25 14:41:45 +00:00
|
|
|
|
2011-03-13 11:41:30 +00:00
|
|
|
void ResizeEffect::slotWindowStepUserMovedResized(EffectWindow *w, const QRect &geometry)
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2011-03-13 11:41:30 +00:00
|
|
|
if (m_active && w == m_resizeWindow) {
|
2009-10-30 14:22:33 +00:00
|
|
|
m_currentGeometry = geometry;
|
|
|
|
effects->addRepaintFull();
|
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2009-10-30 14:22:33 +00:00
|
|
|
|
2009-06-25 14:41:45 +00:00
|
|
|
} // namespace
|