diff --git a/autotests/wayland/quick_tiling_test.cpp b/autotests/wayland/quick_tiling_test.cpp index 45c5f267ea..8190fa06f8 100644 --- a/autotests/wayland/quick_tiling_test.cpp +++ b/autotests/wayland/quick_tiling_test.cpp @@ -20,6 +20,7 @@ along with this program. If not, see . #include "kwin_wayland_test.h" #include "abstract_backend.h" #include "abstract_client.h" +#include "cursor.h" #include "screens.h" #include "wayland_server.h" #include "workspace.h" @@ -33,6 +34,8 @@ along with this program. If not, see . #include #include +#include + Q_DECLARE_METATYPE(KWin::AbstractClient::QuickTileMode) Q_DECLARE_METATYPE(KWin::MaximizeMode) @@ -52,6 +55,8 @@ private Q_SLOTS: void testQuickTiling(); void testQuickMaximizing_data(); void testQuickMaximizing(); + void testQuickTilingKeyboardMove_data(); + void testQuickTilingKeyboardMove(); private: KWayland::Client::ConnectionThread *m_connection = nullptr; @@ -72,6 +77,15 @@ void QuickTilingTest::initTestCase() waylandServer()->backend()->setInitialWindowSize(QSize(1280, 1024)); QMetaObject::invokeMethod(waylandServer()->backend(), "setOutputCount", Qt::DirectConnection, Q_ARG(int, 2)); waylandServer()->init(s_socketName.toLocal8Bit()); + + // set custom config which disables the Outline + KSharedConfig::Ptr config = KSharedConfig::openConfig(QString(), KConfig::SimpleConfig); + KConfigGroup group = config->group("Outline"); + group.writeEntry(QStringLiteral("QmlPath"), QString("/does/not/exist.qml")); + group.sync(); + + kwinApp()->setConfig(config); + kwinApp()->start(); QVERIFY(workspaceCreatedSpy.wait()); QCOMPARE(screens()->count(), 2); @@ -139,12 +153,13 @@ void QuickTilingTest::cleanup() delete m_queue; m_queue = nullptr; if (m_thread) { + m_connection->deleteLater(); m_thread->quit(); m_thread->wait(); delete m_thread; m_thread = nullptr; + m_connection = nullptr; } - } void QuickTilingTest::testQuickTiling_data() @@ -359,6 +374,85 @@ void QuickTilingTest::testQuickMaximizing() QCOMPARE(c->geometryRestore(), QRect(0, 0, 100, 50)); } +void QuickTilingTest::testQuickTilingKeyboardMove_data() +{ + QTest::addColumn("targetPos"); + QTest::addColumn("expectedMode"); + + QTest::newRow("topRight") << QPoint(2559, 24) << AbstractClient::QuickTileMode(AbstractClient::QuickTileTop | AbstractClient::QuickTileRight); + QTest::newRow("right") << QPoint(2559, 512) << AbstractClient::QuickTileMode(AbstractClient::QuickTileRight); + QTest::newRow("bottomRight") << QPoint(2559, 1023) << AbstractClient::QuickTileMode(AbstractClient::QuickTileBottom | AbstractClient::QuickTileRight); + QTest::newRow("bottomLeft") << QPoint(0, 1023) << AbstractClient::QuickTileMode(AbstractClient::QuickTileBottom | AbstractClient::QuickTileLeft); + QTest::newRow("Left") << QPoint(0, 512) << AbstractClient::QuickTileMode(AbstractClient::QuickTileLeft); + QTest::newRow("topLeft") << QPoint(0, 24) << AbstractClient::QuickTileMode(AbstractClient::QuickTileTop | AbstractClient::QuickTileLeft); +} + +void QuickTilingTest::testQuickTilingKeyboardMove() +{ + using namespace KWayland::Client; + + QSignalSpy clientAddedSpy(waylandServer(), &WaylandServer::shellClientAdded); + QVERIFY(clientAddedSpy.isValid()); + + QScopedPointer surface(m_compositor->createSurface()); + QVERIFY(!surface.isNull()); + + QScopedPointer shellSurface(m_shell->createSurface(surface.data())); + QVERIFY(!shellSurface.isNull()); + QSignalSpy sizeChangeSpy(shellSurface.data(), &ShellSurface::sizeChanged); + QVERIFY(sizeChangeSpy.isValid()); + // let's render + QImage img(QSize(100, 50), QImage::Format_ARGB32); + img.fill(Qt::blue); + surface->attachBuffer(m_shm->createBuffer(img)); + surface->damage(QRect(0, 0, 100, 50)); + surface->commit(Surface::CommitFlag::None); + + m_connection->flush(); + QVERIFY(clientAddedSpy.wait()); + AbstractClient *c = workspace()->activeClient(); + QVERIFY(c); + QCOMPARE(clientAddedSpy.first().first().value(), c); + QCOMPARE(c->geometry(), QRect(0, 0, 100, 50)); + QCOMPARE(c->quickTileMode(), AbstractClient::QuickTileNone); + QCOMPARE(c->maximizeMode(), MaximizeRestore); + + QSignalSpy quickTileChangedSpy(c, &AbstractClient::quickTileModeChanged); + QVERIFY(quickTileChangedSpy.isValid()); + + workspace()->performWindowOperation(c, Options::UnrestrictedMoveOp); + QCOMPARE(c, workspace()->getMovingClient()); + QCOMPARE(Cursor::pos(), QPoint(49, 24)); + + QFETCH(QPoint, targetPos); + quint32 timestamp = 1; + waylandServer()->backend()->keyboardKeyPressed(KEY_LEFTCTRL, timestamp++); + while (Cursor::pos().x() > targetPos.x()) { + waylandServer()->backend()->keyboardKeyPressed(KEY_LEFT, timestamp++); + waylandServer()->backend()->keyboardKeyReleased(KEY_LEFT, timestamp++); + } + while (Cursor::pos().x() < targetPos.x()) { + waylandServer()->backend()->keyboardKeyPressed(KEY_RIGHT, timestamp++); + waylandServer()->backend()->keyboardKeyReleased(KEY_RIGHT, timestamp++); + } + while (Cursor::pos().y() < targetPos.y()) { + waylandServer()->backend()->keyboardKeyPressed(KEY_DOWN, timestamp++); + waylandServer()->backend()->keyboardKeyReleased(KEY_DOWN, timestamp++); + } + while (Cursor::pos().y() > targetPos.y()) { + waylandServer()->backend()->keyboardKeyPressed(KEY_UP, timestamp++); + waylandServer()->backend()->keyboardKeyReleased(KEY_UP, timestamp++); + } + waylandServer()->backend()->keyboardKeyReleased(KEY_LEFTCTRL, timestamp++); + waylandServer()->backend()->keyboardKeyPressed(KEY_ENTER, timestamp++); + waylandServer()->backend()->keyboardKeyReleased(KEY_ENTER, timestamp++); + QCOMPARE(Cursor::pos(), targetPos); + QVERIFY(!workspace()->getMovingClient()); + + QCOMPARE(quickTileChangedSpy.count(), 1); + QTEST(c->quickTileMode(), "expectedMode"); +} + } WAYLANTEST_MAIN(KWin::QuickTilingTest)