2000-03-24 22:23:02 +00:00
|
|
|
/*****************************************************************
|
|
|
|
kwin - the KDE window manager
|
2000-07-29 01:55:29 +00:00
|
|
|
|
2000-03-24 22:23:02 +00:00
|
|
|
Copyright (C) 1999, 2000 Daniel M. Duley <mosfet@kde.org>
|
|
|
|
******************************************************************/
|
1999-12-24 01:36:47 +00:00
|
|
|
#include <kglobal.h>
|
|
|
|
#include <kconfig.h>
|
2001-12-29 17:33:05 +00:00
|
|
|
#include <kstandarddirs.h>
|
1999-12-24 01:36:47 +00:00
|
|
|
#include <kdesktopfile.h>
|
2002-02-24 18:16:45 +00:00
|
|
|
#include <kdebug.h>
|
1999-12-24 01:36:47 +00:00
|
|
|
#include <ksimpleconfig.h>
|
|
|
|
#include <klocale.h>
|
2000-12-04 18:47:19 +00:00
|
|
|
#include <klibloader.h>
|
2000-04-20 17:37:33 +00:00
|
|
|
|
|
|
|
// X11/Qt conflict
|
|
|
|
#undef Unsorted
|
|
|
|
|
1999-12-24 01:36:47 +00:00
|
|
|
#include <qdir.h>
|
|
|
|
#include <qfile.h>
|
|
|
|
|
|
|
|
#include "plugins.h"
|
|
|
|
|
2001-02-20 01:20:38 +00:00
|
|
|
using namespace KWinInternal;
|
|
|
|
|
2002-02-19 16:56:16 +00:00
|
|
|
const char* defaultPlugin = "kwin_default";
|
1999-12-24 01:36:47 +00:00
|
|
|
|
|
|
|
|
|
|
|
PluginMgr::PluginMgr()
|
|
|
|
: QObject()
|
|
|
|
{
|
|
|
|
alloc_ptr = NULL;
|
2002-02-24 10:41:20 +00:00
|
|
|
library = 0;
|
2001-06-07 11:35:06 +00:00
|
|
|
pluginStr = "kwin_undefined";
|
1999-12-24 01:36:47 +00:00
|
|
|
|
2002-03-01 01:34:54 +00:00
|
|
|
KConfig *config = KGlobal::config();
|
|
|
|
config->setGroup("Style");
|
|
|
|
loadPlugin( config->readEntry("PluginLib", defaultPlugin) );
|
1999-12-24 01:36:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
PluginMgr::~PluginMgr()
|
|
|
|
{
|
2002-02-24 10:41:20 +00:00
|
|
|
if(library) {
|
2001-06-07 11:35:06 +00:00
|
|
|
// Call the plugin's cleanup function
|
2002-02-24 10:41:20 +00:00
|
|
|
void *deinit_func = library->symbol("deinit");
|
2001-06-07 11:35:06 +00:00
|
|
|
if (deinit_func)
|
|
|
|
((void (*)())deinit_func)();
|
2002-02-24 10:41:20 +00:00
|
|
|
library->unload();
|
|
|
|
library = 0;
|
2001-06-07 11:35:06 +00:00
|
|
|
}
|
1999-12-24 01:36:47 +00:00
|
|
|
}
|
|
|
|
|
2001-06-07 11:35:06 +00:00
|
|
|
void PluginMgr::updatePlugin()
|
2001-01-16 23:54:45 +00:00
|
|
|
{
|
|
|
|
KConfig *config = KGlobal::config();
|
2001-02-21 18:29:24 +00:00
|
|
|
config->reparseConfiguration();
|
2001-01-16 23:54:45 +00:00
|
|
|
config->setGroup("Style");
|
2002-03-01 01:34:54 +00:00
|
|
|
if ( !loadPlugin( config->readEntry("PluginLib", defaultPlugin )) && library ) {
|
|
|
|
void *reset_func = library->symbol("reset");
|
|
|
|
if (reset_func)
|
|
|
|
((void (*)())reset_func)();
|
|
|
|
}
|
2001-01-16 23:54:45 +00:00
|
|
|
}
|
|
|
|
|
2000-09-25 15:30:51 +00:00
|
|
|
Client* PluginMgr::allocateClient(Workspace *ws, WId w, bool tool)
|
1999-12-24 01:36:47 +00:00
|
|
|
{
|
2001-06-07 11:35:06 +00:00
|
|
|
// We are guaranteed to have a plugin loaded,
|
|
|
|
// otherwise, kwin exits during loadPlugin - but verify anyway
|
|
|
|
if (alloc_ptr)
|
2000-09-25 15:30:51 +00:00
|
|
|
return(alloc_ptr(ws, w, tool));
|
1999-12-24 01:36:47 +00:00
|
|
|
else
|
2001-06-07 11:35:06 +00:00
|
|
|
return NULL;
|
1999-12-24 01:36:47 +00:00
|
|
|
}
|
|
|
|
|
2001-06-07 11:35:06 +00:00
|
|
|
// returns true if plugin was loaded successfully
|
2002-03-01 01:34:54 +00:00
|
|
|
bool PluginMgr::loadPlugin(QString nameStr)
|
1999-12-24 01:36:47 +00:00
|
|
|
{
|
2002-02-24 10:41:20 +00:00
|
|
|
KLibrary *oldLibrary = library;
|
2001-06-07 11:35:06 +00:00
|
|
|
|
2001-12-31 01:54:45 +00:00
|
|
|
QString path = KLibLoader::findLibrary(QFile::encodeName(nameStr));
|
2001-06-07 11:35:06 +00:00
|
|
|
|
|
|
|
// If the plugin was not found, try to find the default
|
|
|
|
if (path.isEmpty()) {
|
|
|
|
nameStr = defaultPlugin;
|
2001-12-31 01:54:45 +00:00
|
|
|
path = KLibLoader::findLibrary(QFile::encodeName(nameStr));
|
2001-06-07 11:35:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// If no library was found, exit kwin with an error message
|
|
|
|
if (path.isEmpty())
|
|
|
|
shutdownKWin(i18n("No window decoration plugin library was found!"));
|
|
|
|
|
|
|
|
// Check if this library is not already loaded.
|
2002-03-05 19:02:24 +00:00
|
|
|
if(pluginStr == nameStr)
|
2002-03-01 01:34:54 +00:00
|
|
|
return FALSE;
|
2001-06-07 11:35:06 +00:00
|
|
|
|
|
|
|
// Try loading the requested plugin
|
2002-02-24 10:41:20 +00:00
|
|
|
library = KLibLoader::self()->library(QFile::encodeName(path));
|
2001-06-07 11:35:06 +00:00
|
|
|
|
|
|
|
// If that fails, fall back to the default plugin
|
2002-02-24 10:41:20 +00:00
|
|
|
if (!library) {
|
2002-03-01 01:34:54 +00:00
|
|
|
kdDebug() << " could not load library, try default plugin again" << endl;
|
2001-06-07 11:35:06 +00:00
|
|
|
nameStr = defaultPlugin;
|
2002-03-01 01:34:54 +00:00
|
|
|
if ( pluginStr == nameStr )
|
|
|
|
return FALSE;
|
2001-12-31 01:54:45 +00:00
|
|
|
path = KLibLoader::findLibrary(QFile::encodeName(nameStr));
|
2001-06-07 11:35:06 +00:00
|
|
|
if (!path.isEmpty())
|
2002-02-24 10:41:20 +00:00
|
|
|
library = KLibLoader::self()->library(QFile::encodeName(path));
|
2000-07-16 10:20:29 +00:00
|
|
|
}
|
|
|
|
|
2002-02-24 10:41:20 +00:00
|
|
|
if (!library)
|
2001-06-07 11:35:06 +00:00
|
|
|
shutdownKWin(i18n("The default decoration plugin is corrupt "
|
|
|
|
"and could not be loaded!"));
|
|
|
|
|
|
|
|
// Call the plugin's initialisation function
|
2002-02-24 10:41:20 +00:00
|
|
|
void *init_func = library->symbol("init");
|
2001-06-07 11:35:06 +00:00
|
|
|
if (init_func)
|
|
|
|
((void (*)())init_func)();
|
|
|
|
|
2002-02-24 10:41:20 +00:00
|
|
|
void *alloc_func = library->symbol("allocate");
|
2001-06-07 11:35:06 +00:00
|
|
|
if(alloc_func) {
|
|
|
|
alloc_ptr = (Client* (*)(Workspace *ws, WId w, int tool))alloc_func;
|
|
|
|
} else {
|
2002-02-24 18:16:45 +00:00
|
|
|
kdWarning() << "KWin: The library " << path << " is not a KWin plugin." << endl;
|
2002-02-24 10:41:20 +00:00
|
|
|
library->unload();
|
2001-06-07 11:35:06 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
pluginStr = nameStr;
|
1999-12-24 01:36:47 +00:00
|
|
|
emit resetAllClients();
|
2001-06-07 11:35:06 +00:00
|
|
|
|
|
|
|
// Call the old plugin's cleanup function
|
2002-02-24 10:41:20 +00:00
|
|
|
if(oldLibrary) {
|
|
|
|
void *deinit_func = oldLibrary->symbol("deinit");
|
2001-04-25 16:16:18 +00:00
|
|
|
if (deinit_func)
|
|
|
|
((void (*)())deinit_func)();
|
2002-02-24 10:41:20 +00:00
|
|
|
oldLibrary->unload();
|
2001-04-22 05:39:17 +00:00
|
|
|
}
|
2002-03-01 01:34:54 +00:00
|
|
|
return TRUE;
|
1999-12-24 01:36:47 +00:00
|
|
|
}
|
|
|
|
|
2001-06-07 11:35:06 +00:00
|
|
|
void PluginMgr::shutdownKWin(const QString &error_msg)
|
|
|
|
{
|
2002-03-05 19:02:24 +00:00
|
|
|
qWarning( (i18n("KWin: ") + error_msg +
|
2001-06-07 11:35:06 +00:00
|
|
|
i18n("\nKWin will now exit...")).latin1() );
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2000-06-09 00:20:21 +00:00
|
|
|
#include "plugins.moc"
|
1999-12-24 01:36:47 +00:00
|
|
|
|