scripting: Fix dbus calls with numeric types
DBus calls with numeric types other than int and double were not working(eg. uint16, int16, etc).
This was because the JavaScript types were converted by QJSValue::toVariant(), which only supports int and double.
This change adds support for the other numeric types which JavaScript does not support by introspecting the type signature of the DBus method and converting the JavaScript value to the appropriate QVariant type.
This is important because if one tries to call a DBus method with an incorrect type signature, the call will fail.
Test plan
- Monitor kwin script output:
journalctl -b -f | grep -i "kwin"
-
Open the KWin Scripting Console
-
Call the
Inhibit
method onorg.freedesktop.Notifications
, which works as expected:
callDBus(
"org.freedesktop.Notifications",
"/org/freedesktop/Notifications",
"org.freedesktop.Notifications",
"Inhibit",
"",
"",
{},
function (reply) {
console.info("Callback. Reply: " + reply);
}
);
-
Check the output of the journal, which should show the message "Callback. Reply: $number" - I'll assume it was 1 for the sake of this example. Do Not Disturb should have been enabled.
-
Call the method
UnInhibit
onorg.freedesktop.Notifications
, which expects a uint32 as argument:
callDBus(
"org.freedesktop.Notifications",
"/org/freedesktop/Notifications",
"org.freedesktop.Notifications",
"UnInhibit",
1,
function () {
console.info("UnInhibit callback.");
}
);
Step 5 fails on master, succeeds on the fix branch.