• Skip to content
  • Skip to link menu
KDE 4.4 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 Copyright (C) 2009 Lucas Murray <lmurray@undefinedfire.com>
00007 
00008 This program is free software; you can redistribute it and/or modify
00009 it under the terms of the GNU General Public License as published by
00010 the Free Software Foundation; either version 2 of the License, or
00011 (at your option) any later version.
00012 
00013 This program is distributed in the hope that it will be useful,
00014 but WITHOUT ANY WARRANTY; without even the implied warranty of
00015 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016 GNU General Public License for more details.
00017 
00018 You should have received a copy of the GNU General Public License
00019 along with this program.  If not, see <http://www.gnu.org/licenses/>.
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 108
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, // for the stupid default ctor
00180     WindowQuadContents,
00181     WindowQuadDecoration,
00182     EFFECT_QUAD_TYPE_START = 100 
00183     };
00184 
00188 KWIN_EXPORT inline
00189 QRect infiniteRegion()
00190     { // INT_MIN / 2 because width/height is used (INT_MIN+INT_MAX==-1)
00191     return QRect( INT_MIN / 2, INT_MIN / 2, INT_MAX, INT_MAX );
00192     }
00193 
00242 class KWIN_EXPORT Effect
00243     {
00244     public:
00246         // TODO: is that ok here?
00247         enum
00248         {
00252             PAINT_WINDOW_OPAQUE         = 1 << 0,
00256             PAINT_WINDOW_TRANSLUCENT    = 1 << 1,
00260             PAINT_WINDOW_TRANSFORMED    = 1 << 2,
00265             PAINT_SCREEN_REGION         = 1 << 3,
00270             PAINT_SCREEN_TRANSFORMED    = 1 << 4,
00275             PAINT_SCREEN_WITH_TRANSFORMED_WINDOWS = 1 << 5,
00279             PAINT_SCREEN_BACKGROUND_FIRST = 1 << 6,
00283             PAINT_DECORATION_ONLY = 1 << 7
00284         };
00285 
00289         Effect();
00293         virtual ~Effect();
00294 
00298         enum ReconfigureFlag
00299             {
00300             ReconfigureAll = 1 << 0 
00301             };
00302         Q_DECLARE_FLAGS( ReconfigureFlags, ReconfigureFlag )
00303 
00304         
00307         virtual void reconfigure( ReconfigureFlags flags );
00308 
00312         virtual void* proxy();
00313 
00322         virtual void prePaintScreen( ScreenPrePaintData& data, int time );
00330         virtual void paintScreen( int mask, QRegion region, ScreenPaintData& data );
00337         virtual void postPaintScreen();
00338 
00347         virtual void prePaintWindow( EffectWindow* w, WindowPrePaintData& data, int time );
00355         virtual void paintWindow( EffectWindow* w, int mask, QRegion region, WindowPaintData& data );
00362         virtual void postPaintWindow( EffectWindow* w );
00363 
00369         virtual void drawWindow( EffectWindow* w, int mask, QRegion region, WindowPaintData& data );
00370 
00375         virtual void buildQuads( EffectWindow* w, WindowQuadList& quadList );
00376 
00383         virtual QRect transformWindowDamage( EffectWindow* w, const QRect& r );
00384 
00386         virtual void windowUserMovedResized( EffectWindow* c, bool first, bool last );
00388         virtual void windowMoveResizeGeometryUpdate( EffectWindow* c, const QRect& geometry );
00389         virtual void windowOpacityChanged( EffectWindow* c, double old_opacity );
00390         virtual void windowAdded( EffectWindow* c );
00391         virtual void windowClosed( EffectWindow* c );
00392         virtual void windowDeleted( EffectWindow* c );
00393         virtual void windowActivated( EffectWindow* c );
00394         virtual void windowMinimized( EffectWindow* c );
00395         virtual void windowUnminimized( EffectWindow* c );
00396         virtual void clientGroupItemSwitched( EffectWindow* from, EffectWindow* to );
00397         virtual void clientGroupItemAdded( EffectWindow* from, EffectWindow* to ); // from merged with to
00398         virtual void clientGroupItemRemoved( EffectWindow* c, EffectWindow* group ); // c removed from group
00399         virtual void windowInputMouseEvent( Window w, QEvent* e );
00400         virtual void desktopChanged( int old );
00401         virtual void windowDamaged( EffectWindow* w, const QRect& r );
00402         virtual void windowGeometryShapeChanged( EffectWindow* w, const QRect& old );
00403         virtual void mouseChanged( const QPoint& pos, const QPoint& oldpos,
00404             Qt::MouseButtons buttons, Qt::MouseButtons oldbuttons,
00405             Qt::KeyboardModifiers modifiers, Qt::KeyboardModifiers oldmodifiers );
00406         virtual void grabbedKeyboardEvent( QKeyEvent* e );
00414         virtual void propertyNotify( EffectWindow* w, long atom );
00415 
00416         virtual void tabBoxAdded( int mode );
00417         virtual void tabBoxClosed();
00418         virtual void tabBoxUpdated();
00419         virtual void tabBoxKeyEvent( QKeyEvent* event );
00420         virtual bool borderActivated( ElectricBorder border );
00421 
00422         static int displayWidth();
00423         static int displayHeight();
00424         static QPoint cursorPos();
00425 
00435         // return type is intentionally double so that one can divide using it without losing data
00436         static double animationTime( const KConfigGroup& cfg, const QString& key, int defaultTime );
00441         static double animationTime( int defaultTime );
00447         static double interpolate(double x, double y, double a)
00448             {
00449             return x * (1 - a) + y * a;
00450             }
00454         static void setPositionTransformations( WindowPaintData& data, QRect& region, EffectWindow* w,
00455             const QRect& r, Qt::AspectRatioMode aspect );
00456     };
00457 
00458 
00468 #define KWIN_EFFECT( name, classname ) \
00469     extern "C" { \
00470         KWIN_EXPORT Effect* effect_create_kwin4_effect_##name() { return new classname; } \
00471         KWIN_EXPORT int effect_version_kwin4_effect_##name() { return KWIN_EFFECT_API_VERSION; } \
00472     }
00473 
00477 #define KWIN_EFFECT_SUPPORTED( name, function ) \
00478     extern "C" { \
00479         KWIN_EXPORT bool effect_supported_kwin4_effect_##name() { return function; } \
00480     }
00481 
00485 #define KWIN_EFFECT_CONFIG( name, classname ) \
00486     K_PLUGIN_FACTORY(EffectFactory, registerPlugin<classname>(#name);) \
00487     K_EXPORT_PLUGIN(EffectFactory("kcm_kwin4_effect_" #name))
00488 
00495 #define KWIN_EFFECT_CONFIG_MULTIPLE( name, singles ) \
00496     K_PLUGIN_FACTORY(EffectFactory, singles) \
00497     K_EXPORT_PLUGIN(EffectFactory("kcm_kwin4_effect_" #name))
00498 
00501 #define KWIN_EFFECT_CONFIG_SINGLE( name, classname ) \
00502     registerPlugin<classname>(#name);
00503 
00506 #define KWIN_EFFECT_CONFIG_FACTORY K_PLUGIN_FACTORY_DECLARATION(EffectFactory)
00507 
00508 
00519 class KWIN_EXPORT EffectsHandler
00520     {
00521     friend class Effect;
00522     public:
00523         EffectsHandler(CompositingType type);
00524         virtual ~EffectsHandler();
00525         // for use by effects
00526         virtual void prePaintScreen( ScreenPrePaintData& data, int time ) = 0;
00527         virtual void paintScreen( int mask, QRegion region, ScreenPaintData& data ) = 0;
00528         virtual void postPaintScreen() = 0;
00529         virtual void prePaintWindow( EffectWindow* w, WindowPrePaintData& data, int time ) = 0;
00530         virtual void paintWindow( EffectWindow* w, int mask, QRegion region, WindowPaintData& data ) = 0;
00531         virtual void postPaintWindow( EffectWindow* w ) = 0;
00532         virtual void drawWindow( EffectWindow* w, int mask, QRegion region, WindowPaintData& data ) = 0;
00533         virtual void buildQuads( EffectWindow* w, WindowQuadList& quadList ) = 0;
00534         virtual QRect transformWindowDamage( EffectWindow* w, const QRect& r );
00535         // Functions for handling input - e.g. when an Expose-like effect is shown, an input window
00536         // covering the whole screen is created and all mouse events will be intercepted by it.
00537         // The effect's windowInputMouseEvent() will get called with such events.
00538         virtual Window createInputWindow( Effect* e, int x, int y, int w, int h, const QCursor& cursor ) = 0;
00539         Window createInputWindow( Effect* e, const QRect& r, const QCursor& cursor );
00540         virtual Window createFullScreenInputWindow( Effect* e, const QCursor& cursor );
00541         virtual void destroyInputWindow( Window w ) = 0;
00542         virtual QPoint cursorPos() const = 0;
00543         virtual bool grabKeyboard( Effect* effect ) = 0;
00544         virtual void ungrabKeyboard() = 0;
00545 
00550         virtual void* getProxy( QString name ) = 0;
00551 
00552         // Mouse polling
00553         virtual void startMousePolling() = 0;
00554         virtual void stopMousePolling() = 0;
00555 
00556         virtual void checkElectricBorder(const QPoint &pos, Time time) = 0;
00557         virtual void reserveElectricBorder( ElectricBorder border ) = 0;
00558         virtual void unreserveElectricBorder( ElectricBorder border ) = 0;
00559         virtual void reserveElectricBorderSwitching( bool reserve ) = 0;
00560 
00561         // functions that allow controlling windows/desktop
00562         virtual void activateWindow( EffectWindow* c ) = 0;
00563         virtual EffectWindow* activeWindow() const = 0 ;
00564         virtual void moveWindow( EffectWindow* w, const QPoint& pos, bool snap = false, double snapAdjust = 1.0 ) = 0;
00565         virtual void windowToDesktop( EffectWindow* w, int desktop ) = 0;
00566         virtual void windowToScreen( EffectWindow* w, int screen ) = 0;
00567         virtual void setShowingDesktop( bool showing ) = 0;
00568 
00569         // Desktops
00573         virtual int currentDesktop() const = 0;
00577         virtual int numberOfDesktops() const = 0;
00581         virtual void setCurrentDesktop( int desktop ) = 0;
00585         virtual QSize desktopGridSize() const = 0;
00589         virtual int desktopGridWidth() const = 0;
00593         virtual int desktopGridHeight() const = 0;
00597         virtual int workspaceWidth() const = 0;
00601         virtual int workspaceHeight() const = 0;
00606         virtual int desktopAtCoords( QPoint coords ) const = 0;
00610         virtual QPoint desktopGridCoords( int id ) const = 0;
00614         virtual QPoint desktopCoords( int id ) const = 0;
00619         virtual int desktopAbove( int desktop = 0, bool wrap = true ) const = 0;
00624         virtual int desktopToRight( int desktop = 0, bool wrap = true ) const = 0;
00629         virtual int desktopBelow( int desktop = 0, bool wrap = true ) const = 0;
00634         virtual int desktopToLeft( int desktop = 0, bool wrap = true ) const = 0;
00638         virtual bool isDesktopLayoutDynamic() const = 0;
00643         virtual int addDesktop( QPoint coords ) = 0;
00648         virtual void deleteDesktop( int id ) = 0;
00649         virtual QString desktopName( int desktop ) const = 0;
00650         virtual bool optionRollOverDesktops() const = 0;
00651 
00652         virtual int activeScreen() const = 0; // Xinerama
00653         virtual int numScreens() const = 0; // Xinerama
00654         virtual int screenNumber( const QPoint& pos ) const = 0; // Xinerama
00655         virtual QRect clientArea( clientAreaOption, int screen, int desktop ) const = 0;
00656         virtual QRect clientArea( clientAreaOption, const EffectWindow* c ) const = 0;
00657         virtual QRect clientArea( clientAreaOption, const QPoint& p, int desktop ) const = 0;
00665         virtual double animationTimeFactor() const = 0;
00666         virtual WindowQuadType newWindowQuadType() = 0;
00667 
00668         virtual EffectWindow* findWindow( WId id ) const = 0;
00669         virtual EffectWindowList stackingOrder() const = 0;
00670         // window will be temporarily painted as if being at the top of the stack
00671         virtual void setElevatedWindow( EffectWindow* w, bool set ) = 0;
00672 
00673         virtual void setTabBoxWindow(EffectWindow*) = 0;
00674         virtual void setTabBoxDesktop(int) = 0;
00675         virtual EffectWindowList currentTabBoxWindowList() const = 0;
00676         virtual void refTabBox() = 0;
00677         virtual void unrefTabBox() = 0;
00678         virtual void closeTabBox() = 0;
00679         virtual QList< int > currentTabBoxDesktopList() const = 0;
00680         virtual int currentTabBoxDesktop() const = 0;
00681         virtual EffectWindow* currentTabBoxWindow() const = 0;
00682 
00683         virtual void setActiveFullScreenEffect( Effect* e ) = 0;
00684         virtual Effect* activeFullScreenEffect() const = 0;
00685 
00686         virtual void pushRenderTarget(GLRenderTarget* target) = 0;
00687         virtual GLRenderTarget* popRenderTarget() = 0;
00688 
00694         virtual void addRepaintFull() = 0;
00695         virtual void addRepaint( const QRect& r ) = 0;
00696         virtual void addRepaint( const QRegion& r ) = 0;
00697         virtual void addRepaint( int x, int y, int w, int h ) = 0;
00698 
00699         CompositingType compositingType() const;
00700         virtual unsigned long xrenderBufferPicture() = 0;
00701         bool saturationSupported() const;
00702         virtual void reconfigure() = 0;
00703 
00710         virtual void registerPropertyType( long atom, bool reg ) = 0;
00711 
00715         virtual bool hasDecorationShadows() const = 0;
00716 
00727         bool paintText( const QString& text, const QPoint& center, int maxwidth,
00728                         const QColor& color, const QFont& font = QFont() );
00733         bool paintText( const QString& text, const QRect& rect, const QColor& color,
00734                         const QFont& font = QFont(), const Qt::Alignment& alignment = Qt::AlignCenter );
00739         bool paintTextWithBackground( const QString& text, const QPoint& center, int maxwidth,
00740                                       const QColor& color, const QColor& bgcolor,
00741                                       const QFont& font = QFont() );
00746         bool paintTextWithBackground( const QString& text, const QRect& rect, const QColor& color,
00747                                       const QColor& bgcolor, const QFont& font = QFont(),
00748                                       const Qt::Alignment& alignment = Qt::AlignCenter );
00749 
00750 
00756         static void sendReloadMessage( const QString& effectname );
00760         static KConfigGroup effectConfig( const QString& effectname );
00761 
00762 
00763     protected:
00764         QVector< EffectPair > loaded_effects;
00765         QHash< QString, KLibrary* > effect_libraries;
00766         QList< InputWindowPair > input_windows;
00767         //QHash< QString, EffectFactory* > effect_factories;
00768         int current_paint_screen;
00769         int current_paint_window;
00770         int current_draw_window;
00771         int current_build_quads;
00772         int current_transform;
00773         CompositingType compositing_type;
00774     };
00775 
00776 
00783 class KWIN_EXPORT EffectWindow
00784     {
00785     public:
00787         enum
00788         {
00790             PAINT_DISABLED              = 1 << 0,
00792             PAINT_DISABLED_BY_DELETE    = 1 << 1,
00794             PAINT_DISABLED_BY_DESKTOP   = 1 << 2,
00796             PAINT_DISABLED_BY_MINIMIZE  = 1 << 3
00797         };
00798 
00799         EffectWindow();
00800         virtual ~EffectWindow();
00801 
00802         virtual void enablePainting( int reason ) = 0;
00803         virtual void disablePainting( int reason ) = 0;
00804         virtual bool isPaintingEnabled() = 0;
00805         virtual void addRepaint( const QRect& r ) = 0;
00806         virtual void addRepaint( int x, int y, int w, int h ) = 0;
00807         virtual void addRepaintFull() = 0;
00808 
00809         virtual void refWindow() = 0;
00810         virtual void unrefWindow() = 0;
00811         virtual bool isDeleted() const = 0;
00812 
00813         virtual bool isMinimized() const = 0;
00814         virtual double opacity() const = 0;
00815         virtual bool hasAlpha() const = 0;
00816 
00817         virtual bool isOnDesktop( int d ) const;
00818         virtual bool isOnCurrentDesktop() const;
00819         virtual bool isOnAllDesktops() const = 0;
00820         virtual int desktop() const = 0; // prefer isOnXXX()
00821 
00822         virtual int x() const = 0;
00823         virtual int y() const = 0;
00824         virtual int width() const = 0;
00825         virtual int height() const = 0;
00826         virtual QRect geometry() const = 0;
00827         virtual QRegion shape() const = 0;
00828         virtual int screen() const = 0;
00830         virtual bool hasOwnShape() const = 0; // only for shadow effect, for now
00831         virtual QPoint pos() const = 0;
00832         virtual QSize size() const = 0;
00833         virtual QRect rect() const = 0;
00834         virtual bool isMovable() const = 0;
00835         virtual bool isMovableAcrossScreens() const = 0;
00836         virtual bool isUserMove() const = 0;
00837         virtual bool isUserResize() const = 0;
00838         virtual QRect iconGeometry() const = 0;
00842         virtual QRect contentsRect() const = 0;
00843         bool hasDecoration() const;
00844         virtual QByteArray readProperty( long atom, long type, int format ) const = 0;
00845         virtual void deleteProperty( long atom ) const = 0;
00846 
00847         virtual QString caption() const = 0;
00848         virtual QPixmap icon() const = 0;
00849         virtual QString windowClass() const = 0;
00850         virtual QString windowRole() const = 0;
00851         virtual const EffectWindowGroup* group() const = 0;
00852 
00857         virtual bool isDesktop() const = 0;
00862         virtual bool isDock() const = 0;
00867         virtual bool isToolbar() const = 0;
00872         virtual bool isTopMenu() const = 0;
00877         virtual bool isMenu() const = 0;
00883         virtual bool isNormalWindow() const = 0; // normal as in 'NET::Normal or NET::Unknown non-transient'
00889         virtual bool isSpecialWindow() const = 0;
00894         virtual bool isDialog() const = 0;
00900         virtual bool isSplash() const = 0;
00905         virtual bool isUtility() const = 0;
00911         virtual bool isDropdownMenu() const = 0;
00916         virtual bool isPopupMenu() const = 0; // a context popup, not dropdown, not torn-off
00921         virtual bool isTooltip() const = 0;
00926         virtual bool isNotification() const = 0;
00931         virtual bool isComboBox() const = 0;
00936         virtual bool isDNDIcon() const = 0;
00941         virtual bool isManaged() const = 0; // whether it's managed or override-redirect
00945         virtual bool acceptsFocus() const = 0;
00949         virtual bool keepAbove() const = 0;
00950 
00951         virtual bool isModal() const = 0;
00952         virtual EffectWindow* findModal() = 0;
00953         virtual EffectWindowList mainWindows() const = 0;
00954 
00958         virtual WindowQuadList buildQuads( bool force = false ) const = 0;
00959 
00960         virtual void minimize() const = 0;
00961         virtual void unminimize() const = 0;
00962         virtual void closeWindow() const = 0;
00963 
00964         virtual bool visibleInClientGroup() const = 0;
00965     };
00966 
00967 class KWIN_EXPORT EffectWindowGroup
00968     {
00969     public:
00970         virtual ~EffectWindowGroup();
00971         virtual EffectWindowList members() const = 0;
00972     };
00973 
00974 class KWIN_EXPORT GlobalShortcutsEditor : public KShortcutsEditor
00975     {
00976     public:
00977         GlobalShortcutsEditor( QWidget *parent );
00978     };
00979 
00986 class KWIN_EXPORT WindowVertex
00987     {
00988     public:
00989         double x() const;
00990         double y() const;
00991         void move( double x, double y );
00992         void setX( double x );
00993         void setY( double y );
00994         double originalX() const;
00995         double originalY() const;
00996         double textureX() const;
00997         double textureY() const;
00998         WindowVertex();
00999         WindowVertex( double x, double y, double tx, double ty );
01000     private:
01001         friend class WindowQuad;
01002         friend class WindowQuadList;
01003         double px, py; // position
01004         double ox, oy; // origional position
01005         double tx, ty; // texture coords
01006     };
01007 
01013 // NOTE: This class expects the (original) vertices to be in the clockwise order starting from topleft.
01014 class KWIN_EXPORT WindowQuad
01015     {
01016     public:
01017         explicit WindowQuad( WindowQuadType type, int id = -1 );
01018         WindowQuad makeSubQuad( double x1, double y1, double x2, double y2 ) const;
01019         WindowVertex& operator[]( int index );
01020         const WindowVertex& operator[]( int index ) const;
01021         WindowQuadType type() const;
01022         int id() const;
01023         bool decoration() const;
01024         bool effect() const;
01025         double left() const;
01026         double right() const;
01027         double top() const;
01028         double bottom() const;
01029         double originalLeft() const;
01030         double originalRight() const;
01031         double originalTop() const;
01032         double originalBottom() const;
01033         bool smoothNeeded() const;
01034         bool isTransformed() const;
01035     private:
01036         friend class WindowQuadList;
01037         WindowVertex verts[ 4 ];
01038         WindowQuadType quadType; // 0 - contents, 1 - decoration
01039         int quadID;
01040     };
01041 
01042 class KWIN_EXPORT WindowQuadList
01043     : public QList< WindowQuad >
01044     {
01045     public:
01046         WindowQuadList splitAtX( double x ) const;
01047         WindowQuadList splitAtY( double y ) const;
01048         WindowQuadList makeGrid( int maxquadsize ) const;
01049         WindowQuadList makeRegularGrid( int xSubdivisions, int ySubdivisions ) const;
01050         WindowQuadList select( WindowQuadType type ) const;
01051         WindowQuadList filterOut( WindowQuadType type ) const;
01052         bool smoothNeeded() const;
01053         void makeArrays( float** vertices, float** texcoords ) const;
01054         bool isTransformed() const;
01055     };
01056 
01057 class KWIN_EXPORT WindowPrePaintData
01058     {
01059     public:
01060         int mask;
01064         QRegion paint;
01069         QRegion clip;
01070         WindowQuadList quads;
01075         void setTranslucent();
01079         void setTransformed();
01080     };
01081 
01082 class KWIN_EXPORT WindowPaintData
01083     {
01084     public:
01085         WindowPaintData( EffectWindow* w );
01091         double opacity;
01092         double contents_opacity;
01093         double decoration_opacity;
01094         double xScale;
01095         double yScale;
01096         double zScale;
01097         int xTranslate;
01098         int yTranslate;
01099         double zTranslate;
01108         double saturation;
01114         double brightness;
01115         WindowQuadList quads;
01119         GLShader* shader;
01120         RotationData* rotation;
01121     };
01122 
01123 class KWIN_EXPORT ScreenPaintData
01124     {
01125     public:
01126         ScreenPaintData();
01127         double xScale;
01128         double yScale;
01129         double zScale;
01130         int xTranslate;
01131         int yTranslate;
01132         double zTranslate;
01133         RotationData* rotation;
01134     };
01135 
01136 class KWIN_EXPORT ScreenPrePaintData
01137     {
01138     public:
01139         int mask;
01140         QRegion paint;
01141     };
01142 
01143 class KWIN_EXPORT RotationData
01144     {
01145     public:
01146         RotationData();
01147         enum RotationAxis
01148             {
01149             XAxis,
01150             YAxis,
01151             ZAxis
01152             };
01153         RotationAxis axis;
01154         float angle;
01155         float xRotationPoint;
01156         float yRotationPoint;
01157         float zRotationPoint;
01158     };
01159 
01169 class KWIN_EXPORT PaintClipper
01170     {
01171     public:
01175         PaintClipper( const QRegion& allowed_area );
01179         ~PaintClipper();
01184         static void push( const QRegion& allowed_area );
01188         static void pop( const QRegion& allowed_area );
01192         static bool clip();
01197         static QRegion paintArea();
01208         class KWIN_EXPORT Iterator
01209             {
01210             public:
01211                 Iterator();
01212                 ~Iterator();
01213                 bool isDone();
01214                 void next();
01215                 QRect boundingRect() const;
01216             private:
01217                 struct Data;
01218                 Data* data;
01219             };
01220     private:
01221         QRegion area;
01222         static QStack< QRegion >* areas;
01223     };
01224 
01225 
01268 class KWIN_EXPORT TimeLine
01269     {
01270 
01271     //Q_ENUMS( CurveShape ) // Requires Q_OBJECT
01272 
01273     public:
01279         enum CurveShape
01280         {
01281             EaseInCurve = 0,
01282             EaseOutCurve,
01283             EaseInOutCurve,
01284             LinearCurve,
01285             SineCurve
01286         };
01287 
01294         explicit TimeLine(const int duration = 0);
01295 
01300         TimeLine(const TimeLine &other);
01304         ~TimeLine();
01308         int duration() const;
01312         void setDuration(const int msec);
01320         double value() const;
01326         double valueForTime(const int msec) const;
01331         int time() const;
01336         double progress() const;
01340         void addProgress(const double progress);
01345         void addTime(const int msec);
01351         void removeTime(const int msec);
01358         void setProgress(const double progress);
01364         void setCurveShape(CurveShape curveShape);
01369         //void setCurveShape(CurveShape curveShape);
01370 
01371     private:
01372         QTimeLine* m_TimeLine;
01373         int m_Time;
01374         double m_Progress;
01375         int m_Duration;
01376         CurveShape m_CurveShape;
01377         //Q_DISABLE_COPY(TimeLine)
01378     };
01379 
01383 template <typename T>
01384 class KWIN_EXPORT Motion
01385     {
01386     public:
01393         explicit Motion( T initial, double strength, double smoothness );
01398         Motion( const Motion<T> &other );
01399         ~Motion();
01400 
01401         inline T value() const { return m_value; }
01402         inline void setValue( const T value ) { m_value = value; }
01403         inline T target() const { return m_target; }
01404         inline void setTarget( const T target ) { m_target = target; }
01405         inline T velocity() const { return m_velocity; }
01406         inline void setVelocity( const T velocity ) { m_velocity = velocity; }
01407 
01408         inline double strength() const { return m_strength; }
01409         inline void setStrength( const double strength ) { m_strength = strength; }
01410         inline double smoothness() const { return m_smoothness; }
01411         inline void setSmoothness( const double smoothness ) { m_smoothness = smoothness; }
01412 
01416         inline T distance() const { return m_target - m_value; }
01417 
01422         void calculate( const int msec );
01427         void finish();
01428 
01429     private:
01430         T m_value;
01431 
01432         T m_target;
01433         T m_velocity;
01434         double m_strength;
01435         double m_smoothness;
01436     };
01437 
01445 class KWIN_EXPORT Motion1D : public Motion<double>
01446     {
01447     public:
01448         explicit Motion1D( double initial = 0.0, double strength = 0.08, double smoothness = 4.0 );
01449         Motion1D( const Motion1D &other );
01450         ~Motion1D();
01451     };
01452 
01460 class KWIN_EXPORT Motion2D : public Motion<QPointF>
01461     {
01462     public:
01463         explicit Motion2D( QPointF initial = QPointF(), double strength = 0.08, double smoothness = 4.0 );
01464         Motion2D( const Motion2D &other );
01465         ~Motion2D();
01466     };
01467 
01480 class KWIN_EXPORT WindowMotionManager
01481     {
01482     public:
01486         explicit WindowMotionManager( bool useGlobalAnimationModifier = true );
01487         ~WindowMotionManager();
01488 
01492         void manage( EffectWindow *w );
01496         inline void manage( EffectWindowList list )
01497             {
01498             for( int i = 0; i < list.size(); i++ )
01499                 manage( list.at( i ));
01500             }
01505         void unmanage( EffectWindow *w );
01510         void unmanageAll();
01517         void calculate( int time );
01525         void apply( EffectWindow *w, WindowPaintData &data );
01531         void reset();
01536         void reset( EffectWindow *w );
01537 
01544         void moveWindow( EffectWindow *w, QPoint target, double scale = 1.0, double yScale = 0.0 );
01551         inline void moveWindow( EffectWindow *w, QRect target )
01552             {
01553             // TODO: Scale might be slightly different in the comparison due to rounding
01554             moveWindow( w, target.topLeft(),
01555                 target.width() / double( w->width() ), target.height() / double( w->height() ));
01556             }
01557 
01562         QRectF transformedGeometry( EffectWindow *w ) const;
01567         QRectF targetGeometry( EffectWindow *w ) const;
01574         EffectWindow* windowAtPoint( QPoint point, bool useStackingOrder = true ) const;
01575 
01579         inline EffectWindowList managedWindows() const { return m_managedWindows.keys(); }
01584         inline bool isManaging( EffectWindow *w ) { return m_managedWindows.contains( w ); }
01589         inline bool managingWindows() { return !m_managedWindows.empty(); }
01595         inline bool areWindowsMoving() { return m_movingWindows > 0; }
01596 
01597     private:
01598         bool m_useGlobalAnimationModifier;
01599         struct WindowMotion
01600             { // TODO: Rotation, etc?
01601             Motion2D translation; // Absolute position
01602             Motion2D scale; // xScale and yScale
01603             };
01604         QHash<EffectWindow*, WindowMotion> m_managedWindows;
01605         uint m_movingWindows;
01606     };
01607 
01616 class KWIN_EXPORT EffectFrame : public QObject
01617     {
01618     Q_OBJECT
01619 
01620     public:
01621         enum Style
01622             {
01623             None, 
01624             Unstyled, 
01625             Styled 
01626             };
01627 
01634         explicit EffectFrame( Style style, bool staticSize = true, QPoint position = QPoint( -1, -1 ),
01635             Qt::Alignment alignment = Qt::AlignCenter );
01636         ~EffectFrame();
01637 
01642         void free();
01643 
01647         void render( QRegion region = infiniteRegion(), double opacity = 1.0, double frameOpacity = 1.0 );
01648 
01649         void setPosition( const QPoint& point );
01654         inline void setAlignment( Qt::Alignment alignment )
01655             { m_alignment = alignment; }; // Doesn't change geometry
01656         void setGeometry( const QRect& geometry, bool force = false );
01657         inline QRect geometry() const // Inner/contents geometry
01658             { return m_geometry; };
01659 
01660         void setText( const QString& text );
01661         inline QString text() const
01662             { return m_text; };
01663         void setFont( const QFont& font );
01664         inline QFont font() const
01665             { return m_font; };
01669         void setIcon( const QPixmap& icon );
01670         inline QPixmap icon() const
01671             { return m_icon; };
01672         void setIconSize( const QSize& size );
01673         inline QSize iconSize() const
01674             { return m_iconSize; };
01675 
01679         static QColor styledTextColor();
01680 
01681     private Q_SLOTS:
01682         void plasmaThemeChanged();
01683 
01684     private:
01685         Q_DISABLE_COPY( EffectFrame ) // As we need to use Qt slots we cannot copy this class
01686 
01687         void autoResize(); // Auto-resize if not a static size
01688         void updateTexture(); // Update OpenGL styled frame texture
01689         void updateTextTexture(); // Update OpenGL text texture
01690         void updatePicture(); // Update XRender styled frame picture
01691         void updateTextPicture(); // Update XRender text picture
01692 
01693         Style m_style;
01694         Plasma::FrameSvg m_frame;
01695         GLTexture* m_texture;
01696         GLTexture* m_textTexture;
01697         XRenderPicture* m_picture;
01698         XRenderPicture* m_textPicture;
01699 
01700         // Position
01701         bool m_static;
01702         QPoint m_point;
01703         Qt::Alignment m_alignment;
01704         QRect m_geometry;
01705 
01706         // Contents
01707         QString m_text;
01708         QFont m_font;
01709         QPixmap m_icon;
01710         QSize m_iconSize;
01711 
01712         static GLTexture* m_unstyledTexture;
01713         static void updateUnstyledTexture(); // Update OpenGL unstyled frame texture
01714     };
01715 
01719 extern KWIN_EXPORT EffectsHandler* effects;
01720 
01721 /***************************************************************
01722  EffectsHandler
01723 ***************************************************************/
01724 
01725 inline
01726 bool EffectsHandler::paintText( const QString& text, const QPoint& center, int maxwidth,
01727         const QColor& color, const QFont& font )
01728 {
01729     return paintText( text, QRect( center.x() - maxwidth / 2, center.y() - 5000, maxwidth, 10000 ),
01730         color, font, Qt::AlignCenter );
01731 }
01732 
01733 inline
01734 bool EffectsHandler::paintTextWithBackground( const QString& text, const QPoint& center, int maxwidth,
01735         const QColor& color, const QColor& bgcolor, const QFont& font )
01736 {
01737     return paintTextWithBackground( text,
01738         QRect( center.x() - maxwidth / 2, center.y() - 5000, maxwidth, 10000 ),
01739         color, bgcolor, font, Qt::AlignCenter );
01740 }
01741 
01742 /***************************************************************
01743  WindowVertex
01744 ***************************************************************/
01745 
01746 inline
01747 WindowVertex::WindowVertex()
01748     : px( 0 ), py( 0 ), tx( 0 ), ty( 0 )
01749     {
01750     }
01751 
01752 inline
01753 WindowVertex::WindowVertex( double _x, double _y, double _tx, double _ty )
01754     : px( _x ), py( _y ), ox( _x ), oy( _y ), tx( _tx ), ty( _ty )
01755     {
01756     }
01757 
01758 inline
01759 double WindowVertex::x() const
01760     {
01761     return px;
01762     }
01763 
01764 inline
01765 double WindowVertex::y() const
01766     {
01767     return py;
01768     }
01769 
01770 inline
01771 double WindowVertex::originalX() const
01772     {
01773     return ox;
01774     }
01775 
01776 inline
01777 double WindowVertex::originalY() const
01778     {
01779     return oy;
01780     }
01781 
01782 inline
01783 double WindowVertex::textureX() const
01784     {
01785     return tx;
01786     }
01787 
01788 inline
01789 double WindowVertex::textureY() const
01790     {
01791     return ty;
01792     }
01793 
01794 inline
01795 void WindowVertex::move( double x, double y )
01796     {
01797     px = x;
01798     py = y;
01799     }
01800 
01801 inline
01802 void WindowVertex::setX( double x )
01803     {
01804     px = x;
01805     }
01806 
01807 inline
01808 void WindowVertex::setY( double y )
01809     {
01810     py = y;
01811     }
01812 
01813 /***************************************************************
01814  WindowQuad
01815 ***************************************************************/
01816 
01817 inline
01818 WindowQuad::WindowQuad( WindowQuadType t, int id )
01819     : quadType( t )
01820     , quadID( id )
01821     {
01822     }
01823 
01824 inline
01825 WindowVertex& WindowQuad::operator[]( int index )
01826     {
01827     assert( index >= 0 && index < 4 );
01828     return verts[ index ];
01829     }
01830 
01831 inline
01832 const WindowVertex& WindowQuad::operator[]( int index ) const
01833     {
01834     assert( index >= 0 && index < 4 );
01835     return verts[ index ];
01836     }
01837 
01838 inline
01839 WindowQuadType WindowQuad::type() const
01840     {
01841     assert( quadType != WindowQuadError );
01842     return quadType;
01843     }
01844 
01845 inline
01846 int WindowQuad::id() const
01847     {
01848     return quadID;
01849     }
01850 
01851 inline
01852 bool WindowQuad::decoration() const
01853     {
01854     assert( quadType != WindowQuadError );
01855     return quadType == WindowQuadDecoration;
01856     }
01857 
01858 inline
01859 bool WindowQuad::effect() const
01860     {
01861     assert( quadType != WindowQuadError );
01862     return quadType >= EFFECT_QUAD_TYPE_START;
01863     }
01864 
01865 inline
01866 bool WindowQuad::isTransformed() const
01867     {
01868     return !( verts[ 0 ].px == verts[ 0 ].ox && verts[ 0 ].py == verts[ 0 ].oy
01869         && verts[ 1 ].px == verts[ 1 ].ox && verts[ 1 ].py == verts[ 1 ].oy
01870         && verts[ 2 ].px == verts[ 2 ].ox && verts[ 2 ].py == verts[ 2 ].oy
01871         && verts[ 3 ].px == verts[ 3 ].ox && verts[ 3 ].py == verts[ 3 ].oy );
01872     }
01873 
01874 inline
01875 double WindowQuad::left() const
01876     {
01877     return qMin( verts[ 0 ].px, qMin( verts[ 1 ].px, qMin( verts[ 2 ].px, verts[ 3 ].px )));
01878     }
01879 
01880 inline
01881 double WindowQuad::right() const
01882     {
01883     return qMax( verts[ 0 ].px, qMax( verts[ 1 ].px, qMax( verts[ 2 ].px, verts[ 3 ].px )));
01884     }
01885 
01886 inline
01887 double WindowQuad::top() const
01888     {
01889     return qMin( verts[ 0 ].py, qMin( verts[ 1 ].py, qMin( verts[ 2 ].py, verts[ 3 ].py )));
01890     }
01891 
01892 inline
01893 double WindowQuad::bottom() const
01894     {
01895     return qMax( verts[ 0 ].py, qMax( verts[ 1 ].py, qMax( verts[ 2 ].py, verts[ 3 ].py )));
01896     }
01897 
01898 inline
01899 double WindowQuad::originalLeft() const
01900     {
01901     return verts[ 0 ].ox;
01902     }
01903 
01904 inline
01905 double WindowQuad::originalRight() const
01906     {
01907     return verts[ 2 ].ox;
01908     }
01909 
01910 inline
01911 double WindowQuad::originalTop() const
01912     {
01913     return verts[ 0 ].oy;
01914     }
01915 
01916 inline
01917 double WindowQuad::originalBottom() const
01918     {
01919     return verts[ 2 ].oy;
01920     }
01921 
01922 /***************************************************************
01923  Motion
01924 ***************************************************************/
01925 
01926 template <typename T>
01927 Motion<T>::Motion( T initial, double strength, double smoothness )
01928     :   m_value( initial )
01929     ,   m_target( initial )
01930     ,   m_velocity()
01931     ,   m_strength( strength )
01932     ,   m_smoothness( smoothness )
01933     {
01934     }
01935 
01936 template <typename T>
01937 Motion<T>::Motion( const Motion &other )
01938     :   m_value( other.value() )
01939     ,   m_target( other.target() )
01940     ,   m_velocity( other.velocity() )
01941     ,   m_strength( other.strength() )
01942     ,   m_smoothness( other.smoothness() )
01943     {
01944     }
01945 
01946 template <typename T>
01947 Motion<T>::~Motion()
01948     {
01949     }
01950 
01951 template <typename T>
01952 void Motion<T>::calculate( const int msec )
01953     {
01954     if( m_value == m_target && m_velocity == T() ) // At target and not moving
01955         return;
01956 
01957     // Poor man's time independent calculation
01958     int steps = qMax( 1, msec / 5 );
01959     for( int i = 0; i < steps; i++ )
01960         {
01961         T diff = m_target - m_value;
01962         T strength = diff * m_strength;
01963         m_velocity = ( m_smoothness * m_velocity + strength ) / ( m_smoothness + 1.0 );
01964         m_value += m_velocity;
01965         }
01966     }
01967 
01968 template <typename T>
01969 void Motion<T>::finish()
01970     {
01971     m_value = m_target;
01972     m_velocity = T();
01973     }
01974 
01975 } // namespace
01976 
01979 #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
  • System Settings
  •   SystemSettingsView
Generated for API Reference by doxygen 1.5.9-20090814
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