kwin/effects/taskbarthumbnail/taskbarthumbnail.cpp

160 lines
5.5 KiB
C++
Raw Normal View History

/********************************************************************
KWin - the KDE window manager
This file is part of the KDE project.
Copyright (C) 2007 Rivo Laks <rivolaks@hot.ee>
Copyright (C) 2007 Lubos Lunak <l.lunak@kde.org>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*********************************************************************/
#include "taskbarthumbnail.h"
#include <kdebug.h>
#ifdef KWIN_HAVE_OPENGL_COMPOSITING
2011-01-30 14:34:42 +00:00
#include <kwinglutils.h>
#endif
// This effect shows a preview inside a window that has a special property set
// on it that says which window and where to render. It is used by the taskbar
// to show window previews in tooltips.
namespace KWin
{
2011-01-30 14:34:42 +00:00
KWIN_EFFECT(taskbarthumbnail, TaskbarThumbnailEffect)
TaskbarThumbnailEffect::TaskbarThumbnailEffect()
2011-01-30 14:34:42 +00:00
{
atom = XInternAtom(display(), "_KDE_WINDOW_PREVIEW", False);
effects->registerPropertyType(atom, true);
// TODO hackish way to announce support, make better after 4.0
unsigned char dummy = 0;
2011-01-30 14:34:42 +00:00
XChangeProperty(display(), rootWindow(), atom, atom, 8, PropModeReplace, &dummy, 1);
}
TaskbarThumbnailEffect::~TaskbarThumbnailEffect()
2011-01-30 14:34:42 +00:00
{
XDeleteProperty(display(), rootWindow(), atom);
effects->registerPropertyType(atom, false);
}
2011-01-30 14:34:42 +00:00
void TaskbarThumbnailEffect::prePaintScreen(ScreenPrePaintData& data, int time)
{
if (thumbnails.count() > 0) {
2011-01-30 14:34:42 +00:00
data.mask |= PAINT_SCREEN_WITH_TRANSFORMED_WINDOWS_WITHOUT_FULL_REPAINTS;
}
effects->prePaintScreen(data, time);
2011-01-30 14:34:42 +00:00
}
2011-01-30 14:34:42 +00:00
void TaskbarThumbnailEffect::prePaintWindow(EffectWindow* w, WindowPrePaintData& data, int time)
{
// TODO what if of the windows is translucent and one not? change data.mask?
2011-01-30 14:34:42 +00:00
effects->prePaintWindow(w, data, time);
}
2011-01-30 14:34:42 +00:00
void TaskbarThumbnailEffect::paintWindow(EffectWindow* w, int mask, QRegion region, WindowPaintData& data)
{
effects->paintWindow(w, mask, region, data); // paint window first
if (thumbnails.contains(w)) {
// paint thumbnails on it
int mask = PAINT_WINDOW_TRANSFORMED;
2011-01-30 14:34:42 +00:00
if (data.opacity == 1.0)
mask |= PAINT_WINDOW_OPAQUE;
else
mask |= PAINT_WINDOW_TRANSLUCENT;
mask |= PAINT_WINDOW_LANCZOS;
2011-01-30 14:34:42 +00:00
foreach (const Data & thumb, thumbnails.values(w)) {
EffectWindow* thumbw = effects->findWindow(thumb.window);
if (thumbw == NULL)
continue;
2011-01-30 14:34:42 +00:00
WindowPaintData thumbData(thumbw);
thumbData.opacity *= data.opacity;
QRect r;
#ifdef KWIN_HAVE_OPENGL_COMPOSITING
2011-01-30 14:34:42 +00:00
if (effects->compositingType() == KWin::OpenGLCompositing) {
if (data.shader) {
// there is a shader - update texture width and height
int texw = thumbw->width();
int texh = thumbw->height();
2011-01-30 14:34:42 +00:00
if (!GLTexture::NPOTTextureSupported()) {
kWarning(1212) << "NPOT textures not supported, wasting some memory" ;
texw = nearestPowerOfTwo(texw);
texh = nearestPowerOfTwo(texh);
}
2011-01-30 14:34:42 +00:00
thumbData.shader = data.shader;
thumbData.shader->setTextureWidth((float)texw);
thumbData.shader->setTextureHeight((float)texh);
}
} // if ( effects->compositingType() == KWin::OpenGLCompositing )
#endif
2011-01-30 14:34:42 +00:00
setPositionTransformations(thumbData, r,
thumbw, thumb.rect.translated(w->pos()), Qt::KeepAspectRatio);
effects->drawWindow(thumbw, mask, r, thumbData);
}
2011-01-30 14:34:42 +00:00
}
} // End of function
2011-01-30 14:34:42 +00:00
void TaskbarThumbnailEffect::windowDamaged(EffectWindow* w, const QRect& damage)
{
Q_UNUSED(damage);
// Update the thumbnail if the window was damaged
2011-01-30 14:34:42 +00:00
foreach (EffectWindow * window, thumbnails.uniqueKeys())
foreach (const Data & thumb, thumbnails.values(window))
if (w == effects->findWindow(thumb.window))
effects->addRepaint(thumb.rect.translated(window->pos()));
}
2011-01-30 14:34:42 +00:00
void TaskbarThumbnailEffect::windowAdded(EffectWindow* w)
{
propertyNotify(w, atom); // read initial value
}
2011-01-30 14:34:42 +00:00
void TaskbarThumbnailEffect::windowDeleted(EffectWindow* w)
{
thumbnails.remove(w);
}
2011-01-30 14:34:42 +00:00
void TaskbarThumbnailEffect::propertyNotify(EffectWindow* w, long a)
{
if (!w || a != atom)
return;
2011-01-30 14:34:42 +00:00
thumbnails.remove(w);
QByteArray data = w->readProperty(atom, atom, 32);
if (data.length() < 1)
return;
2011-01-30 14:34:42 +00:00
long* d = reinterpret_cast< long* >(data.data());
int len = data.length() / sizeof(d[ 0 ]);
int pos = 0;
int cnt = d[ 0 ];
++pos;
2011-01-30 14:34:42 +00:00
for (int i = 0;
i < cnt;
++i) {
int size = d[ pos ];
2011-01-30 14:34:42 +00:00
if (len - pos < size)
return; // format error
++pos;
Data data;
data.window = d[ pos ];
2011-01-30 14:34:42 +00:00
data.rect = QRect(d[ pos + 1 ], d[ pos + 2 ], d[ pos + 3 ], d[ pos + 4 ]);
thumbnails.insert(w, data);
pos += size;
}
2011-01-30 14:34:42 +00:00
}
} // namespace