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;
|
|
|
|
|
1999-12-24 01:36:47 +00:00
|
|
|
|
|
|
|
PluginMgr::PluginMgr()
|
|
|
|
: QObject()
|
|
|
|
{
|
2002-07-05 20:05:22 +00:00
|
|
|
create_ptr = NULL;
|
|
|
|
old_create_ptr = NULL;
|
2002-02-24 10:41:20 +00:00
|
|
|
library = 0;
|
2001-06-07 11:35:06 +00:00
|
|
|
pluginStr = "kwin_undefined";
|
2002-10-28 22:54:25 +00:00
|
|
|
defaultPlugin = (QPixmap::defaultDepth() > 8) ?
|
|
|
|
"kwin_keramik" : "kwin_quartz";
|
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-09-16 14:14:29 +00:00
|
|
|
if( library->hasSymbol("deinit")) {
|
|
|
|
void *deinit_func = library->symbol("deinit");
|
|
|
|
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 ) {
|
2002-09-16 14:14:29 +00:00
|
|
|
if( library->hasSymbol("reset")) {
|
|
|
|
void *reset_func = library->symbol("reset");
|
|
|
|
if (reset_func)
|
|
|
|
((void (*)())reset_func)();
|
|
|
|
}
|
2002-03-01 01:34:54 +00:00
|
|
|
}
|
2001-01-16 23:54:45 +00:00
|
|
|
}
|
|
|
|
|
2002-07-05 20:05:22 +00:00
|
|
|
Client* PluginMgr::createClient(Workspace *ws, WId w, NET::WindowType type)
|
1999-12-24 01:36:47 +00:00
|
|
|
{
|
2002-07-05 20:05:22 +00:00
|
|
|
if (create_ptr) // prefer the newer function which accepts exact window type
|
|
|
|
return(create_ptr(ws, w, type));
|
|
|
|
if (old_create_ptr)
|
|
|
|
return(old_create_ptr(ws, w, type == NET::Tool || type == NET::Menu));
|
2001-06-07 11:35:06 +00:00
|
|
|
// We are guaranteed to have a plugin loaded,
|
|
|
|
// otherwise, kwin exits during loadPlugin - but verify anyway
|
2002-07-05 20:05:22 +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-09-16 14:14:29 +00:00
|
|
|
if( library->hasSymbol("init")) {
|
|
|
|
void *init_func = library->symbol("init");
|
|
|
|
if (init_func)
|
|
|
|
((void (*)())init_func)();
|
|
|
|
}
|
2001-06-07 11:35:06 +00:00
|
|
|
|
2003-05-24 02:33:48 +00:00
|
|
|
create_ptr = NULL;
|
|
|
|
old_create_ptr = NULL;
|
2002-09-16 14:14:29 +00:00
|
|
|
if( library->hasSymbol("create")) {
|
|
|
|
void* create_func = library->symbol("create");
|
|
|
|
if(create_func) {
|
|
|
|
create_ptr = (Client* (*)(Workspace *ws, WId w, NET::WindowType))create_func;
|
|
|
|
}
|
2002-07-05 20:05:22 +00:00
|
|
|
}
|
2002-09-16 14:14:29 +00:00
|
|
|
if( library->hasSymbol("allocate")) {
|
|
|
|
void* allocate_func = library->symbol("allocate");
|
|
|
|
if(allocate_func) {
|
|
|
|
old_create_ptr = (Client* (*)(Workspace *ws, WId w, int tool))allocate_func;
|
|
|
|
}
|
2002-07-05 20:05:22 +00:00
|
|
|
}
|
|
|
|
if(!create_ptr && !old_create_ptr) {
|
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) {
|
2002-09-16 14:14:29 +00:00
|
|
|
if( library->hasSymbol("deinit")) {
|
|
|
|
void *deinit_func = oldLibrary->symbol("deinit");
|
|
|
|
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)
|
|
|
|
{
|
2003-01-12 13:00:03 +00:00
|
|
|
qWarning( "%s", (i18n("KWin: ") + error_msg +
|
|
|
|
i18n("\nKWin will now exit...")).latin1() );
|
2001-06-07 11:35:06 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2000-06-09 00:20:21 +00:00
|
|
|
#include "plugins.moc"
|
1999-12-24 01:36:47 +00:00
|
|
|
|