1/********************************************************************
2 KWin - the KDE window manager
3 This file is part of the KDE project.
4
5Copyright (C) 2006 Lubos Lunak <l.lunak@kde.org>
6Copyright (C) 2009 Lucas Murray <lmurray@undefinedfire.com>
7Copyright (C) 2010, 2011 Martin Gräßlin <mgraesslin@kde.org>
8
9This program is free software; you can redistribute it and/or modify
10it under the terms of the GNU General Public License as published by
11the Free Software Foundation; either version 2 of the License, or
12(at your option) any later version.
13
14This program is distributed in the hope that it will be useful,
15but WITHOUT ANY WARRANTY; without even the implied warranty of
16MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17GNU General Public License for more details.
18
19You should have received a copy of the GNU General Public License
20along with this program. If not, see <http://www.gnu.org/licenses/>.
21*********************************************************************/
22
23#ifndef KWINEFFECTS_H
24#define KWINEFFECTS_H
25
26#include <kwinconfig.h>
27#include <kwinglobals.h>
28
29#include <QPair>
30#include <QSet>
31#include <QRect>
32#include <QtGui/QRegion>
33#include <QtGui/QVector2D>
34#include <QtGui/QVector3D>
35
36#include <QVector>
37#include <QList>
38#include <QHash>
39#include <QStack>
40
41#include <KDE/KPluginFactory>
42#include <KDE/KShortcutsEditor>
43
44#include <assert.h>
45#include <limits.h>
46#include <netwm.h>
47
48class KLibrary;
49class KConfigGroup;
50class KActionCollection;
51class QFont;
52class QGraphicsScale;
53class QKeyEvent;
54class QMatrix4x4;
55
56namespace KWin
57{
58
59class PaintDataPrivate;
60class WindowPaintDataPrivate;
61
62class EffectWindow;
63class EffectWindowGroup;
64class EffectFrame;
65class EffectFramePrivate;
66class Effect;
67class WindowQuad;
68class GLShader;
69class XRenderPicture;
70class WindowQuadList;
71class WindowPrePaintData;
72class WindowPaintData;
73class ScreenPrePaintData;
74class ScreenPaintData;
75
76typedef QPair< QString, Effect* > EffectPair;
77typedef QList< KWin::EffectWindow* > EffectWindowList;
78
79
80/** @defgroup kwineffects KWin effects library
81 * KWin effects library contains necessary classes for creating new KWin
82 * compositing effects.
83 *
84 * @section creating Creating new effects
85 * This example will demonstrate the basics of creating an effect. We'll use
86 * CoolEffect as the class name, cooleffect as internal name and
87 * "Cool Effect" as user-visible name of the effect.
88 *
89 * This example doesn't demonstrate how to write the effect's code. For that,
90 * see the documentation of the Effect class.
91 *
92 * @subsection creating-class CoolEffect class
93 * First you need to create CoolEffect class which has to be a subclass of
94 * @ref KWin::Effect. In that class you can reimplement various virtual
95 * methods to control how and where the windows are drawn.
96 *
97 * @subsection creating-macro KWIN_EFFECT macro
98 * To make KWin aware of your new effect, you first need to use the
99 * @ref KWIN_EFFECT macro to connect your effect's class to it's internal
100 * name. The internal name is used by KWin to identify your effect. It can be
101 * freely chosen (although it must be a single word), must be unique and won't
102 * be shown to the user. For our example, you would use the macro like this:
103 * @code
104 * KWIN_EFFECT(cooleffect, CoolEffect)
105 * @endcode
106 *
107 * @subsection creating-buildsystem Buildsystem
108 * To build the effect, you can use the KWIN_ADD_EFFECT() cmake macro which
109 * can be found in effects/CMakeLists.txt file in KWin's source. First
110 * argument of the macro is the name of the library that will contain
111 * your effect. Although not strictly required, it is usually a good idea to
112 * use the same name as your effect's internal name there. Following arguments
113 * to the macro are the files containing your effect's source. If our effect's
114 * source is in cooleffect.cpp, we'd use following:
115 * @code
116 * KWIN_ADD_EFFECT(cooleffect cooleffect.cpp)
117 * @endcode
118 *
119 * This macro takes care of compiling your effect. You'll also need to install
120 * your effect's .desktop file, so the example CMakeLists.txt file would be
121 * as follows:
122 * @code
123 * KWIN_ADD_EFFECT(cooleffect cooleffect.cpp)
124 * install( FILES cooleffect.desktop DESTINATION ${SERVICES_INSTALL_DIR}/kwin )
125 * @endcode
126 *
127 * @subsection creating-desktop Effect's .desktop file
128 * You will also need to create .desktop file to set name, description, icon
129 * and other properties of your effect. Important fields of the .desktop file
130 * are:
131 * @li Name User-visible name of your effect
132 * @li Icon Name of the icon of the effect
133 * @li Comment Short description of the effect
134 * @li Type must be "Service"
135 * @li X-KDE-ServiceTypes must be "KWin/Effect"
136 * @li X-KDE-PluginInfo-Name effect's internal name as passed to the KWIN_EFFECT macro plus "kwin4_effect_" prefix
137 * @li X-KDE-PluginInfo-Category effect's category. Should be one of Appearance, Accessibility, Window Management, Demos, Tests, Misc
138 * @li X-KDE-PluginInfo-EnabledByDefault whether the effect should be enabled by default (use sparingly). Default is false
139 * @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.
140 *
141 * Example cooleffect.desktop file follows:
142 * @code
143[Desktop Entry]
144Name=Cool Effect
145Comment=The coolest effect you've ever seen
146Icon=preferences-system-windows-effect-cooleffect
147
148Type=Service
149X-KDE-ServiceTypes=KWin/Effect
150X-KDE-PluginInfo-Author=My Name
151X-KDE-PluginInfo-Email=my@email.here
152X-KDE-PluginInfo-Name=kwin4_effect_cooleffect
153X-KDE-PluginInfo-Category=Misc
154X-KDE-Library=kwin4_effect_cooleffect
155 * @endcode
156 *
157 *
158 * @section accessing Accessing windows and workspace
159 * Effects can gain access to the properties of windows and workspace via
160 * EffectWindow and EffectsHandler classes.
161 *
162 * There is one global EffectsHandler object which you can access using the
163 * @ref effects pointer.
164 * For each window, there is an EffectWindow object which can be used to read
165 * window properties such as position and also to change them.
166 *
167 * For more information about this, see the documentation of the corresponding
168 * classes.
169 *
170 * @{
171 **/
172
173#define KWIN_EFFECT_API_MAKE_VERSION( major, minor ) (( major ) << 8 | ( minor ))
174#define KWIN_EFFECT_API_VERSION_MAJOR 0
175#define KWIN_EFFECT_API_VERSION_MINOR 224
176#define KWIN_EFFECT_API_VERSION KWIN_EFFECT_API_MAKE_VERSION( \
177 KWIN_EFFECT_API_VERSION_MAJOR, KWIN_EFFECT_API_VERSION_MINOR )
178
179enum WindowQuadType {
180 WindowQuadError, // for the stupid default ctor
181 WindowQuadContents,
182 WindowQuadDecorationLeftRight,
183 WindowQuadDecorationTopBottom,
184 // Shadow Quad types
185 WindowQuadShadowTop,
186 WindowQuadShadowTopRight,
187 WindowQuadShadowRight,
188 WindowQuadShadowBottomRight,
189 WindowQuadShadowBottom,
190 WindowQuadShadowBottomLeft,
191 WindowQuadShadowLeft,
192 WindowQuadShadowTopLeft,
193 EFFECT_QUAD_TYPE_START = 100 ///< @internal
194};
195
196/**
197 * EffectWindow::setData() and EffectWindow::data() global roles.
198 * All values between 0 and 999 are reserved for global roles.
199 */
200enum DataRole {
201 // Grab roles are used to force all other animations to ignore the window.
202 // The value of the data is set to the Effect's `this` value.
203 WindowAddedGrabRole = 1,
204 WindowClosedGrabRole,
205 WindowMinimizedGrabRole,
206 WindowUnminimizedGrabRole,
207 WindowForceBlurRole, ///< For fullscreen effects to enforce blurring of windows,
208 WindowBlurBehindRole, ///< For single windows to blur behind
209 LanczosCacheRole
210};
211
212/**
213 * Style types used by @ref EffectFrame.
214 * @since 4.6
215 */
216enum EffectFrameStyle {
217 EffectFrameNone, ///< Displays no frame around the contents.
218 EffectFrameUnstyled, ///< Displays a basic box around the contents.
219 EffectFrameStyled ///< Displays a Plasma-styled frame around the contents.
220};
221
222/**
223 * Infinite region (i.e. a special region type saying that everything needs to be painted).
224 */
225KWIN_EXPORT inline
226QRect infiniteRegion()
227{
228 // INT_MIN / 2 because width/height is used (INT_MIN+INT_MAX==-1)
229 return QRect(INT_MIN / 2, INT_MIN / 2, INT_MAX, INT_MAX);
230}
231
232/**
233 * @short Base class for all KWin effects
234 *
235 * This is the base class for all effects. By reimplementing virtual methods
236 * of this class, you can customize how the windows are painted.
237 *
238 * The virtual methods are used for painting and need to be implemented for
239 * custom painting.
240 *
241 * In order to react to state changes (e.g. a window gets closed) the effect
242 * should provide slots for the signals emitted by the EffectsHandler.
243 *
244 * @section Chaining
245 * Most methods of this class are called in chain style. This means that when
246 * effects A and B area active then first e.g. A::paintWindow() is called and
247 * then from within that method B::paintWindow() is called (although
248 * indirectly). To achieve this, you need to make sure to call corresponding
249 * method in EffectsHandler class from each such method (using @ref effects
250 * pointer):
251 * @code
252 * void MyEffect::postPaintScreen()
253 * {
254 * // Do your own processing here
255 * ...
256 * // Call corresponding EffectsHandler method
257 * effects->postPaintScreen();
258 * }
259 * @endcode
260 *
261 * @section Effectsptr Effects pointer
262 * @ref effects pointer points to the global EffectsHandler object that you can
263 * use to interact with the windows.
264 *
265 * @section painting Painting stages
266 * Painting of windows is done in three stages:
267 * @li First, the prepaint pass.<br>
268 * Here you can specify how the windows will be painted, e.g. that they will
269 * be translucent and transformed.
270 * @li Second, the paint pass.<br>
271 * Here the actual painting takes place. You can change attributes such as
272 * opacity of windows as well as apply transformations to them. You can also
273 * paint something onto the screen yourself.
274 * @li Finally, the postpaint pass.<br>
275 * Here you can mark windows, part of windows or even the entire screen for
276 * repainting to create animations.
277 *
278 * For each stage there are *Screen() and *Window() methods. The window method
279 * is called for every window which the screen method is usually called just
280 * once.
281 **/
282class KWIN_EXPORT Effect : public QObject
283{
284 Q_OBJECT
285public:
286 /** Flags controlling how painting is done. */
287 // TODO: is that ok here?
288 enum {
289 /**
290 * Window (or at least part of it) will be painted opaque.
291 **/
292 PAINT_WINDOW_OPAQUE = 1 << 0,
293 /**
294 * Window (or at least part of it) will be painted translucent.
295 **/
296 PAINT_WINDOW_TRANSLUCENT = 1 << 1,
297 /**
298 * Window will be painted with transformed geometry.
299 **/
300 PAINT_WINDOW_TRANSFORMED = 1 << 2,
301 /**
302 * Paint only a region of the screen (can be optimized, cannot
303 * be used together with TRANSFORMED flags).
304 **/
305 PAINT_SCREEN_REGION = 1 << 3,
306 /**
307 * The whole screen will be painted with transformed geometry.
308 * Forces the entire screen to be painted.
309 **/
310 PAINT_SCREEN_TRANSFORMED = 1 << 4,
311 /**
312 * At least one window will be painted with transformed geometry.
313 * Forces the entire screen to be painted.
314 **/
315 PAINT_SCREEN_WITH_TRANSFORMED_WINDOWS = 1 << 5,
316 /**
317 * Clear whole background as the very first step, without optimizing it
318 **/
319 PAINT_SCREEN_BACKGROUND_FIRST = 1 << 6,
320 // PAINT_DECORATION_ONLY = 1 << 7 has been deprecated
321 /**
322 * Window will be painted with a lanczos filter.
323 **/
324 PAINT_WINDOW_LANCZOS = 1 << 8
325 // PAINT_SCREEN_WITH_TRANSFORMED_WINDOWS_WITHOUT_FULL_REPAINTS = 1 << 9 has been removed
326 };
327
328 enum Feature {
329 Nothing = 0, Resize, GeometryTip, Outline, ScreenInversion, Blur
330 };
331
332 /**
333 * Constructs new Effect object.
334 **/
335 Effect();
336 /**
337 * Destructs the Effect object.
338 **/
339 virtual ~Effect();
340
341 /**
342 * Flags describing which parts of configuration have changed.
343 */
344 enum ReconfigureFlag {
345 ReconfigureAll = 1 << 0 /// Everything needs to be reconfigured.
346 };
347 Q_DECLARE_FLAGS(ReconfigureFlags, ReconfigureFlag)
348
349 /**
350 * Called when configuration changes (either the effect's or KWin's global).
351 */
352 virtual void reconfigure(ReconfigureFlags flags);
353
354 /**
355 * Called when another effect requests the proxy for this effect.
356 */
357 virtual void* proxy();
358
359 /**
360 * Called before starting to paint the screen.
361 * In this method you can:
362 * @li set whether the windows or the entire screen will be transformed
363 * @li change the region of the screen that will be painted
364 * @li do various housekeeping tasks such as initing your effect's variables
365 for the upcoming paint pass or updating animation's progress
366 **/
367 virtual void prePaintScreen(ScreenPrePaintData& data, int time);
368 /**
369 * In this method you can:
370 * @li paint something on top of the windows (by painting after calling
371 * effects->paintScreen())
372 * @li paint multiple desktops and/or multiple copies of the same desktop
373 * by calling effects->paintScreen() multiple times
374 **/
375 virtual void paintScreen(int mask, QRegion region, ScreenPaintData& data);
376 /**
377 * Called after all the painting has been finished.
378 * In this method you can:
379 * @li schedule next repaint in case of animations
380 * You shouldn't paint anything here.
381 **/
382 virtual void postPaintScreen();
383
384 /**
385 * Called for every window before the actual paint pass
386 * In this method you can:
387 * @li enable or disable painting of the window (e.g. enable paiting of minimized window)
388 * @li set window to be painted with translucency
389 * @li set window to be transformed
390 * @li request the window to be divided into multiple parts
391 **/
392 virtual void prePaintWindow(EffectWindow* w, WindowPrePaintData& data, int time);
393 /**
394 * This is the main method for painting windows.
395 * In this method you can:
396 * @li do various transformations
397 * @li change opacity of the window
398 * @li change brightness and/or saturation, if it's supported
399 **/
400 virtual void paintWindow(EffectWindow* w, int mask, QRegion region, WindowPaintData& data);
401 /**
402 * Called for every window after all painting has been finished.
403 * In this method you can:
404 * @li schedule next repaint for individual window(s) in case of animations
405 * You shouldn't paint anything here.
406 **/
407 virtual void postPaintWindow(EffectWindow* w);
408
409 /**
410 * This method is called directly before painting an @ref EffectFrame.
411 * You can implement this method if you need to bind a shader or perform
412 * other operations before the frame is rendered.
413 * @param frame The EffectFrame which will be rendered
414 * @param region Region to restrict painting to
415 * @param opacity Opacity of text/icon
416 * @param frameOpacity Opacity of background
417 * @since 4.6
418 **/
419 virtual void paintEffectFrame(EffectFrame* frame, QRegion region, double opacity, double frameOpacity);
420
421 /**
422 * Called on Transparent resizes.
423 * return true if your effect substitutes questioned feature
424 */
425 virtual bool provides(Feature);
426
427 /**
428 * Can be called to draw multiple copies (e.g. thumbnails) of a window.
429 * You can change window's opacity/brightness/etc here, but you can't
430 * do any transformations
431 **/
432 virtual void drawWindow(EffectWindow* w, int mask, QRegion region, WindowPaintData& data);
433
434 /**
435 * Define new window quads so that they can be transformed by other effects.
436 * It's up to the effect to keep track of them.
437 **/
438 virtual void buildQuads(EffectWindow* w, WindowQuadList& quadList);
439
440 virtual void windowInputMouseEvent(QEvent* e);
441 virtual void grabbedKeyboardEvent(QKeyEvent* e);
442
443 /**
444 * Overwrite this method to indicate whether your effect will be doing something in
445 * the next frame to be rendered. If the method returns @c false the effect will be
446 * excluded from the chained methods in the next rendered frame.
447 *
448 * This method is called always directly before the paint loop begins. So it is totally
449 * fine to e.g. react on a window event, issue a repaint to trigger an animation and
450 * change a flag to indicate that this method returns @c true.
451 *
452 * As the method is called each frame, you should not perform complex calculations.
453 * Best use just a boolean flag.
454 *
455 * The default implementation of this method returns @c true.
456 * @since 4.8
457 **/
458 virtual bool isActive() const;
459
460 /**
461 * Reimplement this method to provide online debugging.
462 * This could be as trivial as printing specific detail informations about the effect state
463 * but could also be used to move the effect in and out of a special debug modes, clear bogus
464 * data, etc.
465 * Notice that the functions is const by intent! Whenever you alter the state of the object
466 * due to random user input, you should do so with greatest care, hence const_cast<> your
467 * object - signalling "let me alone, i know what i'm doing"
468 * @param parameter A freeform string user input for your effect to interpret.
469 * @since 4.11
470 */
471 virtual QString debug(const QString &parameter) const;
472
473 static int displayWidth();
474 static int displayHeight();
475 static QPoint cursorPos();
476
477 /**
478 * Read animation time from the configuration and possibly adjust using animationTimeFactor().
479 * The configuration value in the effect should also have special value 'default' (set using
480 * QSpinBox::setSpecialValueText()) with the value 0. This special value is adjusted
481 * using the global animation speed, otherwise the exact time configured is returned.
482 * @param cfg configuration group to read value from
483 * @param key configuration key to read value from
484 * @param defaultTime default animation time in milliseconds
485 */
486 // return type is intentionally double so that one can divide using it without losing data
487 static double animationTime(const KConfigGroup& cfg, const QString& key, int defaultTime);
488 /**
489 * @overload Use this variant if the animation time is hardcoded and not configurable
490 * in the effect itself.
491 */
492 static double animationTime(int defaultTime);
493 /**
494 * @overload Use this variant if animation time is provided through a KConfigXT generated class
495 * having a property called "duration".
496 **/
497 template <typename T>
498 int animationTime(int defaultDuration);
499 /**
500 * Linearly interpolates between @p x and @p y.
501 *
502 * Returns @p x when @p a = 0; returns @p y when @p a = 1.
503 **/
504 static double interpolate(double x, double y, double a) {
505 return x * (1 - a) + y * a;
506 }
507 /** Helper to set WindowPaintData and QRegion to necessary transformations so that
508 * a following drawWindow() would put the window at the requested geometry (useful for thumbnails)
509 **/
510 static void setPositionTransformations(WindowPaintData& data, QRect& region, EffectWindow* w,
511 const QRect& r, Qt::AspectRatioMode aspect);
512
513public Q_SLOTS:
514 virtual bool borderActivated(ElectricBorder border);
515};
516
517
518/**
519 * Defines the class to be used for effect with given name.
520 * The name must be same as effect's X-KDE-PluginInfo-Name values in .desktop
521 * file, but without the "kwin4_effect_" prefix.
522 * E.g. KWIN_EFFECT( flames, MyFlameEffect )
523 * In this case object of MyFlameEffect class would be created when effect
524 * "flames" (which has X-KDE-PluginInfo-Name=kwin4_effect_flames in .desktop
525 * file) is loaded.
526 **/
527#define KWIN_EFFECT( name, classname ) \
528 extern "C" { \
529 KWIN_EXPORT Effect* effect_create_kwin4_effect_##name() { return new classname; } \
530 KWIN_EXPORT int effect_version_kwin4_effect_##name() { return KWIN_EFFECT_API_VERSION; } \
531 }
532
533/**
534 * Defines the function used to check whether an effect is supported
535 * E.g. KWIN_EFFECT_SUPPORTED( flames, MyFlameEffect::supported() )
536 **/
537#define KWIN_EFFECT_SUPPORTED( name, function ) \
538 extern "C" { \
539 KWIN_EXPORT bool effect_supported_kwin4_effect_##name() { return function; } \
540 }
541
542/**
543 * Defines the function used to check whether an effect should be enabled by default
544 *
545 * This function provides a way for an effect to override the default at runtime,
546 * e.g. based on the capabilities of the hardware.
547 *
548 * This function is optional; the effect doesn't have to provide it.
549 *
550 * Note that this function is only called if the supported() function returns true,
551 * and if X-KDE-PluginInfo-EnabledByDefault is set to true in the .desktop file.
552 *
553 * Example: KWIN_EFFECT_ENABLEDBYDEFAULT(flames, MyFlameEffect::enabledByDefault())
554 **/
555#define KWIN_EFFECT_ENABLEDBYDEFAULT(name, function) \
556 extern "C" { \
557 KWIN_EXPORT bool effect_enabledbydefault_kwin4_effect_##name() { return function; } \
558 }
559
560/**
561 * Defines the function used to retrieve an effect's config widget
562 * E.g. KWIN_EFFECT_CONFIG( flames, MyFlameEffectConfig )
563 **/
564#define KWIN_EFFECT_CONFIG( name, classname ) \
565 K_PLUGIN_FACTORY(EffectFactory, registerPlugin<classname>(#name);) \
566 K_EXPORT_PLUGIN(EffectFactory("kcm_kwin4_effect_" #name))
567/**
568 * Defines the function used to retrieve multiple effects' config widget
569 * E.g. KWIN_EFFECT_CONFIG_MULTIPLE( flames,
570 * KWIN_EFFECT_CONFIG_SINGLE( flames, MyFlameEffectConfig )
571 * KWIN_EFFECT_CONFIG_SINGLE( fire, MyFireEffectConfig )
572 * )
573 **/
574#define KWIN_EFFECT_CONFIG_MULTIPLE( name, singles ) \
575 K_PLUGIN_FACTORY(EffectFactory, singles) \
576 K_EXPORT_PLUGIN(EffectFactory("kcm_kwin4_effect_" #name))
577/**
578 * @see KWIN_EFFECT_CONFIG_MULTIPLE
579 */
580#define KWIN_EFFECT_CONFIG_SINGLE( name, classname ) \
581 registerPlugin<classname>(#name);
582/**
583 * The declaration of the factory to export the effect
584 */
585#define KWIN_EFFECT_CONFIG_FACTORY K_PLUGIN_FACTORY_DECLARATION(EffectFactory)
586
587
588/**
589 * @short Manager class that handles all the effects.
590 *
591 * This class creates Effect objects and calls it's appropriate methods.
592 *
593 * Effect objects can call methods of this class to interact with the
594 * workspace, e.g. to activate or move a specific window, change current
595 * desktop or create a special input window to receive mouse and keyboard
596 * events.
597 **/
598class KWIN_EXPORT EffectsHandler : public QObject
599{
600 Q_OBJECT
601 Q_PROPERTY(int currentDesktop READ currentDesktop WRITE setCurrentDesktop NOTIFY desktopChanged)
602 Q_PROPERTY(QString currentActivity READ currentActivity NOTIFY currentActivityChanged)
603 Q_PROPERTY(KWin::EffectWindow *activeWindow READ activeWindow WRITE activateWindow NOTIFY windowActivated)
604 Q_PROPERTY(QSize desktopGridSize READ desktopGridSize)
605 Q_PROPERTY(int desktopGridWidth READ desktopGridWidth)
606 Q_PROPERTY(int desktopGridHeight READ desktopGridHeight)
607 Q_PROPERTY(int workspaceWidth READ workspaceWidth)
608 Q_PROPERTY(int workspaceHeight READ workspaceHeight)
609 /**
610 * The number of desktops currently used. Minimum number of desktops is 1, maximum 20.
611 **/
612 Q_PROPERTY(int desktops READ numberOfDesktops WRITE setNumberOfDesktops NOTIFY numberDesktopsChanged)
613 Q_PROPERTY(bool optionRollOverDesktops READ optionRollOverDesktops)
614 Q_PROPERTY(int activeScreen READ activeScreen)
615 Q_PROPERTY(int numScreens READ numScreens)
616 /**
617 * Factor by which animation speed in the effect should be modified (multiplied).
618 * If configurable in the effect itself, the option should have also 'default'
619 * animation speed. The actual value should be determined using animationTime().
620 * Note: The factor can be also 0, so make sure your code can cope with 0ms time
621 * if used manually.
622 */
623 Q_PROPERTY(qreal animationTimeFactor READ animationTimeFactor)
624 Q_PROPERTY(QList< KWin::EffectWindow* > stackingOrder READ stackingOrder)
625 /**
626 * Whether window decorations use the alpha channel.
627 **/
628 Q_PROPERTY(bool decorationsHaveAlpha READ decorationsHaveAlpha)
629 /**
630 * Whether the window decorations support blurring behind the decoration.
631 **/
632 Q_PROPERTY(bool decorationSupportsBlurBehind READ decorationSupportsBlurBehind)
633 Q_PROPERTY(CompositingType compositingType READ compositingType CONSTANT)
634 Q_PROPERTY(QPoint cursorPos READ cursorPos)
635 friend class Effect;
636public:
637 explicit EffectsHandler(CompositingType type);
638 virtual ~EffectsHandler();
639 // for use by effects
640 virtual void prePaintScreen(ScreenPrePaintData& data, int time) = 0;
641 virtual void paintScreen(int mask, QRegion region, ScreenPaintData& data) = 0;
642 virtual void postPaintScreen() = 0;
643 virtual void prePaintWindow(EffectWindow* w, WindowPrePaintData& data, int time) = 0;
644 virtual void paintWindow(EffectWindow* w, int mask, QRegion region, WindowPaintData& data) = 0;
645 virtual void postPaintWindow(EffectWindow* w) = 0;
646 virtual void paintEffectFrame(EffectFrame* frame, QRegion region, double opacity, double frameOpacity) = 0;
647 virtual void drawWindow(EffectWindow* w, int mask, QRegion region, WindowPaintData& data) = 0;
648 virtual void buildQuads(EffectWindow* w, WindowQuadList& quadList) = 0;
649 virtual QVariant kwinOption(KWinOption kwopt) = 0;
650 /**
651 * Sets the cursor while the mouse is intercepted.
652 * @see startMouseInterception
653 * @since 4.11
654 **/
655 virtual void defineCursor(Qt::CursorShape shape) = 0;
656 virtual QPoint cursorPos() const = 0;
657 virtual bool grabKeyboard(Effect* effect) = 0;
658 virtual void ungrabKeyboard() = 0;
659 /**
660 * Ensures that all mouse events are sent to the @p effect.
661 * No window will get the mouse events. Only fullscreen effects providing a custom user interface should
662 * be using this method. The input events are delivered to Effect::windowInputMouseEvent.
663 *
664 * NOTE: this method does not perform an X11 mouse grab. On X11 a fullscreen input window is raised above
665 * all other windows, but no grab is performed.
666 *
667 * @param shape Sets the cursor to be used while the mouse is intercepted
668 * @see stopMouseInterception
669 * @see Effect::windowInputMouseEvent
670 * @since 4.11
671 **/
672 virtual void startMouseInterception(Effect *effect, Qt::CursorShape shape) = 0;
673 /**
674 * Releases the hold mouse interception for @p effect
675 * @see startMouseInterception
676 * @since 4.11
677 **/
678 virtual void stopMouseInterception(Effect *effect) = 0;
679
680 /**
681 * Retrieve the proxy class for an effect if it has one. Will return NULL if
682 * the effect isn't loaded or doesn't have a proxy class.
683 */
684 virtual void* getProxy(QString name) = 0;
685
686 // Mouse polling
687 virtual void startMousePolling() = 0;
688 virtual void stopMousePolling() = 0;
689
690 virtual void reserveElectricBorder(ElectricBorder border, Effect *effect) = 0;
691 virtual void unreserveElectricBorder(ElectricBorder border, Effect *effect) = 0;
692
693 // functions that allow controlling windows/desktop
694 virtual void activateWindow(KWin::EffectWindow* c) = 0;
695 virtual KWin::EffectWindow* activeWindow() const = 0 ;
696 Q_SCRIPTABLE virtual void moveWindow(KWin::EffectWindow* w, const QPoint& pos, bool snap = false, double snapAdjust = 1.0) = 0;
697 Q_SCRIPTABLE virtual void windowToDesktop(KWin::EffectWindow* w, int desktop) = 0;
698 Q_SCRIPTABLE virtual void windowToScreen(KWin::EffectWindow* w, int screen) = 0;
699 virtual void setShowingDesktop(bool showing) = 0;
700
701
702 // Activities
703 /**
704 * @returns The ID of the current activity.
705 */
706 virtual QString currentActivity() const = 0;
707 // Desktops
708 /**
709 * @returns The ID of the current desktop.
710 */
711 virtual int currentDesktop() const = 0;
712 /**
713 * @returns Total number of desktops currently in existence.
714 */
715 virtual int numberOfDesktops() const = 0;
716 /**
717 * Set the current desktop to @a desktop.
718 */
719 virtual void setCurrentDesktop(int desktop) = 0;
720 /**
721 * Sets the total number of desktops to @a desktops.
722 */
723 virtual void setNumberOfDesktops(int desktops) = 0;
724 /**
725 * @returns The size of desktop layout in grid units.
726 */
727 virtual QSize desktopGridSize() const = 0;
728 /**
729 * @returns The width of desktop layout in grid units.
730 */
731 virtual int desktopGridWidth() const = 0;
732 /**
733 * @returns The height of desktop layout in grid units.
734 */
735 virtual int desktopGridHeight() const = 0;
736 /**
737 * @returns The width of desktop layout in pixels.
738 */
739 virtual int workspaceWidth() const = 0;
740 /**
741 * @returns The height of desktop layout in pixels.
742 */
743 virtual int workspaceHeight() const = 0;
744 /**
745 * @returns The ID of the desktop at the point @a coords or 0 if no desktop exists at that
746 * point. @a coords is to be in grid units.
747 */
748 virtual int desktopAtCoords(QPoint coords) const = 0;
749 /**
750 * @returns The coords of desktop @a id in grid units.
751 */
752 virtual QPoint desktopGridCoords(int id) const = 0;
753 /**
754 * @returns The coords of the top-left corner of desktop @a id in pixels.
755 */
756 virtual QPoint desktopCoords(int id) const = 0;
757 /**
758 * @returns The ID of the desktop above desktop @a id. Wraps around to the bottom of
759 * the layout if @a wrap is set. If @a id is not set use the current one.
760 */
761 Q_SCRIPTABLE virtual int desktopAbove(int desktop = 0, bool wrap = true) const = 0;
762 /**
763 * @returns The ID of the desktop to the right of desktop @a id. Wraps around to the
764 * left of the layout if @a wrap is set. If @a id is not set use the current one.
765 */
766 Q_SCRIPTABLE virtual int desktopToRight(int desktop = 0, bool wrap = true) const = 0;
767 /**
768 * @returns The ID of the desktop below desktop @a id. Wraps around to the top of the
769 * layout if @a wrap is set. If @a id is not set use the current one.
770 */
771 Q_SCRIPTABLE virtual int desktopBelow(int desktop = 0, bool wrap = true) const = 0;
772 /**
773 * @returns The ID of the desktop to the left of desktop @a id. Wraps around to the
774 * right of the layout if @a wrap is set. If @a id is not set use the current one.
775 */
776 Q_SCRIPTABLE virtual int desktopToLeft(int desktop = 0, bool wrap = true) const = 0;
777 Q_SCRIPTABLE virtual QString desktopName(int desktop) const = 0;
778 virtual bool optionRollOverDesktops() const = 0;
779
780 virtual int activeScreen() const = 0; // Xinerama
781 virtual int numScreens() const = 0; // Xinerama
782 Q_SCRIPTABLE virtual int screenNumber(const QPoint& pos) const = 0; // Xinerama
783 virtual QRect clientArea(clientAreaOption, int screen, int desktop) const = 0;
784 virtual QRect clientArea(clientAreaOption, const EffectWindow* c) const = 0;
785 virtual QRect clientArea(clientAreaOption, const QPoint& p, int desktop) const = 0;
786 /**
787 * Factor by which animation speed in the effect should be modified (multiplied).
788 * If configurable in the effect itself, the option should have also 'default'
789 * animation speed. The actual value should be determined using animationTime().
790 * Note: The factor can be also 0, so make sure your code can cope with 0ms time
791 * if used manually.
792 */
793 virtual double animationTimeFactor() const = 0;
794 virtual WindowQuadType newWindowQuadType() = 0;
795
796 Q_SCRIPTABLE virtual KWin::EffectWindow* findWindow(WId id) const = 0;
797 virtual EffectWindowList stackingOrder() const = 0;
798 // window will be temporarily painted as if being at the top of the stack
799 virtual void setElevatedWindow(EffectWindow* w, bool set) = 0;
800
801 virtual void setTabBoxWindow(EffectWindow*) = 0;
802 virtual void setTabBoxDesktop(int) = 0;
803 virtual EffectWindowList currentTabBoxWindowList() const = 0;
804 virtual void refTabBox() = 0;
805 virtual void unrefTabBox() = 0;
806 virtual void closeTabBox() = 0;
807 virtual QList< int > currentTabBoxDesktopList() const = 0;
808 virtual int currentTabBoxDesktop() const = 0;
809 virtual EffectWindow* currentTabBoxWindow() const = 0;
810
811 virtual void setActiveFullScreenEffect(Effect* e) = 0;
812 virtual Effect* activeFullScreenEffect() const = 0;
813
814 /**
815 * Schedules the entire workspace to be repainted next time.
816 * If you call it during painting (including prepaint) then it does not
817 * affect the current painting.
818 **/
819 Q_SCRIPTABLE virtual void addRepaintFull() = 0;
820 Q_SCRIPTABLE virtual void addRepaint(const QRect& r) = 0;
821 Q_SCRIPTABLE virtual void addRepaint(const QRegion& r) = 0;
822 Q_SCRIPTABLE virtual void addRepaint(int x, int y, int w, int h) = 0;
823
824 CompositingType compositingType() const;
825 /**
826 * @brief Whether the Compositor is OpenGL based (either GL 1 or 2).
827 *
828 * @return bool @c true in case of OpenGL based Compositor, @c false otherwise
829 **/
830 bool isOpenGLCompositing() const;
831 virtual unsigned long xrenderBufferPicture() = 0;
832 virtual void reconfigure() = 0;
833
834 /**
835 Makes KWin core watch PropertyNotify events for the given atom,
836 or stops watching if reg is false (must be called the same number
837 of times as registering). Events are sent using Effect::propertyNotify().
838 Note that even events that haven't been registered for can be received.
839 */
840 virtual void registerPropertyType(long atom, bool reg) = 0;
841 virtual QByteArray readRootProperty(long atom, long type, int format) const = 0;
842 virtual void deleteRootProperty(long atom) const = 0;
843 /**
844 * @brief Announces support for the feature with the given name. If no other Effect
845 * has announced support for this feature yet, an X11 property will be installed on
846 * the root window.
847 *
848 * The Effect will be notified for events through the signal propertyNotify().
849 *
850 * To remove the support again use @link removeSupportProperty. When an Effect is
851 * destroyed it is automatically taken care of removing the support. It is not
852 * required to call @link removeSupportProperty in the Effect's cleanup handling.
853 *
854 * @param propertyName The name of the property to announce support for
855 * @param effect The effect which announces support
856 * @return xcb_atom_t The created X11 atom
857 * @see removeSupportProperty
858 * @since 4.11
859 **/
860 virtual xcb_atom_t announceSupportProperty(const QByteArray &propertyName, Effect *effect) = 0;
861 /**
862 * @brief Removes support for the feature with the given name. If there is no other Effect left
863 * which has announced support for the given property, the property will be removed from the
864 * root window.
865 *
866 * In case the Effect had not registered support, calling this function does not change anything.
867 *
868 * @param propertyName The name of the property to remove support for
869 * @param effect The effect which had registered the property.
870 * @see announceSupportProperty
871 * @since 4.11
872 **/
873 virtual void removeSupportProperty(const QByteArray &propertyName, Effect *effect) = 0;
874
875 /**
876 * Returns @a true if the active window decoration has shadow API hooks.
877 */
878 virtual bool hasDecorationShadows() const = 0;
879
880 /**
881 * Returns @a true if the window decorations use the alpha channel, and @a false otherwise.
882 * @since 4.5
883 */
884 virtual bool decorationsHaveAlpha() const = 0;
885
886 /**
887 * Returns @a true if the window decorations support blurring behind the decoration, and @a false otherwise
888 * @since 4.6
889 */
890 virtual bool decorationSupportsBlurBehind() const = 0;
891
892 /**
893 * Creates a new frame object. If the frame does not have a static size
894 * then it will be located at @a position with @a alignment. A
895 * non-static frame will automatically adjust its size to fit the contents.
896 * @returns A new @ref EffectFrame. It is the responsibility of the caller to delete the
897 * EffectFrame.
898 * @since 4.6
899 */
900 virtual EffectFrame* effectFrame(EffectFrameStyle style, bool staticSize = true,
901 const QPoint& position = QPoint(-1, -1), Qt::Alignment alignment = Qt::AlignCenter) const = 0;
902
903 /**
904 * Allows an effect to trigger a reload of itself.
905 * This can be used by an effect which needs to be reloaded when screen geometry changes.
906 * It is possible that the effect cannot be loaded again as it's supported method does no longer
907 * hold.
908 * @param effect The effect to reload
909 * @since 4.8
910 **/
911 virtual void reloadEffect(Effect *effect) = 0;
912
913 /**
914 * Whether the screen is currently considered as locked.
915 * Note for technical reasons this is not always possible to detect. The screen will only
916 * be considered as locked if the screen locking process implements the
917 * org.freedesktop.ScreenSaver interface.
918 *
919 * @returns @c true if the screen is currently locked, @c false otherwise
920 * @see screenLockingChanged
921 * @since 4.11
922 **/
923 virtual bool isScreenLocked() const = 0;
924
925 /**
926 * Sends message over DCOP to reload given effect.
927 * @param effectname effect's name without "kwin4_effect_" prefix.
928 * Can be called from effect's config module to apply config changes.
929 **/
930 static void sendReloadMessage(const QString& effectname);
931 /**
932 * @return @ref KConfigGroup which holds given effect's config options
933 **/
934 static KConfigGroup effectConfig(const QString& effectname);
935
936Q_SIGNALS:
937 /**
938 * Signal emitted when the current desktop changed.
939 * @param oldDesktop The previously current desktop
940 * @param newDesktop The new current desktop
941 * @param with The window which is taken over to the new desktop, can be NULL
942 * @since 4.9
943 */
944 void desktopChanged(int oldDesktop, int newDesktop, KWin::EffectWindow *with);
945 /**
946 * @since 4.7
947 * @deprecated
948 */
949 void desktopChanged(int oldDesktop, int newDesktop);
950 /**
951 * Signal emitted when a window moved to another desktop
952 * NOTICE that this does NOT imply that the desktop has changed
953 * The @param window which is moved to the new desktop
954 * @param oldDesktop The previous desktop of the window
955 * @param newDesktop The new desktop of the window
956 * @since 4.11.4
957 */
958 void desktopPresenceChanged(KWin::EffectWindow *window, int oldDesktop, int newDesktop);
959 /**
960 * Signal emitted when the number of currently existing desktops is changed.
961 * @param old The previous number of desktops in used.
962 * @see EffectsHandler::numberOfDesktops.
963 * @since 4.7
964 */
965 void numberDesktopsChanged(uint old);
966 /**
967 * Signal emitted when a new window has been added to the Workspace.
968 * @param w The added window
969 * @since 4.7
970 **/
971 void windowAdded(KWin::EffectWindow *w);
972 /**
973 * Signal emitted when a window is being removed from the Workspace.
974 * An effect which wants to animate the window closing should connect
975 * to this signal and reference the window by using
976 * @link EffectWindow::refWindow
977 * @param w The window which is being closed
978 * @since 4.7
979 **/
980 void windowClosed(KWin::EffectWindow *w);
981 /**
982 * Signal emitted when a window get's activated.
983 * @param w The new active window, or @c NULL if there is no active window.
984 * @since 4.7
985 **/
986 void windowActivated(KWin::EffectWindow *w);
987 /**
988 * Signal emitted when a window is deleted.
989 * This means that a closed window is not referenced any more.
990 * An effect bookkeeping the closed windows should connect to this
991 * signal to clean up the internal references.
992 * @param w The window which is going to be deleted.
993 * @see EffectWindow::refWindow
994 * @see EffectWindow::unrefWindow
995 * @see windowClosed
996 * @since 4.7
997 **/
998 void windowDeleted(KWin::EffectWindow *w);
999 /**
1000 * Signal emitted when a user begins a window move or resize operation.
1001 * To figure out whether the user resizes or moves the window use
1002 * @link EffectWindow::isUserMove or @link EffectWindow::isUserResize.
1003 * Whenever the geometry is updated the signal @link windowStepUserMovedResized
1004 * is emitted with the current geometry.
1005 * The move/resize operation ends with the signal @link windowFinishUserMovedResized.
1006 * Only one window can be moved/resized by the user at the same time!
1007 * @param w The window which is being moved/resized
1008 * @see windowStepUserMovedResized
1009 * @see windowFinishUserMovedResized
1010 * @see EffectWindow::isUserMove
1011 * @see EffectWindow::isUserResize
1012 * @since 4.7
1013 **/
1014 void windowStartUserMovedResized(KWin::EffectWindow *w);
1015 /**
1016 * Signal emitted during a move/resize operation when the user changed the geometry.
1017 * Please note: KWin supports two operation modes. In one mode all changes are applied
1018 * instantly. This means the window's geometry matches the passed in @p geometry. In the
1019 * other mode the geometry is changed after the user ended the move/resize mode.
1020 * The @p geometry differs from the window's geometry. Also the window's pixmap still has
1021 * the same size as before. Depending what the effect wants to do it would be recommended
1022 * to scale/translate the window.
1023 * @param w The window which is being moved/resized
1024 * @param geometry The geometry of the window in the current move/resize step.
1025 * @see windowStartUserMovedResized
1026 * @see windowFinishUserMovedResized
1027 * @see EffectWindow::isUserMove
1028 * @see EffectWindow::isUserResize
1029 * @since 4.7
1030 **/
1031 void windowStepUserMovedResized(KWin::EffectWindow *w, const QRect &geometry);
1032 /**
1033 * Signal emitted when the user finishes move/resize of window @p w.
1034 * @param w The window which has been moved/resized
1035 * @see windowStartUserMovedResized
1036 * @see windowFinishUserMovedResized
1037 * @since 4.7
1038 **/
1039 void windowFinishUserMovedResized(KWin::EffectWindow *w);
1040 /**
1041 * Signal emitted when the maximized state of the window @p w changed.
1042 * A window can be in one of four states:
1043 * @li restored: both @p horizontal and @p vertical are @c false
1044 * @li horizontally maximized: @p horizontal is @c true and @p vertical is @c false
1045 * @li vertically maximized: @p horizontal is @c false and @p vertical is @c true
1046 * @li completely maximized: both @p horizontal and @p vertical are @C true
1047 * @param w The window whose maximized state changed
1048 * @param horizontal If @c true maximized horizontally
1049 * @param vertical If @c true maximized vertically
1050 * @since 4.7
1051 **/
1052 void windowMaximizedStateChanged(KWin::EffectWindow *w, bool horizontal, bool vertical);
1053 /**
1054 * Signal emitted when the geometry or shape of a window changed.
1055 * This is caused if the window changes geometry without user interaction.
1056 * E.g. the decoration is changed. This is in opposite to windowUserMovedResized
1057 * which is caused by direct user interaction.
1058 * @param w The window whose geometry changed
1059 * @param old The previous geometry
1060 * @see windowUserMovedResized
1061 * @since 4.7
1062 **/
1063 void windowGeometryShapeChanged(KWin::EffectWindow *w, const QRect &old);
1064 /**
1065 * Signal emitted when the padding of a window changed. (eg. shadow size)
1066 * @param w The window whose geometry changed
1067 * @param old The previous expandedGeometry()
1068 * @since 4.9
1069 **/
1070 void windowPaddingChanged(KWin::EffectWindow *w, const QRect &old);
1071 /**
1072 * Signal emitted when the windows opacity is changed.
1073 * @param w The window whose opacity level is changed.
1074 * @param oldOpacity The previous opacity level
1075 * @param newOpacity The new opacity level
1076 * @since 4.7
1077 **/
1078 void windowOpacityChanged(KWin::EffectWindow *w, qreal oldOpacity, qreal newOpacity);
1079 /**
1080 * Signal emitted when a window got minimized.
1081 * @param w The window which was minimized
1082 * @since 4.7
1083 **/
1084 void windowMinimized(KWin::EffectWindow *w);
1085 /**
1086 * Signal emitted when a window got unminimized.
1087 * @param w The window which was unminimized
1088 * @since 4.7
1089 **/
1090 void windowUnminimized(KWin::EffectWindow *w);
1091 /**
1092 * Signal emitted when a window either becomes modal (ie. blocking for its main client) or looses that state.
1093 * @param w The window which was unminimized
1094 * @since 4.11
1095 **/
1096 void windowModalityChanged(KWin::EffectWindow *w);
1097 /**
1098 * Signal emitted when an area of a window is scheduled for repainting.
1099 * Use this signal in an effect if another area needs to be synced as well.
1100 * @param w The window which is scheduled for repainting
1101 * @param r Always empty.
1102 * @since 4.7
1103 **/
1104 void windowDamaged(KWin::EffectWindow *w, const QRect &r);
1105 /**
1106 * Signal emitted when a tabbox is added.
1107 * An effect who wants to replace the tabbox with itself should use @link refTabBox.
1108 * @param mode The TabBoxMode.
1109 * @see refTabBox
1110 * @see tabBoxClosed
1111 * @see tabBoxUpdated
1112 * @see tabBoxKeyEvent
1113 * @since 4.7
1114 **/
1115 void tabBoxAdded(int mode);
1116 /**
1117 * Signal emitted when the TabBox was closed by KWin core.
1118 * An effect which referenced the TabBox should use @link unrefTabBox to unref again.
1119 * @see unrefTabBox
1120 * @see tabBoxAdded
1121 * @since 4.7
1122 **/
1123 void tabBoxClosed();
1124 /**
1125 * Signal emitted when the selected TabBox window changed or the TabBox List changed.
1126 * An effect should only response to this signal if it referenced the TabBox with @link refTabBox.
1127 * @see refTabBox
1128 * @see currentTabBoxWindowList
1129 * @see currentTabBoxDesktopList
1130 * @see currentTabBoxWindow
1131 * @see currentTabBoxDesktop
1132 * @since 4.7
1133 **/
1134 void tabBoxUpdated();
1135 /**
1136 * Signal emitted when a key event, which is not handled by TabBox directly is, happens while
1137 * TabBox is active. An effect might use the key event to e.g. change the selected window.
1138 * An effect should only response to this signal if it referenced the TabBox with @link refTabBox.
1139 * @param event The key event not handled by TabBox directly
1140 * @see refTabBox
1141 * @since 4.7
1142 **/
1143 void tabBoxKeyEvent(QKeyEvent* event);
1144 void currentTabAboutToChange(KWin::EffectWindow* from, KWin::EffectWindow* to);
1145 void tabAdded(KWin::EffectWindow* from, KWin::EffectWindow* to); // from merged with to
1146 void tabRemoved(KWin::EffectWindow* c, KWin::EffectWindow* group); // c removed from group
1147 /**
1148 * Signal emitted when mouse changed.
1149 * If an effect needs to get updated mouse positions, it needs to first call @link startMousePolling.
1150 * For a fullscreen effect it is better to use an input window and react on @link windowInputMouseEvent.
1151 * @param pos The new mouse position
1152 * @param oldpos The previously mouse position
1153 * @param buttons The pressed mouse buttons
1154 * @param oldbuttons The previously pressed mouse buttons
1155 * @param modifiers Pressed keyboard modifiers
1156 * @param oldmodifiers Previously pressed keyboard modifiers.
1157 * @see startMousePolling
1158 * @since 4.7
1159 **/
1160 void mouseChanged(const QPoint& pos, const QPoint& oldpos,
1161 Qt::MouseButtons buttons, Qt::MouseButtons oldbuttons,
1162 Qt::KeyboardModifiers modifiers, Qt::KeyboardModifiers oldmodifiers);
1163 /**
1164 * Receives events registered for using @link registerPropertyType.
1165 * Use readProperty() to get the property data.
1166 * Note that the property may be already set on the window, so doing the same
1167 * processing from windowAdded() (e.g. simply calling propertyNotify() from it)
1168 * is usually needed.
1169 * @param w The window whose property changed, is @c null if it is a root window property
1170 * @param atom The property
1171 * @since 4.7
1172 */
1173 void propertyNotify(KWin::EffectWindow* w, long atom);
1174
1175 /**
1176 * Signal emitted after the screen geometry changed (e.g. add of a monitor).
1177 * Effects using displayWidth()/displayHeight() to cache information should
1178 * react on this signal and update the caches.
1179 * @param size The new screen size
1180 * @since 4.8
1181 **/
1182 void screenGeometryChanged(const QSize &size);
1183
1184 /**
1185 * This signal is emitted when the global
1186 * activity is changed
1187 * @param id id of the new current activity
1188 * @since 4.9
1189 **/
1190 void currentActivityChanged(const QString &id);
1191 /**
1192 * This signal is emitted when a new activity is added
1193 * @param id id of the new activity
1194 * @since 4.9
1195 */
1196 void activityAdded(const QString &id);
1197 /**
1198 * This signal is emitted when the activity
1199 * is removed
1200 * @param id id of the removed activity
1201 * @since 4.9
1202 */
1203 void activityRemoved(const QString &id);
1204 /**
1205 * This signal is emitted when the screen got locked or unlocked.
1206 * @param locked @c true if the screen is now locked, @c false if it is now unlocked
1207 * @since 4.11
1208 **/
1209 void screenLockingChanged(bool locked);
1210
1211 /**
1212 * This signels is emitted when ever the stacking order is change, ie. a window is risen
1213 * or lowered
1214 * @since 4.10
1215 */
1216 void stackingOrderChanged();
1217 /**
1218 * This signal is emitted when the user starts to approach the @p border with the mouse.
1219 * The @p factor describes how far away the mouse is in a relative mean. The values are in
1220 * [0.0, 1.0] with 0.0 being emitted when first entered and on leaving. The value 1.0 means that
1221 * the @p border is reached with the mouse. So the values are well suited for animations.
1222 * The signal is always emitted when the mouse cursor position changes.
1223 * @param border The screen edge which is being approached
1224 * @param factor Value in range [0.0,1.0] to describe how close the mouse is to the border
1225 * @param geometry The geometry of the edge which is being approached
1226 * @since 4.11
1227 **/
1228 void screenEdgeApproaching(ElectricBorder border, qreal factor, const QRect &geometry);
1229
1230protected:
1231 QVector< EffectPair > loaded_effects;
1232 QHash< QString, KLibrary* > effect_libraries;
1233 //QHash< QString, EffectFactory* > effect_factories;
1234 CompositingType compositing_type;
1235};
1236
1237
1238/**
1239 * @short Representation of a window used by/for Effect classes.
1240 *
1241 * The purpose is to hide internal data and also to serve as a single
1242 * representation for the case when Client/Unmanaged becomes Deleted.
1243 **/
1244class KWIN_EXPORT EffectWindow : public QObject
1245{
1246 Q_OBJECT
1247 Q_PROPERTY(bool alpha READ hasAlpha CONSTANT)
1248 Q_PROPERTY(QRect geometry READ geometry)
1249 Q_PROPERTY(QRect expandedGeometry READ expandedGeometry)
1250 Q_PROPERTY(int height READ height)
1251 Q_PROPERTY(qreal opacity READ opacity)
1252 Q_PROPERTY(QPoint pos READ pos)
1253 Q_PROPERTY(int screen READ screen)
1254 Q_PROPERTY(QSize size READ size)
1255 Q_PROPERTY(int width READ width)
1256 Q_PROPERTY(int x READ x)
1257 Q_PROPERTY(int y READ y)
1258 Q_PROPERTY(int desktop READ desktop)
1259 Q_PROPERTY(bool onAllDesktops READ isOnAllDesktops)
1260 Q_PROPERTY(bool onCurrentDesktop READ isOnCurrentDesktop)
1261 Q_PROPERTY(QRect rect READ rect)
1262 Q_PROPERTY(QString windowClass READ windowClass)
1263 Q_PROPERTY(QString windowRole READ windowRole)
1264 /**
1265 * Returns whether the window is a desktop background window (the one with wallpaper).
1266 * See _NET_WM_WINDOW_TYPE_DESKTOP at http://standards.freedesktop.org/wm-spec/wm-spec-latest.html .
1267 */
1268 Q_PROPERTY(bool desktopWindow READ isDesktop)
1269 /**
1270 * Returns whether the window is a dock (i.e. a panel).
1271 * See _NET_WM_WINDOW_TYPE_DOCK at http://standards.freedesktop.org/wm-spec/wm-spec-latest.html .
1272 */
1273 Q_PROPERTY(bool dock READ isDock)
1274 /**
1275 * Returns whether the window is a standalone (detached) toolbar window.
1276 * See _NET_WM_WINDOW_TYPE_TOOLBAR at http://standards.freedesktop.org/wm-spec/wm-spec-latest.html .
1277 */
1278 Q_PROPERTY(bool toolbar READ isToolbar)
1279 /**
1280 * Returns whether the window is a torn-off menu.
1281 * See _NET_WM_WINDOW_TYPE_MENU at http://standards.freedesktop.org/wm-spec/wm-spec-latest.html .
1282 */
1283 Q_PROPERTY(bool menu READ isMenu)
1284 /**
1285 * Returns whether the window is a "normal" window, i.e. an application or any other window
1286 * for which none of the specialized window types fit.
1287 * See _NET_WM_WINDOW_TYPE_NORMAL at http://standards.freedesktop.org/wm-spec/wm-spec-latest.html .
1288 */
1289 Q_PROPERTY(bool normalWindow READ isNormalWindow)
1290 /**
1291 * Returns whether the window is a dialog window.
1292 * See _NET_WM_WINDOW_TYPE_DIALOG at http://standards.freedesktop.org/wm-spec/wm-spec-latest.html .
1293 */
1294 Q_PROPERTY(bool dialog READ isDialog)
1295 /**
1296 * Returns whether the window is a splashscreen. Note that many (especially older) applications
1297 * do not support marking their splash windows with this type.
1298 * See _NET_WM_WINDOW_TYPE_SPLASH at http://standards.freedesktop.org/wm-spec/wm-spec-latest.html .
1299 */
1300 Q_PROPERTY(bool splash READ isSplash)
1301 /**
1302 * Returns whether the window is a utility window, such as a tool window.
1303 * See _NET_WM_WINDOW_TYPE_UTILITY at http://standards.freedesktop.org/wm-spec/wm-spec-latest.html .
1304 */
1305 Q_PROPERTY(bool utility READ isUtility)
1306 /**
1307 * Returns whether the window is a dropdown menu (i.e. a popup directly or indirectly open
1308 * from the applications menubar).
1309 * See _NET_WM_WINDOW_TYPE_DROPDOWN_MENU at http://standards.freedesktop.org/wm-spec/wm-spec-latest.html .
1310 */
1311 Q_PROPERTY(bool dropdownMenu READ isDropdownMenu)
1312 /**
1313 * Returns whether the window is a popup menu (that is not a torn-off or dropdown menu).
1314 * See _NET_WM_WINDOW_TYPE_POPUP_MENU at http://standards.freedesktop.org/wm-spec/wm-spec-latest.html .
1315 */
1316 Q_PROPERTY(bool popupMenu READ isPopupMenu)
1317 /**
1318 * Returns whether the window is a tooltip.
1319 * See _NET_WM_WINDOW_TYPE_TOOLTIP at http://standards.freedesktop.org/wm-spec/wm-spec-latest.html .
1320 */
1321 Q_PROPERTY(bool tooltip READ isTooltip)
1322 /**
1323 * Returns whether the window is a window with a notification.
1324 * See _NET_WM_WINDOW_TYPE_NOTIFICATION at http://standards.freedesktop.org/wm-spec/wm-spec-latest.html .
1325 */
1326 Q_PROPERTY(bool notification READ isNotification)
1327 /**
1328 * Returns whether the window is a combobox popup.
1329 * See _NET_WM_WINDOW_TYPE_COMBO at http://standards.freedesktop.org/wm-spec/wm-spec-latest.html .
1330 */
1331 Q_PROPERTY(bool comboBox READ isComboBox)
1332 /**
1333 * Returns whether the window is a Drag&Drop icon.
1334 * See _NET_WM_WINDOW_TYPE_DND at http://standards.freedesktop.org/wm-spec/wm-spec-latest.html .
1335 */
1336 Q_PROPERTY(bool dndIcon READ isDNDIcon)
1337 /**
1338 * Returns the NETWM window type
1339 * See http://standards.freedesktop.org/wm-spec/wm-spec-latest.html .
1340 */
1341 Q_PROPERTY(int windowType READ windowType)
1342 /**
1343 * Whether this EffectWindow is managed by KWin (it has control over its placement and other
1344 * aspects, as opposed to override-redirect windows that are entirely handled by the application).
1345 **/
1346 Q_PROPERTY(bool managed READ isManaged)
1347 /**
1348 * Whether this EffectWindow represents an already deleted window and only kept for the compositor for animations.
1349 **/
1350 Q_PROPERTY(bool deleted READ isDeleted)
1351 /**
1352 * Whether the window has an own shape
1353 **/
1354 Q_PROPERTY(bool shaped READ hasOwnShape)
1355 /**
1356 * The Window's shape
1357 **/
1358 Q_PROPERTY(QRegion shape READ shape)
1359 /**
1360 * The Caption of the window. Read from WM_NAME property together with a suffix for hostname and shortcut.
1361 **/
1362 Q_PROPERTY(QString caption READ caption)
1363 /**
1364 * Whether the window is set to be kept above other windows.
1365 **/
1366 Q_PROPERTY(bool keepAbove READ keepAbove)
1367 /**
1368 * Whether the window is minimized.
1369 **/
1370 Q_PROPERTY(bool minimized READ isMinimized WRITE setMinimized)
1371 /**
1372 * Whether the window represents a modal window.
1373 **/
1374 Q_PROPERTY(bool modal READ isModal)
1375 /**
1376 * Whether the window is moveable. Even if it is not moveable, it might be possible to move
1377 * it to another screen.
1378 * @see moveableAcrossScreens
1379 **/
1380 Q_PROPERTY(bool moveable READ isMovable)
1381 /**
1382 * Whether the window can be moved to another screen.
1383 * @see moveable
1384 **/
1385 Q_PROPERTY(bool moveableAcrossScreens READ isMovableAcrossScreens)
1386 /**
1387 * By how much the window wishes to grow/shrink at least. Usually QSize(1,1).
1388 * MAY BE DISOBEYED BY THE WM! It's only for information, do NOT rely on it at all.
1389 */
1390 Q_PROPERTY(QSize basicUnit READ basicUnit)
1391 /**
1392 * Whether the window is currently being moved by the user.
1393 **/
1394 Q_PROPERTY(bool move READ isUserMove)
1395 /**
1396 * Whether the window is currently being resized by the user.
1397 **/
1398 Q_PROPERTY(bool resize READ isUserResize)
1399 /**
1400 * The optional geometry representing the minimized Client in e.g a taskbar.
1401 * See _NET_WM_ICON_GEOMETRY at http://standards.freedesktop.org/wm-spec/wm-spec-latest.html .
1402 **/
1403 Q_PROPERTY(QRect iconGeometry READ iconGeometry)
1404 /**
1405 * Returns whether the window is any of special windows types (desktop, dock, splash, ...),
1406 * i.e. window types that usually don't have a window frame and the user does not use window
1407 * management (moving, raising,...) on them.
1408 **/
1409 Q_PROPERTY(bool specialWindow READ isSpecialWindow)
1410 Q_PROPERTY(QPixmap icon READ icon)
1411 /**
1412 * Whether the window should be excluded from window switching effects.
1413 **/
1414 Q_PROPERTY(bool skipSwitcher READ isSkipSwitcher)
1415 /**
1416 * Geometry of the actual window contents inside the whole (including decorations) window.
1417 */
1418 Q_PROPERTY(QRect contentsRect READ contentsRect)
1419 /**
1420 * Geometry of the transparent rect in the decoration.
1421 * May be different from contentsRect if the decoration is extended into the client area.
1422 */
1423 Q_PROPERTY(QRect decorationInnerRect READ decorationInnerRect)
1424 Q_PROPERTY(bool hasDecoration READ hasDecoration)
1425 Q_PROPERTY(QStringList activities READ activities)
1426 Q_PROPERTY(bool onCurrentActivity READ isOnCurrentActivity)
1427 Q_PROPERTY(bool onAllActivities READ isOnAllActivities)
1428 /**
1429 * Whether the decoration currently uses an alpha channel.
1430 * @since 4.10
1431 **/
1432 Q_PROPERTY(bool decorationHasAlpha READ decorationHasAlpha)
1433 /**
1434 * Whether the window is currently visible to the user, that is:
1435 * <ul>
1436 * <li>Not minimized</li>
1437 * <li>On current desktop</li>
1438 * <li>On current activity</li>
1439 * </ul>
1440 * @since 4.11
1441 **/
1442 Q_PROPERTY(bool visible READ isVisible)
1443 /**
1444 * Whether the window does not want to be animated on window close.
1445 * In case this property is @c true it is not useful to start an animation on window close.
1446 * The window will not be visible, but the animation hooks are executed.
1447 * @since 5.0
1448 **/
1449 Q_PROPERTY(bool skipsCloseAnimation READ skipsCloseAnimation)
1450public:
1451 /** Flags explaining why painting should be disabled */
1452 enum {
1453 /** Window will not be painted */
1454 PAINT_DISABLED = 1 << 0,
1455 /** Window will not be painted because it is deleted */
1456 PAINT_DISABLED_BY_DELETE = 1 << 1,
1457 /** Window will not be painted because of which desktop it's on */
1458 PAINT_DISABLED_BY_DESKTOP = 1 << 2,
1459 /** Window will not be painted because it is minimized */
1460 PAINT_DISABLED_BY_MINIMIZE = 1 << 3,
1461 /** Window will not be painted because it is not the active window in a client group */
1462 PAINT_DISABLED_BY_TAB_GROUP = 1 << 4,
1463 /** Window will not be painted because it's not on the current activity */
1464 PAINT_DISABLED_BY_ACTIVITY = 1 << 5
1465 };
1466
1467 explicit EffectWindow(QObject *parent = NULL);
1468 virtual ~EffectWindow();
1469
1470 virtual void enablePainting(int reason) = 0;
1471 virtual void disablePainting(int reason) = 0;
1472 virtual bool isPaintingEnabled() = 0;
1473 Q_SCRIPTABLE void addRepaint(const QRect& r);
1474 Q_SCRIPTABLE void addRepaint(int x, int y, int w, int h);
1475 Q_SCRIPTABLE void addRepaintFull();
1476 Q_SCRIPTABLE void addLayerRepaint(const QRect& r);
1477 Q_SCRIPTABLE void addLayerRepaint(int x, int y, int w, int h);
1478
1479 virtual void refWindow() = 0;
1480 virtual void unrefWindow() = 0;
1481 bool isDeleted() const;
1482
1483 bool isMinimized() const;
1484 double opacity() const;
1485 bool hasAlpha() const;
1486
1487 bool isOnCurrentActivity() const;
1488 Q_SCRIPTABLE bool isOnActivity(QString id) const;
1489 bool isOnAllActivities() const;
1490 QStringList activities() const;
1491
1492 bool isOnDesktop(int d) const;
1493 bool isOnCurrentDesktop() const;
1494 bool isOnAllDesktops() const;
1495 int desktop() const; // prefer isOnXXX()
1496
1497 int x() const;
1498 int y() const;
1499 int width() const;
1500 int height() const;
1501 /**
1502 * By how much the window wishes to grow/shrink at least. Usually QSize(1,1).
1503 * MAY BE DISOBEYED BY THE WM! It's only for information, do NOT rely on it at all.
1504 */
1505 QSize basicUnit() const;
1506 QRect geometry() const;
1507 /**
1508 * Geometry of the window including decoration and potentially shadows.
1509 * May be different from geometry() if the window has a shadow.
1510 * @since 4.9
1511 */
1512 QRect expandedGeometry() const;
1513 virtual QRegion shape() const = 0;
1514 int screen() const;
1515 /** @internal Do not use */
1516 bool hasOwnShape() const; // only for shadow effect, for now
1517 QPoint pos() const;
1518 QSize size() const;
1519 QRect rect() const;
1520 bool isMovable() const;
1521 bool isMovableAcrossScreens() const;
1522 bool isUserMove() const;
1523 bool isUserResize() const;
1524 QRect iconGeometry() const;
1525
1526 /**
1527 * Geometry of the actual window contents inside the whole (including decorations) window.
1528 */
1529 QRect contentsRect() const;
1530 /**
1531 * Geometry of the transparent rect in the decoration.
1532 * May be different from contentsRect() if the decoration is extended into the client area.
1533 * @since 4.5
1534 */
1535 virtual QRect decorationInnerRect() const = 0;
1536 bool hasDecoration() const;
1537 bool decorationHasAlpha() const;
1538 virtual QByteArray readProperty(long atom, long type, int format) const = 0;
1539 virtual void deleteProperty(long atom) const = 0;
1540
1541 QString caption() const;
1542 QPixmap icon() const;
1543 QString windowClass() const;
1544 QString windowRole() const;
1545 virtual const EffectWindowGroup* group() const = 0;
1546
1547 /**
1548 * Returns whether the window is a desktop background window (the one with wallpaper).
1549 * See _NET_WM_WINDOW_TYPE_DESKTOP at http://standards.freedesktop.org/wm-spec/wm-spec-latest.html .
1550 */
1551 bool isDesktop() const;
1552 /**
1553 * Returns whether the window is a dock (i.e. a panel).
1554 * See _NET_WM_WINDOW_TYPE_DOCK at http://standards.freedesktop.org/wm-spec/wm-spec-latest.html .
1555 */
1556 bool isDock() const;
1557 /**
1558 * Returns whether the window is a standalone (detached) toolbar window.
1559 * See _NET_WM_WINDOW_TYPE_TOOLBAR at http://standards.freedesktop.org/wm-spec/wm-spec-latest.html .
1560 */
1561 bool isToolbar() const;
1562 /**
1563 * Returns whether the window is a torn-off menu.
1564 * See _NET_WM_WINDOW_TYPE_MENU at http://standards.freedesktop.org/wm-spec/wm-spec-latest.html .
1565 */
1566 bool isMenu() const;
1567 /**
1568 * Returns whether the window is a "normal" window, i.e. an application or any other window
1569 * for which none of the specialized window types fit.
1570 * See _NET_WM_WINDOW_TYPE_NORMAL at http://standards.freedesktop.org/wm-spec/wm-spec-latest.html .
1571 */
1572 bool isNormalWindow() const; // normal as in 'NET::Normal or NET::Unknown non-transient'
1573 /**
1574 * Returns whether the window is any of special windows types (desktop, dock, splash, ...),
1575 * i.e. window types that usually don't have a window frame and the user does not use window
1576 * management (moving, raising,...) on them.
1577 */
1578 bool isSpecialWindow() const;
1579 /**
1580 * Returns whether the window is a dialog window.
1581 * See _NET_WM_WINDOW_TYPE_DIALOG at http://standards.freedesktop.org/wm-spec/wm-spec-latest.html .
1582 */
1583 bool isDialog() const;
1584 /**
1585 * Returns whether the window is a splashscreen. Note that many (especially older) applications
1586 * do not support marking their splash windows with this type.
1587 * See _NET_WM_WINDOW_TYPE_SPLASH at http://standards.freedesktop.org/wm-spec/wm-spec-latest.html .
1588 */
1589 bool isSplash() const;
1590 /**
1591 * Returns whether the window is a utility window, such as a tool window.
1592 * See _NET_WM_WINDOW_TYPE_UTILITY at http://standards.freedesktop.org/wm-spec/wm-spec-latest.html .
1593 */
1594 bool isUtility() const;
1595 /**
1596 * Returns whether the window is a dropdown menu (i.e. a popup directly or indirectly open
1597 * from the applications menubar).
1598 * See _NET_WM_WINDOW_TYPE_DROPDOWN_MENU at http://standards.freedesktop.org/wm-spec/wm-spec-latest.html .
1599 */
1600 bool isDropdownMenu() const;
1601 /**
1602 * Returns whether the window is a popup menu (that is not a torn-off or dropdown menu).
1603 * See _NET_WM_WINDOW_TYPE_POPUP_MENU at http://standards.freedesktop.org/wm-spec/wm-spec-latest.html .
1604 */
1605 bool isPopupMenu() const; // a context popup, not dropdown, not torn-off
1606 /**
1607 * Returns whether the window is a tooltip.
1608 * See _NET_WM_WINDOW_TYPE_TOOLTIP at http://standards.freedesktop.org/wm-spec/wm-spec-latest.html .
1609 */
1610 bool isTooltip() const;
1611 /**
1612 * Returns whether the window is a window with a notification.
1613 * See _NET_WM_WINDOW_TYPE_NOTIFICATION at http://standards.freedesktop.org/wm-spec/wm-spec-latest.html .
1614 */
1615 bool isNotification() const;
1616 /**
1617 * Returns whether the window is a combobox popup.
1618 * See _NET_WM_WINDOW_TYPE_COMBO at http://standards.freedesktop.org/wm-spec/wm-spec-latest.html .
1619 */
1620 bool isComboBox() const;
1621 /**
1622 * Returns whether the window is a Drag&Drop icon.
1623 * See _NET_WM_WINDOW_TYPE_DND at http://standards.freedesktop.org/wm-spec/wm-spec-latest.html .
1624 */
1625 bool isDNDIcon() const;
1626 /**
1627 * Returns the NETWM window type
1628 * See http://standards.freedesktop.org/wm-spec/wm-spec-latest.html .
1629 */
1630 NET::WindowType windowType() const;
1631 /**
1632 * Returns whether the window is managed by KWin (it has control over its placement and other
1633 * aspects, as opposed to override-redirect windows that are entirely handled by the application).
1634 */
1635 bool isManaged() const; // whether it's managed or override-redirect
1636 /**
1637 * Returns whether or not the window can accept keyboard focus.
1638 */
1639 bool acceptsFocus() const;
1640 /**
1641 * Returns whether or not the window is kept above all other windows.
1642 */
1643 bool keepAbove() const;
1644
1645 bool isModal() const;
1646 Q_SCRIPTABLE virtual KWin::EffectWindow* findModal() = 0;
1647 Q_SCRIPTABLE virtual QList<KWin::EffectWindow*> mainWindows() const = 0;
1648
1649 /**
1650 * Returns whether the window should be excluded from window switching effects.
1651 * @since 4.5
1652 */
1653 bool isSkipSwitcher() const;
1654
1655 /**
1656 * Returns the unmodified window quad list. Can also be used to force rebuilding.
1657 */
1658 virtual WindowQuadList buildQuads(bool force = false) const = 0;
1659
1660 void setMinimized(bool minimize);
1661 void minimize();
1662 void unminimize();
1663 Q_SCRIPTABLE void closeWindow() const;
1664
1665 bool isCurrentTab() const;
1666
1667 /**
1668 * @since 4.11
1669 **/
1670 bool isVisible() const;
1671
1672 /**
1673 * @since 5.0
1674 **/
1675 bool skipsCloseAnimation() const;
1676
1677 /**
1678 * Can be used to by effects to store arbitrary data in the EffectWindow.
1679 */
1680 Q_SCRIPTABLE virtual void setData(int role, const QVariant &data) = 0;
1681 Q_SCRIPTABLE virtual QVariant data(int role) const = 0;
1682
1683 /**
1684 * @brief References the previous window pixmap to prevent discarding.
1685 *
1686 * This method allows to reference the previous window pixmap in case that a window changed
1687 * its size, which requires a new window pixmap. By referencing the previous (and then outdated)
1688 * window pixmap an effect can for example cross fade the current window pixmap with the previous
1689 * one. This allows for smoother transitions for window geometry changes.
1690 *
1691 * If an effect calls this method on a window it also needs to call @link unreferencePreviousWindowPixmap
1692 * once it does no longer need the previous window pixmap.
1693 *
1694 * Note: the window pixmap is not kept forever even when referenced. If the geometry changes again, so that
1695 * a new window pixmap is created, the previous window pixmap will be exchanged with the current one. This
1696 * means it's still possible to have rendering glitches. An effect is supposed to track for itself the changes
1697 * to the window's geometry and decide how the transition should continue in such a situation.
1698 *
1699 * @see unreferencePreviousWindowPixmap
1700 * @since 4.11
1701 */
1702 virtual void referencePreviousWindowPixmap() = 0;
1703 /**
1704 * @brief Unreferences the previous window pixmap. Only relevant after @link referencePreviousWindowPixmap had
1705 * been called.
1706 *
1707 * @see referencePreviousWindowPixmap
1708 * @since 4.11
1709 */
1710 virtual void unreferencePreviousWindowPixmap() = 0;
1711};
1712
1713class KWIN_EXPORT EffectWindowGroup
1714{
1715public:
1716 virtual ~EffectWindowGroup();
1717 virtual EffectWindowList members() const = 0;
1718};
1719
1720class KWIN_EXPORT GlobalShortcutsEditor : public KShortcutsEditor
1721{
1722public:
1723 explicit GlobalShortcutsEditor(QWidget *parent);
1724};
1725
1726
1727struct GLVertex2D
1728{
1729 QVector2D position;
1730 QVector2D texcoord;
1731};
1732
1733struct GLVertex3D
1734{
1735 QVector3D position;
1736 QVector2D texcoord;
1737};
1738
1739
1740/**
1741 * @short Vertex class
1742 *
1743 * A vertex is one position in a window. WindowQuad consists of four WindowVertex objects
1744 * and represents one part of a window.
1745 **/
1746class KWIN_EXPORT WindowVertex
1747{
1748public:
1749 WindowVertex();
1750 WindowVertex(double x, double y, double tx, double ty);
1751
1752 double x() const { return px; }
1753 double y() const { return py; }
1754 double u() const { return tx; }
1755 double v() const { return ty; }
1756 double originalX() const { return ox; }
1757 double originalY() const { return oy; }
1758 double textureX() const { return tx; }
1759 double textureY() const { return ty; }
1760 void move(double x, double y);
1761 void setX(double x);
1762 void setY(double y);
1763
1764private:
1765 friend class WindowQuad;
1766 friend class WindowQuadList;
1767 double px, py; // position
1768 double ox, oy; // origional position
1769 double tx, ty; // texture coords
1770};
1771
1772/**
1773 * @short Class representing one area of a window.
1774 *
1775 * WindowQuads consists of four WindowVertex objects and represents one part of a window.
1776 */
1777// NOTE: This class expects the (original) vertices to be in the clockwise order starting from topleft.
1778class KWIN_EXPORT WindowQuad
1779{
1780public:
1781 explicit WindowQuad(WindowQuadType type, int id = -1);
1782 WindowQuad makeSubQuad(double x1, double y1, double x2, double y2) const;
1783 WindowVertex& operator[](int index);
1784 const WindowVertex& operator[](int index) const;
1785 WindowQuadType type() const;
1786 int id() const;
1787 bool decoration() const;
1788 bool effect() const;
1789 double left() const;
1790 double right() const;
1791 double top() const;
1792 double bottom() const;
1793 double originalLeft() const;
1794 double originalRight() const;
1795 double originalTop() const;
1796 double originalBottom() const;
1797 bool smoothNeeded() const;
1798 bool isTransformed() const;
1799private:
1800 friend class WindowQuadList;
1801 WindowVertex verts[ 4 ];
1802 WindowQuadType quadType; // 0 - contents, 1 - decoration
1803 int quadID;
1804};
1805
1806class KWIN_EXPORT WindowQuadList
1807 : public QList< WindowQuad >
1808{
1809public:
1810 WindowQuadList splitAtX(double x) const;
1811 WindowQuadList splitAtY(double y) const;
1812 WindowQuadList makeGrid(int maxquadsize) const;
1813 WindowQuadList makeRegularGrid(int xSubdivisions, int ySubdivisions) const;
1814 WindowQuadList select(WindowQuadType type) const;
1815 WindowQuadList filterOut(WindowQuadType type) const;
1816 bool smoothNeeded() const;
1817 void makeInterleavedArrays(unsigned int type, GLVertex2D *vertices, const QMatrix4x4 &matrix) const;
1818 void makeArrays(float** vertices, float** texcoords, const QSizeF &size, bool yInverted) const;
1819 bool isTransformed() const;
1820};
1821
1822class KWIN_EXPORT WindowPrePaintData
1823{
1824public:
1825 int mask;
1826 /**
1827 * Region that will be painted, in screen coordinates.
1828 **/
1829 QRegion paint;
1830 /**
1831 * The clip region will be subtracted from paint region of following windows.
1832 * I.e. window will definitely cover it's clip region
1833 **/
1834 QRegion clip;
1835 WindowQuadList quads;
1836 /**
1837 * Simple helper that sets data to say the window will be painted as non-opaque.
1838 * Takes also care of changing the regions.
1839 */
1840 void setTranslucent();
1841 /**
1842 * Helper to mark that this window will be transformed
1843 **/
1844 void setTransformed();
1845};
1846
1847class KWIN_EXPORT PaintData
1848{
1849public:
1850 virtual ~PaintData();
1851 /**
1852 * @returns scale factor in X direction.
1853 * @since 4.10
1854 **/
1855 qreal xScale() const;
1856 /**
1857 * @returns scale factor in Y direction.
1858 * @since 4.10
1859 **/
1860 qreal yScale() const;
1861 /**
1862 * @returns scale factor in Z direction.
1863 * @since 4.10
1864 **/
1865 qreal zScale() const;
1866 /**
1867 * Sets the scale factor in X direction to @p scale
1868 * @param scale The scale factor in X direction
1869 * @since 4.10
1870 **/
1871 void setXScale(qreal scale);
1872 /**
1873 * Sets the scale factor in Y direction to @p scale
1874 * @param scale The scale factor in Y direction
1875 * @since 4.10
1876 **/
1877 void setYScale(qreal scale);
1878 /**
1879 * Sets the scale factor in Z direction to @p scale
1880 * @param scale The scale factor in Z direction
1881 * @since 4.10
1882 **/
1883 void setZScale(qreal scale);
1884 /**
1885 * Sets the scale factor in X and Y direction.
1886 * @param scale The scale factor for X and Y direction
1887 * @since 4.10
1888 **/
1889 void setScale(const QVector2D &scale);
1890 /**
1891 * Sets the scale factor in X, Y and Z direction
1892 * @param scale The scale factor for X, Y and Z direction
1893 * @since 4.10
1894 **/
1895 void setScale(const QVector3D &scale);
1896 const QGraphicsScale &scale() const;
1897 const QVector3D &translation() const;
1898 /**
1899 * @returns the translation in X direction.
1900 * @since 4.10
1901 **/
1902 qreal xTranslation() const;
1903 /**
1904 * @returns the translation in Y direction.
1905 * @since 4.10
1906 **/
1907 qreal yTranslation() const;
1908 /**
1909 * @returns the translation in Z direction.
1910 * @since 4.10
1911 **/
1912 qreal zTranslation() const;
1913 /**
1914 * Sets the translation in X direction to @p translate.
1915 * @since 4.10
1916 **/
1917 void setXTranslation(qreal translate);
1918 /**
1919 * Sets the translation in Y direction to @p translate.
1920 * @since 4.10
1921 **/
1922 void setYTranslation(qreal translate);
1923 /**
1924 * Sets the translation in Z direction to @p translate.
1925 * @since 4.10
1926 **/
1927 void setZTranslation(qreal translate);
1928 /**
1929 * Performs a translation by adding the values component wise.
1930 * @param x Translation in X direction
1931 * @param y Translation in Y direction
1932 * @param z Translation in Z direction
1933 * @since 4.10
1934 **/
1935 void translate(qreal x, qreal y = 0.0, qreal z = 0.0);
1936 /**
1937 * Performs a translation by adding the values component wise.
1938 * Overloaded method for convenience.
1939 * @param translate The translation
1940 * @since 4.10
1941 **/
1942 void translate(const QVector3D &translate);
1943
1944 /**
1945 * Sets the rotation angle.
1946 * @param angle The new rotation angle.
1947 * @since 4.10
1948 * @see rotationAngle()
1949 **/
1950 void setRotationAngle(qreal angle);
1951 /**
1952 * Returns the rotation angle.
1953 * Initially 0.0.
1954 * @returns The current rotation angle.
1955 * @since 4.10
1956 * @see setRotationAngle
1957 **/
1958 qreal rotationAngle() const;
1959 /**
1960 * Sets the rotation origin.
1961 * @param origin The new rotation origin.
1962 * @since 4.10
1963 * @see rotationOrigin()
1964 **/
1965 void setRotationOrigin(const QVector3D &origin);
1966 /**
1967 * Returns the rotation origin. That is the point in space which is fixed during the rotation.
1968 * Initially this is 0/0/0.
1969 * @returns The rotation's origin
1970 * @since 4.10
1971 * @see setRotationOrigin()
1972 **/
1973 QVector3D rotationOrigin() const;
1974 /**
1975 * Sets the rotation axis.
1976 * Set a component to 1.0 to rotate around this axis and to 0.0 to disable rotation around the
1977 * axis.
1978 * @param axis A vector holding information on which axis to rotate
1979 * @since 4.10
1980 * @see rotationAxis()
1981 **/
1982 void setRotationAxis(const QVector3D &axis);
1983 /**
1984 * Sets the rotation axis.
1985 * Overloaded method for convenience.
1986 * @param axis The axis around which should be rotated.
1987 * @since 4.10
1988 * @see rotationAxis()
1989 **/
1990 void setRotationAxis(Qt::Axis axis);
1991 /**
1992 * The current rotation axis.
1993 * By default the rotation is (0/0/1) which means a rotation around the z axis.
1994 * @returns The current rotation axis.
1995 * @since 4.10
1996 * @see setRotationAxis
1997 **/
1998 QVector3D rotationAxis() const;
1999
2000protected:
2001 PaintData();
2002 PaintData(const PaintData &other);
2003
2004private:
2005 PaintDataPrivate * const d;
2006};
2007
2008class KWIN_EXPORT WindowPaintData : public PaintData
2009{
2010public:
2011 explicit WindowPaintData(EffectWindow* w);
2012 WindowPaintData(const WindowPaintData &other);
2013 virtual ~WindowPaintData();
2014 /**
2015 * Scales the window by @p scale factor.
2016 * Multiplies all three components by the given factor.
2017 * @since 4.10
2018 **/
2019 WindowPaintData& operator*=(qreal scale);
2020 /**
2021 * Scales the window by @p scale factor.
2022 * Performs a component wise multiplication on x and y components.
2023 * @since 4.10
2024 **/
2025 WindowPaintData& operator*=(const QVector2D &scale);
2026 /**
2027 * Scales the window by @p scale factor.
2028 * Performs a component wise multiplication.
2029 * @since 4.10
2030 **/
2031 WindowPaintData& operator*=(const QVector3D &scale);
2032 /**
2033 * Translates the window by the given @p translation and returns a reference to the ScreenPaintData.
2034 * @since 4.10
2035 **/
2036 WindowPaintData& operator+=(const QPointF &translation);
2037 /**
2038 * Translates the window by the given @p translation and returns a reference to the ScreenPaintData.
2039 * Overloaded method for convenience.
2040 * @since 4.10
2041 **/
2042 WindowPaintData& operator+=(const QPoint &translation);
2043 /**
2044 * Translates the window by the given @p translation and returns a reference to the ScreenPaintData.
2045 * Overloaded method for convenience.
2046 * @since 4.10
2047 **/
2048 WindowPaintData& operator+=(const QVector2D &translation);
2049 /**
2050 * Translates the window by the given @p translation and returns a reference to the ScreenPaintData.
2051 * Overloaded method for convenience.
2052 * @since 4.10
2053 **/
2054 WindowPaintData& operator+=(const QVector3D &translation);
2055 /**
2056 * Window opacity, in range 0 = transparent to 1 = fully opaque
2057 * Opacity for decoration is opacity*decorationOpacity
2058 * @see decorationOpacity
2059 * @see setOpacity
2060 * @see setDecorationOpacity
2061 * @since 4.10
2062 */
2063 qreal opacity() const;
2064 qreal decorationOpacity() const;
2065 /**
2066 * Sets the window opacity to the new @p opacity.
2067 * If you want to modify the existing opacity level consider using multiplyOpacity.
2068 * @param opacity The new opacity level
2069 * @since 4.10
2070 **/
2071 void setOpacity(qreal opacity);
2072 void setDecorationOpacity(qreal opacity);
2073 /**
2074 * Multiplies the current opacity with the @p factor.
2075 * @param factor Factor with which the opacity should be multiplied
2076 * @return New opacity level
2077 * @since 4.10
2078 **/
2079 qreal multiplyOpacity(qreal factor);
2080 /**
2081 * Multiplies the current decoration opacity with the @p factor.
2082 * @param factor Factor with which the opacity should be multiplied
2083 * @return New decoration opacity level
2084 * @since 4.10
2085 **/
2086 qreal multiplyDecorationOpacity(qreal factor);
2087 /**
2088 * Saturation of the window, in range [0; 1]
2089 * 1 means that the window is unchanged, 0 means that it's completely
2090 * unsaturated (greyscale). 0.5 would make the colors less intense,
2091 * but not completely grey
2092 * Use EffectsHandler::saturationSupported() to find out whether saturation
2093 * is supported by the system, otherwise this value has no effect.
2094 * @return The current saturation
2095 * @see setSaturation()
2096 * @since 4.10
2097 **/
2098 qreal saturation() const;
2099 /**
2100 * Sets the window saturation level to @p saturation.
2101 * If you want to modify the existing saturation level consider using multiplySaturation.
2102 * @param saturation The new saturation level
2103 * @since 4.10
2104 **/
2105 void setSaturation(qreal saturation) const;
2106 /**
2107 * Multiplies the current saturation with @p factor.
2108 * @param factor with which the saturation should be multiplied
2109 * @return New saturation level
2110 * @since 4.10
2111 **/
2112 qreal multiplySaturation(qreal factor);
2113 /**
2114 * Brightness of the window, in range [0; 1]
2115 * 1 means that the window is unchanged, 0 means that it's completely
2116 * black. 0.5 would make it 50% darker than usual
2117 **/
2118 qreal brightness() const;
2119 /**
2120 * Sets the window brightness level to @p brightness.
2121 * If you want to modify the existing brightness level consider using multiplyBrightness.
2122 * @param brightness The new brightness level
2123 **/
2124 void setBrightness(qreal brightness);
2125 /**
2126 * Multiplies the current brightness level with @p factor.
2127 * @param factor with which the brightness should be multiplied.
2128 * @return New brightness level
2129 * @since 4.10
2130 **/
2131 qreal multiplyBrightness(qreal factor);
2132 /**
2133 * The screen number for which the painting should be done.
2134 * This affects color correction (different screens may need different
2135 * color correction lookup tables because they have different ICC profiles).
2136 * @return screen for which painting should be done
2137 */
2138 int screen() const;
2139 /**
2140 * @param screen New screen number
2141 * A value less than 0 will indicate that a default profile should be done.
2142 */
2143 void setScreen(int screen) const;
2144 /**
2145 * @brief Sets the cross fading @p factor to fade over with previously sized window.
2146 * If @c 1.0 only the current window is used, if @c 0.0 only the previous window is used.
2147 *
2148 * By default only the current window is used. This factor can only make any visual difference
2149 * if the previous window get referenced.
2150 *
2151 * @param factor The cross fade factor between @c 0.0 (previous window) and @c 1.0 (current window)
2152 * @see crossFadeProgress
2153 */
2154 void setCrossFadeProgress(qreal factor);
2155 /**
2156 * @see setCrossFadeProgress
2157 */
2158 qreal crossFadeProgress() const;
2159 WindowQuadList quads;
2160 /**
2161 * Shader to be used for rendering, if any.
2162 */
2163 GLShader* shader;
2164private:
2165 WindowPaintDataPrivate * const d;
2166};
2167
2168class KWIN_EXPORT ScreenPaintData : public PaintData
2169{
2170public:
2171 ScreenPaintData();
2172 ScreenPaintData(const ScreenPaintData &other);
2173 /**
2174 * Scales the screen by @p scale factor.
2175 * Multiplies all three components by the given factor.
2176 * @since 4.10
2177 **/
2178 ScreenPaintData& operator*=(qreal scale);
2179 /**
2180 * Scales the screen by @p scale factor.
2181 * Performs a component wise multiplication on x and y components.
2182 * @since 4.10
2183 **/
2184 ScreenPaintData& operator*=(const QVector2D &scale);
2185 /**
2186 * Scales the screen by @p scale factor.
2187 * Performs a component wise multiplication.
2188 * @since 4.10
2189 **/
2190 ScreenPaintData& operator*=(const QVector3D &scale);
2191 /**
2192 * Translates the screen by the given @p translation and returns a reference to the ScreenPaintData.
2193 * @since 4.10
2194 **/
2195 ScreenPaintData& operator+=(const QPointF &translation);
2196 /**
2197 * Translates the screen by the given @p translation and returns a reference to the ScreenPaintData.
2198 * Overloaded method for convenience.
2199 * @since 4.10
2200 **/
2201 ScreenPaintData& operator+=(const QPoint &translation);
2202 /**
2203 * Translates the screen by the given @p translation and returns a reference to the ScreenPaintData.
2204 * Overloaded method for convenience.
2205 * @since 4.10
2206 **/
2207 ScreenPaintData& operator+=(const QVector2D &translation);
2208 /**
2209 * Translates the screen by the given @p translation and returns a reference to the ScreenPaintData.
2210 * Overloaded method for convenience.
2211 * @since 4.10
2212 **/
2213 ScreenPaintData& operator+=(const QVector3D &translation);
2214 ScreenPaintData& operator=(const ScreenPaintData &rhs);
2215};
2216
2217class KWIN_EXPORT ScreenPrePaintData
2218{
2219public:
2220 int mask;
2221 QRegion paint;
2222};
2223
2224/**
2225 * @short Helper class for restricting painting area only to allowed area.
2226 *
2227 * This helper class helps specifying areas that should be painted, clipping
2228 * out the rest. The simplest usage is creating an object on the stack
2229 * and giving it the area that is allowed to be painted to. When the object
2230 * is destroyed, the restriction will be removed.
2231 * Note that all painting code must use paintArea() to actually perform the clipping.
2232 */
2233class KWIN_EXPORT PaintClipper
2234{
2235public:
2236 /**
2237 * Calls push().
2238 */
2239 explicit PaintClipper(const QRegion& allowed_area);
2240 /**
2241 * Calls pop().
2242 */
2243 ~PaintClipper();
2244 /**
2245 * Allows painting only in the given area. When areas have been already
2246 * specified, painting is allowed only in the intersection of all areas.
2247 */
2248 static void push(const QRegion& allowed_area);
2249 /**
2250 * Removes the given area. It must match the top item in the stack.
2251 */
2252 static void pop(const QRegion& allowed_area);
2253 /**
2254 * Returns true if any clipping should be performed.
2255 */
2256 static bool clip();
2257 /**
2258 * If clip() returns true, this function gives the resulting area in which
2259 * painting is allowed. It is usually simpler to use the helper Iterator class.
2260 */
2261 static QRegion paintArea();
2262 /**
2263 * Helper class to perform the clipped painting. The usage is:
2264 * @code
2265 * for ( PaintClipper::Iterator iterator;
2266 * !iterator.isDone();
2267 * iterator.next())
2268 * { // do the painting, possibly use iterator.boundingRect()
2269 * }
2270 * @endcode
2271 */
2272 class KWIN_EXPORT Iterator
2273 {
2274 public:
2275 Iterator();
2276 ~Iterator();
2277 bool isDone();
2278 void next();
2279 QRect boundingRect() const;
2280 private:
2281 struct Data;
2282 Data* data;
2283 };
2284private:
2285 QRegion area;
2286 static QStack< QRegion >* areas;
2287};
2288
2289/**
2290 * @internal
2291 */
2292template <typename T>
2293class KWIN_EXPORT Motion
2294{
2295public:
2296 /**
2297 * Creates a new motion object. "Strength" is the amount of
2298 * acceleration that is applied to the object when the target
2299 * changes and "smoothness" relates to how fast the object
2300 * can change its direction and speed.
2301 */
2302 explicit Motion(T initial, double strength, double smoothness);
2303 /**
2304 * Creates an exact copy of another motion object, including
2305 * position, target and velocity.
2306 */
2307 Motion(const Motion<T> &other);
2308 ~Motion();
2309
2310 inline T value() const {
2311 return m_value;
2312 }
2313 inline void setValue(const T value) {
2314 m_value = value;
2315 }
2316 inline T target() const {
2317 return m_target;
2318 }
2319 inline void setTarget(const T target) {
2320 m_start = m_value;
2321 m_target = target;
2322 }
2323 inline T velocity() const {
2324 return m_velocity;
2325 }
2326 inline void setVelocity(const T velocity) {
2327 m_velocity = velocity;
2328 }
2329
2330 inline double strength() const {
2331 return m_strength;
2332 }
2333 inline void setStrength(const double strength) {
2334 m_strength = strength;
2335 }
2336 inline double smoothness() const {
2337 return m_smoothness;
2338 }
2339 inline void setSmoothness(const double smoothness) {
2340 m_smoothness = smoothness;
2341 }
2342 inline T startValue() {
2343 return m_start;
2344 }
2345
2346 /**
2347 * The distance between the current position and the target.
2348 */
2349 inline T distance() const {
2350 return m_target - m_value;
2351 }
2352
2353 /**
2354 * Calculates the new position if not at the target. Called
2355 * once per frame only.
2356 */
2357 void calculate(const int msec);
2358 /**
2359 * Place the object on top of the target immediately,
2360 * bypassing all movement calculation.
2361 */
2362 void finish();
2363
2364private:
2365 T m_value;
2366 T m_start;
2367 T m_target;
2368 T m_velocity;
2369 double m_strength;
2370 double m_smoothness;
2371};
2372
2373/**
2374 * @short A single 1D motion dynamics object.
2375 *
2376 * This class represents a single object that can be moved around a
2377 * 1D space. Although it can be used directly by itself it is
2378 * recommended to use a motion manager instead.
2379 */
2380class KWIN_EXPORT Motion1D : public Motion<double>
2381{
2382public:
2383 explicit Motion1D(double initial = 0.0, double strength = 0.08, double smoothness = 4.0);
2384 Motion1D(const Motion1D &other);
2385 ~Motion1D();
2386};
2387
2388/**
2389 * @short A single 2D motion dynamics object.
2390 *
2391 * This class represents a single object that can be moved around a
2392 * 2D space. Although it can be used directly by itself it is
2393 * recommended to use a motion manager instead.
2394 */
2395class KWIN_EXPORT Motion2D : public Motion<QPointF>
2396{
2397public:
2398 explicit Motion2D(QPointF initial = QPointF(), double strength = 0.08, double smoothness = 4.0);
2399 Motion2D(const Motion2D &other);
2400 ~Motion2D();
2401};
2402
2403/**
2404 * @short Helper class for motion dynamics in KWin effects.
2405 *
2406 * This motion manager class is intended to help KWin effect authors
2407 * move windows across the screen smoothly and naturally. Once
2408 * windows are registered by the manager the effect can issue move
2409 * commands with the moveWindow() methods. The position of any
2410 * managed window can be determined in realtime by the
2411 * transformedGeometry() method. As the manager knows if any windows
2412 * are moving at any given time it can also be used as a notifier as
2413 * to see whether the effect is active or not.
2414 */
2415class KWIN_EXPORT WindowMotionManager
2416{
2417public:
2418 /**
2419 * Creates a new window manager object.
2420 */
2421 explicit WindowMotionManager(bool useGlobalAnimationModifier = true);
2422 ~WindowMotionManager();
2423
2424 /**
2425 * Register a window for managing.
2426 */
2427 void manage(EffectWindow *w);
2428 /**
2429 * Register a list of windows for managing.
2430 */
2431 inline void manage(EffectWindowList list) {
2432 for (int i = 0; i < list.size(); i++)
2433 manage(list.at(i));
2434 }
2435 /**
2436 * Deregister a window. All transformations applied to the
2437 * window will be permanently removed and cannot be recovered.
2438 */
2439 void unmanage(EffectWindow *w);
2440 /**
2441 * Deregister all windows, returning the manager to its
2442 * originally initiated state.
2443 */
2444 void unmanageAll();
2445 /**
2446 * Determine the new positions for windows that have not
2447 * reached their target. Called once per frame, usually in
2448 * prePaintScreen(). Remember to set the
2449 * Effect::PAINT_SCREEN_WITH_TRANSFORMED_WINDOWS flag.
2450 */
2451 void calculate(int time);
2452 /**
2453 * Modify a registered window's paint data to make it appear
2454 * at its real location on the screen. Usually called in
2455 * paintWindow(). Remember to flag the window as having been
2456 * transformed in prePaintWindow() by calling
2457 * WindowPrePaintData::setTransformed()
2458 */
2459 void apply(EffectWindow *w, WindowPaintData &data);
2460 /**
2461 * Set all motion targets and values back to where the
2462 * windows were before transformations. The same as
2463 * unmanaging then remanaging all windows.
2464 */
2465 void reset();
2466 /**
2467 * Resets the motion target and current value of a single
2468 * window.
2469 */
2470 void reset(EffectWindow *w);
2471
2472 /**
2473 * Ask the manager to move the window to the target position
2474 * with the specified scale. If `yScale` is not provided or
2475 * set to 0.0, `scale` will be used as the scale in the
2476 * vertical direction as well as in the horizontal direction.
2477 */
2478 void moveWindow(EffectWindow *w, QPoint target, double scale = 1.0, double yScale = 0.0);
2479 /**
2480 * This is an overloaded method, provided for convenience.
2481 *
2482 * Ask the manager to move the window to the target rectangle.
2483 * Automatically determines scale.
2484 */
2485 inline void moveWindow(EffectWindow *w, QRect target) {
2486 // TODO: Scale might be slightly different in the comparison due to rounding
2487 moveWindow(w, target.topLeft(),
2488 target.width() / double(w->width()), target.height() / double(w->height()));
2489 }
2490
2491 /**
2492 * Retrieve the current tranformed geometry of a registered
2493 * window.
2494 */
2495 QRectF transformedGeometry(EffectWindow *w) const;
2496 /**
2497 * Sets the current transformed geometry of a registered window to the given geometry.
2498 * @see transformedGeometry
2499 * @since 4.5
2500 */
2501 void setTransformedGeometry(EffectWindow *w, const QRectF &geometry);
2502 /**
2503 * Retrieve the current target geometry of a registered
2504 * window.
2505 */
2506 QRectF targetGeometry(EffectWindow *w) const;
2507 /**
2508 * Return the window that has its transformed geometry under
2509 * the specified point. It is recommended to use the stacking
2510 * order as it's what the user sees, but it is slightly
2511 * slower to process.
2512 */
2513 EffectWindow* windowAtPoint(QPoint point, bool useStackingOrder = true) const;
2514
2515 /**
2516 * Return a list of all currently registered windows.
2517 */
2518 inline EffectWindowList managedWindows() const {
2519 return m_managedWindows.keys();
2520 }
2521 /**
2522 * Returns whether or not a specified window is being managed
2523 * by this manager object.
2524 */
2525 inline bool isManaging(EffectWindow *w) const {
2526 return m_managedWindows.contains(w);
2527 }
2528 /**
2529 * Returns whether or not this manager object is actually
2530 * managing any windows or not.
2531 */
2532 inline bool managingWindows() const {
2533 return !m_managedWindows.empty();
2534 }
2535 /**
2536 * Returns whether all windows have reached their targets yet
2537 * or not. Can be used to see if an effect should be
2538 * processed and displayed or not.
2539 */
2540 inline bool areWindowsMoving() const {
2541 return !m_movingWindowsSet.isEmpty();
2542 }
2543 /**
2544 * Returns whether a window has reached its targets yet
2545 * or not.
2546 */
2547 inline bool isWindowMoving(EffectWindow *w) const {
2548 return m_movingWindowsSet.contains(w);
2549 }
2550
2551private:
2552 bool m_useGlobalAnimationModifier;
2553 struct WindowMotion {
2554 // TODO: Rotation, etc?
2555 Motion2D translation; // Absolute position
2556 Motion2D scale; // xScale and yScale
2557 };
2558 QHash<EffectWindow*, WindowMotion> m_managedWindows;
2559 QSet<EffectWindow*> m_movingWindowsSet;
2560};
2561
2562/**
2563 * @short Helper class for displaying text and icons in frames.
2564 *
2565 * Paints text and/or and icon with an optional frame around them. The
2566 * available frames includes one that follows the default Plasma theme and
2567 * another that doesn't.
2568 * It is recommended to use this class whenever displaying text.
2569 */
2570class KWIN_EXPORT EffectFrame
2571{
2572public:
2573 EffectFrame();
2574 virtual ~EffectFrame();
2575
2576 /**
2577 * Delete any existing textures to free up graphics memory. They will
2578 * be automatically recreated the next time they are required.
2579 */
2580 virtual void free() = 0;
2581
2582 /**
2583 * Render the frame.
2584 */
2585 virtual void render(QRegion region = infiniteRegion(), double opacity = 1.0, double frameOpacity = 1.0) = 0;
2586
2587 virtual void setPosition(const QPoint& point) = 0;
2588 /**
2589 * Set the text alignment for static frames and the position alignment
2590 * for non-static.
2591 */
2592 virtual void setAlignment(Qt::Alignment alignment) = 0;
2593 virtual Qt::Alignment alignment() const = 0;
2594 virtual void setGeometry(const QRect& geometry, bool force = false) = 0;
2595 virtual const QRect& geometry() const = 0;
2596
2597 virtual void setText(const QString& text) = 0;
2598 virtual const QString& text() const = 0;
2599 virtual void setFont(const QFont& font) = 0;
2600 virtual const QFont& font() const = 0;
2601 /**
2602 * Set the icon that will appear on the left-hand size of the frame.
2603 */
2604 virtual void setIcon(const QPixmap& icon) = 0;
2605 virtual const QPixmap& icon() const = 0;
2606 virtual void setIconSize(const QSize& size) = 0;
2607 virtual const QSize& iconSize() const = 0;
2608
2609 /**
2610 * Sets the geometry of a selection.
2611 * To remove the selection set a null rect.
2612 * @param selection The geometry of the selection in screen coordinates.
2613 **/
2614 virtual void setSelection(const QRect& selection) = 0;
2615
2616 /**
2617 * @param shader The GLShader for rendering.
2618 **/
2619 virtual void setShader(GLShader* shader) = 0;
2620 /**
2621 * @returns The GLShader used for rendering or null if none.
2622 **/
2623 virtual GLShader* shader() const = 0;
2624
2625 /**
2626 * @returns The style of this EffectFrame.
2627 **/
2628 virtual EffectFrameStyle style() const = 0;
2629
2630 /**
2631 * If @p enable is @c true cross fading between icons and text is enabled
2632 * By default disabled. Use setCrossFadeProgress to cross fade.
2633 * Cross Fading is currently only available if OpenGL is used.
2634 * @param enable @c true enables cross fading, @c false disables it again
2635 * @see isCrossFade
2636 * @see setCrossFadeProgress
2637 * @since 4.6
2638 **/
2639 void enableCrossFade(bool enable);
2640 /**
2641 * @returns @c true if cross fading is enabled, @c false otherwise
2642 * @see enableCrossFade
2643 * @since 4.6
2644 **/
2645 bool isCrossFade() const;
2646 /**
2647 * Sets the current progress for cross fading the last used icon/text
2648 * with current icon/text to @p progress.
2649 * A value of 0.0 means completely old icon/text, a value of 1.0 means
2650 * completely current icon/text.
2651 * Default value is 1.0. You have to enable cross fade before using it.
2652 * Cross Fading is currently only available if OpenGL is used.
2653 * @see enableCrossFade
2654 * @see isCrossFade
2655 * @see crossFadeProgress
2656 * @since 4.6
2657 **/
2658 void setCrossFadeProgress(qreal progress);
2659 /**
2660 * @returns The current progress for cross fading
2661 * @see setCrossFadeProgress
2662 * @see enableCrossFade
2663 * @see isCrossFade
2664 * @since 4.6
2665 **/
2666 qreal crossFadeProgress() const;
2667
2668private:
2669 EffectFramePrivate* const d;
2670};
2671
2672/**
2673 * Pointer to the global EffectsHandler object.
2674 **/
2675extern KWIN_EXPORT EffectsHandler* effects;
2676
2677/***************************************************************
2678 WindowVertex
2679***************************************************************/
2680
2681inline
2682WindowVertex::WindowVertex()
2683 : px(0), py(0), tx(0), ty(0)
2684{
2685}
2686
2687inline
2688WindowVertex::WindowVertex(double _x, double _y, double _tx, double _ty)
2689 : px(_x), py(_y), ox(_x), oy(_y), tx(_tx), ty(_ty)
2690{
2691}
2692
2693inline
2694void WindowVertex::move(double x, double y)
2695{
2696 px = x;
2697 py = y;
2698}
2699
2700inline
2701void WindowVertex::setX(double x)
2702{
2703 px = x;
2704}
2705
2706inline
2707void WindowVertex::setY(double y)
2708{
2709 py = y;
2710}
2711
2712/***************************************************************
2713 WindowQuad
2714***************************************************************/
2715
2716inline
2717WindowQuad::WindowQuad(WindowQuadType t, int id)
2718 : quadType(t)
2719 , quadID(id)
2720{
2721}
2722
2723inline
2724WindowVertex& WindowQuad::operator[](int index)
2725{
2726 assert(index >= 0 && index < 4);
2727 return verts[ index ];
2728}
2729
2730inline
2731const WindowVertex& WindowQuad::operator[](int index) const
2732{
2733 assert(index >= 0 && index < 4);
2734 return verts[ index ];
2735}
2736
2737inline
2738WindowQuadType WindowQuad::type() const
2739{
2740 assert(quadType != WindowQuadError);
2741 return quadType;
2742}
2743
2744inline
2745int WindowQuad::id() const
2746{
2747 return quadID;
2748}
2749
2750inline
2751bool WindowQuad::decoration() const
2752{
2753 assert(quadType != WindowQuadError);
2754 return quadType == WindowQuadDecorationLeftRight ||
2755 quadType == WindowQuadDecorationTopBottom;
2756}
2757
2758inline
2759bool WindowQuad::effect() const
2760{
2761 assert(quadType != WindowQuadError);
2762 return quadType >= EFFECT_QUAD_TYPE_START;
2763}
2764
2765inline
2766bool WindowQuad::isTransformed() const
2767{
2768 return !(verts[ 0 ].px == verts[ 0 ].ox && verts[ 0 ].py == verts[ 0 ].oy
2769 && verts[ 1 ].px == verts[ 1 ].ox && verts[ 1 ].py == verts[ 1 ].oy
2770 && verts[ 2 ].px == verts[ 2 ].ox && verts[ 2 ].py == verts[ 2 ].oy
2771 && verts[ 3 ].px == verts[ 3 ].ox && verts[ 3 ].py == verts[ 3 ].oy);
2772}
2773
2774inline
2775double WindowQuad::left() const
2776{
2777 return qMin(verts[ 0 ].px, qMin(verts[ 1 ].px, qMin(verts[ 2 ].px, verts[ 3 ].px)));
2778}
2779
2780inline
2781double WindowQuad::right() const
2782{
2783 return qMax(verts[ 0 ].px, qMax(verts[ 1 ].px, qMax(verts[ 2 ].px, verts[ 3 ].px)));
2784}
2785
2786inline
2787double WindowQuad::top() const
2788{
2789 return qMin(verts[ 0 ].py, qMin(verts[ 1 ].py, qMin(verts[ 2 ].py, verts[ 3 ].py)));
2790}
2791
2792inline
2793double WindowQuad::bottom() const
2794{
2795 return qMax(verts[ 0 ].py, qMax(verts[ 1 ].py, qMax(verts[ 2 ].py, verts[ 3 ].py)));
2796}
2797
2798inline
2799double WindowQuad::originalLeft() const
2800{
2801 return verts[ 0 ].ox;
2802}
2803
2804inline
2805double WindowQuad::originalRight() const
2806{
2807 return verts[ 2 ].ox;
2808}
2809
2810inline
2811double WindowQuad::originalTop() const
2812{
2813 return verts[ 0 ].oy;
2814}
2815
2816inline
2817double WindowQuad::originalBottom() const
2818{
2819 return verts[ 2 ].oy;
2820}
2821
2822/***************************************************************
2823 Motion
2824***************************************************************/
2825
2826template <typename T>
2827Motion<T>::Motion(T initial, double strength, double smoothness)
2828 : m_value(initial)
2829 , m_start(initial)
2830 , m_target(initial)
2831 , m_velocity()
2832 , m_strength(strength)
2833 , m_smoothness(smoothness)
2834{
2835}
2836
2837template <typename T>
2838Motion<T>::Motion(const Motion &other)
2839 : m_value(other.value())
2840 , m_start(other.target())
2841 , m_target(other.target())
2842 , m_velocity(other.velocity())
2843 , m_strength(other.strength())
2844 , m_smoothness(other.smoothness())
2845{
2846}
2847
2848template <typename T>
2849Motion<T>::~Motion()
2850{
2851}
2852
2853template <typename T>
2854void Motion<T>::calculate(const int msec)
2855{
2856 if (m_value == m_target && m_velocity == T()) // At target and not moving
2857 return;
2858
2859 // Poor man's time independent calculation
2860 int steps = qMax(1, msec / 5);
2861 for (int i = 0; i < steps; i++) {
2862 T diff = m_target - m_value;
2863 T strength = diff * m_strength;
2864 m_velocity = (m_smoothness * m_velocity + strength) / (m_smoothness + 1.0);
2865 m_value += m_velocity;
2866 }
2867}
2868
2869template <typename T>
2870void Motion<T>::finish()
2871{
2872 m_value = m_target;
2873 m_velocity = T();
2874}
2875
2876/***************************************************************
2877 Effect
2878***************************************************************/
2879template <typename T>
2880int Effect::animationTime(int defaultDuration)
2881{
2882 return animationTime(T::duration() != 0 ? T::duration() : defaultDuration);
2883}
2884
2885} // namespace
2886Q_DECLARE_METATYPE(KWin::EffectWindow*)
2887Q_DECLARE_METATYPE(QList<KWin::EffectWindow*>)
2888
2889/** @} */
2890
2891#endif // KWINEFFECTS_H
2892