diff --git a/effects/CMakeLists.txt b/effects/CMakeLists.txt index 85595eabf..23e157d8e 100644 --- a/effects/CMakeLists.txt +++ b/effects/CMakeLists.txt @@ -1,195 +1,196 @@ # KI18N Translation Domain for this library add_definitions(-DTRANSLATION_DOMAIN=\"kwin_effects\" -DEFFECT_BUILTINS) include_directories(${KWIN_SOURCE_DIR}) # for xcbutils.h set(kwin_effect_OWN_LIBS kwineffects ) if( KWIN_HAVE_XRENDER_COMPOSITING ) set(kwin_effect_OWN_LIBS ${kwin_effect_OWN_LIBS} kwinxrenderutils) endif() set(kwin_effect_KDE_LIBS KF5::ConfigGui KF5::ConfigWidgets KF5::GlobalAccel KF5::I18n KF5::WindowSystem KF5::Plasma # screenedge effect KF5::IconThemes KF5::Service KF5::Notifications # screenshot effect ) set(kwin_effect_QT_LIBS Qt5::Concurrent Qt5::DBus Qt5::Quick Qt5::X11Extras ) set(kwin_effect_XLIB_LIBS ${X11_X11_LIB} ) set(kwin_effect_XCB_LIBS XCB::XCB XCB::IMAGE XCB::XFIXES ) if( KWIN_HAVE_XRENDER_COMPOSITING ) set(kwin_effect_XCB_LIBS ${kwin_effect_XCB_LIBS} XCB::RENDER) endif() set(kwin_effect_OWN_LIBS ${kwin_effect_OWN_LIBS} kwinglutils) macro( KWIN4_ADD_EFFECT_BACKEND name ) add_library( ${name} SHARED ${ARGN} ) target_link_libraries( ${name} PRIVATE ${kwin_effect_OWN_LIBS} ${kwin_effect_KDE_LIBS} ${kwin_effect_QT_LIBS} ${kwin_effect_XLIB_LIBS} ${kwin_effect_XCB_LIBS}) endmacro() # Adds effect plugin with given name. Sources are given after the name macro( KWIN4_ADD_EFFECT name ) kwin4_add_effect_backend(kwin4_effect_${name} ${ARGN}) set_target_properties(kwin4_effect_${name} PROPERTIES VERSION 1.0.0 SOVERSION 1 ) set_target_properties(kwin4_effect_${name} PROPERTIES OUTPUT_NAME ${KWIN_NAME}4_effect_${name}) install(TARGETS kwin4_effect_${name} ${INSTALL_TARGETS_DEFAULT_ARGS} ) endmacro() # Install the KWin/Effect service type install( FILES kwineffect.desktop DESTINATION ${SERVICETYPES_INSTALL_DIR} ) # Create initial variables set( kwin4_effect_include_directories ) set( kwin4_effect_builtins_sources logging.cpp effect_builtins.cpp blur/blur.cpp blur/blurshader.cpp colorpicker/colorpicker.cpp cube/cube.cpp cube/cube_proxy.cpp cubeslide/cubeslide.cpp coverswitch/coverswitch.cpp desktopgrid/desktopgrid.cpp diminactive/diminactive.cpp flipswitch/flipswitch.cpp glide/glide.cpp invert/invert.cpp lookingglass/lookingglass.cpp magiclamp/magiclamp.cpp magnifier/magnifier.cpp mouseclick/mouseclick.cpp mousemark/mousemark.cpp presentwindows/presentwindows.cpp presentwindows/presentwindows_proxy.cpp resize/resize.cpp scale/scale.cpp showfps/showfps.cpp + showpaint/showpaint.cpp slide/slide.cpp thumbnailaside/thumbnailaside.cpp touchpoints/touchpoints.cpp trackmouse/trackmouse.cpp windowgeometry/windowgeometry.cpp wobblywindows/wobblywindows.cpp zoom/zoom.cpp ) qt5_add_resources( kwin4_effect_builtins_sources shaders.qrc ) kconfig_add_kcfg_files(kwin4_effect_builtins_sources blur/blurconfig.kcfgc cube/cubeconfig.kcfgc cubeslide/cubeslideconfig.kcfgc coverswitch/coverswitchconfig.kcfgc desktopgrid/desktopgridconfig.kcfgc diminactive/diminactiveconfig.kcfgc fallapart/fallapartconfig.kcfgc flipswitch/flipswitchconfig.kcfgc glide/glideconfig.kcfgc lookingglass/lookingglassconfig.kcfgc magiclamp/magiclampconfig.kcfgc magnifier/magnifierconfig.kcfgc mouseclick/mouseclickconfig.kcfgc mousemark/mousemarkconfig.kcfgc presentwindows/presentwindowsconfig.kcfgc resize/resizeconfig.kcfgc scale/scaleconfig.kcfgc showfps/showfpsconfig.kcfgc slide/slideconfig.kcfgc slidingpopups/slidingpopupsconfig.kcfgc thumbnailaside/thumbnailasideconfig.kcfgc trackmouse/trackmouseconfig.kcfgc windowgeometry/windowgeometryconfig.kcfgc wobblywindows/wobblywindowsconfig.kcfgc zoom/zoomconfig.kcfgc ) # scripted effects add_subdirectory( dialogparent ) add_subdirectory( eyeonscreen ) add_subdirectory( fade ) add_subdirectory( fadedesktop ) add_subdirectory( frozenapp ) add_subdirectory( login ) add_subdirectory( logout ) add_subdirectory( maximize ) add_subdirectory( morphingpopups ) add_subdirectory( translucency ) add_subdirectory( windowaperture ) ############################################################################### # Built-in effects go here # Common effects add_subdirectory( desktopgrid ) add_subdirectory( diminactive ) include( dimscreen/CMakeLists.txt ) include( fallapart/CMakeLists.txt ) include( highlightwindow/CMakeLists.txt ) include( kscreen/CMakeLists.txt ) add_subdirectory( magiclamp ) include( minimizeanimation/CMakeLists.txt ) 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 ) add_subdirectory( thumbnailaside ) add_subdirectory( windowgeometry ) add_subdirectory( zoom ) # OpenGL-specific effects add_subdirectory( blur ) include( backgroundcontrast/CMakeLists.txt ) add_subdirectory( coverswitch ) add_subdirectory( cube ) add_subdirectory( cubeslide ) add_subdirectory( flipswitch ) add_subdirectory( glide ) add_subdirectory( invert ) add_subdirectory( lookingglass ) add_subdirectory( magnifier ) add_subdirectory( mouseclick ) add_subdirectory( mousemark ) add_subdirectory( scale ) include( screenshot/CMakeLists.txt ) include( sheet/CMakeLists.txt ) include( snaphelper/CMakeLists.txt ) include( startupfeedback/CMakeLists.txt ) add_subdirectory( trackmouse ) add_subdirectory( wobblywindows ) ############################################################################### # Add the builtins plugin kwin4_add_effect( builtins ${kwin4_effect_builtins_sources} ) diff --git a/effects/showpaint/CMakeLists.txt b/effects/showpaint/CMakeLists.txt index 64a226b09..dc1d7ef02 100644 --- 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.cpp b/effects/showpaint/showpaint.cpp index 229cf05c5..42d4d66a1 100644 --- a/effects/showpaint/showpaint.cpp +++ b/effects/showpaint/showpaint.cpp @@ -1,126 +1,153 @@ /******************************************************************** KWin - the KDE window manager This file is part of the KDE project. Copyright (C) 2007 Lubos Lunak Copyright (C) 2010 Martin Gräßlin 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.h" #include #ifdef KWIN_HAVE_XRENDER_COMPOSITING #include #endif +#include +#include + +#include #include namespace KWin { static const qreal s_alpha = 0.2; static const QVector s_colors { Qt::red, Qt::green, Qt::blue, Qt::cyan, Qt::magenta, Qt::yellow, 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(); effects->paintScreen(mask, region, data); if (effects->isOpenGLCompositing()) { paintGL(data.projectionMatrix()); } #ifdef KWIN_HAVE_XRENDER_COMPOSITING if (effects->compositingType() == XRenderCompositing) { paintXrender(); } #endif if (effects->compositingType() == QPainterCompositing) { paintQPainter(); } if (++m_colorIndex == s_colors.count()) { m_colorIndex = 0; } } void ShowPaintEffect::paintWindow(EffectWindow *w, int mask, QRegion region, WindowPaintData &data) { m_painted |= region; effects->paintWindow(w, mask, region, data); } void ShowPaintEffect::paintGL(const QMatrix4x4 &projection) { GLVertexBuffer *vbo = GLVertexBuffer::streamingBuffer(); vbo->reset(); vbo->setUseColor(true); ShaderBinder binder(ShaderTrait::UniformColor); binder.shader()->setUniform(GLShader::ModelViewProjectionMatrix, projection); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); QColor color = s_colors[m_colorIndex]; color.setAlphaF(s_alpha); vbo->setColor(color); QVector verts; verts.reserve(m_painted.rectCount() * 12); for (const QRect &r : m_painted) { verts << r.x() + r.width() << r.y(); verts << r.x() << r.y(); verts << r.x() << r.y() + r.height(); verts << r.x() << r.y() + r.height(); verts << r.x() + r.width() << r.y() + r.height(); verts << r.x() + r.width() << r.y(); } vbo->setData(verts.count() / 2, 2, verts.data(), nullptr); vbo->render(GL_TRIANGLES); glDisable(GL_BLEND); } void ShowPaintEffect::paintXrender() { #ifdef KWIN_HAVE_XRENDER_COMPOSITING xcb_render_color_t col; const QColor &color = s_colors[m_colorIndex]; col.alpha = int(s_alpha * 0xffff); col.red = int(s_alpha * 0xffff * color.red() / 255); col.green = int(s_alpha * 0xffff * color.green() / 255); col.blue = int(s_alpha * 0xffff * color.blue() / 255); QVector rects; rects.reserve(m_painted.rectCount()); for (const QRect &r : m_painted) { xcb_rectangle_t rect = {int16_t(r.x()), int16_t(r.y()), uint16_t(r.width()), uint16_t(r.height())}; rects << rect; } xcb_render_fill_rectangles(xcbConnection(), XCB_RENDER_PICT_OP_OVER, effects->xrenderBufferPicture(), col, rects.count(), rects.constData()); #endif } void ShowPaintEffect::paintQPainter() { QColor color = s_colors[m_colorIndex]; color.setAlphaF(s_alpha); for (const QRect &r : m_painted) { effects->scenePainter()->fillRect(r, color); } } +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.h index abd1e1933..c2f0c83a5 100644 --- a/effects/showpaint/showpaint.h +++ b/effects/showpaint/showpaint.h @@ -1,48 +1,56 @@ /******************************************************************** KWin - the KDE window manager This file is part of the KDE project. Copyright (C) 2007 Lubos Lunak 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 . *********************************************************************/ #ifndef KWIN_SHOWPAINT_H #define KWIN_SHOWPAINT_H #include namespace KWin { 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; }; } // namespace KWin #endif diff --git a/effects/showpaint/showpaint_config.cpp b/effects/showpaint/showpaint_config.cpp new file mode 100644 index 000000000..2f33e8e9a --- /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 index 000000000..b6d83dffc --- /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.h b/effects/showpaint/showpaint_config.h similarity index 63% copy from effects/showpaint/showpaint.h copy to effects/showpaint/showpaint_config.h index abd1e1933..976f0e8de 100644 --- a/effects/showpaint/showpaint.h +++ b/effects/showpaint/showpaint_config.h @@ -1,48 +1,46 @@ /******************************************************************** 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 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 . *********************************************************************/ -#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.ui b/effects/showpaint/showpaint_config.ui new file mode 100644 index 000000000..93e77ba12 --- /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 +
+
+ + +