Changeset View
Changeset View
Standalone View
Standalone View
scripting/meta.cpp
Show All 13 Lines | |||||
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
15 | GNU General Public License for more details. | 15 | GNU General Public License for more details. | ||
16 | 16 | | |||
17 | You should have received a copy of the GNU General Public License | 17 | You should have received a copy of the GNU General Public License | ||
18 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 18 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
19 | *********************************************************************/ | 19 | *********************************************************************/ | ||
20 | 20 | | |||
21 | #include "meta.h" | 21 | #include "meta.h" | ||
22 | #include "client.h" | 22 | #include "x11client.h" | ||
23 | 23 | | |||
24 | #include <QtScript/QScriptEngine> | 24 | #include <QtScript/QScriptEngine> | ||
25 | 25 | | |||
26 | using namespace KWin::MetaScripting; | 26 | using namespace KWin::MetaScripting; | ||
27 | 27 | | |||
28 | // Meta for QPoint object | 28 | // Meta for QPoint object | ||
29 | QScriptValue Point::toScriptValue(QScriptEngine* eng, const QPoint& point) | 29 | QScriptValue Point::toScriptValue(QScriptEngine* eng, const QPoint& point) | ||
30 | { | 30 | { | ||
▲ Show 20 Lines • Show All 60 Lines • ▼ Show 20 Line(s) | 90 | if (!w.isUndefined() && !h.isUndefined() && !x.isUndefined() && !y.isUndefined()) { | |||
91 | rect.setX(x.toInt32()); | 91 | rect.setX(x.toInt32()); | ||
92 | rect.setY(y.toInt32()); | 92 | rect.setY(y.toInt32()); | ||
93 | rect.setWidth(w.toInt32()); | 93 | rect.setWidth(w.toInt32()); | ||
94 | rect.setHeight(h.toInt32()); | 94 | rect.setHeight(h.toInt32()); | ||
95 | } | 95 | } | ||
96 | } | 96 | } | ||
97 | // End of meta for QRect object | 97 | // End of meta for QRect object | ||
98 | 98 | | |||
99 | QScriptValue Client::toScriptValue(QScriptEngine *eng, const KClientRef &client) | 99 | QScriptValue X11Client::toScriptValue(QScriptEngine *eng, const KClientRef &client) | ||
100 | { | 100 | { | ||
101 | return eng->newQObject(client, QScriptEngine::QtOwnership, | 101 | return eng->newQObject(client, QScriptEngine::QtOwnership, | ||
102 | QScriptEngine::ExcludeChildObjects | | 102 | QScriptEngine::ExcludeChildObjects | | ||
103 | QScriptEngine::ExcludeDeleteLater | | 103 | QScriptEngine::ExcludeDeleteLater | | ||
104 | QScriptEngine::PreferExistingWrapperObject | | 104 | QScriptEngine::PreferExistingWrapperObject | | ||
105 | QScriptEngine::AutoCreateDynamicProperties); | 105 | QScriptEngine::AutoCreateDynamicProperties); | ||
106 | } | 106 | } | ||
107 | 107 | | |||
108 | void Client::fromScriptValue(const QScriptValue &value, KWin::Client* &client) | 108 | void X11Client::fromScriptValue(const QScriptValue &value, KWin::X11Client *&client) | ||
109 | { | 109 | { | ||
110 | client = qobject_cast<KWin::Client*>(value.toQObject()); | 110 | client = qobject_cast<KWin::X11Client *>(value.toQObject()); | ||
111 | } | 111 | } | ||
112 | 112 | | |||
113 | QScriptValue Toplevel::toScriptValue(QScriptEngine *eng, const KToplevelRef &client) | 113 | QScriptValue Toplevel::toScriptValue(QScriptEngine *eng, const KToplevelRef &client) | ||
114 | { | 114 | { | ||
115 | return eng->newQObject(client, QScriptEngine::QtOwnership, | 115 | return eng->newQObject(client, QScriptEngine::QtOwnership, | ||
116 | QScriptEngine::ExcludeChildObjects | | 116 | QScriptEngine::ExcludeChildObjects | | ||
117 | QScriptEngine::ExcludeDeleteLater | | 117 | QScriptEngine::ExcludeDeleteLater | | ||
118 | QScriptEngine::PreferExistingWrapperObject | | 118 | QScriptEngine::PreferExistingWrapperObject | | ||
119 | QScriptEngine::AutoCreateDynamicProperties); | 119 | QScriptEngine::AutoCreateDynamicProperties); | ||
120 | } | 120 | } | ||
121 | 121 | | |||
122 | void Toplevel::fromScriptValue(const QScriptValue &value, KToplevelRef &client) | 122 | void Toplevel::fromScriptValue(const QScriptValue &value, KToplevelRef &client) | ||
123 | { | 123 | { | ||
124 | client = qobject_cast<KWin::Toplevel*>(value.toQObject()); | 124 | client = qobject_cast<KWin::Toplevel*>(value.toQObject()); | ||
125 | } | 125 | } | ||
126 | 126 | | |||
127 | // Other helper functions | 127 | // Other helper functions | ||
128 | void KWin::MetaScripting::registration(QScriptEngine* eng) | 128 | void KWin::MetaScripting::registration(QScriptEngine* eng) | ||
129 | { | 129 | { | ||
130 | qScriptRegisterMetaType<QPoint>(eng, Point::toScriptValue, Point::fromScriptValue); | 130 | qScriptRegisterMetaType<QPoint>(eng, Point::toScriptValue, Point::fromScriptValue); | ||
131 | qScriptRegisterMetaType<QSize>(eng, Size::toScriptValue, Size::fromScriptValue); | 131 | qScriptRegisterMetaType<QSize>(eng, Size::toScriptValue, Size::fromScriptValue); | ||
132 | qScriptRegisterMetaType<QRect>(eng, Rect::toScriptValue, Rect::fromScriptValue); | 132 | qScriptRegisterMetaType<QRect>(eng, Rect::toScriptValue, Rect::fromScriptValue); | ||
133 | qScriptRegisterMetaType<KClientRef>(eng, Client::toScriptValue, Client::fromScriptValue); | 133 | qScriptRegisterMetaType<KClientRef>(eng, X11Client::toScriptValue, X11Client::fromScriptValue); | ||
134 | qScriptRegisterMetaType<KToplevelRef>(eng, Toplevel::toScriptValue, Toplevel::fromScriptValue); | 134 | qScriptRegisterMetaType<KToplevelRef>(eng, Toplevel::toScriptValue, Toplevel::fromScriptValue); | ||
135 | 135 | | |||
136 | qScriptRegisterSequenceMetaType<QStringList>(eng); | 136 | qScriptRegisterSequenceMetaType<QStringList>(eng); | ||
137 | qScriptRegisterSequenceMetaType< QList<KWin::AbstractClient*> >(eng); | 137 | qScriptRegisterSequenceMetaType< QList<KWin::AbstractClient*> >(eng); | ||
138 | qScriptRegisterSequenceMetaType< QList<KWin::Client*> >(eng); | 138 | qScriptRegisterSequenceMetaType< QList<KWin::X11Client *> >(eng); | ||
139 | } | 139 | } | ||
140 | 140 | | |||
141 | QScriptValue KWin::MetaScripting::configExists(QScriptContext* ctx, QScriptEngine* eng) | 141 | QScriptValue KWin::MetaScripting::configExists(QScriptContext* ctx, QScriptEngine* eng) | ||
142 | { | 142 | { | ||
143 | QHash<QString, QVariant> scriptConfig = (((ctx->thisObject()).data()).toVariant()).toHash(); | 143 | QHash<QString, QVariant> scriptConfig = (((ctx->thisObject()).data()).toVariant()).toHash(); | ||
144 | QVariant val = scriptConfig.value((ctx->argument(0)).toString(), QVariant()); | 144 | QVariant val = scriptConfig.value((ctx->argument(0)).toString(), QVariant()); | ||
145 | 145 | | |||
146 | return eng->toScriptValue<bool>(val.isValid()); | 146 | return eng->toScriptValue<bool>(val.isValid()); | ||
▲ Show 20 Lines • Show All 95 Lines • Show Last 20 Lines |