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"
|
2020-03-04 07:55:26 +00:00
|
|
|
#include "abstract_client.h"
|
2016-09-13 11:04:27 +00:00
|
|
|
#include "cursor.h"
|
|
|
|
#include "input.h"
|
|
|
|
#include "platform.h"
|
|
|
|
#include "screens.h"
|
|
|
|
#include "tabbox/tabbox.h"
|
|
|
|
#include "wayland_server.h"
|
|
|
|
#include "workspace.h"
|
|
|
|
|
|
|
|
#include <KWayland/Client/surface.h>
|
|
|
|
#include <KConfigGroup>
|
|
|
|
|
|
|
|
#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()
|
|
|
|
{
|
|
|
|
qRegisterMetaType<KWin::AbstractClient*>();
|
2020-07-07 09:32:29 +00:00
|
|
|
QSignalSpy applicationStartedSpy(kwinApp(), &Application::started);
|
|
|
|
QVERIFY(applicationStartedSpy.isValid());
|
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));
|
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());
|
2021-05-08 00:08:22 +00:00
|
|
|
Test::initWaylandWorkspace();
|
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
|
2021-09-03 17:54:03 +00:00
|
|
|
QScopedPointer<KWayland::Client::Surface> surface1(Test::createSurface());
|
2021-05-11 05:26:51 +00:00
|
|
|
QScopedPointer<Test::XdgToplevel> shellSurface1(Test::createXdgToplevelSurface(surface1.data()));
|
2016-09-13 11:04:27 +00:00
|
|
|
auto c1 = Test::renderAndWaitForShown(surface1.data(), QSize(100, 50), Qt::blue);
|
|
|
|
QVERIFY(c1);
|
|
|
|
QVERIFY(c1->isActive());
|
2021-09-03 17:54:03 +00:00
|
|
|
QScopedPointer<KWayland::Client::Surface> surface2(Test::createSurface());
|
2021-05-11 05:26:51 +00:00
|
|
|
QScopedPointer<Test::XdgToplevel> shellSurface2(Test::createXdgToplevelSurface(surface2.data()));
|
2016-09-13 11:04:27 +00:00
|
|
|
auto c2 = Test::renderAndWaitForShown(surface2.data(), QSize(100, 50), Qt::red);
|
|
|
|
QVERIFY(c2);
|
|
|
|
QVERIFY(c2->isActive());
|
2021-09-03 17:54:03 +00:00
|
|
|
QScopedPointer<KWayland::Client::Surface> surface3(Test::createSurface());
|
2021-05-11 05:26:51 +00:00
|
|
|
QScopedPointer<Test::XdgToplevel> shellSurface3(Test::createXdgToplevelSurface(surface3.data()));
|
2016-09-13 13:20:46 +00:00
|
|
|
auto c3 = Test::renderAndWaitForShown(surface3.data(), QSize(100, 50), Qt::red);
|
|
|
|
QVERIFY(c3);
|
|
|
|
QVERIFY(c3->isActive());
|
2016-09-13 11:04:27 +00:00
|
|
|
|
|
|
|
// Setup tabbox signal spies
|
|
|
|
QSignalSpy tabboxAddedSpy(TabBox::TabBox::self(), &TabBox::TabBox::tabBoxAdded);
|
|
|
|
QVERIFY(tabboxAddedSpy.isValid());
|
|
|
|
QSignalSpy tabboxClosedSpy(TabBox::TabBox::self(), &TabBox::TabBox::tabBoxClosed);
|
|
|
|
QVERIFY(tabboxClosedSpy.isValid());
|
|
|
|
|
|
|
|
// enable capslock
|
|
|
|
quint32 timestamp = 0;
|
|
|
|
kwinApp()->platform()->keyboardKeyPressed(KEY_CAPSLOCK, timestamp++);
|
|
|
|
kwinApp()->platform()->keyboardKeyReleased(KEY_CAPSLOCK, timestamp++);
|
|
|
|
QCOMPARE(input()->keyboardModifiers(), Qt::ShiftModifier);
|
|
|
|
|
|
|
|
// press alt+tab
|
|
|
|
kwinApp()->platform()->keyboardKeyPressed(KEY_LEFTALT, timestamp++);
|
|
|
|
QCOMPARE(input()->keyboardModifiers(), Qt::ShiftModifier | Qt::AltModifier);
|
|
|
|
kwinApp()->platform()->keyboardKeyPressed(KEY_TAB, timestamp++);
|
|
|
|
kwinApp()->platform()->keyboardKeyReleased(KEY_TAB, timestamp++);
|
|
|
|
|
|
|
|
QVERIFY(tabboxAddedSpy.wait());
|
|
|
|
QVERIFY(TabBox::TabBox::self()->isGrabbed());
|
|
|
|
|
|
|
|
// release alt
|
|
|
|
kwinApp()->platform()->keyboardKeyReleased(KEY_LEFTALT, timestamp++);
|
|
|
|
QCOMPARE(tabboxClosedSpy.count(), 1);
|
|
|
|
QCOMPARE(TabBox::TabBox::self()->isGrabbed(), false);
|
|
|
|
|
|
|
|
// release caps lock
|
|
|
|
kwinApp()->platform()->keyboardKeyPressed(KEY_CAPSLOCK, timestamp++);
|
|
|
|
kwinApp()->platform()->keyboardKeyReleased(KEY_CAPSLOCK, timestamp++);
|
|
|
|
QCOMPARE(input()->keyboardModifiers(), Qt::NoModifier);
|
|
|
|
QCOMPARE(tabboxClosedSpy.count(), 1);
|
|
|
|
QCOMPARE(TabBox::TabBox::self()->isGrabbed(), false);
|
2016-09-13 13:20:46 +00:00
|
|
|
QCOMPARE(workspace()->activeClient(), 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
|
2021-09-03 17:54:03 +00:00
|
|
|
QScopedPointer<KWayland::Client::Surface> surface1(Test::createSurface());
|
2021-05-11 05:26:51 +00:00
|
|
|
QScopedPointer<Test::XdgToplevel> shellSurface1(Test::createXdgToplevelSurface(surface1.data()));
|
2016-09-13 14:11:58 +00:00
|
|
|
auto c1 = Test::renderAndWaitForShown(surface1.data(), QSize(100, 50), Qt::blue);
|
|
|
|
QVERIFY(c1);
|
|
|
|
QVERIFY(c1->isActive());
|
2021-09-03 17:54:03 +00:00
|
|
|
QScopedPointer<KWayland::Client::Surface> surface2(Test::createSurface());
|
2021-05-11 05:26:51 +00:00
|
|
|
QScopedPointer<Test::XdgToplevel> shellSurface2(Test::createXdgToplevelSurface(surface2.data()));
|
2016-09-13 14:11:58 +00:00
|
|
|
auto c2 = Test::renderAndWaitForShown(surface2.data(), QSize(100, 50), Qt::red);
|
|
|
|
QVERIFY(c2);
|
|
|
|
QVERIFY(c2->isActive());
|
2021-09-03 17:54:03 +00:00
|
|
|
QScopedPointer<KWayland::Client::Surface> surface3(Test::createSurface());
|
2021-05-11 05:26:51 +00:00
|
|
|
QScopedPointer<Test::XdgToplevel> shellSurface3(Test::createXdgToplevelSurface(surface3.data()));
|
2016-09-13 14:11:58 +00:00
|
|
|
auto c3 = Test::renderAndWaitForShown(surface3.data(), QSize(100, 50), Qt::red);
|
|
|
|
QVERIFY(c3);
|
|
|
|
QVERIFY(c3->isActive());
|
|
|
|
|
|
|
|
// Setup tabbox signal spies
|
|
|
|
QSignalSpy tabboxAddedSpy(TabBox::TabBox::self(), &TabBox::TabBox::tabBoxAdded);
|
|
|
|
QVERIFY(tabboxAddedSpy.isValid());
|
|
|
|
QSignalSpy tabboxClosedSpy(TabBox::TabBox::self(), &TabBox::TabBox::tabBoxClosed);
|
|
|
|
QVERIFY(tabboxClosedSpy.isValid());
|
|
|
|
|
|
|
|
// press alt+tab
|
|
|
|
quint32 timestamp = 0;
|
|
|
|
kwinApp()->platform()->keyboardKeyPressed(KEY_LEFTALT, timestamp++);
|
|
|
|
QCOMPARE(input()->keyboardModifiers(), Qt::AltModifier);
|
|
|
|
kwinApp()->platform()->keyboardKeyPressed(KEY_TAB, timestamp++);
|
|
|
|
kwinApp()->platform()->keyboardKeyReleased(KEY_TAB, timestamp++);
|
|
|
|
|
|
|
|
QVERIFY(tabboxAddedSpy.wait());
|
|
|
|
QVERIFY(TabBox::TabBox::self()->isGrabbed());
|
|
|
|
|
|
|
|
// release alt
|
|
|
|
kwinApp()->platform()->keyboardKeyReleased(KEY_LEFTALT, timestamp++);
|
|
|
|
QCOMPARE(tabboxClosedSpy.count(), 1);
|
|
|
|
QCOMPARE(TabBox::TabBox::self()->isGrabbed(), false);
|
|
|
|
QCOMPARE(workspace()->activeClient(), c2);
|
|
|
|
|
|
|
|
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
|
2021-09-03 17:54:03 +00:00
|
|
|
QScopedPointer<KWayland::Client::Surface> surface1(Test::createSurface());
|
2021-05-11 05:26:51 +00:00
|
|
|
QScopedPointer<Test::XdgToplevel> shellSurface1(Test::createXdgToplevelSurface(surface1.data()));
|
2016-09-13 14:11:58 +00:00
|
|
|
auto c1 = Test::renderAndWaitForShown(surface1.data(), QSize(100, 50), Qt::blue);
|
|
|
|
QVERIFY(c1);
|
|
|
|
QVERIFY(c1->isActive());
|
2021-09-03 17:54:03 +00:00
|
|
|
QScopedPointer<KWayland::Client::Surface> surface2(Test::createSurface());
|
2021-05-11 05:26:51 +00:00
|
|
|
QScopedPointer<Test::XdgToplevel> shellSurface2(Test::createXdgToplevelSurface(surface2.data()));
|
2016-09-13 14:11:58 +00:00
|
|
|
auto c2 = Test::renderAndWaitForShown(surface2.data(), QSize(100, 50), Qt::red);
|
|
|
|
QVERIFY(c2);
|
|
|
|
QVERIFY(c2->isActive());
|
2021-09-03 17:54:03 +00:00
|
|
|
QScopedPointer<KWayland::Client::Surface> surface3(Test::createSurface());
|
2021-05-11 05:26:51 +00:00
|
|
|
QScopedPointer<Test::XdgToplevel> shellSurface3(Test::createXdgToplevelSurface(surface3.data()));
|
2016-09-13 14:11:58 +00:00
|
|
|
auto c3 = Test::renderAndWaitForShown(surface3.data(), QSize(100, 50), Qt::red);
|
|
|
|
QVERIFY(c3);
|
|
|
|
QVERIFY(c3->isActive());
|
|
|
|
|
|
|
|
// Setup tabbox signal spies
|
|
|
|
QSignalSpy tabboxAddedSpy(TabBox::TabBox::self(), &TabBox::TabBox::tabBoxAdded);
|
|
|
|
QVERIFY(tabboxAddedSpy.isValid());
|
|
|
|
QSignalSpy tabboxClosedSpy(TabBox::TabBox::self(), &TabBox::TabBox::tabBoxClosed);
|
|
|
|
QVERIFY(tabboxClosedSpy.isValid());
|
|
|
|
|
|
|
|
// press alt+shift+tab
|
|
|
|
quint32 timestamp = 0;
|
|
|
|
kwinApp()->platform()->keyboardKeyPressed(KEY_LEFTALT, timestamp++);
|
|
|
|
QCOMPARE(input()->keyboardModifiers(), Qt::AltModifier);
|
|
|
|
kwinApp()->platform()->keyboardKeyPressed(KEY_LEFTSHIFT, timestamp++);
|
|
|
|
QCOMPARE(input()->keyboardModifiers(), Qt::AltModifier | Qt::ShiftModifier);
|
|
|
|
kwinApp()->platform()->keyboardKeyPressed(KEY_TAB, timestamp++);
|
|
|
|
kwinApp()->platform()->keyboardKeyReleased(KEY_TAB, timestamp++);
|
|
|
|
|
|
|
|
QVERIFY(tabboxAddedSpy.wait());
|
|
|
|
QVERIFY(TabBox::TabBox::self()->isGrabbed());
|
|
|
|
|
|
|
|
// release alt
|
|
|
|
kwinApp()->platform()->keyboardKeyReleased(KEY_LEFTSHIFT, timestamp++);
|
|
|
|
QCOMPARE(tabboxClosedSpy.count(), 0);
|
|
|
|
kwinApp()->platform()->keyboardKeyReleased(KEY_LEFTALT, timestamp++);
|
|
|
|
QCOMPARE(tabboxClosedSpy.count(), 1);
|
|
|
|
QCOMPARE(TabBox::TabBox::self()->isGrabbed(), false);
|
|
|
|
QCOMPARE(workspace()->activeClient(), c1);
|
|
|
|
|
|
|
|
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"
|