Changeset View
Changeset View
Standalone View
Standalone View
effects/showpaint/showpaint.cpp
Show All 20 Lines | |||||
21 | 21 | | |||
22 | #include "showpaint.h" | 22 | #include "showpaint.h" | ||
23 | 23 | | |||
24 | #include <kwinglutils.h> | 24 | #include <kwinglutils.h> | ||
25 | #ifdef KWIN_HAVE_XRENDER_COMPOSITING | 25 | #ifdef KWIN_HAVE_XRENDER_COMPOSITING | ||
26 | #include <xcb/render.h> | 26 | #include <xcb/render.h> | ||
27 | #endif | 27 | #endif | ||
28 | 28 | | |||
29 | #include <KGlobalAccel> | ||||
30 | #include <KLocalizedString> | ||||
31 | | ||||
32 | #include <QAction> | ||||
29 | #include <QPainter> | 33 | #include <QPainter> | ||
30 | 34 | | |||
31 | namespace KWin | 35 | namespace KWin | ||
32 | { | 36 | { | ||
33 | 37 | | |||
34 | static const qreal s_alpha = 0.2; | 38 | static const qreal s_alpha = 0.2; | ||
35 | static const QVector<QColor> s_colors { | 39 | static const QVector<QColor> s_colors { | ||
36 | Qt::red, | 40 | Qt::red, | ||
37 | Qt::green, | 41 | Qt::green, | ||
38 | Qt::blue, | 42 | Qt::blue, | ||
39 | Qt::cyan, | 43 | Qt::cyan, | ||
40 | Qt::magenta, | 44 | Qt::magenta, | ||
41 | Qt::yellow, | 45 | Qt::yellow, | ||
42 | Qt::gray | 46 | Qt::gray | ||
43 | }; | 47 | }; | ||
44 | 48 | | |||
49 | ShowPaintEffect::ShowPaintEffect() | ||||
50 | { | ||||
51 | auto *toggleAction = new QAction(this); | ||||
52 | toggleAction->setObjectName(QStringLiteral("Toggle")); | ||||
53 | toggleAction->setText(i18n("Toggle Show Paint")); | ||||
54 | KGlobalAccel::self()->setDefaultShortcut(toggleAction, {}); | ||||
55 | KGlobalAccel::self()->setShortcut(toggleAction, {}); | ||||
56 | effects->registerGlobalShortcut({}, toggleAction); | ||||
57 | | ||||
58 | connect(toggleAction, &QAction::triggered, this, &ShowPaintEffect::toggle); | ||||
59 | } | ||||
60 | | ||||
45 | void ShowPaintEffect::paintScreen(int mask, QRegion region, ScreenPaintData &data) | 61 | void ShowPaintEffect::paintScreen(int mask, QRegion region, ScreenPaintData &data) | ||
46 | { | 62 | { | ||
47 | m_painted = QRegion(); | 63 | m_painted = QRegion(); | ||
48 | effects->paintScreen(mask, region, data); | 64 | effects->paintScreen(mask, region, data); | ||
49 | if (effects->isOpenGLCompositing()) { | 65 | if (effects->isOpenGLCompositing()) { | ||
50 | paintGL(data.projectionMatrix()); | 66 | paintGL(data.projectionMatrix()); | ||
51 | } | 67 | } | ||
52 | #ifdef KWIN_HAVE_XRENDER_COMPOSITING | 68 | #ifdef KWIN_HAVE_XRENDER_COMPOSITING | ||
▲ Show 20 Lines • Show All 65 Lines • ▼ Show 20 Line(s) | |||||
118 | { | 134 | { | ||
119 | QColor color = s_colors[m_colorIndex]; | 135 | QColor color = s_colors[m_colorIndex]; | ||
120 | color.setAlphaF(s_alpha); | 136 | color.setAlphaF(s_alpha); | ||
121 | for (const QRect &r : m_painted) { | 137 | for (const QRect &r : m_painted) { | ||
122 | effects->scenePainter()->fillRect(r, color); | 138 | effects->scenePainter()->fillRect(r, color); | ||
123 | } | 139 | } | ||
124 | } | 140 | } | ||
125 | 141 | | |||
142 | bool ShowPaintEffect::isActive() const | ||||
143 | { | ||||
144 | return m_active; | ||||
145 | } | ||||
146 | | ||||
147 | void ShowPaintEffect::toggle() | ||||
148 | { | ||||
149 | m_active = !m_active; | ||||
150 | effects->addRepaintFull(); | ||||
151 | } | ||||
152 | | ||||
126 | } // namespace KWin | 153 | } // namespace KWin |