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>
|
2007-11-13 16:20:52 +00:00
|
|
|
Copyright (C) 2007 Christian Nitschkowski <christian.nitschkowski@kdemail.net>
|
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 "mousemark.h"
|
|
|
|
|
2007-12-17 14:14:53 +00:00
|
|
|
#include <kwinconfig.h>
|
2010-12-12 13:51:56 +00:00
|
|
|
#include <kwinglutils.h>
|
2007-05-13 17:47:20 +00:00
|
|
|
|
2007-04-29 17:35:43 +00:00
|
|
|
#include <kaction.h>
|
|
|
|
#include <kactioncollection.h>
|
|
|
|
#include <kglobal.h>
|
|
|
|
#include <klocale.h>
|
|
|
|
#include <kstandarddirs.h>
|
2007-11-24 14:23:04 +00:00
|
|
|
#include <kconfiggroup.h>
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
#include <math.h>
|
|
|
|
|
|
|
|
#include <kdebug.h>
|
|
|
|
|
|
|
|
namespace KWin
|
|
|
|
{
|
|
|
|
|
2008-01-08 16:21:04 +00:00
|
|
|
#define NULL_POINT (QPoint( -1, -1 )) // null point is (0,0), which is valid :-/
|
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
KWIN_EFFECT(mousemark, MouseMarkEffect)
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
MouseMarkEffect::MouseMarkEffect()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
KActionCollection* actionCollection = new KActionCollection(this);
|
|
|
|
KAction* a = static_cast< KAction* >(actionCollection->addAction("ClearMouseMarks"));
|
|
|
|
a->setText(i18n("Clear All Mouse Marks"));
|
|
|
|
a->setGlobalShortcut(KShortcut(Qt::SHIFT + Qt::META + Qt::Key_F11));
|
|
|
|
connect(a, SIGNAL(triggered(bool)), this, SLOT(clear()));
|
|
|
|
a = static_cast< KAction* >(actionCollection->addAction("ClearLastMouseMark"));
|
|
|
|
a->setText(i18n("Clear Last Mouse Mark"));
|
|
|
|
a->setGlobalShortcut(KShortcut(Qt::SHIFT + Qt::META + Qt::Key_F12));
|
|
|
|
connect(a, SIGNAL(triggered(bool)), this, SLOT(clearLast()));
|
2011-03-12 13:37:30 +00:00
|
|
|
connect(effects, SIGNAL(mouseChanged(QPoint,QPoint,Qt::MouseButtons,Qt::MouseButtons,Qt::KeyboardModifiers,Qt::KeyboardModifiers)),
|
|
|
|
this, SLOT(slotMouseChanged(QPoint,QPoint,Qt::MouseButtons,Qt::MouseButtons,Qt::KeyboardModifiers,Qt::KeyboardModifiers)));
|
2011-01-30 14:34:42 +00:00
|
|
|
reconfigure(ReconfigureAll);
|
2008-10-02 09:27:32 +00:00
|
|
|
arrow_start = NULL_POINT;
|
2009-02-01 15:16:52 +00:00
|
|
|
effects->startMousePolling(); // We require it to detect activation as well
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2009-02-01 15:16:52 +00:00
|
|
|
|
|
|
|
MouseMarkEffect::~MouseMarkEffect()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2009-02-01 15:16:52 +00:00
|
|
|
effects->stopMousePolling();
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-11-24 14:23:04 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
void MouseMarkEffect::reconfigure(ReconfigureFlags)
|
|
|
|
{
|
2007-11-24 14:23:04 +00:00
|
|
|
KConfigGroup conf = EffectsHandler::effectConfig("MouseMark");
|
2011-01-30 14:34:42 +00:00
|
|
|
width = conf.readEntry("LineWidth", 3);
|
|
|
|
color = conf.readEntry("Color", QColor(Qt::red));
|
2010-12-12 13:51:56 +00:00
|
|
|
color.setAlphaF(1.0);
|
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 MouseMarkEffect::paintScreen(int mask, QRegion region, ScreenPaintData& data)
|
|
|
|
{
|
|
|
|
effects->paintScreen(mask, region, data); // paint normal screen
|
|
|
|
if (marks.isEmpty() && drawing.isEmpty())
|
2007-04-29 17:35:43 +00:00
|
|
|
return;
|
2010-12-12 13:51:56 +00:00
|
|
|
#ifndef KWIN_HAVE_OPENGLES
|
2011-01-30 14:34:42 +00:00
|
|
|
glPushAttrib(GL_ENABLE_BIT | GL_CURRENT_BIT | GL_LINE_BIT);
|
|
|
|
glEnable(GL_LINE_SMOOTH);
|
2010-12-12 13:51:56 +00:00
|
|
|
#endif
|
2011-01-30 14:34:42 +00:00
|
|
|
glLineWidth(width);
|
2010-12-12 13:51:56 +00:00
|
|
|
GLVertexBuffer *vbo = GLVertexBuffer::streamingBuffer();
|
|
|
|
vbo->reset();
|
|
|
|
vbo->setUseColor(true);
|
|
|
|
vbo->setColor(color);
|
|
|
|
if (ShaderManager::instance()->isValid()) {
|
|
|
|
ShaderManager::instance()->pushShader(ShaderManager::ColorShader);
|
|
|
|
}
|
|
|
|
QVector<float> verts;
|
2011-01-30 14:34:42 +00:00
|
|
|
foreach (const Mark & mark, marks) {
|
2010-12-12 13:51:56 +00:00
|
|
|
verts.clear();
|
2011-01-30 14:34:42 +00:00
|
|
|
verts.reserve(mark.size() * 2);
|
|
|
|
foreach (const QPoint & p, mark) {
|
2010-12-12 13:51:56 +00:00
|
|
|
verts << p.x() << p.y();
|
2007-04-29 17:35:43 +00:00
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
vbo->setData(verts.size() / 2, 2, verts.data(), NULL);
|
2010-12-12 13:51:56 +00:00
|
|
|
vbo->render(GL_LINE_STRIP);
|
|
|
|
}
|
|
|
|
if (!drawing.isEmpty()) {
|
|
|
|
verts.clear();
|
2011-01-30 14:34:42 +00:00
|
|
|
verts.reserve(drawing.size() * 2);
|
|
|
|
foreach (const QPoint & p, drawing) {
|
2010-12-12 13:51:56 +00:00
|
|
|
verts << p.x() << p.y();
|
2007-04-29 17:35:43 +00:00
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
vbo->setData(verts.size() / 2, 2, verts.data(), NULL);
|
2010-12-12 13:51:56 +00:00
|
|
|
vbo->render(GL_LINE_STRIP);
|
|
|
|
}
|
|
|
|
if (ShaderManager::instance()->isValid()) {
|
|
|
|
ShaderManager::instance()->popShader();
|
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
glLineWidth(1.0);
|
2010-12-12 13:51:56 +00:00
|
|
|
#ifndef KWIN_HAVE_OPENGLES
|
2011-01-30 14:34:42 +00:00
|
|
|
glDisable(GL_LINE_SMOOTH);
|
2007-04-29 17:35:43 +00:00
|
|
|
glPopAttrib();
|
2010-12-12 13:51:56 +00:00
|
|
|
#endif
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2011-03-12 13:37:30 +00:00
|
|
|
void MouseMarkEffect::slotMouseChanged(const QPoint& pos, const QPoint&,
|
2011-01-30 14:34:42 +00:00
|
|
|
Qt::MouseButtons, Qt::MouseButtons,
|
|
|
|
Qt::KeyboardModifiers modifiers, Qt::KeyboardModifiers)
|
|
|
|
{
|
|
|
|
if (modifiers == (Qt::META | Qt::SHIFT | Qt::CTRL)) { // start/finish arrow
|
|
|
|
if (arrow_start != NULL_POINT) {
|
|
|
|
marks.append(createArrow(arrow_start, pos));
|
2008-01-08 16:21:04 +00:00
|
|
|
arrow_start = NULL_POINT;
|
|
|
|
effects->addRepaintFull();
|
|
|
|
return;
|
2011-01-30 14:34:42 +00:00
|
|
|
} else
|
2008-01-08 16:21:04 +00:00
|
|
|
arrow_start = pos;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
|
|
|
if (arrow_start != NULL_POINT)
|
2008-01-08 16:21:04 +00:00
|
|
|
return;
|
2008-01-08 16:23:56 +00:00
|
|
|
// TODO the shortcuts now trigger this right before they're activated
|
2011-01-30 14:34:42 +00:00
|
|
|
if (modifiers == (Qt::META | Qt::SHIFT)) { // activated
|
|
|
|
if (drawing.isEmpty())
|
|
|
|
drawing.append(pos);
|
|
|
|
if (drawing.last() == pos)
|
2007-04-29 17:35:43 +00:00
|
|
|
return;
|
|
|
|
QPoint pos2 = drawing.last();
|
2011-01-30 14:34:42 +00:00
|
|
|
drawing.append(pos);
|
|
|
|
QRect repaint = QRect(qMin(pos.x(), pos2.x()), qMin(pos.y(), pos2.y()),
|
|
|
|
qMax(pos.x(), pos2.x()), qMax(pos.y(), pos2.y()));
|
|
|
|
repaint.adjust(-width, -width, width, width);
|
|
|
|
effects->addRepaint(repaint);
|
|
|
|
} else if (!drawing.isEmpty()) {
|
|
|
|
marks.append(drawing);
|
2007-04-29 17:35:43 +00:00
|
|
|
drawing.clear();
|
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
void MouseMarkEffect::clear()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2007-04-29 17:35:43 +00:00
|
|
|
drawing.clear();
|
|
|
|
marks.clear();
|
|
|
|
effects->addRepaintFull();
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2008-01-08 16:23:56 +00:00
|
|
|
void MouseMarkEffect::clearLast()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
if (arrow_start != NULL_POINT) {
|
2008-01-08 16:23:56 +00:00
|
|
|
arrow_start = NULL_POINT;
|
2011-01-30 14:34:42 +00:00
|
|
|
} else if (!drawing.isEmpty()) {
|
2008-01-08 16:23:56 +00:00
|
|
|
drawing.clear();
|
|
|
|
effects->addRepaintFull();
|
2011-01-30 14:34:42 +00:00
|
|
|
} else if (!marks.isEmpty()) {
|
2008-01-08 16:23:56 +00:00
|
|
|
marks.pop_back();
|
|
|
|
effects->addRepaintFull();
|
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2008-01-08 16:23:56 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
MouseMarkEffect::Mark MouseMarkEffect::createArrow(QPoint arrow_start, QPoint arrow_end)
|
|
|
|
{
|
2008-01-08 16:21:04 +00:00
|
|
|
Mark ret;
|
2011-01-30 14:34:42 +00:00
|
|
|
double angle = atan2((double)(arrow_end.y() - arrow_start.y()), (double)(arrow_end.x() - arrow_start.x()));
|
|
|
|
ret += arrow_start + QPoint(50 * cos(angle + M_PI / 6),
|
|
|
|
50 * sin(angle + M_PI / 6)); // right one
|
2008-01-08 16:21:04 +00:00
|
|
|
ret += arrow_start;
|
|
|
|
ret += arrow_end;
|
|
|
|
ret += arrow_start; // it's connected lines, so go back with the middle one
|
2011-01-30 14:34:42 +00:00
|
|
|
ret += arrow_start + QPoint(50 * cos(angle - M_PI / 6),
|
|
|
|
50 * sin(angle - M_PI / 6)); // left one
|
2008-01-08 16:21:04 +00:00
|
|
|
return ret;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
|
|
|
|
2007-04-29 17:35:43 +00:00
|
|
|
} // namespace
|
|
|
|
|
|
|
|
#include "mousemark.moc"
|