~ubuntu-branches/ubuntu/utopic/kde-workspace/utopic-proposed

« back to all changes in this revision

Viewing changes to kwin/effects/taskbarthumbnail/taskbarthumbnail.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Michał Zając
  • Date: 2011-07-09 08:31:15 UTC
  • Revision ID: james.westby@ubuntu.com-20110709083115-ohyxn6z93mily9fc
Tags: upstream-4.6.90
Import upstream version 4.6.90

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/********************************************************************
 
2
 KWin - the KDE window manager
 
3
 This file is part of the KDE project.
 
4
 
 
5
Copyright (C) 2007 Rivo Laks <rivolaks@hot.ee>
 
6
Copyright (C) 2007 Lubos Lunak <l.lunak@kde.org>
 
7
 
 
8
This program is free software; you can redistribute it and/or modify
 
9
it under the terms of the GNU General Public License as published by
 
10
the Free Software Foundation; either version 2 of the License, or
 
11
(at your option) any later version.
 
12
 
 
13
This program is distributed in the hope that it will be useful,
 
14
but WITHOUT ANY WARRANTY; without even the implied warranty of
 
15
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
16
GNU General Public License for more details.
 
17
 
 
18
You should have received a copy of the GNU General Public License
 
19
along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
20
*********************************************************************/
 
21
 
 
22
#include "taskbarthumbnail.h"
 
23
 
 
24
#include <kdebug.h>
 
25
 
 
26
#ifdef KWIN_HAVE_OPENGL_COMPOSITING
 
27
#include <kwinglutils.h>
 
28
#endif
 
29
 
 
30
// This effect shows a preview inside a window that has a special property set
 
31
// on it that says which window and where to render. It is used by the taskbar
 
32
// to show window previews in tooltips.
 
33
 
 
34
namespace KWin
 
