diff --git a/effects.h b/effects.h --- a/effects.h +++ b/effects.h @@ -340,6 +340,8 @@ private: void registerPropertyType(long atom, bool reg); + void destroyEffect(Effect *effect); + typedef QVector< Effect*> EffectsList; typedef EffectsList::const_iterator EffectsIterator; EffectsList m_activeEffects; diff --git a/effects.cpp b/effects.cpp --- a/effects.cpp +++ b/effects.cpp @@ -273,19 +273,8 @@ void EffectsHandlerImpl::unloadAllEffects() { - makeOpenGLContextCurrent(); - if (keyboard_grab_effect != NULL) - ungrabKeyboard(); - setActiveFullScreenEffect(nullptr); - for (auto it = loaded_effects.begin(); it != loaded_effects.end(); ++it) { - Effect *effect = (*it).second; - stopMouseInterception(effect); - // remove support properties for the effect - const QList properties = m_propertiesForEffects.keys(); - for (const QByteArray &property : properties) { - removeSupportProperty(property, effect); - } - delete effect; + for (const EffectPair &pair : loaded_effects) { + destroyEffect(pair.second); } effect_order.clear(); @@ -1394,29 +1383,44 @@ void EffectsHandlerImpl::unloadEffect(const QString& name) { - makeOpenGLContextCurrent(); + auto it = std::find_if(effect_order.begin(), effect_order.end(), + [name](EffectPair &pair) { + return pair.first == name; + } + ); + if (it == effect_order.end()) { + qCDebug(KWIN_CORE) << "EffectsHandler::unloadEffect : Effect not loaded :" << name; + return; + } + + qCDebug(KWIN_CORE) << "EffectsHandler::unloadEffect : Unloading Effect :" << name; + destroyEffect((*it).second); + effect_order.erase(it); + effectsChanged(); + m_compositor->addRepaintFull(); +} - for (QMap< int, EffectPair >::iterator it = effect_order.begin(); it != effect_order.end(); ++it) { - if (it.value().first == name) { - qCDebug(KWIN_CORE) << "EffectsHandler::unloadEffect : Unloading Effect : " << name; - if (activeFullScreenEffect() == it.value().second) { - setActiveFullScreenEffect(0); - } - stopMouseInterception(it.value().second); - // remove support properties for the effect - const QList properties = m_propertiesForEffects.keys(); - for (const QByteArray &property : properties) { - removeSupportProperty(property, it.value().second); - } - delete it.value().second; - effect_order.erase(it); - effectsChanged(); - return; - } +void EffectsHandlerImpl::destroyEffect(Effect *effect) +{ + makeOpenGLContextCurrent(); + + if (fullscreen_effect == effect) { + setActiveFullScreenEffect(nullptr); + } + + if (keyboard_grab_effect == effect) { + ungrabKeyboard(); + } + + stopMouseInterception(effect); + + const QList properties = m_propertiesForEffects.keys(); + for (const QByteArray &property : properties) { + removeSupportProperty(property, effect); } - qCDebug(KWIN_CORE) << "EffectsHandler::unloadEffect : Effect not loaded : " << name; + delete effect; } void EffectsHandlerImpl::reconfigureEffect(const QString& name)