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.
22 #include <kapplication.h>
29 #include <QMouseEvent>
30 #include <QResizeEvent>
35 #include <X11/extensions/shape.h>
37 #include <kdecorationfactory.h>
38 #include <kdecoration_plugins_p.h>
41 // FRAME the preview doesn't update to reflect the changes done in the kcm
43 KDecorationPreview::KDecorationPreview( QWidget
* parent
)
46 options
= new KDecorationPreviewOptions
;
48 bridge
[Active
] = new KDecorationPreviewBridge( this, true );
49 bridge
[Inactive
] = new KDecorationPreviewBridge( this, false );
51 deco
[Active
] = deco
[Inactive
] = NULL
;
53 no_preview
= new QLabel( i18n( "No preview available.\n"
54 "Most probably there\n"
55 "was a problem loading the plugin." ), this );
57 no_preview
->setAlignment( Qt::AlignCenter
);
59 setMinimumSize( 100, 100 );
60 no_preview
->resize( size());
63 KDecorationPreview::~KDecorationPreview()
65 for ( int i
= 0; i
< NumWindows
; i
++ )
73 bool KDecorationPreview::recreateDecoration( KDecorationPlugins
* plugins
)
75 for ( int i
= 0; i
< NumWindows
; i
++ )
77 delete deco
[i
]; // deletes also window
78 deco
[i
] = plugins
->createDecoration( bridge
[i
] );
82 if( deco
[Active
] == NULL
|| deco
[Inactive
] == NULL
)
88 deco
[Inactive
]->widget()->show();
89 deco
[Active
]->widget()->show();
94 void KDecorationPreview::enablePreview()
99 void KDecorationPreview::disablePreview()
102 delete deco
[Inactive
];
103 deco
[Active
] = deco
[Inactive
] = NULL
;
107 void KDecorationPreview::resizeEvent( QResizeEvent
* e
)
109 QWidget::resizeEvent( e
);
113 void KDecorationPreview::positionPreviews()
115 int titleBarHeight
, leftBorder
, rightBorder
, xoffset
,
116 dummy1
, dummy2
, dummy3
;
120 no_preview
->resize( this->size() );
122 if ( !deco
[Active
] || !deco
[Inactive
] )
125 // don't have more than one reference to the same dummy variable in one borders() call.
126 deco
[Active
]->borders( dummy1
, dummy2
, titleBarHeight
, dummy3
);
127 deco
[Inactive
]->borders( leftBorder
, rightBorder
, dummy1
, dummy2
);
129 titleBarHeight
= qMin( int( titleBarHeight
* .9 ), 30 );
130 xoffset
= qMin( qMax( 10, QApplication::isRightToLeft()
131 ? leftBorder
: rightBorder
), 30 );
133 // Resize the active window
134 size
= QSize( width() - xoffset
, height() - titleBarHeight
)
135 .expandedTo( deco
[Active
]->minimumSize() );
136 geometry
= QRect( QPoint( 0, titleBarHeight
), size
);
137 deco
[Active
]->widget()->setGeometry( QStyle::visualRect( this->layoutDirection(), this->rect(), geometry
) );
139 // Resize the inactive window
140 size
= QSize( width() - xoffset
, height() - titleBarHeight
)
141 .expandedTo( deco
[Inactive
]->minimumSize() );
142 geometry
= QRect( QPoint( xoffset
, 0 ), size
);
143 deco
[Inactive
]->widget()->setGeometry( QStyle::visualRect( this->layoutDirection(), this->rect(), geometry
) );
146 void KDecorationPreview::setPreviewMask( const QRegion
& reg
, int mode
, bool active
)
148 QWidget
*widget
= active
? deco
[Active
]->widget() : deco
[Inactive
]->widget();
150 // FRAME duped from client.cpp
151 if( mode
== Unsorted
)
153 XShapeCombineRegion( QX11Info::display(), widget
->winId(), ShapeBounding
, 0, 0,
154 reg
.handle(), ShapeSet
);
158 QVector
< QRect
> rects
= reg
.rects();
159 XRectangle
* xrects
= new XRectangle
[ rects
.count() ];
164 xrects
[ i
].x
= rects
[ i
].x();
165 xrects
[ i
].y
= rects
[ i
].y();
166 xrects
[ i
].width
= rects
[ i
].width();
167 xrects
[ i
].height
= rects
[ i
].height();
169 XShapeCombineRectangles( QX11Info::display(), widget
->winId(), ShapeBounding
, 0, 0,
170 xrects
, rects
.count(), ShapeSet
, mode
);
174 mask
= reg
; // keep shape of the active window for unobscuredRegion()
177 QRect
KDecorationPreview::windowGeometry( bool active
) const
179 QWidget
*widget
= active
? deco
[Active
]->widget() : deco
[Inactive
]->widget();
180 return widget
->geometry();
183 void KDecorationPreview::setTempBorderSize(KDecorationPlugins
* plugin
, KDecorationDefines::BorderSize size
)
185 options
->setCustomBorderSize(size
);
186 if (plugin
->factory()->reset(KDecorationDefines::SettingBorder
) )
188 // can't handle the change, recreate decorations then
189 recreateDecoration(plugin
);
193 // handles the update, only update position...
198 void KDecorationPreview::setTempButtons(KDecorationPlugins
* plugin
, bool customEnabled
, const QString
&left
, const QString
&right
)
200 options
->setCustomTitleButtonsEnabled(customEnabled
);
201 options
->setCustomTitleButtons(left
, right
);
202 if (plugin
->factory()->reset(KDecorationDefines::SettingButtons
) )
204 // can't handle the change, recreate decorations then
205 recreateDecoration(plugin
);
209 // handles the update, only update position...
214 QRegion
KDecorationPreview::unobscuredRegion( bool active
, const QRegion
& r
) const
216 if( active
) // this one is not obscured
220 // copied from KWin core's code
224 r2
= QRegion( windowGeometry( true ));
225 r2
.translate( windowGeometry( true ).x() - windowGeometry( false ).x(),
226 windowGeometry( true ).y() - windowGeometry( false ).y());
232 KDecorationPreviewBridge::KDecorationPreviewBridge( KDecorationPreview
* p
, bool a
)
233 : preview( p
), active( a
)
237 QWidget
* KDecorationPreviewBridge::initialParentWidget() const
242 Qt::WFlags
KDecorationPreviewBridge::initialWFlags() const
247 bool KDecorationPreviewBridge::isActive() const
252 bool KDecorationPreviewBridge::isCloseable() const
257 bool KDecorationPreviewBridge::isMaximizable() const
262 KDecoration::MaximizeMode
KDecorationPreviewBridge::maximizeMode() const
264 return KDecoration::MaximizeRestore
;
267 bool KDecorationPreviewBridge::isMinimizable() const
272 bool KDecorationPreviewBridge::providesContextHelp() const
277 int KDecorationPreviewBridge::desktop() const
282 bool KDecorationPreviewBridge::isModal() const
287 bool KDecorationPreviewBridge::isShadeable() const
292 bool KDecorationPreviewBridge::isShade() const
297 bool KDecorationPreviewBridge::isSetShade() const
302 bool KDecorationPreviewBridge::keepAbove() const
307 bool KDecorationPreviewBridge::keepBelow() const
312 bool KDecorationPreviewBridge::isMovable() const
317 bool KDecorationPreviewBridge::isResizable() const
322 NET::WindowType
KDecorationPreviewBridge::windowType( unsigned long ) const
327 QIcon
KDecorationPreviewBridge::icon() const
329 return KIcon( "xorg" );
332 QString
KDecorationPreviewBridge::caption() const
334 return active
? i18n( "Active Window" ) : i18n( "Inactive Window" );
337 void KDecorationPreviewBridge::processMousePressEvent( QMouseEvent
* )
341 void KDecorationPreviewBridge::showWindowMenu( const QRect
&)
345 void KDecorationPreviewBridge::showWindowMenu( const QPoint
& )
349 void KDecorationPreviewBridge::performWindowOperation( WindowOperation
)
353 void KDecorationPreviewBridge::setMask( const QRegion
& reg
, int mode
)
355 preview
->setPreviewMask( reg
, mode
, active
);
358 bool KDecorationPreviewBridge::isPreview() const
363 QRect
KDecorationPreviewBridge::geometry() const
365 return preview
->windowGeometry( active
);
368 QRect
KDecorationPreviewBridge::iconGeometry() const
373 QRegion
KDecorationPreviewBridge::unobscuredRegion( const QRegion
& r
) const
375 return preview
->unobscuredRegion( active
, r
);
378 WId
KDecorationPreviewBridge::windowId() const
380 return 0; // no decorated window
383 void KDecorationPreviewBridge::closeWindow()
387 void KDecorationPreviewBridge::maximize( MaximizeMode
)
391 void KDecorationPreviewBridge::minimize()
395 void KDecorationPreviewBridge::showContextHelp()
399 void KDecorationPreviewBridge::setDesktop( int )
403 void KDecorationPreviewBridge::titlebarDblClickOperation()
407 void KDecorationPreviewBridge::titlebarMouseWheelOperation( int )
411 void KDecorationPreviewBridge::setShade( bool )
415 void KDecorationPreviewBridge::setKeepAbove( bool )
419 void KDecorationPreviewBridge::setKeepBelow( bool )
423 int KDecorationPreviewBridge::currentDesktop() const
428 void KDecorationPreviewBridge::grabXServer( bool )
432 void KDecorationPreviewBridge::repaintShadow()
436 bool KDecorationPreviewBridge::compositingActive() const
441 bool KDecorationPreviewBridge::shadowsActive() const
446 double KDecorationPreviewBridge::opacity() const
451 KDecorationPreviewOptions::KDecorationPreviewOptions()
453 customBorderSize
= BordersCount
; // invalid
454 customButtonsChanged
= false; // invalid
455 customButtons
= true;
456 customTitleButtonsLeft
.clear(); // invalid
457 customTitleButtonsRight
.clear(); // invalid
461 KDecorationPreviewOptions::~KDecorationPreviewOptions()
465 unsigned long KDecorationPreviewOptions::updateSettings()
467 KConfig
cfg( "kwinrc" );
468 unsigned long changed
= 0;
469 changed
|= KDecorationOptions::updateSettings( &cfg
);
471 // set custom border size/buttons
472 if (customBorderSize
!= BordersCount
)
473 setBorderSize( customBorderSize
);
474 if (customButtonsChanged
)
475 setCustomButtonPositions( customButtons
);
477 if (!customTitleButtonsLeft
.isNull() )
478 setTitleButtonsLeft( customTitleButtonsLeft
);
479 if (!customTitleButtonsRight
.isNull() )
480 setTitleButtonsRight( customTitleButtonsRight
);
482 setTitleButtonsLeft( KDecorationOptions::defaultTitleButtonsLeft());
483 setTitleButtonsRight( KDecorationOptions::defaultTitleButtonsRight());
489 void KDecorationPreviewOptions::setCustomBorderSize(BorderSize size
)
491 customBorderSize
= size
;
496 void KDecorationPreviewOptions::setCustomTitleButtonsEnabled(bool enabled
)
498 customButtonsChanged
= true;
499 customButtons
= enabled
;
504 void KDecorationPreviewOptions::setCustomTitleButtons(const QString
&left
, const QString
&right
)
506 customTitleButtonsLeft
= left
;
507 customTitleButtonsRight
= right
;
512 bool KDecorationPreviewPlugins::provides( Requirement
)
517 #include "preview.moc"