3 * Copyright (c) 2003 Lubos Lunak <l.lunak@kde.org>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
24 #include <kapplication.h>
30 #include <QMouseEvent>
31 #include <QResizeEvent>
33 #include <kiconloader.h>
36 #include <X11/extensions/shape.h>
38 #include <kdecorationfactory.h>
39 #include <kdecoration_plugins_p.h>
42 // FRAME the preview doesn't update to reflect the changes done in the kcm
44 KDecorationPreview::KDecorationPreview( KDecorationPlugins
* plugin
, QWidget
* parent
, const char* name
)
45 : QWidget( parent
, name
),
48 options
= new KDecorationPreviewOptions
;
50 bridge
= new KDecorationPreviewBridge( this, true, "Deco Benchmark" );
54 setFixedSize( 600, 500 );
59 KDecorationPreview::~KDecorationPreview()
66 void KDecorationPreview::performRepaintTest(int n
)
68 kDebug(1212) << "start " << n
<< " repaints...";
69 bridge
->setCaption("Deco Benchmark");
70 deco
->captionChange();
72 for (int i
= 0; i
< n
; ++i
) {
73 deco
->widget()->repaint();
74 kapp
->processEvents();
78 void KDecorationPreview::performCaptionTest(int n
)
80 kDebug(1212) << "start " << n
<< " caption changes...";
81 QString caption
= "Deco Benchmark %1";
83 for (int i
= 0; i
< n
; ++i
) {
84 bridge
->setCaption(caption
.arg(i
) );
85 deco
->captionChange();
86 deco
->widget()->repaint();
87 kapp
->processEvents();
91 void KDecorationPreview::performResizeTest(int n
)
93 kDebug(1212) << "start " << n
<< " resizes...";
94 bridge
->setCaption("Deco Benchmark");
95 deco
->captionChange();
96 for (int i
= 0; i
< n
; ++i
) {
97 positionPreviews(i
% 200);
98 kapp
->processEvents();
102 void KDecorationPreview::performRecreationTest(int n
)
104 kDebug(1212) << "start " << n
<< " resizes...";
105 bridge
->setCaption("Deco Benchmark");
106 deco
->captionChange();
108 for (int i
= 0; i
< n
; ++i
) {
109 recreateDecoration();
110 kapp
->processEvents();
114 bool KDecorationPreview::recreateDecoration()
117 deco
= m_plugin
->createDecoration(bridge
);
124 deco
->widget()->show();
129 void KDecorationPreview::positionPreviews(int shrink
)
134 QSize size
= QSize(width()-2*10-shrink
, height()-2*10-shrink
)/*.expandedTo(deco->minimumSize()*/;
136 QRect
geometry(QPoint(10, 10), size
);
137 deco
->widget()->setGeometry(geometry
);
140 void KDecorationPreview::setPreviewMask( const QRegion
& reg
, int mode
)
142 QWidget
*widget
= deco
->widget();
144 // FRAME duped from client.cpp
145 if( mode
== Unsorted
)
147 XShapeCombineRegion( QX11Info::display(), widget
->winId(), ShapeBounding
, 0, 0,
148 reg
.handle(), ShapeSet
);
152 QVector
< QRect
> rects
= reg
.rects();
153 XRectangle
* xrects
= new XRectangle
[ rects
.count() ];
154 for( unsigned int i
= 0;
158 xrects
[ i
].x
= rects
[ i
].x();
159 xrects
[ i
].y
= rects
[ i
].y();
160 xrects
[ i
].width
= rects
[ i
].width();
161 xrects
[ i
].height
= rects
[ i
].height();
163 XShapeCombineRectangles( QX11Info::display(), widget
->winId(), ShapeBounding
, 0, 0,
164 xrects
, rects
.count(), ShapeSet
, mode
);
169 QRect
KDecorationPreview::windowGeometry( bool active
) const
171 QWidget
*widget
= deco
->widget();
172 return widget
->geometry();
175 QRegion
KDecorationPreview::unobscuredRegion( bool active
, const QRegion
& r
) const
180 KDecorationPreviewBridge::KDecorationPreviewBridge( KDecorationPreview
* p
, bool a
, const QString
&c
)
181 : preview( p
), active( a
), m_caption( c
)
185 void KDecorationPreviewBridge::setCaption(const QString
&c
)
190 QWidget
* KDecorationPreviewBridge::initialParentWidget() const
195 Qt::WFlags
KDecorationPreviewBridge::initialWFlags() const
200 bool KDecorationPreviewBridge::isActive() const
205 bool KDecorationPreviewBridge::isCloseable() const
210 bool KDecorationPreviewBridge::isMaximizable() const
215 KDecoration::MaximizeMode
KDecorationPreviewBridge::maximizeMode() const
217 return KDecoration::MaximizeRestore
;
220 bool KDecorationPreviewBridge::isMinimizable() const
225 bool KDecorationPreviewBridge::providesContextHelp() const
230 int KDecorationPreviewBridge::desktop() const
235 bool KDecorationPreviewBridge::isModal() const
240 bool KDecorationPreviewBridge::isShadeable() const
245 bool KDecorationPreviewBridge::isShade() const
250 bool KDecorationPreviewBridge::isSetShade() const
255 bool KDecorationPreviewBridge::keepAbove() const
260 bool KDecorationPreviewBridge::keepBelow() const
265 bool KDecorationPreviewBridge::isMovable() const
270 bool KDecorationPreviewBridge::isResizable() const
275 NET::WindowType
KDecorationPreviewBridge::windowType( unsigned long ) const
280 QIcon
KDecorationPreviewBridge::icon() const
282 return QIcon( KGlobal::iconLoader()->loadIcon( "xorg", KIconLoader::NoGroup
, 32 ));
285 QString
KDecorationPreviewBridge::caption() const
290 void KDecorationPreviewBridge::processMousePressEvent( QMouseEvent
* )
294 void KDecorationPreviewBridge::showWindowMenu( const QRect
& )
298 void KDecorationPreviewBridge::showWindowMenu( QPoint
)
302 void KDecorationPreviewBridge::performWindowOperation( WindowOperation
)
306 void KDecorationPreviewBridge::setMask( const QRegion
& reg
, int mode
)
308 preview
->setPreviewMask( reg
, mode
);
311 bool KDecorationPreviewBridge::isPreview() const
316 QRect
KDecorationPreviewBridge::geometry() const
318 return preview
->windowGeometry( active
);
321 QRect
KDecorationPreviewBridge::iconGeometry() const
326 QRegion
KDecorationPreviewBridge::unobscuredRegion( const QRegion
& r
) const
328 return preview
->unobscuredRegion( active
, r
);
331 WId
KDecorationPreviewBridge::windowId() const
333 return 0; // no decorated window
336 void KDecorationPreviewBridge::closeWindow()
340 void KDecorationPreviewBridge::maximize( MaximizeMode
)
344 void KDecorationPreviewBridge::minimize()
348 void KDecorationPreviewBridge::showContextHelp()
352 void KDecorationPreviewBridge::setDesktop( int )
356 void KDecorationPreviewBridge::titlebarDblClickOperation()
360 void KDecorationPreviewBridge::titlebarMouseWheelOperation( int )
364 void KDecorationPreviewBridge::setShade( bool )
368 void KDecorationPreviewBridge::setKeepAbove( bool )
372 void KDecorationPreviewBridge::setKeepBelow( bool )
376 int KDecorationPreviewBridge::currentDesktop() const
381 void KDecorationPreviewBridge::grabXServer( bool )
385 KDecorationPreviewOptions::KDecorationPreviewOptions()
387 defaultKWinSettings();
391 KDecorationPreviewOptions::~KDecorationPreviewOptions()
395 unsigned long KDecorationPreviewOptions::updateSettings()
397 KConfig
cfg( "kwinrc", true );
398 unsigned long changed
= 0;
399 changed
|= KDecorationOptions::updateKWinSettings( &cfg
);
404 bool KDecorationPreviewPlugins::provides( Requirement
)
409 // #include "preview.moc"