1
/********************************************************************
2
KWin - the KDE window manager
3
This file is part of the KDE project.
5
Copyright (C) 2007 Lubos Lunak <l.lunak@kde.org>
6
Copyright (C) 2007 Christian Nitschkowski <christian.nitschkowski@kdemail.net>
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.
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.
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
*********************************************************************/
22
#include "thumbnailaside.h"
24
#include <kactioncollection.h>
26
#include <kconfiggroup.h>
32
KWIN_EFFECT(thumbnailaside, ThumbnailAsideEffect)
34
ThumbnailAsideEffect::ThumbnailAsideEffect()
36
KActionCollection* actionCollection = new KActionCollection(this);
37
KAction* a = (KAction*)actionCollection->addAction("ToggleCurrentThumbnail");
38
a->setText(i18n("Toggle Thumbnail for Current Window"));
39
a->setGlobalShortcut(KShortcut(Qt::CTRL + Qt::META + Qt::Key_T));
40
connect(a, SIGNAL(triggered(bool)), this, SLOT(toggleCurrentThumbnail()));
41
connect(effects, SIGNAL(windowClosed(EffectWindow*)), this, SLOT(slotWindowClosed(EffectWindow*)));
42
connect(effects, SIGNAL(windowGeometryShapeChanged(EffectWindow*,QRect)), this, SLOT(slotWindowGeometryShapeChanged(EffectWindow*,QRect)));
43
connect(effects, SIGNAL(windowDamaged(EffectWindow*,QRect)), this, SLOT(slotWindowDamaged(EffectWindow*,QRect)));
44
reconfigure(ReconfigureAll);
47
void ThumbnailAsideEffect::reconfigure(ReconfigureFlags)
49
KConfigGroup conf = EffectsHandler::effectConfig("ThumbnailAside");
50
maxwidth = conf.readEntry("MaxWidth", 200);
51
spacing = conf.readEntry("Spacing", 10);
52
opacity = conf.readEntry("Opacity", 50) / 100.0;
53
screen = conf.readEntry("Screen", -1); // Xinerama screen TODO add gui option
57
void ThumbnailAsideEffect::paintScreen(int mask, QRegion region, ScreenPaintData& data)
59
effects->paintScreen(mask, region, data);
60
foreach (const Data & d, windows) {
61
if (region.contains(d.rect)) {
62
WindowPaintData data(d.window);
63
data.opacity = opacity;
65
setPositionTransformations(data, region, d.window, d.rect, Qt::KeepAspectRatio);
66
effects->drawWindow(d.window, PAINT_WINDOW_OPAQUE | PAINT_WINDOW_TRANSLUCENT | PAINT_WINDOW_TRANSFORMED | PAINT_WINDOW_LANCZOS,
72
void ThumbnailAsideEffect::slotWindowDamaged(EffectWindow* w, const QRect&)
74
foreach (const Data & d, windows) {
76
effects->addRepaint(d.rect);
80
void ThumbnailAsideEffect::slotWindowGeometryShapeChanged(EffectWindow* w, const QRect& old)
82
foreach (const Data & d, windows) {
84
if (w->size() == old.size())
85
effects->addRepaint(d.rect);
93
void ThumbnailAsideEffect::slotWindowClosed(EffectWindow* w)
98
void ThumbnailAsideEffect::toggleCurrentThumbnail()
100
EffectWindow* active = effects->activeWindow();
103
if (windows.contains(active))
104
removeThumbnail(active);
106
addThumbnail(active);
109
void ThumbnailAsideEffect::addThumbnail(EffectWindow* w)
111
repaintAll(); // repaint old areas
114
d.index = windows.count();
119
void ThumbnailAsideEffect::removeThumbnail(EffectWindow* w)
121
if (!windows.contains(w))
123
repaintAll(); // repaint old areas
124
int index = windows[ w ].index;
126
for (QHash< EffectWindow*, Data >::Iterator it = windows.begin();
136
void ThumbnailAsideEffect::arrange()
138
if (windows.size() == 0)
141
QVector< int > pos(windows.size());
143
foreach (const Data & d, windows) {
144
height += d.window->height();
145
mwidth = qMax(mwidth, d.window->width());
146
pos[ d.index ] = d.window->height();
148
QRect area = effects->clientArea(MaximizeArea, screen, effects->currentDesktop());
149
double scale = area.height() / double(height);
150
scale = qMin(scale, maxwidth / double(mwidth)); // don't be wider than maxwidth pixels
155
pos[ i ] = int(pos[ i ] * scale);
156
pos[ i ] += spacing + add; // compute offset of each item
159
for (QHash< EffectWindow*, Data >::Iterator it = windows.begin();
163
int width = int(d.window->width() * scale);
164
d.rect = QRect(area.right() - width, area.bottom() - pos[ d.index ], width, int(d.window->height() * scale));
169
void ThumbnailAsideEffect::repaintAll()
171
foreach (const Data & d, windows)
172
effects->addRepaint(d.rect);
177
#include "thumbnailaside.moc"