diff --git a/scripting/meta.cpp b/scripting/meta.cpp index 47dc8bc177..b6c3ba378a 100644 --- a/scripting/meta.cpp +++ b/scripting/meta.cpp @@ -110,6 +110,20 @@ void Client::fromScriptValue(const QScriptValue &value, KWin::Client* &client) client = qobject_cast(value.toQObject()); } +QScriptValue Toplevel::toScriptValue(QScriptEngine *eng, const KToplevelRef &client) +{ + return eng->newQObject(client, QScriptEngine::QtOwnership, + QScriptEngine::ExcludeChildObjects | + QScriptEngine::ExcludeDeleteLater | + QScriptEngine::PreferExistingWrapperObject | + QScriptEngine::AutoCreateDynamicProperties); +} + +void Toplevel::fromScriptValue(const QScriptValue &value, KToplevelRef &client) +{ + client = qobject_cast(value.toQObject()); +} + // Other helper functions void KWin::MetaScripting::registration(QScriptEngine* eng) { @@ -117,6 +131,7 @@ void KWin::MetaScripting::registration(QScriptEngine* eng) qScriptRegisterMetaType(eng, Size::toScriptValue, Size::fromScriptValue); qScriptRegisterMetaType(eng, Rect::toScriptValue, Rect::fromScriptValue); qScriptRegisterMetaType(eng, Client::toScriptValue, Client::fromScriptValue); + qScriptRegisterMetaType(eng, Toplevel::toScriptValue, Toplevel::fromScriptValue); qScriptRegisterSequenceMetaType(eng); qScriptRegisterSequenceMetaType< QList >(eng); diff --git a/scripting/meta.h b/scripting/meta.h index aa0ca7beab..306adec7ad 100644 --- a/scripting/meta.h +++ b/scripting/meta.h @@ -31,9 +31,11 @@ class QSize; namespace KWin { class Client; +class Toplevel; } typedef KWin::Client* KClientRef; +typedef KWin::Toplevel* KToplevelRef; namespace KWin { @@ -79,6 +81,12 @@ QScriptValue toScriptValue(QScriptEngine *eng, const KClientRef &client); void fromScriptValue(const QScriptValue &value, KClientRef& client); } +namespace Toplevel +{ +QScriptValue toScriptValue(QScriptEngine *eng, const KToplevelRef &client); +void fromScriptValue(const QScriptValue &value, KToplevelRef& client); +} + /** * Merges the second QScriptValue in the first one. */ diff --git a/toplevel.h b/toplevel.h index 1c8f1ac20e..0cd8d0af49 100644 --- a/toplevel.h +++ b/toplevel.h @@ -661,5 +661,6 @@ KWIN_COMPARE_PREDICATE(WindowMatchPredicate, Toplevel, Window, cl->window() == v KWIN_COMPARE_PREDICATE(FrameIdMatchPredicate, Toplevel, Window, cl->frameId() == value); } // namespace +Q_DECLARE_METATYPE(KWin::Toplevel*) #endif