2009-02-15 10:34:31 +00:00
|
|
|
/********************************************************************
|
|
|
|
KWin - the KDE window manager
|
|
|
|
This file is part of the KDE project.
|
|
|
|
|
|
|
|
Copyright (C) 2009 Lucas Murray <lmurray@undefinedfire.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 "snaphelper.h"
|
|
|
|
|
|
|
|
#include "kwinglutils.h"
|
2012-05-26 07:31:04 +00:00
|
|
|
#ifdef KWIN_HAVE_XRENDER_COMPOSITING
|
2012-03-09 06:21:28 +00:00
|
|
|
#include "kwinxrenderutils.h"
|
2012-05-26 07:31:04 +00:00
|
|
|
#endif
|
2009-02-15 10:34:31 +00:00
|
|
|
|
|
|
|
namespace KWin
|
|
|
|
{
|
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
KWIN_EFFECT(snaphelper, SnapHelperEffect)
|
2009-02-15 10:34:31 +00:00
|
|
|
|
|
|
|
SnapHelperEffect::SnapHelperEffect()
|
2011-01-30 14:34:42 +00:00
|
|
|
: m_active(false)
|
|
|
|
, m_window(NULL)
|
|
|
|
{
|
2011-03-14 21:50:05 +00:00
|
|
|
m_timeline.setCurveShape(QTimeLine::LinearCurve);
|
2011-01-30 14:34:42 +00:00
|
|
|
reconfigure(ReconfigureAll);
|
2012-01-29 11:29:24 +00:00
|
|
|
connect(effects, SIGNAL(windowClosed(KWin::EffectWindow*)), this, SLOT(slotWindowClosed(KWin::EffectWindow*)));
|
|
|
|
connect(effects, SIGNAL(windowStartUserMovedResized(KWin::EffectWindow*)), this, SLOT(slotWindowStartUserMovedResized(KWin::EffectWindow*)));
|
|
|
|
connect(effects, SIGNAL(windowFinishUserMovedResized(KWin::EffectWindow*)), this, SLOT(slotWindowFinishUserMovedResized(KWin::EffectWindow*)));
|
2012-12-29 15:27:08 +00:00
|
|
|
connect(effects, SIGNAL(windowGeometryShapeChanged(KWin::EffectWindow*, const QRect&)), this, SLOT(slotWindowResized(KWin::EffectWindow*, const QRect&)));
|
2009-02-15 10:34:31 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
/*if ( effects->compositingType() == XRenderCompositing )
|
2009-02-15 10:34:31 +00:00
|
|
|
{
|
|
|
|
XGCValues gcattr;
|
|
|
|
// TODO: Foreground color
|
|
|
|
gcattr.line_width = 4;
|
|
|
|
m_gc = XCreateGC( display(), rootWindow(), GCLineWidth, &gcattr );
|
|
|
|
}*/
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2009-02-15 10:34:31 +00:00
|
|
|
|
|
|
|
SnapHelperEffect::~SnapHelperEffect()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
//if ( effects->compositingType() == XRenderCompositing )
|
2009-02-15 10:34:31 +00:00
|
|
|
// XFreeGC( display(), m_gc );
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2009-02-15 10:34:31 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
void SnapHelperEffect::reconfigure(ReconfigureFlags)
|
|
|
|
{
|
|
|
|
m_timeline.setDuration(animationTime(250));
|
|
|
|
}
|
2009-02-15 10:34:31 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
void SnapHelperEffect::prePaintScreen(ScreenPrePaintData &data, int time)
|
|
|
|
{
|
2011-03-14 21:50:05 +00:00
|
|
|
double oldValue = m_timeline.currentValue();
|
2011-01-30 14:34:42 +00:00
|
|
|
if (m_active)
|
2011-03-14 21:50:05 +00:00
|
|
|
m_timeline.setCurrentTime(m_timeline.currentTime() + time);
|
2009-02-15 10:34:31 +00:00
|
|
|
else
|
2011-03-14 21:50:05 +00:00
|
|
|
m_timeline.setCurrentTime(m_timeline.currentTime() - time);
|
|
|
|
if (oldValue != m_timeline.currentValue())
|
2009-02-15 10:34:31 +00:00
|
|
|
effects->addRepaintFull();
|
2011-01-30 14:34:42 +00:00
|
|
|
effects->prePaintScreen(data, time);
|
|
|
|
}
|
2009-02-15 10:34:31 +00:00
|
|
|
|
|
|
|
void SnapHelperEffect::postPaintScreen()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2009-02-15 10:34:31 +00:00
|
|
|
effects->postPaintScreen();
|
2011-03-14 21:50:05 +00:00
|
|
|
if (m_timeline.currentValue() != 0.0) {
|
2011-01-30 14:34:42 +00:00
|
|
|
// Display the guide
|
2012-09-20 09:33:32 +00:00
|
|
|
if (effects->isOpenGLCompositing()) {
|
2010-12-11 14:56:21 +00:00
|
|
|
GLVertexBuffer *vbo = GLVertexBuffer::streamingBuffer();
|
|
|
|
vbo->reset();
|
|
|
|
vbo->setUseColor(true);
|
2012-09-21 09:25:08 +00:00
|
|
|
ShaderBinder binder(ShaderManager::ColorShader);
|
2011-01-30 14:34:42 +00:00
|
|
|
glEnable(GL_BLEND);
|
|
|
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
2009-02-15 10:34:31 +00:00
|
|
|
|
2010-12-08 18:25:15 +00:00
|
|
|
QColor color;
|
|
|
|
color.setRedF(0.5);
|
|
|
|
color.setGreenF(0.5);
|
|
|
|
color.setBlueF(0.5);
|
2011-03-14 21:50:05 +00:00
|
|
|
color.setAlphaF(m_timeline.currentValue() * 0.5);
|
2010-12-11 14:56:21 +00:00
|
|
|
vbo->setColor(color);
|
2011-01-30 14:34:42 +00:00
|
|
|
glLineWidth(4.0);
|
2010-12-08 18:25:15 +00:00
|
|
|
QVector<float> verts;
|
2011-01-30 14:34:42 +00:00
|
|
|
verts.reserve(effects->numScreens() * 24);
|
2012-12-29 15:27:08 +00:00
|
|
|
for (int i = 0; i < effects->numScreens(); ++i) {
|
2011-01-30 14:34:42 +00:00
|
|
|
const QRect& rect = effects->clientArea(ScreenArea, i, 0);
|
2010-12-08 18:25:15 +00:00
|
|
|
int midX = rect.x() + rect.width() / 2;
|
|
|
|
int midY = rect.y() + rect.height() / 2 ;
|
|
|
|
int halfWidth = m_window->width() / 2;
|
|
|
|
int halfHeight = m_window->height() / 2;
|
|
|
|
|
|
|
|
// Center lines
|
|
|
|
verts << rect.x() + rect.width() / 2 << rect.y();
|
|
|
|
verts << rect.x() + rect.width() / 2 << rect.y() + rect.height();
|
|
|
|
verts << rect.x() << rect.y() + rect.height() / 2;
|
|
|
|
verts << rect.x() + rect.width() << rect.y() + rect.height() / 2;
|
|
|
|
|
|
|
|
// Window outline
|
|
|
|
// The +/- 2 is to prevent line overlap
|
|
|
|
verts << midX - halfWidth + 2 << midY - halfHeight;
|
|
|
|
verts << midX + halfWidth + 2 << midY - halfHeight;
|
|
|
|
verts << midX + halfWidth << midY - halfHeight + 2;
|
|
|
|
verts << midX + halfWidth << midY + halfHeight + 2;
|
|
|
|
verts << midX + halfWidth - 2 << midY + halfHeight;
|
|
|
|
verts << midX - halfWidth - 2 << midY + halfHeight;
|
|
|
|
verts << midX - halfWidth << midY + halfHeight - 2;
|
|
|
|
verts << midX - halfWidth << midY - halfHeight - 2;
|
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
vbo->setData(verts.count() / 2, 2, verts.data(), NULL);
|
2010-12-11 14:56:21 +00:00
|
|
|
vbo->render(GL_LINES);
|
2009-02-15 10:34:31 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
glDisable(GL_BLEND);
|
|
|
|
glLineWidth(1.0);
|
|
|
|
}
|
2012-03-09 06:21:28 +00:00
|
|
|
if ( effects->compositingType() == XRenderCompositing ) {
|
2012-05-26 07:31:04 +00:00
|
|
|
#ifdef KWIN_HAVE_XRENDER_COMPOSITING
|
2012-12-29 15:27:08 +00:00
|
|
|
for (int i = 0; i < effects->numScreens(); ++i) {
|
2009-02-15 10:34:31 +00:00
|
|
|
const QRect& rect = effects->clientArea( ScreenArea, i, 0 );
|
|
|
|
int midX = rect.x() + rect.width() / 2;
|
|
|
|
int midY = rect.y() + rect.height() / 2 ;
|
|
|
|
int halfWidth = m_window->width() / 2;
|
|
|
|
int halfHeight = m_window->height() / 2;
|
|
|
|
|
2012-03-09 06:21:28 +00:00
|
|
|
XRectangle rects[6];
|
2009-02-15 10:34:31 +00:00
|
|
|
// Center lines
|
2012-03-09 06:21:28 +00:00
|
|
|
rects[0].x = rect.x() + rect.width() / 2 - 2;
|
|
|
|
rects[0].y = rect.y();
|
|
|
|
rects[0].width = 4;
|
|
|
|
rects[0].height = rect.height();
|
|
|
|
rects[1].x = rect.x();
|
|
|
|
rects[1].y = rect.y() + rect.height() / 2 - 2;
|
|
|
|
rects[1].width = rect.width();
|
|
|
|
rects[1].height = 4;
|
2009-02-15 10:34:31 +00:00
|
|
|
|
|
|
|
// Window outline
|
2012-03-09 06:21:28 +00:00
|
|
|
// The +/- 4 is to prevent line overlap
|
|
|
|
rects[2].x = midX - halfWidth + 4;
|
|
|
|
rects[2].y = midY - halfHeight;
|
|
|
|
rects[2].width = 2*halfWidth - 4;
|
|
|
|
rects[2].height = 4;
|
|
|
|
rects[3].x = midX + halfWidth - 4;
|
|
|
|
rects[3].y = midY - halfHeight + 4;
|
|
|
|
rects[3].width = 4;
|
|
|
|
rects[3].height = 2*halfHeight - 4;
|
|
|
|
rects[4].x = midX - halfWidth;
|
|
|
|
rects[4].y = midY + halfHeight - 4;
|
|
|
|
rects[4].width = 2*halfWidth - 4;
|
|
|
|
rects[4].height = 4;
|
|
|
|
rects[5].x = midX - halfWidth;
|
|
|
|
rects[5].y = midY - halfHeight;
|
|
|
|
rects[5].width = 4;
|
|
|
|
rects[5].height = 2*halfHeight - 4;
|
|
|
|
|
|
|
|
XRenderColor c = preMultiply(QColor(128, 128, 128, m_timeline.currentValue()*128));
|
|
|
|
XRenderFillRectangles(display(), PictOpOver, effects->xrenderBufferPicture(), &c, rects, 6);
|
|
|
|
}
|
2012-05-26 07:31:04 +00:00
|
|
|
#endif
|
2012-03-09 06:21:28 +00:00
|
|
|
}
|
2011-06-02 08:08:51 +00:00
|
|
|
} else if (m_window && !m_active) {
|
2011-01-30 14:34:42 +00:00
|
|
|
if (m_window->isDeleted())
|
2009-07-28 02:22:32 +00:00
|
|
|
m_window->unrefWindow();
|
2009-02-15 10:34:31 +00:00
|
|
|
m_window = NULL;
|
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2009-02-15 10:34:31 +00:00
|
|
|
|
2011-02-27 08:25:45 +00:00
|
|
|
void SnapHelperEffect::slotWindowClosed(EffectWindow* w)
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
if (m_window == w) {
|
2009-07-28 02:22:32 +00:00
|
|
|
m_window->refWindow();
|
2009-02-15 10:34:31 +00:00
|
|
|
m_active = false;
|
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2009-02-15 10:34:31 +00:00
|
|
|
|
2011-03-13 11:41:30 +00:00
|
|
|
void SnapHelperEffect::slotWindowStartUserMovedResized(EffectWindow *w)
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2011-03-13 11:41:30 +00:00
|
|
|
if (w->isMovable()) {
|
2009-02-15 10:34:31 +00:00
|
|
|
m_active = true;
|
|
|
|
m_window = w;
|
|
|
|
effects->addRepaintFull();
|
2011-03-13 11:41:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SnapHelperEffect::slotWindowFinishUserMovedResized(EffectWindow *w)
|
|
|
|
{
|
|
|
|
Q_UNUSED(w)
|
|
|
|
if (m_active) {
|
2009-02-15 10:34:31 +00:00
|
|
|
m_active = false;
|
2011-03-13 11:41:30 +00:00
|
|
|
effects->addRepaintFull();
|
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2009-02-15 10:34:31 +00:00
|
|
|
|
2012-12-29 15:27:08 +00:00
|
|
|
void SnapHelperEffect::slotWindowResized(KWin::EffectWindow *w, const QRect &oldRect)
|
|
|
|
{
|
|
|
|
if (w == m_window) {
|
|
|
|
QRect r(oldRect);
|
|
|
|
for (int i = 0; i < effects->numScreens(); ++i) {
|
|
|
|
r.moveCenter(effects->clientArea( ScreenArea, i, 0 ).center());
|
|
|
|
effects->addRepaint(r);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-08-27 09:21:31 +00:00
|
|
|
bool SnapHelperEffect::isActive() const
|
|
|
|
{
|
2011-12-15 19:10:13 +00:00
|
|
|
return m_active || m_timeline.currentValue() != 0.0;
|
2011-08-27 09:21:31 +00:00
|
|
|
}
|
|
|
|
|
2009-02-15 10:34:31 +00:00
|
|
|
} // namespace
|