Changeset View
Changeset View
Standalone View
Standalone View
scripting/scriptedeffect.cpp
Show First 20 Lines • Show All 85 Lines • ▼ Show 20 Line(s) | 85 | { | |||
---|---|---|---|---|---|
86 | return globalShortcut<KWin::ScriptedEffect*>(context, engine); | 86 | return globalShortcut<KWin::ScriptedEffect*>(context, engine); | ||
87 | } | 87 | } | ||
88 | 88 | | |||
89 | QScriptValue kwinScriptScreenEdge(QScriptContext *context, QScriptEngine *engine) | 89 | QScriptValue kwinScriptScreenEdge(QScriptContext *context, QScriptEngine *engine) | ||
90 | { | 90 | { | ||
91 | return registerScreenEdge<KWin::ScriptedEffect*>(context, engine); | 91 | return registerScreenEdge<KWin::ScriptedEffect*>(context, engine); | ||
92 | } | 92 | } | ||
93 | 93 | | |||
94 | QScriptValue kwinRegisterTouchScreenEdge(QScriptContext *context, QScriptEngine *engine) | ||||
95 | { | ||||
96 | return registerTouchScreenEdge<KWin::ScriptedEffect*>(context, engine); | ||||
97 | } | ||||
98 | | ||||
99 | QScriptValue kwinUnregisterTouchScreenEdge(QScriptContext *context, QScriptEngine *engine) | ||||
100 | { | ||||
101 | return unregisterTouchScreenEdge<KWin::ScriptedEffect*>(context, engine); | ||||
102 | } | ||||
103 | | ||||
94 | struct AnimationSettings { | 104 | struct AnimationSettings { | ||
95 | enum { Type = 1<<0, Curve = 1<<1, Delay = 1<<2, Duration = 1<<3 }; | 105 | enum { Type = 1<<0, Curve = 1<<1, Delay = 1<<2, Duration = 1<<3 }; | ||
96 | AnimationEffect::Attribute type; | 106 | AnimationEffect::Attribute type; | ||
97 | QEasingCurve::Type curve; | 107 | QEasingCurve::Type curve; | ||
98 | FPx2 from; | 108 | FPx2 from; | ||
99 | FPx2 to; | 109 | FPx2 to; | ||
100 | int delay; | 110 | int delay; | ||
101 | uint duration; | 111 | uint duration; | ||
▲ Show 20 Lines • Show All 411 Lines • ▼ Show 20 Line(s) | 508 | #endif | |||
513 | // add displayWidth and displayHeight | 523 | // add displayWidth and displayHeight | ||
514 | QScriptValue displayWidthFunc = m_engine->newFunction(kwinEffectDisplayWidth); | 524 | QScriptValue displayWidthFunc = m_engine->newFunction(kwinEffectDisplayWidth); | ||
515 | m_engine->globalObject().setProperty(QStringLiteral("displayWidth"), displayWidthFunc); | 525 | m_engine->globalObject().setProperty(QStringLiteral("displayWidth"), displayWidthFunc); | ||
516 | QScriptValue displayHeightFunc = m_engine->newFunction(kwinEffectDisplayHeight); | 526 | QScriptValue displayHeightFunc = m_engine->newFunction(kwinEffectDisplayHeight); | ||
517 | m_engine->globalObject().setProperty(QStringLiteral("displayHeight"), displayHeightFunc); | 527 | m_engine->globalObject().setProperty(QStringLiteral("displayHeight"), displayHeightFunc); | ||
518 | // add global Shortcut | 528 | // add global Shortcut | ||
519 | registerGlobalShortcutFunction(this, m_engine, kwinScriptGlobalShortcut); | 529 | registerGlobalShortcutFunction(this, m_engine, kwinScriptGlobalShortcut); | ||
520 | registerScreenEdgeFunction(this, m_engine, kwinScriptScreenEdge); | 530 | registerScreenEdgeFunction(this, m_engine, kwinScriptScreenEdge); | ||
531 | registerTouchScreenEdgeFunction(this, m_engine, kwinRegisterTouchScreenEdge); | ||||
532 | unregisterTouchScreenEdgeFunction(this, m_engine, kwinUnregisterTouchScreenEdge); | ||||
521 | // add the animate method | 533 | // add the animate method | ||
522 | QScriptValue animateFunc = m_engine->newFunction(kwinEffectAnimate); | 534 | QScriptValue animateFunc = m_engine->newFunction(kwinEffectAnimate); | ||
523 | animateFunc.setData(m_engine->newQObject(this)); | 535 | animateFunc.setData(m_engine->newQObject(this)); | ||
524 | m_engine->globalObject().setProperty(QStringLiteral("animate"), animateFunc); | 536 | m_engine->globalObject().setProperty(QStringLiteral("animate"), animateFunc); | ||
525 | 537 | | |||
526 | // and the set variant | 538 | // and the set variant | ||
527 | QScriptValue setFunc = m_engine->newFunction(kwinEffectSet); | 539 | QScriptValue setFunc = m_engine->newFunction(kwinEffectSet); | ||
528 | setFunc.setData(m_engine->newQObject(this)); | 540 | setFunc.setData(m_engine->newQObject(this)); | ||
▲ Show 20 Lines • Show All 103 Lines • ▼ Show 20 Line(s) | |||||
632 | QVariant ScriptedEffect::readConfig(const QString &key, const QVariant defaultValue) | 644 | QVariant ScriptedEffect::readConfig(const QString &key, const QVariant defaultValue) | ||
633 | { | 645 | { | ||
634 | if (!m_config) { | 646 | if (!m_config) { | ||
635 | return defaultValue; | 647 | return defaultValue; | ||
636 | } | 648 | } | ||
637 | return m_config->property(key); | 649 | return m_config->property(key); | ||
638 | } | 650 | } | ||
639 | 651 | | |||
652 | bool ScriptedEffect::registerTouchScreenCallback(int edge, QScriptValue callback) | ||||
653 | { | ||||
654 | if (m_touchScreenEdgeCallbacks.constFind(edge) != m_touchScreenEdgeCallbacks.constEnd()) { | ||||
655 | return false; | ||||
656 | } | ||||
657 | QAction *action = new QAction(this); | ||||
658 | connect(action, &QAction::triggered, this, | ||||
659 | [callback] { | ||||
660 | QScriptValue invoke(callback); | ||||
661 | invoke.call(); | ||||
662 | } | ||||
663 | ); | ||||
664 | ScreenEdges::self()->reserveTouch(KWin::ElectricBorder(edge), action); | ||||
665 | m_touchScreenEdgeCallbacks.insert(edge, action); | ||||
666 | return true; | ||||
667 | } | ||||
668 | | ||||
669 | bool ScriptedEffect::unregisterTouchScreenCallback(int edge) | ||||
670 | { | ||||
671 | auto it = m_touchScreenEdgeCallbacks.find(edge); | ||||
672 | if (it == m_touchScreenEdgeCallbacks.constEnd()) { | ||||
673 | return false; | ||||
674 | } | ||||
675 | delete it.value(); | ||||
676 | m_touchScreenEdgeCallbacks.erase(it); | ||||
677 | return true; | ||||
678 | } | ||||
679 | | ||||
640 | } // namespace | 680 | } // namespace |