Make a branch to make krunner Good Enough For Aaron™.
[kdebase/uwolfer.git] / workspace / kwin / lib / kwineffects.h
blobb7321ff741b0b77f35e6ce111600753925aafd43
1 /********************************************************************
2 KWin - the KDE window manager
3 This file is part of the KDE project.
5 Copyright (C) 2006 Lubos Lunak <l.lunak@kde.org>
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>.
19 *********************************************************************/
21 #ifndef KWINEFFECTS_H
22 #define KWINEFFECTS_H
24 #include <kwinconfig.h>
25 #include <kwinglobals.h>
27 #include <QtCore/QPair>
28 #include <QtCore/QRect>
29 #include <QtGui/QRegion>
30 #include <QtGui/QFont>
32 #include <QtCore/QVector>
33 #include <QtCore/QList>
34 #include <QtCore/QHash>
35 #include <QtCore/QStack>
37 #include <KDE/KPluginFactory>
38 #include <KDE/KShortcutsEditor>
40 #include <assert.h>
41 #include <limits.h>
43 #ifdef KWIN_HAVE_XRENDER_COMPOSITING
44 #include <X11/extensions/Xfixes.h>
45 #endif
47 class KLibrary;
48 class KConfigGroup;
49 class KActionCollection;
50 class QKeyEvent;
52 namespace KWin
56 class EffectWindow;
57 class EffectWindowGroup;
58 class Effect;
59 class WindowQuad;
60 class GLRenderTarget;
61 class GLShader;
62 class WindowQuadList;
63 class WindowPrePaintData;
64 class WindowPaintData;
65 class ScreenPrePaintData;
66 class ScreenPaintData;
68 typedef QPair< QString, Effect* > EffectPair;
69 typedef QPair< Effect*, Window > InputWindowPair;
70 typedef QList< EffectWindow* > EffectWindowList;
73 /** @defgroup kwineffects KWin effects library
74 * KWin effects library contains necessary classes for creating new KWin
75 * compositing effects.
77 * @section creating Creating new effects
78 * This example will demonstrate the basics of creating an effect. We'll use
79 * CoolEffect as the class name, cooleffect as internal name and
80 * "Cool Effect" as user-visible name of the effect.
82 * This example doesn't demonstrate how to write the effect's code. For that,
83 * see the documentation of the Effect class.
85 * @subsection creating-class CoolEffect class
86 * First you need to create CoolEffect class which has to be a subclass of
87 * @ref KWin::Effect. In that class you can reimplement various virtual
88 * methods to control how and where the windows are drawn.
90 * @subsection creating-macro KWIN_EFFECT macro
91 * To make KWin aware of your new effect, you first need to use the
92 * @ref KWIN_EFFECT macro to connect your effect's class to it's internal
93 * name. The internal name is used by KWin to identify your effect. It can be
94 * freely chosen (although it must be a single word), must be unique and won't
95 * be shown to the user. For our example, you would use the macro like this:
96 * @code
97 * KWIN_EFFECT(cooleffect, CoolEffect)
98 * @endcode
100 * @subsection creating-buildsystem Buildsystem
101 * To build the effect, you can use the KWIN_ADD_EFFECT() cmake macro which
102 * can be found in effects/CMakeLists.txt file in KWin's source. First
103 * argument of the macro is the name of the library that will contain
104 * your effect. Although not strictly required, it is usually a good idea to
105 * use the same name as your effect's internal name there. Following arguments
106 * to the macro are the files containing your effect's source. If our effect's
107 * source is in cooleffect.cpp, we'd use following:
108 * @code
109 * KWIN_ADD_EFFECT(cooleffect cooleffect.cpp)
110 * @endcode
112 * This macro takes care of compiling your effect. You'll also need to install
113 * your effect's .desktop file, so the example CMakeLists.txt file would be
114 * as follows:
115 * @code
116 * KWIN_ADD_EFFECT(cooleffect cooleffect.cpp)
117 * install( FILES cooleffect.desktop DESTINATION ${SERVICES_INSTALL_DIR}/kwin )
118 * @endcode
120 * @subsection creating-desktop Effect's .desktop file
121 * You will also need to create .desktop file to set name, description, icon
122 * and other properties of your effect. Important fields of the .desktop file
123 * are:
124 * @li Name User-visible name of your effect
125 * @li Icon Name of the icon of the effect
126 * @li Comment Short description of the effect
127 * @li Type must be "Service"
128 * @li X-KDE-ServiceTypes must be "KWin/Effect"
129 * @li X-KDE-PluginInfo-Name effect's internal name as passed to the KWIN_EFFECT macro plus "kwin4_effect_" prefix
130 * @li X-KDE-PluginInfo-Category effect's category. Should be one of Appearance, Accessibility, Window Management, Demos, Tests, Misc
131 * @li X-KDE-PluginInfo-EnabledByDefault whether the effect should be enabled by default (use sparingly). Default is false
132 * @li X-KDE-Library name of the library containing the effect. This is the first argument passed to the KWIN_ADD_EFFECT macro in cmake file plus "kwin4_effect_" prefix.
134 * Example cooleffect.desktop file follows:
135 * @code
136 [Desktop Entry]
137 Name=Cool Effect
138 Comment=The coolest effect you've ever seen
139 Icon=preferences-system-windows-effect-cooleffect
141 Type=Service
142 X-KDE-ServiceTypes=KWin/Effect
143 X-KDE-PluginInfo-Author=My Name
144 X-KDE-PluginInfo-Email=my@email.here
145 X-KDE-PluginInfo-Name=kwin4_effect_cooleffect
146 X-KDE-PluginInfo-Category=Misc
147 X-KDE-Library=kwin4_effect_cooleffect
148 * @endcode
151 * @section accessing Accessing windows and workspace
152 * Effects can gain access to the properties of windows and workspace via
153 * EffectWindow and EffectsHandler classes.
155 * There is one global EffectsHandler object which you can access using the
156 * @ref effects pointer.
157 * For each window, there is an EffectWindow object which can be used to read
158 * window properties such as position and also to change them.
160 * For more information about this, see the documentation of the corresponding
161 * classes.
163 * @{
166 #define KWIN_EFFECT_API_MAKE_VERSION( major, minor ) (( major ) << 8 | ( minor ))
167 #define KWIN_EFFECT_API_VERSION_MAJOR 0
168 #define KWIN_EFFECT_API_VERSION_MINOR 7
169 #define KWIN_EFFECT_API_VERSION KWIN_EFFECT_API_MAKE_VERSION( \
170 KWIN_EFFECT_API_VERSION_MAJOR, KWIN_EFFECT_API_VERSION_MINOR )
173 * Infinite region (i.e. a special region type saying that everything needs to be painted).
175 KWIN_EXPORT inline
176 QRect infiniteRegion()
177 { // INT_MIN / 2 because width/height is used (INT_MIN+INT_MAX==-1)
178 return QRect( INT_MIN / 2, INT_MIN / 2, INT_MAX, INT_MAX );
181 #ifdef KWIN_HAVE_XRENDER_COMPOSITING
183 * Convert QRegion to XserverRegion.
185 KWIN_EXPORT XserverRegion toXserverRegion( QRegion region );
186 #endif
189 * @short Base class for all KWin effects
191 * This is the base class for all effects. By reimplementing virtual methods
192 * of this class, you can customize how the windows are painted.
194 * The virtual methods of this class can broadly be divided into two
195 * categories: the methods used for painting and those you can use to be
196 * notified and react to certain events, e.g. that a window was closed.
198 * @section Chaining
199 * Most methods of this class are called in chain style. This means that when
200 * effects A and B area active then first e.g. A::paintWindow() is called and
201 * then from within that method B::paintWindow() is called (although
202 * indirectly). To achieve this, you need to make sure to call corresponding
203 * method in EffectsHandler class from each such method (using @ref effects
204 * pointer):
205 * @code
206 * void MyEffect::postPaintScreen()
208 * // Do your own processing here
209 * ...
210 * // Call corresponding EffectsHandler method
211 * effects->postPaintScreen();
213 * @endcode
215 * @section Effectsptr Effects pointer
216 * @ref effects pointer points to the global EffectsHandler object that you can
217 * use to interact with the windows.
219 * @section painting Painting stages
220 * Painting of windows is done in three stages:
221 * @li First, the prepaint pass.<br>
222 * Here you can specify how the windows will be painted, e.g. that they will
223 * be translucent and transformed.
224 * @li Second, the paint pass.<br>
225 * Here the actual painting takes place. You can change attributes such as
226 * opacity of windows as well as apply transformations to them. You can also
227 * paint something onto the screen yourself.
228 * @li Finally, the postpaint pass.<br>
229 * Here you can mark windows, part of windows or even the entire screen for
230 * repainting to create animations.
232 * For each stage there are *Screen() and *Window() methods. The window method
233 * is called for every window which the screen method is usually called just
234 * once.
236 class KWIN_EXPORT Effect
238 public:
239 /** Flags controlling how painting is done. */
240 // TODO: is that ok here?
241 enum
244 * Window (or at least part of it) will be painted opaque.
246 PAINT_WINDOW_OPAQUE = 1 << 0,
248 * Window (or at least part of it) will be painted translucent.
250 PAINT_WINDOW_TRANSLUCENT = 1 << 1,
252 * Window will be painted with transformed geometry.
254 PAINT_WINDOW_TRANSFORMED = 1 << 2,
256 * Paint only a region of the screen (can be optimized, cannot
257 * be used together with TRANSFORMED flags).
259 PAINT_SCREEN_REGION = 1 << 3,
261 * The whole screen will be painted with transformed geometry.
262 * Forces the entire screen to be painted.
264 PAINT_SCREEN_TRANSFORMED = 1 << 4,
266 * At least one window will be painted with transformed geometry.
267 * Forces the entire screen to be painted.
269 PAINT_SCREEN_WITH_TRANSFORMED_WINDOWS = 1 << 5,
271 * Clear whole background as the very first step, without optimizing it
273 PAINT_SCREEN_BACKGROUND_FIRST = 1 << 6
277 * Constructs new Effect object.
279 Effect();
281 * Destructs the Effect object.
283 virtual ~Effect();
286 * Called before starting to paint the screen.
287 * In this method you can:
288 * @li set whether the windows or the entire screen will be transformed
289 * @li change the region of the screen that will be painted
290 * @li do various housekeeping tasks such as initing your effect's variables
291 for the upcoming paint pass or updating animation's progress
293 virtual void prePaintScreen( ScreenPrePaintData& data, int time );
295 * In this method you can:
296 * @li paint something on top of the windows (by painting after calling
297 * effects->paintScreen())
298 * @li paint multiple desktops and/or multiple copies of the same desktop
299 * by calling effects->paintScreen() multiple times
301 virtual void paintScreen( int mask, QRegion region, ScreenPaintData& data );
303 * Called after all the painting has been finished.
304 * In this method you can:
305 * @li schedule next repaint in case of animations
306 * You shouldn't paint anything here.
308 virtual void postPaintScreen();
311 * Called for every window before the actual paint pass
312 * In this method you can:
313 * @li enable or disable painting of the window (e.g. enable paiting of minimized window)
314 * @li set window to be painted with translucency
315 * @li set window to be transformed
316 * @li request the window to be divided into multiple parts
318 virtual void prePaintWindow( EffectWindow* w, WindowPrePaintData& data, int time );
320 * This is the main method for painting windows.
321 * In this method you can:
322 * @li do various transformations
323 * @li change opacity of the window
324 * @li change brightness and/or saturation, if it's supported
326 virtual void paintWindow( EffectWindow* w, int mask, QRegion region, WindowPaintData& data );
328 * Called for every window after all painting has been finished.
329 * In this method you can:
330 * @li schedule next repaint for individual window(s) in case of animations
331 * You shouldn't paint anything here.
333 virtual void postPaintWindow( EffectWindow* w );
336 * Can be called to draw multiple copies (e.g. thumbnails) of a window.
337 * You can change window's opacity/brightness/etc here, but you can't
338 * do any transformations
340 virtual void drawWindow( EffectWindow* w, int mask, QRegion region, WindowPaintData& data );
342 * This function is used e.g. by the shadow effect which adds area around windows
343 * that needs to be painted as well - e.g. when a window is hidden and the workspace needs
344 * to be repainted at that area, shadow's transformWindowDamage() adds the shadow area
345 * to it, so that it is repainted as well.
347 virtual QRect transformWindowDamage( EffectWindow* w, const QRect& r );
349 /** called when moved/resized or once after it's finished */
350 virtual void windowUserMovedResized( EffectWindow* c, bool first, bool last );
351 virtual void windowOpacityChanged( EffectWindow* c, double old_opacity );
352 virtual void windowAdded( EffectWindow* c );
353 virtual void windowClosed( EffectWindow* c );
354 virtual void windowDeleted( EffectWindow* c );
355 virtual void windowActivated( EffectWindow* c );
356 virtual void windowMinimized( EffectWindow* c );
357 virtual void windowUnminimized( EffectWindow* c );
358 virtual void windowInputMouseEvent( Window w, QEvent* e );
359 virtual void desktopChanged( int old );
360 virtual void windowDamaged( EffectWindow* w, const QRect& r );
361 virtual void windowGeometryShapeChanged( EffectWindow* w, const QRect& old );
362 virtual void mouseChanged( const QPoint& pos, const QPoint& oldpos,
363 Qt::MouseButtons buttons, Qt::MouseButtons oldbuttons,
364 Qt::KeyboardModifiers modifiers, Qt::KeyboardModifiers oldmodifiers );
365 virtual void grabbedKeyboardEvent( QKeyEvent* e );
367 Receives events registered for using EffectsHandler::registerPropertyType().
368 Use readProperty() to get the property data.
369 Note that the property may be already set on the window, so doing the same
370 processing from windowAdded() (e.g. simply calling propertyNotify() from it)
371 is usually needed.
373 virtual void propertyNotify( EffectWindow* w, long atom );
375 virtual void tabBoxAdded( int mode );
376 virtual void tabBoxClosed();
377 virtual void tabBoxUpdated();
378 virtual bool borderActivated( ElectricBorder border );
380 static int displayWidth();
381 static int displayHeight();
382 static QPoint cursorPos();
385 * Linearly interpolates between @p x and @p y.
387 * Returns @p x when @p a = 0; returns @p y when @p a = 1.
389 static double interpolate(double x, double y, double a)
391 return x * (1 - a) + y * a;
393 /** Helper to set WindowPaintData and QRegion to necessary transformations so that
394 * a following drawWindow() would put the window at the requested geometry (useful for thumbnails)
396 static void setPositionTransformations( WindowPaintData& data, QRect& region, EffectWindow* w,
397 const QRect& r, Qt::AspectRatioMode aspect );
402 * Defines the class to be used for effect with given name.
403 * The name must be same as effect's X-KDE-PluginInfo-Name values in .desktop
404 * file, but without the "kwin4_effect_" prefix.
405 * E.g. KWIN_EFFECT( flames, MyFlameEffect )
406 * In this case object of MyFlameEffect class would be created when effect
407 * "flames" (which has X-KDE-PluginInfo-Name=kwin4_effect_flames in .desktop
408 * file) is loaded.
410 #define KWIN_EFFECT( name, classname ) \
411 extern "C" { \
412 KWIN_EXPORT Effect* effect_create_kwin4_effect_##name() { return new classname; } \
413 KWIN_EXPORT int effect_version_kwin4_effect_##name() { return KWIN_EFFECT_API_VERSION; } \
416 * Defines the function used to check whether an effect is supported
417 * E.g. KWIN_EFFECT_SUPPORTED( flames, MyFlameEffect::supported() )
419 #define KWIN_EFFECT_SUPPORTED( name, function ) \
420 extern "C" { \
421 KWIN_EXPORT bool effect_supported_kwin4_effect_##name() { return function; } \
424 * Defines the function used to retrieve an effect's config widget
425 * E.g. KWIN_EFFECT_CONFIG( flames, MyFlameEffectConfig )
427 #define KWIN_EFFECT_CONFIG( name, classname ) \
428 K_PLUGIN_FACTORY(name##_factory, registerPlugin<classname>();) \
429 K_EXPORT_PLUGIN(name##_factory("kcm_kwineffect_" #name))
432 * The declaration of the factory to export the effect
434 #define KWIN_EFFECT_CONFIG_FACTORY K_PLUGIN_FACTORY_DECLARATION(EffectFactory)
438 * @short Manager class that handles all the effects.
440 * This class creates Effect objects and calls it's appropriate methods.
442 * Effect objects can call methods of this class to interact with the
443 * workspace, e.g. to activate or move a specific window, change current
444 * desktop or create a special input window to receive mouse and keyboard
445 * events.
447 class KWIN_EXPORT EffectsHandler
449 friend class Effect;
450 public:
451 EffectsHandler(CompositingType type);
452 virtual ~EffectsHandler();
453 // for use by effects
454 virtual void prePaintScreen( ScreenPrePaintData& data, int time ) = 0;
455 virtual void paintScreen( int mask, QRegion region, ScreenPaintData& data ) = 0;
456 virtual void postPaintScreen() = 0;
457 virtual void prePaintWindow( EffectWindow* w, WindowPrePaintData& data, int time ) = 0;
458 virtual void paintWindow( EffectWindow* w, int mask, QRegion region, WindowPaintData& data ) = 0;
459 virtual void postPaintWindow( EffectWindow* w ) = 0;
460 virtual void drawWindow( EffectWindow* w, int mask, QRegion region, WindowPaintData& data ) = 0;
461 virtual QRect transformWindowDamage( EffectWindow* w, const QRect& r );
462 // Functions for handling input - e.g. when an Expose-like effect is shown, an input window
463 // covering the whole screen is created and all mouse events will be intercepted by it.
464 // The effect's windowInputMouseEvent() will get called with such events.
465 virtual Window createInputWindow( Effect* e, int x, int y, int w, int h, const QCursor& cursor ) = 0;
466 Window createInputWindow( Effect* e, const QRect& r, const QCursor& cursor );
467 virtual Window createFullScreenInputWindow( Effect* e, const QCursor& cursor );
468 virtual void destroyInputWindow( Window w ) = 0;
469 virtual QPoint cursorPos() const = 0;
470 virtual bool grabKeyboard( Effect* effect ) = 0;
471 virtual void ungrabKeyboard() = 0;
473 virtual void checkElectricBorder(const QPoint &pos, Time time) = 0;
474 virtual void reserveElectricBorder( ElectricBorder border ) = 0;
475 virtual void unreserveElectricBorder( ElectricBorder border ) = 0;
476 virtual void reserveElectricBorderSwitching( bool reserve ) = 0;
478 // functions that allow controlling windows/desktop
479 virtual void activateWindow( EffectWindow* c ) = 0;
480 virtual EffectWindow* activeWindow() const = 0 ;
481 virtual void moveWindow( EffectWindow* w, const QPoint& pos ) = 0;
482 virtual void windowToDesktop( EffectWindow* w, int desktop ) = 0;
484 virtual int currentDesktop() const = 0;
485 virtual int numberOfDesktops() const = 0;
486 virtual void setCurrentDesktop( int desktop ) = 0;
487 virtual QString desktopName( int desktop ) const = 0;
488 virtual int activeScreen() const = 0; // Xinerama
489 virtual QRect clientArea( clientAreaOption, int screen, int desktop ) const = 0;
490 virtual QRect clientArea( clientAreaOption, const EffectWindow* c ) const = 0;
491 virtual QRect clientArea( clientAreaOption, const QPoint& p, int desktop ) const = 0;
492 virtual void calcDesktopLayout(int* x, int* y, Qt::Orientation* orientation) const = 0;
493 virtual bool optionRollOverDesktops() const = 0;
494 virtual int desktopToLeft( int desktop, bool wrap ) const = 0;
495 virtual int desktopToRight( int desktop, bool wrap ) const = 0;
496 virtual int desktopUp( int desktop, bool wrap ) const = 0;
497 virtual int desktopDown( int desktop, bool wrap ) const = 0;
499 virtual EffectWindow* findWindow( WId id ) const = 0;
500 virtual EffectWindowList stackingOrder() const = 0;
501 // window will be temporarily painted as if being at the top of the stack
502 virtual void setElevatedWindow( EffectWindow* w, bool set ) = 0;
504 virtual void setTabBoxWindow(EffectWindow*) = 0;
505 virtual void setTabBoxDesktop(int) = 0;
506 virtual EffectWindowList currentTabBoxWindowList() const = 0;
507 virtual void refTabBox() = 0;
508 virtual void unrefTabBox() = 0;
509 virtual void closeTabBox() = 0;
510 virtual QList< int > currentTabBoxDesktopList() const = 0;
511 virtual int currentTabBoxDesktop() const = 0;
512 virtual EffectWindow* currentTabBoxWindow() const = 0;
514 virtual void setActiveFullScreenEffect( Effect* e ) = 0;
515 virtual Effect* activeFullScreenEffect() const = 0;
517 virtual void pushRenderTarget(GLRenderTarget* target) = 0;
518 virtual GLRenderTarget* popRenderTarget() = 0;
521 * Schedules the entire workspace to be repainted next time.
522 * If you call it during painting (including prepaint) then it does not
523 * affect the current painting.
525 virtual void addRepaintFull() = 0;
526 virtual void addRepaint( const QRect& r ) = 0;
527 virtual void addRepaint( int x, int y, int w, int h ) = 0;
529 CompositingType compositingType() const;
530 virtual unsigned long xrenderBufferPicture() = 0;
531 virtual void reconfigure() = 0;
534 Makes KWin core watch PropertyNotify events for the given atom,
535 or stops watching if reg is false (must be called the same number
536 of times as registering). Events are sent using Effect::propertyNotify().
537 Note that even events that haven't been registered for can be received.
539 virtual void registerPropertyType( long atom, bool reg ) = 0;
542 * Paints given text onto screen, possibly in elided form
543 * @param text
544 * @param center center point of the painted text
545 * @param maxwidth if text is longer than this, is will be elided
546 * @param color color of the text, may contain alpha
547 * @param font font for the text
549 bool paintText( const QString& text, const QPoint& center, int maxwidth,
550 const QColor& color, const QFont& font = QFont() );
551 bool paintTextWithBackground( const QString& text, const QPoint& center, int maxwidth,
552 const QColor& color, const QColor& bgcolor,
553 const QFont& font = QFont() );
557 * Sends message over DCOP to reload given effect.
558 * @param effectname effect's name without "kwin4_effect_" prefix.
559 * Can be called from effect's config module to apply config changes.
561 static void sendReloadMessage( const QString& effectname );
563 * @return @ref KConfigGroup which holds given effect's config options
565 static KConfigGroup effectConfig( const QString& effectname );
568 protected:
569 QVector< EffectPair > loaded_effects;
570 QHash< QString, KLibrary* > effect_libraries;
571 QList< InputWindowPair > input_windows;
572 //QHash< QString, EffectFactory* > effect_factories;
573 int current_paint_screen;
574 int current_paint_window;
575 int current_draw_window;
576 int current_transform;
577 CompositingType compositing_type;
582 * @short Representation of a window used by/for Effect classes.
584 * The purpose is to hide internal data and also to serve as a single
585 * representation for the case when Client/Unmanaged becomes Deleted.
587 class KWIN_EXPORT EffectWindow
589 public:
590 /** Flags explaining why painting should be disabled */
591 enum
593 /** Window will not be painted */
594 PAINT_DISABLED = 1 << 0,
595 /** Window will not be painted because it is deleted */
596 PAINT_DISABLED_BY_DELETE = 1 << 1,
597 /** Window will not be painted because of which desktop it's on */
598 PAINT_DISABLED_BY_DESKTOP = 1 << 2,
599 /** Window will not be painted because it is minimized */
600 PAINT_DISABLED_BY_MINIMIZE = 1 << 3
603 EffectWindow();
604 virtual ~EffectWindow();
606 virtual void enablePainting( int reason ) = 0;
607 virtual void disablePainting( int reason ) = 0;
608 virtual bool isPaintingEnabled() = 0;
609 virtual void addRepaint( const QRect& r ) = 0;
610 virtual void addRepaint( int x, int y, int w, int h ) = 0;
611 virtual void addRepaintFull() = 0;
613 virtual void refWindow() = 0;
614 virtual void unrefWindow() = 0;
615 virtual bool isDeleted() const = 0;
617 virtual bool isMinimized() const = 0;
618 virtual double opacity() const = 0;
620 virtual bool isOnDesktop( int d ) const;
621 virtual bool isOnCurrentDesktop() const;
622 virtual bool isOnAllDesktops() const = 0;
623 virtual int desktop() const = 0; // prefer isOnXXX()
625 virtual int x() const = 0;
626 virtual int y() const = 0;
627 virtual int width() const = 0;
628 virtual int height() const = 0;
629 virtual QRect geometry() const = 0;
630 virtual QRegion shape() const = 0;
631 /** @internal Do not use */
632 virtual bool hasOwnShape() const = 0; // only for shadow effect, for now
633 virtual QPoint pos() const = 0;
634 virtual QSize size() const = 0;
635 virtual QRect rect() const = 0;
636 virtual bool isMovable() const = 0;
637 virtual bool isUserMove() const = 0;
638 virtual bool isUserResize() const = 0;
639 virtual QRect iconGeometry() const = 0;
641 * Geometry of the actual window contents inside the whole (including decorations) window.
643 virtual QRect contentsRect() const = 0;
644 bool hasDecoration() const;
645 virtual QByteArray readProperty( long atom, long type, int format ) const = 0;
647 virtual QString caption() const = 0;
648 virtual QPixmap icon() const = 0;
649 virtual QString windowClass() const = 0;
650 virtual QString windowRole() const = 0;
651 virtual const EffectWindowGroup* group() const = 0;
653 virtual bool isDesktop() const = 0;
654 virtual bool isDock() const = 0;
655 virtual bool isToolbar() const = 0;
656 virtual bool isTopMenu() const = 0;
657 virtual bool isMenu() const = 0;
658 virtual bool isNormalWindow() const = 0; // normal as in 'NET::Normal or NET::Unknown non-transient'
659 virtual bool isSpecialWindow() const = 0;
660 virtual bool isDialog() const = 0;
661 virtual bool isSplash() const = 0;
662 virtual bool isUtility() const = 0;
663 virtual bool isDropdownMenu() const = 0;
664 virtual bool isPopupMenu() const = 0; // a context popup, not dropdown, not torn-off
665 virtual bool isTooltip() const = 0;
666 virtual bool isNotification() const = 0;
667 virtual bool isComboBox() const = 0;
668 virtual bool isDNDIcon() const = 0;
669 virtual bool isManaged() const = 0; // whether it's managed or override-redirect
671 virtual bool isModal() const = 0;
672 virtual EffectWindow* findModal() = 0;
673 virtual EffectWindowList mainWindows() const = 0;
675 // TODO internal?
676 virtual WindowQuadList buildQuads() const = 0;
679 class KWIN_EXPORT EffectWindowGroup
681 public:
682 virtual ~EffectWindowGroup();
683 virtual EffectWindowList members() const = 0;
686 class KWIN_EXPORT GlobalShortcutsEditor : public KShortcutsEditor
688 public:
689 GlobalShortcutsEditor( QWidget *parent );
693 * @short Vertex class
695 * A vertex is one position in a window. WindowQuad consists of four WindowVertex objects
696 * and represents one part of a window.
698 class KWIN_EXPORT WindowVertex
700 public:
701 double x() const;
702 double y() const;
703 void move( double x, double y );
704 void setX( double x );
705 void setY( double y );
706 double originalX() const;
707 double originalY() const;
708 WindowVertex();
709 WindowVertex( double x, double y, double tx, double ty );
710 private:
711 friend class WindowQuad;
712 friend class WindowQuadList;
713 double px, py; // position
714 double ox, oy; // origional position
715 double tx, ty; // texture coords
718 enum WindowQuadType
720 WindowQuadError, // for the stupid default ctor
721 WindowQuadContents,
722 WindowQuadDecoration
726 * @short Class representing one area of a window.
728 * WindowQuads consists of four WindowVertex objects and represents one part of a window.
730 // NOTE: This class expects the (original) vertices to be in the clockwise order starting from topleft.
731 class KWIN_EXPORT WindowQuad
733 public:
734 explicit WindowQuad( WindowQuadType type );
735 WindowQuad makeSubQuad( double x1, double y1, double x2, double y2 ) const;
736 WindowVertex& operator[]( int index );
737 const WindowVertex& operator[]( int index ) const;
738 bool decoration() const;
739 double left() const;
740 double right() const;
741 double top() const;
742 double bottom() const;
743 double originalLeft() const;
744 double originalRight() const;
745 double originalTop() const;
746 double originalBottom() const;
747 bool smoothNeeded() const;
748 bool isTransformed() const;
749 private:
750 friend class WindowQuadList;
751 WindowVertex verts[ 4 ];
752 WindowQuadType type; // 0 - contents, 1 - decoration
755 class KWIN_EXPORT WindowQuadList
756 : public QList< WindowQuad >
758 public:
759 WindowQuadList splitAtX( double x ) const;
760 WindowQuadList splitAtY( double y ) const;
761 WindowQuadList makeGrid( int maxquadsize ) const;
762 WindowQuadList select( WindowQuadType type ) const;
763 WindowQuadList filterOut( WindowQuadType type ) const;
764 bool smoothNeeded() const;
765 void makeArrays( float** vertices, float** texcoords ) const;
768 class KWIN_EXPORT WindowPrePaintData
770 public:
771 int mask;
773 * Region that will be painted, in screen coordinates.
775 QRegion paint;
777 * The clip region will be substracted from paint region of following windows.
778 * I.e. window will definitely cover it's clip region
780 QRegion clip;
781 WindowQuadList quads;
783 * Simple helper that sets data to say the window will be painted as non-opaque.
784 * Takes also care of changing the regions.
786 void setTranslucent();
788 * Helper to mark that this window will be transformed
790 void setTransformed();
793 class KWIN_EXPORT WindowPaintData
795 public:
796 WindowPaintData( EffectWindow* w );
798 * Window opacity, in range 0 = transparent to 1 = fully opaque
799 * Opacity for contents is opacity*contents_opacity, the same
800 * way for decoration.
802 double opacity;
803 double contents_opacity;
804 double decoration_opacity;
805 double xScale;
806 double yScale;
807 int xTranslate;
808 int yTranslate;
810 * Saturation of the window, in range [0; 1]
811 * 1 means that the window is unchanged, 0 means that it's completely
812 * unsaturated (greyscale). 0.5 would make the colors less intense,
813 * but not completely grey
815 double saturation;
817 * Brightness of the window, in range [0; 1]
818 * 1 means that the window is unchanged, 0 means that it's completely
819 * black. 0.5 would make it 50% darker than usual
821 double brightness;
822 WindowQuadList quads;
824 * Shader to be used for rendering, if any.
826 GLShader* shader;
829 class KWIN_EXPORT ScreenPaintData
831 public:
832 ScreenPaintData();
833 double xScale;
834 double yScale;
835 int xTranslate;
836 int yTranslate;
839 class KWIN_EXPORT ScreenPrePaintData
841 public:
842 int mask;
843 QRegion paint;
847 * @short Helper class for restricting painting area only to allowed area.
849 * This helper class helps specifying areas that should be painted, clipping
850 * out the rest. The simplest usage is creating an object on the stack
851 * and giving it the area that is allowed to be painted to. When the object
852 * is destroyed, the restriction will be removed.
853 * Note that all painting code must use paintArea() to actually perform the clipping.
855 class KWIN_EXPORT PaintClipper
857 public:
859 * Calls push().
861 PaintClipper( const QRegion& allowed_area );
863 * Calls pop().
865 ~PaintClipper();
867 * Allows painting only in the given area. When areas have been already
868 * specified, painting is allowed only in the intersection of all areas.
870 static void push( const QRegion& allowed_area );
872 * Removes the given area. It must match the top item in the stack.
874 static void pop( const QRegion& allowed_area );
876 * Returns true if any clipping should be performed.
878 static bool clip();
880 * If clip() returns true, this function gives the resulting area in which
881 * painting is allowed. It is usually simpler to use the helper Iterator class.
883 static QRegion paintArea();
885 * Helper class to perform the clipped painting. The usage is:
886 * @code
887 * for( PaintClipper::Iterator iterator;
888 * !iterator.isDone();
889 * iterator.next())
890 * { // do the painting, possibly use iterator.boundingRect()
892 * @endcode
894 class KWIN_EXPORT Iterator
896 public:
897 Iterator();
898 ~Iterator();
899 bool isDone();
900 void next();
901 QRect boundingRect() const;
902 private:
903 struct Data;
904 Data* data;
906 private:
907 QRegion area;
908 static QStack< QRegion >* areas;
912 * Pointer to the global EffectsHandler object.
914 extern KWIN_EXPORT EffectsHandler* effects;
916 /***************************************************************
917 WindowVertex
918 ***************************************************************/
920 inline
921 WindowVertex::WindowVertex()
922 : px( 0 ), py( 0 ), tx( 0 ), ty( 0 )
926 inline
927 WindowVertex::WindowVertex( double _x, double _y, double _tx, double _ty )
928 : px( _x ), py( _y ), ox( _x ), oy( _y ), tx( _tx ), ty( _ty )
932 inline
933 double WindowVertex::x() const
935 return px;
938 inline
939 double WindowVertex::y() const
941 return py;
944 inline
945 double WindowVertex::originalX() const
947 return ox;
950 inline
951 double WindowVertex::originalY() const
953 return oy;
956 inline
957 void WindowVertex::move( double x, double y )
959 px = x;
960 py = y;
963 inline
964 void WindowVertex::setX( double x )
966 px = x;
969 inline
970 void WindowVertex::setY( double y )
972 py = y;
975 /***************************************************************
976 WindowQuad
977 ***************************************************************/
979 inline
980 WindowQuad::WindowQuad( WindowQuadType t )
981 : type( t )
985 inline
986 WindowVertex& WindowQuad::operator[]( int index )
988 assert( index >= 0 && index < 4 );
989 return verts[ index ];
992 inline
993 const WindowVertex& WindowQuad::operator[]( int index ) const
995 assert( index >= 0 && index < 4 );
996 return verts[ index ];
999 inline
1000 bool WindowQuad::decoration() const
1002 assert( type != WindowQuadError );
1003 return type == WindowQuadDecoration;
1006 inline
1007 bool WindowQuad::isTransformed() const
1009 return !( verts[ 0 ].px == verts[ 0 ].ox && verts[ 0 ].py == verts[ 0 ].oy
1010 && verts[ 1 ].px == verts[ 1 ].ox && verts[ 1 ].py == verts[ 1 ].oy
1011 && verts[ 2 ].px == verts[ 2 ].ox && verts[ 2 ].py == verts[ 2 ].oy
1012 && verts[ 3 ].px == verts[ 3 ].ox && verts[ 3 ].py == verts[ 3 ].oy );
1015 inline
1016 double WindowQuad::left() const
1018 return qMin( verts[ 0 ].px, qMin( verts[ 1 ].px, qMin( verts[ 2 ].px, verts[ 3 ].px )));
1021 inline
1022 double WindowQuad::right() const
1024 return qMax( verts[ 0 ].px, qMax( verts[ 1 ].px, qMax( verts[ 2 ].px, verts[ 3 ].px )));
1027 inline
1028 double WindowQuad::top() const
1030 return qMin( verts[ 0 ].py, qMin( verts[ 1 ].py, qMin( verts[ 2 ].py, verts[ 3 ].py )));
1033 inline
1034 double WindowQuad::bottom() const
1036 return qMax( verts[ 0 ].py, qMax( verts[ 1 ].py, qMax( verts[ 2 ].py, verts[ 3 ].py )));
1039 inline
1040 double WindowQuad::originalLeft() const
1042 return verts[ 0 ].ox;
1045 inline
1046 double WindowQuad::originalRight() const
1048 return verts[ 2 ].ox;
1051 inline
1052 double WindowQuad::originalTop() const
1054 return verts[ 0 ].oy;
1057 inline
1058 double WindowQuad::originalBottom() const
1060 return verts[ 2 ].oy;
1063 } // namespace
1065 /** @} */
1067 #endif // KWINEFFECTS_H