File indexing completed on 2024-11-10 04:57:03

0001 /*
0002     KWin - the KDE window manager
0003     This file is part of the KDE project.
0004 
0005     SPDX-FileCopyrightText: 2007 Lubos Lunak <l.lunak@kde.org>
0006     SPDX-FileCopyrightText: 2023 Andrew Shark <ashark at linuxcomp.ru>
0007 
0008     SPDX-License-Identifier: GPL-2.0-or-later
0009 */
0010 
0011 #pragma once
0012 
0013 #include "effect/effect.h"
0014 #include "opengl/glutils.h"
0015 
0016 namespace KWin
0017 {
0018 
0019 class MouseMarkEffect
0020     : public Effect
0021 {
0022     Q_OBJECT
0023     Q_PROPERTY(int width READ configuredWidth)
0024     Q_PROPERTY(QColor color READ configuredColor)
0025     Q_PROPERTY(Qt::KeyboardModifiers modifiers READ freedraw_modifiers)
0026     Q_PROPERTY(Qt::KeyboardModifiers modifiers READ arrowdraw_modifiers)
0027 public:
0028     MouseMarkEffect();
0029     ~MouseMarkEffect() override;
0030     void reconfigure(ReconfigureFlags) override;
0031     void paintScreen(const RenderTarget &renderTarget, const RenderViewport &viewport, int mask, const QRegion &region, Output *screen) override;
0032     bool isActive() const override;
0033     int requestedEffectChainPosition() const override;
0034 
0035     // for properties
0036     int configuredWidth() const
0037     {
0038         return width;
0039     }
0040     QColor configuredColor() const
0041     {
0042         return color;
0043     }
0044     Qt::KeyboardModifiers freedraw_modifiers() const
0045     {
0046         return m_freedraw_modifiers;
0047     }
0048     Qt::KeyboardModifiers arrowdraw_modifiers() const
0049     {
0050         return m_freedraw_modifiers;
0051     }
0052 private Q_SLOTS:
0053     void clear();
0054     void clearLast();
0055     void slotMouseChanged(const QPointF &pos, const QPointF &old,
0056                           Qt::MouseButtons buttons, Qt::MouseButtons oldbuttons,
0057                           Qt::KeyboardModifiers modifiers, Qt::KeyboardModifiers oldmodifiers);
0058     void screenLockingChanged(bool locked);
0059 
0060 private:
0061     typedef QList<QPointF> Mark;
0062     void drawMark(QPainter *painter, const Mark &mark);
0063     static Mark createArrow(QPointF arrow_head, QPointF arrow_tail);
0064     QList<Mark> marks;
0065     Mark drawing;
0066     QPointF arrow_tail;
0067     int width;
0068     QColor color;
0069     Qt::KeyboardModifiers m_freedraw_modifiers;
0070     Qt::KeyboardModifiers m_arrowdraw_modifiers;
0071 };
0072 
0073 } // namespace