Add invert effect which inverts aka negates desktop's colors.

Shortcut is Ctrl+F6 for now.
  Requires shaders.

svn path=/trunk/KDE/kdebase/workspace/; revision=683162
This commit is contained in:
Rivo Laks 2007-07-04 09:59:07 +00:00
parent 2632c2ff56
commit f69139e825
6 changed files with 119 additions and 0 deletions

View file

@ -60,6 +60,7 @@ if(OPENGL_FOUND)
SET(kwin4_effect_builtins_sources ${kwin4_effect_builtins_sources} SET(kwin4_effect_builtins_sources ${kwin4_effect_builtins_sources}
blur.cpp blur.cpp
explosioneffect.cpp explosioneffect.cpp
invert.cpp
magnifier.cpp magnifier.cpp
mousemark.cpp mousemark.cpp
shadow.cpp shadow.cpp
@ -68,6 +69,7 @@ if(OPENGL_FOUND)
install( FILES install( FILES
blur.desktop blur.desktop
explosion.desktop explosion.desktop
invert.desktop
magnifier.desktop magnifier.desktop
mousemark.desktop mousemark.desktop
shadow.desktop shadow.desktop
@ -83,6 +85,8 @@ if(OPENGL_FOUND)
data/blur.vert data/blur.vert
data/blur-render.frag data/blur-render.frag
data/blur-render.vert data/blur-render.vert
data/invert.frag
data/invert.vert
DESTINATION ${DATA_INSTALL_DIR}/kwin ) DESTINATION ${DATA_INSTALL_DIR}/kwin )
# config modules # config modules

18
effects/data/invert.frag Normal file
View file

@ -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);
}

6
effects/data/invert.vert Normal file
View file

@ -0,0 +1,6 @@
void main()
{
gl_TexCoord[0].xy = gl_Vertex.xy;
gl_Position = ftransform();
}

42
effects/invert.cpp Normal file
View file

@ -0,0 +1,42 @@
/*****************************************************************
KWin - the KDE window manager
This file is part of the KDE project.
Copyright (C) 2007 Rivo Laks <rivolaks@hot.ee>
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 <kactioncollection.h>
#include <kaction.h>
#include <klocale.h>
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"

15
effects/invert.desktop Normal file
View file

@ -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

34
effects/invert.h Normal file
View file

@ -0,0 +1,34 @@
/*****************************************************************
KWin - the KDE window manager
This file is part of the KDE project.
Copyright (C) 2007 Rivo Laks <rivolaks@hot.ee>
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 <kwinshadereffect.h>
namespace KWin
{
/**
* Inverts desktop's colors
**/
class InvertEffect : public QObject, public ShaderEffect
{
Q_OBJECT
public:
InvertEffect();
public slots:
void toggle();
};
} // namespace
#endif