summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSam Spilsbury <SmSpillaz@gmail.com>2010-06-12 15:52:46 +0800
committerSam Spilsbury <SmSpillaz@gmail.com>2010-06-12 15:52:46 +0800
commiteea40346e89847e0afcadcc0ccf2595a467c3a31 (patch)
tree5ee6ce64475b934b29aabd2a14ab5f4697823a2c
parent13e0ff224b2729ec97abe9b44cf7311f594c2dbe (diff)
downloadelements-eea40346e89847e0afcadcc0ccf2595a467c3a31.tar.gz
elements-eea40346e89847e0afcadcc0ccf2595a467c3a31.tar.bz2
Added serialization interface and necessary changes
-rw-r--r--CMakeLists.txt4
-rw-r--r--include/elements/elements.h135
-rw-r--r--plugins/autumn/src/autumn.h20
-rw-r--r--plugins/bubbles/src/bubbles.h18
-rw-r--r--plugins/fireflies/src/fireflies.h23
-rw-r--r--plugins/snow/src/snow.h12
-rw-r--r--plugins/stars/src/stars.h12
-rw-r--r--src/animation.cpp126
-rw-r--r--src/elements.cpp212
-rw-r--r--src/private.h49
-rw-r--r--src/type.cpp58
11 files changed, 478 insertions, 191 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 32a1f6d..37c8e7b 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -4,7 +4,7 @@ include (CompizPlugin)
include (CompizCommon)
include (CompizPackage)
-compiz_plugin (elements PLUGINDEPS composite opengl text)
+compiz_plugin (elements PLUGINDEPS composite opengl text compiztoolbox)
set (COMPIZ_VERSION_MAJOR 0)
set (COMPIZ_VERSION_MINOR 9)
@@ -18,4 +18,4 @@ compiz_print_plugin_stats ("${CMAKE_CURRENT_SOURCE_DIR}/plugins")
compiz_print_configure_footer ()
compiz_package_generation ("Compiz Elements Plugins")
-compiz_add_uninstall () \ No newline at end of file
+compiz_add_uninstall ()
diff --git a/include/elements/elements.h b/include/elements/elements.h
index 212349e..ca102b2 100644
--- a/include/elements/elements.h
+++ b/include/elements/elements.h
@@ -48,11 +48,15 @@
#include <core/core.h>
#include <core/pluginclasshandler.h>
+#include <core/serialization.h>
#include <opengl/opengl.h>
#include <composite/composite.h>
#include <text/text.h>
+#include <boost/ptr_container/ptr_vector.hpp>
+#include <boost/ptr_container/serialize_ptr_vector.hpp>
+
#define COMPIZ_ELEMENTS_ABI 1
class ElementType;
@@ -129,6 +133,23 @@ class Element
float opacity;
float glowAlpha; /* Needs to be painted */
+
+ template <class Archive>
+ void serialize (Archive &ar, const unsigned int version)
+ {
+ fprintf (stderr, "saving an element\n");
+ ar & x;
+ ar & y;
+ ar & z;
+ ar & dx;
+ ar & dy;
+ ar & dz;
+ ar & rSpeed;
+ ar & rDirection;
+ ar & rAngle;
+ ar & opacity;
+ ar & glowAlpha;
+ }
virtual bool init ();
virtual void move ();
@@ -143,11 +164,74 @@ class Element
friend class PrivateElementScreen;
};
+class ElementType
+{
+ public:
+
+ class KillTimer:
+ public CompTimer
+ {
+ private:
+ KillTimer ();
+ static void registerKillType (ElementType &);
+ public:
+ bool killTimeout (CompString elementName);
+
+ friend class PrivateElementScreen;
+ friend class ElementType;
+ };
+
+ void
+ setName (CompString, CompString);
+
+ void
+ setCallbacks (elementAddFunc);
+
+ CompString
+ name ();
+
+ CompString
+ desc ();
+
+ static ElementType *
+ find (CompString);
+
+ static ElementType *
+ create (CompString, CompString, elementAddFunc);
+
+ static ElementType *
+ create ();
+
+ void
+ destroy ();
+
+ elementAddFunc addFunc;
+
+ private:
+ ElementType ();
+ ElementType (CompString, CompString, elementAddFunc);
+ ~ElementType ();
+
+ CompString mName;
+ CompString mDesc;
+
+ friend class ElementAnimation;
+ friend class ElementTextSurface;
+ friend class boost::serialization::access;
+};
+
class ElementAnimation
{
public:
~ElementAnimation ();
+ ElementAnimation () {};
+
+ template <class Archive>
+ void serialize (Archive &ar, const unsigned int version)
+ {
+ ar & priv;
+ }
void setNElement (int n);
void setSize (int s);
@@ -162,19 +246,21 @@ class ElementAnimation
int id ();
ElementType * type ();
bool rotate ();
+ bool valid ();
int nTexture ();
void setNTexture (int);
ElementTexture::List textures ();
- std::list<Element *> elements ();
+
+ const boost::ptr_vector<Element> & elements ();
bool start ();
void stop ();
bool active ();
- static ElementAnimation *
+ static ElementAnimation &
create (CompString type,
int nElement,
int size,
@@ -192,50 +278,10 @@ class ElementAnimation
PrivateElementAnimation *priv;
friend class PrivateElementScreen;
+ friend class ElementType::KillTimer;
+ friend class boost::serialization::access;
};
-class ElementType
-{
- public:
-
- void
- setName (CompString, CompString);
-
- void
- setCallbacks (elementAddFunc);
-
- CompString
- name ();
-
- CompString
- desc ();
-
- static ElementType *
- find (CompString);
-
- static ElementType *
- create (CompString, CompString, elementAddFunc);
-
- static ElementType *
- create ();
-
- void
- destroy ();
-
- elementAddFunc addFunc;
-
- private:
- ElementType ();
- ElementType (CompString, CompString, elementAddFunc);
- ~ElementType ();
-
- CompString mName;
- CompString mDesc;
- friend class ElementAnimation;
- friend class ElementTextSurface;
-};
-
-
class ElementScreen :
public PluginClassHandler<ElementScreen, CompScreen>,
public CompOption::Class
@@ -264,6 +310,7 @@ class ElementScreen :
friend class ElementsWindow;
friend class ElementType;
+ friend class ElementType::KillTimer;
friend class ElementAnimation;
friend class ElementsTextSurface;
friend class Element;
diff --git a/plugins/autumn/src/autumn.h b/plugins/autumn/src/autumn.h
index 7319f9e..2dd9c6b 100644
--- a/plugins/autumn/src/autumn.h
+++ b/plugins/autumn/src/autumn.h
@@ -47,6 +47,7 @@
#include <elements/elements.h>
#include <core/core.h>
#include <core/pluginclasshandler.h>
+#include <compiztoolbox/compiztoolbox.h>
#include "autumn_options.h"
#define MAX_AUTUMN_AGE 100
@@ -82,11 +83,28 @@ class AutumnElement :
void fini ();
static Element * create ();
+
+ template <class Archive>
+ void serialize (Archive &ar, const unsigned int version)
+ {
+ boost::serialization::base_object <Element> (*this);
+ ar & autumnFloat;
+ ar & autumnAge;
+ ar & autumnChange;
+ }
+
~AutumnElement ();
- private:
AutumnElement ();
+
+ friend class boost::serialization::access;
+ private:
+
};
+BOOST_CLASS_EXPORT_GUID (AutumnElement, "AutumnElement");
+// this class has a default constructor
+BOOST_SERIALIZATION_FACTORY_0 (AutumnElement);
+
class AutumnPluginVTable :
public CompPlugin::VTableForScreen <AutumnScreen>
{
diff --git a/plugins/bubbles/src/bubbles.h b/plugins/bubbles/src/bubbles.h
index 20f9da9..f4197dd 100644
--- a/plugins/bubbles/src/bubbles.h
+++ b/plugins/bubbles/src/bubbles.h
@@ -46,6 +46,7 @@
#include <elements/elements.h>
#include <core/core.h>
+#include <compiztoolbox/compiztoolbox.h>
#include "bubbles_options.h"
@@ -79,15 +80,30 @@ class BubbleElement :
bool init ();
void move ();
void fini ();
+
+ template <class Archive>
+ void serialize (Archive &ar, const unsigned int version)
+ {
+ boost::serialization::base_object <Element> (*this);
+ ar & bubbleFloat;
+ ar & bubbleAge;
+ ar & bubbleChange;
+ }
static Element *
create ();
~BubbleElement ();
- private:
BubbleElement ();
+ friend class boost::serialization::access;
+ private:
+
};
+BOOST_CLASS_EXPORT_GUID (BubbleElement, "BubbleElement");
+// this class has a default constructor
+BOOST_SERIALIZATION_FACTORY_0 (BubbleElement);
+
class BubblePluginVTable :
public CompPlugin::VTableForScreen <BubbleScreen>
{
diff --git a/plugins/fireflies/src/fireflies.h b/plugins/fireflies/src/fireflies.h
index af07be4..aa1ab9d 100644
--- a/plugins/fireflies/src/fireflies.h
+++ b/plugins/fireflies/src/fireflies.h
@@ -47,6 +47,8 @@
#include <elements/elements.h>
#include <core/core.h>
#include <cmath>
+#include <compiztoolbox/compiztoolbox.h>
+#include <boost/serialization/export.hpp>
#include "fireflies_options.h"
@@ -66,7 +68,7 @@ class FirefliesScreen :
ElementType *type;
};
-
+
class FireflyElement :
public Element
@@ -82,14 +84,31 @@ class FireflyElement :
void move ();
void fini ();
+ template <class Archive>
+ void serialize (Archive &ar, const unsigned int version)
+ {
+ boost::serialization::base_object <Element> (*this);
+ ar & lifespan;
+ ar & age;
+ ar & lifecycle;
+ ar & dx;
+ ar & dy;
+ ar & dz;
+ }
+
static Element *
create ();
~FireflyElement ();
- private:
FireflyElement ();
+ friend class boost::serialization::access;
+ private:
};
+BOOST_CLASS_EXPORT_GUID (FireflyElement, "FireflyElement");
+// this class has a default constructor
+BOOST_SERIALIZATION_FACTORY_0 (FireflyElement);
+
class FireflyPluginVTable :
public CompPlugin::VTableForScreen <FirefliesScreen>
{
diff --git a/plugins/snow/src/snow.h b/plugins/snow/src/snow.h
index 2da3dd9..a3d46a7 100644
--- a/plugins/snow/src/snow.h
+++ b/plugins/snow/src/snow.h
@@ -76,14 +76,24 @@ class SnowElement :
void move ();
void fini ();
+ template <class Archive>
+ void serialize (Archive &ar, const unsigned int version)
+ {
+ boost::serialization::base_object <Element> (*this);
+ }
+
static Element *
create ();
~SnowElement ();
- private:
SnowElement ();
+ private:
};
+BOOST_CLASS_EXPORT_GUID (SnowElement, "SnowElement");
+// this class has a default constructor
+BOOST_SERIALIZATION_FACTORY_0 (SnowElement);
+
class SnowPluginVTable :
public CompPlugin::VTableForScreen <SnowScreen>
{
diff --git a/plugins/stars/src/stars.h b/plugins/stars/src/stars.h
index 8e90162..29fb760 100644
--- a/plugins/stars/src/stars.h
+++ b/plugins/stars/src/stars.h
@@ -75,14 +75,24 @@ class StarElement :
void move ();
void fini ();
+ template <class Archive>
+ void serialize (Archive &ar, const unsigned int version)
+ {
+ boost::serialization::base_object <Element> (*this);
+ }
+
static Element *
create ();
~StarElement ();
- private:
StarElement ();
+ private:
};
+BOOST_CLASS_EXPORT_GUID (StarElement, "StarElement");
+// this class has a default constructor
+BOOST_SERIALIZATION_FACTORY_0 (StarElement);
+
class StarPluginVTable :
public CompPlugin::VTableForScreen <StarScreen>
{
diff --git a/src/animation.cpp b/src/animation.cpp
index c554664..0f5acb1 100644
--- a/src/animation.cpp
+++ b/src/animation.cpp
@@ -46,7 +46,7 @@
#include "private.h"
-ElementAnimation *
+ElementAnimation &
ElementAnimation::create (CompString type,
int nElement,
int size,
@@ -54,34 +54,32 @@ ElementAnimation::create (CompString type,
int iter,
bool rotate)
{
- ElementAnimation *anim = new ElementAnimation (type, nElement, size,
- speed, iter, rotate);
-
- if (!anim)
- return NULL;
-
ELEMENTS_SCREEN (screen);
+
+ es->priv->animations.push_back (ElementAnimation (type, nElement, size,
+ speed, iter, rotate));
+
+ ElementAnimation &anim = es->priv->animations.back ();
CompOption::Value::Vector paths, iters;
- if (anim->type ())
+ if (anim.type ())
{
paths = es->priv->optionGetElementImage ();
iters = es->priv->optionGetElementIter ();
- anim->priv->applyTextures (type, &paths, &iters, size, iter);
+ anim.priv->applyTextures (type, &paths, &iters, size, iter);
- for (int i = 0; i < anim->nElement (); i++)
+ for (int i = 0; i < anim.nElement (); i++)
{
- Element *e = anim->type ()->addFunc ();
- e->anim = anim;
+ Element *e = anim.type ()->addFunc ();
+ e->anim = &anim;
e->defaultInit ();
e->init ();
- anim->priv->mElements.push_back (e);
+ anim.priv->mElements.push_back (e);
}
-
- es->priv->animations.push_back (anim);
-
- return anim;
+
+ anim.priv->mValid = true;
+ return es->priv->animations.back ();
}
else
@@ -89,8 +87,8 @@ ElementAnimation::create (CompString type,
compLogMessage ("elements", CompLogLevelWarn,
"Could not find element movement pattern %s, "
"disabling this element", type.c_str ());
- delete anim;
- return NULL;
+ anim.priv->mValid = false;
+ return es->priv->animations.back ();
}
}
@@ -106,6 +104,7 @@ PrivateElementAnimation::PrivateElementAnimation (CompString type,
mId (iter),
mNTexture (0),
mType (ElementType::find (type)),
+ mTypename (type),
mActive (false),
mValid (true),
mRotate (rotate)
@@ -125,16 +124,6 @@ ElementAnimation::ElementAnimation (CompString type,
ElementAnimation::~ElementAnimation ()
{
- ELEMENTS_SCREEN (screen);
-
- while (!priv->mElements.empty ())
- {
- Element *e = priv->mElements.back ();
- e->fini ();
- priv->mElements.remove (e);
- }
-
- es->priv->animations.remove (this);
}
/* Check to see if an element is still within the screen. If it is,
@@ -147,38 +136,35 @@ PrivateElementAnimation::removeOffscreenElements ()
{
ELEMENTS_SCREEN (screen);
bool ret = true;
+ int count = 0;
+ int nElem = mElements.size ();
/* Reverse the stack, remove elements that are no longer needed */
- while (mElements.begin () != mElements.end ())
+ while (count != nElem)
{
- Element *e = mElements.front ();
-
- if (e)
+ Element &e = mElements.back ();
+
+ if (e.opacity > 0.0f)
+ e.opacity -= 0.03f;
+ if (!(e.y >= screen->height () + 200 ||
+ e.x <= -200 ||
+ e.x >= screen->width () + 200 ||
+ e.y >= screen->height () + 200 ||
+ e.z <= -((float) es->depth () / 500.0) ||
+ e.z >= 1 ||
+ e.y <= -((float) es->boxing () / 5.0f)) &&
+ e.opacity > 0.0f)
{
-
- mElements.pop_front ();
-
- if (e->opacity > 0.0f)
- e->opacity -= 0.003f;
- if (!(e->y >= screen->height () + 200 ||
- e->x <= -200 ||
- e->x >= screen->width () + 200 ||
- e->y >= screen->height () + 200 ||
- e->z <= -((float) es->depth () / 500.0) ||
- e->z >= 1 ||
- e->y <= -((float) es->boxing () / 5.0f)) &&
- e->opacity > 0.0f)
- {
- ret = false;
- mElements.push_back (e);
- }
- else
- {
- e->fini ();
- mElements.remove (e);
- }
+ ret = false;
+ }
+ else
+ {
+ e.fini ();
+ mElements.pop_back ();
}
+
+ count++;
}
return ret;
@@ -229,9 +215,9 @@ ElementAnimation::setNElement (int n)
while (count--)
{
- Element *e = priv->mElements.back ();
- e->fini ();
- priv->mElements.remove (e);
+ Element &e = priv->mElements.back ();
+ e.fini ();
+ priv->mElements.pop_back ();
}
}
else if (n > priv->mNElement)
@@ -243,6 +229,9 @@ ElementAnimation::setNElement (int n)
while (count--)
{
Element *e = priv->mType->addFunc ();
+ e->anim = this;
+ e->defaultInit ();
+ e->init ();
priv->mElements.push_back (e);
}
}
@@ -271,18 +260,21 @@ ElementAnimation::setId (int n)
bool
ElementAnimation::setType (CompString name)
{
+ priv->mTypename = name;
+
priv->mType = ElementType::find (name);
if (priv->mType)
{
+
/* Fini all elements */
int nElement = priv->mNElement;
while (nElement--)
{
- Element *e = priv->mElements.back ();
- e->fini ();
- priv->mElements.remove (e);
+ Element &e = priv->mElements.back ();
+ e.fini ();
+ priv->mElements.pop_back ();
}
nElement = priv->mNElement;
@@ -291,12 +283,13 @@ ElementAnimation::setType (CompString name)
while (nElement--)
{
- Element *e = priv->mType->addFunc ();
- priv->mElements.push_back (e);
+ priv->mElements.push_back (priv->mType->addFunc ());
}
}
else
+ {
return false;
+ }
return true;
}
@@ -313,7 +306,7 @@ ElementAnimation::textures ()
return priv->mTexture;
}
-std::list<Element *>
+const boost::ptr_vector<Element> &
ElementAnimation::elements ()
{
return priv->mElements;
@@ -351,6 +344,11 @@ int ElementAnimation::nTexture ()
return priv->mNTexture;
}
+bool ElementAnimation::valid ()
+{
+ return priv->mValid;
+}
+
ElementType *
ElementAnimation::type ()
{
diff --git a/src/elements.cpp b/src/elements.cpp
index af44137..ebefb88 100644
--- a/src/elements.cpp
+++ b/src/elements.cpp
@@ -263,7 +263,6 @@ PrivateElementScreen::toggleElementName (CompAction *action,
CompString elementType;
bool stopped = false;
int savedIter = 0;
- ElementAnimation *currAnim = NULL;
CompOption::Value::Vector cIter = optionGetElementIter ();
CompOption::Value::Vector cType = optionGetElementType ();
CompOption::Value::Vector cPath = optionGetElementImage ();
@@ -287,14 +286,14 @@ PrivateElementScreen::toggleElementName (CompAction *action,
return false;
}
- foreach (ElementAnimation *anim, animations)
+ foreach (ElementAnimation &anim, animations)
{
- if (anim->type ()->name () == elementType)
+ if (anim.type ()->name () == elementType)
{
- if (anim->active ())
- anim->stop ();
+ if (anim.active ())
+ anim.stop ();
else
- anim->start ();
+ anim.start ();
stopped = true;
}
@@ -312,14 +311,15 @@ PrivateElementScreen::toggleElementName (CompAction *action,
{
savedIter = cIter.at (i).i ();
- currAnim = ElementAnimation::create (cType.at (i).s (),
+ ElementAnimation &anim =
+ ElementAnimation::create (cType.at (i).s (),
cCap.at (i).i () ,
cSize.at (i).i (),
cSpeed.at (i).i (),
cIter.at (i).i (),
cRot.at (i).b ());
- currAnim->start ();
+ anim.start ();
break;
}
}
@@ -335,7 +335,7 @@ PrivateElementScreen::toggleSelected (CompAction *action,
CompOption::Vector &options)
{
CompString string;
- ElementAnimation *currAnim = NULL;
+ bool foundAnim = false;
CompOption::Value::Vector cIter = optionGetElementIter ();
CompOption::Value::Vector cType = optionGetElementType ();
CompOption::Value::Vector cPath = optionGetElementImage ();
@@ -344,8 +344,6 @@ PrivateElementScreen::toggleSelected (CompAction *action,
CompOption::Value::Vector cSpeed = optionGetElementSpeed ();
CompOption::Value::Vector cRot = optionGetElementRotate ();
- fprintf (stderr, "toggleSelected called\n");
-
if (!((cType.size () == cIter.size ()) &&
(cPath.size () == cIter.size ()) &&
(cCap.size () == cIter.size ()) &&
@@ -363,34 +361,35 @@ PrivateElementScreen::toggleSelected (CompAction *action,
if (!displayTextInfo (cType))
return true;
- foreach (ElementAnimation *anim, animations)
+ foreach (ElementAnimation &anim, animations)
{
- if (anim->id () == animIter)
+ if (anim.id () == animIter)
{
- if (anim->active ())
- anim->stop ();
+ if (anim.active ())
+ anim.stop ();
else
- anim->start ();
+ anim.start ();
- currAnim = anim;
+ foundAnim = true;
break;
}
}
- if (!currAnim)
+ if (!foundAnim)
{
if (!redrawTimer.active ())
redrawTimer.start ();
- currAnim = ElementAnimation::create (cType.at (listIter).s (),
+ ElementAnimation &anim =
+ ElementAnimation::create (cType.at (listIter).s (),
cCap.at (listIter).i () ,
cSize.at (listIter).i (),
cSpeed.at (listIter).i (),
animIter,
cRot.at (listIter).b ());
- currAnim->start ();
+ anim.start ();
}
return true;
@@ -414,9 +413,9 @@ PrivateElementScreen::switchTimeout ()
if (!animations.empty ())
{
- foreach (ElementAnimation *anim, animations)
+ foreach (ElementAnimation &anim, animations)
{
- anim->setNTexture ((anim->nTexture () + 1) % (anim->textures ().size ()));
+ anim.setNTexture ((anim.nTexture () + 1) % (anim.textures ().size ()));
}
}
@@ -453,22 +452,24 @@ PrivateElementScreen::render (const GLMatrix &transform)
needUpdate = false;
}
- foreach (ElementAnimation *anim, animations)
+ foreach (ElementAnimation &anim, animations)
{
- if (anim->textures ().size () > 0)
+ if (anim.textures ().size () > 0)
{
- int n = anim->nTexture () % anim->textures ().size ();
- ElementTexture *eTex = (anim->textures () [n]);
- foreach (Element *e, anim->elements ())
+ int n = anim.nTexture () % anim.textures ().size ();
+ ElementTexture *eTex = (anim.textures () [n]);
+
+ for (unsigned int i = 0; i < anim.elements ().size (); i++)
{
+ const Element &e = anim.elements ()[i];
glPushMatrix ();
glLoadMatrixf (transform.getMatrix ());
- glColor4f (1.0, 1.0, 1.0, e->opacity);
- glTranslatef (e->x, e->y, e->z);
- glRotatef (e->rAngle, 0, 0, 1);
+ glColor4f (1.0, 1.0, 1.0, e.opacity);
+ glTranslatef (e.x, e.y, e.z);
+ glRotatef (e.rAngle, 0, 0, 1);
eTex->draw ();
- glRotatef (-e->rAngle, 0, 0, 1);
- glTranslatef (-e->x, -e->y, -e->z);
+ glRotatef (-e.rAngle, 0, 0, 1);
+ glTranslatef (-e.x, -e.y, -e.z);
glPopMatrix ();
}
}
@@ -544,23 +545,26 @@ ElementsWindow::glDraw (const GLMatrix &transform,
bool
PrivateElementScreen::redrawTimeout ()
{
- std::list <ElementAnimation *>::iterator it = animations.begin ();
+ std::list <ElementAnimation>::iterator it = animations.begin ();
if (animations.empty ())
return false;
while (it != animations.end ())
{
- ElementAnimation *anim = *it;
+ ElementAnimation &anim = *it;
+ boost::ptr_vector <Element>::iterator eit = anim.priv->mElements.begin ();
- if (anim->active ())
+ if (anim.active ())
{
- foreach (Element *e, anim->priv->mElements)
+ while (eit != anim.priv->mElements.end ())
{
/* This tests to see if the element is offscreen, if so
* replace it with one at the beginning of its animation
* the screen if not, move it */
- e->regenerateOffscreen ();
+ Element &e = *eit;
+ e.regenerateOffscreen ();
+ eit++;
}
}
else
@@ -570,11 +574,11 @@ PrivateElementScreen::redrawTimeout ()
* finish "nicely", ie they don't just disappear when untoggled)
*/
- if (anim->priv->removeOffscreenElements ())
+ if (anim.priv->removeOffscreenElements ())
{
- anim->priv->mTexture.clear ();
- anim->priv->mElements.clear ();
- delete anim;
+ anim.priv->mTexture.clear ();
+ anim.priv->mElements.clear ();
+ animations.erase (it);
/* We must reset the list count here otherwise foreach will
* attempt to access an item in a list that we just deleted
@@ -584,9 +588,15 @@ PrivateElementScreen::redrawTimeout ()
continue;
}
}
+
+ eit = anim.priv->mElements.begin ();
- foreach (Element *e, anim->elements ())
- e->move ();
+ while (eit != anim.priv->mElements.end ())
+ {
+ Element &e = *eit;
+ e.move ();
+ eit++;
+ }
it++;
}
@@ -620,7 +630,7 @@ PrivateElementScreen::redrawTimeout ()
void
PrivateElementScreen::updateElementTextures ()
{
- foreach (ElementAnimation *anim, animations)
+ foreach (ElementAnimation &anim, animations)
{
int iter, nElement, size,speed;
bool rotate;
@@ -647,16 +657,16 @@ PrivateElementScreen::updateElementTextures ()
return;
}
- iter = anim->id ();
- nElement = cCap.at (anim->id () - 1).i ();
- type = cType.at (anim->id () - 1).s ();
- size = cSize.at (anim->id () - 1).i ();
- speed = cSpeed.at (anim->id () - 1).i ();
- rotate = cRot.at (anim->id () - 1).b ();
+ iter = anim.id ();
+ nElement = cCap.at (anim.id () - 1).i ();
+ type = cType.at (anim.id () - 1).s ();
+ size = cSize.at (anim.id () - 1).i ();
+ speed = cSpeed.at (anim.id () - 1).i ();
+ rotate = cRot.at (anim.id () - 1).b ();
- anim->priv->mTexture.clear ();
+ anim.priv->mTexture.clear ();
- if (type != anim->type ()->name ())
+ if (type != anim.type ()->name ())
{
bool found = false;
@@ -671,44 +681,50 @@ PrivateElementScreen::updateElementTextures ()
"Could not find element movement pattern %s",
type.c_str ());
- anim->stop ();
+ anim.stop ();
- foreach (Element *e, anim->elements ())
+ for (unsigned int i = 0; i < anim.priv->mElements.size (); i++)
{
- e->fini ();
+ Element &e = anim.priv->mElements[i];
+ e.fini ();
+ i++;
}
initiate = true;
}
- if (anim->priv->applyTextures (anim->type ()->name (), &cPath, &cIter, size, iter))
+ if (anim.priv->applyTextures (anim.type ()->name (), &cPath, &cIter, size, iter))
{
- if (nElement != anim->nElement ())
+ if (nElement != anim.nElement ())
{
/* Implicitly or subtracts elements and handles memory */
- anim->setNElement (nElement);
+ anim.setNElement (nElement);
/* FIXME: NULL check? */
initiate = true;
}
- if (type != anim->type ()->name ())
+ if (type != anim.type ()->name ())
{
- anim->setType (type);
+ anim.setType (type);
initiate = true;
}
- if (anim->rotate () != rotate)
+ if (anim.rotate () != rotate)
initiate = true;
- anim->setRotate (rotate);
- anim->setSize (size);
- anim->setSpeed (speed);
+ anim.setRotate (rotate);
+ anim.setSize (size);
+ anim.setSpeed (speed);
- foreach (Element *e, anim->elements ())
- e->init ();
+ for (unsigned int i = 0; i < anim.priv->mElements.size (); i++)
+ {
+ Element &e = anim.priv->mElements[i];
+ e.init ();
+ i++;
+ }
- anim->start ();
+ anim.start ();
}
}
@@ -769,7 +785,64 @@ ElementsWindow::ElementsWindow (CompWindow *window) :
GLWindowInterface::setHandler (gWindow, false);
}
+void
+PrivateElementScreen::postLoad ()
+{
+ std::list<ElementAnimation>::iterator ait = animations.begin ();
+
+ CompOption::Value::Vector cIter = optionGetElementIter ();
+
+ /* The multi options list may have changed while we were disabled
+ * if this happens then it really isn't worth trying to restore what
+ * was, as this will likely cause havoc.
+ */
+
+ if (cIter.size () != multiOptionsListSize)
+ {
+ animations.clear ();
+ return;
+ }
+
+ /* At this point, all the types should be loaded .... */
+
+ while (ait != animations.end ())
+ {
+ ElementAnimation &anim = *ait;
+
+ /* Don't need to start clearing and reloading lists here ...
+ * circumvent
+ */
+
+ unsigned int tempNElement = anim.priv->mNElement;
+ anim.priv->mNElement = 0;
+
+ if (!anim.setType (anim.priv->mTypename))
+ {
+ /* Couldn't find the type, bail and kill it */
+ animations.erase (ait);
+ ait = animations.begin ();
+ continue;
+ }
+
+ anim.setNElement (tempNElement);
+
+ if (anim.priv->mActive)
+ {
+ if (!redrawTimer.active ())
+ {
+ redrawTimer.start ();
+ }
+ }
+
+ ait++;
+ }
+
+ updateElementTextures ();
+}
+
+
PrivateElementScreen::PrivateElementScreen (CompScreen *screen) :
+ PluginStateWriter <PrivateElementScreen> (this, "ELEMENTS", screen->root ()),
cScreen (CompositeScreen::get (screen)),
gScreen (GLScreen::get (screen)),
text (NULL),
@@ -788,6 +861,9 @@ PrivateElementScreen::PrivateElementScreen (CompScreen *screen) :
if (cIter.at (i).i () < lowest)
lowest = cIter.at (i).i ();
+
+ multiOptionsListSize = cIter.size ();
+
optionSetNextElementKeyInitiate (boost::bind
(&PrivateElementScreen::nextElement,
this, _1, _2, _3));
@@ -861,6 +937,8 @@ ElementScreen::~ElementScreen ()
PrivateElementScreen::~PrivateElementScreen ()
{
+ writeSerializedData ();
+
while (!types.empty ())
{
ElementType_ *type = types.front ();
diff --git a/src/private.h b/src/private.h
index 6a08db5..eefb9e3 100644
--- a/src/private.h
+++ b/src/private.h
@@ -103,6 +103,8 @@ class PrivateElementAnimation
int speed,
int iter,
bool rotate);
+
+ PrivateElementAnimation () {};
bool applyTextures (CompString,
CompOption::Value::Vector *paths,
@@ -111,6 +113,25 @@ class PrivateElementAnimation
int iter);
bool removeOffscreenElements ();
+
+ template <class Archive>
+ void serialize (Archive &ar, const unsigned int version)
+ {
+ ar & mNElement;
+ ar & mSize;
+ ar & mSpeed;
+ ar & mId;
+ ar & mNTexture;
+ ar & mTypename;
+ ar & mActive;
+ ar & mValid;
+ ar & mRotate;
+ // ar & mTexture;
+ /* Until we can resolve serialization type registration at
+ * runtime, it will not be possible to save individual elements
+ * ar & mElements;
+ */
+ }
int mNElement;
int mSize;
@@ -120,6 +141,7 @@ class PrivateElementAnimation
int mNTexture;
ElementType *mType;
+ CompString mTypename; // Used for serialization purposes
bool mActive;
bool mValid;
@@ -127,11 +149,12 @@ class PrivateElementAnimation
bool mRotate;
ElementTexture::List mTexture;
- std::list<Element *> mElements;
+ boost::ptr_vector<Element> mElements;
};
class PrivateElementScreen :
public ElementsOptions,
+ public PluginStateWriter <PrivateElementScreen>,
public GLScreenInterface,
public CompositeScreenInterface
{
@@ -147,6 +170,26 @@ class PrivateElementScreen :
CompTimer switchTimer;
CompTimer textTimer;
+
+ /* Used to kill animations at the top
+ * of handleEvent (), so that we can
+ * serialize animation data before
+ * it gets killed by all the subplugins
+ * unloading. */
+ std::list <ElementType::KillTimer> killAnimationsTimers;
+
+ template <class Archive>
+ void serialize (Archive &ar, const unsigned int version)
+ {
+ ar & listIter;
+ ar & animIter;
+ ar & needUpdate;
+ ar & animations;
+ //ar & types;
+ }
+
+ void postLoad ();
+
bool
glPaintOutput (const GLScreenPaintAttrib &,
const GLMatrix &,
@@ -189,11 +232,13 @@ class PrivateElementScreen :
int listIter;
int animIter;
+
+ unsigned int multiOptionsListSize;
GLuint displayList;
bool needUpdate;
- std::list<ElementAnimation *> animations;
+ std::list<ElementAnimation> animations;
std::list<ElementType_ *> types;
};
diff --git a/src/type.cpp b/src/type.cpp
index d124a94..cde8403 100644
--- a/src/type.cpp
+++ b/src/type.cpp
@@ -73,25 +73,69 @@ ElementType::~ElementType ()
delete this;
}
-void
-ElementType::destroy ()
+bool
+ElementType::KillTimer::killTimeout (CompString elementName)
{
+ std::list<ElementType::KillTimer>::iterator kit;
+ std::list<ElementAnimation>::iterator it;
ELEMENTS_SCREEN (screen);
+
+ for (kit = es->priv->killAnimationsTimers.begin ();
+ kit != es->priv->killAnimationsTimers.end ();
+ kit++)
+ {
+ ElementType::KillTimer &kObj = *this;
+ ElementType::KillTimer &kItr = *kit;
+ if (memcmp (&kItr, &kObj, sizeof (KillTimer)) == 0)
+ break;
+ }
- std::list<ElementAnimation *>::iterator it = es->priv->animations.begin ();
+ it = es->priv->animations.begin ();
while (it != es->priv->animations.end ())
{
- ElementAnimation *anim = *it;
+ ElementAnimation &anim = *it;
- if (this == anim->type ())
+ if (elementName == anim.priv->mTypename)
{
- delete anim;
+ es->priv->animations.erase (it);
it = es->priv->animations.begin ();
}
else
it++;
}
+
+ /* Remove from the master list of timeouts, since we're done now */
+
+ es->priv->killAnimationsTimers.erase (kit);
+
+ return false;
+}
+
+ElementType::KillTimer::KillTimer ()
+{
+}
+
+void
+ElementType::KillTimer::registerKillType (ElementType &t)
+{
+ ELEMENTS_SCREEN (screen);
+
+ std::list<ElementAnimation>::iterator it = es->priv->animations.begin ();
+
+ es->priv->killAnimationsTimers.push_back (KillTimer ());
+
+ KillTimer &killTimer = es->priv->killAnimationsTimers.back ();
+
+ killTimer.setTimes (0, 0);
+ killTimer.setCallback (boost::bind (&ElementType::KillTimer::killTimeout,
+ &killTimer, t.mName));
+}
+
+void
+ElementType::destroy ()
+{
+ ElementType::KillTimer::registerKillType (*this);
}
ElementType *
@@ -154,7 +198,9 @@ ElementType::find (CompString name)
foreach (ElementType *type, es->priv->types)
{
if (type->name () == name)
+ {
return type;
+ }
}
return NULL;