Commit 1de9648a authored by Vlad Zahorodnii's avatar Vlad Zahorodnii

[effects/showpaint] Use a shortcut to toggle the effect

Summary:
The Show Paint effect is useful when debugging repaint regions issued by
effects. The only headache with it is necessity to enable/disable it.
Consider the following workflow:

* Do some change to an effect;
* Compile KWin (or the effect);
* Go to System Settings and enable the Show Paint effect;
* Test effect, check repaint regions, etc;
* Disable the Show Paint effect;
* Go to the step 1.

This workflow is really exhausting. Also, when testing repaints in a
nested compositor, things become quite messy.

Because purpose of this effect is to debug repaints (and because this
effect is not meant for daily usage), I think that's fine to change
how it's activated.

This patch improves the workflow by changing the way how this effect
gets activated. Instead of enabling/disabling it, one can just use a shortcut
to activate or deactivate the effect.

Reviewers: #kwin, davidedmundson

Reviewed By: #kwin, davidedmundson

Subscribers: broulik, davidedmundson, kwin

Tags: #kwin

Differential Revision: https://phabricator.kde.org/D15703
parent fa6fa279
......@@ -92,6 +92,7 @@ set( kwin4_effect_builtins_sources
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( presentwindows )
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 )
......
#######################################
# 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
)
......@@ -26,6 +26,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <xcb/render.h>
#endif
#include <KGlobalAccel>
#include <KLocalizedString>
#include <QAction>
#include <QPainter>
namespace KWin
......@@ -42,6 +46,18 @@ static const QVector<QColor> s_colors {
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 @@ void ShowPaintEffect::paintQPainter()
}
}
bool ShowPaintEffect::isActive() const
{
return m_active;
}
void ShowPaintEffect::toggle()
{
m_active = !m_active;
effects->addRepaintFull();
}
} // namespace KWin
......@@ -31,14 +31,22 @@ class ShowPaintEffect : public Effect
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;
};
......
/********************************************************************
KWin - the KDE window manager
This file is part of the KDE project.
Copyright (C) 2018 Vlad Zagorodniy <vladzzag@gmail.com>
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 <http://www.gnu.org/licenses/>.
*********************************************************************/
#include "showpaint_config.h"
#include <KAboutData>
#include <KActionCollection>
#include <KGlobalAccel>
#include <KLocalizedString>
#include <KPluginFactory>
#include <KShortcutsEditor>
#include <QAction>
K_PLUGIN_FACTORY_WITH_JSON(ShowPaintEffectConfigFactory,
"showpaint_config.json",
registerPlugin<KWin::ShowPaintEffectConfig>();)
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"
[Desktop Entry]
Type=Service
X-KDE-ServiceTypes=KCModule
X-KDE-Library=kwin_showpaint_config
X-KDE-ParentComponents=showpaint
Name=Show Paint
/********************************************************************
KWin - the KDE window manager
This file is part of the KDE project.
Copyright (C) 2018 Vlad Zagorodniy <vladzzag@gmail.com>
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 <http://www.gnu.org/licenses/>.
*********************************************************************/
#pragma once
#include <KCModule>
#include "ui_showpaint_config.h"
namespace KWin
{
class ShowPaintEffectConfig : public KCModule
{
Q_OBJECT
public:
explicit ShowPaintEffectConfig(QWidget *parent = nullptr, const QVariantList &args = {});
~ShowPaintEffectConfig() override;
public Q_SLOTS:
void save() override;
void defaults() override;
private:
Ui::ShowPaintEffectConfig *m_ui;
};
} // namespace KWin
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>ShowPaintEffectConfig</class>
<widget class="QWidget" name="ShowPaintEffectConfig">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>452</width>
<height>246</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="KShortcutsEditor" name="shortcutsEditor" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="actionTypes">
<enum>KShortcutsEditor::GlobalAction</enum>
</property>
</widget>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>KShortcutsEditor</class>
<extends>QWidget</extends>
<header location="global">KShortcutsEditor</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment