kwin: Add an enabledByDefault() function to the effects interface
This makes it possible to decide at runtime if an effect should be enabled by default.
This commit is contained in:
parent
422eacb42b
commit
e5ea420e96
3 changed files with 52 additions and 6 deletions
36
effects.cpp
36
effects.cpp
|
@ -162,11 +162,19 @@ void EffectsHandlerImpl::reconfigure()
|
|||
|
||||
KService::List offers = KServiceTypeTrader::self()->query("KWin/Effect");
|
||||
QStringList effectsToBeLoaded;
|
||||
QStringList checkDefault;
|
||||
|
||||
// First unload necessary effects
|
||||
foreach (const KService::Ptr & service, offers) {
|
||||
KPluginInfo plugininfo(service);
|
||||
plugininfo.load(conf);
|
||||
|
||||
if (plugininfo.isPluginEnabledByDefault()) {
|
||||
const QString key = plugininfo.pluginName() + QString::fromLatin1("Enabled");
|
||||
if (!conf.hasKey(key))
|
||||
checkDefault.append(plugininfo.pluginName());
|
||||
}
|
||||
|
||||
bool isloaded = isEffectLoaded(plugininfo.pluginName());
|
||||
bool shouldbeloaded = plugininfo.isPluginEnabled();
|
||||
if (!shouldbeloaded && isloaded)
|
||||
|
@ -178,8 +186,8 @@ void EffectsHandlerImpl::reconfigure()
|
|||
// Then load those that should be loaded
|
||||
foreach (const QString & effectName, effectsToBeLoaded) {
|
||||
if (!isEffectLoaded(effectName)) {
|
||||
loadEffect(effectName);
|
||||
newLoaded.append(effectName);
|
||||
if (loadEffect(effectName, checkDefault.contains(effectName)))
|
||||
newLoaded.append(effectName);
|
||||
}
|
||||
}
|
||||
foreach (const EffectPair & ep, loaded_effects) {
|
||||
|
@ -1007,7 +1015,7 @@ QStringList EffectsHandlerImpl::listOfEffects() const
|
|||
return listOfModules;
|
||||
}
|
||||
|
||||
bool EffectsHandlerImpl::loadEffect(const QString& name)
|
||||
bool EffectsHandlerImpl::loadEffect(const QString& name, bool checkDefault)
|
||||
{
|
||||
Workspace::self()->addRepaintFull();
|
||||
assert(current_paint_screen == 0);
|
||||
|
@ -1059,10 +1067,16 @@ bool EffectsHandlerImpl::loadEffect(const QString& name)
|
|||
kWarning(1212) << "Effect " << name << " requires unsupported API version " << version;
|
||||
return false;
|
||||
}
|
||||
QString supported_symbol = "effect_supported_" + name;
|
||||
|
||||
const QString enabledByDefault_symbol = "effect_enabledbydefault_" + name;
|
||||
KLibrary::void_function_ptr enabledByDefault_func = library->resolveFunction(enabledByDefault_symbol.toAscii().data());
|
||||
|
||||
const QString supported_symbol = "effect_supported_" + name;
|
||||
KLibrary::void_function_ptr supported_func = library->resolveFunction(supported_symbol.toAscii().data());
|
||||
QString create_symbol = "effect_create_" + name;
|
||||
|
||||
const QString create_symbol = "effect_create_" + name;
|
||||
KLibrary::void_function_ptr create_func = library->resolveFunction(create_symbol.toAscii().data());
|
||||
|
||||
if (supported_func) {
|
||||
typedef bool (*t_supportedfunc)();
|
||||
t_supportedfunc supported = reinterpret_cast<t_supportedfunc>(supported_func);
|
||||
|
@ -1072,11 +1086,23 @@ bool EffectsHandlerImpl::loadEffect(const QString& name)
|
|||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (checkDefault && enabledByDefault_func) {
|
||||
typedef bool (*t_enabledByDefaultfunc)();
|
||||
t_enabledByDefaultfunc enabledByDefault = reinterpret_cast<t_enabledByDefaultfunc>(enabledByDefault_func);
|
||||
|
||||
if (!enabledByDefault()) {
|
||||
library->unload();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (!create_func) {
|
||||
kError(1212) << "EffectsHandler::loadEffect : effect_create function not found" << endl;
|
||||
library->unload();
|
||||
return false;
|
||||
}
|
||||
|
||||
typedef Effect*(*t_createfunc)();
|
||||
t_createfunc create = reinterpret_cast<t_createfunc>(create_func);
|
||||
|
||||
|
|
|
@ -157,7 +157,7 @@ public:
|
|||
void grabbedKeyboardEvent(QKeyEvent* e);
|
||||
bool hasKeyboardGrab() const;
|
||||
|
||||
bool loadEffect(const QString& name);
|
||||
bool loadEffect(const QString& name, bool checkDefault = false);
|
||||
void toggleEffect(const QString& name);
|
||||
void unloadEffect(const QString& name);
|
||||
void reconfigureEffect(const QString& name);
|
||||
|
|
|
@ -497,6 +497,7 @@ public:
|
|||
KWIN_EXPORT Effect* effect_create_kwin4_effect_##name() { return new classname; } \
|
||||
KWIN_EXPORT int effect_version_kwin4_effect_##name() { return KWIN_EFFECT_API_VERSION; } \
|
||||
}
|
||||
|
||||
/**
|
||||
* Defines the function used to check whether an effect is supported
|
||||
* E.g. KWIN_EFFECT_SUPPORTED( flames, MyFlameEffect::supported() )
|
||||
|
@ -505,6 +506,25 @@ public:
|
|||
extern "C" { \
|
||||
KWIN_EXPORT bool effect_supported_kwin4_effect_##name() { return function; } \
|
||||
}
|
||||
|
||||
/**
|
||||
* Defines the function used to check whether an effect should be enabled by default
|
||||
*
|
||||
* This function provides a way for an effect to override the default at runtime,
|
||||
* e.g. based on the capabilities of the hardware.
|
||||
*
|
||||
* This function is optional; the effect doesn't have to provide it.
|
||||
*
|
||||
* Note that this function is only called if the supported() function returns true,
|
||||
* and if X-KDE-PluginInfo-EnabledByDefault is set to true in the .desktop file.
|
||||
*
|
||||
* Example: KWIN_EFFECT_ENABLEDBYDEFAULT(flames, MyFlameEffect::enabledByDefault())
|
||||
**/
|
||||
#define KWIN_EFFECT_ENABLEDBYDEFAULT(name, function) \
|
||||
extern "C" { \
|
||||
KWIN_EXPORT bool effect_enabledbydefault_kwin4_effect_##name() { return function; } \
|
||||
}
|
||||
|
||||
/**
|
||||
* Defines the function used to retrieve an effect's config widget
|
||||
* E.g. KWIN_EFFECT_CONFIG( flames, MyFlameEffectConfig )
|
||||
|
|
Loading…
Reference in a new issue