Commit 0f668b05 authored by Vlad Zahorodnii's avatar Vlad Zahorodnii
Browse files

scripting: Add js object <-> QRectF/QSizeF/QPointF conversion helpers

The js code contains code such as

    window.frameGeometry = {x: 42, y: 42, width: 100, height: 50};

However, QJSEngine doesn't know how to convert js object to QRect. For
that purpose, we need to register conversion functions.

So far, we kept registering converter functions only for integer based
geometry types, i.e. QRect, QSize and QPoint. In 5.26, Window was ported
to QRectF, QSizeF and QPointF, but the corresponding conversion helpers
were not added.

BUG: 459369


(cherry picked from commit 4696bdaa)
parent 2bcdc8ab
Pipeline #234498 passed with stage
in 27 minutes and 44 seconds
......@@ -58,18 +58,38 @@ static QRect scriptValueToRect(const QJSValue &value)
value.property(QStringLiteral("height")).toInt());
}
static QRectF scriptValueToRectF(const QJSValue &value)
{
return QRectF(value.property(QStringLiteral("x")).toNumber(),
value.property(QStringLiteral("y")).toNumber(),
value.property(QStringLiteral("width")).toNumber(),
value.property(QStringLiteral("height")).toNumber());
}
static QPoint scriptValueToPoint(const QJSValue &value)
{
return QPoint(value.property(QStringLiteral("x")).toInt(),
value.property(QStringLiteral("y")).toInt());
}
static QPointF scriptValueToPointF(const QJSValue &value)
{
return QPointF(value.property(QStringLiteral("x")).toNumber(),
value.property(QStringLiteral("y")).toNumber());
}
static QSize scriptValueToSize(const QJSValue &value)
{
return QSize(value.property(QStringLiteral("width")).toInt(),
value.property(QStringLiteral("height")).toInt());
}
static QSizeF scriptValueToSizeF(const QJSValue &value)
{
return QSizeF(value.property(QStringLiteral("width")).toNumber(),
value.property(QStringLiteral("height")).toNumber());
}
KWin::AbstractScript::AbstractScript(int id, QString scriptName, QString pluginName, QObject *parent)
: QObject(parent)
, m_scriptId(id)
......@@ -113,12 +133,23 @@ KWin::Script::Script(int id, QString scriptName, QString pluginName, QObject *pa
if (!QMetaType::hasRegisteredConverterFunction<QJSValue, QRect>()) {
QMetaType::registerConverter<QJSValue, QRect>(scriptValueToRect);
}
if (!QMetaType::hasRegisteredConverterFunction<QJSValue, QRectF>()) {
QMetaType::registerConverter<QJSValue, QRectF>(scriptValueToRectF);
}
if (!QMetaType::hasRegisteredConverterFunction<QJSValue, QPoint>()) {
QMetaType::registerConverter<QJSValue, QPoint>(scriptValueToPoint);
}
if (!QMetaType::hasRegisteredConverterFunction<QJSValue, QPointF>()) {
QMetaType::registerConverter<QJSValue, QPointF>(scriptValueToPointF);
}
if (!QMetaType::hasRegisteredConverterFunction<QJSValue, QSize>()) {
QMetaType::registerConverter<QJSValue, QSize>(scriptValueToSize);
}
if (!QMetaType::hasRegisteredConverterFunction<QJSValue, QSizeF>()) {
QMetaType::registerConverter<QJSValue, QSizeF>(scriptValueToSizeF);
}
qRegisterMetaType<QList<KWin::Window *>>();
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment