2007-04-29 17:35:43 +00:00
|
|
|
/*
|
|
|
|
*
|
|
|
|
* Copyright (c) 2003 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, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "preview.h"
|
|
|
|
|
|
|
|
#include <kdebug.h>
|
|
|
|
|
|
|
|
#include <kapplication.h>
|
|
|
|
#include <klocale.h>
|
|
|
|
#include <kconfig.h>
|
|
|
|
#include <kglobal.h>
|
|
|
|
#include <QLabel>
|
|
|
|
#include <QStyle>
|
|
|
|
#include <QMouseEvent>
|
|
|
|
#include <QResizeEvent>
|
|
|
|
#include <QVector>
|
|
|
|
#include <kiconloader.h>
|
|
|
|
|
|
|
|
#include <X11/Xlib.h>
|
|
|
|
#include <X11/extensions/shape.h>
|
|
|
|
|
|
|
|
#include <kdecorationfactory.h>
|
|
|
|
#include <kdecoration_plugins_p.h>
|
|
|
|
#include <QX11Info>
|
|
|
|
|
|
|
|
// FRAME the preview doesn't update to reflect the changes done in the kcm
|
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
KDecorationPreview::KDecorationPreview(KDecorationPlugins* plugin, QWidget* parent, const char* name)
|
|
|
|
: QWidget(parent, name),
|
|
|
|
m_plugin(plugin)
|
2007-04-29 17:35:43 +00:00
|
|
|
{
|
|
|
|
options = new KDecorationPreviewOptions;
|
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
bridge = new KDecorationPreviewBridge(this, true, "Deco Benchmark");
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
deco = 0;
|
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
setFixedSize(600, 500);
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
positionPreviews();
|
|
|
|
}
|
|
|
|
|
|
|
|
KDecorationPreview::~KDecorationPreview()
|
|
|
|
{
|
|
|
|
delete deco;
|
|
|
|
delete bridge;
|
|
|
|
delete options;
|
|
|
|
}
|
|
|
|
|
|
|
|
void KDecorationPreview::performRepaintTest(int n)
|
|
|
|
{
|
2008-11-17 15:04:52 +00:00
|
|
|
kDebug(1212) << "start " << n << " repaints...";
|
2007-04-29 17:35:43 +00:00
|
|
|
bridge->setCaption("Deco Benchmark");
|
|
|
|
deco->captionChange();
|
|
|
|
positionPreviews(0);
|
|
|
|
for (int i = 0; i < n; ++i) {
|
|
|
|
deco->widget()->repaint();
|
|
|
|
kapp->processEvents();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void KDecorationPreview::performCaptionTest(int n)
|
|
|
|
{
|
2008-11-17 15:04:52 +00:00
|
|
|
kDebug(1212) << "start " << n << " caption changes...";
|
2007-04-29 17:35:43 +00:00
|
|
|
QString caption = "Deco Benchmark %1";
|
|
|
|
positionPreviews(0);
|
|
|
|
for (int i = 0; i < n; ++i) {
|
2011-01-30 14:34:42 +00:00
|
|
|
bridge->setCaption(caption.arg(i));
|
2007-04-29 17:35:43 +00:00
|
|
|
deco->captionChange();
|
|
|
|
deco->widget()->repaint();
|
|
|
|
kapp->processEvents();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void KDecorationPreview::performResizeTest(int n)
|
|
|
|
{
|
2008-11-17 15:04:52 +00:00
|
|
|
kDebug(1212) << "start " << n << " resizes...";
|
2007-04-29 17:35:43 +00:00
|
|
|
bridge->setCaption("Deco Benchmark");
|
|
|
|
deco->captionChange();
|
|
|
|
for (int i = 0; i < n; ++i) {
|
|
|
|
positionPreviews(i % 200);
|
|
|
|
kapp->processEvents();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void KDecorationPreview::performRecreationTest(int n)
|
|
|
|
{
|
2008-11-17 15:04:52 +00:00
|
|
|
kDebug(1212) << "start " << n << " resizes...";
|
2007-04-29 17:35:43 +00:00
|
|
|
bridge->setCaption("Deco Benchmark");
|
|
|
|
deco->captionChange();
|
|
|
|
positionPreviews(0);
|
|
|
|
for (int i = 0; i < n; ++i) {
|
|
|
|
recreateDecoration();
|
|
|
|
kapp->processEvents();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool KDecorationPreview::recreateDecoration()
|
|
|
|
{
|
|
|
|
delete deco;
|
|
|
|
deco = m_plugin->createDecoration(bridge);
|
|
|
|
deco->init();
|
|
|
|
|
|
|
|
if (!deco)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
positionPreviews();
|
|
|
|
deco->widget()->show();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void KDecorationPreview::positionPreviews(int shrink)
|
|
|
|
{
|
2011-01-30 14:34:42 +00:00
|
|
|
if (!deco)
|
2007-04-29 17:35:43 +00:00
|
|
|
return;
|
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
QSize size = QSize(width() - 2 * 10 - shrink, height() - 2 * 10 - shrink)/*.expandedTo(deco->minimumSize()*/;
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
QRect geometry(QPoint(10, 10), size);
|
|
|
|
deco->widget()->setGeometry(geometry);
|
|
|
|
}
|
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
void KDecorationPreview::setPreviewMask(const QRegion& reg, int mode)
|
2007-04-29 17:35:43 +00:00
|
|
|
{
|
|
|
|
QWidget *widget = deco->widget();
|
|
|
|
|
|
|
|
// FRAME duped from client.cpp
|
2011-01-30 14:34:42 +00:00
|
|
|
if (mode == Unsorted) {
|
|
|
|
XShapeCombineRegion(QX11Info::display(), widget->winId(), ShapeBounding, 0, 0,
|
|
|
|
reg.handle(), ShapeSet);
|
|
|
|
} else {
|
2007-04-29 17:35:43 +00:00
|
|
|
QVector< QRect > rects = reg.rects();
|
2011-01-30 14:34:42 +00:00
|
|
|
XRectangle* xrects = new XRectangle[ rects.count()];
|
|
|
|
for (unsigned int i = 0;
|
|
|
|
i < rects.count();
|
|
|
|
++i) {
|
2007-04-29 17:35:43 +00:00
|
|
|
xrects[ i ].x = rects[ i ].x();
|
|
|
|
xrects[ i ].y = rects[ i ].y();
|
|
|
|
xrects[ i ].width = rects[ i ].width();
|
|
|
|
xrects[ i ].height = rects[ i ].height();
|
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
XShapeCombineRectangles(QX11Info::display(), widget->winId(), ShapeBounding, 0, 0,
|
|
|
|
xrects, rects.count(), ShapeSet, mode);
|
|
|
|
delete[] xrects;
|
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
}
|
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
QRect KDecorationPreview::windowGeometry(bool active) const
|
2007-04-29 17:35:43 +00:00
|
|
|
{
|
|
|
|
QWidget *widget = deco->widget();
|
|
|
|
return widget->geometry();
|
|
|
|
}
|
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
QRegion KDecorationPreview::unobscuredRegion(bool active, const QRegion& r) const
|
2007-04-29 17:35:43 +00:00
|
|
|
{
|
2011-01-30 14:34:42 +00:00
|
|
|
return r;
|
2007-04-29 17:35:43 +00:00
|
|
|
}
|
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
KDecorationPreviewBridge::KDecorationPreviewBridge(KDecorationPreview* p, bool a, const QString &c)
|
|
|
|
: preview(p), active(a), m_caption(c)
|
2007-04-29 17:35:43 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void KDecorationPreviewBridge::setCaption(const QString &c)
|
|
|
|
{
|
|
|
|
m_caption = c;
|
|
|
|
}
|
|
|
|
|
|
|
|
QWidget* KDecorationPreviewBridge::initialParentWidget() const
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2007-04-29 17:35:43 +00:00
|
|
|
return preview;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
Qt::WFlags KDecorationPreviewBridge::initialWFlags() const
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2007-04-29 17:35:43 +00:00
|
|
|
return 0;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
bool KDecorationPreviewBridge::isActive() const
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2007-04-29 17:35:43 +00:00
|
|
|
return active;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
bool KDecorationPreviewBridge::isCloseable() const
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2007-04-29 17:35:43 +00:00
|
|
|
return true;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
bool KDecorationPreviewBridge::isMaximizable() const
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2007-04-29 17:35:43 +00:00
|
|
|
return true;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
KDecoration::MaximizeMode KDecorationPreviewBridge::maximizeMode() const
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2007-04-29 17:35:43 +00:00
|
|
|
return KDecoration::MaximizeRestore;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
bool KDecorationPreviewBridge::isMinimizable() const
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2007-04-29 17:35:43 +00:00
|
|
|
return true;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
bool KDecorationPreviewBridge::providesContextHelp() const
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2007-04-29 17:35:43 +00:00
|
|
|
return true;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
int KDecorationPreviewBridge::desktop() const
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2007-04-29 17:35:43 +00:00
|
|
|
return 1;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
bool KDecorationPreviewBridge::isModal() const
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2007-04-29 17:35:43 +00:00
|
|
|
return false;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
bool KDecorationPreviewBridge::isShadeable() const
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2007-04-29 17:35:43 +00:00
|
|
|
return true;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
bool KDecorationPreviewBridge::isShade() const
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2007-04-29 17:35:43 +00:00
|
|
|
return false;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
bool KDecorationPreviewBridge::isSetShade() const
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2007-04-29 17:35:43 +00:00
|
|
|
return false;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
bool KDecorationPreviewBridge::keepAbove() const
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2007-04-29 17:35:43 +00:00
|
|
|
return false;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
bool KDecorationPreviewBridge::keepBelow() const
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2007-04-29 17:35:43 +00:00
|
|
|
return false;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
bool KDecorationPreviewBridge::isMovable() const
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2007-04-29 17:35:43 +00:00
|
|
|
return true;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
bool KDecorationPreviewBridge::isResizable() const
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2007-04-29 17:35:43 +00:00
|
|
|
return true;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
NET::WindowType KDecorationPreviewBridge::windowType(unsigned long) const
|
|
|
|
{
|
2007-04-29 17:35:43 +00:00
|
|
|
return NET::Normal;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
QIcon KDecorationPreviewBridge::icon() const
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
return QIcon(KGlobal::iconLoader()->loadIcon("xorg", KIconLoader::NoGroup, 32));
|
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
QString KDecorationPreviewBridge::caption() const
|
|
|
|
{
|
|
|
|
return m_caption;
|
|
|
|
}
|
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
void KDecorationPreviewBridge::processMousePressEvent(QMouseEvent*)
|
|
|
|
{
|
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
void KDecorationPreviewBridge::showWindowMenu(const QRect &)
|
|
|
|
{
|
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
void KDecorationPreviewBridge::showWindowMenu(QPoint)
|
|
|
|
{
|
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
void KDecorationPreviewBridge::performWindowOperation(WindowOperation)
|
|
|
|
{
|
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
void KDecorationPreviewBridge::setMask(const QRegion& reg, int mode)
|
|
|
|
{
|
|
|
|
preview->setPreviewMask(reg, mode);
|
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
bool KDecorationPreviewBridge::isPreview() const
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2007-04-29 17:35:43 +00:00
|
|
|
return false;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
QRect KDecorationPreviewBridge::geometry() const
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
return preview->windowGeometry(active);
|
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
QRect KDecorationPreviewBridge::iconGeometry() const
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2007-04-29 17:35:43 +00:00
|
|
|
return QRect();
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
QRegion KDecorationPreviewBridge::unobscuredRegion(const QRegion& r) const
|
|
|
|
{
|
|
|
|
return preview->unobscuredRegion(active, r);
|
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
WId KDecorationPreviewBridge::windowId() const
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2007-04-29 17:35:43 +00:00
|
|
|
return 0; // no decorated window
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
void KDecorationPreviewBridge::closeWindow()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
void KDecorationPreviewBridge::maximize(MaximizeMode)
|
|
|
|
{
|
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
void KDecorationPreviewBridge::minimize()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
void KDecorationPreviewBridge::showContextHelp()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
void KDecorationPreviewBridge::setDesktop(int)
|
|
|
|
{
|
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
void KDecorationPreviewBridge::titlebarDblClickOperation()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
void KDecorationPreviewBridge::titlebarMouseWheelOperation(int)
|
2007-04-29 17:35:43 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
void KDecorationPreviewBridge::setShade(bool)
|
|
|
|
{
|
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
void KDecorationPreviewBridge::setKeepAbove(bool)
|
|
|
|
{
|
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
void KDecorationPreviewBridge::setKeepBelow(bool)
|
|
|
|
{
|
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
int KDecorationPreviewBridge::currentDesktop() const
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2007-04-29 17:35:43 +00:00
|
|
|
return 1;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
void KDecorationPreviewBridge::grabXServer(bool)
|
|
|
|
{
|
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
KDecorationPreviewOptions::KDecorationPreviewOptions()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2008-01-29 16:44:41 +00:00
|
|
|
defaultKWinSettings();
|
2007-04-29 17:35:43 +00:00
|
|
|
updateSettings();
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
KDecorationPreviewOptions::~KDecorationPreviewOptions()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
unsigned long KDecorationPreviewOptions::updateSettings()
|
|
|
|
{
|
2011-01-30 14:34:42 +00:00
|
|
|
KConfig cfg("kwinrc", true);
|
2007-04-29 17:35:43 +00:00
|
|
|
unsigned long changed = 0;
|
2011-01-30 14:34:42 +00:00
|
|
|
changed |= KDecorationOptions::updateKWinSettings(&cfg);
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
return changed;
|
|
|
|
}
|
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
bool KDecorationPreviewPlugins::provides(Requirement)
|
|
|
|
{
|
2007-04-29 17:35:43 +00:00
|
|
|
return false;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
// #include "preview.moc"
|