diff --git a/clients/aurorae/src/aurorae.cpp b/clients/aurorae/src/aurorae.cpp index 886df59591..a8aee0f152 100644 --- a/clients/aurorae/src/aurorae.cpp +++ b/clients/aurorae/src/aurorae.cpp @@ -434,6 +434,9 @@ extern "C" KDE_EXPORT KDecorationFactory *create_factory() { return Aurorae::AuroraeFactory::instance(); } + KWIN_EXPORT int decoration_version() { + return KWIN_DECORATION_API_VERSION; + } } diff --git a/clients/b2/b2client.cpp b/clients/b2/b2client.cpp index 6b52996423..73e4710533 100644 --- a/clients/b2/b2client.cpp +++ b/clients/b2/b2client.cpp @@ -119,10 +119,7 @@ static bool drawSmallBorders = false; // ===================================== -extern "C" KDE_EXPORT KDecorationFactory* create_factory() -{ - return new B2::B2ClientFactory(); -} +KWIN_DECORATION(B2::B2ClientFactory) // ===================================== diff --git a/clients/laptop/laptopclient.cpp b/clients/laptop/laptopclient.cpp index 52efcd1fe9..355355ce10 100644 --- a/clients/laptop/laptopclient.cpp +++ b/clients/laptop/laptopclient.cpp @@ -78,10 +78,8 @@ static bool pixmaps_created = false; // ===================================== -extern "C" KDE_EXPORT KDecorationFactory* create_factory() -{ - return new Laptop::LaptopClientFactory(); -} +KWIN_DECORATION(Laptop::LaptopClientFactory) + // ===================================== diff --git a/clients/oxygen/oxygenfactory.cpp b/clients/oxygen/oxygenfactory.cpp index 827aa59eec..5502a6a6b4 100644 --- a/clients/oxygen/oxygenfactory.cpp +++ b/clients/oxygen/oxygenfactory.cpp @@ -35,11 +35,7 @@ #include #include -extern "C" -{ - KDE_EXPORT KDecorationFactory* create_factory() - { return new Oxygen::Factory(); } -} +KWIN_DECORATION(Oxygen::Factory) namespace Oxygen { diff --git a/clients/plastik/plastik.cpp b/clients/plastik/plastik.cpp index ff9825f879..d1a1147f41 100644 --- a/clients/plastik/plastik.cpp +++ b/clients/plastik/plastik.cpp @@ -552,6 +552,8 @@ PlastikHandler* Handler() // Plugin Stuff // ////////////////////////////////////////////////////////////////////////////// + +// KWIN_DECORATION(KWinPlastik::PlastikHandler) extern "C" { KDE_EXPORT KDecorationFactory *create_factory() @@ -559,4 +561,8 @@ extern "C" KWinPlastik::handler = new KWinPlastik::PlastikHandler(); return KWinPlastik::handler; } + KWIN_EXPORT int decoration_version() { + return KWIN_DECORATION_API_VERSION; + } } + diff --git a/libkdecorations/kdecoration.h b/libkdecorations/kdecoration.h index 442d0a1dc4..ce9ad3622a 100644 --- a/libkdecorations/kdecoration.h +++ b/libkdecorations/kdecoration.h @@ -34,6 +34,19 @@ DEALINGS IN THE SOFTWARE. #define KWIN_EXPORT KDE_EXPORT +#define KWIN_DECORATION_API_VERSION 1 + +/** + * Defines the class to be used for decoration factory. + * The class must be namespace complete. + * E.g. KWIN_EFFECT( Oxygen::Factory ) + **/ +#define KWIN_DECORATION( classname ) \ + extern "C" { \ + KWIN_EXPORT KDecorationFactory* create_factory() { return new classname(); } \ + KWIN_EXPORT int decoration_version() { return KWIN_DECORATION_API_VERSION; } \ + } + class KConfig; /** @defgroup kdecoration KWin decorations library */ diff --git a/libkdecorations/kdecoration_plugins_p.cpp b/libkdecorations/kdecoration_plugins_p.cpp index 26e01bfadc..905015ce6b 100644 --- a/libkdecorations/kdecoration_plugins_p.cpp +++ b/libkdecorations/kdecoration_plugins_p.cpp @@ -157,6 +157,25 @@ trydefaultlib: } create_ptr = NULL; + version_ptr = 0; + KLibrary::void_function_ptr version_func = library->resolveFunction("decoration_version"); + if (version_func) { + // TODO for the moment we let unversioned decos through + // later on this function shall become mandatory! + version_ptr = (int(*)())version_func; + const int deco_version = version_ptr(); + if (deco_version != KWIN_DECORATION_API_VERSION) { + if (nameStr != defaultPlugin) { + kWarning(1212) << i18n("The library %1 has wrong API version %2", path, deco_version); + library->unload(); + library = NULL; + goto trydefaultlib; + } + } + } else { + kWarning(1212) << i18n("******\n\nThe library %1 has no API version\nPlease use the KWIN_DECORATION or future versions of kwin will no longer load this decoration!\n*******", path); + } + KLibrary::void_function_ptr create_func = library->resolveFunction("create_factory"); if (create_func) create_ptr = (KDecorationFactory * (*)())create_func; diff --git a/libkdecorations/kdecoration_plugins_p.h b/libkdecorations/kdecoration_plugins_p.h index 3da3f2e4d6..27873efa8d 100644 --- a/libkdecorations/kdecoration_plugins_p.h +++ b/libkdecorations/kdecoration_plugins_p.h @@ -59,6 +59,7 @@ protected: QString defaultPlugin; // FRAME normalne protected? private: KDecorationFactory*(*create_ptr)(); + int (*version_ptr)(); KLibrary *library; KDecorationFactory* fact; KLibrary *old_library; @@ -71,6 +72,7 @@ private: Plugins API: KDecorationFactory* create_factory(); - called once after loading + int decoration_version(); - called once after loading */