diff --git a/src/effects.cpp b/src/effects.cpp index bfbb9930af..fd1b1b5c52 100644 --- a/src/effects.cpp +++ b/src/effects.cpp @@ -1421,6 +1421,17 @@ QStringList EffectsHandlerImpl::activeEffects() const return ret; } +bool EffectsHandlerImpl::isEffectActive(const QString &pluginId) const +{ + auto it = std::find_if(loaded_effects.cbegin(), loaded_effects.cend(), [&pluginId](const EffectPair &p) { + return p.first == pluginId; + }); + if (it == loaded_effects.cend()) { + return false; + } + return it->second->isActive(); +} + bool EffectsHandlerImpl::blocksDirectScanout() const { return std::any_of(m_activeEffects.constBegin(), m_activeEffects.constEnd(), [](const Effect *effect) { diff --git a/src/effects.h b/src/effects.h index 7045b093cd..7c25165ef9 100644 --- a/src/effects.h +++ b/src/effects.h @@ -177,6 +177,7 @@ public: QStringList listOfEffects() const; void unloadAllEffects(); QStringList activeEffects() const; + bool isEffectActive(const QString &pluginId) const; /** * @returns whether or not any effect is currently active where KWin should not use direct scanout diff --git a/src/scripting/workspace_wrapper.cpp b/src/scripting/workspace_wrapper.cpp index da40dbe8f5..0c132cab5a 100644 --- a/src/scripting/workspace_wrapper.cpp +++ b/src/scripting/workspace_wrapper.cpp @@ -12,6 +12,7 @@ #include "core/output.h" #include "core/outputbackend.h" #include "cursor.h" +#include "effects.h" #include "outline.h" #include "tiles/tilemanager.h" #include "virtualdesktops.h" @@ -327,6 +328,14 @@ QList WorkspaceWrapper::windowAt(const QPointF &pos, int count) return result; } +bool WorkspaceWrapper::isEffectActive(const QString &pluginId) const +{ + if (!effects) { + return false; + } + return static_cast(effects)->isEffectActive(pluginId); +} + QSize WorkspaceWrapper::desktopGridSize() const { return VirtualDesktopManager::self()->grid().size(); diff --git a/src/scripting/workspace_wrapper.h b/src/scripting/workspace_wrapper.h index 36fb4cb8e4..b05a5f6ee8 100644 --- a/src/scripting/workspace_wrapper.h +++ b/src/scripting/workspace_wrapper.h @@ -256,6 +256,14 @@ public: */ Q_INVOKABLE QList windowAt(const QPointF &pos, int count = 1) const; + /** + * Checks if a specific effect is currently active. + * @param pluginId The plugin Id of the effect to check. + * @return @c true if the effect is loaded and currently active, @c false otherwise. + * @since 6.0 + */ + Q_INVOKABLE bool isEffectActive(const QString &pluginId) const; + public Q_SLOTS: // all the available key bindings void slotSwitchDesktopNext();