00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef KWINEFFECTS_H
00023 #define KWINEFFECTS_H
00024
00025 #include <kwinconfig.h>
00026 #include <kwinglobals.h>
00027 #include "kdecoration.h"
00028
00029 #include <QtCore/QPair>
00030 #include <QtCore/QRect>
00031 #include <QtGui/QRegion>
00032 #include <QtGui/QFont>
00033
00034 #include <QtCore/QVector>
00035 #include <QtCore/QList>
00036 #include <QtCore/QHash>
00037 #include <QtCore/QStack>
00038 #include <QtCore/QTimeLine>
00039
00040 #include <KDE/KPluginFactory>
00041 #include <KDE/KShortcutsEditor>
00042
00043 #include <KDE/Plasma/FrameSvg>
00044 #include <KDE/Plasma/Theme>
00045
00046 #include <assert.h>
00047 #include <limits.h>
00048
00049 class KLibrary;
00050 class KConfigGroup;
00051 class KActionCollection;
00052 class QKeyEvent;
00053
00054 namespace KWin
00055 {
00056
00057
00058 class EffectWindow;
00059 class EffectWindowGroup;
00060 class Effect;
00061 class WindowQuad;
00062 class GLRenderTarget;
00063 class GLShader;
00064 class GLTexture;
00065 class XRenderPicture;
00066 class RotationData;
00067 class WindowQuadList;
00068 class WindowPrePaintData;
00069 class WindowPaintData;
00070 class ScreenPrePaintData;
00071 class ScreenPaintData;
00072
00073 typedef QPair< QString, Effect* > EffectPair;
00074 typedef QPair< Effect*, Window > InputWindowPair;
00075 typedef QList< EffectWindow* > EffectWindowList;
00076
00077
00171 #define KWIN_EFFECT_API_MAKE_VERSION( major, minor ) (( major ) << 8 | ( minor ))
00172 #define KWIN_EFFECT_API_VERSION_MAJOR 0
00173 #define KWIN_EFFECT_API_VERSION_MINOR 131
00174 #define KWIN_EFFECT_API_VERSION KWIN_EFFECT_API_MAKE_VERSION( \
00175 KWIN_EFFECT_API_VERSION_MAJOR, KWIN_EFFECT_API_VERSION_MINOR )
00176
00177 enum WindowQuadType
00178 {
00179 WindowQuadError,
00180 WindowQuadContents,
00181 WindowQuadDecoration,
00182 EFFECT_QUAD_TYPE_START = 100
00183 };
00184
00189 enum DataRole
00190 {
00191
00192
00193 WindowAddedGrabRole = 1,
00194 WindowClosedGrabRole,
00195 WindowMinimizedGrabRole,
00196 WindowUnminimizedGrabRole
00197 };
00198
00202 KWIN_EXPORT inline
00203 QRect infiniteRegion()
00204 {
00205 return QRect( INT_MIN / 2, INT_MIN / 2, INT_MAX, INT_MAX );
00206 }
00207
00256 class KWIN_EXPORT Effect
00257 {
00258 public:
00260
00261 enum
00262 {
00266 PAINT_WINDOW_OPAQUE = 1 << 0,
00270 PAINT_WINDOW_TRANSLUCENT = 1 << 1,
00274 PAINT_WINDOW_TRANSFORMED = 1 << 2,
00279 PAINT_SCREEN_REGION = 1 << 3,
00284 PAINT_SCREEN_TRANSFORMED = 1 << 4,
00289 PAINT_SCREEN_WITH_TRANSFORMED_WINDOWS = 1 << 5,
00293 PAINT_SCREEN_BACKGROUND_FIRST = 1 << 6,
00297 PAINT_DECORATION_ONLY = 1 << 7
00298 };
00299
00303 Effect();
00307 virtual ~Effect();
00308
00312 enum ReconfigureFlag
00313 {
00314 ReconfigureAll = 1 << 0
00315 };
00316 Q_DECLARE_FLAGS( ReconfigureFlags, ReconfigureFlag )
00317
00318
00321 virtual void reconfigure( ReconfigureFlags flags );
00322
00326 virtual void* proxy();
00327
00336 virtual void prePaintScreen( ScreenPrePaintData& data, int time );
00344 virtual void paintScreen( int mask, QRegion region, ScreenPaintData& data );
00351 virtual void postPaintScreen();
00352
00361 virtual void prePaintWindow( EffectWindow* w, WindowPrePaintData& data, int time );
00369 virtual void paintWindow( EffectWindow* w, int mask, QRegion region, WindowPaintData& data );
00376 virtual void postPaintWindow( EffectWindow* w );
00377
00383 virtual void drawWindow( EffectWindow* w, int mask, QRegion region, WindowPaintData& data );
00384
00389 virtual void buildQuads( EffectWindow* w, WindowQuadList& quadList );
00390
00397 virtual QRect transformWindowDamage( EffectWindow* w, const QRect& r );
00398
00400 virtual void windowUserMovedResized( EffectWindow* c, bool first, bool last );
00402 virtual void windowMoveResizeGeometryUpdate( EffectWindow* c, const QRect& geometry );
00403 virtual void windowOpacityChanged( EffectWindow* c, double old_opacity );
00404 virtual void windowAdded( EffectWindow* c );
00405 virtual void windowClosed( EffectWindow* c );
00406 virtual void windowDeleted( EffectWindow* c );
00407 virtual void windowActivated( EffectWindow* c );
00408 virtual void windowMinimized( EffectWindow* c );
00409 virtual void windowUnminimized( EffectWindow* c );
00410 virtual void clientGroupItemSwitched( EffectWindow* from, EffectWindow* to );
00411 virtual void clientGroupItemAdded( EffectWindow* from, EffectWindow* to );
00412 virtual void clientGroupItemRemoved( EffectWindow* c, EffectWindow* group );
00413 virtual void windowInputMouseEvent( Window w, QEvent* e );
00414 virtual void desktopChanged( int old );
00415 virtual void windowDamaged( EffectWindow* w, const QRect& r );
00416 virtual void windowGeometryShapeChanged( EffectWindow* w, const QRect& old );
00417 virtual void mouseChanged( const QPoint& pos, const QPoint& oldpos,
00418 Qt::MouseButtons buttons, Qt::MouseButtons oldbuttons,
00419 Qt::KeyboardModifiers modifiers, Qt::KeyboardModifiers oldmodifiers );
00420 virtual void grabbedKeyboardEvent( QKeyEvent* e );
00428 virtual void propertyNotify( EffectWindow* w, long atom );
00429
00430 virtual void tabBoxAdded( int mode );
00431 virtual void tabBoxClosed();
00432 virtual void tabBoxUpdated();
00433 virtual void tabBoxKeyEvent( QKeyEvent* event );
00434 virtual bool borderActivated( ElectricBorder border );
00435
00436 static int displayWidth();
00437 static int displayHeight();
00438 static QPoint cursorPos();
00439
00449
00450 static double animationTime( const KConfigGroup& cfg, const QString& key, int defaultTime );
00455 static double animationTime( int defaultTime );
00461 static double interpolate(double x, double y, double a)
00462 {
00463 return x * (1 - a) + y * a;
00464 }
00468 static void setPositionTransformations( WindowPaintData& data, QRect& region, EffectWindow* w,
00469 const QRect& r, Qt::AspectRatioMode aspect );
00470 };
00471
00472
00482 #define KWIN_EFFECT( name, classname ) \
00483 extern "C" { \
00484 KWIN_EXPORT Effect* effect_create_kwin4_effect_##name() { return new classname; } \
00485 KWIN_EXPORT int effect_version_kwin4_effect_##name() { return KWIN_EFFECT_API_VERSION; } \
00486 }
00487
00491 #define KWIN_EFFECT_SUPPORTED( name, function ) \
00492 extern "C" { \
00493 KWIN_EXPORT bool effect_supported_kwin4_effect_##name() { return function; } \
00494 }
00495
00499 #define KWIN_EFFECT_CONFIG( name, classname ) \
00500 K_PLUGIN_FACTORY(EffectFactory, registerPlugin<classname>(#name);) \
00501 K_EXPORT_PLUGIN(EffectFactory("kcm_kwin4_effect_" #name))
00502
00509 #define KWIN_EFFECT_CONFIG_MULTIPLE( name, singles ) \
00510 K_PLUGIN_FACTORY(EffectFactory, singles) \
00511 K_EXPORT_PLUGIN(EffectFactory("kcm_kwin4_effect_" #name))
00512
00515 #define KWIN_EFFECT_CONFIG_SINGLE( name, classname ) \
00516 registerPlugin<classname>(#name);
00517
00520 #define KWIN_EFFECT_CONFIG_FACTORY K_PLUGIN_FACTORY_DECLARATION(EffectFactory)
00521
00522
00533 class KWIN_EXPORT EffectsHandler
00534 {
00535 friend class Effect;
00536 public:
00537 EffectsHandler(CompositingType type);
00538 virtual ~EffectsHandler();
00539
00540 virtual void prePaintScreen( ScreenPrePaintData& data, int time ) = 0;
00541 virtual void paintScreen( int mask, QRegion region, ScreenPaintData& data ) = 0;
00542 virtual void postPaintScreen() = 0;
00543 virtual void prePaintWindow( EffectWindow* w, WindowPrePaintData& data, int time ) = 0;
00544 virtual void paintWindow( EffectWindow* w, int mask, QRegion region, WindowPaintData& data ) = 0;
00545 virtual void postPaintWindow( EffectWindow* w ) = 0;
00546 virtual void drawWindow( EffectWindow* w, int mask, QRegion region, WindowPaintData& data ) = 0;
00547 virtual void buildQuads( EffectWindow* w, WindowQuadList& quadList ) = 0;
00548 virtual QRect transformWindowDamage( EffectWindow* w, const QRect& r );
00549
00550
00551
00552 virtual Window createInputWindow( Effect* e, int x, int y, int w, int h, const QCursor& cursor ) = 0;
00553 Window createInputWindow( Effect* e, const QRect& r, const QCursor& cursor );
00554 virtual Window createFullScreenInputWindow( Effect* e, const QCursor& cursor );
00555 virtual void destroyInputWindow( Window w ) = 0;
00556 virtual QPoint cursorPos() const = 0;
00557 virtual bool grabKeyboard( Effect* effect ) = 0;
00558 virtual void ungrabKeyboard() = 0;
00559
00564 virtual void* getProxy( QString name ) = 0;
00565
00566
00567 virtual void startMousePolling() = 0;
00568 virtual void stopMousePolling() = 0;
00569
00570 virtual void checkElectricBorder(const QPoint &pos, Time time) = 0;
00571 virtual void reserveElectricBorder( ElectricBorder border ) = 0;
00572 virtual void unreserveElectricBorder( ElectricBorder border ) = 0;
00573 virtual void reserveElectricBorderSwitching( bool reserve ) = 0;
00574
00575
00576 virtual void activateWindow( EffectWindow* c ) = 0;
00577 virtual EffectWindow* activeWindow() const = 0 ;
00578 virtual void moveWindow( EffectWindow* w, const QPoint& pos, bool snap = false, double snapAdjust = 1.0 ) = 0;
00579 virtual void windowToDesktop( EffectWindow* w, int desktop ) = 0;
00580 virtual void windowToScreen( EffectWindow* w, int screen ) = 0;
00581 virtual void setShowingDesktop( bool showing ) = 0;
00582
00583
00587 virtual int currentDesktop() const = 0;
00591 virtual int numberOfDesktops() const = 0;
00595 virtual void setCurrentDesktop( int desktop ) = 0;
00599 virtual QSize desktopGridSize() const = 0;
00603 virtual int desktopGridWidth() const = 0;
00607 virtual int desktopGridHeight() const = 0;
00611 virtual int workspaceWidth() const = 0;
00615 virtual int workspaceHeight() const = 0;
00620 virtual int desktopAtCoords( QPoint coords ) const = 0;
00624 virtual QPoint desktopGridCoords( int id ) const = 0;
00628 virtual QPoint desktopCoords( int id ) const = 0;
00633 virtual int desktopAbove( int desktop = 0, bool wrap = true ) const = 0;
00638 virtual int desktopToRight( int desktop = 0, bool wrap = true ) const = 0;
00643 virtual int desktopBelow( int desktop = 0, bool wrap = true ) const = 0;
00648 virtual int desktopToLeft( int desktop = 0, bool wrap = true ) const = 0;
00652 virtual bool isDesktopLayoutDynamic() const = 0;
00657 virtual int addDesktop( QPoint coords ) = 0;
00662 virtual void deleteDesktop( int id ) = 0;
00663 virtual QString desktopName( int desktop ) const = 0;
00664 virtual bool optionRollOverDesktops() const = 0;
00665
00666 virtual int activeScreen() const = 0;
00667 virtual int numScreens() const = 0;
00668 virtual int screenNumber( const QPoint& pos ) const = 0;
00669 virtual QRect clientArea( clientAreaOption, int screen, int desktop ) const = 0;
00670 virtual QRect clientArea( clientAreaOption, const EffectWindow* c ) const = 0;
00671 virtual QRect clientArea( clientAreaOption, const QPoint& p, int desktop ) const = 0;
00679 virtual double animationTimeFactor() const = 0;
00680 virtual WindowQuadType newWindowQuadType() = 0;
00681
00682 virtual EffectWindow* findWindow( WId id ) const = 0;
00683 virtual EffectWindowList stackingOrder() const = 0;
00684
00685 virtual void setElevatedWindow( EffectWindow* w, bool set ) = 0;
00686
00687 virtual void setTabBoxWindow(EffectWindow*) = 0;
00688 virtual void setTabBoxDesktop(int) = 0;
00689 virtual EffectWindowList currentTabBoxWindowList() const = 0;
00690 virtual void refTabBox() = 0;
00691 virtual void unrefTabBox() = 0;
00692 virtual void closeTabBox() = 0;
00693 virtual QList< int > currentTabBoxDesktopList() const = 0;
00694 virtual int currentTabBoxDesktop() const = 0;
00695 virtual EffectWindow* currentTabBoxWindow() const = 0;
00696
00697 virtual void setActiveFullScreenEffect( Effect* e ) = 0;
00698 virtual Effect* activeFullScreenEffect() const = 0;
00699
00700 virtual void pushRenderTarget(GLRenderTarget* target) = 0;
00701 virtual GLRenderTarget* popRenderTarget() = 0;
00702
00708 virtual void addRepaintFull() = 0;
00709 virtual void addRepaint( const QRect& r ) = 0;
00710 virtual void addRepaint( const QRegion& r ) = 0;
00711 virtual void addRepaint( int x, int y, int w, int h ) = 0;
00712
00713 CompositingType compositingType() const;
00714 virtual unsigned long xrenderBufferPicture() = 0;
00715 bool saturationSupported() const;
00716 virtual void reconfigure() = 0;
00717
00724 virtual void registerPropertyType( long atom, bool reg ) = 0;
00725 virtual QByteArray readRootProperty( long atom, long type, int format ) const = 0;
00726 virtual void deleteRootProperty( long atom ) const = 0;
00727
00731 virtual bool hasDecorationShadows() const = 0;
00732
00737 virtual bool decorationsHaveAlpha() const = 0;
00738
00749 bool paintText( const QString& text, const QPoint& center, int maxwidth,
00750 const QColor& color, const QFont& font = QFont() );
00755 bool paintText( const QString& text, const QRect& rect, const QColor& color,
00756 const QFont& font = QFont(), const Qt::Alignment& alignment = Qt::AlignCenter );
00761 bool paintTextWithBackground( const QString& text, const QPoint& center, int maxwidth,
00762 const QColor& color, const QColor& bgcolor,
00763 const QFont& font = QFont() );
00768 bool paintTextWithBackground( const QString& text, const QRect& rect, const QColor& color,
00769 const QColor& bgcolor, const QFont& font = QFont(),
00770 const Qt::Alignment& alignment = Qt::AlignCenter );
00771
00772
00778 static void sendReloadMessage( const QString& effectname );
00782 static KConfigGroup effectConfig( const QString& effectname );
00783
00784
00785 protected:
00786 QVector< EffectPair > loaded_effects;
00787 QHash< QString, KLibrary* > effect_libraries;
00788 QList< InputWindowPair > input_windows;
00789
00790 int current_paint_screen;
00791 int current_paint_window;
00792 int current_draw_window;
00793 int current_build_quads;
00794 int current_transform;
00795 CompositingType compositing_type;
00796 };
00797
00798
00805 class KWIN_EXPORT EffectWindow
00806 {
00807 public:
00809 enum
00810 {
00812 PAINT_DISABLED = 1 << 0,
00814 PAINT_DISABLED_BY_DELETE = 1 << 1,
00816 PAINT_DISABLED_BY_DESKTOP = 1 << 2,
00818 PAINT_DISABLED_BY_MINIMIZE = 1 << 3,
00820 PAINT_DISABLED_BY_CLIENT_GROUP = 1 << 4
00821 };
00822
00823 EffectWindow();
00824 virtual ~EffectWindow();
00825
00826 virtual void enablePainting( int reason ) = 0;
00827 virtual void disablePainting( int reason ) = 0;
00828 virtual bool isPaintingEnabled() = 0;
00829 virtual void addRepaint( const QRect& r ) = 0;
00830 virtual void addRepaint( int x, int y, int w, int h ) = 0;
00831 virtual void addRepaintFull() = 0;
00832
00833 virtual void refWindow() = 0;
00834 virtual void unrefWindow() = 0;
00835 virtual bool isDeleted() const = 0;
00836
00837 virtual bool isMinimized() const = 0;
00838 virtual double opacity() const = 0;
00839 virtual bool hasAlpha() const = 0;
00840
00841 virtual bool isOnDesktop( int d ) const;
00842 virtual bool isOnCurrentDesktop() const;
00843 virtual bool isOnAllDesktops() const = 0;
00844 virtual int desktop() const = 0;
00845
00846 virtual int x() const = 0;
00847 virtual int y() const = 0;
00848 virtual int width() const = 0;
00849 virtual int height() const = 0;
00850 virtual QRect geometry() const = 0;
00851 virtual QRegion shape() const = 0;
00852 virtual int screen() const = 0;
00854 virtual bool hasOwnShape() const = 0;
00855 virtual QPoint pos() const = 0;
00856 virtual QSize size() const = 0;
00857 virtual QRect rect() const = 0;
00858 virtual bool isMovable() const = 0;
00859 virtual bool isMovableAcrossScreens() const = 0;
00860 virtual bool isUserMove() const = 0;
00861 virtual bool isUserResize() const = 0;
00862 virtual QRect iconGeometry() const = 0;
00866 virtual QRect contentsRect() const = 0;
00872 virtual QRect decorationInnerRect() const = 0;
00873 bool hasDecoration() const;
00874 virtual QByteArray readProperty( long atom, long type, int format ) const = 0;
00875 virtual void deleteProperty( long atom ) const = 0;
00876
00877 virtual QString caption() const = 0;
00878 virtual QPixmap icon() const = 0;
00879 virtual QString windowClass() const = 0;
00880 virtual QString windowRole() const = 0;
00881 virtual const EffectWindowGroup* group() const = 0;
00882
00887 virtual bool isDesktop() const = 0;
00892 virtual bool isDock() const = 0;
00897 virtual bool isToolbar() const = 0;
00902 virtual bool isTopMenu() const = 0;
00907 virtual bool isMenu() const = 0;
00913 virtual bool isNormalWindow() const = 0;
00919 virtual bool isSpecialWindow() const = 0;
00924 virtual bool isDialog() const = 0;
00930 virtual bool isSplash() const = 0;
00935 virtual bool isUtility() const = 0;
00941 virtual bool isDropdownMenu() const = 0;
00946 virtual bool isPopupMenu() const = 0;
00951 virtual bool isTooltip() const = 0;
00956 virtual bool isNotification() const = 0;
00961 virtual bool isComboBox() const = 0;
00966 virtual bool isDNDIcon() const = 0;
00971 virtual bool isManaged() const = 0;
00975 virtual bool acceptsFocus() const = 0;
00979 virtual bool keepAbove() const = 0;
00980
00981 virtual bool isModal() const = 0;
00982 virtual EffectWindow* findModal() = 0;
00983 virtual EffectWindowList mainWindows() const = 0;
00984
00988 virtual WindowQuadList buildQuads( bool force = false ) const = 0;
00989
00990 virtual void minimize() const = 0;
00991 virtual void unminimize() const = 0;
00992 virtual void closeWindow() const = 0;
00993
00994 virtual bool visibleInClientGroup() const = 0;
00995
00999 virtual void setData( int role, const QVariant &data ) = 0;
01000 virtual QVariant data( int role ) const = 0;
01001 };
01002
01003 class KWIN_EXPORT EffectWindowGroup
01004 {
01005 public:
01006 virtual ~EffectWindowGroup();
01007 virtual EffectWindowList members() const = 0;
01008 };
01009
01010 class KWIN_EXPORT GlobalShortcutsEditor : public KShortcutsEditor
01011 {
01012 public:
01013 GlobalShortcutsEditor( QWidget *parent );
01014 };
01015
01022 class KWIN_EXPORT WindowVertex
01023 {
01024 public:
01025 double x() const;
01026 double y() const;
01027 void move( double x, double y );
01028 void setX( double x );
01029 void setY( double y );
01030 double originalX() const;
01031 double originalY() const;
01032 double textureX() const;
01033 double textureY() const;
01034 WindowVertex();
01035 WindowVertex( double x, double y, double tx, double ty );
01036 private:
01037 friend class WindowQuad;
01038 friend class WindowQuadList;
01039 double px, py;
01040 double ox, oy;
01041 double tx, ty;
01042 };
01043
01049
01050 class KWIN_EXPORT WindowQuad
01051 {
01052 public:
01053 explicit WindowQuad( WindowQuadType type, int id = -1 );
01054 WindowQuad makeSubQuad( double x1, double y1, double x2, double y2 ) const;
01055 WindowVertex& operator[]( int index );
01056 const WindowVertex& operator[]( int index ) const;
01057 WindowQuadType type() const;
01058 int id() const;
01059 bool decoration() const;
01060 bool effect() const;
01061 double left() const;
01062 double right() const;
01063 double top() const;
01064 double bottom() const;
01065 double originalLeft() const;
01066 double originalRight() const;
01067 double originalTop() const;
01068 double originalBottom() const;
01069 bool smoothNeeded() const;
01070 bool isTransformed() const;
01071 private:
01072 friend class WindowQuadList;
01073 WindowVertex verts[ 4 ];
01074 WindowQuadType quadType;
01075 int quadID;
01076 };
01077
01078 class KWIN_EXPORT WindowQuadList
01079 : public QList< WindowQuad >
01080 {
01081 public:
01082 WindowQuadList splitAtX( double x ) const;
01083 WindowQuadList splitAtY( double y ) const;
01084 WindowQuadList makeGrid( int maxquadsize ) const;
01085 WindowQuadList makeRegularGrid( int xSubdivisions, int ySubdivisions ) const;
01086 WindowQuadList select( WindowQuadType type ) const;
01087 WindowQuadList filterOut( WindowQuadType type ) const;
01088 bool smoothNeeded() const;
01089 void makeArrays( float** vertices, float** texcoords ) const;
01090 bool isTransformed() const;
01091 };
01092
01093 class KWIN_EXPORT WindowPrePaintData
01094 {
01095 public:
01096 int mask;
01100 QRegion paint;
01105 QRegion clip;
01106 WindowQuadList quads;
01111 void setTranslucent();
01115 void setTransformed();
01116 };
01117
01118 class KWIN_EXPORT WindowPaintData
01119 {
01120 public:
01121 WindowPaintData( EffectWindow* w );
01127 double opacity;
01128 double contents_opacity;
01129 double decoration_opacity;
01130 double xScale;
01131 double yScale;
01132 double zScale;
01133 int xTranslate;
01134 int yTranslate;
01135 double zTranslate;
01144 double saturation;
01150 double brightness;
01151 WindowQuadList quads;
01155 GLShader* shader;
01156 RotationData* rotation;
01157 };
01158
01159 class KWIN_EXPORT ScreenPaintData
01160 {
01161 public:
01162 ScreenPaintData();
01163 double xScale;
01164 double yScale;
01165 double zScale;
01166 int xTranslate;
01167 int yTranslate;
01168 double zTranslate;
01169 RotationData* rotation;
01170 };
01171
01172 class KWIN_EXPORT ScreenPrePaintData
01173 {
01174 public:
01175 int mask;
01176 QRegion paint;
01177 };
01178
01179 class KWIN_EXPORT RotationData
01180 {
01181 public:
01182 RotationData();
01183 enum RotationAxis
01184 {
01185 XAxis,
01186 YAxis,
01187 ZAxis
01188 };
01189 RotationAxis axis;
01190 float angle;
01191 float xRotationPoint;
01192 float yRotationPoint;
01193 float zRotationPoint;
01194 };
01195
01205 class KWIN_EXPORT PaintClipper
01206 {
01207 public:
01211 PaintClipper( const QRegion& allowed_area );
01215 ~PaintClipper();
01220 static void push( const QRegion& allowed_area );
01224 static void pop( const QRegion& allowed_area );
01228 static bool clip();
01233 static QRegion paintArea();
01244 class KWIN_EXPORT Iterator
01245 {
01246 public:
01247 Iterator();
01248 ~Iterator();
01249 bool isDone();
01250 void next();
01251 QRect boundingRect() const;
01252 private:
01253 struct Data;
01254 Data* data;
01255 };
01256 private:
01257 QRegion area;
01258 static QStack< QRegion >* areas;
01259 };
01260
01261
01304 class KWIN_EXPORT TimeLine
01305 {
01306
01307
01308
01309 public:
01315 enum CurveShape
01316 {
01317 EaseInCurve = 0,
01318 EaseOutCurve,
01319 EaseInOutCurve,
01320 LinearCurve,
01321 SineCurve
01322 };
01323
01330 explicit TimeLine(const int duration = 0);
01331
01336 TimeLine(const TimeLine &other);
01340 ~TimeLine();
01344 int duration() const;
01348 void setDuration(const int msec);
01356 double value() const;
01362 double valueForTime(const int msec) const;
01367 int time() const;
01372 double progress() const;
01376 void addProgress(const double progress);
01381 void addTime(const int msec);
01387 void removeTime(const int msec);
01394 void setProgress(const double progress);
01400 void setCurveShape(CurveShape curveShape);
01405
01406
01407 private:
01408 QTimeLine* m_TimeLine;
01409 int m_Time;
01410 double m_Progress;
01411 int m_Duration;
01412 CurveShape m_CurveShape;
01413
01414 };
01415
01419 template <typename T>
01420 class KWIN_EXPORT Motion
01421 {
01422 public:
01429 explicit Motion( T initial, double strength, double smoothness );
01434 Motion( const Motion<T> &other );
01435 ~Motion();
01436
01437 inline T value() const { return m_value; }
01438 inline void setValue( const T value ) { m_value = value; }
01439 inline T target() const { return m_target; }
01440 inline void setTarget( const T target ) { m_target = target; }
01441 inline T velocity() const { return m_velocity; }
01442 inline void setVelocity( const T velocity ) { m_velocity = velocity; }
01443
01444 inline double strength() const { return m_strength; }
01445 inline void setStrength( const double strength ) { m_strength = strength; }
01446 inline double smoothness() const { return m_smoothness; }
01447 inline void setSmoothness( const double smoothness ) { m_smoothness = smoothness; }
01448
01452 inline T distance() const { return m_target - m_value; }
01453
01458 void calculate( const int msec );
01463 void finish();
01464
01465 private:
01466 T m_value;
01467
01468 T m_target;
01469 T m_velocity;
01470 double m_strength;
01471 double m_smoothness;
01472 };
01473
01481 class KWIN_EXPORT Motion1D : public Motion<double>
01482 {
01483 public:
01484 explicit Motion1D( double initial = 0.0, double strength = 0.08, double smoothness = 4.0 );
01485 Motion1D( const Motion1D &other );
01486 ~Motion1D();
01487 };
01488
01496 class KWIN_EXPORT Motion2D : public Motion<QPointF>
01497 {
01498 public:
01499 explicit Motion2D( QPointF initial = QPointF(), double strength = 0.08, double smoothness = 4.0 );
01500 Motion2D( const Motion2D &other );
01501 ~Motion2D();
01502 };
01503
01516 class KWIN_EXPORT WindowMotionManager
01517 {
01518 public:
01522 explicit WindowMotionManager( bool useGlobalAnimationModifier = true );
01523 ~WindowMotionManager();
01524
01528 void manage( EffectWindow *w );
01532 inline void manage( EffectWindowList list )
01533 {
01534 for( int i = 0; i < list.size(); i++ )
01535 manage( list.at( i ));
01536 }
01541 void unmanage( EffectWindow *w );
01546 void unmanageAll();
01553 void calculate( int time );
01561 void apply( EffectWindow *w, WindowPaintData &data );
01567 void reset();
01572 void reset( EffectWindow *w );
01573
01580 void moveWindow( EffectWindow *w, QPoint target, double scale = 1.0, double yScale = 0.0 );
01587 inline void moveWindow( EffectWindow *w, QRect target )
01588 {
01589
01590 moveWindow( w, target.topLeft(),
01591 target.width() / double( w->width() ), target.height() / double( w->height() ));
01592 }
01593
01598 QRectF transformedGeometry( EffectWindow *w ) const;
01603 QRectF targetGeometry( EffectWindow *w ) const;
01610 EffectWindow* windowAtPoint( QPoint point, bool useStackingOrder = true ) const;
01611
01615 inline EffectWindowList managedWindows() const { return m_managedWindows.keys(); }
01620 inline bool isManaging( EffectWindow *w ) { return m_managedWindows.contains( w ); }
01625 inline bool managingWindows() { return !m_managedWindows.empty(); }
01631 inline bool areWindowsMoving() { return !m_movingWindowsSet.isEmpty(); }
01632
01633 private:
01634 bool m_useGlobalAnimationModifier;
01635 struct WindowMotion
01636 {
01637 Motion2D translation;
01638 Motion2D scale;
01639 };
01640 QHash<EffectWindow*, WindowMotion> m_managedWindows;
01641 QSet<EffectWindow*> m_movingWindowsSet;
01642 };
01643
01652 class KWIN_EXPORT EffectFrame : public QObject
01653 {
01654 Q_OBJECT
01655
01656 public:
01657 enum Style
01658 {
01659 None,
01660 Unstyled,
01661 Styled
01662 };
01663
01670 explicit EffectFrame( Style style, bool staticSize = true, QPoint position = QPoint( -1, -1 ),
01671 Qt::Alignment alignment = Qt::AlignCenter );
01672 ~EffectFrame();
01673
01678 void free();
01679
01683 void render( QRegion region = infiniteRegion(), double opacity = 1.0, double frameOpacity = 1.0 );
01684
01685 void setPosition( const QPoint& point );
01690 inline void setAlignment( Qt::Alignment alignment )
01691 { m_alignment = alignment; };
01692 void setGeometry( const QRect& geometry, bool force = false );
01693 inline QRect geometry() const
01694 { return m_geometry; };
01695
01696 void setText( const QString& text );
01697 inline QString text() const
01698 { return m_text; };
01699 void setFont( const QFont& font );
01700 inline QFont font() const
01701 { return m_font; };
01705 void setIcon( const QPixmap& icon );
01706 inline QPixmap icon() const
01707 { return m_icon; };
01708 void setIconSize( const QSize& size );
01709 inline QSize iconSize() const
01710 { return m_iconSize; };
01711
01715 static QColor styledTextColor();
01716
01721 static void cleanup();
01722
01723 private Q_SLOTS:
01724 void plasmaThemeChanged();
01725
01726 private:
01727 Q_DISABLE_COPY( EffectFrame )
01728
01729 void autoResize();
01730 void updateTexture();
01731 void updateTextTexture();
01732 void updatePicture();
01733 void updateTextPicture();
01734
01735 Style m_style;
01736 Plasma::FrameSvg m_frame;
01737 GLTexture* m_texture;
01738 GLTexture* m_textTexture;
01739 XRenderPicture* m_picture;
01740 XRenderPicture* m_textPicture;
01741
01742
01743 bool m_static;
01744 QPoint m_point;
01745 Qt::Alignment m_alignment;
01746 QRect m_geometry;
01747
01748
01749 QString m_text;
01750 QFont m_font;
01751 QPixmap m_icon;
01752 QSize m_iconSize;
01753
01754 static GLTexture* m_unstyledTexture;
01755 static void updateUnstyledTexture();
01756 };
01757
01761 extern KWIN_EXPORT EffectsHandler* effects;
01762
01763
01764
01765
01766
01767 inline
01768 bool EffectsHandler::paintText( const QString& text, const QPoint& center, int maxwidth,
01769 const QColor& color, const QFont& font )
01770 {
01771 return paintText( text, QRect( center.x() - maxwidth / 2, center.y() - 5000, maxwidth, 10000 ),
01772 color, font, Qt::AlignCenter );
01773 }
01774
01775 inline
01776 bool EffectsHandler::paintTextWithBackground( const QString& text, const QPoint& center, int maxwidth,
01777 const QColor& color, const QColor& bgcolor, const QFont& font )
01778 {
01779 return paintTextWithBackground( text,
01780 QRect( center.x() - maxwidth / 2, center.y() - 5000, maxwidth, 10000 ),
01781 color, bgcolor, font, Qt::AlignCenter );
01782 }
01783
01784
01785
01786
01787
01788 inline
01789 WindowVertex::WindowVertex()
01790 : px( 0 ), py( 0 ), tx( 0 ), ty( 0 )
01791 {
01792 }
01793
01794 inline
01795 WindowVertex::WindowVertex( double _x, double _y, double _tx, double _ty )
01796 : px( _x ), py( _y ), ox( _x ), oy( _y ), tx( _tx ), ty( _ty )
01797 {
01798 }
01799
01800 inline
01801 double WindowVertex::x() const
01802 {
01803 return px;
01804 }
01805
01806 inline
01807 double WindowVertex::y() const
01808 {
01809 return py;
01810 }
01811
01812 inline
01813 double WindowVertex::originalX() const
01814 {
01815 return ox;
01816 }
01817
01818 inline
01819 double WindowVertex::originalY() const
01820 {
01821 return oy;
01822 }
01823
01824 inline
01825 double WindowVertex::textureX() const
01826 {
01827 return tx;
01828 }
01829
01830 inline
01831 double WindowVertex::textureY() const
01832 {
01833 return ty;
01834 }
01835
01836 inline
01837 void WindowVertex::move( double x, double y )
01838 {
01839 px = x;
01840 py = y;
01841 }
01842
01843 inline
01844 void WindowVertex::setX( double x )
01845 {
01846 px = x;
01847 }
01848
01849 inline
01850 void WindowVertex::setY( double y )
01851 {
01852 py = y;
01853 }
01854
01855
01856
01857
01858
01859 inline
01860 WindowQuad::WindowQuad( WindowQuadType t, int id )
01861 : quadType( t )
01862 , quadID( id )
01863 {
01864 }
01865
01866 inline
01867 WindowVertex& WindowQuad::operator[]( int index )
01868 {
01869 assert( index >= 0 && index < 4 );
01870 return verts[ index ];
01871 }
01872
01873 inline
01874 const WindowVertex& WindowQuad::operator[]( int index ) const
01875 {
01876 assert( index >= 0 && index < 4 );
01877 return verts[ index ];
01878 }
01879
01880 inline
01881 WindowQuadType WindowQuad::type() const
01882 {
01883 assert( quadType != WindowQuadError );
01884 return quadType;
01885 }
01886
01887 inline
01888 int WindowQuad::id() const
01889 {
01890 return quadID;
01891 }
01892
01893 inline
01894 bool WindowQuad::decoration() const
01895 {
01896 assert( quadType != WindowQuadError );
01897 return quadType == WindowQuadDecoration;
01898 }
01899
01900 inline
01901 bool WindowQuad::effect() const
01902 {
01903 assert( quadType != WindowQuadError );
01904 return quadType >= EFFECT_QUAD_TYPE_START;
01905 }
01906
01907 inline
01908 bool WindowQuad::isTransformed() const
01909 {
01910 return !( verts[ 0 ].px == verts[ 0 ].ox && verts[ 0 ].py == verts[ 0 ].oy
01911 && verts[ 1 ].px == verts[ 1 ].ox && verts[ 1 ].py == verts[ 1 ].oy
01912 && verts[ 2 ].px == verts[ 2 ].ox && verts[ 2 ].py == verts[ 2 ].oy
01913 && verts[ 3 ].px == verts[ 3 ].ox && verts[ 3 ].py == verts[ 3 ].oy );
01914 }
01915
01916 inline
01917 double WindowQuad::left() const
01918 {
01919 return qMin( verts[ 0 ].px, qMin( verts[ 1 ].px, qMin( verts[ 2 ].px, verts[ 3 ].px )));
01920 }
01921
01922 inline
01923 double WindowQuad::right() const
01924 {
01925 return qMax( verts[ 0 ].px, qMax( verts[ 1 ].px, qMax( verts[ 2 ].px, verts[ 3 ].px )));
01926 }
01927
01928 inline
01929 double WindowQuad::top() const
01930 {
01931 return qMin( verts[ 0 ].py, qMin( verts[ 1 ].py, qMin( verts[ 2 ].py, verts[ 3 ].py )));
01932 }
01933
01934 inline
01935 double WindowQuad::bottom() const
01936 {
01937 return qMax( verts[ 0 ].py, qMax( verts[ 1 ].py, qMax( verts[ 2 ].py, verts[ 3 ].py )));
01938 }
01939
01940 inline
01941 double WindowQuad::originalLeft() const
01942 {
01943 return verts[ 0 ].ox;
01944 }
01945
01946 inline
01947 double WindowQuad::originalRight() const
01948 {
01949 return verts[ 2 ].ox;
01950 }
01951
01952 inline
01953 double WindowQuad::originalTop() const
01954 {
01955 return verts[ 0 ].oy;
01956 }
01957
01958 inline
01959 double WindowQuad::originalBottom() const
01960 {
01961 return verts[ 2 ].oy;
01962 }
01963
01964
01965
01966
01967
01968 template <typename T>
01969 Motion<T>::Motion( T initial, double strength, double smoothness )
01970 : m_value( initial )
01971 , m_target( initial )
01972 , m_velocity()
01973 , m_strength( strength )
01974 , m_smoothness( smoothness )
01975 {
01976 }
01977
01978 template <typename T>
01979 Motion<T>::Motion( const Motion &other )
01980 : m_value( other.value() )
01981 , m_target( other.target() )
01982 , m_velocity( other.velocity() )
01983 , m_strength( other.strength() )
01984 , m_smoothness( other.smoothness() )
01985 {
01986 }
01987
01988 template <typename T>
01989 Motion<T>::~Motion()
01990 {
01991 }
01992
01993 template <typename T>
01994 void Motion<T>::calculate( const int msec )
01995 {
01996 if( m_value == m_target && m_velocity == T() )
01997 return;
01998
01999
02000 int steps = qMax( 1, msec / 5 );
02001 for( int i = 0; i < steps; i++ )
02002 {
02003 T diff = m_target - m_value;
02004 T strength = diff * m_strength;
02005 m_velocity = ( m_smoothness * m_velocity + strength ) / ( m_smoothness + 1.0 );
02006 m_value += m_velocity;
02007 }
02008 }
02009
02010 template <typename T>
02011 void Motion<T>::finish()
02012 {
02013 m_value = m_target;
02014 m_velocity = T();
02015 }
02016
02017 }
02018
02021 #endif // KWINEFFECTS_H