35
{
 
36
 
 
37
KWIN_EFFECT(taskbarthumbnail, TaskbarThumbnailEffect)
 
38
 
 
39
TaskbarThumbnailEffect::TaskbarThumbnailEffect()
 
40
{
 
41
    atom = XInternAtom(display(), "_KDE_WINDOW_PREVIEW", False);
 
42
    effects->registerPropertyType(atom, true);
 
43
    // TODO hackish way to announce support, make better after 4.0
 
44
    unsigned char dummy = 0;
 
45
    XChangeProperty(display(), rootWindow(), atom, atom, 8, PropModeReplace, &dummy, 1);
 
46
    connect(effects, SIGNAL(windowAdded(EffectWindow*)), this, SLOT(slotWindowAdded(EffectWindow*)));
 
47
    connect(effects, SIGNAL(windowDeleted(EffectWindow*)), this, SLOT(slotWindowDeleted(EffectWindow*)));
 
48
    connect(effects, SIGNAL(windowDamaged(EffectWindow*,QRect)), this, SLOT(slotWindowDamaged(EffectWindow*,QRect)));
 
49
    connect(effects, SIGNAL(propertyNotify(EffectWindow*,long)), this, SLOT(slotPropertyNotify(EffectWindow*,long)));
 
50
}
 
51
 
 
52
TaskbarThumbnailEffect::~TaskbarThumbnailEffect()
 
53
{
 
54
    XDeleteProperty(display(), rootWindow(), atom);
 
55
    effects->registerPropertyType(atom, false);
 
56
}
 
57
 
 
58
void TaskbarThumbnailEffect::prePaintScreen(ScreenPrePaintData& data, int time)
 
59
{
 
60
    if (thumbnails.count() > 0) {
 
61
        data.mask |= PAINT_SCREEN_WITH_TRANSFORMED_WINDOWS_WITHOUT_FULL_REPAINTS;
 
62
    }
 
63
    effects->prePaintScreen(data, time);
 
64
}
 
65
 
 
66
void TaskbarThumbnailEffect::prePaintWindow(EffectWindow* w, WindowPrePaintData& data, int time)
 
67
{
 
68
    // TODO what if of the windows is translucent and one not? change data.mask?
 
69
    effects->prePaintWindow(w, data, time);
 
70
}
 
71
 
 
72
void TaskbarThumbnailEffect::paintWindow(EffectWindow* w, int mask, QRegion region, WindowPaintData& data)
 
73
{
 
74
    effects->paintWindow(w, mask, region, data);   // paint window first
 
75
    if (thumbnails.contains(w)) {
 
76
        // paint thumbnails on it
 
77
        int mask = PAINT_WINDOW_TRANSFORMED;
 
78
        if (data.opacity == 1.0)
 
79
            mask |= PAINT_WINDOW_OPAQUE;
 
80
        else
 
81
            mask |= PAINT_WINDOW_TRANSLUCENT;
 
82
        mask |= PAINT_WINDOW_LANCZOS;
 
83
        foreach (const Data & thumb, thumbnails.values(w)) {
 
84
            EffectWindow* thumbw = effects->findWindow(thumb.window);
 
85
            if (thumbw == NULL)
 
86
                continue;
 
87
            WindowPaintData thumbData(thumbw);
 
88
            thumbData.opacity *= data.opacity;
 
89
            QRect r;
 
90
 
 
91
#ifdef KWIN_HAVE_OPENGL_COMPOSITING
 
92
            if (effects->compositingType() == KWin::OpenGLCompositing) {
 
93
                if (data.shader) {
 
94
                    thumbData.shader = data.shader;
 
95
                }
 
96
            } // if ( effects->compositingType() == KWin::OpenGLCompositing )
 
97
#endif
 
98
            setPositionTransformations(thumbData, r,
 
99
                                       thumbw, thumb.rect.translated(w->pos()), Qt::KeepAspectRatio);
 
100
            effects->drawWindow(thumbw, mask, r, thumbData);
 
101
        }
 
102
    }
 
103
} // End of function
 
104
 
 
105
void TaskbarThumbnailEffect::slotWindowDamaged(EffectWindow* w, const QRect& damage)
 
106
{
 
107
    Q_UNUSED(damage);
 
108
    // Update the thumbnail if the window was damaged
 
109
    foreach (EffectWindow * window, thumbnails.uniqueKeys())
 
110
    foreach (const Data & thumb, thumbnails.values(window))
 
111
    if (w == effects->findWindow(thumb.window))
 
112
        effects->addRepaint(thumb.rect.translated(window->pos()));
 
113
}
 
114
 
 
115
void TaskbarThumbnailEffect::slotWindowAdded(EffectWindow* w)
 
116
{
 
117
    slotPropertyNotify(w, atom);   // read initial value
 
118
}
 
119
 
 
120
void TaskbarThumbnailEffect::slotWindowDeleted(EffectWindow* w)
 
121
{
 
122
    thumbnails.remove(w);
 
123
}
 
124
 
 
125
void TaskbarThumbnailEffect::slotPropertyNotify(EffectWindow* w, long a)
 
126
{
 
127
    if (!w || a != atom)
 
128
        return;
 
129
    foreach (const Data & thumb, thumbnails.values(w)) {
 
130
        effects->addRepaint(thumb.rect);
 
131
    }
 
132
    thumbnails.remove(w);
 
133
    QByteArray data = w->readProperty(atom, atom, 32);
 
134
    if (data.length() < 1)
 
135
        return;
 
136
    long* d = reinterpret_cast< long* >(data.data());
 
137
    int len = data.length() / sizeof(d[ 0 ]);
 
138
    int pos = 0;
 
139
    int cnt = d[ 0 ];
 
140
    ++pos;
 
141
    for (int i = 0;
 
142
            i < cnt;
 
143
            ++i) {
 
144
        int size = d[ pos ];
 
145
        if (len - pos < size)
 
146
            return; // format error
 
147
        ++pos;
 
148
        Data data;
 
149
        data.window = d[ pos ];
 
150
        data.rect = QRect(d[ pos + 1 ], d[ pos + 2 ], d[ pos + 3 ], d[ pos + 4 ]);
 
151
        thumbnails.insert(w, data);
 
152
        effects->addRepaint(data.rect);
 
153
        pos += size;
 
154
    }
 
155
}
 
156
 
 
157
} // namespace