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 *********************************************************************/
24 #include <kwinconfig.h>
25 #include <kwinglobals.h>
26 #include "kdecoration.h"
28 #include <QtCore/QPair>
29 #include <QtCore/QRect>
30 #include <QtGui/QRegion>
31 #include <QtGui/QFont>
33 #include <QtCore/QVector>
34 #include <QtCore/QList>
35 #include <QtCore/QHash>
36 #include <QtCore/QStack>
37 #include <QtCore/QTimeLine>
39 #include <KDE/KPluginFactory>
40 #include <KDE/KShortcutsEditor>
47 class KActionCollection
;
55 class EffectWindowGroup
;
62 class WindowPrePaintData
;
63 class WindowPaintData
;
64 class ScreenPrePaintData
;
65 class ScreenPaintData
;
67 typedef QPair
< QString
, Effect
* > EffectPair
;
68 typedef QPair
< Effect
*, Window
> InputWindowPair
;
69 typedef QList
< EffectWindow
* > EffectWindowList
;
72 /** @defgroup kwineffects KWin effects library
73 * KWin effects library contains necessary classes for creating new KWin
74 * compositing effects.
76 * @section creating Creating new effects
77 * This example will demonstrate the basics of creating an effect. We'll use
78 * CoolEffect as the class name, cooleffect as internal name and
79 * "Cool Effect" as user-visible name of the effect.
81 * This example doesn't demonstrate how to write the effect's code. For that,
82 * see the documentation of the Effect class.
84 * @subsection creating-class CoolEffect class
85 * First you need to create CoolEffect class which has to be a subclass of
86 * @ref KWin::Effect. In that class you can reimplement various virtual
87 * methods to control how and where the windows are drawn.
89 * @subsection creating-macro KWIN_EFFECT macro
90 * To make KWin aware of your new effect, you first need to use the
91 * @ref KWIN_EFFECT macro to connect your effect's class to it's internal
92 * name. The internal name is used by KWin to identify your effect. It can be
93 * freely chosen (although it must be a single word), must be unique and won't
94 * be shown to the user. For our example, you would use the macro like this:
96 * KWIN_EFFECT(cooleffect, CoolEffect)
99 * @subsection creating-buildsystem Buildsystem
100 * To build the effect, you can use the KWIN_ADD_EFFECT() cmake macro which
101 * can be found in effects/CMakeLists.txt file in KWin's source. First
102 * argument of the macro is the name of the library that will contain
103 * your effect. Although not strictly required, it is usually a good idea to
104 * use the same name as your effect's internal name there. Following arguments
105 * to the macro are the files containing your effect's source. If our effect's
106 * source is in cooleffect.cpp, we'd use following:
108 * KWIN_ADD_EFFECT(cooleffect cooleffect.cpp)
111 * This macro takes care of compiling your effect. You'll also need to install
112 * your effect's .desktop file, so the example CMakeLists.txt file would be
115 * KWIN_ADD_EFFECT(cooleffect cooleffect.cpp)
116 * install( FILES cooleffect.desktop DESTINATION ${SERVICES_INSTALL_DIR}/kwin )
119 * @subsection creating-desktop Effect's .desktop file
120 * You will also need to create .desktop file to set name, description, icon
121 * and other properties of your effect. Important fields of the .desktop file
123 * @li Name User-visible name of your effect
124 * @li Icon Name of the icon of the effect
125 * @li Comment Short description of the effect
126 * @li Type must be "Service"
127 * @li X-KDE-ServiceTypes must be "KWin/Effect"
128 * @li X-KDE-PluginInfo-Name effect's internal name as passed to the KWIN_EFFECT macro plus "kwin4_effect_" prefix
129 * @li X-KDE-PluginInfo-Category effect's category. Should be one of Appearance, Accessibility, Window Management, Demos, Tests, Misc
130 * @li X-KDE-PluginInfo-EnabledByDefault whether the effect should be enabled by default (use sparingly). Default is false
131 * @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.
133 * Example cooleffect.desktop file follows:
137 Comment=The coolest effect you've ever seen
138 Icon=preferences-system-windows-effect-cooleffect
141 X-KDE-ServiceTypes=KWin/Effect
142 X-KDE-PluginInfo-Author=My Name
143 X-KDE-PluginInfo-Email=my@email.here
144 X-KDE-PluginInfo-Name=kwin4_effect_cooleffect
145 X-KDE-PluginInfo-Category=Misc
146 X-KDE-Library=kwin4_effect_cooleffect
150 * @section accessing Accessing windows and workspace
151 * Effects can gain access to the properties of windows and workspace via
152 * EffectWindow and EffectsHandler classes.
154 * There is one global EffectsHandler object which you can access using the
155 * @ref effects pointer.
156 * For each window, there is an EffectWindow object which can be used to read
157 * window properties such as position and also to change them.
159 * For more information about this, see the documentation of the corresponding
165 #define KWIN_EFFECT_API_MAKE_VERSION( major, minor ) (( major ) << 8 | ( minor ))
166 #define KWIN_EFFECT_API_VERSION_MAJOR 0
167 #define KWIN_EFFECT_API_VERSION_MINOR 57
168 #define KWIN_EFFECT_API_VERSION KWIN_EFFECT_API_MAKE_VERSION( \
169 KWIN_EFFECT_API_VERSION_MAJOR, KWIN_EFFECT_API_VERSION_MINOR )
173 WindowQuadError
, // for the stupid default ctor
175 WindowQuadDecoration
,
176 EFFECT_QUAD_TYPE_START
= 100 ///< @internal
180 * Infinite region (i.e. a special region type saying that everything needs to be painted).
183 QRect
infiniteRegion()
184 { // INT_MIN / 2 because width/height is used (INT_MIN+INT_MAX==-1)
185 return QRect( INT_MIN
/ 2, INT_MIN
/ 2, INT_MAX
, INT_MAX
);
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.
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
206 * void MyEffect::postPaintScreen()
208 * // Do your own processing here
210 * // Call corresponding EffectsHandler method
211 * effects->postPaintScreen();
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
236 class KWIN_EXPORT Effect
239 /** Flags controlling how painting is done. */
240 // TODO: is that ok here?
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.
281 * Destructs the Effect object.
286 * Flags describing which parts of configuration have changed.
290 ReconfigureAll
= 1 << 0 /// Everything needs to be reconfigured.
292 Q_DECLARE_FLAGS( ReconfigureFlags
, ReconfigureFlag
)
295 * Called when configuration changes (either the effect's or KWin's global).
297 virtual void reconfigure( ReconfigureFlags flags
);
300 * Called before starting to paint the screen.
301 * In this method you can:
302 * @li set whether the windows or the entire screen will be transformed
303 * @li change the region of the screen that will be painted
304 * @li do various housekeeping tasks such as initing your effect's variables
305 for the upcoming paint pass or updating animation's progress
307 virtual void prePaintScreen( ScreenPrePaintData
& data
, int time
);
309 * In this method you can:
310 * @li paint something on top of the windows (by painting after calling
311 * effects->paintScreen())
312 * @li paint multiple desktops and/or multiple copies of the same desktop
313 * by calling effects->paintScreen() multiple times
315 virtual void paintScreen( int mask
, QRegion region
, ScreenPaintData
& data
);
317 * Called after all the painting has been finished.
318 * In this method you can:
319 * @li schedule next repaint in case of animations
320 * You shouldn't paint anything here.
322 virtual void postPaintScreen();
325 * Called for every window before the actual paint pass
326 * In this method you can:
327 * @li enable or disable painting of the window (e.g. enable paiting of minimized window)
328 * @li set window to be painted with translucency
329 * @li set window to be transformed
330 * @li request the window to be divided into multiple parts
332 virtual void prePaintWindow( EffectWindow
* w
, WindowPrePaintData
& data
, int time
);
334 * This is the main method for painting windows.
335 * In this method you can:
336 * @li do various transformations
337 * @li change opacity of the window
338 * @li change brightness and/or saturation, if it's supported
340 virtual void paintWindow( EffectWindow
* w
, int mask
, QRegion region
, WindowPaintData
& data
);
342 * Called for every window after all painting has been finished.
343 * In this method you can:
344 * @li schedule next repaint for individual window(s) in case of animations
345 * You shouldn't paint anything here.
347 virtual void postPaintWindow( EffectWindow
* w
);
350 * Can be called to draw multiple copies (e.g. thumbnails) of a window.
351 * You can change window's opacity/brightness/etc here, but you can't
352 * do any transformations
354 virtual void drawWindow( EffectWindow
* w
, int mask
, QRegion region
, WindowPaintData
& data
);
357 * Define new window quads so that they can be transformed by other effects.
358 * It's up to the effect to keep track of them.
360 virtual void buildQuads( EffectWindow
* w
, WindowQuadList
& quadList
);
363 * This function is used e.g. by the shadow effect which adds area around windows
364 * that needs to be painted as well - e.g. when a window is hidden and the workspace needs
365 * to be repainted at that area, shadow's transformWindowDamage() adds the shadow area
366 * to it, so that it is repainted as well.
368 virtual QRect
transformWindowDamage( EffectWindow
* w
, const QRect
& r
);
370 /** called when moved/resized or once after it's finished */
371 virtual void windowUserMovedResized( EffectWindow
* c
, bool first
, bool last
);
372 virtual void windowOpacityChanged( EffectWindow
* c
, double old_opacity
);
373 virtual void windowAdded( EffectWindow
* c
);
374 virtual void windowClosed( EffectWindow
* c
);
375 virtual void windowDeleted( EffectWindow
* c
);
376 virtual void windowActivated( EffectWindow
* c
);
377 virtual void windowMinimized( EffectWindow
* c
);
378 virtual void windowUnminimized( EffectWindow
* c
);
379 virtual void windowInputMouseEvent( Window w
, QEvent
* e
);
380 virtual void desktopChanged( int old
);
381 virtual void windowDamaged( EffectWindow
* w
, const QRect
& r
);
382 virtual void windowGeometryShapeChanged( EffectWindow
* w
, const QRect
& old
);
383 virtual void mouseChanged( const QPoint
& pos
, const QPoint
& oldpos
,
384 Qt::MouseButtons buttons
, Qt::MouseButtons oldbuttons
,
385 Qt::KeyboardModifiers modifiers
, Qt::KeyboardModifiers oldmodifiers
);
386 virtual void grabbedKeyboardEvent( QKeyEvent
* e
);
388 Receives events registered for using EffectsHandler::registerPropertyType().
389 Use readProperty() to get the property data.
390 Note that the property may be already set on the window, so doing the same
391 processing from windowAdded() (e.g. simply calling propertyNotify() from it)
394 virtual void propertyNotify( EffectWindow
* w
, long atom
);
396 virtual void tabBoxAdded( int mode
);
397 virtual void tabBoxClosed();
398 virtual void tabBoxUpdated();
399 virtual bool borderActivated( ElectricBorder border
);
401 static int displayWidth();
402 static int displayHeight();
403 static QPoint
cursorPos();
406 * Read animation time from the configuration and possibly adjust using animationTimeFactor().
407 * The configuration value in the effect should also have special value 'default' (set using
408 * QSpinBox::setSpecialValueText()) with the value 0. This special value is adjusted
409 * using the global animation speed, otherwise the exact time configured is returned.
410 * @param cfg configuration group to read value from
411 * @param key configuration key to read value from
412 * @param defaultTime default animation time in milliseconds
414 // return type is intentionally double so that one can divide using it without losing data
415 static double animationTime( const KConfigGroup
& cfg
, const QString
& key
, int defaultTime
);
417 * @overload Use this variant if the animation time is hardcoded and not configurable
418 * in the effect itself.
420 static double animationTime( int defaultTime
);
422 * Linearly interpolates between @p x and @p y.
424 * Returns @p x when @p a = 0; returns @p y when @p a = 1.
426 static double interpolate(double x
, double y
, double a
)
428 return x
* (1 - a
) + y
* a
;
430 /** Helper to set WindowPaintData and QRegion to necessary transformations so that
431 * a following drawWindow() would put the window at the requested geometry (useful for thumbnails)
433 static void setPositionTransformations( WindowPaintData
& data
, QRect
& region
, EffectWindow
* w
,
434 const QRect
& r
, Qt::AspectRatioMode aspect
);
439 * Defines the class to be used for effect with given name.
440 * The name must be same as effect's X-KDE-PluginInfo-Name values in .desktop
441 * file, but without the "kwin4_effect_" prefix.
442 * E.g. KWIN_EFFECT( flames, MyFlameEffect )
443 * In this case object of MyFlameEffect class would be created when effect
444 * "flames" (which has X-KDE-PluginInfo-Name=kwin4_effect_flames in .desktop
447 #define KWIN_EFFECT( name, classname ) \
449 KWIN_EXPORT Effect* effect_create_kwin4_effect_##name() { return new classname; } \
450 KWIN_EXPORT int effect_version_kwin4_effect_##name() { return KWIN_EFFECT_API_VERSION; } \
453 * Defines the function used to check whether an effect is supported
454 * E.g. KWIN_EFFECT_SUPPORTED( flames, MyFlameEffect::supported() )
456 #define KWIN_EFFECT_SUPPORTED( name, function ) \
458 KWIN_EXPORT bool effect_supported_kwin4_effect_##name() { return function; } \
461 * Defines the function used to retrieve an effect's config widget
462 * E.g. KWIN_EFFECT_CONFIG( flames, MyFlameEffectConfig )
464 #define KWIN_EFFECT_CONFIG( name, classname ) \
465 K_PLUGIN_FACTORY(name##_factory, registerPlugin<classname>();) \
466 K_EXPORT_PLUGIN(name##_factory("kcm_kwineffect_" #name))
469 * The declaration of the factory to export the effect
471 #define KWIN_EFFECT_CONFIG_FACTORY K_PLUGIN_FACTORY_DECLARATION(EffectFactory)
475 * @short Manager class that handles all the effects.
477 * This class creates Effect objects and calls it's appropriate methods.
479 * Effect objects can call methods of this class to interact with the
480 * workspace, e.g. to activate or move a specific window, change current
481 * desktop or create a special input window to receive mouse and keyboard
484 class KWIN_EXPORT EffectsHandler
488 EffectsHandler(CompositingType type
);
489 virtual ~EffectsHandler();
490 // for use by effects
491 virtual void prePaintScreen( ScreenPrePaintData
& data
, int time
) = 0;
492 virtual void paintScreen( int mask
, QRegion region
, ScreenPaintData
& data
) = 0;
493 virtual void postPaintScreen() = 0;
494 virtual void prePaintWindow( EffectWindow
* w
, WindowPrePaintData
& data
, int time
) = 0;
495 virtual void paintWindow( EffectWindow
* w
, int mask
, QRegion region
, WindowPaintData
& data
) = 0;
496 virtual void postPaintWindow( EffectWindow
* w
) = 0;
497 virtual void drawWindow( EffectWindow
* w
, int mask
, QRegion region
, WindowPaintData
& data
) = 0;
498 virtual void buildQuads( EffectWindow
* w
, WindowQuadList
& quadList
) = 0;
499 virtual QRect
transformWindowDamage( EffectWindow
* w
, const QRect
& r
);
500 // Functions for handling input - e.g. when an Expose-like effect is shown, an input window
501 // covering the whole screen is created and all mouse events will be intercepted by it.
502 // The effect's windowInputMouseEvent() will get called with such events.
503 virtual Window
createInputWindow( Effect
* e
, int x
, int y
, int w
, int h
, const QCursor
& cursor
) = 0;
504 Window
createInputWindow( Effect
* e
, const QRect
& r
, const QCursor
& cursor
);
505 virtual Window
createFullScreenInputWindow( Effect
* e
, const QCursor
& cursor
);
506 virtual void destroyInputWindow( Window w
) = 0;
507 virtual QPoint
cursorPos() const = 0;
508 virtual bool grabKeyboard( Effect
* effect
) = 0;
509 virtual void ungrabKeyboard() = 0;
511 virtual void checkElectricBorder(const QPoint
&pos
, Time time
) = 0;
512 virtual void reserveElectricBorder( ElectricBorder border
) = 0;
513 virtual void unreserveElectricBorder( ElectricBorder border
) = 0;
514 virtual void reserveElectricBorderSwitching( bool reserve
) = 0;
516 // functions that allow controlling windows/desktop
517 virtual void activateWindow( EffectWindow
* c
) = 0;
518 virtual EffectWindow
* activeWindow() const = 0 ;
519 virtual void moveWindow( EffectWindow
* w
, const QPoint
& pos
) = 0;
520 virtual void windowToDesktop( EffectWindow
* w
, int desktop
) = 0;
522 virtual int currentDesktop() const = 0;
523 virtual int numberOfDesktops() const = 0;
524 virtual void setCurrentDesktop( int desktop
) = 0;
525 virtual QString
desktopName( int desktop
) const = 0;
526 virtual int activeScreen() const = 0; // Xinerama
527 virtual int numScreens() const = 0; // Xinerama
528 virtual int screenNumber( const QPoint
& pos
) const = 0; // Xinerama
529 virtual QRect
clientArea( clientAreaOption
, int screen
, int desktop
) const = 0;
530 virtual QRect
clientArea( clientAreaOption
, const EffectWindow
* c
) const = 0;
531 virtual QRect
clientArea( clientAreaOption
, const QPoint
& p
, int desktop
) const = 0;
532 virtual void calcDesktopLayout(int* x
, int* y
, Qt::Orientation
* orientation
) const = 0;
533 virtual bool optionRollOverDesktops() const = 0;
534 virtual int desktopToLeft( int desktop
, bool wrap
) const = 0;
535 virtual int desktopToRight( int desktop
, bool wrap
) const = 0;
536 virtual int desktopUp( int desktop
, bool wrap
) const = 0;
537 virtual int desktopDown( int desktop
, bool wrap
) const = 0;
539 * Factor by which animation speed in the effect should be modified (multiplied).
540 * If configurable in the effect itself, the option should have also 'default'
541 * animation speed. The actual value should be determined using animationTime().
542 * Note: The factor can be also 0, so make sure your code can cope with 0ms time
545 virtual double animationTimeFactor() const = 0;
546 virtual WindowQuadType
newWindowQuadType() = 0;
548 virtual EffectWindow
* findWindow( WId id
) const = 0;
549 virtual EffectWindowList
stackingOrder() const = 0;
550 // window will be temporarily painted as if being at the top of the stack
551 virtual void setElevatedWindow( EffectWindow
* w
, bool set
) = 0;
553 virtual void setTabBoxWindow(EffectWindow
*) = 0;
554 virtual void setTabBoxDesktop(int) = 0;
555 virtual EffectWindowList
currentTabBoxWindowList() const = 0;
556 virtual void refTabBox() = 0;
557 virtual void unrefTabBox() = 0;
558 virtual void closeTabBox() = 0;
559 virtual QList
< int > currentTabBoxDesktopList() const = 0;
560 virtual int currentTabBoxDesktop() const = 0;
561 virtual EffectWindow
* currentTabBoxWindow() const = 0;
563 virtual void setActiveFullScreenEffect( Effect
* e
) = 0;
564 virtual Effect
* activeFullScreenEffect() const = 0;
566 virtual void pushRenderTarget(GLRenderTarget
* target
) = 0;
567 virtual GLRenderTarget
* popRenderTarget() = 0;
570 * Schedules the entire workspace to be repainted next time.
571 * If you call it during painting (including prepaint) then it does not
572 * affect the current painting.
574 virtual void addRepaintFull() = 0;
575 virtual void addRepaint( const QRect
& r
) = 0;
576 virtual void addRepaint( const QRegion
& r
) = 0;
577 virtual void addRepaint( int x
, int y
, int w
, int h
) = 0;
579 CompositingType
compositingType() const;
580 virtual unsigned long xrenderBufferPicture() = 0;
581 bool saturationSupported() const;
582 virtual void reconfigure() = 0;
585 Makes KWin core watch PropertyNotify events for the given atom,
586 or stops watching if reg is false (must be called the same number
587 of times as registering). Events are sent using Effect::propertyNotify().
588 Note that even events that haven't been registered for can be received.
590 virtual void registerPropertyType( long atom
, bool reg
) = 0;
593 * Returns @a true if the active window decoration has shadow API hooks.
595 virtual bool hasDecorationShadows() const = 0;
597 * Returns the textures to be used in the shadow. Textures are mapped
598 * to the quad that has the same list offset. E.g. texture[2] is
599 * rendered where the third QRect that EffectWindow::shadowQuads()
602 virtual QList
< QList
<QImage
> > shadowTextures() = 0;
604 * Returns the texture list offset for the requested type.
606 virtual int shadowTextureList( ShadowType type
) const = 0;
609 * Paints given text onto screen, possibly in elided form
611 * @param center center point of the painted text
612 * @param maxwidth if text is longer than this, is will be elided
613 * @param color color of the text, may contain alpha
614 * @param font font for the text
616 bool paintText( const QString
& text
, const QPoint
& center
, int maxwidth
,
617 const QColor
& color
, const QFont
& font
= QFont() );
618 bool paintText( const QString
& text
, const QRect
& rect
, const QColor
& color
,
619 const QFont
& font
= QFont(), const Qt::Alignment
& alignment
= Qt::AlignCenter
);
620 bool paintTextWithBackground( const QString
& text
, const QPoint
& center
, int maxwidth
,
621 const QColor
& color
, const QColor
& bgcolor
,
622 const QFont
& font
= QFont() );
623 bool paintTextWithBackground( const QString
& text
, const QRect
& rect
, const QColor
& color
,
624 const QColor
& bgcolor
, const QFont
& font
= QFont(),
625 const Qt::Alignment
& alignment
= Qt::AlignCenter
);
629 * Sends message over DCOP to reload given effect.
630 * @param effectname effect's name without "kwin4_effect_" prefix.
631 * Can be called from effect's config module to apply config changes.
633 static void sendReloadMessage( const QString
& effectname
);
635 * @return @ref KConfigGroup which holds given effect's config options
637 static KConfigGroup
effectConfig( const QString
& effectname
);
641 QVector
< EffectPair
> loaded_effects
;
642 QHash
< QString
, KLibrary
* > effect_libraries
;
643 QList
< InputWindowPair
> input_windows
;
644 //QHash< QString, EffectFactory* > effect_factories;
645 int current_paint_screen
;
646 int current_paint_window
;
647 int current_draw_window
;
648 int current_build_quads
;
649 int current_transform
;
650 CompositingType compositing_type
;
655 * @short Representation of a window used by/for Effect classes.
657 * The purpose is to hide internal data and also to serve as a single
658 * representation for the case when Client/Unmanaged becomes Deleted.
660 class KWIN_EXPORT EffectWindow
663 /** Flags explaining why painting should be disabled */
666 /** Window will not be painted */
667 PAINT_DISABLED
= 1 << 0,
668 /** Window will not be painted because it is deleted */
669 PAINT_DISABLED_BY_DELETE
= 1 << 1,
670 /** Window will not be painted because of which desktop it's on */
671 PAINT_DISABLED_BY_DESKTOP
= 1 << 2,
672 /** Window will not be painted because it is minimized */
673 PAINT_DISABLED_BY_MINIMIZE
= 1 << 3
677 virtual ~EffectWindow();
679 virtual void enablePainting( int reason
) = 0;
680 virtual void disablePainting( int reason
) = 0;
681 virtual bool isPaintingEnabled() = 0;
682 virtual void addRepaint( const QRect
& r
) = 0;
683 virtual void addRepaint( int x
, int y
, int w
, int h
) = 0;
684 virtual void addRepaintFull() = 0;
686 virtual void refWindow() = 0;
687 virtual void unrefWindow() = 0;
688 virtual bool isDeleted() const = 0;
690 virtual bool isMinimized() const = 0;
691 virtual double opacity() const = 0;
693 virtual bool isOnDesktop( int d
) const;
694 virtual bool isOnCurrentDesktop() const;
695 virtual bool isOnAllDesktops() const = 0;
696 virtual int desktop() const = 0; // prefer isOnXXX()
698 virtual int x() const = 0;
699 virtual int y() const = 0;
700 virtual int width() const = 0;
701 virtual int height() const = 0;
702 virtual QRect
geometry() const = 0;
703 virtual QRegion
shape() const = 0;
704 virtual int screen() const = 0;
705 /** @internal Do not use */
706 virtual bool hasOwnShape() const = 0; // only for shadow effect, for now
707 virtual QPoint
pos() const = 0;
708 virtual QSize
size() const = 0;
709 virtual QRect
rect() const = 0;
710 virtual bool isMovable() const = 0;
711 virtual bool isMovableAcrossScreens() const = 0;
712 virtual bool isUserMove() const = 0;
713 virtual bool isUserResize() const = 0;
714 virtual QRect
iconGeometry() const = 0;
716 * Geometry of the actual window contents inside the whole (including decorations) window.
718 virtual QRect
contentsRect() const = 0;
719 bool hasDecoration() const;
720 virtual QByteArray
readProperty( long atom
, long type
, int format
) const = 0;
722 virtual QString
caption() const = 0;
723 virtual QPixmap
icon() const = 0;
724 virtual QString
windowClass() const = 0;
725 virtual QString
windowRole() const = 0;
726 virtual const EffectWindowGroup
* group() const = 0;
729 * Returns whether the window is a desktop background window (the one with wallpaper).
730 * See _NET_WM_WINDOW_TYPE_DESKTOP at http://standards.freedesktop.org/wm-spec/wm-spec-latest.html .
732 virtual bool isDesktop() const = 0;
734 * Returns whether the window is a dock (i.e. a panel).
735 * See _NET_WM_WINDOW_TYPE_DOCK at http://standards.freedesktop.org/wm-spec/wm-spec-latest.html .
737 virtual bool isDock() const = 0;
739 * Returns whether the window is a standalone (detached) toolbar window.
740 * See _NET_WM_WINDOW_TYPE_TOOLBAR at http://standards.freedesktop.org/wm-spec/wm-spec-latest.html .
742 virtual bool isToolbar() const = 0;
744 * Returns whether the window is standalone menubar (AKA macmenu).
745 * This window type is a KDE extension.
747 virtual bool isTopMenu() const = 0;
749 * Returns whether the window is a torn-off menu.
750 * See _NET_WM_WINDOW_TYPE_MENU at http://standards.freedesktop.org/wm-spec/wm-spec-latest.html .
752 virtual bool isMenu() const = 0;
754 * Returns whether the window is a "normal" window, i.e. an application or any other window
755 * for which none of the specialized window types fit.
756 * See _NET_WM_WINDOW_TYPE_NORMAL at http://standards.freedesktop.org/wm-spec/wm-spec-latest.html .
758 virtual bool isNormalWindow() const = 0; // normal as in 'NET::Normal or NET::Unknown non-transient'
760 * Returns whether the window is any of special windows types (desktop, dock, splash, ...),
761 * i.e. window types that usually don't have a window frame and the user does not use window
762 * management (moving, raising,...) on them.
764 virtual bool isSpecialWindow() const = 0;
766 * Returns whether the window is a dialog window.
767 * See _NET_WM_WINDOW_TYPE_DIALOG at http://standards.freedesktop.org/wm-spec/wm-spec-latest.html .
769 virtual bool isDialog() const = 0;
771 * Returns whether the window is a splashscreen. Note that many (especially older) applications
772 * do not support marking their splash windows with this type.
773 * See _NET_WM_WINDOW_TYPE_SPLASH at http://standards.freedesktop.org/wm-spec/wm-spec-latest.html .
775 virtual bool isSplash() const = 0;
777 * Returns whether the window is a utility window, such as a tool window.
778 * See _NET_WM_WINDOW_TYPE_UTILITY at http://standards.freedesktop.org/wm-spec/wm-spec-latest.html .
780 virtual bool isUtility() const = 0;
782 * Returns whether the window is a dropdown menu (i.e. a popup directly or indirectly open
783 * from the applications menubar).
784 * See _NET_WM_WINDOW_TYPE_DROPDOWN_MENU at http://standards.freedesktop.org/wm-spec/wm-spec-latest.html .
786 virtual bool isDropdownMenu() const = 0;
788 * Returns whether the window is a popup menu (that is not a torn-off or dropdown menu).
789 * See _NET_WM_WINDOW_TYPE_POPUP_MENU at http://standards.freedesktop.org/wm-spec/wm-spec-latest.html .
791 virtual bool isPopupMenu() const = 0; // a context popup, not dropdown, not torn-off
793 * Returns whether the window is a tooltip.
794 * See _NET_WM_WINDOW_TYPE_TOOLTIP at http://standards.freedesktop.org/wm-spec/wm-spec-latest.html .
796 virtual bool isTooltip() const = 0;
798 * Returns whether the window is a window with a notification.
799 * See _NET_WM_WINDOW_TYPE_NOTIFICATION at http://standards.freedesktop.org/wm-spec/wm-spec-latest.html .
801 virtual bool isNotification() const = 0;
803 * Returns whether the window is a combobox popup.
804 * See _NET_WM_WINDOW_TYPE_COMBO at http://standards.freedesktop.org/wm-spec/wm-spec-latest.html .
806 virtual bool isComboBox() const = 0;
808 * Returns whether the window is a Drag&Drop icon.
809 * See _NET_WM_WINDOW_TYPE_DND at http://standards.freedesktop.org/wm-spec/wm-spec-latest.html .
811 virtual bool isDNDIcon() const = 0;
813 * Returns whether the window is managed by KWin (it has control over its placement and other
814 * aspects, as opposed to override-redirect windows that are entirely handled by the application).
816 virtual bool isManaged() const = 0; // whether it's managed or override-redirect
818 virtual bool isModal() const = 0;
819 virtual EffectWindow
* findModal() = 0;
820 virtual EffectWindowList
mainWindows() const = 0;
823 * Returns the positions of the shadow quads to be rendered. All positions
824 * are relative to the window's top-left corner.
826 virtual QList
<QRect
> shadowQuads( ShadowType type
) const = 0;
828 * Returns the desired opacity of the shadow.
830 virtual double shadowOpacity( ShadowType type
) const = 0;
832 * Returns the desired brightness of the shadow.
834 virtual double shadowBrightness( ShadowType type
) const = 0;
836 * Returns the desired saturation of the shadow.
838 virtual double shadowSaturation( ShadowType type
) const = 0;
840 * Returns the unmodified window quad list. Can also be used to force rebuilding.
842 virtual WindowQuadList
buildQuads( bool force
= false ) const = 0;
845 class KWIN_EXPORT EffectWindowGroup
848 virtual ~EffectWindowGroup();
849 virtual EffectWindowList
members() const = 0;
852 class KWIN_EXPORT GlobalShortcutsEditor
: public KShortcutsEditor
855 GlobalShortcutsEditor( QWidget
*parent
);
859 * @short Vertex class
861 * A vertex is one position in a window. WindowQuad consists of four WindowVertex objects
862 * and represents one part of a window.
864 class KWIN_EXPORT WindowVertex
869 void move( double x
, double y
);
870 void setX( double x
);
871 void setY( double y
);
872 double originalX() const;
873 double originalY() const;
874 double textureX() const;
875 double textureY() const;
877 WindowVertex( double x
, double y
, double tx
, double ty
);
879 friend class WindowQuad
;
880 friend class WindowQuadList
;
881 double px
, py
; // position
882 double ox
, oy
; // origional position
883 double tx
, ty
; // texture coords
887 * @short Class representing one area of a window.
889 * WindowQuads consists of four WindowVertex objects and represents one part of a window.
891 // NOTE: This class expects the (original) vertices to be in the clockwise order starting from topleft.
892 class KWIN_EXPORT WindowQuad
895 explicit WindowQuad( WindowQuadType type
, int id
= -1 );
896 WindowQuad
makeSubQuad( double x1
, double y1
, double x2
, double y2
) const;
897 WindowVertex
& operator[]( int index
);
898 const WindowVertex
& operator[]( int index
) const;
899 WindowQuadType
type() const;
901 bool decoration() const;
904 double right() const;
906 double bottom() const;
907 double originalLeft() const;
908 double originalRight() const;
909 double originalTop() const;
910 double originalBottom() const;
911 bool smoothNeeded() const;
912 bool isTransformed() const;
914 friend class WindowQuadList
;
915 WindowVertex verts
[ 4 ];
916 WindowQuadType quadType
; // 0 - contents, 1 - decoration
920 class KWIN_EXPORT WindowQuadList
921 : public QList
< WindowQuad
>
924 WindowQuadList
splitAtX( double x
) const;
925 WindowQuadList
splitAtY( double y
) const;
926 WindowQuadList
makeGrid( int maxquadsize
) const;
927 WindowQuadList
makeRegularGrid( int xSubdivisions
, int ySubdivisions
) const;
928 WindowQuadList
select( WindowQuadType type
) const;
929 WindowQuadList
filterOut( WindowQuadType type
) const;
930 bool smoothNeeded() const;
931 void makeArrays( float** vertices
, float** texcoords
) const;
932 bool isTransformed() const;
935 class KWIN_EXPORT WindowPrePaintData
940 * Region that will be painted, in screen coordinates.
944 * The clip region will be substracted from paint region of following windows.
945 * I.e. window will definitely cover it's clip region
948 WindowQuadList quads
;
950 * Simple helper that sets data to say the window will be painted as non-opaque.
951 * Takes also care of changing the regions.
953 void setTranslucent();
955 * Helper to mark that this window will be transformed
957 void setTransformed();
960 class KWIN_EXPORT WindowPaintData
963 WindowPaintData( EffectWindow
* w
);
965 * Window opacity, in range 0 = transparent to 1 = fully opaque
966 * Opacity for contents is opacity*contents_opacity, the same
967 * way for decoration.
970 double contents_opacity
;
971 double decoration_opacity
;
979 * Saturation of the window, in range [0; 1]
980 * 1 means that the window is unchanged, 0 means that it's completely
981 * unsaturated (greyscale). 0.5 would make the colors less intense,
982 * but not completely grey
983 * Use EffectsHandler::saturationSupported() to find out whether saturation
984 * is supported by the system, otherwise this value has no effect.
988 * Brightness of the window, in range [0; 1]
989 * 1 means that the window is unchanged, 0 means that it's completely
990 * black. 0.5 would make it 50% darker than usual
993 WindowQuadList quads
;
995 * Shader to be used for rendering, if any.
998 RotationData
* rotation
;
1001 class KWIN_EXPORT ScreenPaintData
1011 RotationData
* rotation
;
1014 class KWIN_EXPORT ScreenPrePaintData
1021 class KWIN_EXPORT RotationData
1033 float xRotationPoint
;
1034 float yRotationPoint
;
1035 float zRotationPoint
;
1039 * @short Helper class for restricting painting area only to allowed area.
1041 * This helper class helps specifying areas that should be painted, clipping
1042 * out the rest. The simplest usage is creating an object on the stack
1043 * and giving it the area that is allowed to be painted to. When the object
1044 * is destroyed, the restriction will be removed.
1045 * Note that all painting code must use paintArea() to actually perform the clipping.
1047 class KWIN_EXPORT PaintClipper
1053 PaintClipper( const QRegion
& allowed_area
);
1059 * Allows painting only in the given area. When areas have been already
1060 * specified, painting is allowed only in the intersection of all areas.
1062 static void push( const QRegion
& allowed_area
);
1064 * Removes the given area. It must match the top item in the stack.
1066 static void pop( const QRegion
& allowed_area
);
1068 * Returns true if any clipping should be performed.
1072 * If clip() returns true, this function gives the resulting area in which
1073 * painting is allowed. It is usually simpler to use the helper Iterator class.
1075 static QRegion
paintArea();
1077 * Helper class to perform the clipped painting. The usage is:
1079 * for( PaintClipper::Iterator iterator;
1080 * !iterator.isDone();
1082 * { // do the painting, possibly use iterator.boundingRect()
1086 class KWIN_EXPORT Iterator
1093 QRect
boundingRect() const;
1100 static QStack
< QRegion
>* areas
;
1105 * @short Wrapper class for using timelines in KWin effects.
1107 * This class provides an easy and specialized interface for
1108 * effects that want a non-linear timeline. Currently, most
1109 * it does is wrapping QTimeLine. In the future, this class
1110 * could help using physics animations in KWin.
1112 * KWin effects will usually use this feature by keeping one
1113 * TimeLine per animation, for example per effect (when only
1114 * one animation is done by the effect) or per windows (in
1115 * the case that multiple animations can take place at the
1116 * same time (such as minizing multiple windows with a short
1117 * time offset. Increasing the internal time state of the
1118 * TimeLine is done either by changing the 'current' time in
1119 * the TimeLine, which is an int value between 0 and the
1120 * duration set (defaulting to 250msec). The current time
1121 * can also be changed by setting the 'progress' of the
1122 * TimeLine, a double between 0.0 and 1.0. setProgress(),
1123 * addProgress(), addTime(), removeTime() can all be used to
1124 * manipulate the 'current' time (and at the same time
1125 * progress) of the TimeLine.
1127 * The internal state of the TimeLine is determined by the
1128 * duration of the TimeLine, int in milliseconds, defaulting.
1129 * the 'current' time and the current 'progress' are
1130 * interchangeable, both determine the x-axis of a graph
1131 * of a TimeLine. The value() returned represents the y-axis
1134 * m_TimeLine.setProgress(0.5) would change the 'current'
1135 * time of a default TimeLine to 125 msec. m_TimeLine.value()
1136 * would then return the progress value (a double between 0.0
1137 * and 1.0), which can be lower than 0.5 in case the animation
1138 * should start slowly, such as for the EaseInCurve.
1139 * In KWin effect, the prePaintWindow() or prePaintScreen()
1140 * methods have int time as one of their arguments. This int
1141 * can be used to increase the 'current' time in the TimeLine.
1142 * The double the is subsequently returned by value() (usually
1143 * in paintWindow() or paintScreen() methods can then be used
1144 * to manipulate windows, or their positions.
1146 class KWIN_EXPORT TimeLine
1149 Q_ENUMS( CurveShape
)
1153 * The CurveShape describes the relationship between time
1154 * and values. We can pass some of them through to QTimeLine
1155 * but also invent our own ones.
1167 * Creates a TimeLine and computes the progress data. Usually, for larger
1168 * animations you want to choose values more towards 300 milliseconds.
1169 * For small animations, values around 150 milliseconds are sensible.
1170 * Note that duration 0 is not valid.
1172 explicit TimeLine(int duration
= 0);
1175 * Creates a copy of the TimeLine so we can have the state copied
1178 TimeLine(const TimeLine
&other
);
1184 * Returns the duration of the timeline in msec.
1186 int duration() const;
1188 * Set the duration of the TimeLine.
1190 void setDuration(const int msec
);
1192 * Returns the Value at the time set, this method will
1193 * usually be used to get the progress in the paintWindow()
1194 * and related methods. The value represents the y-axis' value
1195 * corresponding to the current progress (or time) set by
1196 * setProgress(), addProgress(), addTime(), removeTime()
1198 double value() const;
1200 * Returns the Value at the time provided, this method will
1201 * usually be used to get the progress in the paintWindow()
1202 * and related methods, the y value of the current state x.
1204 double valueForTime(const int msec
) const;
1206 * Returns the current time of the TimeLine, between 0 and duration()
1207 * The value returned is equivalent to the x-axis on a curve.
1211 * Returns the progress of the TimeLine, between 0.0 and 1.0.
1212 * The value returned is equivalent to the y-axis on a curve.
1214 double progress() const;
1216 * Increases the internal progress accounting of the timeline.
1218 void addProgress(const double progress
);
1220 * Increases the internal counter, this is usually done in
1223 void addTime(const int msec
);
1225 * Decreases the internal counter, this is usually done in
1226 * prePaintWindow(). This function comes handy for reverse
1229 void removeTime(const int msec
);
1231 * Set the time to progress * duration. This will change the
1232 * internal time in the TimeLine. It's usually used in
1233 * prePaintWindow() or prePaintScreen() so the value()
1234 * taken in paint* is increased.
1236 void setProgress(const double progress
);
1238 * Set the CurveShape. The CurveShape describes the relation
1239 * between the value and the time. progress is between 0 and 1
1240 * It's used as input for the timeline, the x axis of the curve.
1242 void setCurveShape(CurveShape curveShape
);
1244 * Set the CurveShape. The CurveShape describes the relation
1245 * between the value and the time.
1247 //void setCurveShape(CurveShape curveShape);
1250 QTimeLine
* m_TimeLine
;
1254 CurveShape m_CurveShape
;
1255 //Q_DISABLE_COPY(TimeLine)
1259 * @short A single motion dynamics object.
1261 * This class represents a single object that can be moved around a
1262 * n-dimensional space. Although it can be used directly by itself
1263 * it is recommended to use a motion manager instead.
1265 * To create a 1D motion object use Motion<double>
1266 * To create a 2D motion object use Motion<QRectF>
1268 template <typename T
>
1269 class KWIN_EXPORT Motion
1273 * Creates a new motion object. "Strength" is the amount of
1274 * acceleration that is applied to the object when the target
1275 * changes and "decay" relates to the amount of overshoot
1276 * once the object reaches the target. A decay of 1.0 will
1277 * cause never-ending oscillation and while a decay of 0.0
1278 * will cause no overshoot.
1280 explicit Motion( T initial
= T(), double strength
= 7.5, double decay
= 0.5 );
1282 * Creates an exact copy of another motion object, including
1283 * position, target and velocity.
1285 Motion( const Motion
<T
> &other
);
1288 inline T
value() const { return m_value
; }
1289 inline void setValue( const T value
) { m_value
= value
; }
1290 inline T
target() const { return m_target
; }
1291 inline void setTarget( const T target
) { m_target
= target
; }
1292 inline T
velocity() const { return m_velocity
; }
1293 inline void setVelocity( const T velocity
) { m_velocity
= velocity
; }
1295 inline double strength() const { return m_strength
; }
1296 inline void setStrength( const double strength
) { m_strength
= strength
; }
1297 inline double decay() const { return m_decay
; }
1298 inline void setDecay( const double decay
) { m_decay
= decay
; }
1299 inline void setStrengthDecay( const double strength
, const double decay
)
1300 { m_strength
= strength
; m_decay
= decay
; }
1303 * The distance between the current position and the target.
1305 inline T
distance() const { return m_target
- m_value
; }
1308 * Calculates the new position if not at the target. Called
1309 * once per frame only.
1311 void calculate( const int msec
);
1313 * Place the object on top of the target immediately,
1314 * bypassing all movement calculation.
1328 * @short Helper class for motion dynamics in KWin effects.
1330 * This motion manager class is intended to help KWin effect authors
1331 * move windows across the screen smoothly and naturally. Once
1332 * windows are registered by the manager the effect can issue move
1333 * commands with the moveWindow() methods. The position of any
1334 * managed window can be determined in realtime by the
1335 * transformedGeometry() method. As the manager knows if any windows
1336 * are moving at any given time it can also be used as a notifier as
1337 * to see whether the effect is active or not.
1339 class KWIN_EXPORT WindowMotionManager
1343 * Creates a new window manager object.
1345 explicit WindowMotionManager( bool useGlobalAnimationModifier
= true );
1346 ~WindowMotionManager();
1349 * Register a window for managing.
1351 void manage( EffectWindow
*w
);
1353 * Register a list of windows for managing.
1355 inline void manage( EffectWindowList list
)
1357 for( int i
= 0; i
< list
.size(); i
++ )
1358 manage( list
.at( i
));
1361 * Deregister a window. All transformations applied to the
1362 * window will be permanently removed and cannot be recovered.
1364 void unmanage( EffectWindow
*w
);
1366 * Deregister all windows, returning the manager to it's
1367 * originally initiated state.
1371 * Determine the new positions for windows that have not
1372 * reached their target. Called once per frame, usually in
1373 * prePaintScreen(). Remember to set the
1374 * Effect::PAINT_SCREEN_WITH_TRANSFORMED_WINDOWS flag.
1376 void calculate( int time
);
1378 * Modify a registered window's paint data to make it appear
1379 * at it's real location on the screen. Usually called in
1380 * paintWindow(). Remember to flag the window as having been
1381 * transformed in prePaintWindow() by calling
1382 * WindowPrePaintData::setTransformed()
1384 void apply( EffectWindow
*w
, WindowPaintData
&data
);
1386 * Set all motion targets and values back to where the
1387 * windows were before transformations. The same as
1388 * unmanaging then remanaging all windows.
1392 * Resets the motion target and current value of a single
1395 void reset( EffectWindow
*w
);
1398 * As the manager to move the window to the target position
1399 * with the specified scale. If `yScale` is not provided or
1400 * set to 0.0, `scale` will be used as the scale in the
1401 * vertical direction as well as in the horizontal direction.
1403 void moveWindow( EffectWindow
*w
, QPoint target
, double scale
= 1.0, double yScale
= 0.0 );
1405 * This is an overloaded method, provided for convenience.
1407 * Ask the manager to move the window to the target rectangle.
1408 * Automatically determines scale.
1410 inline void moveWindow( EffectWindow
*w
, QRect target
)
1412 // TODO: Scale might be slightly different in the comparison due to rounding
1413 moveWindow( w
, target
.topLeft(),
1414 target
.width() / double( w
->width() ), target
.height() / double( w
->height() ));
1418 * Retrieve the current tranformed geometry of a registered
1421 QRectF
transformedGeometry( EffectWindow
*w
) const;
1423 * Return the window that has it's transformed geometry under
1424 * the specified point. It is recommended to use the stacking
1425 * order as it's what the user sees, but it is slightly
1426 * slower to process.
1428 EffectWindow
* windowAtPoint( QPoint point
, bool useStackingOrder
= true ) const;
1431 * Return a list of all currently registered windows.
1433 inline EffectWindowList
managedWindows() const { return m_managedWindows
.keys(); }
1435 * Returns whether or not a specified window is being managed
1436 * by this manager object.
1438 inline bool isManaging( EffectWindow
*w
) { return m_managedWindows
.contains( w
); }
1440 * Returns whether or not this manager object is actually
1441 * managing any windows or not.
1443 inline bool managingWindows() { return !m_managedWindows
.empty(); }
1445 * Returns whether all windows have reached their targets yet
1446 * or not. Can be used to see if an effect should be
1447 * processed and displayed or not.
1449 inline bool areWindowsMoving() { return m_movingWindows
> 0; }
1452 bool m_useGlobalAnimationModifier
;
1454 { // TODO: Rotation, etc?
1455 Motion
<QPointF
> translation
; // Absolute position
1456 Motion
<QPointF
> scale
; // xScale and yScale
1458 QHash
<EffectWindow
*, WindowMotion
> m_managedWindows
;
1459 uint m_movingWindows
;
1463 * Pointer to the global EffectsHandler object.
1465 extern KWIN_EXPORT EffectsHandler
* effects
;
1467 /***************************************************************
1469 ***************************************************************/
1472 bool EffectsHandler::paintText( const QString
& text
, const QPoint
& center
, int maxwidth
,
1473 const QColor
& color
, const QFont
& font
)
1475 return paintText( text
, QRect( center
.x() - maxwidth
/ 2, center
.y() - 5000, maxwidth
, 10000 ),
1476 color
, font
, Qt::AlignCenter
);
1480 bool EffectsHandler::paintTextWithBackground( const QString
& text
, const QPoint
& center
, int maxwidth
,
1481 const QColor
& color
, const QColor
& bgcolor
, const QFont
& font
)
1483 return paintTextWithBackground( text
,
1484 QRect( center
.x() - maxwidth
/ 2, center
.y() - 5000, maxwidth
, 10000 ),
1485 color
, bgcolor
, font
, Qt::AlignCenter
);
1488 /***************************************************************
1490 ***************************************************************/
1493 WindowVertex::WindowVertex()
1494 : px( 0 ), py( 0 ), tx( 0 ), ty( 0 )
1499 WindowVertex::WindowVertex( double _x
, double _y
, double _tx
, double _ty
)
1500 : px( _x
), py( _y
), ox( _x
), oy( _y
), tx( _tx
), ty( _ty
)
1505 double WindowVertex::x() const
1511 double WindowVertex::y() const
1517 double WindowVertex::originalX() const
1523 double WindowVertex::originalY() const
1529 double WindowVertex::textureX() const
1535 double WindowVertex::textureY() const
1541 void WindowVertex::move( double x
, double y
)
1548 void WindowVertex::setX( double x
)
1554 void WindowVertex::setY( double y
)
1559 /***************************************************************
1561 ***************************************************************/
1564 WindowQuad::WindowQuad( WindowQuadType t
, int id
)
1571 WindowVertex
& WindowQuad::operator[]( int index
)
1573 assert( index
>= 0 && index
< 4 );
1574 return verts
[ index
];
1578 const WindowVertex
& WindowQuad::operator[]( int index
) const
1580 assert( index
>= 0 && index
< 4 );
1581 return verts
[ index
];
1585 WindowQuadType
WindowQuad::type() const
1587 assert( quadType
!= WindowQuadError
);
1592 int WindowQuad::id() const
1598 bool WindowQuad::decoration() const
1600 assert( quadType
!= WindowQuadError
);
1601 return quadType
== WindowQuadDecoration
;
1605 bool WindowQuad::effect() const
1607 assert( quadType
!= WindowQuadError
);
1608 return quadType
>= EFFECT_QUAD_TYPE_START
;
1612 bool WindowQuad::isTransformed() const
1614 return !( verts
[ 0 ].px
== verts
[ 0 ].ox
&& verts
[ 0 ].py
== verts
[ 0 ].oy
1615 && verts
[ 1 ].px
== verts
[ 1 ].ox
&& verts
[ 1 ].py
== verts
[ 1 ].oy
1616 && verts
[ 2 ].px
== verts
[ 2 ].ox
&& verts
[ 2 ].py
== verts
[ 2 ].oy
1617 && verts
[ 3 ].px
== verts
[ 3 ].ox
&& verts
[ 3 ].py
== verts
[ 3 ].oy
);
1621 double WindowQuad::left() const
1623 return qMin( verts
[ 0 ].px
, qMin( verts
[ 1 ].px
, qMin( verts
[ 2 ].px
, verts
[ 3 ].px
)));
1627 double WindowQuad::right() const
1629 return qMax( verts
[ 0 ].px
, qMax( verts
[ 1 ].px
, qMax( verts
[ 2 ].px
, verts
[ 3 ].px
)));
1633 double WindowQuad::top() const
1635 return qMin( verts
[ 0 ].py
, qMin( verts
[ 1 ].py
, qMin( verts
[ 2 ].py
, verts
[ 3 ].py
)));
1639 double WindowQuad::bottom() const
1641 return qMax( verts
[ 0 ].py
, qMax( verts
[ 1 ].py
, qMax( verts
[ 2 ].py
, verts
[ 3 ].py
)));
1645 double WindowQuad::originalLeft() const
1647 return verts
[ 0 ].ox
;
1651 double WindowQuad::originalRight() const
1653 return verts
[ 2 ].ox
;
1657 double WindowQuad::originalTop() const
1659 return verts
[ 0 ].oy
;
1663 double WindowQuad::originalBottom() const
1665 return verts
[ 2 ].oy
;
1668 /***************************************************************
1670 ***************************************************************/
1672 template <typename T
>
1673 Motion
<T
>::Motion( T initial
, double strength
, double decay
)
1674 : m_value( initial
)
1675 , m_target( initial
)
1677 , m_strength( strength
)
1682 template <typename T
>
1683 Motion
<T
>::Motion( const Motion
&other
)
1684 : m_value( other
.value() )
1685 , m_target( other
.target() )
1686 , m_velocity( other
.velocity() )
1687 , m_strength( other
.strength() )
1688 , m_decay( other
.decay() )
1692 template <typename T
>
1693 Motion
<T
>::~Motion()
1697 template <typename T
>
1698 void Motion
<T
>::calculate( const int msec
)
1700 if( m_value
== m_target
&& m_velocity
== T() ) // At target and not moving
1703 double delta
= qMin( 1.0, double( msec
) / 100.0 );
1704 T diff
= m_target
- m_value
;
1705 T strength
= diff
* m_strength
;
1706 m_velocity
= m_decay
* m_velocity
* ( 1.0 - delta
) * ( 1.0 - delta
)
1707 + strength
* delta
; // TODO/HACK: Need to work out correct formula
1708 m_value
+= m_velocity
;
1711 template <typename T
>
1712 void Motion
<T
>::finish()
1722 #endif // KWINEFFECTS_H