Port to plugins.

svn path=/branches/work/kwin_composite/; revision=652956
This commit is contained in:
Luboš Luňák 2007-04-12 11:55:07 +00:00
parent 6bf23a5c48
commit 8e25dd6bfa
26 changed files with 172 additions and 123 deletions

View file

@ -570,6 +570,20 @@ bool EffectWindowImpl::isDeleted() const
return (dynamic_cast<Deleted*>( toplevel ) != 0);
}
void EffectWindowImpl::refWindow()
{
if( Deleted* d = dynamic_cast< Deleted* >( toplevel ))
return d->refWindow();
abort(); // TODO
}
void EffectWindowImpl::unrefWindow()
{
if( Deleted* d = dynamic_cast< Deleted* >( toplevel ))
return d->unrefWindow();
abort(); // TODO
}
const Toplevel* EffectWindowImpl::window() const
{
return toplevel;
@ -635,6 +649,27 @@ QRect EffectWindowImpl::rect() const
return toplevel->rect();
}
bool EffectWindowImpl::isUserMove() const
{
if( Client* c = dynamic_cast< Client* >( toplevel ))
return c->isMove();
return false;
}
bool EffectWindowImpl::isUserResize() const
{
if( Client* c = dynamic_cast< Client* >( toplevel ))
return c->isResize();
return false;
}
QRect EffectWindowImpl::iconGeometry() const
{
if( Client* c = dynamic_cast< Client* >( toplevel ))
return c->iconGeometry();
return QRect();
}
bool EffectWindowImpl::isDesktop() const
{
return toplevel->isDesktop();

View file

@ -95,6 +95,8 @@ class EffectWindowImpl : public EffectWindow
virtual void addRepaint( int x, int y, int w, int h );
virtual void addRepaintFull();
virtual void refWindow();
virtual void unrefWindow();
virtual bool isDeleted() const;
virtual bool isOnAllDesktops() const;
@ -111,6 +113,9 @@ class EffectWindowImpl : public EffectWindow
virtual QPoint pos() const;
virtual QSize size() const;
virtual QRect rect() const;
virtual bool isUserMove() const;
virtual bool isUserResize() const;
virtual QRect iconGeometry() const;
virtual bool isDesktop() const;
virtual bool isDock() const;

View file

@ -11,12 +11,18 @@ include_directories(
)
SET(kwin4_effect_builtins_sources
presentwindows.cpp
diminactive.cpp
flame.cpp
maketransparent.cpp
minimizeanimation.cpp
presentwindows.cpp
scalein.cpp
shakymove.cpp
zoom.cpp
)
SET(kwin4_effect_tests_sources
howto.cpp
test_input.cpp
test_shiftworkspaceup.cpp
test_thumbnail.cpp
@ -56,8 +62,14 @@ endif (X11_Xrender_FOUND)
KWIN4_ADD_EFFECT(tests ${kwin4_effect_tests_sources})
install( FILES
presentwindows.desktop
diminactive.desktop
flame.desktop
howto.desktop
maketransparent.desktop
minimizeanimation.desktop
presentwindows.desktop
scalein.desktop
shakymove.desktop
zoom.desktop
test_input.desktop
test_shiftworkspaceup.desktop

View file

@ -15,9 +15,6 @@ License. See the file "COPYING" for the exact licensing terms.
#include <client.h>
// Note that currently effects need to be manually enabled in the EffectsHandler
// class constructor (in effects.cpp).
namespace KWin
{

View file

@ -13,9 +13,6 @@ License. See the file "COPYING" for the exact licensing terms.
#include <client.h>
// Note that currently effects need to be manually enabled in the EffectsHandler
// class constructor (in effects.cpp).
namespace KWin
{

View file

@ -10,16 +10,17 @@ License. See the file "COPYING" for the exact licensing terms.
#include "flame.h"
#include <deleted.h>
#include <scene_opengl.h>
#include <assert.h>
namespace KWin
{
KWIN_EFFECT( Flame, FlameEffect )
void FlameEffect::prePaintScreen( int* mask, QRegion* region, int time )
{
if( !windows.isEmpty())
*mask |= Scene::PAINT_SCREEN_WITH_TRANSFORMED_WINDOWS;
*mask |= PAINT_SCREEN_WITH_TRANSFORMED_WINDOWS;
effects->prePaintScreen(mask, region, time);
}
@ -27,22 +28,18 @@ void FlameEffect::prePaintWindow( EffectWindow* w, int* mask, QRegion* paint, QR
{
if( windows.contains( w ))
{
SceneOpenGL::Window* glwin = dynamic_cast< SceneOpenGL::Window* >( w->sceneWindow());
if( glwin )
if( windows[ w ] < 1 )
{
if( windows[ w ] < 1 )
{
windows[ w ] += time / 500.;
*mask |= Scene::PAINT_WINDOW_TRANSFORMED;
glwin->enablePainting( Scene::Window::PAINT_DISABLED_BY_DELETE );
// Request the window to be divided into cells
glwin->requestVertexGrid( qMax( glwin->height() / 50, 5 ));
}
else
{
windows.remove( w );
static_cast< Deleted* >( w->window())->unrefWindow();
}
windows[ w ] += time / 500.;
*mask |= PAINT_WINDOW_TRANSFORMED;
w->enablePainting( EffectWindow::PAINT_DISABLED_BY_DELETE );
// Request the window to be divided into cells
w->requestVertexGrid( qMax( w->height() / 50, 5 ));
}
else
{
windows.remove( w );
w->unrefWindow();
}
}
effects->prePaintWindow( w, mask, paint, clip, time );
@ -52,38 +49,34 @@ void FlameEffect::paintWindow( EffectWindow* w, int mask, QRegion region, Window
{
if( windows.contains( w ))
{
SceneOpenGL::Window* glwin = dynamic_cast< SceneOpenGL::Window* >( w->sceneWindow() );
if( glwin )
QVector< Vertex >& vertices = w->vertices();
QVector< Vertex > new_vertices;
double ylimit = windows[ w ] * w->height(); // parts above this are already away
assert( vertices.count() % 4 == 0 );
for( int i = 0;
i < vertices.count();
i += 4 )
{
QVector< SceneOpenGL::Window::Vertex >& vertices = glwin->vertices();
QVector< SceneOpenGL::Window::Vertex > new_vertices;
double ylimit = windows[ w ] * w->height(); // parts above this are already away
assert( vertices.count() % 4 == 0 );
for( int i = 0;
i < vertices.count();
i += 4 )
bool is_in = false;
for( int j = 0;
j < 4;
++j )
if( vertices[ i + j ].pos[ 1 ] >= ylimit )
is_in = true;
if( !is_in )
continue;
for( int j = 0;
j < 4;
++j )
{
bool is_in = false;
for( int j = 0;
j < 4;
++j )
if( vertices[ i + j ].pos[ 1 ] >= ylimit )
is_in = true;
if( !is_in )
continue;
for( int j = 0;
j < 4;
++j )
{
SceneOpenGL::Window::Vertex vertex = vertices[ i + j ];
new_vertices.append( vertex );
}
Vertex vertex = vertices[ i + j ];
new_vertices.append( vertex );
}
if( new_vertices.isEmpty())
return; // nothing to paint
glwin->vertices() = new_vertices;
glwin->markVerticesDirty();
}
if( new_vertices.isEmpty())
return; // nothing to paint
w->vertices() = new_vertices;
w->markVerticesDirty();
}
effects->paintWindow( w, mask, region, data );
}
@ -91,14 +84,14 @@ void FlameEffect::paintWindow( EffectWindow* w, int mask, QRegion region, Window
void FlameEffect::postPaintWindow( EffectWindow* w )
{
if( windows.contains( w ))
workspace()->addRepaint( w->geometry()); // workspace, since the window under it will need painting too
effects->addRepaint( w->geometry()); // workspace, since the window under it will need painting too
effects->postPaintScreen();
}
void FlameEffect::windowClosed( EffectWindow* c )
{
windows[ c ] = 0;
static_cast< Deleted* >( c->window())->refWindow();
c->refWindow();
}
void FlameEffect::windowDeleted( EffectWindow* c )

4
effects/flame.desktop Normal file
View file

@ -0,0 +1,4 @@
[Desktop Entry]
Encoding=UTF-8
Name=Flame
X-KDE-Library=kwin4_effect_builtins

View file

@ -11,7 +11,7 @@ License. See the file "COPYING" for the exact licensing terms.
#ifndef KWIN_FLAME_H
#define KWIN_FLAME_H
#include <effects.h>
#include <kwineffects.h>
namespace KWin
{

View file

@ -20,11 +20,6 @@ License. See the file "COPYING" for the exact licensing terms.
// Include the class definition.
#include "howto.h"
#include "deleted.h"
// Note that currently effects need to be manually enabled in the EffectsHandler
// class constructor (in effects.cpp).
namespace KWin
{
@ -51,8 +46,8 @@ void HowtoEffect::prePaintWindow( EffectWindow* w, int* mask, QRegion* paint, QR
{
// Since the effect will make the window translucent, explicitly change
// the flags so that the window will be painted only as translucent.
*mask |= Scene::PAINT_WINDOW_TRANSLUCENT;
*mask &= ~Scene::PAINT_WINDOW_OPAQUE;
*mask |= PAINT_WINDOW_TRANSLUCENT;
*mask &= ~PAINT_WINDOW_OPAQUE;
}
else
{
@ -115,9 +110,7 @@ void HowtoEffect::postPaintWindow( EffectWindow* w )
if( w == fade_window )
{
// Trigger repaint of the whole window, this will cause it to be repainted the next painting pass.
// Currently the API for effects is not complete, so for now window() is used to access
// internal class Toplevel. This should change in the future.
w->window()->addRepaintFull(); // trigger next animation repaint
w->addRepaintFull(); // trigger next animation repaint
}
// Call the next effect.
effects->postPaintWindow( w );
@ -133,7 +126,7 @@ void HowtoEffect::windowActivated( EffectWindow* c )
// If there is a window to be faded, reset the progress to zero.
progress = 0;
// And add repaint to the window so that it needs to be repainted.
c->window()->addRepaintFull();
c->addRepaintFull();
}
}
@ -146,6 +139,7 @@ void HowtoEffect::windowClosed( EffectWindow* c )
fade_window = NULL;
}
// That's all. Don't forget to enable the effect as described at the beginning of this file.
// That's all. Now only the matching .desktop file is needed.
} // namespace

6
effects/howto.desktop Normal file
View file

@ -0,0 +1,6 @@
[Desktop Entry]
Encoding=UTF-8
# Name of the effect
Name=Howto
# The plugin (library) which contains the effect. One library may contain more effects.
X-KDE-Library=kwin4_effect_tests

View file

@ -19,7 +19,7 @@ License. See the file "COPYING" for the exact licensing terms.
#define KWIN_HOWTO_H
// Include with base class for effects.
#include <effects.h>
#include <kwineffects.h>
// Everything in KWin is in a namespace. There's no need to prefix names
// with KWin or K, there's no (big) need to care about symbol clashes.

View file

@ -10,36 +10,34 @@ License. See the file "COPYING" for the exact licensing terms.
#include "maketransparent.h"
#include <client.h>
namespace KWin
{
KWIN_EFFECT( MakeTransparent, MakeTransparentEffect )
void MakeTransparentEffect::prePaintWindow( EffectWindow* w, int* mask, QRegion* paint, QRegion* clip, int time )
{
const Client* c = dynamic_cast< const Client* >( w->window());
if(( c != NULL && ( c->isMove() || c->isResize())) || w->window()->isDialog())
if(( w->isUserMove() || w->isUserResize()) || w->isDialog())
{
*mask |= Scene::PAINT_WINDOW_TRANSLUCENT;
*mask &= ~Scene::PAINT_WINDOW_OPAQUE;
*mask |= PAINT_WINDOW_TRANSLUCENT;
*mask &= ~PAINT_WINDOW_OPAQUE;
}
effects->prePaintWindow( w, mask, paint, clip, time );
}
void MakeTransparentEffect::paintWindow( EffectWindow* w, int mask, QRegion region, WindowPaintData& data )
{
const Client* c = dynamic_cast< const Client* >( w->window());
if( w->window()->isDialog())
if( w->isDialog())
data.opacity *= 0.8;
if( c != NULL && ( c->isMove() || c->isResize()))
if( w->isUserMove() || w->isUserResize())
data.opacity *= 0.5;
effects->paintWindow( w, mask, region, data );
}
void MakeTransparentEffect::windowUserMovedResized( EffectWindow* c, bool first, bool last )
void MakeTransparentEffect::windowUserMovedResized( EffectWindow* w, bool first, bool last )
{
if( first || last )
c->window()->addRepaintFull();
w->addRepaintFull();
}
} // namespace

View file

@ -0,0 +1,4 @@
[Desktop Entry]
Encoding=UTF-8
Name=MakeTransparent
X-KDE-Library=kwin4_effect_builtins

View file

@ -11,7 +11,7 @@ License. See the file "COPYING" for the exact licensing terms.
#ifndef KWIN_MAKETRANSPARENT_H
#define KWIN_MAKETRANSPARENT_H
#include <effects.h>
#include <kwineffects.h>
namespace KWin
{

View file

@ -11,16 +11,11 @@ License. See the file "COPYING" for the exact licensing terms.
#include "minimizeanimation.h"
#include <workspace.h>
#include <client.h>
// Note that currently effects need to be manually enabled in the EffectsHandler
// class constructor (in effects.cpp).
namespace KWin
{
KWIN_EFFECT( MinimizeAnimation, MinimizeAnimationEffect )
MinimizeAnimationEffect::MinimizeAnimationEffect()
{
mActiveAnimations = 0;
@ -32,7 +27,7 @@ void MinimizeAnimationEffect::prePaintScreen( int* mask, QRegion* region, int ti
if( mActiveAnimations > 0 )
// 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);
}
@ -42,8 +37,7 @@ void MinimizeAnimationEffect::prePaintWindow( EffectWindow* w, int* mask, QRegio
const float changeTime = 500;
if( mAnimationProgress.contains( w ))
{
Client* c = static_cast< Client* >( w->window() );
if( c->isMinimized() )
if( w->isMinimized() )
{
mAnimationProgress[w] += time / changeTime;
if( mAnimationProgress[w] >= 1.0f )
@ -61,8 +55,8 @@ void MinimizeAnimationEffect::prePaintWindow( EffectWindow* w, int* mask, QRegio
if( mAnimationProgress.contains( w ))
{
// We'll transform this window
*mask |= Scene::PAINT_WINDOW_TRANSFORMED;
w->enablePainting( Scene::Window::PAINT_DISABLED_BY_MINIMIZE );
*mask |= PAINT_WINDOW_TRANSFORMED;
w->enablePainting( EffectWindow::PAINT_DISABLED_BY_MINIMIZE );
}
else
// Animation just finished
@ -79,9 +73,8 @@ void MinimizeAnimationEffect::paintWindow( EffectWindow* w, int mask, QRegion re
// 0 = not minimized, 1 = fully minimized
float progress = mAnimationProgress[w];
Client* c = static_cast< Client* >( w->window() );
QRect geo = c->geometry();
QRect icon = c->iconGeometry();
QRect geo = w->geometry();
QRect icon = w->iconGeometry();
// If there's no icon geometry, minimize to the center of the screen
if( !icon.isValid() )
icon = QRect( displayWidth() / 2, displayHeight() / 2, 0, 0 );
@ -100,7 +93,7 @@ void MinimizeAnimationEffect::postPaintScreen()
{
if( mActiveAnimations > 0 )
// Repaint the workspace so that everything would be repainted next time
workspace()->addRepaintFull();
effects->addRepaintFull();
// Call the next effect.
effects->postPaintScreen();

View file

@ -0,0 +1,4 @@
[Desktop Entry]
Encoding=UTF-8
Name=MinimizeAnimation
X-KDE-Library=kwin4_effect_builtins

View file

@ -12,7 +12,7 @@ License. See the file "COPYING" for the exact licensing terms.
#define KWIN_MINIMIZEANIMATION_H
// Include with base class for effects.
#include <effects.h>
#include <kwineffects.h>
namespace KWin

View file

@ -22,9 +22,6 @@ License. See the file "COPYING" for the exact licensing terms.
// Note that currently effects need to be manually enabled in the EffectsHandler
// class constructor (in effects.cpp).
namespace KWin
{

View file

@ -10,15 +10,15 @@ License. See the file "COPYING" for the exact licensing terms.
#include "scalein.h"
#include <client.h>
namespace KWin
{
KWIN_EFFECT( ScaleIn, ScaleInEffect )
void ScaleInEffect::prePaintScreen( int* mask, QRegion* region, int time )
{
if( !windows.isEmpty())
*mask |= Scene::PAINT_SCREEN_WITH_TRANSFORMED_WINDOWS;
*mask |= PAINT_SCREEN_WITH_TRANSFORMED_WINDOWS;
effects->prePaintScreen( mask, region, time );
}
@ -28,7 +28,7 @@ void ScaleInEffect::prePaintWindow( EffectWindow* w, int* mask, QRegion* paint,
{
windows[ w ] += time / 500.; // complete change in 500ms
if( windows[ w ] < 1 )
*mask |= Scene::PAINT_WINDOW_TRANSFORMED;
*mask |= PAINT_WINDOW_TRANSFORMED;
else
windows.remove( w );
}
@ -41,8 +41,8 @@ void ScaleInEffect::paintWindow( EffectWindow* w, int mask, QRegion region, Wind
{
data.xScale *= windows[ w ];
data.yScale *= windows[ w ];
data.xTranslate += int( w->window()->width() / 2 * ( 1 - windows[ w ] ));
data.yTranslate += int( w->window()->height() / 2 * ( 1 - windows[ w ] ));
data.xTranslate += int( w->width() / 2 * ( 1 - windows[ w ] ));
data.yTranslate += int( w->height() / 2 * ( 1 - windows[ w ] ));
}
effects->paintWindow( w, mask, region, data );
}
@ -50,17 +50,16 @@ void ScaleInEffect::paintWindow( EffectWindow* w, int mask, QRegion region, Wind
void ScaleInEffect::postPaintWindow( EffectWindow* w )
{
if( windows.contains( w ))
w->window()->addRepaintFull(); // trigger next animation repaint
w->addRepaintFull(); // trigger next animation repaint
effects->postPaintWindow( w );
}
void ScaleInEffect::windowAdded( EffectWindow* c )
{
Client* cc = dynamic_cast< Client* >( c->window());
if( cc == NULL || cc->isOnCurrentDesktop())
if( c->isOnCurrentDesktop())
{
windows[ c ] = 0;
c->window()->addRepaintFull();
c->addRepaintFull();
}
}

4
effects/scalein.desktop Normal file
View file

@ -0,0 +1,4 @@
[Desktop Entry]
Encoding=UTF-8
Name=Shadow
X-KDE-Library=kwin4_effect_builtins

View file

@ -11,7 +11,7 @@ License. See the file "COPYING" for the exact licensing terms.
#ifndef KWIN_SCALEIN_H
#define KWIN_SCALEIN_H
#include <effects.h>
#include <kwineffects.h>
namespace KWin
{

View file

@ -10,11 +10,11 @@ License. See the file "COPYING" for the exact licensing terms.
#include "shakymove.h"
#include <workspace.h>
namespace KWin
{
KWIN_EFFECT( ShakyMove, ShakyMoveEffect )
ShakyMoveEffect::ShakyMoveEffect()
{
connect( &timer, SIGNAL( timeout()), SLOT( tick()));
@ -26,14 +26,14 @@ static const int SHAKY_MAX = sizeof( shaky_diff ) / sizeof( shaky_diff[ 0 ] );
void ShakyMoveEffect::prePaintScreen( int* mask, QRegion* region, int time )
{
if( !windows.isEmpty())
*mask |= Scene::PAINT_SCREEN_WITH_TRANSFORMED_WINDOWS;
*mask |= PAINT_SCREEN_WITH_TRANSFORMED_WINDOWS;
effects->prePaintScreen( mask, region, time );
}
void ShakyMoveEffect::prePaintWindow( EffectWindow* w, int* mask, QRegion* paint, QRegion* clip, int time )
{
if( windows.contains( w ))
*mask |= Scene::PAINT_WINDOW_TRANSFORMED;
*mask |= PAINT_WINDOW_TRANSFORMED;
effects->prePaintWindow( w, mask, paint, clip, time );
}
@ -56,7 +56,7 @@ void ShakyMoveEffect::windowUserMovedResized( EffectWindow* c, bool first, bool
{
windows.remove( c );
// just repaint whole screen, transformation is involved
c->window()->workspace()->addRepaintFull();
effects->addRepaintFull();
if( windows.isEmpty())
timer.stop();
}
@ -81,7 +81,7 @@ void ShakyMoveEffect::tick()
else
++(*it);
// just repaint whole screen, transformation is involved
it.key()->window()->workspace()->addRepaintFull();
effects->addRepaintFull();
}
}

View file

@ -0,0 +1,4 @@
[Desktop Entry]
Encoding=UTF-8
Name=ShakyMove
X-KDE-Library=kwin4_effect_builtins

View file

@ -13,7 +13,7 @@ License. See the file "COPYING" for the exact licensing terms.
#include <qtimer.h>
#include <effects.h>
#include <kwineffects.h>
namespace KWin
{

View file

@ -14,9 +14,6 @@ License. See the file "COPYING" for the exact licensing terms.
#include <math.h>
// Note that currently effects need to be manually enabled in the EffectsHandler
// class constructor (in effects.cpp).
namespace KWin
{

View file

@ -234,7 +234,10 @@ class KWIN_EXPORT EffectWindow
virtual void addRepaint( int x, int y, int w, int h ) = 0;
virtual void addRepaintFull() = 0;
virtual void refWindow() = 0;
virtual void unrefWindow() = 0;
virtual bool isDeleted() const = 0;
virtual bool isMinimized() const = 0;
virtual bool isOnDesktop( int d ) const;
@ -250,6 +253,9 @@ class KWIN_EXPORT EffectWindow
virtual QPoint pos() const = 0;
virtual QSize size() const = 0;
virtual QRect rect() const = 0;
virtual bool isUserMove() const = 0;
virtual bool isUserResize() const = 0;
virtual QRect iconGeometry() const = 0;
virtual QString caption() const = 0;
virtual const EffectWindowGroup* group() const = 0;