From 607e175b4b53fedb6b115b68db2f03ad55a0bc6e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Gr=C3=A4=C3=9Flin?= Date: Thu, 22 Nov 2012 13:06:42 +0100 Subject: [PATCH] Make Placement a Singleton No real change as there has only been one Placement instance inside Workspace anyway. --- placement.cpp | 14 ++++++++++++++ placement.h | 23 +++++++++++++++++++---- workspace.cpp | 2 +- 3 files changed, 34 insertions(+), 5 deletions(-) diff --git a/placement.cpp b/placement.cpp index d5ad358016..e889980e60 100644 --- a/placement.cpp +++ b/placement.cpp @@ -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 */ diff --git a/placement.h b/placement.h index 0fe894ef77..93b42f4037 100644 --- a/placement.h +++ b/placement.h @@ -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 cci; Workspace* m_WorkspacePtr; + static Placement *s_self; }; +inline +Placement *Placement::self() +{ + return s_self; +} + } // namespace #endif diff --git a/workspace.cpp b/workspace.cpp index f80649da26..9489ae56dc 100644 --- a/workspace.cpp +++ b/workspace.cpp @@ -374,7 +374,7 @@ void Workspace::init() m_desktopFocusChain = m_activitiesDesktopFocusChain.insert(QString(), QVector(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();