add more spacing
[personal-kdebase.git] / workspace / kwin / effects / taskbarthumbnail.cpp
blob8bcd3adfb1fba1008062eeb77afa26df3327641e
1 /********************************************************************
2 KWin - the KDE window manager
3 This file is part of the KDE project.
5 Copyright (C) 2007 Rivo Laks <rivolaks@hot.ee>
6 Copyright (C) 2007 Lubos Lunak <l.lunak@kde.org>
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 "taskbarthumbnail.h"
24 #include <kdebug.h>
27 // This effect shows a preview inside a window that has a special property set
28 // on it that says which window and where to render. It is used by the taskbar
29 // to show window previews in tooltips.
31 namespace KWin
34 KWIN_EFFECT( taskbarthumbnail, TaskbarThumbnailEffect )
36 TaskbarThumbnailEffect::TaskbarThumbnailEffect()
38 atom = XInternAtom( display(), "_KDE_WINDOW_PREVIEW", False );
39 effects->registerPropertyType( atom, true );
40 // TODO hackish way to announce support, make better after 4.0
41 unsigned char dummy = 0;
42 XChangeProperty( display(), rootWindow(), atom, atom, 8, PropModeReplace, &dummy, 1 );
45 TaskbarThumbnailEffect::~TaskbarThumbnailEffect()
47 XDeleteProperty( display(), rootWindow(), atom );
48 effects->registerPropertyType( atom, false );
51 void TaskbarThumbnailEffect::prePaintScreen( ScreenPrePaintData& data, int time )
53 // if( thumbnails.count() > 0 )
54 // // TODO this should not be needed (it causes whole screen repaint)
55 // data.mask |= PAINT_SCREEN_WITH_TRANSFORMED_WINDOWS;
56 effects->prePaintScreen(data, time);
59 void TaskbarThumbnailEffect::prePaintWindow( EffectWindow* w, WindowPrePaintData& data, int time )
61 // TODO what if of the windows is translucent and one not? change data.mask?
62 effects->prePaintWindow( w, data, time );
65 void TaskbarThumbnailEffect::paintWindow( EffectWindow* w, int mask, QRegion region, WindowPaintData& data )
67 effects->paintWindow( w, mask, region, data ); // paint window first
68 if( thumbnails.contains( w ))
69 { // paint thumbnails on it
70 foreach( const Data &thumb, thumbnails.values( w ))
72 EffectWindow* thumbw = effects->findWindow( thumb.window );
73 if( thumbw == NULL )
74 continue;
75 WindowPaintData data( thumbw );
76 QRect r;
77 setPositionTransformations( data, r,
78 thumbw, thumb.rect.translated( w->pos()), Qt::KeepAspectRatio );
79 effects->drawWindow( thumbw,
80 PAINT_WINDOW_OPAQUE | PAINT_WINDOW_TRANSFORMED,
81 r, data );
86 void TaskbarThumbnailEffect::windowAdded( EffectWindow* w )
88 propertyNotify( w, atom ); // read initial value
91 void TaskbarThumbnailEffect::windowRemoved( EffectWindow* w )
93 thumbnails.remove( w );
96 void TaskbarThumbnailEffect::propertyNotify( EffectWindow* w, long a )
98 if( a != atom )
99 return;
100 thumbnails.remove( w );
101 QByteArray data = w->readProperty( atom, atom, 32 );
102 if( data.length() < 1 )
103 return;
104 long* d = reinterpret_cast< long* >( data.data());
105 int len = data.length() / sizeof( d[ 0 ] );
106 int pos = 0;
107 int cnt = d[ 0 ];
108 ++pos;
109 for( int i = 0;
110 i < cnt;
111 ++i )
113 int size = d[ pos ];
114 if( len - pos < size )
115 return; // format error
116 ++pos;
117 Data data;
118 data.window = d[ pos ];
119 data.rect = QRect( d[ pos + 1 ], d[ pos + 2 ], d[ pos + 3 ], d[ pos + 4 ] );
120 thumbnails.insert( w, data );
121 pos += size;
125 } // namespace