diff --git a/effects/CMakeLists.txt b/effects/CMakeLists.txt index 0ffee550a1..31e67a6a25 100644 --- a/effects/CMakeLists.txt +++ b/effects/CMakeLists.txt @@ -60,6 +60,7 @@ if(OPENGL_FOUND) SET(kwin4_effect_builtins_sources ${kwin4_effect_builtins_sources} blur.cpp explosioneffect.cpp + invert.cpp magnifier.cpp mousemark.cpp shadow.cpp @@ -68,6 +69,7 @@ if(OPENGL_FOUND) install( FILES blur.desktop explosion.desktop + invert.desktop magnifier.desktop mousemark.desktop shadow.desktop @@ -83,6 +85,8 @@ if(OPENGL_FOUND) data/blur.vert data/blur-render.frag data/blur-render.vert + data/invert.frag + data/invert.vert DESTINATION ${DATA_INSTALL_DIR}/kwin ) # config modules diff --git a/effects/data/invert.frag b/effects/data/invert.frag new file mode 100644 index 0000000000..4e124fd31c --- /dev/null +++ b/effects/data/invert.frag @@ -0,0 +1,18 @@ +uniform sampler2D sceneTex; +uniform float textureWidth; +uniform float textureHeight; + + +// Converts pixel coordinates to texture coordinates +vec2 pix2tex(vec2 pix) +{ + return vec2(pix.x / textureWidth, 1.0 - pix.y / textureHeight); +} + +void main() +{ + vec3 tex = texture2D(sceneTex, pix2tex(gl_TexCoord[0].xy)).rgb; + + gl_FragColor = vec4(vec3(1.0) - tex, 1.0); +} + diff --git a/effects/data/invert.vert b/effects/data/invert.vert new file mode 100644 index 0000000000..066ac6c2aa --- /dev/null +++ b/effects/data/invert.vert @@ -0,0 +1,6 @@ +void main() +{ + gl_TexCoord[0].xy = gl_Vertex.xy; + gl_Position = ftransform(); +} + diff --git a/effects/invert.cpp b/effects/invert.cpp new file mode 100644 index 0000000000..00417357c5 --- /dev/null +++ b/effects/invert.cpp @@ -0,0 +1,42 @@ +/***************************************************************** + KWin - the KDE window manager + This file is part of the KDE project. + +Copyright (C) 2007 Rivo Laks + +You can Freely distribute this program under the GNU General Public +License. See the file "COPYING" for the exact licensing terms. +******************************************************************/ + + +#include "invert.h" + +#include +#include +#include + + +namespace KWin +{ + +KWIN_EFFECT( invert, InvertEffect ) +KWIN_EFFECT_SUPPORTED( invert, ShaderEffect::supported() ) + + +InvertEffect::InvertEffect() : QObject(), ShaderEffect("invert") + { + KActionCollection* actionCollection = new KActionCollection( this ); + KAction* a = (KAction*)actionCollection->addAction( "Invert" ); + a->setText( i18n("Toggle Invert effect" )); + a->setGlobalShortcut(KShortcut(Qt::CTRL + Qt::Key_F6)); + connect(a, SIGNAL(triggered(bool)), this, SLOT(toggle())); + } + +void InvertEffect::toggle() + { + setEnabled( !isEnabled()); + } + +} // namespace + +#include "invert.moc" diff --git a/effects/invert.desktop b/effects/invert.desktop new file mode 100644 index 0000000000..608df7a3f5 --- /dev/null +++ b/effects/invert.desktop @@ -0,0 +1,15 @@ +[Desktop Entry] +Encoding=UTF-8 +Name=Invert + +Type=Service +ServiceTypes=KWin/Effect +X-KDE-PluginInfo-Author=Rivo Laks +X-KDE-PluginInfo-Email=rivolaks@hot.ee +X-KDE-PluginInfo-Name=kwin4_effect_invert +X-KDE-PluginInfo-Version=0.1.0 +X-KDE-PluginInfo-Category=Appearance +X-KDE-PluginInfo-Depends= +X-KDE-PluginInfo-License=GPL +X-KDE-PluginInfo-EnabledByDefault=true +X-KDE-Library=kwin4_effect_builtins diff --git a/effects/invert.h b/effects/invert.h new file mode 100644 index 0000000000..c09e7c1838 --- /dev/null +++ b/effects/invert.h @@ -0,0 +1,34 @@ +/***************************************************************** + KWin - the KDE window manager + This file is part of the KDE project. + +Copyright (C) 2007 Rivo Laks + +You can Freely distribute this program under the GNU General Public +License. See the file "COPYING" for the exact licensing terms. +******************************************************************/ + +#ifndef KWIN_INVERT_H +#define KWIN_INVERT_H + +#include + +namespace KWin +{ + +/** + * Inverts desktop's colors + **/ +class InvertEffect : public QObject, public ShaderEffect + { + Q_OBJECT + public: + InvertEffect(); + + public slots: + void toggle(); + }; + +} // namespace + +#endif