Support for KWin.registerShortcut() in declarative script

Summary:
registerShortcut is available to javascript KWin scripts but was not
available to those written in declarative script.

BUG: 340225
FIXED-IN: 5.8.4
REVIEW: 129250
This commit is contained in:
James Pike 2016-10-30 01:00:22 +01:00
parent 9e3fb47259
commit 0c4c529d68
2 changed files with 24 additions and 0 deletions

View file

@ -587,6 +587,28 @@ void KWin::JSEngineGlobalMethodsWrapper::registerWindow(QQuickWindow *window)
});
}
bool KWin::JSEngineGlobalMethodsWrapper::registerShortcut(const QString &name, const QString &text, const QKeySequence& keys, QJSValue function)
{
if (!function.isCallable()) {
qCDebug(KWIN_SCRIPTING) << "Fourth and final argument must be a javascript function";
return false;
}
QAction *a = new QAction(this);
a->setObjectName(name);
a->setText(text);
const QKeySequence shortcut = QKeySequence(keys);
KGlobalAccel::self()->setShortcut(a, QList<QKeySequence>{shortcut});
KWin::input()->registerShortcut(shortcut, a);
connect(a, &QAction::triggered, this, [=]() mutable {
QJSValueList arguments;
arguments << Scripting::self()->qmlEngine()->toScriptValue(a);
function.call(arguments);
});
return true;
}
KWin::Scripting *KWin::Scripting::s_self = nullptr;
KWin::Scripting *KWin::Scripting::create(QObject *parent)

View file

@ -28,6 +28,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <QHash>
#include <QStringList>
#include <QtScript/QScriptEngineAgent>
#include <QtQml/QJSValue>
class QQmlComponent;
class QQmlContext;
@ -318,6 +319,7 @@ public:
public Q_SLOTS:
QVariant readConfig(const QString &key, QVariant defaultValue = QVariant());
void registerWindow(QQuickWindow *window);
bool registerShortcut(const QString &name, const QString &text, const QKeySequence& keys, QJSValue function);
private:
DeclarativeScript *m_script;