2006-07-04 20:51:01 +00:00
|
|
|
/*****************************************************************
|
|
|
|
KWin - the KDE window manager
|
|
|
|
This file is part of the KDE project.
|
|
|
|
|
|
|
|
Copyright (C) 2006 Lubos Lunak <l.lunak@kde.org>
|
|
|
|
|
|
|
|
You can Freely distribute this program under the GNU General Public
|
|
|
|
License. See the file "COPYING" for the exact licensing terms.
|
|
|
|
******************************************************************/
|
|
|
|
|
2006-07-05 12:56:04 +00:00
|
|
|
// TODO MIT or some other licence, perhaps move to some lib
|
|
|
|
|
2006-07-04 20:51:01 +00:00
|
|
|
#ifndef KWIN_EFFECTS_H
|
|
|
|
#define KWIN_EFFECTS_H
|
|
|
|
|
2006-10-16 10:12:48 +00:00
|
|
|
#include "scene.h"
|
|
|
|
|
2007-01-05 16:45:56 +00:00
|
|
|
#include <qpair.h>
|
|
|
|
|
2006-07-04 20:51:01 +00:00
|
|
|
namespace KWinInternal
|
|
|
|
{
|
|
|
|
|
|
|
|
class Toplevel;
|
|
|
|
class Workspace;
|
2007-01-22 22:57:22 +00:00
|
|
|
class EffectWindow;
|
2006-07-04 20:51:01 +00:00
|
|
|
|
2006-10-16 10:12:48 +00:00
|
|
|
class WindowPaintData
|
2006-07-05 12:56:04 +00:00
|
|
|
{
|
|
|
|
public:
|
2006-10-16 10:12:48 +00:00
|
|
|
WindowPaintData();
|
2006-11-09 21:27:27 +00:00
|
|
|
/**
|
|
|
|
* Window opacity, in range 0 = transparent to 1 = fully opaque
|
|
|
|
*/
|
2006-10-16 10:12:48 +00:00
|
|
|
double opacity;
|
|
|
|
double xScale;
|
|
|
|
double yScale;
|
|
|
|
int xTranslate;
|
|
|
|
int yTranslate;
|
2006-11-09 21:27:27 +00:00
|
|
|
/**
|
|
|
|
* Saturation of the window, in range [0; 1]
|
|
|
|
* 1 means that the window is unchanged, 0 means that it's completely
|
|
|
|
* unsaturated (greyscale). 0.5 would make the colors less intense,
|
|
|
|
* but not completely grey
|
|
|
|
**/
|
2006-11-07 23:33:23 +00:00
|
|
|
float saturation;
|
2006-11-09 21:27:27 +00:00
|
|
|
/**
|
|
|
|
* Brightness of the window, in range [0; 1]
|
|
|
|
* 1 means that the window is unchanged, 0 means that it's completely
|
|
|
|
* black. 0.5 would make it 50% darker than usual
|
|
|
|
**/
|
2006-11-08 19:10:07 +00:00
|
|
|
float brightness;
|
2006-07-05 12:56:04 +00:00
|
|
|
};
|
|
|
|
|
2006-10-16 10:12:48 +00:00
|
|
|
class ScreenPaintData
|
2006-07-05 12:56:04 +00:00
|
|
|
{
|
|
|
|
public:
|
2006-10-16 10:12:48 +00:00
|
|
|
ScreenPaintData();
|
2006-12-03 13:36:40 +00:00
|
|
|
double xScale;
|
|
|
|
double yScale;
|
2006-10-16 10:12:48 +00:00
|
|
|
int xTranslate;
|
|
|
|
int yTranslate;
|
2006-07-05 12:56:04 +00:00
|
|
|
};
|
|
|
|
|
2006-07-04 20:51:01 +00:00
|
|
|
class Effect
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
virtual ~Effect();
|
2006-10-24 19:17:48 +00:00
|
|
|
virtual void prePaintScreen( int* mask, QRegion* region, int time );
|
2006-10-16 10:12:48 +00:00
|
|
|
virtual void paintScreen( int mask, QRegion region, ScreenPaintData& data );
|
2006-10-29 19:07:10 +00:00
|
|
|
virtual void postPaintScreen();
|
2007-01-22 22:57:22 +00:00
|
|
|
virtual void prePaintWindow( EffectWindow* w, int* mask, QRegion* region, int time );
|
2007-03-07 17:50:33 +00:00
|
|
|
// paintWindow() can do various transformations
|
2007-01-22 22:57:22 +00:00
|
|
|
virtual void paintWindow( EffectWindow* w, int mask, QRegion region, WindowPaintData& data );
|
|
|
|
virtual void postPaintWindow( EffectWindow* w );
|
2007-03-07 17:50:33 +00:00
|
|
|
// drawWindow() is used even for thumbnails etc. - it can alter the window itself where it
|
|
|
|
// makes sense (e.g.darkening out unresponsive windows), but it cannot do transformations
|
|
|
|
virtual void drawWindow( EffectWindow* w, int mask, QRegion region, WindowPaintData& data );
|
2006-07-06 13:17:44 +00:00
|
|
|
// called when moved/resized or once after it's finished
|
2007-01-22 22:57:22 +00:00
|
|
|
virtual void windowUserMovedResized( EffectWindow* c, bool first, bool last );
|
2007-02-12 23:14:50 +00:00
|
|
|
virtual void windowOpacityChanged( EffectWindow* c, double old_opacity );
|
2007-01-22 22:57:22 +00:00
|
|
|
virtual void windowAdded( EffectWindow* c );
|
|
|
|
virtual void windowClosed( EffectWindow* c );
|
|
|
|
virtual void windowDeleted( EffectWindow* c );
|
|
|
|
virtual void windowActivated( EffectWindow* c );
|
|
|
|
virtual void windowMinimized( EffectWindow* c );
|
|
|
|
virtual void windowUnminimized( EffectWindow* c );
|
2007-01-05 16:45:56 +00:00
|
|
|
virtual void windowInputMouseEvent( Window w, QEvent* e );
|
2007-02-01 17:20:48 +00:00
|
|
|
virtual void desktopChanged( int old );
|
2007-03-07 17:50:33 +00:00
|
|
|
virtual void windowDamaged( EffectWindow* w, const QRect& r );
|
|
|
|
virtual void windowGeometryShapeChanged( EffectWindow* w, const QRect& old );
|
2007-03-08 16:49:44 +00:00
|
|
|
virtual void tabBoxAdded( int mode );
|
|
|
|
virtual void tabBoxClosed();
|
|
|
|
virtual void tabBoxUpdated();
|
2007-01-12 14:14:53 +00:00
|
|
|
|
|
|
|
// Interpolates between x and y
|
|
|
|
static float interpolate(float x, float y, float a)
|
|
|
|
{
|
|
|
|
return x * (1 - a) + y * a;
|
|
|
|
}
|
2007-03-07 17:50:33 +00:00
|
|
|
// helper to set WindowPaintData and QRegion to necessary transformations so that
|
|
|
|
// a following drawWindow() would put the window at the requested geometry (useful for thumbnails)
|
|
|
|
static void setPositionTransformations( WindowPaintData& data, QRect& region, EffectWindow* w,
|
|
|
|
const QRect& r, Qt::AspectRatioMode aspect );
|
2007-02-04 22:19:17 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
Workspace* workspace() const;
|
2006-07-04 20:51:01 +00:00
|
|
|
};
|
|
|
|
|
2007-02-04 22:19:17 +00:00
|
|
|
class EffectFactory
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
// only here to avoid warnings
|
|
|
|
virtual ~EffectFactory();
|
|
|
|
|
|
|
|
virtual Effect* create() const = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
template <class EFFECT>
|
|
|
|
class GenericEffectFactory : public EffectFactory
|
|
|
|
{
|
|
|
|
virtual Effect* create() const
|
|
|
|
{
|
|
|
|
return new EFFECT();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2006-07-04 20:51:01 +00:00
|
|
|
class EffectsHandler
|
|
|
|
{
|
2007-02-04 22:19:17 +00:00
|
|
|
friend class Effect;
|
2006-07-04 20:51:01 +00:00
|
|
|
public:
|
2007-02-04 22:19:17 +00:00
|
|
|
EffectsHandler();
|
2006-07-10 18:34:57 +00:00
|
|
|
~EffectsHandler();
|
2006-10-16 10:12:48 +00:00
|
|
|
// for use by effects
|
2006-10-29 19:06:32 +00:00
|
|
|
void prePaintScreen( int* mask, QRegion* region, int time );
|
|
|
|
void paintScreen( int mask, QRegion region, ScreenPaintData& data );
|
2006-10-29 19:07:10 +00:00
|
|
|
void postPaintScreen();
|
2007-01-22 22:57:22 +00:00
|
|
|
void prePaintWindow( EffectWindow* w, int* mask, QRegion* region, int time );
|
|
|
|
void paintWindow( EffectWindow* w, int mask, QRegion region, WindowPaintData& data );
|
|
|
|
void postPaintWindow( EffectWindow* w );
|
2007-03-07 17:50:33 +00:00
|
|
|
void drawWindow( EffectWindow* w, int mask, QRegion region, WindowPaintData& data );
|
2007-01-05 16:45:56 +00:00
|
|
|
// Functions for handling input - e.g. when an Expose-like effect is shown, an input window
|
|
|
|
// covering the whole screen is created and all mouse events will be intercepted by it.
|
|
|
|
// The effect's windowInputMouseEvent() will get called with such events.
|
|
|
|
Window createInputWindow( Effect* e, int x, int y, int w, int h, const QCursor& cursor );
|
|
|
|
Window createInputWindow( Effect* e, const QRect& r, const QCursor& cursor );
|
|
|
|
void destroyInputWindow( Window w );
|
|
|
|
// functions that allow controlling windows/desktop
|
2007-01-22 22:57:22 +00:00
|
|
|
void activateWindow( EffectWindow* c );
|
2007-02-01 17:20:48 +00:00
|
|
|
//
|
|
|
|
int currentDesktop() const;
|
2006-10-16 10:12:48 +00:00
|
|
|
// internal (used by kwin core or compositing code)
|
2006-10-29 19:06:32 +00:00
|
|
|
void startPaint();
|
2007-01-22 22:57:22 +00:00
|
|
|
void windowUserMovedResized( EffectWindow* c, bool first, bool last );
|
2007-02-12 23:14:50 +00:00
|
|
|
void windowOpacityChanged( EffectWindow* c, double old_opacity );
|
2007-01-22 22:57:22 +00:00
|
|
|
void windowAdded( EffectWindow* c );
|
|
|
|
void windowClosed( EffectWindow* c );
|
|
|
|
void windowDeleted( EffectWindow* c );
|
|
|
|
void windowActivated( EffectWindow* c );
|
|
|
|
void windowMinimized( EffectWindow* c );
|
|
|
|
void windowUnminimized( EffectWindow* c );
|
2007-01-05 16:45:56 +00:00
|
|
|
bool checkInputWindowEvent( XEvent* e );
|
|
|
|
void checkInputWindowStacking();
|
2007-02-01 17:20:48 +00:00
|
|
|
void desktopChanged( int old );
|
2007-03-07 17:50:33 +00:00
|
|
|
void windowDamaged( EffectWindow* w, const QRect& r );
|
|
|
|
void windowGeometryShapeChanged( EffectWindow* w, const QRect& old );
|
2007-03-08 16:49:44 +00:00
|
|
|
void tabBoxAdded( int mode );
|
|
|
|
void tabBoxClosed();
|
|
|
|
void tabBoxUpdated();
|
2007-03-07 17:50:33 +00:00
|
|
|
|
2007-02-04 22:19:17 +00:00
|
|
|
void registerEffect( const QString& name, EffectFactory* factory );
|
|
|
|
void loadEffect( const QString& name );
|
|
|
|
void unloadEffect( const QString& name );
|
|
|
|
|
2006-10-16 10:12:48 +00:00
|
|
|
private:
|
2007-02-04 22:19:17 +00:00
|
|
|
typedef QPair< QString, Effect* > EffectPair;
|
|
|
|
QVector< EffectPair > loaded_effects;
|
2007-01-05 16:45:56 +00:00
|
|
|
typedef QPair< Effect*, Window > InputWindowPair;
|
|
|
|
QList< InputWindowPair > input_windows;
|
2007-03-14 16:50:19 +00:00
|
|
|
QHash< QString, EffectFactory* > effect_factories;
|
2006-10-16 10:12:48 +00:00
|
|
|
int current_paint_screen;
|
2007-03-07 17:50:33 +00:00
|
|
|
int current_paint_window;
|
|
|
|
int current_draw_window;
|
2006-07-04 20:51:01 +00:00
|
|
|
};
|
|
|
|
|
2007-01-22 22:57:22 +00:00
|
|
|
// This class is a representation of a window used by/for Effect classes.
|
|
|
|
// The purpose is to hide internal data and also to serve as a single
|
|
|
|
// representation for the case when Client/Unmanaged becomes Deleted.
|
|
|
|
class EffectWindow
|
|
|
|
{
|
|
|
|
public:
|
2007-02-01 17:20:48 +00:00
|
|
|
EffectWindow();
|
2007-01-22 22:57:22 +00:00
|
|
|
const Toplevel* window() const;
|
|
|
|
Toplevel* window();
|
2007-02-11 17:36:32 +00:00
|
|
|
void enablePainting( int reason );
|
|
|
|
void disablePainting( int reason );
|
2007-02-01 17:20:48 +00:00
|
|
|
bool isOnDesktop( int d ) const;
|
|
|
|
bool isOnCurrentDesktop() const;
|
|
|
|
bool isOnAllDesktops() const;
|
|
|
|
int desktop() const; // prefer isOnXXX()
|
2007-02-11 18:36:57 +00:00
|
|
|
int x() const;
|
|
|
|
int y() const;
|
|
|
|
int width() const;
|
|
|
|
int height() const;
|
|
|
|
QRect geometry() const;
|
|
|
|
QPoint pos() const;
|
|
|
|
QSize size() const;
|
|
|
|
QRect rect() const;
|
2007-02-23 17:47:52 +00:00
|
|
|
bool isDesktop() const;
|
|
|
|
bool isDock() const;
|
|
|
|
bool isToolbar() const;
|
|
|
|
bool isTopMenu() const;
|
|
|
|
bool isMenu() const;
|
|
|
|
bool isNormalWindow() const; // normal as in 'NET::Normal or NET::Unknown non-transient'
|
|
|
|
bool isDialog() const;
|
|
|
|
bool isSplash() const;
|
|
|
|
bool isUtility() const;
|
|
|
|
bool isDropdownMenu() const;
|
|
|
|
bool isPopupMenu() const; // a context popup, not dropdown, not torn-off
|
|
|
|
bool isTooltip() const;
|
|
|
|
bool isNotification() const;
|
|
|
|
bool isComboBox() const;
|
|
|
|
bool isDNDIcon() const;
|
2007-02-01 17:20:48 +00:00
|
|
|
|
2007-01-22 22:57:22 +00:00
|
|
|
void setWindow( Toplevel* w ); // internal
|
|
|
|
void setSceneWindow( Scene::Window* w ); // internal
|
|
|
|
Scene::Window* sceneWindow(); // internal
|
|
|
|
private:
|
2007-02-01 17:20:48 +00:00
|
|
|
Toplevel* toplevel;
|
2007-01-22 22:57:22 +00:00
|
|
|
Scene::Window* sw; // This one is used only during paint pass.
|
|
|
|
};
|
|
|
|
|
|
|
|
EffectWindow* effectWindow( Toplevel* w );
|
|
|
|
EffectWindow* effectWindow( Scene::Window* w );
|
|
|
|
|
2006-07-04 20:51:01 +00:00
|
|
|
extern EffectsHandler* effects;
|
|
|
|
|
2006-10-16 10:12:48 +00:00
|
|
|
inline
|
|
|
|
WindowPaintData::WindowPaintData()
|
|
|
|
: opacity( 1.0 )
|
|
|
|
, xScale( 1 )
|
|
|
|
, yScale( 1 )
|
|
|
|
, xTranslate( 0 )
|
|
|
|
, yTranslate( 0 )
|
2006-11-07 23:33:23 +00:00
|
|
|
, saturation( 1 )
|
2006-11-08 19:10:07 +00:00
|
|
|
, brightness( 1 )
|
2006-10-16 10:12:48 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
inline
|
|
|
|
ScreenPaintData::ScreenPaintData()
|
2006-12-03 13:36:40 +00:00
|
|
|
: xScale( 1 )
|
|
|
|
, yScale( 1 )
|
|
|
|
, xTranslate( 0 )
|
2006-10-16 10:12:48 +00:00
|
|
|
, yTranslate( 0 )
|
|
|
|
{
|
|
|
|
}
|
2006-07-06 19:02:14 +00:00
|
|
|
|
2007-01-22 22:57:22 +00:00
|
|
|
inline
|
|
|
|
const Toplevel* EffectWindow::window() const
|
|
|
|
{
|
2007-02-01 17:20:48 +00:00
|
|
|
return toplevel;
|
2007-01-22 22:57:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
inline
|
|
|
|
Toplevel* EffectWindow::window()
|
|
|
|
{
|
2007-02-01 17:20:48 +00:00
|
|
|
return toplevel;
|
2007-01-22 22:57:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
inline
|
|
|
|
void EffectWindow::setWindow( Toplevel* w )
|
|
|
|
{
|
2007-02-01 17:20:48 +00:00
|
|
|
toplevel = w;
|
2007-01-22 22:57:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
inline
|
|
|
|
void EffectWindow::setSceneWindow( Scene::Window* w )
|
|
|
|
{
|
|
|
|
sw = w;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline
|
|
|
|
Scene::Window* EffectWindow::sceneWindow()
|
|
|
|
{
|
|
|
|
return sw;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline
|
2007-02-11 18:36:57 +00:00
|
|
|
int EffectWindow::x() const
|
|
|
|
{
|
|
|
|
return toplevel->x();
|
|
|
|
}
|
|
|
|
|
|
|
|
inline
|
|
|
|
int EffectWindow::y() const
|
|
|
|
{
|
|
|
|
return toplevel->y();
|
|
|
|
}
|
|
|
|
|
|
|
|
inline
|
|
|
|
int EffectWindow::width() const
|
|
|
|
{
|
|
|
|
return toplevel->width();
|
|
|
|
}
|
|
|
|
|
|
|
|
inline
|
|
|
|
int EffectWindow::height() const
|
|
|
|
{
|
|
|
|
return toplevel->height();
|
|
|
|
}
|
|
|
|
|
|
|
|
inline
|
|
|
|
QRect EffectWindow::geometry() const
|
|
|
|
{
|
|
|
|
return toplevel->geometry();
|
|
|
|
}
|
|
|
|
|
|
|
|
inline
|
|
|
|
QSize EffectWindow::size() const
|
|
|
|
{
|
|
|
|
return toplevel->size();
|
|
|
|
}
|
|
|
|
|
|
|
|
inline
|
|
|
|
QPoint EffectWindow::pos() const
|
|
|
|
{
|
|
|
|
return toplevel->pos();
|
|
|
|
}
|
|
|
|
|
|
|
|
inline
|
|
|
|
QRect EffectWindow::rect() const
|
|
|
|
{
|
|
|
|
return toplevel->rect();
|
|
|
|
}
|
2007-02-23 17:47:52 +00:00
|
|
|
|
|
|
|
inline
|
|
|
|
bool EffectWindow::isDesktop() const
|
|
|
|
{
|
|
|
|
return toplevel->isDesktop();
|
|
|
|
}
|
|
|
|
|
|
|
|
inline
|
|
|
|
bool EffectWindow::isDock() const
|
|
|
|
{
|
|
|
|
return toplevel->isDock();
|
|
|
|
}
|
|
|
|
|
|
|
|
inline
|
|
|
|
bool EffectWindow::isToolbar() const
|
|
|
|
{
|
|
|
|
return toplevel->isToolbar();
|
|
|
|
}
|
|
|
|
|
|
|
|
inline
|
|
|
|
bool EffectWindow::isTopMenu() const
|
|
|
|
{
|
|
|
|
return toplevel->isTopMenu();
|
|
|
|
}
|
|
|
|
|
|
|
|
inline
|
|
|
|
bool EffectWindow::isMenu() const
|
|
|
|
{
|
|
|
|
return toplevel->isMenu();
|
|
|
|
}
|
|
|
|
|
|
|
|
inline
|
|
|
|
bool EffectWindow::isNormalWindow() const
|
|
|
|
{
|
|
|
|
return toplevel->isNormalWindow();
|
|
|
|
}
|
|
|
|
|
|
|
|
inline
|
|
|
|
bool EffectWindow::isDialog() const
|
|
|
|
{
|
|
|
|
return toplevel->isDialog();
|
|
|
|
}
|
|
|
|
|
|
|
|
inline
|
|
|
|
bool EffectWindow::isSplash() const
|
|
|
|
{
|
|
|
|
return toplevel->isSplash();
|
|
|
|
}
|
|
|
|
|
|
|
|
inline
|
|
|
|
bool EffectWindow::isUtility() const
|
|
|
|
{
|
|
|
|
return toplevel->isUtility();
|
|
|
|
}
|
|
|
|
|
|
|
|
inline
|
|
|
|
bool EffectWindow::isDropdownMenu() const
|
|
|
|
{
|
|
|
|
return toplevel->isDropdownMenu();
|
|
|
|
}
|
|
|
|
|
|
|
|
inline
|
|
|
|
bool EffectWindow::isPopupMenu() const
|
|
|
|
{
|
|
|
|
return toplevel->isPopupMenu();
|
|
|
|
}
|
|
|
|
|
|
|
|
inline
|
|
|
|
bool EffectWindow::isTooltip() const
|
|
|
|
{
|
|
|
|
return toplevel->isTooltip();
|
|
|
|
}
|
|
|
|
|
|
|
|
inline
|
|
|
|
bool EffectWindow::isNotification() const
|
|
|
|
{
|
|
|
|
return toplevel->isNotification();
|
|
|
|
}
|
|
|
|
|
|
|
|
inline
|
|
|
|
bool EffectWindow::isComboBox() const
|
|
|
|
{
|
|
|
|
return toplevel->isComboBox();
|
|
|
|
}
|
|
|
|
|
|
|
|
inline
|
|
|
|
bool EffectWindow::isDNDIcon() const
|
|
|
|
{
|
|
|
|
return toplevel->isDNDIcon();
|
|
|
|
}
|
|
|
|
|
2007-02-11 18:36:57 +00:00
|
|
|
inline
|
2007-01-22 22:57:22 +00:00
|
|
|
EffectWindow* effectWindow( Toplevel* w )
|
|
|
|
{
|
|
|
|
EffectWindow* ret = w->effectWindow();
|
|
|
|
ret->setSceneWindow( NULL ); // just in case
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline
|
|
|
|
EffectWindow* effectWindow( Scene::Window* w )
|
|
|
|
{
|
|
|
|
EffectWindow* ret = w->window()->effectWindow();
|
|
|
|
ret->setSceneWindow( w );
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2007-02-04 22:19:17 +00:00
|
|
|
inline
|
|
|
|
Workspace* Effect::workspace() const
|
|
|
|
{
|
|
|
|
return Workspace::self();
|
|
|
|
}
|
|
|
|
|
2006-07-04 20:51:01 +00:00
|
|
|
} // namespace
|
|
|
|
|
|
|
|
#endif
|