00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef KWINEFFECTS_H
00022 #define KWINEFFECTS_H
00023
00024 #include <kwinconfig.h>
00025 #include <kwinglobals.h>
00026
00027 #include <QtCore/QPair>
00028 #include <QtCore/QRect>
00029 #include <QtGui/QRegion>
00030 #include <QtGui/QFont>
00031
00032 #include <QtCore/QVector>
00033 #include <QtCore/QList>
00034 #include <QtCore/QHash>
00035
00036 #include <KDE/KPluginFactory>
00037 #include <KDE/KShortcutsEditor>
00038
00039 #include <assert.h>
00040
00044 #define KWIN_EFFECT_API_MAKE_VERSION( major, minor ) (( major ) << 8 | ( minor ))
00045 #define KWIN_EFFECT_API_VERSION_MAJOR 0
00046 #define KWIN_EFFECT_API_VERSION_MINOR 6
00047 #define KWIN_EFFECT_API_VERSION KWIN_EFFECT_API_MAKE_VERSION( \
00048 KWIN_EFFECT_API_VERSION_MAJOR, KWIN_EFFECT_API_VERSION_MINOR )
00049
00050 class KLibrary;
00051 class KConfigGroup;
00052 class KActionCollection;
00053 class QKeyEvent;
00054
00057 namespace KWin
00058 {
00059
00060
00061 class EffectWindow;
00062 class EffectWindowGroup;
00063 class Effect;
00064 class WindowQuad;
00065 class GLRenderTarget;
00066 class GLShader;
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
00126 class KWIN_EXPORT Effect
00127 {
00128 public:
00130
00131 enum
00132 {
00136 PAINT_WINDOW_OPAQUE = 1 << 0,
00140 PAINT_WINDOW_TRANSLUCENT = 1 << 1,
00144 PAINT_WINDOW_TRANSFORMED = 1 << 2,
00149 PAINT_SCREEN_REGION = 1 << 3,
00154 PAINT_SCREEN_TRANSFORMED = 1 << 4,
00159 PAINT_SCREEN_WITH_TRANSFORMED_WINDOWS = 1 << 5,
00163 PAINT_SCREEN_BACKGROUND_FIRST = 1 << 6
00164 };
00165
00169 Effect();
00173 virtual ~Effect();
00174
00183 virtual void prePaintScreen( ScreenPrePaintData& data, int time );
00191 virtual void paintScreen( int mask, QRegion region, ScreenPaintData& data );
00198 virtual void postPaintScreen();
00199
00208 virtual void prePaintWindow( EffectWindow* w, WindowPrePaintData& data, int time );
00216 virtual void paintWindow( EffectWindow* w, int mask, QRegion region, WindowPaintData& data );
00223 virtual void postPaintWindow( EffectWindow* w );
00224
00230 virtual void drawWindow( EffectWindow* w, int mask, QRegion region, WindowPaintData& data );
00237 virtual QRect transformWindowDamage( EffectWindow* w, const QRect& r );
00238
00240 virtual void windowUserMovedResized( EffectWindow* c, bool first, bool last );
00241 virtual void windowOpacityChanged( EffectWindow* c, double old_opacity );
00242 virtual void windowAdded( EffectWindow* c );
00243 virtual void windowClosed( EffectWindow* c );
00244 virtual void windowDeleted( EffectWindow* c );
00245 virtual void windowActivated( EffectWindow* c );
00246 virtual void windowMinimized( EffectWindow* c );
00247 virtual void windowUnminimized( EffectWindow* c );
00248 virtual void windowInputMouseEvent( Window w, QEvent* e );
00249 virtual void desktopChanged( int old );
00250 virtual void windowDamaged( EffectWindow* w, const QRect& r );
00251 virtual void windowGeometryShapeChanged( EffectWindow* w, const QRect& old );
00252 virtual void mouseChanged( const QPoint& pos, const QPoint& oldpos,
00253 Qt::MouseButtons buttons, Qt::MouseButtons oldbuttons,
00254 Qt::KeyboardModifiers modifiers, Qt::KeyboardModifiers oldmodifiers );
00255 virtual void grabbedKeyboardEvent( QKeyEvent* e );
00263 virtual void propertyNotify( EffectWindow* w, long atom );
00264
00265 virtual void tabBoxAdded( int mode );
00266 virtual void tabBoxClosed();
00267 virtual void tabBoxUpdated();
00268 virtual bool borderActivated( ElectricBorder border );
00269
00270 static int displayWidth();
00271 static int displayHeight();
00272 static QPoint cursorPos();
00273
00279 static double interpolate(double x, double y, double a)
00280 {
00281 return x * (1 - a) + y * a;
00282 }
00286 static void setPositionTransformations( WindowPaintData& data, QRect& region, EffectWindow* w,
00287 const QRect& r, Qt::AspectRatioMode aspect );
00288 };
00289
00290
00300 #define KWIN_EFFECT( name, classname ) \
00301 extern "C" { \
00302 KWIN_EXPORT Effect* effect_create_kwin4_effect_##name() { return new classname; } \
00303 KWIN_EXPORT int effect_version_kwin4_effect_##name() { return KWIN_EFFECT_API_VERSION; } \
00304 }
00305
00309 #define KWIN_EFFECT_SUPPORTED( name, function ) \
00310 extern "C" { \
00311 KWIN_EXPORT bool effect_supported_kwin4_effect_##name() { return function; } \
00312 }
00313
00317 #define KWIN_EFFECT_CONFIG( name, classname ) \
00318 K_PLUGIN_FACTORY(name##_factory, registerPlugin<classname>();) \
00319 K_EXPORT_PLUGIN(name##_factory("kcm_kwineffect_" #name))
00320
00324 #define KWIN_EFFECT_CONFIG_FACTORY K_PLUGIN_FACTORY_DECLARATION(EffectFactory)
00325
00326
00337 class KWIN_EXPORT EffectsHandler
00338 {
00339 friend class Effect;
00340 public:
00341 EffectsHandler(CompositingType type);
00342 virtual ~EffectsHandler();
00343
00344 virtual void prePaintScreen( ScreenPrePaintData& data, int time ) = 0;
00345 virtual void paintScreen( int mask, QRegion region, ScreenPaintData& data ) = 0;
00346 virtual void postPaintScreen() = 0;
00347 virtual void prePaintWindow( EffectWindow* w, WindowPrePaintData& data, int time ) = 0;
00348 virtual void paintWindow( EffectWindow* w, int mask, QRegion region, WindowPaintData& data ) = 0;
00349 virtual void postPaintWindow( EffectWindow* w ) = 0;
00350 virtual void drawWindow( EffectWindow* w, int mask, QRegion region, WindowPaintData& data ) = 0;
00351 virtual QRect transformWindowDamage( EffectWindow* w, const QRect& r );
00352
00353
00354
00355 virtual Window createInputWindow( Effect* e, int x, int y, int w, int h, const QCursor& cursor ) = 0;
00356 Window createInputWindow( Effect* e, const QRect& r, const QCursor& cursor );
00357 virtual Window createFullScreenInputWindow( Effect* e, const QCursor& cursor );
00358 virtual void destroyInputWindow( Window w ) = 0;
00359 virtual QPoint cursorPos() const = 0;
00360 virtual bool grabKeyboard( Effect* effect ) = 0;
00361 virtual void ungrabKeyboard() = 0;
00362
00363 virtual void checkElectricBorder(const QPoint &pos, Time time) = 0;
00364 virtual void reserveElectricBorder( ElectricBorder border ) = 0;
00365 virtual void unreserveElectricBorder( ElectricBorder border ) = 0;
00366 virtual void reserveElectricBorderSwitching( bool reserve ) = 0;
00367
00368
00369 virtual void activateWindow( EffectWindow* c ) = 0;
00370 virtual EffectWindow* activeWindow() const = 0 ;
00371 virtual void moveWindow( EffectWindow* w, const QPoint& pos ) = 0;
00372 virtual void windowToDesktop( EffectWindow* w, int desktop ) = 0;
00373
00374 virtual int currentDesktop() const = 0;
00375 virtual int numberOfDesktops() const = 0;
00376 virtual void setCurrentDesktop( int desktop ) = 0;
00377 virtual QString desktopName( int desktop ) const = 0;
00378 virtual int activeScreen() const = 0;
00379 virtual QRect clientArea( clientAreaOption, int screen, int desktop ) const = 0;
00380 virtual QRect clientArea( clientAreaOption, const EffectWindow* c ) const = 0;
00381 virtual QRect clientArea( clientAreaOption, const QPoint& p, int desktop ) const = 0;
00382 virtual void calcDesktopLayout(int* x, int* y, Qt::Orientation* orientation) const = 0;
00383 virtual bool optionRollOverDesktops() const = 0;
00384 virtual int desktopToLeft( int desktop, bool wrap ) const = 0;
00385 virtual int desktopToRight( int desktop, bool wrap ) const = 0;
00386 virtual int desktopUp( int desktop, bool wrap ) const = 0;
00387 virtual int desktopDown( int desktop, bool wrap ) const = 0;
00388
00389 virtual EffectWindow* findWindow( WId id ) const = 0;
00390 virtual EffectWindowList stackingOrder() const = 0;
00391
00392 virtual void setElevatedWindow( EffectWindow* w, bool set ) = 0;
00393
00394 virtual void setTabBoxWindow(EffectWindow*) = 0;
00395 virtual void setTabBoxDesktop(int) = 0;
00396 virtual EffectWindowList currentTabBoxWindowList() const = 0;
00397 virtual void refTabBox() = 0;
00398 virtual void unrefTabBox() = 0;
00399 virtual void closeTabBox() = 0;
00400 virtual QList< int > currentTabBoxDesktopList() const = 0;
00401 virtual int currentTabBoxDesktop() const = 0;
00402 virtual EffectWindow* currentTabBoxWindow() const = 0;
00403
00404 virtual void setActiveFullScreenEffect( Effect* e ) = 0;
00405 virtual Effect* activeFullScreenEffect() const = 0;
00406
00407 virtual void pushRenderTarget(GLRenderTarget* target) = 0;
00408 virtual GLRenderTarget* popRenderTarget() = 0;
00409
00415 virtual void addRepaintFull() = 0;
00416 virtual void addRepaint( const QRect& r ) = 0;
00417 virtual void addRepaint( int x, int y, int w, int h ) = 0;
00418
00419 CompositingType compositingType() const;
00420 virtual unsigned long xrenderBufferPicture() = 0;
00421 virtual void reconfigure() = 0;
00422
00429 virtual void registerPropertyType( long atom, bool reg ) = 0;
00430
00439 bool paintText( const QString& text, const QPoint& center, int maxwidth,
00440 const QColor& color, const QFont& font = QFont() );
00441 bool paintTextWithBackground( const QString& text, const QPoint& center, int maxwidth,
00442 const QColor& color, const QColor& bgcolor,
00443 const QFont& font = QFont() );
00444
00445
00451 static void sendReloadMessage( const QString& effectname );
00455 static KConfigGroup effectConfig( const QString& effectname );
00456
00457
00458 protected:
00459 QVector< EffectPair > loaded_effects;
00460 QHash< QString, KLibrary* > effect_libraries;
00461 QList< InputWindowPair > input_windows;
00462
00463 int current_paint_screen;
00464 int current_paint_window;
00465 int current_draw_window;
00466 int current_transform;
00467 CompositingType compositing_type;
00468 };
00469
00470
00477 class KWIN_EXPORT EffectWindow
00478 {
00479 public:
00481 enum
00482 {
00484 PAINT_DISABLED = 1 << 0,
00486 PAINT_DISABLED_BY_DELETE = 1 << 1,
00488 PAINT_DISABLED_BY_DESKTOP = 1 << 2,
00490 PAINT_DISABLED_BY_MINIMIZE = 1 << 3
00491 };
00492
00493 EffectWindow();
00494 virtual ~EffectWindow();
00495
00496 virtual void enablePainting( int reason ) = 0;
00497 virtual void disablePainting( int reason ) = 0;
00498 virtual bool isPaintingEnabled() = 0;
00499 virtual void addRepaint( const QRect& r ) = 0;
00500 virtual void addRepaint( int x, int y, int w, int h ) = 0;
00501 virtual void addRepaintFull() = 0;
00502
00503 virtual void refWindow() = 0;
00504 virtual void unrefWindow() = 0;
00505 virtual bool isDeleted() const = 0;
00506
00507 virtual bool isMinimized() const = 0;
00508 virtual double opacity() const = 0;
00509
00510 virtual bool isOnDesktop( int d ) const;
00511 virtual bool isOnCurrentDesktop() const;
00512 virtual bool isOnAllDesktops() const = 0;
00513 virtual int desktop() const = 0;
00514
00515 virtual int x() const = 0;
00516 virtual int y() const = 0;
00517 virtual int width() const = 0;
00518 virtual int height() const = 0;
00519 virtual QRect geometry() const = 0;
00520 virtual QRegion shape() const = 0;
00522 virtual bool hasOwnShape() const = 0;
00523 virtual QPoint pos() const = 0;
00524 virtual QSize size() const = 0;
00525 virtual QRect rect() const = 0;
00526 virtual bool isMovable() const = 0;
00527 virtual bool isUserMove() const = 0;
00528 virtual bool isUserResize() const = 0;
00529 virtual QRect iconGeometry() const = 0;
00533 virtual QRect contentsRect() const = 0;
00534 bool hasDecoration() const;
00535 virtual QByteArray readProperty( long atom, long type, int format ) const = 0;
00536
00537 virtual QString caption() const = 0;
00538 virtual QPixmap icon() const = 0;
00539 virtual QString windowClass() const = 0;
00540 virtual QString windowRole() const = 0;
00541 virtual const EffectWindowGroup* group() const = 0;
00542
00543 virtual bool isDesktop() const = 0;
00544 virtual bool isDock() const = 0;
00545 virtual bool isToolbar() const = 0;
00546 virtual bool isTopMenu() const = 0;
00547 virtual bool isMenu() const = 0;
00548 virtual bool isNormalWindow() const = 0;
00549 virtual bool isSpecialWindow() const = 0;
00550 virtual bool isDialog() const = 0;
00551 virtual bool isSplash() const = 0;
00552 virtual bool isUtility() const = 0;
00553 virtual bool isDropdownMenu() const = 0;
00554 virtual bool isPopupMenu() const = 0;
00555 virtual bool isTooltip() const = 0;
00556 virtual bool isNotification() const = 0;
00557 virtual bool isComboBox() const = 0;
00558 virtual bool isDNDIcon() const = 0;
00559 virtual bool isManaged() const = 0;
00560
00561 virtual bool isModal() const = 0;
00562 virtual EffectWindow* findModal() = 0;
00563 virtual EffectWindowList mainWindows() const = 0;
00564
00565
00566 virtual WindowQuadList buildQuads() const = 0;
00567 };
00568
00569 class KWIN_EXPORT EffectWindowGroup
00570 {
00571 public:
00572 virtual ~EffectWindowGroup();
00573 virtual EffectWindowList members() const = 0;
00574 };
00575
00576 class KWIN_EXPORT GlobalShortcutsEditor : public KShortcutsEditor
00577 {
00578 public:
00579 GlobalShortcutsEditor( QWidget *parent );
00580 };
00581
00588 class KWIN_EXPORT WindowVertex
00589 {
00590 public:
00591 double x() const;
00592 double y() const;
00593 void move( double x, double y );
00594 void setX( double x );
00595 void setY( double y );
00596 double originalX() const;
00597 double originalY() const;
00598 WindowVertex();
00599 WindowVertex( double x, double y, double tx, double ty );
00600 private:
00601 friend class WindowQuad;
00602 friend class WindowQuadList;
00603 double px, py;
00604 double ox, oy;
00605 double tx, ty;
00606 };
00607
00608 enum WindowQuadType
00609 {
00610 WindowQuadError,
00611 WindowQuadContents,
00612 WindowQuadDecoration
00613 };
00614
00620
00621 class KWIN_EXPORT WindowQuad
00622 {
00623 public:
00624 explicit WindowQuad( WindowQuadType type );
00625 WindowQuad makeSubQuad( double x1, double y1, double x2, double y2 ) const;
00626 WindowVertex& operator[]( int index );
00627 const WindowVertex& operator[]( int index ) const;
00628 bool decoration() const;
00629 double left() const;
00630 double right() const;
00631 double top() const;
00632 double bottom() const;
00633 double originalLeft() const;
00634 double originalRight() const;
00635 double originalTop() const;
00636 double originalBottom() const;
00637 bool smoothNeeded() const;
00638 bool isTransformed() const;
00639 private:
00640 friend class WindowQuadList;
00641 WindowVertex verts[ 4 ];
00642 WindowQuadType type;
00643 };
00644
00645 class KWIN_EXPORT WindowQuadList
00646 : public QList< WindowQuad >
00647 {
00648 public:
00649 WindowQuadList splitAtX( double x ) const;
00650 WindowQuadList splitAtY( double y ) const;
00651 WindowQuadList makeGrid( int maxquadsize ) const;
00652 WindowQuadList select( WindowQuadType type ) const;
00653 WindowQuadList filterOut( WindowQuadType type ) const;
00654 bool smoothNeeded() const;
00655 void makeArrays( float** vertices, float** texcoords ) const;
00656 };
00657
00658 class KWIN_EXPORT WindowPrePaintData
00659 {
00660 public:
00661 int mask;
00665 QRegion paint;
00670 QRegion clip;
00671 WindowQuadList quads;
00676 void setTranslucent();
00680 void setTransformed();
00681 };
00682
00683 class KWIN_EXPORT WindowPaintData
00684 {
00685 public:
00686 WindowPaintData( EffectWindow* w );
00692 double opacity;
00693 double contents_opacity;
00694 double decoration_opacity;
00695 double xScale;
00696 double yScale;
00697 int xTranslate;
00698 int yTranslate;
00705 double saturation;
00711 double brightness;
00712 WindowQuadList quads;
00716 GLShader* shader;
00717 };
00718
00719 class KWIN_EXPORT ScreenPaintData
00720 {
00721 public:
00722 ScreenPaintData();
00723 double xScale;
00724 double yScale;
00725 int xTranslate;
00726 int yTranslate;
00727 };
00728
00729 class KWIN_EXPORT ScreenPrePaintData
00730 {
00731 public:
00732 int mask;
00733 QRegion paint;
00734 };
00735
00739 extern KWIN_EXPORT EffectsHandler* effects;
00740
00741
00742
00743
00744
00745 inline
00746 WindowVertex::WindowVertex()
00747 : px( 0 ), py( 0 ), tx( 0 ), ty( 0 )
00748 {
00749 }
00750
00751 inline
00752 WindowVertex::WindowVertex( double _x, double _y, double _tx, double _ty )
00753 : px( _x ), py( _y ), ox( _x ), oy( _y ), tx( _tx ), ty( _ty )
00754 {
00755 }
00756
00757 inline
00758 double WindowVertex::x() const
00759 {
00760 return px;
00761 }
00762
00763 inline
00764 double WindowVertex::y() const
00765 {
00766 return py;
00767 }
00768
00769 inline
00770 double WindowVertex::originalX() const
00771 {
00772 return ox;
00773 }
00774
00775 inline
00776 double WindowVertex::originalY() const
00777 {
00778 return oy;
00779 }
00780
00781 inline
00782 void WindowVertex::move( double x, double y )
00783 {
00784 px = x;
00785 py = y;
00786 }
00787
00788 inline
00789 void WindowVertex::setX( double x )
00790 {
00791 px = x;
00792 }
00793
00794 inline
00795 void WindowVertex::setY( double y )
00796 {
00797 py = y;
00798 }
00799
00800
00801
00802
00803
00804 inline
00805 WindowQuad::WindowQuad( WindowQuadType t )
00806 : type( t )
00807 {
00808 }
00809
00810 inline
00811 WindowVertex& WindowQuad::operator[]( int index )
00812 {
00813 assert( index >= 0 && index < 4 );
00814 return verts[ index ];
00815 }
00816
00817 inline
00818 const WindowVertex& WindowQuad::operator[]( int index ) const
00819 {
00820 assert( index >= 0 && index < 4 );
00821 return verts[ index ];
00822 }
00823
00824 inline
00825 bool WindowQuad::decoration() const
00826 {
00827 assert( type != WindowQuadError );
00828 return type == WindowQuadDecoration;
00829 }
00830
00831 inline
00832 bool WindowQuad::isTransformed() const
00833 {
00834 return !( verts[ 0 ].px == verts[ 0 ].ox && verts[ 0 ].py == verts[ 0 ].oy
00835 && verts[ 1 ].px == verts[ 1 ].ox && verts[ 1 ].py == verts[ 1 ].oy
00836 && verts[ 2 ].px == verts[ 2 ].ox && verts[ 2 ].py == verts[ 2 ].oy
00837 && verts[ 3 ].px == verts[ 3 ].ox && verts[ 3 ].py == verts[ 3 ].oy );
00838 }
00839
00840 inline
00841 double WindowQuad::left() const
00842 {
00843 return qMin( verts[ 0 ].px, qMin( verts[ 1 ].px, qMin( verts[ 2 ].px, verts[ 3 ].px )));
00844 }
00845
00846 inline
00847 double WindowQuad::right() const
00848 {
00849 return qMax( verts[ 0 ].px, qMax( verts[ 1 ].px, qMax( verts[ 2 ].px, verts[ 3 ].px )));
00850 }
00851
00852 inline
00853 double WindowQuad::top() const
00854 {
00855 return qMin( verts[ 0 ].py, qMin( verts[ 1 ].py, qMin( verts[ 2 ].py, verts[ 3 ].py )));
00856 }
00857
00858 inline
00859 double WindowQuad::bottom() const
00860 {
00861 return qMax( verts[ 0 ].py, qMax( verts[ 1 ].py, qMax( verts[ 2 ].py, verts[ 3 ].py )));
00862 }
00863
00864 inline
00865 double WindowQuad::originalLeft() const
00866 {
00867 return verts[ 0 ].ox;
00868 }
00869
00870 inline
00871 double WindowQuad::originalRight() const
00872 {
00873 return verts[ 2 ].ox;
00874 }
00875
00876 inline
00877 double WindowQuad::originalTop() const
00878 {
00879 return verts[ 0 ].oy;
00880 }
00881
00882 inline
00883 double WindowQuad::originalBottom() const
00884 {
00885 return verts[ 2 ].oy;
00886 }
00887
00888 }
00889
00892 #endif // KWINEFFECTS_H