2020-08-02 22:22:19 +00:00
|
|
|
/*
|
|
|
|
KWin - the KDE window manager
|
|
|
|
This file is part of the KDE project.
|
2016-09-13 11:04:27 +00:00
|
|
|
|
2020-08-02 22:22:19 +00:00
|
|
|
SPDX-FileCopyrightText: 2016 Martin Gräßlin <mgraesslin@kde.org>
|
2016-09-13 11:04:27 +00:00
|
|
|
|
2020-08-02 22:22:19 +00:00
|
|
|
SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
*/
|
2016-09-13 11:04:27 +00:00
|
|
|
#include "kwin_wayland_test.h"
|
2022-03-23 10:13:38 +00:00
|
|
|
|
2022-08-29 07:55:49 +00:00
|
|
|
#include "core/platform.h"
|
2016-09-13 11:04:27 +00:00
|
|
|
#include "cursor.h"
|
|
|
|
#include "input.h"
|
|
|
|
#include "tabbox/tabbox.h"
|
|
|
|
#include "wayland_server.h"
|
2022-04-22 17:39:12 +00:00
|
|
|
#include "window.h"
|
2016-09-13 11:04:27 +00:00
|
|
|
#include "workspace.h"
|
|
|
|
|
|
|
|
#include <KConfigGroup>
|
2022-03-23 10:13:38 +00:00
|
|
|
#include <KWayland/Client/surface.h>
|
2016-09-13 11:04:27 +00:00
|
|
|
|
|
|
|
#include <linux/input.h>
|
|
|
|
|
|
|
|
using namespace KWin;
|
|
|
|
using namespace KWayland::Client;
|
|
|
|
|
|
|
|
static const QString s_socketName = QStringLiteral("wayland_test_kwin_tabbox-0");
|
|
|
|
|
|
|
|
class TabBoxTest : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
private Q_SLOTS:
|
|
|
|
void initTestCase();
|
|
|
|
void init();
|
|
|
|
void cleanup();
|
|
|
|
|
2016-09-13 14:11:58 +00:00
|
|
|
void testMoveForward();
|
|
|
|
void testMoveBackward();
|
2016-09-13 11:04:27 +00:00
|
|
|
void testCapsLock();
|
|
|
|
};
|
|
|
|
|
|
|
|
void TabBoxTest::initTestCase()
|
|
|
|
{
|
2022-04-22 17:39:12 +00:00
|
|
|
qRegisterMetaType<KWin::Window *>();
|
2020-07-07 09:32:29 +00:00
|
|
|
QSignalSpy applicationStartedSpy(kwinApp(), &Application::started);
|
2016-09-13 11:04:27 +00:00
|
|
|
kwinApp()->platform()->setInitialWindowSize(QSize(1280, 1024));
|
2020-12-09 13:06:15 +00:00
|
|
|
QVERIFY(waylandServer()->init(s_socketName));
|
2022-09-16 08:42:55 +00:00
|
|
|
QMetaObject::invokeMethod(kwinApp()->platform(), "setVirtualOutputs", Qt::DirectConnection, Q_ARG(int, 2));
|
2016-09-13 11:04:27 +00:00
|
|
|
|
|
|
|
KSharedConfigPtr c = KSharedConfig::openConfig(QString(), KConfig::SimpleConfig);
|
|
|
|
c->group("TabBox").writeEntry("ShowTabBox", false);
|
|
|
|
c->sync();
|
|
|
|
kwinApp()->setConfig(c);
|
|
|
|
qputenv("KWIN_XKB_DEFAULT_KEYMAP", "1");
|
|
|
|
|
|
|
|
kwinApp()->start();
|
2020-07-07 09:32:29 +00:00
|
|
|
QVERIFY(applicationStartedSpy.wait());
|
2016-09-13 11:04:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void TabBoxTest::init()
|
|
|
|
{
|
2016-12-03 13:31:14 +00:00
|
|
|
QVERIFY(Test::setupWaylandConnection());
|
2021-08-28 18:58:29 +00:00
|
|
|
workspace()->setActiveOutput(QPoint(640, 512));
|
2020-04-02 16:18:01 +00:00
|
|
|
KWin::Cursors::self()->mouse()->setPos(QPoint(640, 512));
|
2016-09-13 11:04:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void TabBoxTest::cleanup()
|
|
|
|
{
|
|
|
|
Test::destroyWaylandConnection();
|
|
|
|
}
|
|
|
|
|
|
|
|
void TabBoxTest::testCapsLock()
|
|
|
|
{
|
|
|
|
// this test verifies that Alt+tab works correctly also when Capslock is on
|
|
|
|
// bug 368590
|
|
|
|
|
2016-09-13 13:20:46 +00:00
|
|
|
// first create three windows
|
2022-08-01 21:29:02 +00:00
|
|
|
std::unique_ptr<KWayland::Client::Surface> surface1(Test::createSurface());
|
|
|
|
std::unique_ptr<Test::XdgToplevel> shellSurface1(Test::createXdgToplevelSurface(surface1.get()));
|
|
|
|
auto c1 = Test::renderAndWaitForShown(surface1.get(), QSize(100, 50), Qt::blue);
|
2016-09-13 11:04:27 +00:00
|
|
|
QVERIFY(c1);
|
|
|
|
QVERIFY(c1->isActive());
|
2022-08-01 21:29:02 +00:00
|
|
|
std::unique_ptr<KWayland::Client::Surface> surface2(Test::createSurface());
|
|
|
|
std::unique_ptr<Test::XdgToplevel> shellSurface2(Test::createXdgToplevelSurface(surface2.get()));
|
|
|
|
auto c2 = Test::renderAndWaitForShown(surface2.get(), QSize(100, 50), Qt::red);
|
2016-09-13 11:04:27 +00:00
|
|
|
QVERIFY(c2);
|
|
|
|
QVERIFY(c2->isActive());
|
2022-08-01 21:29:02 +00:00
|
|
|
std::unique_ptr<KWayland::Client::Surface> surface3(Test::createSurface());
|
|
|
|
std::unique_ptr<Test::XdgToplevel> shellSurface3(Test::createXdgToplevelSurface(surface3.get()));
|
|
|
|
auto c3 = Test::renderAndWaitForShown(surface3.get(), QSize(100, 50), Qt::red);
|
2016-09-13 13:20:46 +00:00
|
|
|
QVERIFY(c3);
|
|
|
|
QVERIFY(c3->isActive());
|
2016-09-13 11:04:27 +00:00
|
|
|
|
|
|
|
// Setup tabbox signal spies
|
2022-07-31 00:12:25 +00:00
|
|
|
QSignalSpy tabboxAddedSpy(workspace()->tabbox(), &TabBox::TabBox::tabBoxAdded);
|
|
|
|
QSignalSpy tabboxClosedSpy(workspace()->tabbox(), &TabBox::TabBox::tabBoxClosed);
|
2016-09-13 11:04:27 +00:00
|
|
|
|
|
|
|
// enable capslock
|
|
|
|
quint32 timestamp = 0;
|
2022-03-10 10:27:35 +00:00
|
|
|
Test::keyboardKeyPressed(KEY_CAPSLOCK, timestamp++);
|
|
|
|
Test::keyboardKeyReleased(KEY_CAPSLOCK, timestamp++);
|
2016-09-13 11:04:27 +00:00
|
|
|
QCOMPARE(input()->keyboardModifiers(), Qt::ShiftModifier);
|
|
|
|
|
|
|
|
// press alt+tab
|
2022-03-10 10:27:35 +00:00
|
|
|
Test::keyboardKeyPressed(KEY_LEFTALT, timestamp++);
|
2016-09-13 11:04:27 +00:00
|
|
|
QCOMPARE(input()->keyboardModifiers(), Qt::ShiftModifier | Qt::AltModifier);
|
2022-03-10 10:27:35 +00:00
|
|
|
Test::keyboardKeyPressed(KEY_TAB, timestamp++);
|
|
|
|
Test::keyboardKeyReleased(KEY_TAB, timestamp++);
|
2016-09-13 11:04:27 +00:00
|
|
|
|
|
|
|
QVERIFY(tabboxAddedSpy.wait());
|
2022-07-31 00:12:25 +00:00
|
|
|
QVERIFY(workspace()->tabbox()->isGrabbed());
|
2016-09-13 11:04:27 +00:00
|
|
|
|
|
|
|
// release alt
|
2022-03-10 10:27:35 +00:00
|
|
|
Test::keyboardKeyReleased(KEY_LEFTALT, timestamp++);
|
2016-09-13 11:04:27 +00:00
|
|
|
QCOMPARE(tabboxClosedSpy.count(), 1);
|
2022-07-31 00:12:25 +00:00
|
|
|
QCOMPARE(workspace()->tabbox()->isGrabbed(), false);
|
2016-09-13 11:04:27 +00:00
|
|
|
|
|
|
|
// release caps lock
|
2022-03-10 10:27:35 +00:00
|
|
|
Test::keyboardKeyPressed(KEY_CAPSLOCK, timestamp++);
|
|
|
|
Test::keyboardKeyReleased(KEY_CAPSLOCK, timestamp++);
|
2016-09-13 11:04:27 +00:00
|
|
|
QCOMPARE(input()->keyboardModifiers(), Qt::NoModifier);
|
|
|
|
QCOMPARE(tabboxClosedSpy.count(), 1);
|
2022-07-31 00:12:25 +00:00
|
|
|
QCOMPARE(workspace()->tabbox()->isGrabbed(), false);
|
2022-04-23 08:33:23 +00:00
|
|
|
QCOMPARE(workspace()->activeWindow(), c2);
|
2016-09-13 11:04:27 +00:00
|
|
|
|
2016-09-13 13:20:46 +00:00
|
|
|
surface3.reset();
|
|
|
|
QVERIFY(Test::waitForWindowDestroyed(c3));
|
2016-09-13 11:04:27 +00:00
|
|
|
surface2.reset();
|
|
|
|
QVERIFY(Test::waitForWindowDestroyed(c2));
|
|
|
|
surface1.reset();
|
|
|
|
QVERIFY(Test::waitForWindowDestroyed(c1));
|
|
|
|
}
|
|
|
|
|
2016-09-13 14:11:58 +00:00
|
|
|
void TabBoxTest::testMoveForward()
|
|
|
|
{
|
|
|
|
// this test verifies that Alt+tab works correctly moving forward
|
|
|
|
|
|
|
|
// first create three windows
|
2022-08-01 21:29:02 +00:00
|
|
|
std::unique_ptr<KWayland::Client::Surface> surface1(Test::createSurface());
|
|
|
|
std::unique_ptr<Test::XdgToplevel> shellSurface1(Test::createXdgToplevelSurface(surface1.get()));
|
|
|
|
auto c1 = Test::renderAndWaitForShown(surface1.get(), QSize(100, 50), Qt::blue);
|
2016-09-13 14:11:58 +00:00
|
|
|
QVERIFY(c1);
|
|
|
|
QVERIFY(c1->isActive());
|
2022-08-01 21:29:02 +00:00
|
|
|
std::unique_ptr<KWayland::Client::Surface> surface2(Test::createSurface());
|
|
|
|
std::unique_ptr<Test::XdgToplevel> shellSurface2(Test::createXdgToplevelSurface(surface2.get()));
|
|
|
|
auto c2 = Test::renderAndWaitForShown(surface2.get(), QSize(100, 50), Qt::red);
|
2016-09-13 14:11:58 +00:00
|
|
|
QVERIFY(c2);
|
|
|
|
QVERIFY(c2->isActive());
|
2022-08-01 21:29:02 +00:00
|
|
|
std::unique_ptr<KWayland::Client::Surface> surface3(Test::createSurface());
|
|
|
|
std::unique_ptr<Test::XdgToplevel> shellSurface3(Test::createXdgToplevelSurface(surface3.get()));
|
|
|
|
auto c3 = Test::renderAndWaitForShown(surface3.get(), QSize(100, 50), Qt::red);
|
2016-09-13 14:11:58 +00:00
|
|
|
QVERIFY(c3);
|
|
|
|
QVERIFY(c3->isActive());
|
|
|
|
|
|
|
|
// Setup tabbox signal spies
|
2022-07-31 00:12:25 +00:00
|
|
|
QSignalSpy tabboxAddedSpy(workspace()->tabbox(), &TabBox::TabBox::tabBoxAdded);
|
|
|
|
QSignalSpy tabboxClosedSpy(workspace()->tabbox(), &TabBox::TabBox::tabBoxClosed);
|
2016-09-13 14:11:58 +00:00
|
|
|
|
|
|
|
// press alt+tab
|
|
|
|
quint32 timestamp = 0;
|
2022-03-10 10:27:35 +00:00
|
|
|
Test::keyboardKeyPressed(KEY_LEFTALT, timestamp++);
|
2016-09-13 14:11:58 +00:00
|
|
|
QCOMPARE(input()->keyboardModifiers(), Qt::AltModifier);
|
2022-03-10 10:27:35 +00:00
|
|
|
Test::keyboardKeyPressed(KEY_TAB, timestamp++);
|
|
|
|
Test::keyboardKeyReleased(KEY_TAB, timestamp++);
|
2016-09-13 14:11:58 +00:00
|
|
|
|
|
|
|
QVERIFY(tabboxAddedSpy.wait());
|
2022-07-31 00:12:25 +00:00
|
|
|
QVERIFY(workspace()->tabbox()->isGrabbed());
|
2016-09-13 14:11:58 +00:00
|
|
|
|
|
|
|
// release alt
|
2022-03-10 10:27:35 +00:00
|
|
|
Test::keyboardKeyReleased(KEY_LEFTALT, timestamp++);
|
2016-09-13 14:11:58 +00:00
|
|
|
QCOMPARE(tabboxClosedSpy.count(), 1);
|
2022-07-31 00:12:25 +00:00
|
|
|
QCOMPARE(workspace()->tabbox()->isGrabbed(), false);
|
2022-04-23 08:33:23 +00:00
|
|
|
QCOMPARE(workspace()->activeWindow(), c2);
|
2016-09-13 14:11:58 +00:00
|
|
|
|
|
|
|
surface3.reset();
|
|
|
|
QVERIFY(Test::waitForWindowDestroyed(c3));
|
|
|
|
surface2.reset();
|
|
|
|
QVERIFY(Test::waitForWindowDestroyed(c2));
|
|
|
|
surface1.reset();
|
|
|
|
QVERIFY(Test::waitForWindowDestroyed(c1));
|
|
|
|
}
|
|
|
|
|
|
|
|
void TabBoxTest::testMoveBackward()
|
|
|
|
{
|
|
|
|
// this test verifies that Alt+Shift+tab works correctly moving backward
|
|
|
|
|
|
|
|
// first create three windows
|
2022-08-01 21:29:02 +00:00
|
|
|
std::unique_ptr<KWayland::Client::Surface> surface1(Test::createSurface());
|
|
|
|
std::unique_ptr<Test::XdgToplevel> shellSurface1(Test::createXdgToplevelSurface(surface1.get()));
|
|
|
|
auto c1 = Test::renderAndWaitForShown(surface1.get(), QSize(100, 50), Qt::blue);
|
2016-09-13 14:11:58 +00:00
|
|
|
QVERIFY(c1);
|
|
|
|
QVERIFY(c1->isActive());
|
2022-08-01 21:29:02 +00:00
|
|
|
std::unique_ptr<KWayland::Client::Surface> surface2(Test::createSurface());
|
|
|
|
std::unique_ptr<Test::XdgToplevel> shellSurface2(Test::createXdgToplevelSurface(surface2.get()));
|
|
|
|
auto c2 = Test::renderAndWaitForShown(surface2.get(), QSize(100, 50), Qt::red);
|
2016-09-13 14:11:58 +00:00
|
|
|
QVERIFY(c2);
|
|
|
|
QVERIFY(c2->isActive());
|
2022-08-01 21:29:02 +00:00
|
|
|
std::unique_ptr<KWayland::Client::Surface> surface3(Test::createSurface());
|
|
|
|
std::unique_ptr<Test::XdgToplevel> shellSurface3(Test::createXdgToplevelSurface(surface3.get()));
|
|
|
|
auto c3 = Test::renderAndWaitForShown(surface3.get(), QSize(100, 50), Qt::red);
|
2016-09-13 14:11:58 +00:00
|
|
|
QVERIFY(c3);
|
|
|
|
QVERIFY(c3->isActive());
|
|
|
|
|
|
|
|
// Setup tabbox signal spies
|
2022-07-31 00:12:25 +00:00
|
|
|
QSignalSpy tabboxAddedSpy(workspace()->tabbox(), &TabBox::TabBox::tabBoxAdded);
|
|
|
|
QSignalSpy tabboxClosedSpy(workspace()->tabbox(), &TabBox::TabBox::tabBoxClosed);
|
2016-09-13 14:11:58 +00:00
|
|
|
|
|
|
|
// press alt+shift+tab
|
|
|
|
quint32 timestamp = 0;
|
2022-03-10 10:27:35 +00:00
|
|
|
Test::keyboardKeyPressed(KEY_LEFTALT, timestamp++);
|
2016-09-13 14:11:58 +00:00
|
|
|
QCOMPARE(input()->keyboardModifiers(), Qt::AltModifier);
|
2022-03-10 10:27:35 +00:00
|
|
|
Test::keyboardKeyPressed(KEY_LEFTSHIFT, timestamp++);
|
2016-09-13 14:11:58 +00:00
|
|
|
QCOMPARE(input()->keyboardModifiers(), Qt::AltModifier | Qt::ShiftModifier);
|
2022-03-10 10:27:35 +00:00
|
|
|
Test::keyboardKeyPressed(KEY_TAB, timestamp++);
|
|
|
|
Test::keyboardKeyReleased(KEY_TAB, timestamp++);
|
2016-09-13 14:11:58 +00:00
|
|
|
|
|
|
|
QVERIFY(tabboxAddedSpy.wait());
|
2022-07-31 00:12:25 +00:00
|
|
|
QVERIFY(workspace()->tabbox()->isGrabbed());
|
2016-09-13 14:11:58 +00:00
|
|
|
|
|
|
|
// release alt
|
2022-03-10 10:27:35 +00:00
|
|
|
Test::keyboardKeyReleased(KEY_LEFTSHIFT, timestamp++);
|
2016-09-13 14:11:58 +00:00
|
|
|
QCOMPARE(tabboxClosedSpy.count(), 0);
|
2022-03-10 10:27:35 +00:00
|
|
|
Test::keyboardKeyReleased(KEY_LEFTALT, timestamp++);
|
2016-09-13 14:11:58 +00:00
|
|
|
QCOMPARE(tabboxClosedSpy.count(), 1);
|
2022-07-31 00:12:25 +00:00
|
|
|
QCOMPARE(workspace()->tabbox()->isGrabbed(), false);
|
2022-04-23 08:33:23 +00:00
|
|
|
QCOMPARE(workspace()->activeWindow(), c1);
|
2016-09-13 14:11:58 +00:00
|
|
|
|
|
|
|
surface3.reset();
|
|
|
|
QVERIFY(Test::waitForWindowDestroyed(c3));
|
|
|
|
surface2.reset();
|
|
|
|
QVERIFY(Test::waitForWindowDestroyed(c2));
|
|
|
|
surface1.reset();
|
|
|
|
QVERIFY(Test::waitForWindowDestroyed(c1));
|
|
|
|
}
|
|
|
|
|
2016-09-13 11:04:27 +00:00
|
|
|
WAYLANDTEST_MAIN(TabBoxTest)
|
|
|
|
#include "tabbox_test.moc"
|