diff --git a/effects/CMakeLists.txt b/effects/CMakeLists.txt --- a/effects/CMakeLists.txt +++ b/effects/CMakeLists.txt @@ -92,6 +92,7 @@ resize/resize.cpp scale/scale.cpp showfps/showfps.cpp + showpaint/showpaint.cpp slide/slide.cpp thumbnailaside/thumbnailaside.cpp touchpoints/touchpoints.cpp @@ -160,7 +161,7 @@ add_subdirectory( resize ) include( screenedge/CMakeLists.txt ) add_subdirectory( showfps ) -include( showpaint/CMakeLists.txt ) +add_subdirectory( showpaint ) add_subdirectory( slide ) include( slideback/CMakeLists.txt ) include( slidingpopups/CMakeLists.txt ) diff --git a/effects/showpaint/CMakeLists.txt b/effects/showpaint/CMakeLists.txt --- a/effects/showpaint/CMakeLists.txt +++ b/effects/showpaint/CMakeLists.txt @@ -1,7 +1,25 @@ ####################################### -# Effect -# Source files -set( kwin4_effect_builtins_sources ${kwin4_effect_builtins_sources} - showpaint/showpaint.cpp - ) +# Config +set(kwin_showpaint_config_SRCS showpaint_config.cpp) +ki18n_wrap_ui(kwin_showpaint_config_SRCS showpaint_config.ui) + +add_library(kwin_showpaint_config MODULE ${kwin_showpaint_config_SRCS}) + +target_link_libraries(kwin_showpaint_config + KF5::ConfigWidgets + KF5::GlobalAccel + KF5::I18n + KF5::Service + KF5::XmlGui +) + +kcoreaddons_desktop_to_json(kwin_showpaint_config showpaint_config.desktop SERVICE_TYPES kcmodule.desktop) + +install( + TARGETS + kwin_showpaint_config + + DESTINATION + ${PLUGIN_INSTALL_DIR}/kwin/effects/configs +) diff --git a/effects/showpaint/showpaint.h b/effects/showpaint/showpaint.h --- a/effects/showpaint/showpaint.h +++ b/effects/showpaint/showpaint.h @@ -31,14 +31,22 @@ Q_OBJECT public: + ShowPaintEffect(); + void paintScreen(int mask, QRegion region, ScreenPaintData &data) override; void paintWindow(EffectWindow *w, int mask, QRegion region, WindowPaintData &data) override; + bool isActive() const override; + +private Q_SLOTS: + void toggle(); + private: void paintGL(const QMatrix4x4 &projection); void paintXrender(); void paintQPainter(); + bool m_active = false; QRegion m_painted; // what's painted in one pass int m_colorIndex = 0; }; diff --git a/effects/showpaint/showpaint.cpp b/effects/showpaint/showpaint.cpp --- a/effects/showpaint/showpaint.cpp +++ b/effects/showpaint/showpaint.cpp @@ -26,6 +26,10 @@ #include #endif +#include +#include + +#include #include namespace KWin @@ -42,6 +46,18 @@ Qt::gray }; +ShowPaintEffect::ShowPaintEffect() +{ + auto *toggleAction = new QAction(this); + toggleAction->setObjectName(QStringLiteral("Toggle")); + toggleAction->setText(i18n("Toggle Show Paint")); + KGlobalAccel::self()->setDefaultShortcut(toggleAction, {}); + KGlobalAccel::self()->setShortcut(toggleAction, {}); + effects->registerGlobalShortcut({}, toggleAction); + + connect(toggleAction, &QAction::triggered, this, &ShowPaintEffect::toggle); +} + void ShowPaintEffect::paintScreen(int mask, QRegion region, ScreenPaintData &data) { m_painted = QRegion(); @@ -123,4 +139,15 @@ } } +bool ShowPaintEffect::isActive() const +{ + return m_active; +} + +void ShowPaintEffect::toggle() +{ + m_active = !m_active; + effects->addRepaintFull(); +} + } // namespace KWin diff --git a/effects/showpaint/showpaint.h b/effects/showpaint/showpaint_config.h copy from effects/showpaint/showpaint.h copy to effects/showpaint/showpaint_config.h --- a/effects/showpaint/showpaint.h +++ b/effects/showpaint/showpaint_config.h @@ -2,7 +2,7 @@ KWin - the KDE window manager This file is part of the KDE project. -Copyright (C) 2007 Lubos Lunak +Copyright (C) 2018 Vlad Zagorodniy 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 @@ -18,31 +18,29 @@ along with this program. If not, see . *********************************************************************/ -#ifndef KWIN_SHOWPAINT_H -#define KWIN_SHOWPAINT_H +#pragma once -#include +#include + +#include "ui_showpaint_config.h" namespace KWin { -class ShowPaintEffect : public Effect +class ShowPaintEffectConfig : public KCModule { Q_OBJECT public: - void paintScreen(int mask, QRegion region, ScreenPaintData &data) override; - void paintWindow(EffectWindow *w, int mask, QRegion region, WindowPaintData &data) override; + explicit ShowPaintEffectConfig(QWidget *parent = nullptr, const QVariantList &args = {}); + ~ShowPaintEffectConfig() override; -private: - void paintGL(const QMatrix4x4 &projection); - void paintXrender(); - void paintQPainter(); +public Q_SLOTS: + void save() override; + void defaults() override; - QRegion m_painted; // what's painted in one pass - int m_colorIndex = 0; +private: + Ui::ShowPaintEffectConfig *m_ui; }; } // namespace KWin - -#endif diff --git a/effects/showpaint/showpaint_config.cpp b/effects/showpaint/showpaint_config.cpp new file mode 100644 --- /dev/null +++ b/effects/showpaint/showpaint_config.cpp @@ -0,0 +1,87 @@ +/******************************************************************** + KWin - the KDE window manager + This file is part of the KDE project. + +Copyright (C) 2018 Vlad Zagorodniy + +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 . +*********************************************************************/ + +#include "showpaint_config.h" + +#include +#include +#include +#include +#include +#include + +#include + +K_PLUGIN_FACTORY_WITH_JSON(ShowPaintEffectConfigFactory, + "showpaint_config.json", + registerPlugin();) + +namespace KWin +{ + +ShowPaintEffectConfig::ShowPaintEffectConfig(QWidget *parent, const QVariantList &args) + : KCModule(KAboutData::pluginData(QStringLiteral("showpaint")), parent, args) + , m_ui(new Ui::ShowPaintEffectConfig) +{ + m_ui->setupUi(this); + + auto *actionCollection = new KActionCollection(this, QStringLiteral("kwin")); + + actionCollection->setComponentDisplayName(i18n("KWin")); + actionCollection->setConfigGroup(QStringLiteral("ShowPaint")); + actionCollection->setConfigGlobal(true); + + QAction *toggleAction = actionCollection->addAction(QStringLiteral("Toggle")); + toggleAction->setText(i18n("Toggle Show Paint")); + toggleAction->setProperty("isConfigurationAction", true); + KGlobalAccel::self()->setDefaultShortcut(toggleAction, {}); + KGlobalAccel::self()->setShortcut(toggleAction, {}); + + m_ui->shortcutsEditor->addCollection(actionCollection); + + connect(m_ui->shortcutsEditor, &KShortcutsEditor::keyChange, + this, qOverload<>(&ShowPaintEffectConfig::changed)); + + load(); +} + +ShowPaintEffectConfig::~ShowPaintEffectConfig() +{ + // If save() is called, undoChanges() has no effect. + m_ui->shortcutsEditor->undoChanges(); + + delete m_ui; +} + +void ShowPaintEffectConfig::save() +{ + KCModule::save(); + m_ui->shortcutsEditor->save(); +} + +void ShowPaintEffectConfig::defaults() +{ + m_ui->shortcutsEditor->allDefault(); + KCModule::defaults(); +} + +} // namespace KWin + +#include "showpaint_config.moc" diff --git a/effects/showpaint/showpaint_config.desktop b/effects/showpaint/showpaint_config.desktop new file mode 100644 --- /dev/null +++ b/effects/showpaint/showpaint_config.desktop @@ -0,0 +1,8 @@ +[Desktop Entry] +Type=Service +X-KDE-ServiceTypes=KCModule + +X-KDE-Library=kwin_showpaint_config +X-KDE-ParentComponents=showpaint + +Name=Show Paint diff --git a/effects/showpaint/showpaint_config.ui b/effects/showpaint/showpaint_config.ui new file mode 100644 --- /dev/null +++ b/effects/showpaint/showpaint_config.ui @@ -0,0 +1,39 @@ + + + ShowPaintEffectConfig + + + + 0 + 0 + 452 + 246 + + + + + + + + 0 + 0 + + + + KShortcutsEditor::GlobalAction + + + + + + + + KShortcutsEditor + QWidget +
KShortcutsEditor
+ 1 +
+
+ + +