13#include "mousemarklogging.h"
16#include "mousemarkconfig.h"
22#include <KGlobalAccel>
23#include <KLocalizedString>
33static consteval QPoint nullPoint()
35 return QPoint(-1, -1);
41 QAction *a =
new QAction(
this);
42 a->setObjectName(QStringLiteral(
"ClearMouseMarks"));
43 a->setText(i18n(
"Clear All Mouse Marks"));
44 KGlobalAccel::self()->setDefaultShortcut(a, QList<QKeySequence>() << (Qt::SHIFT | Qt::META | Qt::Key_F11));
45 KGlobalAccel::self()->setShortcut(a, QList<QKeySequence>() << (Qt::SHIFT | Qt::META | Qt::Key_F11));
46 connect(a, &QAction::triggered,
this, &MouseMarkEffect::clear);
47 a =
new QAction(
this);
48 a->setObjectName(QStringLiteral(
"ClearLastMouseMark"));
49 a->setText(i18n(
"Clear Last Mouse Mark"));
50 KGlobalAccel::self()->setDefaultShortcut(a, QList<QKeySequence>() << (Qt::SHIFT | Qt::META | Qt::Key_F12));
51 KGlobalAccel::self()->setShortcut(a, QList<QKeySequence>() << (Qt::SHIFT | Qt::META | Qt::Key_F12));
52 connect(a, &QAction::triggered,
this, &MouseMarkEffect::clearLast);
57 arrow_tail = nullPoint();
66static int width_2 = 1;
69 m_freedraw_modifiers = Qt::KeyboardModifiers();
70 m_arrowdraw_modifiers = Qt::KeyboardModifiers();
71 MouseMarkConfig::self()->read();
72 width = MouseMarkConfig::lineWidth();
74 color = MouseMarkConfig::color();
76 if (MouseMarkConfig::freedrawshift()) {
77 m_freedraw_modifiers |= Qt::ShiftModifier;
79 if (MouseMarkConfig::freedrawalt()) {
80 m_freedraw_modifiers |= Qt::AltModifier;
82 if (MouseMarkConfig::freedrawcontrol()) {
83 m_freedraw_modifiers |= Qt::ControlModifier;
85 if (MouseMarkConfig::freedrawmeta()) {
86 m_freedraw_modifiers |= Qt::MetaModifier;
89 if (MouseMarkConfig::arrowdrawshift()) {
90 m_arrowdraw_modifiers |= Qt::ShiftModifier;
92 if (MouseMarkConfig::arrowdrawalt()) {
93 m_arrowdraw_modifiers |= Qt::AltModifier;
95 if (MouseMarkConfig::arrowdrawcontrol()) {
96 m_arrowdraw_modifiers |= Qt::ControlModifier;
98 if (MouseMarkConfig::arrowdrawmeta()) {
99 m_arrowdraw_modifiers |= Qt::MetaModifier;
106 if (marks.isEmpty() && drawing.isEmpty()) {
112 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
114 glEnable(GL_LINE_SMOOTH);
115 glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);
120 const auto scale = viewport.
scale();
125 QList<QVector2D> verts;
126 for (
const Mark &mark : std::as_const(marks)) {
128 verts.reserve(mark.size() * 2);
129 for (
const QPointF &p : std::as_const(mark)) {
130 verts.push_back(QVector2D(p.x() * scale, p.y() * scale));
133 vbo->
render(GL_LINE_STRIP);
135 if (!drawing.isEmpty()) {
137 verts.reserve(drawing.size() * 2);
138 for (
const QPointF &p : std::as_const(drawing)) {
139 verts.push_back(QVector2D(p.x() * scale, p.y() * scale));
142 vbo->
render(GL_LINE_STRIP);
146 glDisable(GL_LINE_SMOOTH);
154 painter->setPen(pen);
155 for (
const Mark &mark : std::as_const(marks)) {
156 drawMark(painter, mark);
158 drawMark(painter, drawing);
163void MouseMarkEffect::drawMark(QPainter *painter,
const Mark &mark)
165 if (mark.count() <= 1) {
168 for (
int i = 0; i < mark.count() - 1; ++i) {
169 painter->drawLine(mark[i], mark[i + 1]);
173void MouseMarkEffect::slotMouseChanged(
const QPointF &pos,
const QPointF &,
174 Qt::MouseButtons, Qt::MouseButtons,
175 Qt::KeyboardModifiers modifiers, Qt::KeyboardModifiers)
177 qCDebug(KWIN_MOUSEMARK) <<
"MouseChanged" << pos;
178 if (
modifiers == m_arrowdraw_modifiers && m_arrowdraw_modifiers != Qt::NoModifier) {
179 if (arrow_tail != nullPoint()) {
180 if (drawing.length() != 0) {
183 drawing = createArrow(pos, arrow_tail);
187 if (drawing.length() > 0) {
188 marks.append(drawing);
193 }
else if (
modifiers == m_freedraw_modifiers && m_freedraw_modifiers != Qt::NoModifier ) {
194 if (arrow_tail != nullPoint()) {
195 arrow_tail = nullPoint();
196 marks.append(drawing);
199 if (drawing.isEmpty()) {
202 if (drawing.last() == pos) {
205 QPointF pos2 = drawing.last();
207 QRect repaint = QRect(std::min(pos.x(), pos2.x()), std::min(pos.y(), pos2.y()),
208 std::max(pos.x(), pos2.x()), std::max(pos.y(), pos2.y()));
212 if (drawing.length() > 1) {
213 marks.append(drawing);
216 arrow_tail = nullPoint();
220void MouseMarkEffect::clear()
222 arrow_tail = nullPoint();
228void MouseMarkEffect::clearLast()
230 if (drawing.length() > 1) {
233 }
else if (!marks.isEmpty()) {
239MouseMarkEffect::Mark MouseMarkEffect::createArrow(QPointF arrow_head, QPointF arrow_tail)
242 double angle = atan2((
double)(arrow_tail.y() - arrow_head.y()), (
double)(arrow_tail.x() - arrow_head.x()));
245 ret += arrow_head + QPoint(50 * cos(angle + M_PI / 6),
246 50 * sin(angle + M_PI / 6));
248 ret += arrow_head + QPoint(50 * cos(angle - M_PI / 6),
249 50 * sin(angle - M_PI / 6));
255void MouseMarkEffect::screenLockingChanged(
bool locked)
257 if (!marks.isEmpty() || !drawing.isEmpty()) {
280#include "moc_mousemark.cpp"
void screenLockingChanged(bool locked)
void paintScreen(const RenderTarget &renderTarget, const RenderViewport &viewport, int mask, const QRegion ®ion, Output *screen)
Q_SCRIPTABLE void addRepaint(const QRectF &r)
CompositingType compositingType
bool isScreenLocked() const
bool isOpenGLCompositing() const
Whether the Compositor is OpenGL based (either GL 1 or 2).
void mouseChanged(const QPointF &pos, const QPointF &oldpos, Qt::MouseButtons buttons, Qt::MouseButtons oldbuttons, Qt::KeyboardModifiers modifiers, Qt::KeyboardModifiers oldmodifiers)
KSharedConfigPtr config() const
Q_SCRIPTABLE void addRepaintFull()
QPainter * scenePainter()
Provides access to the QPainter which is rendering to the back buffer.
bool setColorspaceUniformsFromSRGB(const ColorDescription &dst)
@ ModelViewProjectionMatrix
bool setUniform(const char *name, float value)
static GLVertexBuffer * streamingBuffer()
void render(GLenum primitiveMode)
void setVertices(const T &range)
void reconfigure(ReconfigureFlags) override
~MouseMarkEffect() override
void paintScreen(const RenderTarget &renderTarget, const RenderViewport &viewport, int mask, const QRegion ®ion, Output *screen) override
int requestedEffectChainPosition() const override
bool isActive() const override
Qt::KeyboardModifiers modifiers
const ColorDescription & colorDescription() const
QMatrix4x4 projectionMatrix() const