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>
|
|
|
|
#include <kstddirs.h>
|
|
|
|
#include <kdesktopfile.h>
|
|
|
|
#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-04-25 16:16:18 +00:00
|
|
|
#if 0
|
|
|
|
#define lt_ptr lt_ptr_t
|
|
|
|
#endif
|
|
|
|
|
2001-02-20 01:20:38 +00:00
|
|
|
using namespace KWinInternal;
|
|
|
|
|
2001-06-07 11:35:06 +00:00
|
|
|
const char* defaultPlugin = "libkwindefault";
|
1999-12-24 01:36:47 +00:00
|
|
|
|
|
|
|
|
|
|
|
PluginMgr::PluginMgr()
|
|
|
|
: QObject()
|
|
|
|
{
|
|
|
|
alloc_ptr = NULL;
|
|
|
|
handle = 0;
|
2001-06-07 11:35:06 +00:00
|
|
|
pluginStr = "kwin_undefined";
|
1999-12-24 01:36:47 +00:00
|
|
|
|
2001-01-16 23:54:45 +00:00
|
|
|
updatePlugin();
|
1999-12-24 01:36:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
PluginMgr::~PluginMgr()
|
|
|
|
{
|
2001-06-07 11:35:06 +00:00
|
|
|
if(handle) {
|
|
|
|
// Call the plugin's cleanup function
|
|
|
|
lt_ptr_t deinit_func = lt_dlsym(handle, "deinit");
|
|
|
|
if (deinit_func)
|
|
|
|
((void (*)())deinit_func)();
|
1999-12-24 01:36:47 +00:00
|
|
|
lt_dlclose(handle);
|
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");
|
2001-06-07 11:35:06 +00:00
|
|
|
QString newPlugin = config->readEntry("PluginLib", defaultPlugin);
|
|
|
|
|
|
|
|
if (newPlugin != pluginStr)
|
|
|
|
loadPlugin(newPlugin);
|
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
|
1999-12-24 01:36:47 +00:00
|
|
|
void PluginMgr::loadPlugin(QString nameStr)
|
|
|
|
{
|
|
|
|
static bool dlregistered = false;
|
2001-02-21 18:29:24 +00:00
|
|
|
lt_dlhandle oldHandle = handle;
|
|
|
|
handle = 0;
|
2001-06-07 11:35:06 +00:00
|
|
|
|
|
|
|
if(!dlregistered) {
|
|
|
|
dlregistered = true;
|
|
|
|
lt_dlinit();
|
|
|
|
}
|
|
|
|
|
|
|
|
QString path = KLibLoader::findLibrary(nameStr.latin1());
|
|
|
|
|
|
|
|
// If the plugin was not found, try to find the default
|
|
|
|
if (path.isEmpty()) {
|
|
|
|
nameStr = defaultPlugin;
|
|
|
|
path = KLibLoader::findLibrary(nameStr.latin1());
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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.
|
|
|
|
if(pluginStr == nameStr)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Try loading the requested plugin
|
|
|
|
handle = lt_dlopen(path.latin1());
|
|
|
|
|
|
|
|
// If that fails, fall back to the default plugin
|
|
|
|
if (!handle) {
|
|
|
|
nameStr = defaultPlugin;
|
|
|
|
path = KLibLoader::findLibrary(nameStr.latin1());
|
|
|
|
if (!path.isEmpty())
|
|
|
|
handle = lt_dlopen(path.latin1());
|
2000-07-16 10:20:29 +00:00
|
|
|
}
|
|
|
|
|
2001-06-07 11:35:06 +00:00
|
|
|
if (!handle)
|
|
|
|
shutdownKWin(i18n("The default decoration plugin is corrupt "
|
|
|
|
"and could not be loaded!"));
|
|
|
|
|
|
|
|
// Call the plugin's initialisation function
|
|
|
|
lt_ptr_t init_func = lt_dlsym(handle, "init");
|
|
|
|
if (init_func)
|
|
|
|
((void (*)())init_func)();
|
|
|
|
|
|
|
|
lt_ptr_t alloc_func = lt_dlsym(handle, "allocate");
|
|
|
|
if(alloc_func) {
|
|
|
|
alloc_ptr = (Client* (*)(Workspace *ws, WId w, int tool))alloc_func;
|
|
|
|
} else {
|
|
|
|
qWarning("KWin: The library %s is not a KWin plugin.", path.latin1());
|
|
|
|
lt_dlclose(handle);
|
|
|
|
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
|
2001-04-25 16:16:18 +00:00
|
|
|
if(oldHandle) {
|
2001-05-12 00:33:43 +00:00
|
|
|
lt_ptr_t deinit_func = lt_dlsym(oldHandle, "deinit");
|
2001-04-25 16:16:18 +00:00
|
|
|
if (deinit_func)
|
|
|
|
((void (*)())deinit_func)();
|
1999-12-24 01:36:47 +00:00
|
|
|
lt_dlclose(oldHandle);
|
2001-04-22 05:39:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void PluginMgr::resetPlugin()
|
|
|
|
{
|
2001-05-12 00:33:43 +00:00
|
|
|
lt_ptr_t reset_func = lt_dlsym(handle, "reset");
|
2001-04-22 05:39:17 +00:00
|
|
|
if (reset_func)
|
|
|
|
((void (*)())reset_func)();
|
1999-12-24 01:36:47 +00:00
|
|
|
}
|
|
|
|
|
2001-06-07 11:35:06 +00:00
|
|
|
void PluginMgr::shutdownKWin(const QString &error_msg)
|
|
|
|
{
|
|
|
|
qWarning( (i18n("KWin: ") + error_msg +
|
|
|
|
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
|
|
|
|