From ca5451fef0231ca4c7a3d3bf8fc5e9432bdfa339 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lubo=C5=A1=20Lu=C5=88=C3=A1k?= Date: Wed, 11 Apr 2007 15:46:46 +0000 Subject: [PATCH] Convert WavyWindows to plugins (and move Vertex class to the effects lib). svn path=/branches/work/kwin_composite/; revision=652628 --- effects.cpp | 22 ++++++++++++++++++++++ effects.h | 4 ++++ effects/CMakeLists.txt | 2 ++ effects/wavywindows.cpp | 29 ++++++++++++----------------- effects/wavywindows.desktop | 4 ++++ effects/wavywindows.h | 2 +- lib/kwineffects.h | 30 ++++++++++++++++++++++++++++++ scene_opengl.h | 20 -------------------- 8 files changed, 75 insertions(+), 38 deletions(-) create mode 100644 effects/wavywindows.desktop diff --git a/effects.cpp b/effects.cpp index 4c4e256cba..d9dc99953c 100644 --- a/effects.cpp +++ b/effects.cpp @@ -14,6 +14,7 @@ License. See the file "COPYING" for the exact licensing terms. #include "client.h" #include "group.h" #include "scene_xrender.h" +#include "scene_opengl.h" #include "workspace.h" #include @@ -717,6 +718,27 @@ bool EffectWindowImpl::isDNDIcon() const return toplevel->isDNDIcon(); } +QVector& EffectWindowImpl::vertices() + { + if( SceneOpenGL::Window* w = dynamic_cast< SceneOpenGL::Window* >( sceneWindow())) + return w->vertices(); + abort(); // TODO + } + +void EffectWindowImpl::requestVertexGrid(int maxquadsize) + { + if( SceneOpenGL::Window* w = dynamic_cast< SceneOpenGL::Window* >( sceneWindow())) + return w->requestVertexGrid( maxquadsize ); + abort(); // TODO + } + +void EffectWindowImpl::markVerticesDirty() + { + if( SceneOpenGL::Window* w = dynamic_cast< SceneOpenGL::Window* >( sceneWindow())) + return w->markVerticesDirty(); + abort(); // TODO + } + EffectWindow* effectWindow( Toplevel* w ) { EffectWindowImpl* ret = w->effectWindow(); diff --git a/effects.h b/effects.h index 5912786d12..89e0ba9481 100644 --- a/effects.h +++ b/effects.h @@ -129,6 +129,10 @@ class EffectWindowImpl : public EffectWindow virtual bool isComboBox() const; virtual bool isDNDIcon() const; + virtual QVector& vertices(); + virtual void requestVertexGrid(int maxquadsize); + virtual void markVerticesDirty(); + const Toplevel* window() const; Toplevel* window(); diff --git a/effects/CMakeLists.txt b/effects/CMakeLists.txt index 15a95d0bcc..de8f1707a1 100644 --- a/effects/CMakeLists.txt +++ b/effects/CMakeLists.txt @@ -19,9 +19,11 @@ SET(kwin4_effect_builtins_sources if(OPENGL_FOUND) SET(kwin4_effect_builtins_sources ${kwin4_effect_builtins_sources} shadow.cpp + wavywindows.cpp ) install( FILES shadow.desktop + wavywindows.desktop DESTINATION ${DATA_INSTALL_DIR}/kwin/effects ) endif(OPENGL_FOUND) diff --git a/effects/wavywindows.cpp b/effects/wavywindows.cpp index b6cfe40437..47c3447890 100644 --- a/effects/wavywindows.cpp +++ b/effects/wavywindows.cpp @@ -11,10 +11,6 @@ License. See the file "COPYING" for the exact licensing terms. #include "wavywindows.h" -#include -#include -#include - #include @@ -24,6 +20,8 @@ License. See the file "COPYING" for the exact licensing terms. namespace KWin { +KWIN_EFFECT( WavyWindows, WavyWindowsEffect ) + WavyWindowsEffect::WavyWindowsEffect() { mTimeElapsed = 0.0f; @@ -36,7 +34,7 @@ void WavyWindowsEffect::prePaintScreen( int* mask, QRegion* region, int time ) mTimeElapsed += (time / 1000.0f); // We need to mark the screen windows as transformed. Otherwise the whole // screen won't be repainted, resulting in artefacts - *mask |= Scene::PAINT_SCREEN_WITH_TRANSFORMED_WINDOWS; + *mask |= PAINT_SCREEN_WITH_TRANSFORMED_WINDOWS; effects->prePaintScreen(mask, region, time); } @@ -44,13 +42,11 @@ void WavyWindowsEffect::prePaintScreen( int* mask, QRegion* region, int time ) void WavyWindowsEffect::prePaintWindow( EffectWindow* w, int* mask, QRegion* paint, QRegion* clip, int time ) { // This window will be transformed by the effect - *mask |= Scene::PAINT_WINDOW_TRANSFORMED; + *mask |= PAINT_WINDOW_TRANSFORMED; // Check if OpenGL compositing is used - SceneOpenGL::Window* glwin = dynamic_cast< SceneOpenGL::Window *>( w->sceneWindow() ); - if(glwin) - // Request the window to be divided into cells which are at most 30x30 - // pixels big - glwin->requestVertexGrid(30); + // Request the window to be divided into cells which are at most 30x30 + // pixels big + w->requestVertexGrid(30); effects->prePaintWindow( w, mask, paint, clip, time ); } @@ -59,14 +55,13 @@ void WavyWindowsEffect::paintWindow( EffectWindow* w, int mask, QRegion region, { // Make sure we have OpenGL compositing and the window is vidible and not a // special window - SceneOpenGL::Window* glwin = dynamic_cast< SceneOpenGL::Window* >( w->sceneWindow() ); - Client* c = qobject_cast< Client* >( w->window() ); - if( glwin && glwin->isVisible() && c && !c->isSpecialWindow() ) +// TODO if( w->isVisible() && !w->isSpecialWindow() ) + if( !w->isSpecialWindow() ) { // We have OpenGL compositing and the window has been subdivided // because of our request (in pre-paint pass) // Transform all the vertices to create wavy effect - QVector< SceneOpenGL::Window::Vertex >& vertices = glwin->vertices(); + QVector< Vertex >& vertices = w->vertices(); for(int i = 0; i < vertices.count(); i++) { vertices[i].pos[0] += sin(mTimeElapsed + vertices[i].texcoord[1] / 60 + 0.5f) * 10; @@ -74,7 +69,7 @@ void WavyWindowsEffect::paintWindow( EffectWindow* w, int mask, QRegion region, } // We have changed the vertices, so they will have to be reset before // the next paint pass - glwin->markVerticesDirty(); + w->markVerticesDirty(); } // Call the next effect. @@ -84,7 +79,7 @@ void WavyWindowsEffect::paintWindow( EffectWindow* w, int mask, QRegion region, void WavyWindowsEffect::postPaintScreen() { // Repaint the workspace so that everything would be repainted next time - workspace()->addRepaintFull(); + effects->addRepaintFull(); // Call the next effect. effects->postPaintScreen(); diff --git a/effects/wavywindows.desktop b/effects/wavywindows.desktop new file mode 100644 index 0000000000..ab4db766c0 --- /dev/null +++ b/effects/wavywindows.desktop @@ -0,0 +1,4 @@ +[Desktop Entry] +Encoding=UTF-8 +Name=WavyWindows +X-KDE-Library=kwin4_effect_builtins diff --git a/effects/wavywindows.h b/effects/wavywindows.h index 6b8fa4e247..5efbcbe692 100644 --- a/effects/wavywindows.h +++ b/effects/wavywindows.h @@ -12,7 +12,7 @@ License. See the file "COPYING" for the exact licensing terms. #define KWIN_WAVYWINDOWS_H // Include with base class for effects. -#include +#include namespace KWin diff --git a/lib/kwineffects.h b/lib/kwineffects.h index cc1d019312..61f91dd3a0 100644 --- a/lib/kwineffects.h +++ b/lib/kwineffects.h @@ -34,6 +34,7 @@ namespace KWin class EffectWindow; class EffectWindowGroup; class Effect; +class Vertex; typedef QPair< QString, Effect* > EffectPair; typedef QPair< Effect*, Window > InputWindowPair; @@ -270,6 +271,14 @@ class KWIN_EXPORT EffectWindow virtual bool isComboBox() const = 0; virtual bool isDNDIcon() const = 0; + virtual QVector& vertices() = 0; + // Can be called in pre-paint pass. Makes sure that all quads that the + // window consists of are not bigger than maxquadsize x maxquadsize + // (in pixels) in the following paint pass. + virtual void requestVertexGrid(int maxquadsize) = 0; + // Marks vertices of the window as dirty. Call this if you change + // position of the vertices + virtual void markVerticesDirty() = 0; }; class KWIN_EXPORT EffectWindowGroup @@ -279,6 +288,27 @@ class KWIN_EXPORT EffectWindowGroup virtual EffectWindowList members() const = 0; }; +/** + * @short Vertex class + * Vertex has position and texture coordinate which are equal at first, + * however effects can e.g. modify position to move the window or part of it. + **/ +class KWIN_EXPORT Vertex +{ + public: + Vertex() {} + Vertex(float x, float y) + { + pos[0] = texcoord[0] = x; pos[1] = texcoord[1] = y; pos[2] = 0.0f; + } + Vertex(float x, float y, float u, float v) + { + pos[0] = x; pos[1] = y; pos[2] = 0.0f; texcoord[0] = u; texcoord[1] = v; + } + float pos[3]; + float texcoord[2]; +}; + extern KWIN_EXPORT EffectsHandler* effects; diff --git a/scene_opengl.h b/scene_opengl.h index be6c141a1c..235095b207 100644 --- a/scene_opengl.h +++ b/scene_opengl.h @@ -122,26 +122,6 @@ class SceneOpenGL::Window void discardTexture(); void discardVertices(); - /** - * @short Vertex class - * Vertex has position and texture coordinate which are equal at first, - * however effects can e.g. modify position to move the window or part of it. - **/ - class Vertex - { - public: - Vertex() {} - Vertex(float x, float y) - { - pos[0] = texcoord[0] = x; pos[1] = texcoord[1] = y; pos[2] = 0.0f; - } - Vertex(float x, float y, float u, float v) - { - pos[0] = x; pos[1] = y; pos[2] = 0.0f; texcoord[0] = u; texcoord[1] = v; - } - float pos[3]; - float texcoord[2]; - }; // Returns list of vertices QVector& vertices() { return verticeslist; } // Can be called in pre-paint pass. Makes sure that all quads that the