Merge branch 'Plasma/5.8'

remotes/origin/bshah/hwcomposer_testing
Martin Gräßlin 10 years ago
commit 13f142b1bf
  1. 1
      autotests/integration/effects/CMakeLists.txt
  2. 387
      autotests/integration/effects/slidingpopups_test.cpp
  3. 70
      autotests/integration/move_resize_window_test.cpp
  4. 15
      pointer_input.cpp
  5. 1
      pointer_input.h
  6. 22
      scripting/scripting.cpp
  7. 2
      scripting/scripting.h

@ -1,3 +1,4 @@
if (XCB_ICCCM_FOUND)
integrationTest(NAME testTranslucency SRCS translucency_test.cpp LIBS XCB::ICCCM)
integrationTest(NAME testSlidingPopups SRCS slidingpopups_test.cpp LIBS XCB::ICCCM)
endif()

@ -0,0 +1,387 @@
/********************************************************************
KWin - the KDE window manager
This file is part of the KDE project.
Copyright (C) 2016 Martin Gräßlin <mgraesslin@kde.org>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*********************************************************************/
#include "kwin_wayland_test.h"
#include "composite.h"
#include "effects.h"
#include "effectloader.h"
#include "cursor.h"
#include "platform.h"
#include "scene_qpainter.h"
#include "shell_client.h"
#include "wayland_server.h"
#include "workspace.h"
#include "effect_builtins.h"
#include <KConfigGroup>
#include <KWayland/Client/connection_thread.h>
#include <KWayland/Client/registry.h>
#include <KWayland/Client/surface.h>
#include <KWayland/Client/shell.h>
#include <KWayland/Client/slide.h>
#include <netwm.h>
#include <xcb/xcb_icccm.h>
using namespace KWin;
static const QString s_socketName = QStringLiteral("wayland_test_effects_slidingpopups-0");
class SlidingPopupsTest : public QObject
{
Q_OBJECT
private Q_SLOTS:
void initTestCase();
void init();
void cleanup();
void testWithOtherEffect_data();
void testWithOtherEffect();
void testWithOtherEffectWayland_data();
void testWithOtherEffectWayland();
};
void SlidingPopupsTest::initTestCase()
{
qRegisterMetaType<KWin::ShellClient*>();
qRegisterMetaType<KWin::AbstractClient*>();
qRegisterMetaType<KWin::Effect*>();
QSignalSpy workspaceCreatedSpy(kwinApp(), &Application::workspaceCreated);
QVERIFY(workspaceCreatedSpy.isValid());
kwinApp()->platform()->setInitialWindowSize(QSize(1280, 1024));
QVERIFY(waylandServer()->init(s_socketName.toLocal8Bit()));
// disable all effects - we don't want to have it interact with the rendering
auto config = KSharedConfig::openConfig(QString(), KConfig::SimpleConfig);
KConfigGroup plugins(config, QStringLiteral("Plugins"));
ScriptedEffectLoader loader;
const auto builtinNames = BuiltInEffects::availableEffectNames() << loader.listOfKnownEffects();
for (QString name : builtinNames) {
plugins.writeEntry(name + QStringLiteral("Enabled"), false);
}
config->sync();
kwinApp()->setConfig(config);
// TODO: make effects use KWin's config directly
KSharedConfig::openConfig(QStringLiteral(KWIN_CONFIG), KConfig::NoGlobals)->group("Effect-Wobbly").writeEntry(QStringLiteral("Settings"), QStringLiteral("Custom"));
KSharedConfig::openConfig(QStringLiteral(KWIN_CONFIG), KConfig::NoGlobals)->group("Effect-Wobbly").writeEntry(QStringLiteral("OpenEffect"), true);
KSharedConfig::openConfig(QStringLiteral(KWIN_CONFIG), KConfig::NoGlobals)->group("Effect-Wobbly").writeEntry(QStringLiteral("CloseEffect"), true);
if (QFile::exists(QStringLiteral("/dev/dri/card0"))) {
qputenv("KWIN_COMPOSE", QByteArrayLiteral("O2"));
}
qputenv("KWIN_EFFECTS_FORCE_ANIMATIONS", "1");
kwinApp()->start();
QVERIFY(workspaceCreatedSpy.wait());
QVERIFY(Compositor::self());
}
void SlidingPopupsTest::init()
{
QVERIFY(Test::setupWaylandConnection(s_socketName, Test::AdditionalWaylandInterface::Decoration));
}
void SlidingPopupsTest::cleanup()
{
Test::destroyWaylandConnection();
EffectsHandlerImpl *e = static_cast<EffectsHandlerImpl*>(effects);
while (!e->loadedEffects().isEmpty()) {
const QString effect = e->loadedEffects().first();
e->unloadEffect(effect);
QVERIFY(!e->isEffectLoaded(effect));
}
}
struct XcbConnectionDeleter
{
static inline void cleanup(xcb_connection_t *pointer)
{
xcb_disconnect(pointer);
}
};
void SlidingPopupsTest::testWithOtherEffect_data()
{
QTest::addColumn<QStringList>("effectsToLoad");
QTest::newRow("scale, slide") << QStringList{QStringLiteral("kwin4_effect_scalein"), QStringLiteral("slidingpopups")};
QTest::newRow("slide, scale") << QStringList{QStringLiteral("slidingpopups"), QStringLiteral("kwin4_effect_scalein")};
QTest::newRow("fade, slide") << QStringList{QStringLiteral("kwin4_effect_fade"), QStringLiteral("slidingpopups")};
QTest::newRow("slide, fade") << QStringList{QStringLiteral("slidingpopups"), QStringLiteral("kwin4_effect_fade")};
if (effects->compositingType() & KWin::OpenGLCompositing) {
QTest::newRow("glide, slide") << QStringList{QStringLiteral("glide"), QStringLiteral("slidingpopups")};
QTest::newRow("slide, glide") << QStringList{QStringLiteral("slidingpopups"), QStringLiteral("glide")};
QTest::newRow("wobblywindows, slide") << QStringList{QStringLiteral("wobblywindows"), QStringLiteral("slidingpopups")};
QTest::newRow("slide, wobblywindows") << QStringList{QStringLiteral("slidingpopups"), QStringLiteral("wobblywindows")};
QTest::newRow("fallapart, slide") << QStringList{QStringLiteral("fallapart"), QStringLiteral("slidingpopups")};
QTest::newRow("slide, fallapart") << QStringList{QStringLiteral("slidingpopups"), QStringLiteral("fallapart")};
}
}
void SlidingPopupsTest::testWithOtherEffect()
{
// this test verifies that slidingpopups effect grabs the window added role
// independently of the sequence how the effects are loaded.
// see BUG 336866
EffectsHandlerImpl *e = static_cast<EffectsHandlerImpl*>(effects);
// find the effectsloader
auto effectloader = e->findChild<AbstractEffectLoader*>();
QVERIFY(effectloader);
QSignalSpy effectLoadedSpy(effectloader, &AbstractEffectLoader::effectLoaded);
QVERIFY(effectLoadedSpy.isValid());
Effect *slidingPoupus = nullptr;
Effect *otherEffect = nullptr;
QFETCH(QStringList, effectsToLoad);
for (const QString &effectName : effectsToLoad) {
QVERIFY(!e->isEffectLoaded(effectName));
QVERIFY(e->loadEffect(effectName));
QVERIFY(e->isEffectLoaded(effectName));
QCOMPARE(effectLoadedSpy.count(), 1);
Effect *effect = effectLoadedSpy.first().first().value<Effect*>();
if (effectName == QStringLiteral("slidingpopups")) {
slidingPoupus = effect;
} else {
otherEffect = effect;
}
effectLoadedSpy.clear();
}
QVERIFY(slidingPoupus);
QVERIFY(otherEffect);
QVERIFY(!slidingPoupus->isActive());
QVERIFY(!otherEffect->isActive());
// give the compositor some time to render
QTest::qWait(50);
QSignalSpy windowAddedSpy(effects, &EffectsHandler::windowAdded);
QVERIFY(windowAddedSpy.isValid());
// create an xcb window
QScopedPointer<xcb_connection_t, XcbConnectionDeleter> c(xcb_connect(nullptr, nullptr));
QVERIFY(!xcb_connection_has_error(c.data()));
const QRect windowGeometry(0, 0, 100, 200);
xcb_window_t w = xcb_generate_id(c.data());
xcb_create_window(c.data(), XCB_COPY_FROM_PARENT, w, rootWindow(),
windowGeometry.x(),
windowGeometry.y(),
windowGeometry.width(),
windowGeometry.height(),
0, XCB_WINDOW_CLASS_INPUT_OUTPUT, XCB_COPY_FROM_PARENT, 0, nullptr);
xcb_size_hints_t hints;
memset(&hints, 0, sizeof(hints));
xcb_icccm_size_hints_set_position(&hints, 1, windowGeometry.x(), windowGeometry.y());
xcb_icccm_size_hints_set_size(&hints, 1, windowGeometry.width(), windowGeometry.height());
xcb_icccm_set_wm_normal_hints(c.data(), w, &hints);
NETWinInfo winInfo(c.data(), w, rootWindow(), NET::Properties(), NET::Properties2());
winInfo.setWindowType(NET::Normal);
// and get the slide atom
const QByteArray effectAtomName = QByteArrayLiteral("_KDE_SLIDE");
xcb_intern_atom_cookie_t atomCookie = xcb_intern_atom_unchecked(c.data(), false, effectAtomName.length(), effectAtomName.constData());
const int size = 2;
int32_t data[size];
data[0] = 0;
data[1] = 0;
QScopedPointer<xcb_intern_atom_reply_t, QScopedPointerPodDeleter> atom(xcb_intern_atom_reply(c.data(), atomCookie, nullptr));
QVERIFY(!atom.isNull());
xcb_change_property(c.data(), XCB_PROP_MODE_REPLACE, w, atom->atom, atom->atom, 32, size, data);
xcb_map_window(c.data(), w);
xcb_flush(c.data());
// we should get a client for it
QSignalSpy windowCreatedSpy(workspace(), &Workspace::clientAdded);
QVERIFY(windowCreatedSpy.isValid());
QVERIFY(windowCreatedSpy.wait());
Client *client = windowCreatedSpy.first().first().value<Client*>();
QVERIFY(client);
QCOMPARE(client->window(), w);
QVERIFY(client->isNormalWindow());
// sliding popups should be active
QVERIFY(windowAddedSpy.wait());
QTRY_VERIFY(slidingPoupus->isActive());
QEXPECT_FAIL("scale, slide", "bug 336866", Continue);
QEXPECT_FAIL("fade, slide", "bug 336866", Continue);
QEXPECT_FAIL("wobblywindows, slide", "bug 336866", Continue);
QEXPECT_FAIL("slide, wobblywindows", "bug 336866", Continue);
QVERIFY(!otherEffect->isActive());
// wait till effect ends
QTRY_VERIFY(!slidingPoupus->isActive());
QTest::qWait(300);
QVERIFY(!otherEffect->isActive());
// and destroy the window again
xcb_unmap_window(c.data(), w);
xcb_flush(c.data());
QSignalSpy windowClosedSpy(client, &Client::windowClosed);
QVERIFY(windowClosedSpy.isValid());
QSignalSpy windowDeletedSpy(effects, &EffectsHandler::windowDeleted);
QVERIFY(windowDeletedSpy.isValid());
QVERIFY(windowClosedSpy.wait());
// again we should have the sliding popups active
QVERIFY(slidingPoupus->isActive());
QEXPECT_FAIL("wobblywindows, slide", "bug 336866", Continue);
QEXPECT_FAIL("slide, wobblywindows", "bug 336866", Continue);
QVERIFY(!otherEffect->isActive());
QVERIFY(windowDeletedSpy.wait());
QCOMPARE(windowDeletedSpy.count(), 1);
QTRY_VERIFY(!slidingPoupus->isActive());
QTest::qWait(300);
QVERIFY(!otherEffect->isActive());
xcb_destroy_window(c.data(), w);
c.reset();
}
void SlidingPopupsTest::testWithOtherEffectWayland_data()
{
QTest::addColumn<QStringList>("effectsToLoad");
QTest::newRow("scale, slide") << QStringList{QStringLiteral("kwin4_effect_scalein"), QStringLiteral("slidingpopups")};
QTest::newRow("slide, scale") << QStringList{QStringLiteral("slidingpopups"), QStringLiteral("kwin4_effect_scalein")};
QTest::newRow("fade, slide") << QStringList{QStringLiteral("kwin4_effect_fade"), QStringLiteral("slidingpopups")};
QTest::newRow("slide, fade") << QStringList{QStringLiteral("slidingpopups"), QStringLiteral("kwin4_effect_fade")};
if (effects->compositingType() & KWin::OpenGLCompositing) {
QTest::newRow("glide, slide") << QStringList{QStringLiteral("glide"), QStringLiteral("slidingpopups")};
QTest::newRow("slide, glide") << QStringList{QStringLiteral("slidingpopups"), QStringLiteral("glide")};
QTest::newRow("wobblywindows, slide") << QStringList{QStringLiteral("wobblywindows"), QStringLiteral("slidingpopups")};
QTest::newRow("slide, wobblywindows") << QStringList{QStringLiteral("slidingpopups"), QStringLiteral("wobblywindows")};
QTest::newRow("fallapart, slide") << QStringList{QStringLiteral("fallapart"), QStringLiteral("slidingpopups")};
QTest::newRow("slide, fallapart") << QStringList{QStringLiteral("slidingpopups"), QStringLiteral("fallapart")};
}
}
void SlidingPopupsTest::testWithOtherEffectWayland()
{
// this test verifies that slidingpopups effect grabs the window added role
// independently of the sequence how the effects are loaded.
// see BUG 336866
// the test is like testWithOtherEffect, but simulates using a Wayland window
EffectsHandlerImpl *e = static_cast<EffectsHandlerImpl*>(effects);
// find the effectsloader
auto effectloader = e->findChild<AbstractEffectLoader*>();
QVERIFY(effectloader);
QSignalSpy effectLoadedSpy(effectloader, &AbstractEffectLoader::effectLoaded);
QVERIFY(effectLoadedSpy.isValid());
Effect *slidingPoupus = nullptr;
Effect *otherEffect = nullptr;
QFETCH(QStringList, effectsToLoad);
for (const QString &effectName : effectsToLoad) {
QVERIFY(!e->isEffectLoaded(effectName));
QVERIFY(e->loadEffect(effectName));
QVERIFY(e->isEffectLoaded(effectName));
QCOMPARE(effectLoadedSpy.count(), 1);
Effect *effect = effectLoadedSpy.first().first().value<Effect*>();
if (effectName == QStringLiteral("slidingpopups")) {
slidingPoupus = effect;
} else {
otherEffect = effect;
}
effectLoadedSpy.clear();
}
QVERIFY(slidingPoupus);
QVERIFY(otherEffect);
QVERIFY(!slidingPoupus->isActive());
QVERIFY(!otherEffect->isActive());
QSignalSpy windowAddedSpy(effects, &EffectsHandler::windowAdded);
QVERIFY(windowAddedSpy.isValid());
using namespace KWayland::Client;
// the test created the slide protocol, let's create a Registry and listen for it
QScopedPointer<Registry> registry(new Registry);
registry->create(Test::waylandConnection());
QSignalSpy interfacesAnnouncedSpy(registry.data(), &Registry::interfacesAnnounced);
QVERIFY(interfacesAnnouncedSpy.isValid());
registry->setup();
QVERIFY(interfacesAnnouncedSpy.wait());
auto slideInterface = registry->interface(Registry::Interface::Slide);
QVERIFY(slideInterface.name != 0);
QScopedPointer<SlideManager> slideManager(registry->createSlideManager(slideInterface.name, slideInterface.version));
QVERIFY(slideManager);
// create Wayland window
QScopedPointer<Surface> surface(Test::createSurface());
QVERIFY(surface);
QScopedPointer<Slide> slide(slideManager->createSlide(surface.data()));
slide->setLocation(Slide::Location::Left);
slide->commit();
QScopedPointer<ShellSurface> shellSurface(Test::createShellSurface(surface.data()));
QVERIFY(shellSurface);
QCOMPARE(windowAddedSpy.count(), 0);
auto client = Test::renderAndWaitForShown(surface.data(), QSize(10, 20), Qt::blue);
QVERIFY(client);
QVERIFY(client->isNormalWindow());
// sliding popups should be active
QCOMPARE(windowAddedSpy.count(), 1);
QTRY_VERIFY(slidingPoupus->isActive());
QEXPECT_FAIL("scale, slide", "bug 336866", Continue);
QEXPECT_FAIL("fade, slide", "bug 336866", Continue);
QEXPECT_FAIL("wobblywindows, slide", "bug 336866", Continue);
QEXPECT_FAIL("slide, wobblywindows", "bug 336866", Continue);
QVERIFY(!otherEffect->isActive());
// wait till effect ends
QTRY_VERIFY(!slidingPoupus->isActive());
QTest::qWait(300);
QVERIFY(!otherEffect->isActive());
// and destroy the window again
shellSurface.reset();
surface.reset();
QSignalSpy windowClosedSpy(client, &Client::windowClosed);
QVERIFY(windowClosedSpy.isValid());
QSignalSpy windowDeletedSpy(effects, &EffectsHandler::windowDeleted);
QVERIFY(windowDeletedSpy.isValid());
QVERIFY(windowClosedSpy.wait());
// again we should have the sliding popups active
QVERIFY(slidingPoupus->isActive());
QEXPECT_FAIL("wobblywindows, slide", "bug 336866", Continue);
QEXPECT_FAIL("slide, wobblywindows", "bug 336866", Continue);
QVERIFY(!otherEffect->isActive());
QVERIFY(windowDeletedSpy.wait());
QCOMPARE(windowDeletedSpy.count(), 1);
QTRY_VERIFY(!slidingPoupus->isActive());
QTest::qWait(300);
QVERIFY(!otherEffect->isActive());
}
WAYLANDTEST_MAIN(SlidingPopupsTest)
#include "slidingpopups_test.moc"

