WIP: [scripting] Port to QJSEngine
Changes PlannedPublic

Authored by zzag on Apr 17 2019, 5:40 PM.

Details

Reviewers
None
Summary

QtScript is not well maintained and deprecated in favor of QJSEngine.

This is still WIP because callDBus isn't yet ported.

Diff Detail

Repository
R108 KWin
Branch
port-scripting-to-qjsengine
Lint
Lint OK
Unit
No Unit Test Coverage
Build Status
Buildable 11113
Build 11131: arc lint + arc unit
zzag created this revision.Apr 17 2019, 5:40 PM
Restricted Application added a project: KWin. · View Herald TranscriptApr 17 2019, 5:40 PM
Restricted Application added a subscriber: kwin. · View Herald Transcript
zzag requested review of this revision.Apr 17 2019, 5:40 PM
zzag added a comment.EditedApr 21 2019, 8:13 PM

Current status:

callDBus is still not ported. I have the following list of potential ways how to do it:

  • Forward arguments to C++ implementation where the arguments will parsed and validated (similar to what we have in QScriptEngine implementation);
  • In addition to 4 required arguments, specify N optional QVariant arguments;
  • Expose DBusCall to QJSEngine, so we could wrap callDBus around DBusCall right in js.

In all three cases I'm worried about reply arguments, e.g. if there is any QDBusVariant reply argument, we have to unwrap it.

zzag updated this revision to Diff 56746.Apr 22 2019, 2:00 PM

Implement callDBus.

I went with the second option. Overall, the solution doesn't
look nice, but it works.

In long term, I think it would be nice to introduce a module
for such things, e.g.

const dbus = require('dbus');

dbus.makeMethodCall({
    service: 'org.kde.KWin',
    path: '/KWin',
    interface: 'org.kde.KWin',
    method: 'supportInformation',
    onFinished: (text) => console.log(text),
    onError: (err) => console.log(err)
});

In all three cases I'm worried about reply arguments, e.g. if there is any QDBusVariant reply argument, we have to unwrap it.

That's true of the current state. Not just for QDBusVariant but for any complex type we demarshall that doesn't have a script-friendly metaobject attached.

In addition to 4 required arguments, specify N optional QVariant arguments;

That's what we do for i18n in kdeclarative. It's not super clever but pragmatically easy to read.

In long term, I think it would be nice to introduce a module

If we're thinking long term with API breaks it would be better to have something generic for all Plasma - as well as removing duplication between this and the QQmlEngine scripting.

zzag updated this revision to Diff 56755.Apr 22 2019, 4:55 PM

Cleanup

zzag added a comment.Apr 22 2019, 5:02 PM

That's true of the current state. Not just for QDBusVariant but for any complex type we demarshall that doesn't have a script-friendly metaobject attached.

Is there some nice way to handle this?

zzag added a comment.Apr 22 2019, 7:57 PM

Argh, it's not possible anymore to do

client.geometry = { x: 0, y: 0, width: 42, height: 73 };

Potential solution would be to introduce some sort of Qt.rect, but that would break existing scripts. :(

This comment was removed by davidedmundson.
zzag planned changes to this revision.EditedApr 23 2019, 8:39 PM

Given that we have to break compatibility, KWin 6 is probably a good time to port scripting.