summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/compcore.h3
-rw-r--r--include/compdisplay.h7
-rw-r--r--include/compiz-core.h99
-rw-r--r--include/compobject.h53
-rw-r--r--include/compscreen.h6
-rw-r--r--include/compwindow.h6
-rw-r--r--plugins/move.cpp68
-rw-r--r--src/Makefile.am1
-rw-r--r--src/core.cpp68
-rw-r--r--src/display.cpp78
-rw-r--r--src/object.cpp161
-rw-r--r--src/plugin.cpp99
-rw-r--r--src/privates.cpp68
-rw-r--r--src/screen.cpp82
-rw-r--r--src/window.cpp76
15 files changed, 209 insertions, 666 deletions
diff --git a/include/compcore.h b/include/compcore.h
index 4324ef4..97a38b5 100644
--- a/include/compcore.h
+++ b/include/compcore.h
@@ -138,6 +138,9 @@ class CompCore : public WrapableHandler<CoreInterface>, public CompObject {
void *
removeTimeout (CompTimeoutHandle handle);
+ static int allocPrivateIndex ();
+ static void freePrivateIndex (int index);
+
// Wrapable interface
WRAPABLE_HND(void, fileWatchAdded, CompFileWatch *)
diff --git a/include/compdisplay.h b/include/compdisplay.h
index 564d9f2..cc69df7 100644
--- a/include/compdisplay.h
+++ b/include/compdisplay.h
@@ -8,6 +8,8 @@ class CompDisplay;
class CompScreen;
class PrivateDisplay;
+#define GET_CORE_DISPLAY(object) (dynamic_cast<CompDisplay *> (object))
+#define CORE_DISPLAY(object) CompDisplay *d = GET_CORE_DISPLAY (object)
class DisplayInterface : public WrapableInterface<CompDisplay> {
public:
@@ -34,8 +36,6 @@ class CompDisplay : public WrapableHandler<DisplayInterface>, public CompObject
public:
CompDisplay *next;
- char *screenPrivateIndices;
- int screenPrivateLen;
class Atoms {
public:
@@ -354,6 +354,9 @@ class CompDisplay : public WrapableHandler<DisplayInterface>, public CompObject
void
addScreenActions (CompScreen *s);
+
+ static int allocPrivateIndex ();
+ static void freePrivateIndex (int index);
// wrapable interface
WRAPABLE_HND(void, handleEvent, XEvent *event)
diff --git a/include/compiz-core.h b/include/compiz-core.h
index dd0068c..1ef11c1 100644
--- a/include/compiz-core.h
+++ b/include/compiz-core.h
@@ -258,6 +258,7 @@ extern CompMetadata coreMetadata;
#define UNWRAP(priv, real, func) \
(real)->func = (priv)->func
+
typedef union _CompPrivate {
void *ptr;
long val;
@@ -265,20 +266,6 @@ typedef union _CompPrivate {
void *(*fptr) (void);
} CompPrivate;
-typedef int (*ReallocPrivatesProc) (int size, void *closure);
-
-int
-allocatePrivateIndex (int *len,
- char **indices,
- ReallocPrivatesProc reallocProc,
- void *closure);
-
-void
-freePrivateIndex (int len,
- char *indices,
- int index);
-
-
/* session.c */
@@ -647,35 +634,6 @@ union _CompMatchOp {
};
-
-
-#define GET_CORE_DISPLAY(object) ((CompDisplay *) (object))
-#define CORE_DISPLAY(object) CompDisplay *d = GET_CORE_DISPLAY (object)
-
-CompBool
-allocDisplayObjectPrivates (CompObject *object,
- CompObject *parent);
-
-int
-allocDisplayObjectPrivateIndex (CompObject *parent);
-
-void
-freeDisplayObjectPrivateIndex (CompObject *parent,
- int index);
-
-char *
-nameDisplayObject (CompObject *object);
-
-CompObject *
-findDisplayObject (CompObject *parent,
- const char *name);
-
-int
-allocateDisplayPrivateIndex (void);
-
-void
-freeDisplayPrivateIndex (int index);
-
bool
setDisplayOption (CompObject *object,
const char *name,
@@ -1248,31 +1206,6 @@ typedef struct _CompActiveWindowHistory {
int activeNum;
} CompActiveWindowHistory;
-
-#define GET_CORE_SCREEN(object) ((CompScreen *) (object))
-#define CORE_SCREEN(object) CompScreen *s = GET_CORE_SCREEN (object)
-
-CompBool
-allocScreenObjectPrivates (CompObject *object,
- CompObject *parent);
-
-int
-allocScreenObjectPrivateIndex (CompObject *parent);
-
-void
-freeScreenObjectPrivateIndex (CompObject *parent,
- int index);
-
-char *
-nameScreenObject (CompObject *object);
-
-int
-allocateScreenPrivateIndex (CompDisplay *display);
-
-void
-freeScreenPrivateIndex (CompDisplay *display,
- int index);
-
bool
setScreenOption (CompObject *object,
const char *name,
@@ -1306,34 +1239,6 @@ typedef struct _CompStruts {
} CompStruts;
-#define GET_CORE_WINDOW(object) ((CompWindow *) (object))
-#define CORE_WINDOW(object) CompWindow *w = GET_CORE_WINDOW (object)
-
-CompBool
-allocWindowObjectPrivates (CompObject *object,
- CompObject *parent);
-
-int
-allocWindowObjectPrivateIndex (CompObject *parent);
-
-void
-freeWindowObjectPrivateIndex (CompObject *parent,
- int index);
-
-char *
-nameWindowObject (CompObject *object);
-
-CompObject *
-findWindowObject (CompObject *parent,
- const char *name);
-
-int
-allocateWindowPrivateIndex (CompScreen *screen);
-
-void
-freeWindowPrivateIndex (CompScreen *screen,
- int index);
-
/* plugin.c */
#define HOME_PLUGINDIR ".compiz/plugins"
@@ -1360,7 +1265,7 @@ struct _CompPlugin {
CompPluginVTable *vTable;
};
-CompBool
+bool
objectInitPlugins (CompObject *o);
void
diff --git a/include/compobject.h b/include/compobject.h
index 03aa85d..9ff1cde 100644
--- a/include/compobject.h
+++ b/include/compobject.h
@@ -1,6 +1,7 @@
#ifndef _COMPOBJECT_H
#define _COMPOBJECT_H
+#include <vector>
typedef int CompObjectType;
@@ -15,43 +16,6 @@ typedef int CompObjectType;
typedef bool (*ObjectCallBackProc) (CompObject *object,
void *closure);
-typedef bool (*ObjectTypeCallBackProc) (CompObjectType type,
- CompObject *parent,
- void *closure);
-
-void
-compObjectInit (CompObject *object,
- CompPrivate *privates,
- CompObjectType type);
-
-void
-compObjectFini (CompObject *object);
-
-int
-compObjectAllocatePrivateIndex (CompObject *parent,
- CompObjectType type);
-
-void
-compObjectFreePrivateIndex (CompObject *parent,
- CompObjectType type,
- int index);
-
-CompBool
-compObjectForEachType (CompObject *parent,
- ObjectTypeCallBackProc proc,
- void *closure);
-
-const char *
-compObjectTypeName (CompObjectType type);
-
-char *
-compObjectName (CompObject *object);
-
-CompObject *
-compObjectFind (CompObject *parent,
- CompObjectType type,
- const char *name);
-
#define ARRAY_SIZE(array) \
(sizeof (array) / sizeof (array[0]))
@@ -71,8 +35,13 @@ compObjectFind (CompObject *parent,
class PrivateObject;
class CompObject {
+
public:
- CompObject (CompObjectType type, const char* typeName);
+ typedef std::vector<bool> indices;
+
+ public:
+ CompObject (CompObjectType type, const char* typeName,
+ indices *iList = NULL);
virtual ~CompObject ();
const char *typeName ();
@@ -87,7 +56,13 @@ class CompObject {
virtual CompString name () = 0;
public:
- CompPrivate *privates;
+
+ std::vector<CompPrivate> privates;
+
+ protected:
+ static int allocatePrivateIndex (CompObjectType type, indices *iList);
+ static void freePrivateIndex (CompObjectType type,
+ indices *iList, int idx);
private:
PrivateObject *priv;
diff --git a/include/compscreen.h b/include/compscreen.h
index 6cf0aba..30e5e6d 100644
--- a/include/compscreen.h
+++ b/include/compscreen.h
@@ -6,6 +6,9 @@
class CompScreen;
class PrivateScreen;
+#define GET_CORE_SCREEN(object) (dynamic_cast<CompScreen *> (object))
+#define CORE_SCREEN(object) CompScreen *s = GET_CORE_SCREEN (object)
+
class ScreenInterface : public WrapableInterface<CompScreen> {
public:
ScreenInterface ();
@@ -400,6 +403,9 @@ class CompScreen : public WrapableHandler<ScreenInterface>, public CompObject {
CompCursorImage *&
cursorImages ();
+ static int allocPrivateIndex ();
+ static void freePrivateIndex (int index);
+
WRAPABLE_HND(void, preparePaint, int);
WRAPABLE_HND(void, donePaint);
WRAPABLE_HND(void, paint, CompOutput::ptrList &outputs, unsigned int);
diff --git a/include/compwindow.h b/include/compwindow.h
index 7ecdc6d..139f64e 100644
--- a/include/compwindow.h
+++ b/include/compwindow.h
@@ -7,6 +7,9 @@
class CompWindow;
class PrivateWindow;
+#define GET_CORE_WINDOW(object) (dynamic_cast<CompWindow *> (object))
+#define CORE_WINDOW(object) CompWindow *w = GET_CORE_WINDOW (object)
+
class WindowInterface : public WrapableInterface<CompWindow> {
public:
WindowInterface ();
@@ -451,6 +454,9 @@ class CompWindow : public WrapableHandler<WindowInterface>, public CompObject {
compareWindowActiveness (CompWindow *w1,
CompWindow *w2);
+ static int allocPrivateIndex ();
+ static void freePrivateIndex (int index);
+
WRAPABLE_HND(bool, paint, const WindowPaintAttrib *,
const CompTransform *, Region, unsigned int);
WRAPABLE_HND(bool, draw, const CompTransform *,
diff --git a/plugins/move.cpp b/plugins/move.cpp
index 5a7f9c5..3cafe88 100644
--- a/plugins/move.cpp
+++ b/plugins/move.cpp
@@ -85,6 +85,9 @@ struct _MoveKeys {
#define SNAP_OFF 100
static int displayPrivateIndex;
+static int screenPrivateIndex;
+static int windowPrivateIndex;
+
#define MOVE_DISPLAY_OPTION_INITIATE_BUTTON 0
#define MOVE_DISPLAY_OPTION_INITIATE_KEY 1
@@ -106,10 +109,7 @@ class MoveDisplay : public DisplayInterface {
void
handleEvent (XEvent *);
-
CompDisplay *display;
- int screenPrivateIndex;
-
CompOption opt[MOVE_DISPLAY_OPTION_NUM];
@@ -134,8 +134,6 @@ class MoveScreen {
MoveScreen (CompScreen *screen) : screen (screen) {};
- int windowPrivateIndex;
-
CompScreen *screen;
CompScreen::grabHandle grab;
@@ -163,22 +161,22 @@ class MoveWindow : public WindowInterface {
};
#define GET_MOVE_DISPLAY(d) \
- ((MoveDisplay *) (d)->privates[displayPrivateIndex].ptr)
+ static_cast<MoveDisplay *> ((d)->privates[displayPrivateIndex].ptr)
#define MOVE_DISPLAY(d) \
MoveDisplay *md = GET_MOVE_DISPLAY (d)
-#define GET_MOVE_SCREEN(s, md) \
- ((MoveScreen *) (s)->privates[(md)->screenPrivateIndex].ptr)
+#define GET_MOVE_SCREEN(s) \
+ static_cast<MoveScreen *> ((s)->privates[screenPrivateIndex].ptr)
#define MOVE_SCREEN(s) \
- MoveScreen *ms = GET_MOVE_SCREEN (s, GET_MOVE_DISPLAY (s->display ()))
+ MoveScreen *ms = GET_MOVE_SCREEN (s)
-#define GET_MOVE_WINDOW(w, ms) \
- ((MoveWindow *) (w)->privates[(ms)->windowPrivateIndex].ptr)
+#define GET_MOVE_WINDOW(w) \
+ static_cast<MoveWindow *> ((w)->privates[windowPrivateIndex].ptr)
#define MOVE_WINDOW(w) \
- MoveWindow *mw = GET_MOVE_WINDOW (w, GET_MOVE_SCREEN (w->screen (), GET_MOVE_DISPLAY (w->screen ()->display())))
+ MoveWindow *mw = GET_MOVE_WINDOW (w)
#define NUM_OPTIONS(s) (sizeof ((s)->opt) / sizeof (CompOption))
@@ -639,6 +637,7 @@ MoveDisplay::handleEvent (XEvent *event)
case ButtonPress:
case ButtonRelease:
s = display->findScreen (event->xbutton.root);
+
if (s)
{
MOVE_SCREEN (s);
@@ -903,14 +902,6 @@ moveInitDisplay (CompObject *o)
return false;
}
- md->screenPrivateIndex = allocateScreenPrivateIndex (d);
- if (md->screenPrivateIndex < 0)
- {
- compFiniDisplayOptions (d, md->opt, MOVE_DISPLAY_OPTION_NUM);
- delete md;
- return false;
- }
-
md->moveOpacity =
(md->opt[MOVE_DISPLAY_OPTION_OPACITY].value.i * OPAQUE) / 100;
@@ -935,8 +926,6 @@ moveFiniDisplay (CompObject *o)
CORE_DISPLAY (o);
MOVE_DISPLAY (d);
- freeScreenPrivateIndex (d, md->screenPrivateIndex);
-
compFiniDisplayOptions (d, md->opt, MOVE_DISPLAY_OPTION_NUM);
delete md;
@@ -954,18 +943,11 @@ moveInitScreen (CompObject *o)
if (!ms)
return false;
- ms->windowPrivateIndex = allocateWindowPrivateIndex (s);
- if (ms->windowPrivateIndex < 0)
- {
- delete ms;
- return false;
- }
-
ms->grab = NULL;
ms->moveCursor = XCreateFontCursor (s->display ()->dpy (), XC_fleur);
- s->privates[md->screenPrivateIndex].ptr = ms;
+ s->privates[screenPrivateIndex].ptr = ms;
return true;
}
@@ -976,8 +958,6 @@ moveFiniScreen (CompObject *o)
CORE_SCREEN (o);
MOVE_SCREEN (s);
- freeWindowPrivateIndex (s, ms->windowPrivateIndex);
-
if (ms->moveCursor)
XFreeCursor (s->display ()->dpy (), ms->moveCursor);
@@ -996,7 +976,7 @@ moveInitWindow (CompObject *o)
if (!mw)
return false;
- w->privates[ms->windowPrivateIndex].ptr = mw;
+ w->privates[windowPrivateIndex].ptr = mw;
return true;
}
@@ -1073,12 +1053,27 @@ MovePluginVTable::init ()
0, 0))
return false;
- displayPrivateIndex = allocateDisplayPrivateIndex ();
+ displayPrivateIndex = CompDisplay::allocPrivateIndex ();
if (displayPrivateIndex < 0)
{
compFiniMetadata (&moveMetadata);
return false;
}
+ screenPrivateIndex = CompScreen::allocPrivateIndex ();
+ if (screenPrivateIndex < 0)
+ {
+ CompDisplay::freePrivateIndex (displayPrivateIndex);
+ compFiniMetadata (&moveMetadata);
+ return false;
+ }
+ windowPrivateIndex = CompWindow::allocPrivateIndex ();
+ if (windowPrivateIndex < 0)
+ {
+ CompDisplay::freePrivateIndex (displayPrivateIndex);
+ CompScreen::freePrivateIndex (screenPrivateIndex);
+ compFiniMetadata (&moveMetadata);
+ return false;
+ }
compAddMetadataFromFile (&moveMetadata, name ());
@@ -1088,7 +1083,10 @@ MovePluginVTable::init ()
void
MovePluginVTable::fini ()
{
- freeDisplayPrivateIndex (displayPrivateIndex);
+ CompDisplay::freePrivateIndex (displayPrivateIndex);
+ CompScreen::freePrivateIndex (screenPrivateIndex);
+ CompWindow::freePrivateIndex (windowPrivateIndex);
+
compFiniMetadata (&moveMetadata);
}
diff --git a/src/Makefile.am b/src/Makefile.am
index 8f687e9..6925765 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -13,7 +13,6 @@ compiz_LDADD = @COMPIZ_LIBS@ @GL_LIBS@ -lm
compiz_LDFLAGS = -export-dynamic
compiz_SOURCES = \
main.cpp \
- privates.cpp \
object.cpp \
core.cpp \
display.cpp \
diff --git a/src/core.cpp b/src/core.cpp
index 7743aa6..bf03ab9 100644
--- a/src/core.cpp
+++ b/src/core.cpp
@@ -32,74 +32,22 @@
CompCore *core;
-static char *corePrivateIndices = 0;
-static int corePrivateLen = 0;
-
-static int
-reallocCorePrivate (int size,
- void *closure)
-{
- void *privates;
-
- privates = realloc (core->privates, size * sizeof (CompPrivate));
- if (!privates)
- return FALSE;
-
- core->privates = (CompPrivate *) privates;
-
- return TRUE;
-}
+CompObject::indices corePrivateIndices (0);
int
-allocCoreObjectPrivateIndex (CompObject *parent)
+CompCore::allocPrivateIndex ()
{
- return allocatePrivateIndex (&corePrivateLen,
- &corePrivateIndices,
- reallocCorePrivate,
- 0);
+ return CompObject::allocatePrivateIndex (COMP_OBJECT_TYPE_CORE,
+ &corePrivateIndices);
}
void
-freeCoreObjectPrivateIndex (CompObject *parent,
- int index)
+CompCore::freePrivateIndex (int index)
{
- freePrivateIndex (corePrivateLen, corePrivateIndices, index);
+ CompObject::freePrivateIndex (COMP_OBJECT_TYPE_CORE,
+ &corePrivateIndices, index);
}
-CompBool
-forEachCoreObject (CompObject *parent,
- ObjectCallBackProc proc,
- void *closure)
-{
- return TRUE;
-}
-
-char *
-nameCoreObject (CompObject *object)
-{
- return NULL;
-}
-
-CompObject *
-findCoreObject (CompObject *parent,
- const char *name)
-{
- return NULL;
-}
-
-int
-allocateCorePrivateIndex (void)
-{
- return compObjectAllocatePrivateIndex (NULL, COMP_OBJECT_TYPE_CORE);
-}
-
-void
-freeCorePrivateIndex (int index)
-{
- compObjectFreePrivateIndex (NULL, COMP_OBJECT_TYPE_CORE, index);
-}
-
-
#define TIMEVALDIFF(tv1, tv2) \
((tv1)->tv_sec == (tv2)->tv_sec || (tv1)->tv_usec >= (tv2)->tv_usec) ? \
((((tv1)->tv_sec - (tv2)->tv_sec) * 1000000) + \
@@ -112,8 +60,6 @@ CompCore::CompCore () :
{
priv = new PrivateCore (this);
assert (priv);
-
- compObjectInit (this, 0, COMP_OBJECT_TYPE_CORE);
}
bool
diff --git a/src/display.cpp b/src/display.cpp
index 2305c5e..7495b54 100644
--- a/src/display.cpp
+++ b/src/display.cpp
@@ -76,54 +76,21 @@ typedef struct {
#define NUM_OPTIONS(d) (sizeof ((d)->priv->opt) / sizeof (CompOption))
-static char *displayPrivateIndices = 0;
-static int displayPrivateLen = 0;
-static int
-reallocDisplayPrivate (int size,
- void *closure)
-{
- CompDisplay *d;
- void *privates;
-
- for (d = core->displays(); d; d = d->next)
- {
- privates = realloc (d->privates, size * sizeof (CompPrivate));
- if (!privates)
- return FALSE;
-
- d->privates = (CompPrivate *) privates;
- }
-
- return TRUE;
-}
+CompObject::indices displayPrivateIndices (0);
int
-allocDisplayObjectPrivateIndex (CompObject *parent)
+CompDisplay::allocPrivateIndex ()
{
- return allocatePrivateIndex (&displayPrivateLen,
- &displayPrivateIndices,
- reallocDisplayPrivate,
- 0);
+ return CompObject::allocatePrivateIndex (COMP_OBJECT_TYPE_DISPLAY,
+ &displayPrivateIndices);
}
void
-freeDisplayObjectPrivateIndex (CompObject *parent,
- int index)
+CompDisplay::freePrivateIndex (int index)
{
- freePrivateIndex (displayPrivateLen, displayPrivateIndices, index);
-}
-
-int
-allocateDisplayPrivateIndex (void)
-{
- return compObjectAllocatePrivateIndex (NULL, COMP_OBJECT_TYPE_DISPLAY);
-}
-
-void
-freeDisplayPrivateIndex (int index)
-{
- compObjectFreePrivateIndex (NULL, COMP_OBJECT_TYPE_DISPLAY, index);
+ CompObject::freePrivateIndex (COMP_OBJECT_TYPE_DISPLAY,
+ &displayPrivateIndices, index);
}
bool
@@ -794,10 +761,8 @@ setDisplayAction (CompDisplay *display,
}
CompDisplay::CompDisplay () :
- CompObject (COMP_OBJECT_TYPE_DISPLAY, "display"),
- next (0),
- screenPrivateIndices (0),
- screenPrivateLen (0)
+ CompObject (COMP_OBJECT_TYPE_DISPLAY, "display", &displayPrivateIndices),
+ next (0)
{
WRAPABLE_INIT_HND(handleEvent);
WRAPABLE_INIT_HND(handleCompizEvent);
@@ -839,19 +804,12 @@ CompDisplay::~CompDisplay ()
if (priv->modMap)
XFreeModifiermap (priv->modMap);
- if (screenPrivateIndices)
- free (screenPrivateIndices);
-
- if (privates)
- free (privates);
-
delete priv;
}
bool
CompDisplay::init (const char *name)
{
- CompPrivate *privates;
Window focus;
int revertTo, i;
int compositeMajor, compositeMinor;
@@ -859,20 +817,6 @@ CompDisplay::init (const char *name)
int xkbOpcode;
int firstScreen, lastScreen;
- if (displayPrivateLen)
- {
- privates =
- (CompPrivate *) malloc (displayPrivateLen * sizeof (CompPrivate));
- if (!privates)
- {
- return false;
- }
- }
- else
- privates = 0;
-
- compObjectInit (this, privates, COMP_OBJECT_TYPE_DISPLAY);
-
mTmpRegion = XCreateRegion ();
if (!mTmpRegion)
return false;
@@ -1023,11 +967,11 @@ CompDisplay::init (const char *name)
priv->returnKeyCode =
XKeysymToKeycode (priv->dpy, XStringToKeysym ("Return"));
+ core->addChild (this);
+
/* TODO: bailout properly when objectInitPlugins fails */
assert (objectInitPlugins (this));
- core->addChild (this);
-
if (onlyCurrentScreen)
{
firstScreen = DefaultScreen (priv->dpy);
diff --git a/src/object.cpp b/src/object.cpp
index 7db8f37..64b4d49 100644
--- a/src/object.cpp
+++ b/src/object.cpp
@@ -28,89 +28,6 @@
#include <compiz-core.h>
#include "privateobject.h"
-typedef CompBool (*AllocObjectPrivateIndexProc) (CompObject *parent);
-
-typedef void (*FreeObjectPrivateIndexProc) (CompObject *parent,
- int index);
-
-typedef CompBool (*ForEachObjectProc) (CompObject *parent,
- ObjectCallBackProc proc,
- void *closure);
-
-typedef char *(*NameObjectProc) (CompObject *object);
-
-typedef CompObject *(*FindObjectProc) (CompObject *parent,
- const char *name);
-
-struct _CompObjectInfo {
- const char *name;
- AllocObjectPrivateIndexProc allocPrivateIndex;
- FreeObjectPrivateIndexProc freePrivateIndex;
-} objectInfo[] = {
- {
- "core",
- allocCoreObjectPrivateIndex,
- freeCoreObjectPrivateIndex
- }, {
- "display",
- allocDisplayObjectPrivateIndex,
- freeDisplayObjectPrivateIndex
- }, {
- "screen",
- allocScreenObjectPrivateIndex,
- freeScreenObjectPrivateIndex
- }, {
- "window",
- allocWindowObjectPrivateIndex,
- freeWindowObjectPrivateIndex
- }
-};
-
-void
-compObjectInit (CompObject *object,
- CompPrivate *privates,
- CompObjectType type)
-{
- object->privates = privates;
-}
-
-int
-compObjectAllocatePrivateIndex (CompObject *parent,
- CompObjectType type)
-{
- return (*objectInfo[type].allocPrivateIndex) (parent);
-}
-
-void
-compObjectFreePrivateIndex (CompObject *parent,
- CompObjectType type,
- int index)
-{
- (*objectInfo[type].freePrivateIndex) (parent, index);
-}
-
-
-const char *
-compObjectTypeName (CompObjectType type)
-{
- return objectInfo[type].name;
-}
-
-CompBool
-compObjectForEachType (CompObject *parent,
- ObjectTypeCallBackProc proc,
- void *closure)
-{
- int i;
-
- for (i = 0; i < sizeof (objectInfo) / sizeof (objectInfo[0]); i++)
- if (!(*proc) (i, parent, closure))
- return FALSE;
-
- return TRUE;
-}
-
-
PrivateObject::PrivateObject () :
typeName (0),
parent (NULL),
@@ -119,7 +36,8 @@ PrivateObject::PrivateObject () :
}
-CompObject::CompObject (CompObjectType type, const char* typeName) :
+CompObject::CompObject (CompObjectType type, const char* typeName,
+ CompObject::indices *iList) :
privates (0)
{
priv = new PrivateObject ();
@@ -127,6 +45,9 @@ CompObject::CompObject (CompObjectType type, const char* typeName) :
priv->type = type;
priv->typeName = typeName;
+
+ if (iList && iList->size() > 0)
+ privates.resize (iList->size ());
}
CompObject::~CompObject ()
@@ -195,3 +116,75 @@ CompObject::forEachChild (ObjectCallBackProc proc,
return rv;
}
+typedef struct _ResizeInfo {
+ CompObjectType type;
+ unsigned int size;
+} ResizeInfo;
+
+static bool
+resizePrivates (CompObject *o, void * closure)
+{
+ ResizeInfo *info = static_cast<ResizeInfo *> (closure);
+
+ if (o->type () == info->type)
+ {
+ o->privates.resize (info->size);
+ }
+ o->forEachChild (resizePrivates, info);
+
+ return true;
+}
+
+int
+CompObject::allocatePrivateIndex (CompObjectType type,
+ CompObject::indices *iList)
+{
+ if (!iList)
+ return -1;
+
+ for (unsigned int i = 0; i < iList->size(); i++)
+ {
+ if (!iList->at (i))
+ {
+ iList->at (i) = true;
+ return i;
+ }
+ }
+ unsigned int i = iList->size ();
+ iList->resize (i + 1);
+ iList->at (i) = true;
+
+ ResizeInfo info;
+ info.type = type;
+ info.size = i + 1;
+
+
+ resizePrivates (core, static_cast<void *> (&info));
+
+ return i;
+}
+
+void
+CompObject::freePrivateIndex (CompObjectType type,
+ CompObject::indices *iList,
+ int idx)
+{
+ if (!iList || idx < 0 || idx >= (int) iList->size())
+ return;
+
+ if (idx < (int) iList->size () - 1)
+ {
+ iList->at(idx) = false;
+ return;
+ }
+
+ unsigned int i = iList->size () - 1;
+ iList->resize (i);
+
+ ResizeInfo info;
+ info.type = type;
+ info.size = i;
+
+ resizePrivates (core, static_cast<void *> (&info));
+}
+
diff --git a/src/plugin.cpp b/src/plugin.cpp
index 8762ad8..93c35fa 100644
--- a/src/plugin.cpp
+++ b/src/plugin.cpp
@@ -315,11 +315,6 @@ typedef struct _InitObjectContext {
CompObject *object;
} InitObjectContext;
-typedef struct _InitObjectTypeContext {
- CompPlugin *plugin;
- CompObjectType type;
-} InitObjectTypeContext;
-
static bool
initObjectTree (CompObject *object,
void *closure);
@@ -329,55 +324,12 @@ finiObjectTree (CompObject *object,
void *closure);
static bool
-initObjectsWithType (CompObjectType type,
- CompObject *parent,
- void *closure)
-{
- InitObjectTypeContext *pCtx = (InitObjectTypeContext *) closure;
- InitObjectContext ctx;
-
- pCtx->type = type;
-
- ctx.plugin = pCtx->plugin;
- ctx.object = NULL;
-
- if (!parent->forEachChild (initObjectTree, (void *) &ctx, type))
- {
- parent->forEachChild (finiObjectTree, (void *) &ctx, type);
-
- return FALSE;
- }
-
- return TRUE;
-}
-
-static bool
-finiObjectsWithType (CompObjectType type,
- CompObject *parent,
- void *closure)
-{
- InitObjectTypeContext *pCtx = (InitObjectTypeContext *) closure;
- InitObjectContext ctx;
-
- /* pCtx->type is set to the object type that failed to be initialized */
- if (pCtx->type == type)
- return FALSE;
-
- ctx.plugin = pCtx->plugin;
- ctx.object = NULL;
-
- parent->forEachChild (finiObjectTree, (void *) &ctx, type);
-
- return TRUE;
-}
-
-static bool
initObjectTree (CompObject *object,
void *closure)
{
InitObjectContext *pCtx = (InitObjectContext *) closure;
CompPlugin *p = pCtx->plugin;
- InitObjectTypeContext ctx;
+ InitObjectContext ctx;
pCtx->object = object;
@@ -386,32 +338,28 @@ initObjectTree (CompObject *object,
{
compLogMessage (NULL, p->vTable->name (), CompLogLevelError,
"InitObject failed");
- return FALSE;
+ return false;
}
- ctx.plugin = p;
- ctx.type = 0;
+ ctx.plugin = pCtx->plugin;
+ ctx.object = NULL;
- /* initialize children */
- if (!compObjectForEachType (object, initObjectsWithType, (void *) &ctx))
+ if (!object->forEachChild (initObjectTree, static_cast<void *> (&ctx)))
{
- compObjectForEachType (object, finiObjectsWithType, (void *) &ctx);
-
- p->vTable->finiObject (object);
+ object->forEachChild (finiObjectTree, static_cast<void *> (&ctx));
- return FALSE;
+ return false;
}
if (!core->initPluginForObject (p, object))
{
- compObjectForEachType (object, finiObjectsWithType, (void *) &ctx);
-
+ object->forEachChild (finiObjectTree, static_cast<void *> (&ctx));
p->vTable->finiObject (object);
- return FALSE;
+ return false;
}
- return TRUE;
+ return true;
}
static bool
@@ -420,26 +368,25 @@ finiObjectTree (CompObject *object,
{
InitObjectContext *pCtx = (InitObjectContext *) closure;
CompPlugin *p = pCtx->plugin;
- InitObjectTypeContext ctx;
+ InitObjectContext ctx;
/* pCtx->object is set to the object that failed to be initialized */
if (pCtx->object == object)
- return FALSE;
+ return false;
ctx.plugin = p;
- ctx.type = ~0;
+ ctx.object = NULL;
- compObjectForEachType (object, finiObjectsWithType, (void *) &ctx);
+ object->forEachChild (finiObjectTree, static_cast<void *> (&ctx));
-
p->vTable->finiObject (object);
core->finiPluginForObject (p, object);
- return TRUE;
+ return true;
}
-static Bool
+static bool
initPlugin (CompPlugin *p)
{
InitObjectContext ctx;
@@ -448,19 +395,19 @@ initPlugin (CompPlugin *p)
{
compLogMessage (NULL, "core", CompLogLevelError,
"InitPlugin '%s' failed", p->vTable->name ());
- return FALSE;
+ return false;
}
ctx.plugin = p;
ctx.object = NULL;
- if (!initObjectTree (core, (void *) &ctx))
+ if (!initObjectTree (core, static_cast<void *> (&ctx)))
{
p->vTable->fini ();
- return FALSE;
+ return false;
}
- return TRUE;
+ return true;
}
static void
@@ -476,7 +423,7 @@ finiPlugin (CompPlugin *p)
p->vTable->fini ();
}
-CompBool
+bool
objectInitPlugins (CompObject *o)
{
InitObjectContext ctx;
@@ -505,11 +452,11 @@ objectInitPlugins (CompObject *o)
finiObjectTree (o, (void *) &ctx);
}
- return FALSE;
+ return false;
}
}
- return TRUE;
+ return true;
}
void
diff --git a/src/privates.cpp b/src/privates.cpp
deleted file mode 100644
index 56baa4b..0000000
--- a/src/privates.cpp
+++ /dev/null
@@ -1,68 +0,0 @@
-/*
- * Copyright © 2005 Novell, Inc.
- *
- * Permission to use, copy, modify, distribute, and sell this software
- * and its documentation for any purpose is hereby granted without
- * fee, provided that the above copyright notice appear in all copies
- * and that both that copyright notice and this permission notice
- * appear in supporting documentation, and that the name of
- * Novell, Inc. not be used in advertising or publicity pertaining to
- * distribution of the software without specific, written prior permission.
- * Novell, Inc. makes no representations about the suitability of this
- * software for any purpose. It is provided "as is" without express or
- * implied warranty.
- *
- * NOVELL, INC. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
- * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN
- * NO EVENT SHALL NOVELL, INC. BE LIABLE FOR ANY SPECIAL, INDIRECT OR
- * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
- * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
- * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
- * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- *
- * Author: David Reveman <davidr@novell.com>
- */
-
-#include <stdlib.h>
-
-#include <compiz-core.h>
-
-int
-allocatePrivateIndex (int *len,
- char **indices,
- ReallocPrivatesProc reallocProc,
- void *closure)
-{
- char *newIndices;
- int i;
-
- for (i = 0; i < *len; i++)
- {
- if (!(*indices)[i])
- {
- (*indices)[i] = 1;
- return i;
- }
- }
-
- newIndices = (char *) realloc (*indices, (*len + 1) * sizeof (char));
- if (!newIndices)
- return -1;
-
- newIndices[*len] = 1;
- *indices = newIndices;
-
- if (!(*reallocProc) (*len + 1, closure))
- return -1;
-
- return (*len)++;
-}
-
-void
-freePrivateIndex (int len,
- char *indices,
- int index)
-{
- if (index < len)
- indices[index] = 0;
-}
diff --git a/src/screen.cpp b/src/screen.cpp
index edee063..80c61e4 100644
--- a/src/screen.cpp
+++ b/src/screen.cpp
@@ -53,59 +53,20 @@
#define NUM_OPTIONS(s) (sizeof ((s)->priv->opt) / sizeof (CompOption))
-static int
-reallocScreenPrivate (int size,
- void *closure)
-{
- CompDisplay *d = (CompDisplay *) closure;
- CompScreen *s;
- void *privates;
-
- for (s = d->screens(); s; s = s->next)
- {
- privates = realloc (s->privates, size * sizeof (CompPrivate));
- if (!privates)
- return FALSE;
-
- s->privates = (CompPrivate *) privates;
- }
-
- return TRUE;
-}
-
-int
-allocScreenObjectPrivateIndex (CompObject *parent)
-{
- CompDisplay *display = (CompDisplay *) parent;
-
- return allocatePrivateIndex (&display->screenPrivateLen,
- &display->screenPrivateIndices,
- reallocScreenPrivate,
- (void *) display);
-}
-
-void
-freeScreenObjectPrivateIndex (CompObject *parent,
- int index)
-{
- CompDisplay *display = (CompDisplay *) parent;
-
- freePrivateIndex (display->screenPrivateLen,
- display->screenPrivateIndices,
- index);
-}
+CompObject::indices screenPrivateIndices (0);
int
-allocateScreenPrivateIndex (CompDisplay *display)
+CompScreen::allocPrivateIndex ()
{
- return compObjectAllocatePrivateIndex (display, COMP_OBJECT_TYPE_SCREEN);
+ return CompObject::allocatePrivateIndex (COMP_OBJECT_TYPE_SCREEN,
+ &screenPrivateIndices);
}
void
-freeScreenPrivateIndex (CompDisplay *display,
- int index)
+CompScreen::freePrivateIndex (int index)
{
- compObjectFreePrivateIndex (display, COMP_OBJECT_TYPE_SCREEN, index);
+ CompObject::freePrivateIndex (COMP_OBJECT_TYPE_SCREEN,
+ &screenPrivateIndices, index);
}
@@ -1440,7 +1401,7 @@ CompScreen::initWindowWalker (CompWalker *walker)
}
CompScreen::CompScreen ():
- CompObject (COMP_OBJECT_TYPE_SCREEN, "screen")
+ CompObject (COMP_OBJECT_TYPE_SCREEN, "screen", &screenPrivateIndices)
{
WRAPABLE_INIT_HND(preparePaint);
WRAPABLE_INIT_HND(donePaint);
@@ -1731,7 +1692,6 @@ CompScreen::init (CompDisplay *display,
Atom wmSnAtom,
Time wmSnTimestamp)
{
- CompPrivate *privates;
Display *dpy = display->dpy ();
static char data = 0;
XColor black;
@@ -1751,20 +1711,6 @@ CompScreen::init (CompDisplay *display,
GLfloat light0Position[] = { -0.5f, 0.5f, -9.0f, 1.0f };
CompWindow *w;
- if (display->screenPrivateLen)
- {
- privates = (CompPrivate *)
- malloc (display->screenPrivateLen * sizeof (CompPrivate));
- if (!privates)
- {
- return false;
- }
- }
- else
- privates = 0;
-
- compObjectInit (this, privates, COMP_OBJECT_TYPE_SCREEN);
-
priv->display = display;
if (!compInitScreenOptionsFromMetadata (this,
@@ -2276,10 +2222,12 @@ CompScreen::init (CompDisplay *display,
priv->getDesktopHints ();
+ display->addChild (this);
+
/* TODO: bailout properly when objectInitPlugins fails */
assert (objectInitPlugins (this));
- display->addChild (this);
+
XQueryTree (dpy, priv->root,
&rootReturn, &parentReturn,
@@ -2404,12 +2352,6 @@ CompScreen::~CompScreen ()
compFiniScreenOptions (this, priv->opt, COMP_SCREEN_OPTION_NUM);
- if (windowPrivateIndices)
- free (windowPrivateIndices);
-
- if (privates)
- free (privates);
-
delete priv;
}
@@ -2727,7 +2669,7 @@ CompScreen::removeGrab (CompScreen::grabHandle handle,
if (it != priv->grabs.end ())
{
priv->grabs.erase (it);
- delete handle;
+ delete (static_cast<PrivateScreen::Grab *> (handle));
}
if (!priv->grabs.empty ())
{
diff --git a/src/window.cpp b/src/window.cpp
index 854e08f..75b81fc 100644
--- a/src/window.cpp
+++ b/src/window.cpp
@@ -41,63 +41,20 @@
#include "privatewindow.h"
-
-
-
-
-static int
-reallocWindowPrivates (int size,
- void *closure)
-{
- CompScreen *s = (CompScreen *) closure;
- CompWindow *w;
- void *privates;
-
- for (w = s->windows (); w; w = w->next)
- {
- privates = realloc (w->privates, size * sizeof (CompPrivate));
- if (!privates)
- return FALSE;
-
- w->privates = (CompPrivate *) privates;
- }
-
- return TRUE;
-}
-
-int
-allocWindowObjectPrivateIndex (CompObject *parent)
-{
- CompScreen *screen = (CompScreen *) parent;
-
- return allocatePrivateIndex (&screen->windowPrivateLen,
- &screen->windowPrivateIndices,
- reallocWindowPrivates,
- (void *) screen);
-}
-
-void
-freeWindowObjectPrivateIndex (CompObject *parent,
- int index)
-{
- CompScreen *screen = (CompScreen *) parent;
-
- freePrivateIndex (screen->windowPrivateLen,
- screen->windowPrivateIndices,
- index);
-}
+CompObject::indices windowPrivateIndices (0);
int
-allocateWindowPrivateIndex (CompScreen *screen)
+CompWindow::allocPrivateIndex ()
{
- return compObjectAllocatePrivateIndex (screen, COMP_OBJECT_TYPE_WINDOW);
+ return CompObject::allocatePrivateIndex (COMP_OBJECT_TYPE_WINDOW,
+ &windowPrivateIndices);
}
void
-freeWindowPrivateIndex (CompScreen *screen,
- int index)
+CompWindow::freePrivateIndex (int index)
{
- compObjectFreePrivateIndex (screen, COMP_OBJECT_TYPE_WINDOW, index);
+ CompObject::freePrivateIndex (COMP_OBJECT_TYPE_WINDOW,
+ &windowPrivateIndices, index);
}
bool
@@ -4943,7 +4900,7 @@ CompWindow::paintAttrib ()
CompWindow::CompWindow (CompScreen *screen,
Window id,
Window aboveId) :
- CompObject (COMP_OBJECT_TYPE_WINDOW, "window")
+ CompObject (COMP_OBJECT_TYPE_WINDOW, "window", &windowPrivateIndices)
{
WRAPABLE_INIT_HND(paint);
WRAPABLE_INIT_HND(draw);
@@ -4972,19 +4929,8 @@ CompWindow::CompWindow (CompScreen *screen,
priv->screen = screen;
- CompPrivate *privates;
CompDisplay *d = screen->display ();
- if (screen->windowPrivateLen)
- {
- privates = (CompPrivate *) malloc (screen->windowPrivateLen * sizeof (CompPrivate));
- assert (privates);
- }
- else
- privates = 0;
-
- compObjectInit (this, privates, COMP_OBJECT_TYPE_WINDOW);
-
priv->region = XCreateRegion ();
assert (priv->region);
@@ -5189,10 +5135,11 @@ CompWindow::CompWindow (CompScreen *screen,
}
}
+ screen->addChild (this);
+
/* TODO: bailout properly when objectInitPlugins fails */
assert (objectInitPlugins (this));
- core->objectAdd (screen, this);
recalcActions ();
updateIconGeometry ();
@@ -5267,9 +5214,6 @@ CompWindow::~CompWindow ()
release ();
- if (privates)
- free (privates);
-
delete priv;
}