[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [kwin/scripting2] /: working shortcuts
From:       David Edmundson <null () kde ! org>
Date:       2018-07-31 21:37:18
Message-ID: E1fkcKU-0001yG-IM () code ! kde ! org
[Download RAW message or body]

Git commit 53956064d91d96a7ced4d27bacaee2776b7ff2c6 by David Edmundson.
Committed on 31/07/2018 at 20:28.
Pushed by davidedmundson into branch 'scripting2'.

working shortcuts

M  +8    -30   autotests/integration/effects/scripted_effects_test.cpp
M  +23   -12   scripting/scriptedeffect.cpp
M  +4    -8    scripting/scriptedeffect.h

https://commits.kde.org/kwin/53956064d91d96a7ced4d27bacaee2776b7ff2c6

diff --git a/autotests/integration/effects/scripted_effects_test.cpp \
b/autotests/integration/effects/scripted_effects_test.cpp index 903547c65..c8a878ac3 \
                100644
--- a/autotests/integration/effects/scripted_effects_test.cpp
+++ b/autotests/integration/effects/scripted_effects_test.cpp
@@ -75,42 +75,20 @@ class ScriptedEffectWithDebugSpy : public KWin::ScriptedEffect
 public:
     bool load(const QString &name);
     using AnimationEffect::state;
-    Q_INVOKABLE void sendTestResponse(const QString &out);
+    Q_INVOKABLE void sendTestResponse(const QString &out); //proxies triggers out \
from the tests +    QList<QAction*> actions(); //returns any QActions owned by the \
ScriptEngine  signals:
     void testOutput(const QString &data);
 };
 
-class SendTestResponseContext : public QObject
-{
-<<<<<<< HEAD
-    auto *script = qobject_cast<ScriptedEffectWithDebugSpy*>(context->callee().data().toQObject());
                
-    QString result;
-    for (int i = 0; i < context->argumentCount(); ++i) {
-        if (i > 0) {
-            result.append(QLatin1Char(' '));
-        }
-        result.append(context->argument(i).toString());
-    }
-    emit script->testOutput(result);
-=======
-    Q_OBJECT
-public:
-    SendTestResponseContext(ScriptedEffectWithDebugSpy *scriptedEffect);
-private:
-    ScriptedEffectWithDebugSpy *m_scriptedEffect;
-};
-
->>>>>>> 87ad4e45f... port to QJSEngine
-
-SendTestResponseContext::SendTestResponseContext(ScriptedEffectWithDebugSpy \
                *scriptedEffect):
-    QObject(scriptedEffect),
-    m_scriptedEffect(scriptedEffect)
+void ScriptedEffectWithDebugSpy::sendTestResponse(const QString &out)
 {
+    emit testOutput(out);
 }
 
-void ScriptedEffectWithDebugSpy::sendTestResponse(const QString &out)
+QList<QAction*> ScriptedEffectWithDebugSpy::actions()
 {
-    emit testOutput(out);
+    return findChildren<QAction*>(QString(), Qt::FindDirectChildrenOnly);
 }
 
 bool ScriptedEffectWithDebugSpy::load(const QString &name)
@@ -247,8 +225,8 @@ void ScriptedEffectsTest::testShortcuts()
     auto *effect = new ScriptedEffectWithDebugSpy; // cleaned up in ::clean
     QSignalSpy effectOutputSpy(effect, &ScriptedEffectWithDebugSpy::testOutput);
     QVERIFY(effect->load("shortcutsTest"));
-    QCOMPARE(effect->shortcutCallbacks().count(), 1);
-    QAction *action = effect->shortcutCallbacks().keys()[0];
+    QCOMPARE(effect->actions().count(), 1);
+    auto action = effect->actions()[0];
     QCOMPARE(action->objectName(), "testShortcut");
     QCOMPARE(action->text(), "Test Shortcut");
     QCOMPARE(KGlobalAccel::self()->shortcut(action).first(), \
                QKeySequence("Meta+Shift+Y"));
diff --git a/scripting/scriptedeffect.cpp b/scripting/scriptedeffect.cpp
index 0e7967a1c..15dcb73ef 100644
--- a/scripting/scriptedeffect.cpp
+++ b/scripting/scriptedeffect.cpp
@@ -495,6 +495,13 @@ bool ScriptedEffect::init(const QString &effectName, const \
                QString &pathToScript
     engine()->globalObject().setProperty("unregisterScreenEdge", \
                selfWrapper.property("unregisterScreenEdge"));
     engine()->globalObject().setProperty("registerTouchScreenEdge", \
                selfWrapper.property("registerTouchScreenEdge"));
     engine()->globalObject().setProperty("unregisterTouchScreenEdge", \
selfWrapper.property("unregisterTouchScreenEdge")); +
+    engine()->globalObject().setProperty("animate", \
selfWrapper.property("animate")); +    \
engine()->globalObject().setProperty("retarget", selfWrapper.property("retarget")); + \
engine()->globalObject().setProperty("set", selfWrapper.property("set")); +    \
engine()->globalObject().setProperty("cancel", selfWrapper.property("cancel")); +
+
 //TODO
 //    fpx2
 //    print
@@ -504,7 +511,6 @@ bool ScriptedEffect::init(const QString &effectName, const \
QString &pathToScript  
 
 //    MetaScripting::registration(m_engine);
-//    qScriptRegisterMetaType<KEffectWindowRef>(m_engine, effectWindowToScriptValue, \
effectWindowFromScriptValue);  //    qScriptRegisterMetaType<KWin::FPx2>(m_engine, \
fpx2ToScriptValue, fpx2FromScriptValue);  //    \
qScriptRegisterSequenceMetaType<QList< KWin::EffectWindow* > >(m_engine);  //    // \
add our print @@ -516,6 +522,7 @@ bool ScriptedEffect::init(const QString \
&effectName, const QString &pathToScript  //    registerScreenEdgeFunction(this, \
m_engine, kwinScriptScreenEdge);  //    registerTouchScreenEdgeFunction(this, \
m_engine, kwinRegisterTouchScreenEdge);  //    \
unregisterTouchScreenEdgeFunction(this, m_engine, kwinUnregisterTouchScreenEdge); +
 //    // add the animate method
 //    QJSValue animateFunc = m_engine->newFunction(kwinEffectAnimate);
 //    animateFunc.setData(m_engine->newQObject(this));
@@ -558,6 +565,16 @@ int ScriptedEffect::animationTime(int defaultTime) const
     return Effect::animationTime(defaultTime);
 }
 
+bool ScriptedEffect::registerScreenEdge(int edge, const QJSValue &callback)
+{
+    return true;
+}
+
+bool ScriptedEffect::unregisterScreenEdge(int edge)
+{
+    return true;
+}
+
 int ScriptedEffect::displayWidth() const
 {
     return screens()->displaySize().width();
@@ -635,16 +652,11 @@ bool ScriptedEffect::registerShortcut(const QString \
&objectName, const QString &  a->setText(text);
     const QKeySequence shortcut = QKeySequence(keySequence);
     KGlobalAccel::self()->setShortcut(a, QList<QKeySequence>() << shortcut);
-    m_shortcutCallbacks.insert(a, callback);
     input()->registerShortcut(shortcut, a);
 
     connect(a, &QAction::triggered, this, [this, a, callback]() {
         QJSValue c(callback);
 
-        auto it = m_shortcutCallbacks.constFind(a);
-        if (it == m_shortcutCallbacks.constEnd()) {
-            return;
-        }
 //        QJSValue value(it.value());
         //DAVE - WTF is this for? why would a JS script need to know the action? it \
can just use a different callback?  //        arguments << m_engine->newQObject(a);
@@ -668,7 +680,7 @@ QVariant ScriptedEffect::readConfig(const QString &key, const \
QVariant defaultVa  return m_config->property(key);
 }
 
-bool ScriptedEffect::registerTouchScreenCallback(int edge, const QJSValue &callback)
+bool ScriptedEffect::registerTouchScreenEdge(int edge, const QJSValue &callback)
 {
     if (m_touchScreenEdgeCallbacks.constFind(edge) != \
m_touchScreenEdgeCallbacks.constEnd()) {  return false;
@@ -680,12 +692,12 @@ bool ScriptedEffect::registerTouchScreenCallback(int edge, \
const QJSValue &callb  invoke.call();
         }
     );
-    const auto ret = ScreenEdges::self()->reserveTouch(KWin::ElectricBorder(edge), \
action); +    ScreenEdges::self()->reserveTouch(KWin::ElectricBorder(edge), action);
     m_touchScreenEdgeCallbacks.insert(edge, action);
-    return ret;
+    return true;
 }
 
-bool ScriptedEffect::unregisterTouchScreenCallback(int edge)
+bool ScriptedEffect::unregisterTouchScreenEdge(int edge)
 {
     auto it = m_touchScreenEdgeCallbacks.find(edge);
     if (it == m_touchScreenEdgeCallbacks.end()) {
@@ -693,9 +705,8 @@ bool ScriptedEffect::unregisterTouchScreenCallback(int edge)
     }
     delete it.value();
 
-    //DAVE
     m_touchScreenEdgeCallbacks.erase(it);
-    return ret;
+    return true;
 }
 
 QJSEngine *ScriptedEffect::engine() const
diff --git a/scripting/scriptedeffect.h b/scripting/scriptedeffect.h
index 87fab9429..939e498ea 100644
--- a/scripting/scriptedeffect.h
+++ b/scripting/scriptedeffect.h
@@ -89,13 +89,12 @@ public:
     Q_SCRIPTABLE int displayHeight() const;
     Q_SCRIPTABLE int animationTime(int defaultTime) const;
 
-    Q_SCRIPTABLE void registerScreenEdge(int edge, const QJSValue &callback);
-    Q_SCRIPTABLE void unregisterScreenEdge(int edge);
-    Q_SCRIPTABLE void registerTouchScreenEdge(int edge, const QJSValue &callback);
-    Q_SCRIPTABLE void unregisterTouchScreenEdge(int edge);
+    Q_SCRIPTABLE bool registerScreenEdge(int edge, const QJSValue &callback);
+    Q_SCRIPTABLE bool unregisterScreenEdge(int edge);
+    Q_SCRIPTABLE bool registerTouchScreenEdge(int edge, const QJSValue &callback);
+    Q_SCRIPTABLE bool unregisterTouchScreenEdge(int edge);
 
 
-    void registerShortcut(QAction *a, QJSValue callback);
     QHash<int, QList<QJSValue > > &screenEdgeCallbacks() {
         return m_screenEdgeCallbacks;
     }
@@ -119,13 +118,10 @@ protected:
     bool init(const QString &effectName, const QString &pathToScript);
     void animationEnded(KWin::EffectWindow *w, Attribute a, uint meta);
 
-private Q_SLOTS:
-    void globalShortcutTriggered();
 private:
     QJSEngine *m_engine;
     QString m_effectName;
     QString m_scriptFile;
-    QHash<QAction*, QJSValue> m_shortcutCallbacks; //remove
     QHash<int, QList<QJSValue> > m_screenEdgeCallbacks;
     KConfigLoader *m_config;
     int m_chainPosition;


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic