1
/********************************************************************
2
KWin - the KDE window manager
3
This file is part of the KDE project.
5
Copyright (C) 2006 Lubos Lunak <l.lunak@kde.org>
6
Copyright (C) 2007 Christian Nitschkowski <christian.nitschkowski@kdemail.net>
8
This program is free software; you can redistribute it and/or modify
9
it under the terms of the GNU General Public License as published by
10
the Free Software Foundation; either version 2 of the License, or
11
(at your option) any later version.
13
This program is distributed in the hope that it will be useful,
14
but WITHOUT ANY WARRANTY; without even the implied warranty of
15
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
GNU General Public License for more details.
18
You should have received a copy of the GNU General Public License
19
along with this program. If not, see <http://www.gnu.org/licenses/>.
20
*********************************************************************/
22
#include "mousemark.h"
24
#include <kwinconfig.h>
25
#include <kwinglutils.h>
28
#include <kactioncollection.h>
31
#include <kstandarddirs.h>
32
#include <kconfiggroup.h>
41
#define NULL_POINT (QPoint( -1, -1 )) // null point is (0,0), which is valid :-/
43
KWIN_EFFECT(mousemark, MouseMarkEffect)
45
MouseMarkEffect::MouseMarkEffect()
47
KActionCollection* actionCollection = new KActionCollection(this);
48
KAction* a = static_cast< KAction* >(actionCollection->addAction("ClearMouseMarks"));
49
a->setText(i18n("Clear All Mouse Marks"));
50
a->setGlobalShortcut(KShortcut(Qt::SHIFT + Qt::META + Qt::Key_F11));
51
connect(a, SIGNAL(triggered(bool)), this, SLOT(clear()));
52
a = static_cast< KAction* >(actionCollection->addAction("ClearLastMouseMark"));
53
a->setText(i18n("Clear Last Mouse Mark"));
54
a->setGlobalShortcut(KShortcut(Qt::SHIFT + Qt::META + Qt::Key_F12));
55
connect(a, SIGNAL(triggered(bool)), this, SLOT(clearLast()));
56
connect(effects, SIGNAL(mouseChanged(QPoint,QPoint,Qt::MouseButtons,Qt::MouseButtons,Qt::KeyboardModifiers,Qt::KeyboardModifiers)),
57
this, SLOT(slotMouseChanged(QPoint,QPoint,Qt::MouseButtons,Qt::MouseButtons,Qt::KeyboardModifiers,Qt::KeyboardModifiers)));
58
reconfigure(ReconfigureAll);
59
arrow_start = NULL_POINT;
60
effects->startMousePolling(); // We require it to detect activation as well
63
MouseMarkEffect::~MouseMarkEffect()
65
effects->stopMousePolling();
68
void MouseMarkEffect::reconfigure(ReconfigureFlags)
70
KConfigGroup conf = EffectsHandler::effectConfig("MouseMark");
71
width = conf.readEntry("LineWidth", 3);
72
color = conf.readEntry("Color", QColor(Qt::red));
76
void MouseMarkEffect::paintScreen(int mask, QRegion region, ScreenPaintData& data)
78
effects->paintScreen(mask, region, data); // paint normal screen
79
if (marks.isEmpty() && drawing.isEmpty())
81
#ifndef KWIN_HAVE_OPENGLES
82
glPushAttrib(GL_ENABLE_BIT | GL_CURRENT_BIT | GL_LINE_BIT);
83
glEnable(GL_LINE_SMOOTH);
86
GLVertexBuffer *vbo = GLVertexBuffer::streamingBuffer();
88
vbo->setUseColor(true);
90
if (ShaderManager::instance()->isValid()) {
91
ShaderManager::instance()->pushShader(ShaderManager::ColorShader);
94
foreach (const Mark & mark, marks) {
96
verts.reserve(mark.size() * 2);
97
foreach (const QPoint & p, mark) {
98
verts << p.x() << p.y();
100
vbo->setData(verts.size() / 2, 2, verts.data(), NULL);
101
vbo->render(GL_LINE_STRIP);
103
if (!drawing.isEmpty()) {
105
verts.reserve(drawing.size() * 2);
106
foreach (const QPoint & p, drawing) {
107
verts << p.x() << p.y();
109
vbo->setData(verts.size() / 2, 2, verts.data(), NULL);
110
vbo->render(GL_LINE_STRIP);
112
if (ShaderManager::instance()->isValid()) {
113
ShaderManager::instance()->popShader();
116
#ifndef KWIN_HAVE_OPENGLES
117
glDisable(GL_LINE_SMOOTH);
122
void MouseMarkEffect::slotMouseChanged(const QPoint& pos, const QPoint&,
123
Qt::MouseButtons, Qt::MouseButtons,
124
Qt::KeyboardModifiers modifiers, Qt::KeyboardModifiers)
126
if (modifiers == (Qt::META | Qt::SHIFT | Qt::CTRL)) { // start/finish arrow
127
if (arrow_start != NULL_POINT) {
128
marks.append(createArrow(arrow_start, pos));
129
arrow_start = NULL_POINT;
130
effects->addRepaintFull();
135
if (arrow_start != NULL_POINT)
137
// TODO the shortcuts now trigger this right before they're activated
138
if (modifiers == (Qt::META | Qt::SHIFT)) { // activated
139
if (drawing.isEmpty())
141
if (drawing.last() == pos)
143
QPoint pos2 = drawing.last();
145
QRect repaint = QRect(qMin(pos.x(), pos2.x()), qMin(pos.y(), pos2.y()),
146
qMax(pos.x(), pos2.x()), qMax(pos.y(), pos2.y()));
147
repaint.adjust(-width, -width, width, width);
148
effects->addRepaint(repaint);
149
} else if (!drawing.isEmpty()) {
150
marks.append(drawing);
155
void MouseMarkEffect::clear()
159
effects->addRepaintFull();
162
void MouseMarkEffect::clearLast()
164
if (arrow_start != NULL_POINT) {
165
arrow_start = NULL_POINT;
166
} else if (!drawing.isEmpty()) {
168
effects->addRepaintFull();
169
} else if (!marks.isEmpty()) {
171
effects->addRepaintFull();
175
MouseMarkEffect::Mark MouseMarkEffect::createArrow(QPoint arrow_start, QPoint arrow_end)
178
double angle = atan2((double)(arrow_end.y() - arrow_start.y()), (double)(arrow_end.x() - arrow_start.x()));
179
ret += arrow_start + QPoint(50 * cos(angle + M_PI / 6),
180
50 * sin(angle + M_PI / 6)); // right one
183
ret += arrow_start; // it's connected lines, so go back with the middle one
184
ret += arrow_start + QPoint(50 * cos(angle - M_PI / 6),
185
50 * sin(angle - M_PI / 6)); // left one
191
#include "mousemark.moc"