From 8c4cfbca60a355f2f507f07cee7b1e95508eb692 Mon Sep 17 00:00:00 2001 From: "Aaron J. Seigo" Date: Wed, 5 Mar 2008 07:08:32 +0000 Subject: [PATCH] keep the toolbox in the workArea (e.g. out from underneath panels and other strut reservers) svn path=/trunk/KDE/kdebase/workspace/libs/plasma/; revision=782438 --- containment.cpp | 43 +++++++++++++++++++++++++++++++++++++------ containment.h | 5 +++++ 2 files changed, 42 insertions(+), 6 deletions(-) diff --git a/containment.cpp b/containment.cpp index 25c9602fa..6bbdfbcdc 100644 --- a/containment.cpp +++ b/containment.cpp @@ -36,6 +36,7 @@ #include #include #include +#include #include "applethandle_p.h" #include "corona.h" @@ -74,12 +75,25 @@ public: { if (!toolbox) { toolbox = new DesktopToolbox(q); - toolbox->setPos(q->geometry().width() - toolbox->boundingRect().width(), 0); + positionToolbox(); } return toolbox; } + void positionToolbox() + { + QRectF r; + if (screen < 0) { + r = q->geometry(); + } else { + QDesktopWidget *desktop = QApplication::desktop(); + r = desktop->availableGeometry(screen); + } + + toolbox->setPos(QPointF(r.right() - toolbox->boundingRect().width(), r.y())); + } + void setLockToolText(); Containment *q; @@ -743,11 +757,20 @@ void Containment::setScreen(int screen) { // screen of -1 means no associated screen. // sanity check to make sure someone else doesn't have this screen already! - if (screen > -1 && containmentType() == DesktopContainment && corona()) { - Containment* currently = corona()->containmentForScreen(screen); - if (currently && currently != this) { - //kDebug() << "currently is on screen" << currently->screen() << "and is" << currently->name() << (QObject*)currently << (QObject*)this; - currently->setScreen(-1); + if (containmentType() == DesktopContainment) { + // we want to listen to changes in work area if our screen changes + if (d->screen < 0 && screen > -1) { + connect(KWindowSystem::self(), SIGNAL(workAreaChanged()), this, SLOT(repositionToolbox())); + } else if (screen < 0) { + disconnect(KWindowSystem::self(), SIGNAL(workAreaChanged()), this, SLOT(repositionToolbox())); + } + + if (screen > -1 && corona()) { + Containment* currently = corona()->containmentForScreen(screen); + if (currently && currently != this) { + //kDebug() << "currently is on screen" << currently->screen() << "and is" << currently->name() << (QObject*)currently << (QObject*)this; + currently->setScreen(-1); + } } } @@ -991,6 +1014,14 @@ void Containment::hideToolbox() d->createToolbox()->hideToolbox(); } +void Containment::repositionToolbox() +{ + //kDebug() << "reposition" << d->screen << (QObject*)d->toolbox; + if (d->toolbox) { + d->positionToolbox(); + } +} + } // Plasma namespace #include "containment.moc" diff --git a/containment.h b/containment.h index 515761647..f5b384583 100644 --- a/containment.h +++ b/containment.h @@ -361,6 +361,11 @@ class PLASMA_EXPORT Containment : public Applet void handleDisappeared(AppletHandle *handle); void destroyApplet(); + /** + * Repositions the Plasma toolbox. Useful to ensure its always in the correct place within the view. + */ + void repositionToolbox(); + private: QRectF geometryForApplet(Applet *applet) const; bool regionIsEmpty(const QRectF ®ion, Applet *ignoredApplet=0) const;