diff options
author | Dennis Kasprzyk <onestone@opencompositing.org> | 2008-08-08 00:54:13 +0200 |
---|---|---|
committer | Dennis kasprzyk <onestone@opencompositing.org> | 2008-08-08 00:54:13 +0200 |
commit | 51a6ee41ec7299191381de897f36d983ba12bdcc (patch) | |
tree | 9980ae2c91ef5d6fff90545da14c935d650c7c2e | |
parent | 860cc8ec6898fc33eda3aabb59eed7443a536e05 (diff) | |
download | compiz-with-glib-mainloop-51a6ee41ec7299191381de897f36d983ba12bdcc.tar.gz compiz-with-glib-mainloop-51a6ee41ec7299191381de897f36d983ba12bdcc.tar.bz2 |
Make CompObject smarter.
-rw-r--r-- | include/compcore.h | 2 | ||||
-rw-r--r-- | include/compdisplay.h | 2 | ||||
-rw-r--r-- | include/compiz-core.h | 91 | ||||
-rw-r--r-- | include/compobject.h | 92 | ||||
-rw-r--r-- | include/compscreen.h | 2 | ||||
-rw-r--r-- | include/compwindow.h | 2 | ||||
-rw-r--r-- | src/core.cpp | 17 | ||||
-rw-r--r-- | src/display.cpp | 49 | ||||
-rw-r--r-- | src/object.cpp | 128 | ||||
-rw-r--r-- | src/plugin.cpp | 19 | ||||
-rw-r--r-- | src/privateobject.h | 21 | ||||
-rw-r--r-- | src/screen.cpp | 71 | ||||
-rw-r--r-- | src/window.cpp | 65 |
13 files changed, 262 insertions, 299 deletions
diff --git a/include/compcore.h b/include/compcore.h index 123d7f4..4324ef4 100644 --- a/include/compcore.h +++ b/include/compcore.h @@ -94,6 +94,8 @@ class CompCore : public WrapableHandler<CoreInterface>, public CompObject { CompCore (); ~CompCore (); + CompString name (); + bool init (); diff --git a/include/compdisplay.h b/include/compdisplay.h index 18058a5..564d9f2 100644 --- a/include/compdisplay.h +++ b/include/compdisplay.h @@ -170,6 +170,8 @@ class CompDisplay : public WrapableHandler<DisplayInterface>, public CompObject CompDisplay (); ~CompDisplay (); + CompString name (); + bool init (const char *name); diff --git a/include/compiz-core.h b/include/compiz-core.h index 5a62e21..dd0068c 100644 --- a/include/compiz-core.h +++ b/include/compiz-core.h @@ -32,6 +32,7 @@ #include <stdio.h> #include <sys/time.h> +#include <assert.h> #include <X11/Xlib-xcb.h> #include <X11/Xutil.h> @@ -278,77 +279,6 @@ freePrivateIndex (int len, int index); -/* object.c */ - -typedef unsigned int CompObjectType; - -#define COMP_OBJECT_TYPE_CORE 0 -#define COMP_OBJECT_TYPE_DISPLAY 1 -#define COMP_OBJECT_TYPE_SCREEN 2 -#define COMP_OBJECT_TYPE_WINDOW 3 - - -typedef CompBool (*ObjectCallBackProc) (CompObject *object, - void *closure); - -typedef CompBool (*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 -compObjectForEach (CompObject *parent, - CompObjectType type, - ObjectCallBackProc proc, - void *closure); - -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])) - -#define DISPATCH_CHECK(object, dispTab, tabSize) \ - ((object)->type < (tabSize) && (dispTab)[(object)->type]) - -#define DISPATCH(object, dispTab, tabSize, args) \ - if (DISPATCH_CHECK (object, dispTab, tabSize)) \ - (*(dispTab)[(object)->type]) args - -#define RETURN_DISPATCH(object, dispTab, tabSize, def, args) \ - if (DISPATCH_CHECK (object, dispTab, tabSize)) \ - return (*(dispTab)[(object)->type]) args; \ - else \ - return (def) /* session.c */ @@ -733,11 +663,6 @@ void freeDisplayObjectPrivateIndex (CompObject *parent, int index); -CompBool -forEachDisplayObject (CompObject *parent, - ObjectCallBackProc proc, - void *closure); - char * nameDisplayObject (CompObject *object); @@ -1338,18 +1263,9 @@ void freeScreenObjectPrivateIndex (CompObject *parent, int index); -CompBool -forEachScreenObject (CompObject *parent, - ObjectCallBackProc proc, - void *closure); - char * nameScreenObject (CompObject *object); -CompObject * -findScreenObject (CompObject *parent, - const char *name); - int allocateScreenPrivateIndex (CompDisplay *display); @@ -1404,11 +1320,6 @@ void freeWindowObjectPrivateIndex (CompObject *parent, int index); -CompBool -forEachWindowObject (CompObject *parent, - ObjectCallBackProc proc, - void *closure); - char * nameWindowObject (CompObject *object); diff --git a/include/compobject.h b/include/compobject.h index a95ced7..03aa85d 100644 --- a/include/compobject.h +++ b/include/compobject.h @@ -1,12 +1,96 @@ #ifndef _COMPOBJECT_H #define _COMPOBJECT_H + +typedef int CompObjectType; + + +#define COMP_OBJECT_TYPE_ALL -1 +#define COMP_OBJECT_TYPE_CORE 0 +#define COMP_OBJECT_TYPE_DISPLAY 1 +#define COMP_OBJECT_TYPE_SCREEN 2 +#define COMP_OBJECT_TYPE_WINDOW 3 + + +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])) + +#define DISPATCH_CHECK(object, dispTab, tabSize) \ + ((object)->type () < (tabSize) && (dispTab)[(object)->type ()]) + +#define DISPATCH(object, dispTab, tabSize, args) \ + if (DISPATCH_CHECK (object, dispTab, tabSize)) \ + (*(dispTab)[(object)->type ()]) args + +#define RETURN_DISPATCH(object, dispTab, tabSize, def, args) \ + if (DISPATCH_CHECK (object, dispTab, tabSize)) \ + return (*(dispTab)[(object)->type ()]) args; \ + else \ + return (def) + +class PrivateObject; + class CompObject { - public : + public: + CompObject (CompObjectType type, const char* typeName); + virtual ~CompObject (); + + const char *typeName (); + CompObjectType type (); + + void addChild (CompObject *); + + bool forEachChild (ObjectCallBackProc proc, + void *closure = NULL, + int type = -1); + + virtual CompString name () = 0; + + public: + CompPrivate *privates; - CompObjectType type; - CompPrivate *privates; - CompObject *parent; + private: + PrivateObject *priv; }; diff --git a/include/compscreen.h b/include/compscreen.h index 4429c51..6cf0aba 100644 --- a/include/compscreen.h +++ b/include/compscreen.h @@ -52,6 +52,8 @@ class CompScreen : public WrapableHandler<ScreenInterface>, public CompObject { CompScreen (); ~CompScreen (); + CompString name (); + bool init (CompDisplay *, int); diff --git a/include/compwindow.h b/include/compwindow.h index baad68a..7ecdc6d 100644 --- a/include/compwindow.h +++ b/include/compwindow.h @@ -72,6 +72,8 @@ class CompWindow : public WrapableHandler<WindowInterface>, public CompObject { Window aboveId); ~CompWindow (); + CompString name (); + CompScreen * screen (); diff --git a/src/core.cpp b/src/core.cpp index 9e88618..7743aa6 100644 --- a/src/core.cpp +++ b/src/core.cpp @@ -107,7 +107,8 @@ freeCorePrivateIndex (int index) ((((tv1)->tv_sec - 1 - (tv2)->tv_sec) * 1000000) + \ (1000000 + (tv1)->tv_usec - (tv2)->tv_usec)) / 1000 -CompCore::CompCore () +CompCore::CompCore () : + CompObject (COMP_OBJECT_TYPE_CORE, "core") { priv = new PrivateCore (this); assert (priv); @@ -160,6 +161,13 @@ CompCore::~CompCore () } +CompString +CompCore::name () +{ + return CompString (""); +} + + CompDisplay * CompCore::displays() { @@ -553,17 +561,12 @@ CompCore::setOptionForPlugin (CompObject *object, void CompCore::objectAdd (CompObject *parent, CompObject *object) -{ WRAPABLE_HND_FUNC(objectAdd, parent, object) - object->parent = parent; -} + void CompCore::objectRemove (CompObject *parent, CompObject *object) -{ WRAPABLE_HND_FUNC(objectRemove, parent, object) - object->parent = NULL; -} void CompCore::sessionEvent (CompSessionEvent event, diff --git a/src/display.cpp b/src/display.cpp index b78c0e9..2305c5e 100644 --- a/src/display.cpp +++ b/src/display.cpp @@ -114,44 +114,6 @@ freeDisplayObjectPrivateIndex (CompObject *parent, freePrivateIndex (displayPrivateLen, displayPrivateIndices, index); } -CompBool -forEachDisplayObject (CompObject *parent, - ObjectCallBackProc proc, - void *closure) -{ - if (parent->type == COMP_OBJECT_TYPE_CORE) - { - CompDisplay *d; - - for (d = core->displays(); d; d = d->next) - { - if (!(*proc) (d, closure)) - return FALSE; - } - } - - return TRUE; -} - -char * -nameDisplayObject (CompObject *object) -{ - return NULL; -} - -CompObject * -findDisplayObject (CompObject *parent, - const char *name) -{ - if (parent->type == COMP_OBJECT_TYPE_CORE) - { - if (!name || !name[0]) - return core->displays (); - } - - return NULL; -} - int allocateDisplayPrivateIndex (void) { @@ -832,6 +794,7 @@ setDisplayAction (CompDisplay *display, } CompDisplay::CompDisplay () : + CompObject (COMP_OBJECT_TYPE_DISPLAY, "display"), next (0), screenPrivateIndices (0), screenPrivateLen (0) @@ -855,8 +818,6 @@ CompDisplay::~CompDisplay () while (priv->screens) removeScreen (priv->screens); - core->objectRemove (core, this); - objectFiniPlugins (this); core->removeTimeout (priv->pingHandle); @@ -1065,7 +1026,7 @@ CompDisplay::init (const char *name) /* TODO: bailout properly when objectInitPlugins fails */ assert (objectInitPlugins (this)); - core->objectAdd (core, this); + core->addChild (this); if (onlyCurrentScreen) { @@ -1125,6 +1086,12 @@ CompDisplay::init (const char *name) return true; } +CompString +CompDisplay::name () +{ + return CompString (""); +} + CompDisplay::Atoms CompDisplay::atoms () { diff --git a/src/object.cpp b/src/object.cpp index e9717c6..7db8f37 100644 --- a/src/object.cpp +++ b/src/object.cpp @@ -23,7 +23,10 @@ * Author: David Reveman <davidr@novell.com> */ +#include <algorithm> + #include <compiz-core.h> +#include "privateobject.h" typedef CompBool (*AllocObjectPrivateIndexProc) (CompObject *parent); @@ -43,38 +46,23 @@ struct _CompObjectInfo { const char *name; AllocObjectPrivateIndexProc allocPrivateIndex; FreeObjectPrivateIndexProc freePrivateIndex; - ForEachObjectProc forEachObject; - NameObjectProc nameObject; - FindObjectProc findObject; } objectInfo[] = { { "core", allocCoreObjectPrivateIndex, - freeCoreObjectPrivateIndex, - forEachCoreObject, - nameCoreObject, - findCoreObject + freeCoreObjectPrivateIndex }, { "display", allocDisplayObjectPrivateIndex, - freeDisplayObjectPrivateIndex, - forEachDisplayObject, - nameDisplayObject, - findDisplayObject + freeDisplayObjectPrivateIndex }, { "screen", allocScreenObjectPrivateIndex, - freeScreenObjectPrivateIndex, - forEachScreenObject, - nameScreenObject, - findScreenObject + freeScreenObjectPrivateIndex }, { "window", allocWindowObjectPrivateIndex, - freeWindowObjectPrivateIndex, - forEachWindowObject, - nameWindowObject, - findWindowObject + freeWindowObjectPrivateIndex } }; @@ -83,9 +71,7 @@ compObjectInit (CompObject *object, CompPrivate *privates, CompObjectType type) { - object->type = type; object->privates = privates; - object->parent = NULL; } int @@ -103,19 +89,17 @@ compObjectFreePrivateIndex (CompObject *parent, (*objectInfo[type].freePrivateIndex) (parent, index); } -CompBool -compObjectForEach (CompObject *parent, - CompObjectType type, - ObjectCallBackProc proc, - void *closure) + +const char * +compObjectTypeName (CompObjectType type) { - return (*objectInfo[type].forEachObject) (parent, proc, closure); + return objectInfo[type].name; } CompBool -compObjectForEachType (CompObject *parent, +compObjectForEachType (CompObject *parent, ObjectTypeCallBackProc proc, - void *closure) + void *closure) { int i; @@ -126,22 +110,88 @@ compObjectForEachType (CompObject *parent, return TRUE; } + +PrivateObject::PrivateObject () : + typeName (0), + parent (NULL), + children (0) +{ +} + + +CompObject::CompObject (CompObjectType type, const char* typeName) : + privates (0) +{ + priv = new PrivateObject (); + assert (priv); + + priv->type = type; + priv->typeName = typeName; +} + +CompObject::~CompObject () +{ + std::list<CompObject *>::iterator it; + + while (!priv->children.empty ()) + { + CompObject *o = priv->children.front (); + priv->children.pop_front (); + o->priv->parent = NULL; + core->objectRemove (this, o); + delete o; + } + if (priv->parent) + { + it = std::find (priv->parent->priv->children.begin (), + priv->parent->priv->children.end (), + this); + + if (it != priv->parent->priv->children.end ()) + { + priv->parent->priv->children.erase (it); + core->objectRemove (priv->parent, this); + } + } +} + const char * -compObjectTypeName (CompObjectType type) +CompObject::typeName () { - return objectInfo[type].name; + return priv->typeName; +} + +CompObjectType +CompObject::type () +{ + return priv->type; } -char * -compObjectName (CompObject *object) +void +CompObject::addChild (CompObject *object) { - return (*objectInfo[object->type].nameObject) (object); + if (!object) + return; + object->priv->parent = this; + priv->children.push_back (object); + core->objectAdd (this, object); } -CompObject * -compObjectFind (CompObject *parent, - CompObjectType type, - const char *name) +bool +CompObject::forEachChild (ObjectCallBackProc proc, + void *closure, + CompObjectType type) { - return (*objectInfo[type].findObject) (parent, name); + bool rv = true; + + std::list<CompObject *>::iterator it; + for (it = priv->children.begin (); it != priv->children.end (); it++) + { + if (type > 0 && (*it)->type () != type) + continue; + rv &= (*proc) ((*it), closure); + } + + return rv; } + diff --git a/src/plugin.cpp b/src/plugin.cpp index d81b320..8762ad8 100644 --- a/src/plugin.cpp +++ b/src/plugin.cpp @@ -30,6 +30,7 @@ #include <dirent.h> #include <compiz-core.h> +#include <compobject.h> CompPlugin *plugins = 0; @@ -319,15 +320,15 @@ typedef struct _InitObjectTypeContext { CompObjectType type; } InitObjectTypeContext; -static CompBool +static bool initObjectTree (CompObject *object, void *closure); -static CompBool +static bool finiObjectTree (CompObject *object, void *closure); -static CompBool +static bool initObjectsWithType (CompObjectType type, CompObject *parent, void *closure) @@ -340,9 +341,9 @@ initObjectsWithType (CompObjectType type, ctx.plugin = pCtx->plugin; ctx.object = NULL; - if (!compObjectForEach (parent, type, initObjectTree, (void *) &ctx)) + if (!parent->forEachChild (initObjectTree, (void *) &ctx, type)) { - compObjectForEach (parent, type, finiObjectTree, (void *) &ctx); + parent->forEachChild (finiObjectTree, (void *) &ctx, type); return FALSE; } @@ -350,7 +351,7 @@ initObjectsWithType (CompObjectType type, return TRUE; } -static CompBool +static bool finiObjectsWithType (CompObjectType type, CompObject *parent, void *closure) @@ -365,12 +366,12 @@ finiObjectsWithType (CompObjectType type, ctx.plugin = pCtx->plugin; ctx.object = NULL; - compObjectForEach (parent, type, finiObjectTree, (void *) &ctx); + parent->forEachChild (finiObjectTree, (void *) &ctx, type); return TRUE; } -static CompBool +static bool initObjectTree (CompObject *object, void *closure) { @@ -413,7 +414,7 @@ initObjectTree (CompObject *object, return TRUE; } -static CompBool +static bool finiObjectTree (CompObject *object, void *closure) { diff --git a/src/privateobject.h b/src/privateobject.h new file mode 100644 index 0000000..a8f8eca --- /dev/null +++ b/src/privateobject.h @@ -0,0 +1,21 @@ +#ifndef _PRIVATEOBJECT_H +#define _PRIVATEOBJECT_H + +#include <list> +#include <compiz-core.h> +#include <compobject.h> + +class PrivateObject { + public : + PrivateObject (); + + CompObjectType type; + + const char *typeName; + + CompObject *parent; + std::list<CompObject *> children; +}; + + +#endif
\ No newline at end of file diff --git a/src/screen.cpp b/src/screen.cpp index 2a02d0b..edee063 100644 --- a/src/screen.cpp +++ b/src/screen.cpp @@ -37,6 +37,7 @@ #include <unistd.h> #include <assert.h> #include <limits.h> +#include <algorithm> #include <X11/Xlib.h> #include <X11/Xatom.h> @@ -94,58 +95,6 @@ freeScreenObjectPrivateIndex (CompObject *parent, index); } -CompBool -forEachScreenObject (CompObject *parent, - ObjectCallBackProc proc, - void *closure) -{ - if (parent->type == COMP_OBJECT_TYPE_DISPLAY) - { - CompScreen *s; - - CORE_DISPLAY (parent); - - for (s = d->screens(); s; s = s->next) - { - if (!(*proc) (s, closure)) - return FALSE; - } - } - - return TRUE; -} - -char * -nameScreenObject (CompObject *object) -{ - char tmp[256]; - - CORE_SCREEN (object); - - snprintf (tmp, 256, "%d", s->screenNum ()); - - return strdup (tmp); -} - -CompObject * -findScreenObject (CompObject *parent, - const char *name) -{ - if (parent->type == COMP_OBJECT_TYPE_DISPLAY) - { - CompScreen *s; - int screenNum = atoi (name); - - CORE_DISPLAY (parent); - - for (s = d->screens(); s; s = s->next) - if (s->screenNum () == screenNum) - return s; - } - - return NULL; -} - int allocateScreenPrivateIndex (CompDisplay *display) { @@ -1490,7 +1439,8 @@ CompScreen::initWindowWalker (CompWalker *walker) walker->prev = walkPrev; } -CompScreen::CompScreen () +CompScreen::CompScreen (): + CompObject (COMP_OBJECT_TYPE_SCREEN, "screen") { WRAPABLE_INIT_HND(preparePaint); WRAPABLE_INIT_HND(donePaint); @@ -2329,7 +2279,7 @@ CompScreen::init (CompDisplay *display, /* TODO: bailout properly when objectInitPlugins fails */ assert (objectInitPlugins (this)); - core->objectAdd (display, this); + display->addChild (this); XQueryTree (dpy, priv->root, &rootReturn, &parentReturn, @@ -2405,8 +2355,6 @@ CompScreen::~CompScreen () while (priv->windows) delete priv->windows; - core->objectRemove (priv->display, this); - objectFiniPlugins (this); XUngrabKey (priv->display->dpy (), AnyKey, AnyModifier, priv->root); @@ -2465,6 +2413,17 @@ CompScreen::~CompScreen () delete priv; } +CompString +CompScreen::name () +{ + char tmp[256]; + + snprintf (tmp, 256, "%d", priv->screenNum); + + return CompString (tmp); + +} + void CompScreen::damageRegion (Region region) { diff --git a/src/window.cpp b/src/window.cpp index 0e4524d..854e08f 100644 --- a/src/window.cpp +++ b/src/window.cpp @@ -87,58 +87,6 @@ freeWindowObjectPrivateIndex (CompObject *parent, index); } -CompBool -forEachWindowObject (CompObject *parent, - ObjectCallBackProc proc, - void *closure) -{ - if (parent->type == COMP_OBJECT_TYPE_SCREEN) - { - CompWindow *w; - - CORE_SCREEN (parent); - - for (w = s->windows (); w; w = w->next) - { - if (!(*proc) (w, closure)) - return FALSE; - } - } - - return TRUE; -} - -char * -nameWindowObject (CompObject *object) -{ - char tmp[256]; - - CORE_WINDOW (object); - - snprintf (tmp, 256, "0x%lu", w->id ()); - - return strdup (tmp); -} - -CompObject * -findWindowObject (CompObject *parent, - const char *name) -{ - if (parent->type == COMP_OBJECT_TYPE_SCREEN) - { - CompWindow *w; - Window id = atoi (name); - - CORE_SCREEN (parent); - - for (w = s->windows (); w; w = w->next) - if (w->id () == id) - return w; - } - - return NULL; -} - int allocateWindowPrivateIndex (CompScreen *screen) { @@ -4994,7 +4942,8 @@ CompWindow::paintAttrib () CompWindow::CompWindow (CompScreen *screen, Window id, - Window aboveId) + Window aboveId) : + CompObject (COMP_OBJECT_TYPE_WINDOW, "window") { WRAPABLE_INIT_HND(paint); WRAPABLE_INIT_HND(draw); @@ -5485,3 +5434,13 @@ PrivateWindow::~PrivateWindow () free (resClass); } +CompString +CompWindow::name () +{ + char tmp[256]; + + snprintf (tmp, 256, "0x%lu", priv->id); + + return CompString (tmp); + +} |