From b0e452563ba0ec996a54aa301939ce97ecdd702c Mon Sep 17 00:00:00 2001 From: Vlad Zahorodnii Date: Fri, 6 Jan 2023 12:01:05 +0200 Subject: [PATCH] kcms/effects: Fix effect loading/unloading order There are effects that are mutually exclusive, e.g. magnifier and zoom. They both use the same global shortcuts. When switching from zoom to magnifier, the zoom effect must be unloaded first, then the magnifier effect can be loaded. Doing so in the opposite order will break global shortcuts in the magnifier effect because zooming shortcuts are still bound by the zoom effect. BUG: 457800 --- src/kcms/common/effectsmodel.cpp | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/kcms/common/effectsmodel.cpp b/src/kcms/common/effectsmodel.cpp index 41ce579b0c..86e6064f57 100644 --- a/src/kcms/common/effectsmodel.cpp +++ b/src/kcms/common/effectsmodel.cpp @@ -536,12 +536,18 @@ void EffectsModel::save() return; } - for (const EffectData &effect : dirtyEffects) { - if (effect.status != Status::Disabled) { - interface.loadEffect(effect.serviceName); - } else { - interface.unloadEffect(effect.serviceName); - } + // Unload effects first, it's need to ensure that switching between mutually exclusive + // effects works as expected, for example so global shortcuts are handed over, etc. + auto split = std::partition(dirtyEffects.begin(), dirtyEffects.end(), [](const EffectData &data) { + return data.status == Status::Disabled; + }); + + for (auto it = dirtyEffects.begin(); it != split; ++it) { + interface.unloadEffect(it->serviceName); + } + + for (auto it = split; it != dirtyEffects.end(); ++it) { + interface.loadEffect(it->serviceName); } }