1
/*****************************************************************
2
KWin - the KDE window manager
3
This file is part of the KDE project.
5
Copyright (C) 2006 Lubos Lunak <l.lunak@kde.org>
7
You can Freely distribute this program under the GNU General Public
8
License. See the file "COPYING" for the exact licensing terms.
9
******************************************************************/
13
Files howto.cpp and howto.h implement HowtoEffect, a commented demo compositing
14
effect that fades out and again in a window after it has been activated.
16
Please see file howto.h first.
20
// Include the class definition.
26
// This macro creates entry function for the plugin. First argument is name, second is class name.
27
KWIN_EFFECT(howto, HowtoEffect)
29
// A pre-paint function that tells the compositing code how this effect will affect
30
// the painting. During every painting pass this function is called first, before
31
// the actual painting function.
33
// w - the window that will be painted
34
// mask - a mask of flags controlling the painting, setting or resetting flags changes
35
// how the painting will be done
36
// region - the region of the screen that needs to be painted, support for modifying it
37
// is not fully implemented yet, do not use
38
// time - time in milliseconds since the last paint, useful for animations
39
void HowtoEffect::prePaintWindow(EffectWindow* w, WindowPrePaintData& data, int time)
41
// Is this window the one that is going to be faded out and in again?
42
if (w == fade_window) {
43
// Simply add the time to the total progress. The value of progress will be used
44
// to determine how far in effect is.
46
// If progress is < 1000 (milliseconds), the effect is still in progress.
47
if (progress < 1000) { // complete change in 1000ms
48
// Since the effect will make the window translucent, explicitly change
49
// the flags so that the window will be painted only as translucent.
50
// Use a helper that also takes care of changing the clipping rectangle.
51
data.setTranslucent();
53
// If progress has reached 1000 (milliseconds), it means the effect is done
54
// and there is no window to fade anymore.
58
// Call the next effect (or the actual window painting code if this is the last effect).
59
// Effects are chained and they all modify something if needed and then call the next one.
60
effects->prePaintWindow(w, data, time);
63
// The function that handles the actual painting. Some simple modifications are possible
64
// by only changing the painting data. More complicated effects would do some painting
65
// or transformations directly.
67
// w - the window that will be painted
68
// mask - a mask of flags controlling the painting
69
// region - the region of the screen that needs to be painted, if mask includes the TRANSFORMED
70
// then special care needs to be taken, because the region may be infiniteRegion(), meaning
71
// everything needs to be painted
72
// data - painting data that can be modified to do some simple transformations
73
void HowtoEffect::paintWindow(EffectWindow* w, int mask, QRegion region, WindowPaintData& data)
75
// Is this the window to be faded out and in again?
76
if (w == fade_window) {
77
// This effect, after a window has been activated, fades it out to only 50% transparency
78
// and then fades it in again to be fully opaque (assuming it's otherwise a fully opaque
79
// window, otherwise the transparencies will be added).
80
if (progress <= 500) {
81
// For the first 500 milliseconds (progress being 0 to 500), the window is faded out.
82
// progress == 0 -> opacity *= 1
83
// progress == 500 -> opacity *= 0.5
84
// Note that the division is floating-point division to avoid integer rounding down.
85
// Note that data.opacity is not set but multiplied - this allows chaining of effects,
86
// for example if another effect always changes opacity of some window types.
87
data.opacity *= 1 - 0.5 * (progress / 500.0);
89
// For the second 500 milliseconds (progress being 500 to 1000), the window is
91
// progress == 500 -> opacity *= 0.5
92
// progress == 1000 -> opacity *= 1
93
data.opacity *= 0.5 + 0.5 * (progress - 500) / 500.0;
96
// Call the next effect.
97
effects->paintWindow(w, mask, region, data);
100
// The function that is called after the painting pass is finished. When an animation is going on,
101
// it can add repaints of some areas so that the next painting pass has to repaint them again.
102
void HowtoEffect::postPaintWindow(EffectWindow* w)
104
// Is this the window to be faded out and in again?
105
if (w == fade_window) {
106
// Trigger repaint of the whole window, this will cause it to be repainted the next painting pass.
107
w->addRepaintFull(); // trigger next animation repaint
109
// Call the next effect.
110
effects->postPaintWindow(w);
113
// This function is called when a new window becomes active.
114
void HowtoEffect::windowActivated(EffectWindow* c)
116
// Set the window to be faded (or NULL if no window is active).
118
if (fade_window != NULL) {
119
// If there is a window to be faded, reset the progress to zero.
121
// And add repaint to the window so that it needs to be repainted.
126
// This function is called when a window is closed.
127
void HowtoEffect::windowClosed(EffectWindow* c)
129
// If the window to be faded out and in is closed, just reset the pointer.
130
// This effect then will do nothing and just call the next effect.
131
if (fade_window == c)
135
// That's all. Now only the matching .desktop file is needed.