Index: beryl-core/src/library.c =================================================================== --- beryl-core/src/library.c (Revision 0) +++ beryl-core/src/library.c (Revision 0) @@ -0,0 +1,121 @@ +/** + * + * Beryl library interface + * + * library.c + * + * Copyright : (C) 2007 by Patrick Niklaus + * Authors: Patrick Niklaus + * + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + **/ + +#ifdef HAVE_CONFIG_H +# include "../config.h" +#endif + +#include +#include +#include + +#include +#include + +static void updateLibraryFuncion(CompDisplay *d, CompLibraryFunction *func) +{ + CompPlugin *p; + + for (p = getPlugins(); p; p = p->next) + if (p->vTable->updateLibrayFunction) + (*p->vTable->updateLibrayFunction) (d, func); +} + +static void appendLibraryFunction(CompDisplay *d, CompLibraryFunction *func) +{ + if (d->libFunctions) { + d->libFunctions->next = func; + func->prev = d->libFunctions; + func->next = NULL; + }else { + d->libFunctions = func; + func->prev = NULL; + func->next = NULL; + } +} + +static void unhookLibraryFunction(CompDisplay *d, CompLibraryFunction *func) +{ + CompLibraryFunction *prev = func->prev; + CompLibraryFunction *next = func->next; + + if (prev) { + if (next) + prev->next = next; + else + prev->next = NULL; + } + if (next) { + if (prev) + next->prev = prev; + else + next->prev = NULL; + } + + if (!prev && !next) + d->libFunctions = NULL; + else if (!prev && next) + d->libFunctions = next; +} + +void addLibraryFunction(CompDisplay *d, char *name, void *function) +{ + CompLibraryFunction *func = (CompLibraryFunction*) malloc(sizeof(CompLibraryFunction)); + + func->name = name; + func->function = function; + + appendLibraryFunction(d, func); + + updateLibraryFuncion(d, func); +} + +void removeLibraryFunction(CompDisplay *d, char *name) +{ + if (!d->libFunctions) + return; + + CompLibraryFunction *func; + for (func = d->libFunctions; func; func = func->next) + if (strcmp(func->name, name) == 0) + break; + + if (!func) + return; + + unhookLibraryFunction(d, func); + updateLibraryFuncion(d, func); + free(func); +} + +void *getLibraryFunction(CompDisplay *d, char *name) +{ + if (!d->libFunctions) + return; + + CompLibraryFunction *func; + for (func = d->libFunctions; func; func = func->next) + if (strcmp(func->name, name) == 0) + return func->function; + + return NULL; +} Index: beryl-core/src/display.c =================================================================== --- beryl-core/src/display.c (Revision 4370) +++ beryl-core/src/display.c (Arbeitskopie) @@ -2361,6 +2361,8 @@ d->fileToImage = fileToImage; d->imageToFile = imageToFile; + d->libFunctions = NULL; + d->reloadSettingsAtom=XInternAtom(dpy,"_BERYL_SETTINGS_RELOAD",0); d->berylDesktopManaged = XInternAtom(dpy, "_BERYL_DESKTOP_MANAGED", 0); Index: beryl-core/src/Makefile.am =================================================================== --- beryl-core/src/Makefile.am (Revision 4370) +++ beryl-core/src/Makefile.am (Arbeitskopie) @@ -39,6 +39,7 @@ syscheck.h \ beryl-private.h \ fsp.h \ + library.c \ blog.c Index: beryl-core/include/beryl.h =================================================================== --- beryl-core/include/beryl.h (Revision 4370) +++ beryl-core/include/beryl.h (Arbeitskopie) @@ -102,6 +102,7 @@ typedef struct _CompProgram CompProgram; typedef struct _CompFunction CompFunction; typedef struct _CompFunctionData CompFunctionData; +typedef struct _CompLibraryFunction CompLibraryFunction; typedef struct _FragmentAttrib FragmentAttrib; /* virtual modifiers */ @@ -851,6 +852,8 @@ FileToImageProc fileToImage; ImageToFileProc imageToFile; + CompLibraryFunction *libFunctions; + CompPrivate *privates; int lastPointerX; @@ -2709,7 +2712,27 @@ setDesktopForWindow (CompWindow *w, unsigned int desktop); +/* library.c */ +typedef void (*UpdateLibraryFunctionProc) (CompDisplay *d, CompLibraryFunction *func); + +struct _CompLibraryFunction { + CompLibraryFunction *prev; + CompLibraryFunction *next; + + char *name; + void *function; +}; + +void +addLibraryFunction (CompDisplay *d, char *name, void *function); + +void +removeLibraryFunction (CompDisplay *d, char *name); + +void* +getLibraryFunction (CompDisplay *d, char* name); + /* plugin.c */ typedef Bool (*InitPluginProc) (CompPlugin *plugin); @@ -2766,6 +2789,8 @@ GetScreenOptionsProc getScreenOptions; SetScreenOptionProc setScreenOption; + UpdateLibraryFunctionProc updateLibrayFunction; + CompPluginDep *deps; int nDeps; @@ -2883,7 +2908,6 @@ void closeSession (void); - /* fragment.c */ #define MAX_FRAGMENT_FUNCTIONS 16