Changeset View
Changeset View
Standalone View
Standalone View
scripting/scriptingutils.h
Show First 20 Lines • Show All 190 Lines • ▼ Show 20 Line(s) | 189 | if (it == script->screenEdgeCallbacks().end()) { | |||
---|---|---|---|---|---|
191 | return engine->newVariant(false); | 191 | return engine->newVariant(false); | ||
192 | } | 192 | } | ||
193 | ScreenEdges::self()->unreserve(static_cast<KWin::ElectricBorder>(edge), script); | 193 | ScreenEdges::self()->unreserve(static_cast<KWin::ElectricBorder>(edge), script); | ||
194 | script->screenEdgeCallbacks().erase(it); | 194 | script->screenEdgeCallbacks().erase(it); | ||
195 | return engine->newVariant(true); | 195 | return engine->newVariant(true); | ||
196 | } | 196 | } | ||
197 | 197 | | |||
198 | template<class T> | 198 | template<class T> | ||
199 | QScriptValue registerTouchScreenEdge(QScriptContext *context, QScriptEngine *engine) | ||||
200 | { | ||||
201 | auto script = qobject_cast<T>(context->callee().data().toQObject()); | ||||
202 | if (!script) { | ||||
203 | return engine->undefinedValue(); | ||||
204 | } | ||||
205 | if (!validateParameters(context, 2, 2)) { | ||||
206 | return engine->undefinedValue(); | ||||
207 | } | ||||
208 | if (!validateArgumentType<int>(context)) { | ||||
209 | return engine->undefinedValue(); | ||||
210 | } | ||||
211 | if (!context->argument(1).isFunction()) { | ||||
212 | context->throwError(QScriptContext::SyntaxError, i18nc("KWin Scripting error thrown due to incorrect argument", | ||||
213 | "Second argument to registerTouchScreenEdge needs to be a callback")); | ||||
214 | } | ||||
215 | const int edge = context->argument(0).toVariant().toInt(); | ||||
216 | const auto ret = script->registerTouchScreenCallback(edge, context->argument(1)); | ||||
217 | return engine->newVariant(ret); | ||||
218 | } | ||||
219 | | ||||
220 | template<class T> | ||||
221 | QScriptValue unregisterTouchScreenEdge(QScriptContext *context, QScriptEngine *engine) | ||||
222 | { | ||||
223 | auto script = qobject_cast<T>(context->callee().data().toQObject()); | ||||
224 | if (!script) { | ||||
225 | return engine->undefinedValue(); | ||||
226 | } | ||||
227 | if (!validateParameters(context, 1, 1)) { | ||||
228 | return engine->undefinedValue(); | ||||
229 | } | ||||
230 | if (!validateArgumentType<int>(context)) { | ||||
231 | return engine->undefinedValue(); | ||||
232 | } | ||||
233 | const int edge = context->argument(0).toVariant().toInt(); | ||||
234 | const auto ret = script->unregisterTouchScreenCallback(edge); | ||||
235 | return engine->newVariant(ret); | ||||
236 | } | ||||
237 | | ||||
238 | template<class T> | ||||
199 | QScriptValue registerUserActionsMenu(QScriptContext *context, QScriptEngine *engine) | 239 | QScriptValue registerUserActionsMenu(QScriptContext *context, QScriptEngine *engine) | ||
200 | { | 240 | { | ||
201 | T script = qobject_cast<T>(context->callee().data().toQObject()); | 241 | T script = qobject_cast<T>(context->callee().data().toQObject()); | ||
202 | if (!script) { | 242 | if (!script) { | ||
203 | return engine->undefinedValue(); | 243 | return engine->undefinedValue(); | ||
204 | } | 244 | } | ||
205 | if (!validateParameters(context, 1, 1)) { | 245 | if (!validateParameters(context, 1, 1)) { | ||
206 | return engine->undefinedValue(); | 246 | return engine->undefinedValue(); | ||
▲ Show 20 Lines • Show All 91 Lines • ▼ Show 20 Line(s) | |||||
298 | 338 | | |||
299 | inline void unregisterScreenEdgeFunction(QObject *parent, QScriptEngine *engine, QScriptEngine::FunctionSignature function) | 339 | inline void unregisterScreenEdgeFunction(QObject *parent, QScriptEngine *engine, QScriptEngine::FunctionSignature function) | ||
300 | { | 340 | { | ||
301 | QScriptValue shortcutFunc = engine->newFunction(function); | 341 | QScriptValue shortcutFunc = engine->newFunction(function); | ||
302 | shortcutFunc.setData(engine->newQObject(parent)); | 342 | shortcutFunc.setData(engine->newQObject(parent)); | ||
303 | engine->globalObject().setProperty(QStringLiteral("unregisterScreenEdge"), shortcutFunc); | 343 | engine->globalObject().setProperty(QStringLiteral("unregisterScreenEdge"), shortcutFunc); | ||
304 | } | 344 | } | ||
305 | 345 | | |||
346 | inline void registerTouchScreenEdgeFunction(QObject *parent, QScriptEngine *engine, QScriptEngine::FunctionSignature function) | ||||
347 | { | ||||
348 | QScriptValue touchScreenFunc = engine->newFunction(function); | ||||
349 | touchScreenFunc.setData(engine->newQObject(parent)); | ||||
350 | engine->globalObject().setProperty(QStringLiteral("registerTouchScreenEdge"), touchScreenFunc); | ||||
351 | } | ||||
352 | | ||||
353 | inline void unregisterTouchScreenEdgeFunction(QObject *parent, QScriptEngine *engine, QScriptEngine::FunctionSignature function) | ||||
354 | { | ||||
355 | QScriptValue touchScreenFunc = engine->newFunction(function); | ||||
356 | touchScreenFunc.setData(engine->newQObject(parent)); | ||||
357 | engine->globalObject().setProperty(QStringLiteral("unregisterTouchScreenEdge"), touchScreenFunc); | ||||
358 | } | ||||
359 | | ||||
306 | inline void registerUserActionsMenuFunction(QObject *parent, QScriptEngine *engine, QScriptEngine::FunctionSignature function) | 360 | inline void registerUserActionsMenuFunction(QObject *parent, QScriptEngine *engine, QScriptEngine::FunctionSignature function) | ||
307 | { | 361 | { | ||
308 | QScriptValue shortcutFunc = engine->newFunction(function); | 362 | QScriptValue shortcutFunc = engine->newFunction(function); | ||
309 | shortcutFunc.setData(engine->newQObject(parent)); | 363 | shortcutFunc.setData(engine->newQObject(parent)); | ||
310 | engine->globalObject().setProperty(QStringLiteral("registerUserActionsMenu"), shortcutFunc); | 364 | engine->globalObject().setProperty(QStringLiteral("registerUserActionsMenu"), shortcutFunc); | ||
311 | } | 365 | } | ||
312 | 366 | | |||
313 | } // namespace KWin | 367 | } // namespace KWin | ||
314 | 368 | | |||
315 | #endif // KWIN_SCRIPTINGUTILS_H | 369 | #endif // KWIN_SCRIPTINGUTILS_H |