• Skip to content
  • Skip to link menu
KDE 4.2 API Reference
  • KDE API Reference
  • API Reference
  • Sitemap
  • Contact Us
 

KWinLibraries

kwineffects.h

Go to the documentation of this file.
00001 /********************************************************************
00002  KWin - the KDE window manager
00003  This file is part of the KDE project.
00004 
00005 Copyright (C) 2006 Lubos Lunak <l.lunak@kde.org>
00006 
00007 This program is free software; you can redistribute it and/or modify
00008 it under the terms of the GNU General Public License as published by
00009 the Free Software Foundation; either version 2 of the License, or
00010 (at your option) any later version.
00011 
00012 This program is distributed in the hope that it will be useful,
00013 but WITHOUT ANY WARRANTY; without even the implied warranty of
00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015 GNU General Public License for more details.
00016 
00017 You should have received a copy of the GNU General Public License
00018 along with this program.  If not, see <http://www.gnu.org/licenses/>.
00019 *********************************************************************/
00020 
00021 #ifndef KWINEFFECTS_H
00022 #define KWINEFFECTS_H
00023 
00024 #include <kwinconfig.h>
00025 #include <kwinglobals.h>
00026 #include "kdecoration.h"
00027 
00028 #include <QtCore/QPair>
00029 #include <QtCore/QRect>
00030 #include <QtGui/QRegion>
00031 #include <QtGui/QFont>
00032 
00033 #include <QtCore/QVector>
00034 #include <QtCore/QList>
00035 #include <QtCore/QHash>
00036 #include <QtCore/QStack>
00037 #include <QtCore/QTimeLine>
00038 
00039 #include <KDE/KPluginFactory>
00040 #include <KDE/KShortcutsEditor>
00041 
00042 #include <assert.h>
00043 #include <limits.h>
00044 
00045 class KLibrary;
00046 class KConfigGroup;
00047 class KActionCollection;
00048 class QKeyEvent;
00049 
00050 namespace KWin
00051 {
00052 
00053 
00054 class EffectWindow;
00055 class EffectWindowGroup;
00056 class Effect;
00057 class WindowQuad;
00058 class GLRenderTarget;
00059 class GLShader;
00060 class RotationData;
00061 class WindowQuadList;
00062 class WindowPrePaintData;
00063 class WindowPaintData;
00064 class ScreenPrePaintData;
00065 class ScreenPaintData;
00066 
00067 typedef QPair< QString, Effect* > EffectPair;
00068 typedef QPair< Effect*, Window > InputWindowPair;
00069 typedef QList< EffectWindow* > EffectWindowList;
00070 
00071 
00165 #define KWIN_EFFECT_API_MAKE_VERSION( major, minor ) (( major ) << 8 | ( minor ))
00166 #define KWIN_EFFECT_API_VERSION_MAJOR 0
00167 #define KWIN_EFFECT_API_VERSION_MINOR 57
00168 #define KWIN_EFFECT_API_VERSION KWIN_EFFECT_API_MAKE_VERSION( \
00169     KWIN_EFFECT_API_VERSION_MAJOR, KWIN_EFFECT_API_VERSION_MINOR )
00170 
00171 enum WindowQuadType
00172     {
00173     WindowQuadError, // for the stupid default ctor
00174     WindowQuadContents,
00175     WindowQuadDecoration,
00176     EFFECT_QUAD_TYPE_START = 100 
00177     };
00178 
00182 KWIN_EXPORT inline
00183 QRect infiniteRegion()
00184     { // INT_MIN / 2 because width/height is used (INT_MIN+INT_MAX==-1)
00185     return QRect( INT_MIN / 2, INT_MIN / 2, INT_MAX, INT_MAX );
00186     }
00187 
00236 class KWIN_EXPORT Effect
00237     {
00238     public:
00240         // TODO: is that ok here?
00241         enum
00242         {
00246             PAINT_WINDOW_OPAQUE         = 1 << 0,
00250             PAINT_WINDOW_TRANSLUCENT    = 1 << 1,
00254             PAINT_WINDOW_TRANSFORMED    = 1 << 2,
00259             PAINT_SCREEN_REGION         = 1 << 3,
00264             PAINT_SCREEN_TRANSFORMED    = 1 << 4,
00269             PAINT_SCREEN_WITH_TRANSFORMED_WINDOWS = 1 << 5,
00273             PAINT_SCREEN_BACKGROUND_FIRST = 1 << 6
00274         };
00275 
00279         Effect();
00283         virtual ~Effect();
00284 
00288         enum ReconfigureFlag
00289             {
00290             ReconfigureAll = 1 << 0 
00291             };
00292         Q_DECLARE_FLAGS( ReconfigureFlags, ReconfigureFlag )
00293 
00294         
00297         virtual void reconfigure( ReconfigureFlags flags );
00298 
00307         virtual void prePaintScreen( ScreenPrePaintData& data, int time );
00315         virtual void paintScreen( int mask, QRegion region, ScreenPaintData& data );
00322         virtual void postPaintScreen();
00323 
00332         virtual void prePaintWindow( EffectWindow* w, WindowPrePaintData& data, int time );
00340         virtual void paintWindow( EffectWindow* w, int mask, QRegion region, WindowPaintData& data );
00347         virtual void postPaintWindow( EffectWindow* w );
00348 
00354         virtual void drawWindow( EffectWindow* w, int mask, QRegion region, WindowPaintData& data );
00355 
00360         virtual void buildQuads( EffectWindow* w, WindowQuadList& quadList );
00361 
00368         virtual QRect transformWindowDamage( EffectWindow* w, const QRect& r );
00369 
00371         virtual void windowUserMovedResized( EffectWindow* c, bool first, bool last );
00372         virtual void windowOpacityChanged( EffectWindow* c, double old_opacity );
00373         virtual void windowAdded( EffectWindow* c );
00374         virtual void windowClosed( EffectWindow* c );
00375         virtual void windowDeleted( EffectWindow* c );
00376         virtual void windowActivated( EffectWindow* c );
00377         virtual void windowMinimized( EffectWindow* c );
00378         virtual void windowUnminimized( EffectWindow* c );
00379         virtual void windowInputMouseEvent( Window w, QEvent* e );
00380         virtual void desktopChanged( int old );
00381         virtual void windowDamaged( EffectWindow* w, const QRect& r );
00382         virtual void windowGeometryShapeChanged( EffectWindow* w, const QRect& old );
00383         virtual void mouseChanged( const QPoint& pos, const QPoint& oldpos,
00384             Qt::MouseButtons buttons, Qt::MouseButtons oldbuttons,
00385             Qt::KeyboardModifiers modifiers, Qt::KeyboardModifiers oldmodifiers );
00386         virtual void grabbedKeyboardEvent( QKeyEvent* e );
00394         virtual void propertyNotify( EffectWindow* w, long atom );
00395 
00396         virtual void tabBoxAdded( int mode );
00397         virtual void tabBoxClosed();
00398         virtual void tabBoxUpdated();
00399         virtual bool borderActivated( ElectricBorder border );
00400 
00401         static int displayWidth();
00402         static int displayHeight();
00403         static QPoint cursorPos();
00404 
00414         // return type is intentionally double so that one can divide using it without losing data
00415         static double animationTime( const KConfigGroup& cfg, const QString& key, int defaultTime );
00420         static double animationTime( int defaultTime );
00426         static double interpolate(double x, double y, double a)
00427             {
00428             return x * (1 - a) + y * a;
00429             }
00433         static void setPositionTransformations( WindowPaintData& data, QRect& region, EffectWindow* w,
00434             const QRect& r, Qt::AspectRatioMode aspect );
00435     };
00436 
00437 
00447 #define KWIN_EFFECT( name, classname ) \
00448     extern "C" { \
00449         KWIN_EXPORT Effect* effect_create_kwin4_effect_##name() { return new classname; } \
00450         KWIN_EXPORT int effect_version_kwin4_effect_##name() { return KWIN_EFFECT_API_VERSION; } \
00451     }
00452 
00456 #define KWIN_EFFECT_SUPPORTED( name, function ) \
00457     extern "C" { \
00458         KWIN_EXPORT bool effect_supported_kwin4_effect_##name() { return function; } \
00459     }
00460 
00464 #define KWIN_EFFECT_CONFIG( name, classname ) \
00465     K_PLUGIN_FACTORY(name##_factory, registerPlugin<classname>();) \
00466     K_EXPORT_PLUGIN(name##_factory("kcm_kwineffect_" #name))
00467 
00471 #define KWIN_EFFECT_CONFIG_FACTORY K_PLUGIN_FACTORY_DECLARATION(EffectFactory)
00472 
00473 
00484 class KWIN_EXPORT EffectsHandler
00485     {
00486     friend class Effect;
00487     public:
00488         EffectsHandler(CompositingType type);
00489         virtual ~EffectsHandler();
00490         // for use by effects
00491         virtual void prePaintScreen( ScreenPrePaintData& data, int time ) = 0;
00492         virtual void paintScreen( int mask, QRegion region, ScreenPaintData& data ) = 0;
00493         virtual void postPaintScreen() = 0;
00494         virtual void prePaintWindow( EffectWindow* w, WindowPrePaintData& data, int time ) = 0;
00495         virtual void paintWindow( EffectWindow* w, int mask, QRegion region, WindowPaintData& data ) = 0;
00496         virtual void postPaintWindow( EffectWindow* w ) = 0;
00497         virtual void drawWindow( EffectWindow* w, int mask, QRegion region, WindowPaintData& data ) = 0;
00498         virtual void buildQuads( EffectWindow* w, WindowQuadList& quadList ) = 0;
00499         virtual QRect transformWindowDamage( EffectWindow* w, const QRect& r );
00500         // Functions for handling input - e.g. when an Expose-like effect is shown, an input window
00501         // covering the whole screen is created and all mouse events will be intercepted by it.
00502         // The effect's windowInputMouseEvent() will get called with such events.
00503         virtual Window createInputWindow( Effect* e, int x, int y, int w, int h, const QCursor& cursor ) = 0;
00504         Window createInputWindow( Effect* e, const QRect& r, const QCursor& cursor );
00505         virtual Window createFullScreenInputWindow( Effect* e, const QCursor& cursor );
00506         virtual void destroyInputWindow( Window w ) = 0;
00507         virtual QPoint cursorPos() const = 0;
00508         virtual bool grabKeyboard( Effect* effect ) = 0;
00509         virtual void ungrabKeyboard() = 0;
00510 
00511         virtual void checkElectricBorder(const QPoint &pos, Time time) = 0;
00512         virtual void reserveElectricBorder( ElectricBorder border ) = 0;
00513         virtual void unreserveElectricBorder( ElectricBorder border ) = 0;
00514         virtual void reserveElectricBorderSwitching( bool reserve ) = 0;
00515 
00516         // functions that allow controlling windows/desktop
00517         virtual void activateWindow( EffectWindow* c ) = 0;
00518         virtual EffectWindow* activeWindow() const = 0 ;
00519         virtual void moveWindow( EffectWindow* w, const QPoint& pos ) = 0;
00520         virtual void windowToDesktop( EffectWindow* w, int desktop ) = 0;
00521         // 
00522         virtual int currentDesktop() const = 0;
00523         virtual int numberOfDesktops() const = 0;
00524         virtual void setCurrentDesktop( int desktop ) = 0;
00525         virtual QString desktopName( int desktop ) const = 0;
00526         virtual int activeScreen() const = 0; // Xinerama
00527         virtual int numScreens() const = 0; // Xinerama
00528         virtual int screenNumber( const QPoint& pos ) const = 0; // Xinerama
00529         virtual QRect clientArea( clientAreaOption, int screen, int desktop ) const = 0;
00530         virtual QRect clientArea( clientAreaOption, const EffectWindow* c ) const = 0;
00531         virtual QRect clientArea( clientAreaOption, const QPoint& p, int desktop ) const = 0;
00532         virtual void calcDesktopLayout(int* x, int* y, Qt::Orientation* orientation) const = 0;
00533         virtual bool optionRollOverDesktops() const = 0;
00534         virtual int desktopToLeft( int desktop, bool wrap ) const = 0;
00535         virtual int desktopToRight( int desktop, bool wrap ) const = 0;
00536         virtual int desktopUp( int desktop, bool wrap ) const = 0;
00537         virtual int desktopDown( int desktop, bool wrap ) const = 0;
00545         virtual double animationTimeFactor() const = 0;
00546         virtual WindowQuadType newWindowQuadType() = 0;
00547 
00548         virtual EffectWindow* findWindow( WId id ) const = 0;
00549         virtual EffectWindowList stackingOrder() const = 0;
00550         // window will be temporarily painted as if being at the top of the stack
00551         virtual void setElevatedWindow( EffectWindow* w, bool set ) = 0;
00552 
00553         virtual void setTabBoxWindow(EffectWindow*) = 0;
00554         virtual void setTabBoxDesktop(int) = 0;
00555         virtual EffectWindowList currentTabBoxWindowList() const = 0;
00556         virtual void refTabBox() = 0;
00557         virtual void unrefTabBox() = 0;
00558         virtual void closeTabBox() = 0;
00559         virtual QList< int > currentTabBoxDesktopList() const = 0;
00560         virtual int currentTabBoxDesktop() const = 0;
00561         virtual EffectWindow* currentTabBoxWindow() const = 0;
00562 
00563         virtual void setActiveFullScreenEffect( Effect* e ) = 0;
00564         virtual Effect* activeFullScreenEffect() const = 0;
00565 
00566         virtual void pushRenderTarget(GLRenderTarget* target) = 0;
00567         virtual GLRenderTarget* popRenderTarget() = 0;
00568 
00574         virtual void addRepaintFull() = 0;
00575         virtual void addRepaint( const QRect& r ) = 0;
00576         virtual void addRepaint( const QRegion& r ) = 0;
00577         virtual void addRepaint( int x, int y, int w, int h ) = 0;
00578 
00579         CompositingType compositingType() const;
00580         virtual unsigned long xrenderBufferPicture() = 0;
00581         bool saturationSupported() const;
00582         virtual void reconfigure() = 0;
00583 
00590         virtual void registerPropertyType( long atom, bool reg ) = 0;
00591 
00595         virtual bool hasDecorationShadows() const = 0;
00602         virtual QList< QList<QImage> > shadowTextures() = 0;
00606         virtual int shadowTextureList( ShadowType type ) const = 0;
00607 
00616         bool paintText( const QString& text, const QPoint& center, int maxwidth,
00617                         const QColor& color, const QFont& font = QFont() );
00618         bool paintText( const QString& text, const QRect& rect, const QColor& color,
00619                         const QFont& font = QFont(), const Qt::Alignment& alignment = Qt::AlignCenter );
00620         bool paintTextWithBackground( const QString& text, const QPoint& center, int maxwidth,
00621                                       const QColor& color, const QColor& bgcolor,
00622                                       const QFont& font = QFont() );
00623         bool paintTextWithBackground( const QString& text, const QRect& rect, const QColor& color,
00624                                       const QColor& bgcolor, const QFont& font = QFont(),
00625                                       const Qt::Alignment& alignment = Qt::AlignCenter );
00626 
00627 
00633         static void sendReloadMessage( const QString& effectname );
00637         static KConfigGroup effectConfig( const QString& effectname );
00638 
00639 
00640     protected:
00641         QVector< EffectPair > loaded_effects;
00642         QHash< QString, KLibrary* > effect_libraries;
00643         QList< InputWindowPair > input_windows;
00644         //QHash< QString, EffectFactory* > effect_factories;
00645         int current_paint_screen;
00646         int current_paint_window;
00647         int current_draw_window;
00648         int current_build_quads;
00649         int current_transform;
00650         CompositingType compositing_type;
00651     };
00652 
00653 
00660 class KWIN_EXPORT EffectWindow
00661     {
00662     public:
00664         enum
00665         {
00667             PAINT_DISABLED              = 1 << 0,
00669             PAINT_DISABLED_BY_DELETE    = 1 << 1,
00671             PAINT_DISABLED_BY_DESKTOP   = 1 << 2,
00673             PAINT_DISABLED_BY_MINIMIZE  = 1 << 3
00674         };
00675 
00676         EffectWindow();
00677         virtual ~EffectWindow();
00678 
00679         virtual void enablePainting( int reason ) = 0;
00680         virtual void disablePainting( int reason ) = 0;
00681         virtual bool isPaintingEnabled() = 0;
00682         virtual void addRepaint( const QRect& r ) = 0;
00683         virtual void addRepaint( int x, int y, int w, int h ) = 0;
00684         virtual void addRepaintFull() = 0;
00685 
00686         virtual void refWindow() = 0;
00687         virtual void unrefWindow() = 0;
00688         virtual bool isDeleted() const = 0;
00689 
00690         virtual bool isMinimized() const = 0;
00691         virtual double opacity() const = 0;
00692 
00693         virtual bool isOnDesktop( int d ) const;
00694         virtual bool isOnCurrentDesktop() const;
00695         virtual bool isOnAllDesktops() const = 0;
00696         virtual int desktop() const = 0; // prefer isOnXXX()
00697 
00698         virtual int x() const = 0;
00699         virtual int y() const = 0;
00700         virtual int width() const = 0;
00701         virtual int height() const = 0;
00702         virtual QRect geometry() const = 0;
00703         virtual QRegion shape() const = 0;
00704         virtual int screen() const = 0;
00706         virtual bool hasOwnShape() const = 0; // only for shadow effect, for now
00707         virtual QPoint pos() const = 0;
00708         virtual QSize size() const = 0;
00709         virtual QRect rect() const = 0;
00710         virtual bool isMovable() const = 0;
00711         virtual bool isMovableAcrossScreens() const = 0;
00712         virtual bool isUserMove() const = 0;
00713         virtual bool isUserResize() const = 0;
00714         virtual QRect iconGeometry() const = 0;
00718         virtual QRect contentsRect() const = 0;
00719         bool hasDecoration() const;
00720         virtual QByteArray readProperty( long atom, long type, int format ) const = 0;
00721 
00722         virtual QString caption() const = 0;
00723         virtual QPixmap icon() const = 0;
00724         virtual QString windowClass() const = 0;
00725         virtual QString windowRole() const = 0;
00726         virtual const EffectWindowGroup* group() const = 0;
00727 
00732         virtual bool isDesktop() const = 0;
00737         virtual bool isDock() const = 0;
00742         virtual bool isToolbar() const = 0;
00747         virtual bool isTopMenu() const = 0;
00752         virtual bool isMenu() const = 0;
00758         virtual bool isNormalWindow() const = 0; // normal as in 'NET::Normal or NET::Unknown non-transient'
00764         virtual bool isSpecialWindow() const = 0;
00769         virtual bool isDialog() const = 0;
00775         virtual bool isSplash() const = 0;
00780         virtual bool isUtility() const = 0;
00786         virtual bool isDropdownMenu() const = 0;
00791         virtual bool isPopupMenu() const = 0; // a context popup, not dropdown, not torn-off
00796         virtual bool isTooltip() const = 0;
00801         virtual bool isNotification() const = 0;
00806         virtual bool isComboBox() const = 0;
00811         virtual bool isDNDIcon() const = 0;
00816         virtual bool isManaged() const = 0; // whether it's managed or override-redirect
00817 
00818         virtual bool isModal() const = 0;
00819         virtual EffectWindow* findModal() = 0;
00820         virtual EffectWindowList mainWindows() const = 0;
00821 
00826         virtual QList<QRect> shadowQuads( ShadowType type ) const = 0;
00830         virtual double shadowOpacity( ShadowType type ) const = 0;
00834         virtual double shadowBrightness( ShadowType type ) const = 0;
00838         virtual double shadowSaturation( ShadowType type ) const = 0;
00842         virtual WindowQuadList buildQuads( bool force = false ) const = 0;
00843     };
00844 
00845 class KWIN_EXPORT EffectWindowGroup
00846     {
00847     public:
00848         virtual ~EffectWindowGroup();
00849         virtual EffectWindowList members() const = 0;
00850     };
00851 
00852 class KWIN_EXPORT GlobalShortcutsEditor : public KShortcutsEditor
00853     {
00854     public:
00855         GlobalShortcutsEditor( QWidget *parent );
00856     };
00857 
00864 class KWIN_EXPORT WindowVertex
00865     {
00866     public:
00867         double x() const;
00868         double y() const;
00869         void move( double x, double y );
00870         void setX( double x );
00871         void setY( double y );
00872         double originalX() const;
00873         double originalY() const;
00874         double textureX() const;
00875         double textureY() const;
00876         WindowVertex();
00877         WindowVertex( double x, double y, double tx, double ty );
00878     private:
00879         friend class WindowQuad;
00880         friend class WindowQuadList;
00881         double px, py; // position
00882         double ox, oy; // origional position
00883         double tx, ty; // texture coords
00884     };
00885 
00891 // NOTE: This class expects the (original) vertices to be in the clockwise order starting from topleft.
00892 class KWIN_EXPORT WindowQuad
00893     {
00894     public:
00895         explicit WindowQuad( WindowQuadType type, int id = -1 );
00896         WindowQuad makeSubQuad( double x1, double y1, double x2, double y2 ) const;
00897         WindowVertex& operator[]( int index );
00898         const WindowVertex& operator[]( int index ) const;
00899         WindowQuadType type() const;
00900         int id() const;
00901         bool decoration() const;
00902         bool effect() const;
00903         double left() const;
00904         double right() const;
00905         double top() const;
00906         double bottom() const;
00907         double originalLeft() const;
00908         double originalRight() const;
00909         double originalTop() const;
00910         double originalBottom() const;
00911         bool smoothNeeded() const;
00912         bool isTransformed() const;
00913     private:
00914         friend class WindowQuadList;
00915         WindowVertex verts[ 4 ];
00916         WindowQuadType quadType; // 0 - contents, 1 - decoration
00917         int quadID;
00918     };
00919 
00920 class KWIN_EXPORT WindowQuadList
00921     : public QList< WindowQuad >
00922     {
00923     public:
00924         WindowQuadList splitAtX( double x ) const;
00925         WindowQuadList splitAtY( double y ) const;
00926         WindowQuadList makeGrid( int maxquadsize ) const;
00927         WindowQuadList makeRegularGrid( int xSubdivisions, int ySubdivisions ) const;
00928         WindowQuadList select( WindowQuadType type ) const;
00929         WindowQuadList filterOut( WindowQuadType type ) const;
00930         bool smoothNeeded() const;
00931         void makeArrays( float** vertices, float** texcoords ) const;
00932         bool isTransformed() const;
00933     };
00934 
00935 class KWIN_EXPORT WindowPrePaintData
00936     {
00937     public:
00938         int mask;
00942         QRegion paint;
00947         QRegion clip;
00948         WindowQuadList quads;
00953         void setTranslucent();
00957         void setTransformed();
00958     };
00959 
00960 class KWIN_EXPORT WindowPaintData
00961     {
00962     public:
00963         WindowPaintData( EffectWindow* w );
00969         double opacity;
00970         double contents_opacity;
00971         double decoration_opacity;
00972         double xScale;
00973         double yScale;
00974         double zScale;
00975         int xTranslate;
00976         int yTranslate;
00977         double zTranslate;
00986         double saturation;
00992         double brightness;
00993         WindowQuadList quads;
00997         GLShader* shader;
00998         RotationData* rotation;
00999     };
01000 
01001 class KWIN_EXPORT ScreenPaintData
01002     {
01003     public:
01004         ScreenPaintData();
01005         double xScale;
01006         double yScale;
01007         double zScale;
01008         int xTranslate;
01009         int yTranslate;
01010         double zTranslate;
01011         RotationData* rotation;
01012     };
01013 
01014 class KWIN_EXPORT ScreenPrePaintData
01015     {
01016     public:
01017         int mask;
01018         QRegion paint;
01019     };
01020 
01021 class KWIN_EXPORT RotationData
01022     {
01023     public:
01024         RotationData();
01025         enum RotationAxis
01026             {
01027             XAxis,
01028             YAxis,
01029             ZAxis
01030             };
01031         RotationAxis axis;
01032         float angle;
01033         float xRotationPoint;
01034         float yRotationPoint;
01035         float zRotationPoint;
01036     };
01037 
01047 class KWIN_EXPORT PaintClipper
01048     {
01049     public:
01053         PaintClipper( const QRegion& allowed_area );
01057         ~PaintClipper();
01062         static void push( const QRegion& allowed_area );
01066         static void pop( const QRegion& allowed_area );
01070         static bool clip();
01075         static QRegion paintArea();
01086         class KWIN_EXPORT Iterator
01087             {
01088             public:
01089                 Iterator();
01090                 ~Iterator();
01091                 bool isDone();
01092                 void next();
01093                 QRect boundingRect() const;
01094             private:
01095                 struct Data;
01096                 Data* data;
01097             };
01098     private:
01099         QRegion area;
01100         static QStack< QRegion >* areas;
01101     };
01102 
01103 
01146 class KWIN_EXPORT TimeLine
01147     {
01148 
01149     Q_ENUMS( CurveShape )
01150 
01151     public:
01157         enum CurveShape
01158         {
01159             EaseInCurve = 0,
01160             EaseOutCurve,
01161             EaseInOutCurve,
01162             LinearCurve,
01163             SineCurve
01164         };
01165 
01172         explicit TimeLine(int duration = 0);
01173 
01178         TimeLine(const TimeLine &other);
01182         ~TimeLine();
01186         int duration() const;
01190         void setDuration(const int msec);
01198         double value() const;
01204         double valueForTime(const int msec) const;
01209         int time() const;
01214         double progress() const;
01218         void addProgress(const double progress);
01223         void addTime(const int msec);
01229         void removeTime(const int msec);
01236         void setProgress(const double progress);
01242         void setCurveShape(CurveShape curveShape);
01247         //void setCurveShape(CurveShape curveShape);
01248 
01249     private:
01250         QTimeLine* m_TimeLine;
01251         int m_Time;
01252         double m_Progress;
01253         int m_Duration;
01254         CurveShape m_CurveShape;
01255         //Q_DISABLE_COPY(TimeLine)
01256     };
01257 
01268 template <typename T>
01269 class KWIN_EXPORT Motion
01270     {
01271     public:
01280         explicit Motion( T initial = T(), double strength = 7.5, double decay = 0.5 );
01285         Motion( const Motion<T> &other );
01286         ~Motion();
01287 
01288         inline T value() const { return m_value; }
01289         inline void setValue( const T value ) { m_value = value; }
01290         inline T target() const { return m_target; }
01291         inline void setTarget( const T target ) { m_target = target; }
01292         inline T velocity() const { return m_velocity; }
01293         inline void setVelocity( const T velocity ) { m_velocity = velocity; }
01294 
01295         inline double strength() const { return m_strength; }
01296         inline void setStrength( const double strength ) { m_strength = strength; }
01297         inline double decay() const { return m_decay; }
01298         inline void setDecay( const double decay ) { m_decay = decay; }
01299         inline void setStrengthDecay( const double strength, const double decay )
01300             { m_strength = strength; m_decay = decay; }
01301 
01305         inline T distance() const { return m_target - m_value; }
01306 
01311         void calculate( const int msec );
01316         void finish();
01317 
01318     private:
01319         T m_value;
01320 
01321         T m_target;
01322         T m_velocity;
01323         double m_strength;
01324         double m_decay;
01325     };
01326 
01339 class KWIN_EXPORT WindowMotionManager
01340     {
01341     public:
01345         explicit WindowMotionManager( bool useGlobalAnimationModifier = true );
01346         ~WindowMotionManager();
01347 
01351         void manage( EffectWindow *w );
01355         inline void manage( EffectWindowList list )
01356             {
01357             for( int i = 0; i < list.size(); i++ )
01358                 manage( list.at( i ));
01359             }
01364         void unmanage( EffectWindow *w );
01369         void unmanageAll();
01376         void calculate( int time );
01384         void apply( EffectWindow *w, WindowPaintData &data );
01390         void reset();
01395         void reset( EffectWindow *w );
01396 
01403         void moveWindow( EffectWindow *w, QPoint target, double scale = 1.0, double yScale = 0.0 );
01410         inline void moveWindow( EffectWindow *w, QRect target )
01411             {
01412             // TODO: Scale might be slightly different in the comparison due to rounding
01413             moveWindow( w, target.topLeft(),
01414                 target.width() / double( w->width() ), target.height() / double( w->height() ));
01415             }
01416 
01421         QRectF transformedGeometry( EffectWindow *w ) const;
01428         EffectWindow* windowAtPoint( QPoint point, bool useStackingOrder = true ) const;
01429 
01433         inline EffectWindowList managedWindows() const { return m_managedWindows.keys(); }
01438         inline bool isManaging( EffectWindow *w ) { return m_managedWindows.contains( w ); }
01443         inline bool managingWindows() { return !m_managedWindows.empty(); }
01449         inline bool areWindowsMoving() { return m_movingWindows > 0; }
01450 
01451     private:
01452         bool m_useGlobalAnimationModifier;
01453         struct WindowMotion
01454             { // TODO: Rotation, etc?
01455             Motion<QPointF> translation; // Absolute position
01456             Motion<QPointF> scale; // xScale and yScale
01457             };
01458         QHash<EffectWindow*, WindowMotion> m_managedWindows;
01459         uint m_movingWindows;
01460     };
01461 
01465 extern KWIN_EXPORT EffectsHandler* effects;
01466 
01467 /***************************************************************
01468  EffectsHandler
01469 ***************************************************************/
01470 
01471 inline
01472 bool EffectsHandler::paintText( const QString& text, const QPoint& center, int maxwidth,
01473         const QColor& color, const QFont& font )
01474 {
01475     return paintText( text, QRect( center.x() - maxwidth / 2, center.y() - 5000, maxwidth, 10000 ),
01476         color, font, Qt::AlignCenter );
01477 }
01478 
01479 inline
01480 bool EffectsHandler::paintTextWithBackground( const QString& text, const QPoint& center, int maxwidth,
01481         const QColor& color, const QColor& bgcolor, const QFont& font )
01482 {
01483     return paintTextWithBackground( text,
01484         QRect( center.x() - maxwidth / 2, center.y() - 5000, maxwidth, 10000 ),
01485         color, bgcolor, font, Qt::AlignCenter );
01486 }
01487 
01488 /***************************************************************
01489  WindowVertex
01490 ***************************************************************/
01491 
01492 inline
01493 WindowVertex::WindowVertex()
01494     : px( 0 ), py( 0 ), tx( 0 ), ty( 0 )
01495     {
01496     }
01497 
01498 inline
01499 WindowVertex::WindowVertex( double _x, double _y, double _tx, double _ty )
01500     : px( _x ), py( _y ), ox( _x ), oy( _y ), tx( _tx ), ty( _ty )
01501     {
01502     }
01503 
01504 inline
01505 double WindowVertex::x() const
01506     {
01507     return px;
01508     }
01509 
01510 inline
01511 double WindowVertex::y() const
01512     {
01513     return py;
01514     }
01515 
01516 inline
01517 double WindowVertex::originalX() const
01518     {
01519     return ox;
01520     }
01521 
01522 inline
01523 double WindowVertex::originalY() const
01524     {
01525     return oy;
01526     }
01527 
01528 inline
01529 double WindowVertex::textureX() const
01530     {
01531     return tx;
01532     }
01533 
01534 inline
01535 double WindowVertex::textureY() const
01536     {
01537     return ty;
01538     }
01539 
01540 inline
01541 void WindowVertex::move( double x, double y )
01542     {
01543     px = x;
01544     py = y;
01545     }
01546 
01547 inline
01548 void WindowVertex::setX( double x )
01549     {
01550     px = x;
01551     }
01552 
01553 inline
01554 void WindowVertex::setY( double y )
01555     {
01556     py = y;
01557     }
01558 
01559 /***************************************************************
01560  WindowQuad
01561 ***************************************************************/
01562 
01563 inline
01564 WindowQuad::WindowQuad( WindowQuadType t, int id )
01565     : quadType( t )
01566     , quadID( id )
01567     {
01568     }
01569 
01570 inline
01571 WindowVertex& WindowQuad::operator[]( int index )
01572     {
01573     assert( index >= 0 && index < 4 );
01574     return verts[ index ];
01575     }
01576 
01577 inline
01578 const WindowVertex& WindowQuad::operator[]( int index ) const
01579     {
01580     assert( index >= 0 && index < 4 );
01581     return verts[ index ];
01582     }
01583 
01584 inline
01585 WindowQuadType WindowQuad::type() const
01586     {
01587     assert( quadType != WindowQuadError );
01588     return quadType;
01589     }
01590 
01591 inline
01592 int WindowQuad::id() const
01593     {
01594     return quadID;
01595     }
01596 
01597 inline
01598 bool WindowQuad::decoration() const
01599     {
01600     assert( quadType != WindowQuadError );
01601     return quadType == WindowQuadDecoration;
01602     }
01603 
01604 inline
01605 bool WindowQuad::effect() const
01606     {
01607     assert( quadType != WindowQuadError );
01608     return quadType >= EFFECT_QUAD_TYPE_START;
01609     }
01610 
01611 inline
01612 bool WindowQuad::isTransformed() const
01613     {
01614     return !( verts[ 0 ].px == verts[ 0 ].ox && verts[ 0 ].py == verts[ 0 ].oy
01615         && verts[ 1 ].px == verts[ 1 ].ox && verts[ 1 ].py == verts[ 1 ].oy
01616         && verts[ 2 ].px == verts[ 2 ].ox && verts[ 2 ].py == verts[ 2 ].oy
01617         && verts[ 3 ].px == verts[ 3 ].ox && verts[ 3 ].py == verts[ 3 ].oy );
01618     }
01619 
01620 inline
01621 double WindowQuad::left() const
01622     {
01623     return qMin( verts[ 0 ].px, qMin( verts[ 1 ].px, qMin( verts[ 2 ].px, verts[ 3 ].px )));
01624     }
01625 
01626 inline
01627 double WindowQuad::right() const
01628     {
01629     return qMax( verts[ 0 ].px, qMax( verts[ 1 ].px, qMax( verts[ 2 ].px, verts[ 3 ].px )));
01630     }
01631 
01632 inline
01633 double WindowQuad::top() const
01634     {
01635     return qMin( verts[ 0 ].py, qMin( verts[ 1 ].py, qMin( verts[ 2 ].py, verts[ 3 ].py )));
01636     }
01637 
01638 inline
01639 double WindowQuad::bottom() const
01640     {
01641     return qMax( verts[ 0 ].py, qMax( verts[ 1 ].py, qMax( verts[ 2 ].py, verts[ 3 ].py )));
01642     }
01643 
01644 inline
01645 double WindowQuad::originalLeft() const
01646     {
01647     return verts[ 0 ].ox;
01648     }
01649 
01650 inline
01651 double WindowQuad::originalRight() const
01652     {
01653     return verts[ 2 ].ox;
01654     }
01655 
01656 inline
01657 double WindowQuad::originalTop() const
01658     {
01659     return verts[ 0 ].oy;
01660     }
01661 
01662 inline
01663 double WindowQuad::originalBottom() const
01664     {
01665     return verts[ 2 ].oy;
01666     }
01667 
01668 /***************************************************************
01669  Motion
01670 ***************************************************************/
01671 
01672 template <typename T>
01673 Motion<T>::Motion( T initial, double strength, double decay )
01674     :   m_value( initial )
01675     ,   m_target( initial )
01676     ,   m_velocity()
01677     ,   m_strength( strength )
01678     ,   m_decay( decay )
01679     {
01680     }
01681 
01682 template <typename T>
01683 Motion<T>::Motion( const Motion &other )
01684     :   m_value( other.value() )
01685     ,   m_target( other.target() )
01686     ,   m_velocity( other.velocity() )
01687     ,   m_strength( other.strength() )
01688     ,   m_decay( other.decay() )
01689     {
01690     }
01691 
01692 template <typename T>
01693 Motion<T>::~Motion()
01694     {
01695     }
01696 
01697 template <typename T>
01698 void Motion<T>::calculate( const int msec )
01699     {
01700     if( m_value == m_target && m_velocity == T() ) // At target and not moving
01701         return;
01702 
01703     double delta = qMin( 1.0, double( msec ) / 100.0 );
01704     T diff = m_target - m_value;
01705     T strength = diff * m_strength;
01706     m_velocity = m_decay * m_velocity * ( 1.0 - delta ) * ( 1.0 - delta )
01707                + strength * delta; // TODO/HACK: Need to work out correct formula
01708     m_value += m_velocity;
01709     }
01710 
01711 template <typename T>
01712 void Motion<T>::finish()
01713     {
01714     m_value = m_target;
01715     m_velocity = T();
01716     }
01717 
01718 } // namespace
01719 
01722 #endif // KWINEFFECTS_H

KWinLibraries

Skip menu "KWinLibraries"
  • Main Page
  • Modules
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

API Reference

Skip menu "API Reference"
  • KWin
  •   KWin Libraries
  • Libraries
  •   libkworkspace
  •   libsolidcontrol
  •   libtaskmanager
  • Plasma
  •   Animators
  •   Applets
  •   Engines
  • Solid Modules
Generated for API Reference by doxygen 1.5.7
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal