Make Placement a Singleton

No real change as there has only been one Placement instance inside
Workspace anyway.
This commit is contained in:
Martin Gräßlin 2012-11-22 13:06:42 +01:00
parent 7518da995f
commit 607e175b4b
3 changed files with 34 additions and 5 deletions

View file

@ -39,6 +39,15 @@ namespace KWin
#ifndef KCMRULES
Placement *Placement::s_self = NULL;
Placement *Placement::create(Workspace *ws)
{
Q_ASSERT(!s_self);
s_self = new Placement(ws);
return s_self;
}
Placement::Placement(Workspace* w)
{
m_WorkspacePtr = w;
@ -46,6 +55,11 @@ Placement::Placement(Workspace* w)
reinitCascading(0);
}
Placement::~Placement()
{
s_self = NULL;
}
/*!
Places the client \a c according to the workspace's layout policy
*/

View file

@ -36,8 +36,7 @@ class Client;
class Placement
{
public:
Placement(Workspace* w);
virtual ~Placement();
/**
* Placement policies. How workspace decides the way windows get positioned
@ -75,15 +74,24 @@ public:
static Policy policyFromString(const QString& policy, bool no_special);
static const char* policyToString(Policy policy);
/**
* Singleton getter for this Placement object once the Placement has been created.
* @see create
**/
static Placement *self();
/**
* Creates the Placement singleton.
**/
static Placement *create(Workspace *ws);
private:
explicit Placement(Workspace* w);
void place(Client* c, QRect& area, Policy policy, Policy nextPlacement = Unknown);
void placeUnderMouse(Client* c, QRect& area, Policy next = Unknown);
void placeOnMainWindow(Client* c, QRect& area, Policy next = Unknown);
QRect checkArea(const Client*c, const QRect& area);
Placement();
//CT needed for cascading+
struct DesktopCascadingInfo {
QPoint pos;
@ -94,8 +102,15 @@ private:
QList<DesktopCascadingInfo> cci;
Workspace* m_WorkspacePtr;
static Placement *s_self;
};
inline
Placement *Placement::self()
{
return s_self;
}
} // namespace
#endif

View file

@ -374,7 +374,7 @@ void Workspace::init()
m_desktopFocusChain = m_activitiesDesktopFocusChain.insert(QString(), QVector<int>(numberOfDesktops()));
// Now we know how many desktops we'll have, thus we initialize the positioning object
initPositioning = new Placement(this);
initPositioning = Placement::create(this);
loadDesktopSettings();
updateDesktopLayout();