kwin/lib/kdecoration.cpp

616 lines
14 KiB
C++
Raw Normal View History

/*****************************************************************
This file is part of the KDE project.
Copyright (C) 2003 Lubos Lunak <l.lunak@kde.org>
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
******************************************************************/
#include "kdecoration.h"
#include "kdecoration_p.h"
#include <kdebug.h>
#include <QApplication>
#include <kglobal.h>
#include <assert.h>
#if defined Q_WS_X11 && ! defined K_WS_QTONLY
#include <X11/Xlib.h>
#include <fixx11h.h>
#include <QX11Info>
#endif
#include "kdecorationfactory.h"
#include "kdecorationbridge.h"
/*
Extending KDecoration:
======================
If KDecoration will ever need to be extended in a way that'd break binary compatibility
(i.e. adding new virtual methods most probably), new class KDecoration2 should be
inherited from KDecoration and those methods added there. Code that would depend
on the new functionality could then dynamic_cast<> to KDecoration2 to check whether
it is available and use it.
KCommonDecoration would have to be extended the same way, adding KCommonDecoration2
inheriting KCommonDecoration and adding the new API matching KDecoration2.
*/
KDecorationOptions* KDecoration::options_;
2011-01-30 14:34:42 +00:00
KDecoration::KDecoration(KDecorationBridge* bridge, KDecorationFactory* factory)
: bridge_(bridge),
w_(NULL),
factory_(factory)
{
factory->addDecoration(this);
}
KDecoration::~KDecoration()
2011-01-30 14:34:42 +00:00
{
factory()->removeDecoration(this);
delete w_;
2011-01-30 14:34:42 +00:00
}
const KDecorationOptions* KDecoration::options()
2011-01-30 14:34:42 +00:00
{
return options_;
2011-01-30 14:34:42 +00:00
}
2011-01-30 14:34:42 +00:00
void KDecoration::createMainWidget(Qt::WFlags flags)
{
// FRAME check flags?
2011-01-30 14:34:42 +00:00
QWidget *w = new QWidget(initialParentWidget(), initialWFlags() | flags);
w->setObjectName(QLatin1String("decoration widget"));
w->setAttribute(Qt::WA_PaintOnScreen);
if (options()->showTooltips())
w->setAttribute(Qt::WA_AlwaysShowToolTips);
setMainWidget(w);
2011-01-30 14:34:42 +00:00
}
2011-01-30 14:34:42 +00:00
void KDecoration::setMainWidget(QWidget* w)
{
assert(w_ == NULL);
w_ = w;
2011-01-30 14:34:42 +00:00
w->setMouseTracking(true);
widget()->resize(geometry().size());
}
QWidget* KDecoration::initialParentWidget() const
2011-01-30 14:34:42 +00:00
{
return bridge_->initialParentWidget();
2011-01-30 14:34:42 +00:00
}
Qt::WFlags KDecoration::initialWFlags() const
2011-01-30 14:34:42 +00:00
{
return bridge_->initialWFlags();
2011-01-30 14:34:42 +00:00
}
bool KDecoration::isActive() const
2011-01-30 14:34:42 +00:00
{
return bridge_->isActive();
2011-01-30 14:34:42 +00:00
}
bool KDecoration::isCloseable() const
2011-01-30 14:34:42 +00:00
{
return bridge_->isCloseable();
2011-01-30 14:34:42 +00:00
}
bool KDecoration::isMaximizable() const
2011-01-30 14:34:42 +00:00
{
return bridge_->isMaximizable();
2011-01-30 14:34:42 +00:00
}
KDecoration::MaximizeMode KDecoration::maximizeMode() const
2011-01-30 14:34:42 +00:00
{
return bridge_->maximizeMode();
2011-01-30 14:34:42 +00:00
}
bool KDecoration::isMinimizable() const
2011-01-30 14:34:42 +00:00
{
return bridge_->isMinimizable();
2011-01-30 14:34:42 +00:00
}
bool KDecoration::providesContextHelp() const
2011-01-30 14:34:42 +00:00
{
return bridge_->providesContextHelp();
2011-01-30 14:34:42 +00:00
}
int KDecoration::desktop() const
2011-01-30 14:34:42 +00:00
{
return bridge_->desktop();
2011-01-30 14:34:42 +00:00
}
bool KDecoration::isModal() const
2011-01-30 14:34:42 +00:00
{
return bridge_->isModal();
2011-01-30 14:34:42 +00:00
}
bool KDecoration::isShadeable() const
2011-01-30 14:34:42 +00:00
{
return bridge_->isShadeable();
2011-01-30 14:34:42 +00:00
}
bool KDecoration::isShade() const
2011-01-30 14:34:42 +00:00
{
return bridge_->isShade();
2011-01-30 14:34:42 +00:00
}
bool KDecoration::isSetShade() const
2011-01-30 14:34:42 +00:00
{
return bridge_->isSetShade();
2011-01-30 14:34:42 +00:00
}
bool KDecoration::keepAbove() const
2011-01-30 14:34:42 +00:00
{
return bridge_->keepAbove();
2011-01-30 14:34:42 +00:00
}
bool KDecoration::keepBelow() const
2011-01-30 14:34:42 +00:00
{
return bridge_->keepBelow();
2011-01-30 14:34:42 +00:00
}
bool KDecoration::isMovable() const
2011-01-30 14:34:42 +00:00
{
return bridge_->isMovable();
2011-01-30 14:34:42 +00:00
}
bool KDecoration::isResizable() const
2011-01-30 14:34:42 +00:00
{
return bridge_->isResizable();
2011-01-30 14:34:42 +00:00
}
2011-01-30 14:34:42 +00:00
NET::WindowType KDecoration::windowType(unsigned long supported_types) const
{
// this one is also duplicated in KDecorationFactory
return bridge_->windowType(supported_types);
}
QIcon KDecoration::icon() const
2011-01-30 14:34:42 +00:00
{
return bridge_->icon();
2011-01-30 14:34:42 +00:00
}
QString KDecoration::caption() const
2011-01-30 14:34:42 +00:00
{
return bridge_->caption();
2011-01-30 14:34:42 +00:00
}
2011-01-30 14:34:42 +00:00
void KDecoration::processMousePressEvent(QMouseEvent* e)
{
return bridge_->processMousePressEvent(e);
}
2011-01-30 14:34:42 +00:00
void KDecoration::showWindowMenu(const QRect &pos)
{
bridge_->showWindowMenu(pos);
}
2011-01-30 14:34:42 +00:00
void KDecoration::showWindowMenu(QPoint pos)
{
bridge_->showWindowMenu(pos);
}
2011-01-30 14:34:42 +00:00
void KDecoration::performWindowOperation(WindowOperation op)
{
bridge_->performWindowOperation(op);
}
2011-01-30 14:34:42 +00:00
void KDecoration::setMask(const QRegion& reg, int mode)
{
bridge_->setMask(reg, mode);
}
void KDecoration::clearMask()
2011-01-30 14:34:42 +00:00
{
bridge_->setMask(QRegion(), 0);
}
bool KDecoration::isPreview() const
2011-01-30 14:34:42 +00:00
{
return bridge_->isPreview();
2011-01-30 14:34:42 +00:00
}
QRect KDecoration::geometry() const
2011-01-30 14:34:42 +00:00
{
return bridge_->geometry();
2011-01-30 14:34:42 +00:00
}
QRect KDecoration::iconGeometry() const
2011-01-30 14:34:42 +00:00
{
return bridge_->iconGeometry();
2011-01-30 14:34:42 +00:00
}
2011-01-30 14:34:42 +00:00
QRegion KDecoration::unobscuredRegion(const QRegion& r) const
{
return bridge_->unobscuredRegion(r);
}
WId KDecoration::windowId() const
2011-01-30 14:34:42 +00:00
{
return bridge_->windowId();
2011-01-30 14:34:42 +00:00
}
void KDecoration::closeWindow()
2011-01-30 14:34:42 +00:00
{
bridge_->closeWindow();
2011-01-30 14:34:42 +00:00
}
2011-01-30 14:34:42 +00:00
void KDecoration::maximize(Qt::MouseButtons button)
{
performWindowOperation(options()->operationMaxButtonClick(button));
}
2011-01-30 14:34:42 +00:00
void KDecoration::maximize(MaximizeMode mode)
{
bridge_->maximize(mode);
}
void KDecoration::minimize()
2011-01-30 14:34:42 +00:00
{
bridge_->minimize();
2011-01-30 14:34:42 +00:00
}
void KDecoration::showContextHelp()
2011-01-30 14:34:42 +00:00
{
bridge_->showContextHelp();
2011-01-30 14:34:42 +00:00
}
2011-01-30 14:34:42 +00:00
void KDecoration::setDesktop(int desktop)
{
bridge_->setDesktop(desktop);
}
void KDecoration::toggleOnAllDesktops()
2011-01-30 14:34:42 +00:00
{
if (isOnAllDesktops())
setDesktop(bridge_->currentDesktop());
else
2011-01-30 14:34:42 +00:00
setDesktop(NET::OnAllDesktops);
}
void KDecoration::titlebarDblClickOperation()
2011-01-30 14:34:42 +00:00
{
bridge_->titlebarDblClickOperation();
2011-01-30 14:34:42 +00:00
}
void KDecoration::titlebarMouseWheelOperation(int delta)
{
bridge_->titlebarMouseWheelOperation(delta);
}
void KDecoration::setShade(bool set)
{
bridge_->setShade(set);
}
void KDecoration::setKeepAbove(bool set)
{
bridge_->setKeepAbove(set);
}
void KDecoration::setKeepBelow(bool set)
{
bridge_->setKeepBelow(set);
}
void KDecoration::emitKeepAboveChanged(bool above)
{
keepAboveChanged(above);
}
void KDecoration::emitKeepBelowChanged(bool below)
{
keepBelowChanged(below);
}
bool KDecoration::drawbound(const QRect&, bool)
{
return false;
2011-01-30 14:34:42 +00:00
}
2011-01-30 14:34:42 +00:00
bool KDecoration::windowDocked(Position)
{
return false;
2011-01-30 14:34:42 +00:00
}
2011-01-30 14:34:42 +00:00
void KDecoration::reset(unsigned long)
{
}
void KDecoration::grabXServer()
2011-01-30 14:34:42 +00:00
{
bridge_->grabXServer(true);
}
void KDecoration::ungrabXServer()
2011-01-30 14:34:42 +00:00
{
bridge_->grabXServer(false);
}
2011-01-30 14:34:42 +00:00
KDecoration::Position KDecoration::mousePosition(const QPoint& p) const
{
const int range = 16;
int bleft, bright, btop, bbottom;
2011-01-30 14:34:42 +00:00
borders(bleft, bright, btop, bbottom);
btop = qMin(btop, 4); // otherwise whole titlebar would have resize cursor
Position m = PositionCenter;
2011-01-30 14:34:42 +00:00
if ((p.x() > bleft && p.x() < widget()->width() - bright)
&& (p.y() > btop && p.y() < widget()->height() - bbottom))
return PositionCenter;
2011-01-30 14:34:42 +00:00
if (p.y() <= qMax(range, btop) && p.x() <= qMax(range, bleft))
m = PositionTopLeft;
2011-01-30 14:34:42 +00:00
else if (p.y() >= widget()->height() - qMax(range, bbottom)
&& p.x() >= widget()->width() - qMax(range, bright))
m = PositionBottomRight;
2011-01-30 14:34:42 +00:00
else if (p.y() >= widget()->height() - qMax(range, bbottom) && p.x() <= qMax(range, bleft))
m = PositionBottomLeft;
2011-01-30 14:34:42 +00:00
else if (p.y() <= qMax(range, btop) && p.x() >= widget()->width() - qMax(range, bright))
m = PositionTopRight;
2011-01-30 14:34:42 +00:00
else if (p.y() <= btop)
m = PositionTop;
2011-01-30 14:34:42 +00:00
else if (p.y() >= widget()->height() - bbottom)
m = PositionBottom;
2011-01-30 14:34:42 +00:00
else if (p.x() <= bleft)
m = PositionLeft;
2011-01-30 14:34:42 +00:00
else if (p.x() >= widget()->width() - bright)
m = PositionRight;
else
m = PositionCenter;
return m;
2011-01-30 14:34:42 +00:00
}
QRect KDecoration::transparentRect() const
2011-01-30 14:34:42 +00:00
{
if (KDecorationBridgeUnstable *bridge2 = dynamic_cast<KDecorationBridgeUnstable*>(bridge_))
return bridge2->transparentRect();
else
return QRect();
2011-01-30 14:34:42 +00:00
}
2011-01-30 14:34:42 +00:00
KDecorationUnstable::KDecorationUnstable(KDecorationBridge* bridge, KDecorationFactory* factory)
: KDecoration(bridge, factory)
{
Q_ASSERT(dynamic_cast< KDecorationBridgeUnstable* >(bridge));
}
KDecorationUnstable::~KDecorationUnstable()
2011-01-30 14:34:42 +00:00
{
}
bool KDecorationUnstable::compositingActive() const
2011-01-30 14:34:42 +00:00
{
return static_cast< KDecorationBridgeUnstable* >(bridge_)->compositingActive();
}
void KDecorationUnstable::padding(int &left, int &right, int &top, int &bottom) const
2011-01-30 14:34:42 +00:00
{
left = right = top = bottom = 0;
2011-01-30 14:34:42 +00:00
}
// Window tabbing
bool KDecorationUnstable::isClientGroupActive()
2011-01-30 14:34:42 +00:00
{
return static_cast< KDecorationBridgeUnstable* >(bridge_)->isClientGroupActive();
}
QList< ClientGroupItem > KDecorationUnstable::clientGroupItems() const
2011-01-30 14:34:42 +00:00
{
return static_cast< KDecorationBridgeUnstable* >(bridge_)->clientGroupItems();
}
2011-01-30 14:34:42 +00:00
long KDecorationUnstable::itemId(int index)
{
return static_cast< KDecorationBridgeUnstable* >(bridge_)->itemId(index);
}
int KDecorationUnstable::visibleClientGroupItem()
2011-01-30 14:34:42 +00:00
{
return static_cast< KDecorationBridgeUnstable* >(bridge_)->visibleClientGroupItem();
}
void KDecorationUnstable::setVisibleClientGroupItem(int index)
{
static_cast< KDecorationBridgeUnstable* >(bridge_)->setVisibleClientGroupItem(index);
}
void KDecorationUnstable::moveItemInClientGroup(int index, int before)
{
static_cast< KDecorationBridgeUnstable* >(bridge_)->moveItemInClientGroup(index, before);
}
void KDecorationUnstable::moveItemToClientGroup(long itemId, int before)
{
static_cast< KDecorationBridgeUnstable* >(bridge_)->moveItemToClientGroup(itemId, before);
}
void KDecorationUnstable::removeFromClientGroup(int index, const QRect& newGeom)
{
static_cast< KDecorationBridgeUnstable* >(bridge_)->removeFromClientGroup(index, newGeom);
}
void KDecorationUnstable::closeClientGroupItem(int index)
{
static_cast< KDecorationBridgeUnstable* >(bridge_)->closeClientGroupItem(index);
}
void KDecorationUnstable::closeAllInClientGroup()
2011-01-30 14:34:42 +00:00
{
static_cast< KDecorationBridgeUnstable* >(bridge_)->closeAllInClientGroup();
}
2011-01-30 14:34:42 +00:00
void KDecorationUnstable::displayClientMenu(int index, const QPoint& pos)
{
static_cast< KDecorationBridgeUnstable* >(bridge_)->displayClientMenu(index, pos);
}
2011-01-30 14:34:42 +00:00
KDecoration::WindowOperation KDecorationUnstable::buttonToWindowOperation(Qt::MouseButtons button)
{
return static_cast< KDecorationBridgeUnstable* >(bridge_)->buttonToWindowOperation(button);
}
QString KDecorationDefines::clientGroupItemDragMimeType()
2011-01-30 14:34:42 +00:00
{
return "text/ClientGroupItem";
2011-01-30 14:34:42 +00:00
}
KDecorationOptions::KDecorationOptions()
2011-01-30 14:34:42 +00:00
: d(new KDecorationOptionsPrivate)
{
assert(KDecoration::options_ == NULL);
KDecoration::options_ = this;
2011-01-30 14:34:42 +00:00
}
KDecorationOptions::~KDecorationOptions()
2011-01-30 14:34:42 +00:00
{
assert(KDecoration::options_ == this);
KDecoration::options_ = NULL;
delete d;
2011-01-30 14:34:42 +00:00
}
QColor KDecorationOptions::color(ColorType type, bool active) const
2011-01-30 14:34:42 +00:00
{
return(d->colors[type + (active ? 0 : NUM_COLORS)]);
2011-01-30 14:34:42 +00:00
}
QFont KDecorationOptions::font(bool active, bool small) const
2011-01-30 14:34:42 +00:00
{
if (small)
return(active ? d->activeFontSmall : d->inactiveFontSmall);
else
return(active ? d->activeFont : d->inactiveFont);
2011-01-30 14:34:42 +00:00
}
QPalette KDecorationOptions::palette(ColorType type, bool active) const
2011-01-30 14:34:42 +00:00
{
int idx = type + (active ? 0 : NUM_COLORS);
2011-01-30 14:34:42 +00:00
if (d->pal[idx])
return(*d->pal[idx]);
// TODO: Why construct the palette this way? Is it worth porting to Qt4?
//d->pal[idx] = new QPalette(Qt::black, d->colors[idx], d->colors[idx].light(150),
// d->colors[idx].dark(), d->colors[idx].dark(120),
// Qt::black, QApplication::palette().active().
// base());
d->pal[idx] = new QPalette(d->colors[idx]);
return(*d->pal[idx]);
2011-01-30 14:34:42 +00:00
}
2011-01-30 14:34:42 +00:00
unsigned long KDecorationOptions::updateSettings(KConfig* config)
{
return d->updateSettings(config);
}
bool KDecorationOptions::customButtonPositions() const
2011-01-30 14:34:42 +00:00
{
return d->custom_button_positions;
2011-01-30 14:34:42 +00:00
}
QString KDecorationOptions::titleButtonsLeft() const
2011-01-30 14:34:42 +00:00
{
return d->title_buttons_left;
2011-01-30 14:34:42 +00:00
}
QString KDecorationOptions::defaultTitleButtonsLeft()
2011-01-30 14:34:42 +00:00
{
return "MS";
2011-01-30 14:34:42 +00:00
}
QString KDecorationOptions::titleButtonsRight() const
2011-01-30 14:34:42 +00:00
{
return d->title_buttons_right;
2011-01-30 14:34:42 +00:00
}
QString KDecorationOptions::defaultTitleButtonsRight()
2011-01-30 14:34:42 +00:00
{
return "HIA__X";
2011-01-30 14:34:42 +00:00
}
bool KDecorationOptions::showTooltips() const
2011-01-30 14:34:42 +00:00
{
return d->show_tooltips;
2011-01-30 14:34:42 +00:00
}
KDecorationOptions::BorderSize KDecorationOptions::preferredBorderSize(KDecorationFactory* factory) const
{
assert(factory != NULL);
if (d->cached_border_size == BordersCount) // invalid
d->cached_border_size = d->findPreferredBorderSize(d->border_size,
factory->borderSizes());
return d->cached_border_size;
2011-01-30 14:34:42 +00:00
}
bool KDecorationOptions::moveResizeMaximizedWindows() const
2011-01-30 14:34:42 +00:00
{
return d->move_resize_maximized_windows;
2011-01-30 14:34:42 +00:00
}
2011-01-30 14:34:42 +00:00
KDecorationDefines::WindowOperation KDecorationOptions::operationMaxButtonClick(Qt::MouseButtons button) const
{
return button == Qt::RightButton ? d->opMaxButtonRightClick :
button == Qt::MidButton ? d->opMaxButtonMiddleClick :
d->opMaxButtonLeftClick;
}
2011-01-30 14:34:42 +00:00
void KDecorationOptions::setOpMaxButtonLeftClick(WindowOperation op)
{
d->opMaxButtonLeftClick = op;
2011-01-30 14:34:42 +00:00
}
2011-01-30 14:34:42 +00:00
void KDecorationOptions::setOpMaxButtonRightClick(WindowOperation op)
{
d->opMaxButtonRightClick = op;
2011-01-30 14:34:42 +00:00
}
2011-01-30 14:34:42 +00:00
void KDecorationOptions::setOpMaxButtonMiddleClick(WindowOperation op)
{
d->opMaxButtonMiddleClick = op;
2011-01-30 14:34:42 +00:00
}
2011-01-30 14:34:42 +00:00
void KDecorationOptions::setBorderSize(BorderSize bs)
{
d->border_size = bs;
d->cached_border_size = BordersCount; // invalid
2011-01-30 14:34:42 +00:00
}
2011-01-30 14:34:42 +00:00
void KDecorationOptions::setCustomButtonPositions(bool b)
{
d->custom_button_positions = b;
2011-01-30 14:34:42 +00:00
}
2011-01-30 14:34:42 +00:00
void KDecorationOptions::setTitleButtonsLeft(const QString& b)
{
d->title_buttons_left = b;
2011-01-30 14:34:42 +00:00
}
2011-01-30 14:34:42 +00:00
void KDecorationOptions::setTitleButtonsRight(const QString& b)
{
d->title_buttons_right = b;
2011-01-30 14:34:42 +00:00
}
#include "kdecoration.moc"