2008-01-03 14:00:13 +00:00
|
|
|
/********************************************************************
|
|
|
|
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"
|
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
#include <kwinglutils.h>
|
2009-04-27 11:10:08 +00:00
|
|
|
|
2008-01-03 14:00:13 +00:00
|
|
|
// 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
|
|
|
|
{
|
|
|
|
|
|
|
|
TaskbarThumbnailEffect::TaskbarThumbnailEffect()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2012-12-13 23:09:47 +00:00
|
|
|
atom = effects->announceSupportProperty("_KDE_WINDOW_PREVIEW", this);
|
2012-01-29 11:29:24 +00:00
|
|
|
connect(effects, SIGNAL(windowAdded(KWin::EffectWindow*)), this, SLOT(slotWindowAdded(KWin::EffectWindow*)));
|
|
|
|
connect(effects, SIGNAL(windowDeleted(KWin::EffectWindow*)), this, SLOT(slotWindowDeleted(KWin::EffectWindow*)));
|
|
|
|
connect(effects, SIGNAL(windowDamaged(KWin::EffectWindow*,QRect)), this, SLOT(slotWindowDamaged(KWin::EffectWindow*,QRect)));
|
|
|
|
connect(effects, SIGNAL(propertyNotify(KWin::EffectWindow*,long)), this, SLOT(slotPropertyNotify(KWin::EffectWindow*,long)));
|
2013-01-30 12:07:59 +00:00
|
|
|
connect(effects, SIGNAL(screenLockingChanged(bool)), SLOT(screenLockingChanged()));
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2008-01-03 14:00:13 +00:00
|
|
|
|
|
|
|
TaskbarThumbnailEffect::~TaskbarThumbnailEffect()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
}
|
2008-01-03 14:00:13 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
void TaskbarThumbnailEffect::prePaintScreen(ScreenPrePaintData& data, int time)
|
|
|
|
{
|
2008-01-03 14:00:13 +00:00
|
|
|
effects->prePaintScreen(data, time);
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2008-01-03 14:00:13 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
void TaskbarThumbnailEffect::prePaintWindow(EffectWindow* w, WindowPrePaintData& data, int time)
|
|
|
|
{
|
2008-01-03 14:00:13 +00:00
|
|
|
// 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);
|
|
|
|
}
|
2008-01-03 14:00:13 +00:00
|
|
|
|
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
|
2009-02-03 09:39:48 +00:00
|
|
|
int mask = PAINT_WINDOW_TRANSFORMED;
|
2012-07-12 15:20:17 +00:00
|
|
|
if (data.opacity() == 1.0)
|
2009-02-03 09:39:48 +00:00
|
|
|
mask |= PAINT_WINDOW_OPAQUE;
|
|
|
|
else
|
|
|
|
mask |= PAINT_WINDOW_TRANSLUCENT;
|
2010-06-02 20:04:54 +00:00
|
|
|
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)
|
2008-01-24 15:14:13 +00:00
|
|
|
continue;
|
2011-01-30 14:34:42 +00:00
|
|
|
WindowPaintData thumbData(thumbw);
|
2012-07-12 15:20:17 +00:00
|
|
|
thumbData.multiplyOpacity(data.opacity());
|
2011-11-30 20:15:35 +00:00
|
|
|
QRect r, thumbRect(thumb.rect);
|
2012-05-28 12:45:46 +00:00
|
|
|
thumbRect.translate(w->pos() + QPoint(data.xTranslation(), data.yTranslation()));
|
2012-05-28 10:00:31 +00:00
|
|
|
thumbRect.setSize(QSize(thumbRect.width() * data.xScale(), thumbRect.height() * data.yScale())); // QSize has no vector multiplicator... :-(
|
2009-04-27 11:10:08 +00:00
|
|
|
|
2012-09-20 09:33:32 +00:00
|
|
|
if (effects->isOpenGLCompositing()) {
|
2011-01-30 14:34:42 +00:00
|
|
|
if (data.shader) {
|
|
|
|
thumbData.shader = data.shader;
|
|
|
|
}
|
|
|
|
} // if ( effects->compositingType() == KWin::OpenGLCompositing )
|
2011-11-30 20:15:35 +00:00
|
|
|
setPositionTransformations(thumbData, r, thumbw, thumbRect, Qt::KeepAspectRatio);
|
2011-01-30 14:34:42 +00:00
|
|
|
effects->drawWindow(thumbw, mask, r, thumbData);
|
2008-01-03 14:00:13 +00:00
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
|
|
|
} // End of function
|
2008-01-03 14:00:13 +00:00
|
|
|
|
2011-03-12 14:04:22 +00:00
|
|
|
void TaskbarThumbnailEffect::slotWindowDamaged(EffectWindow* w, const QRect& damage)
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
Q_UNUSED(damage);
|
2009-03-06 06:16:00 +00:00
|
|
|
// 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))
|
2011-08-27 16:22:05 +00:00
|
|
|
window->addRepaint(thumb.rect);
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2009-03-06 06:16:00 +00:00
|
|
|
|
2011-02-25 21:06:02 +00:00
|
|
|
void TaskbarThumbnailEffect::slotWindowAdded(EffectWindow* w)
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2011-03-12 18:18:19 +00:00
|
|
|
slotPropertyNotify(w, atom); // read initial value
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2008-01-03 14:00:13 +00:00
|
|
|
|
2011-02-27 09:47:42 +00:00
|
|
|
void TaskbarThumbnailEffect::slotWindowDeleted(EffectWindow* w)
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2011-09-10 05:56:58 +00:00
|
|
|
foreach (EffectWindow *window, thumbnails.uniqueKeys()) {
|
|
|
|
foreach (const Data &thumb, thumbnails.values(window)) {
|
|
|
|
if (w == effects->findWindow(thumb.window)) {
|
|
|
|
window->addRepaint(thumb.rect);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
thumbnails.remove(w);
|
|
|
|
}
|
2008-01-03 14:00:13 +00:00
|
|
|
|
2011-03-12 18:18:19 +00:00
|
|
|
void TaskbarThumbnailEffect::slotPropertyNotify(EffectWindow* w, long a)
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
if (!w || a != atom)
|
2008-01-03 14:00:13 +00:00
|
|
|
return;
|
2012-05-24 09:15:24 +00:00
|
|
|
w->addRepaintFull();
|
2011-01-30 14:34:42 +00:00
|
|
|
thumbnails.remove(w);
|
|
|
|
QByteArray data = w->readProperty(atom, atom, 32);
|
|
|
|
if (data.length() < 1)
|
2008-01-03 14:00:13 +00:00
|
|
|
return;
|
2013-09-25 06:54:22 +00:00
|
|
|
auto* d = reinterpret_cast< uint32_t* >(data.data());
|
2011-01-30 14:34:42 +00:00
|
|
|
int len = data.length() / sizeof(d[ 0 ]);
|
2008-01-03 14:00:13 +00:00
|
|
|
int pos = 0;
|
|
|
|
int cnt = d[ 0 ];
|
|
|
|
++pos;
|
2011-01-30 14:34:42 +00:00
|
|
|
for (int i = 0;
|
|
|
|
i < cnt;
|
|
|
|
++i) {
|
2008-01-03 14:00:13 +00:00
|
|
|
int size = d[ pos ];
|
2011-01-30 14:34:42 +00:00
|
|
|
if (len - pos < size)
|
2008-01-03 14:00:13 +00:00
|
|
|
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);
|
2011-08-27 16:22:05 +00:00
|
|
|
w->addRepaint(data.rect);
|
2008-01-03 14:00:13 +00:00
|
|
|
pos += size;
|
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2008-01-03 14:00:13 +00:00
|
|
|
|
2013-01-30 12:07:59 +00:00
|
|
|
void TaskbarThumbnailEffect::screenLockingChanged()
|
|
|
|
{
|
|
|
|
foreach (EffectWindow *window, thumbnails.uniqueKeys()) {
|
|
|
|
window->addRepaintFull();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-08-27 09:21:31 +00:00
|
|
|
bool TaskbarThumbnailEffect::isActive() const
|
|
|
|
{
|
2013-01-30 12:07:59 +00:00
|
|
|
return !thumbnails.isEmpty() && !effects->isScreenLocked();
|
2011-08-27 09:21:31 +00:00
|
|
|
}
|
|
|
|
|
2008-01-03 14:00:13 +00:00
|
|
|
} // namespace
|