diff --git a/libkwineffects/kwineffects.h b/libkwineffects/kwineffects.h --- a/libkwineffects/kwineffects.h +++ b/libkwineffects/kwineffects.h @@ -661,6 +661,41 @@ static void setPositionTransformations(WindowPaintData& data, QRect& region, EffectWindow* w, const QRect& r, Qt::AspectRatioMode aspect); + /** + * Whether another effect has grabbed the @p w with the given @p grabRole. + * @param w The window to check + * @param grabRole The grab role to check + * @returns @c true if another window has grabbed the effect, @c false otherwise + * @since ?.?? + **/ + Q_SCRIPTABLE bool isGrabbed(KWin::EffectWindow *w, DataRole grabRole); + /** + * Grabs @p w with the given @p grabRole. + * + * If the given window is already grabbed by somebody else, this method will do + * nothing, unless @p force is set to @c true. + * + * @param w The window to grab + * @param grabRole The role to grab + * @param force Whether to force the effect to grab the window + * @returns @c true if the window has been grabbed successfully, @c false otherwise + * @since 5.?? + **/ + Q_SCRIPTABLE bool grab(KWin::EffectWindow *w, DataRole grabRole, bool force = false); + /** + * Ungrabs @p w with the given @p grabRole. + * + * If the given window is grabbed by somebody else, this method will do + * nothing, unless @p force is set to @c true. + * + * @param w The window to ungrab + * @param grabRole The role to ungrab + * @param force Whether to force the effect to ungrab the window + * @returns @c true if the window has been ungrabbed successfully, @c false otherwise + * @since 5.?? + **/ + Q_SCRIPTABLE bool ungrab(KWin::EffectWindow *w, DataRole grabRole, bool force = false); + public Q_SLOTS: virtual bool borderActivated(ElectricBorder border); diff --git a/libkwineffects/kwineffects.cpp b/libkwineffects/kwineffects.cpp --- a/libkwineffects/kwineffects.cpp +++ b/libkwineffects/kwineffects.cpp @@ -711,6 +711,33 @@ return false; } +bool Effect::isGrabbed(EffectWindow* w, DataRole grabRole) +{ + void *e = w->data(grabRole).value(); + if (e) { + return e != this; + } + return false; +} + +bool Effect::grab(EffectWindow *w, DataRole grabRole, bool force) +{ + if (isGrabbed(w, grabRole) && !force) { + return false; + } + w->setData(grabRole, QVariant::fromValue(static_cast(this))); + return true; +} + +bool Effect::ungrab(EffectWindow *w, DataRole grabRole, bool force) +{ + if (isGrabbed(w, grabRole) && !force) { + return false; + } + w->setData(grabRole, QVariant()); + return true; +} + //**************************************** // EffectFactory //**************************************** diff --git a/scripting/scriptedeffect.h b/scripting/scriptedeffect.h --- a/scripting/scriptedeffect.h +++ b/scripting/scriptedeffect.h @@ -69,13 +69,6 @@ static ScriptedEffect *create(const KPluginMetaData &effect); static bool supported(); virtual ~ScriptedEffect(); - /** - * Whether another effect has grabbed the @p w with the given @p grabRole. - * @param w The window to check - * @param grabRole The grab role to check - * @returns @c true if another window has grabbed the effect, @c false otherwise - **/ - Q_SCRIPTABLE bool isGrabbed(KWin::EffectWindow *w, DataRole grabRole); /** * Reads the value from the configuration data for the given key. * @param key The key to search for diff --git a/scripting/scriptedeffect.cpp b/scripting/scriptedeffect.cpp --- a/scripting/scriptedeffect.cpp +++ b/scripting/scriptedeffect.cpp @@ -606,16 +606,6 @@ return AnimationEffect::retarget(animationId, newTarget, newRemainingTime); } -bool ScriptedEffect::isGrabbed(EffectWindow* w, ScriptedEffect::DataRole grabRole) -{ - void *e = w->data(static_cast(grabRole)).value(); - if (e) { - return e != this; - } else { - return false; - } -} - void ScriptedEffect::reconfigure(ReconfigureFlags flags) { AnimationEffect::reconfigure(flags);