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"
|
|
|
|
//#include "kwinxrenderutils.h"
|
|
|
|
|
|
|
|
namespace KWin
|
|
|
|
{
|
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
KWIN_EFFECT(snaphelper, SnapHelperEffect)
|
|
|
|
KWIN_EFFECT_SUPPORTED(snaphelper, SnapHelperEffect::supported())
|
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);
|
2011-02-27 08:25:45 +00:00
|
|
|
connect(effects, SIGNAL(windowClosed(EffectWindow*)), this, SLOT(slotWindowClosed(EffectWindow*)));
|
2011-03-13 11:41:30 +00:00
|
|
|
connect(effects, SIGNAL(windowStartUserMovedResized(EffectWindow*)), this, SLOT(slotWindowStartUserMovedResized(EffectWindow*)));
|
|
|
|
connect(effects, SIGNAL(windowFinishUserMovedResized(EffectWindow*)), this, SLOT(slotWindowFinishUserMovedResized(EffectWindow*)));
|
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
|
|
|
|
|
|
|
bool SnapHelperEffect::supported()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2009-02-15 10:34:31 +00:00
|
|
|
return effects->compositingType() == OpenGLCompositing;
|
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::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
|
|
|
|
if (effects->compositingType() == OpenGLCompositing) {
|
2010-12-08 18:25:15 +00:00
|
|
|
#ifndef KWIN_HAVE_OPENGLES
|
2011-01-30 14:34:42 +00:00
|
|
|
glPushAttrib(GL_CURRENT_BIT | GL_ENABLE_BIT);
|
2010-12-08 18:25:15 +00:00
|
|
|
#endif
|
2010-12-11 14:56:21 +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 18:25:15 +00:00
|
|
|
}
|
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);
|
2010-12-08 18:25:15 +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);
|
2010-12-11 09:28:37 +00:00
|
|
|
if (ShaderManager::instance()->isValid()) {
|
|
|
|
ShaderManager::instance()->popShader();
|
2010-12-08 18:25:15 +00:00
|
|
|
}
|
2009-02-15 10:34:31 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
glDisable(GL_BLEND);
|
|
|
|
glLineWidth(1.0);
|
2010-12-08 18:25:15 +00:00
|
|
|
#ifndef KWIN_HAVE_OPENGLES
|
2009-02-15 10:34:31 +00:00
|
|
|
glPopAttrib();
|
2010-12-08 18:25:15 +00:00
|
|
|
#endif
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
|
|
|
/*if ( effects->compositingType() == XRenderCompositing )
|
2009-02-15 10:34:31 +00:00
|
|
|
{ // TODO
|
2011-01-30 14:34:42 +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;
|
|
|
|
|
|
|
|
XSegment segments[6];
|
|
|
|
|
|
|
|
// Center lines
|
|
|
|
segments[0].x1 = rect.x() + rect.width() / 2;
|
|
|
|
segments[0].y1 = rect.y();
|
|
|
|
segments[0].x2 = rect.x() + rect.width() / 2;
|
|
|
|
segments[0].y2 = rect.y() + rect.height();
|
|
|
|
segments[1].x1 = rect.x();
|
|
|
|
segments[1].y1 = rect.y() + rect.height() / 2;
|
|
|
|
segments[1].x2 = rect.x() + rect.width();
|
|
|
|
segments[1].y2 = rect.y() + rect.height() / 2;
|
|
|
|
|
|
|
|
// Window outline
|
|
|
|
// The +/- 2 is to prevent line overlap
|
|
|
|
segments[2].x1 = midX - halfWidth + 2;
|
|
|
|
segments[2].y1 = midY - halfHeight;
|
|
|
|
segments[2].x2 = midX + halfWidth + 2;
|
|
|
|
segments[2].y2 = midY - halfHeight;
|
|
|
|
segments[3].x1 = midX + halfWidth;
|
|
|
|
segments[3].y1 = midY - halfHeight + 2;
|
|
|
|
segments[3].x2 = midX + halfWidth;
|
|
|
|
segments[3].y2 = midY + halfHeight + 2;
|
|
|
|
segments[4].x1 = midX + halfWidth - 2;
|
|
|
|
segments[4].y1 = midY + halfHeight;
|
|
|
|
segments[4].x2 = midX - halfWidth - 2;
|
|
|
|
segments[4].y2 = midY + halfHeight;
|
|
|
|
segments[5].x1 = midX - halfWidth;
|
|
|
|
segments[5].y1 = midY + halfHeight - 2;
|
|
|
|
segments[5].x2 = midX - halfWidth;
|
|
|
|
segments[5].y2 = midY - halfHeight - 2;
|
|
|
|
|
|
|
|
XDrawSegments( display(), effects->xrenderBufferPicture(), m_gc, segments, 6 );
|
|
|
|
}
|
|
|
|
}*/
|
2011-01-30 14:34:42 +00:00
|
|
|
} else if (m_window) {
|
|
|
|
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
|
|
|
|
|
|
|
} // namespace
|