@ -30,9 +30,12 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <KWayland/Client/connection_thread.h>
#include <KWayland/Client/compositor.h>
#include <KWayland/Client/pointer.h>
#include <KWayland/Client/plasmashell.h>
#include <KWayland/Client/seat.h>
#include <KWayland/Client/shell.h>
#include <KWayland/Client/surface.h>
#include <KWayland/Client/xdgshell.h>
#include <linux/input.h>
#include <xcb/xcb_icccm.h>
@ -61,6 +64,8 @@ private Q_SLOTS:
void testGrowShrink();
void testPointerMoveEnd_data();
void testPointerMoveEnd();
void testClientSideMove_data();
void testClientSideMove();
void testPlasmaShellSurfaceMovable_data();
void testPlasmaShellSurfaceMovable();
void testNetMove();
@ -88,7 +93,8 @@ void MoveResizeWindowTest::initTestCase()
void MoveResizeWindowTest::init()
{
QVERIFY(Test::setupWaylandConnection(s_socketName, Test::AdditionalWaylandInterface::PlasmaShell));
QVERIFY(Test::setupWaylandConnection(s_socketName, Test::AdditionalWaylandInterface::PlasmaShell | Test::AdditionalWaylandInterface::Seat));
QVERIFY(Test::waitForWaylandPointer());
m_connection = Test::waylandConnection();
m_compositor = Test::waylandCompositor();
m_shell = Test::waylandShell();
@ -402,6 +408,68 @@ void MoveResizeWindowTest::testPointerMoveEnd()
surface.reset();
QVERIFY(Test::waitForWindowDestroyed(c));
}
void MoveResizeWindowTest::testClientSideMove_data()
{
QTest::addColumn<Test::ShellSurfaceType>("type");
QTest::newRow("wlShell") << Test::ShellSurfaceType::WlShell;
QTest::newRow("xdgShellV5") << Test::ShellSurfaceType::XdgShellV5;
}
void MoveResizeWindowTest::testClientSideMove()
{
using namespace KWayland::Client;
Cursor::setPos(640, 512);
QScopedPointer<Pointer> pointer(Test::waylandSeat()->createPointer());
QSignalSpy pointerEnteredSpy(pointer.data(), &Pointer::entered);
QVERIFY(pointerEnteredSpy.isValid());
QSignalSpy pointerLeftSpy(pointer.data(), &Pointer::left);
QVERIFY(pointerLeftSpy.isValid());
QSignalSpy buttonSpy(pointer.data(), &Pointer::buttonStateChanged);
QVERIFY(buttonSpy.isValid());
QScopedPointer<Surface> surface(Test::createSurface());
QFETCH(Test::ShellSurfaceType, type);
QScopedPointer<QObject> shellSurface(Test::createShellSurface(type, surface.data()));
auto c = Test::renderAndWaitForShown(surface.data(), QSize(100, 50), Qt::blue);
QVERIFY(c);
// move pointer into center of geometry
const QRect startGeometry = c->geometry();
Cursor::setPos(startGeometry.center());
QVERIFY(pointerEnteredSpy.wait());
QCOMPARE(pointerEnteredSpy.first().last().toPoint(), QPoint(49, 24));
// simulate press
quint32 timestamp = 1;
kwinApp()->platform()->pointerButtonPressed(BTN_LEFT, timestamp++);
QVERIFY(buttonSpy.wait());
QSignalSpy moveStartSpy(c, &AbstractClient::clientStartUserMovedResized);
QVERIFY(moveStartSpy.isValid());
if (auto s = qobject_cast<ShellSurface*>(shellSurface.data())) {
s->requestMove(Test::waylandSeat(), buttonSpy.first().first().value<quint32>());
} else if (auto s = qobject_cast<XdgShellSurface*>(shellSurface.data())) {
s->requestMove(Test::waylandSeat(), buttonSpy.first().first().value<quint32>());
}
QVERIFY(moveStartSpy.wait());
QCOMPARE(c->isMove(), true);
QVERIFY(pointerLeftSpy.wait());
// move a bit
QSignalSpy clientMoveStepSpy(c, &AbstractClient::clientStepUserMovedResized);
QVERIFY(clientMoveStepSpy.isValid());
const QPoint startPoint = startGeometry.center();
const int dragDistance = QApplication::startDragDistance();
// Why?
kwinApp()->platform()->pointerMotion(startPoint + QPoint(dragDistance, dragDistance) + QPoint(6, 6), timestamp++);
QCOMPARE(clientMoveStepSpy.count(), 1);
// and release again
kwinApp()->platform()->pointerButtonReleased(BTN_LEFT, timestamp++);
QVERIFY(pointerEnteredSpy.wait());
QCOMPARE(c->isMove(), false);
QCOMPARE(c->geometry(), startGeometry.translated(QPoint(dragDistance, dragDistance) + QPoint(6, 6)));
QCOMPARE(pointerEnteredSpy.last().last().toPoint(), QPoint(49, 24));
}
void MoveResizeWindowTest::testPlasmaShellSurfaceMovable_data()
{

@ -154,12 +154,27 @@ void PointerInputRedirection::init()
}
}
);
// connect the move resize of all window
auto setupMoveResizeConnection = [this] (AbstractClient *c) {
connect(c, &AbstractClient::clientStartUserMovedResized, this, &PointerInputRedirection::updateOnStartMoveResize);
connect(c, &AbstractClient::clientFinishUserMovedResized, this, &PointerInputRedirection::update);
};
const auto clients = workspace()->allClientList();
std::for_each(clients.begin(), clients.end(), setupMoveResizeConnection);
connect(workspace(), &Workspace::clientAdded, this, setupMoveResizeConnection);
connect(waylandServer(), &WaylandServer::shellClientAdded, this, setupMoveResizeConnection);
// warp the cursor to center of screen
warp(screens()->geometry().center());
updateAfterScreenChange();
}
void PointerInputRedirection::updateOnStartMoveResize()
{
m_window.clear();
waylandServer()->seat()->setFocusedPointerSurface(nullptr);
}
void PointerInputRedirection::processMotion(const QPointF &pos, uint32_t time, LibInput::Device *device)
{
processMotion(pos, QSizeF(), QSizeF(), time, 0, device);

@ -132,6 +132,7 @@ public:
void processPinchGestureCancelled(quint32 time, KWin::LibInput::Device *device = nullptr);
private:
void updateOnStartMoveResize();
void updatePosition(const QPointF &pos);
void updateButton(uint32_t button, InputRedirection::PointerButtonState state);
void warpXcbOnSurfaceLeft(KWayland::Server::SurfaceInterface *surface);

@ -595,6 +595,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)

@ -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;

Loading…
Cancel
Save