diff --git a/autotests/integration/CMakeLists.txt b/autotests/integration/CMakeLists.txt index 15e00b6d4c..456188ec8a 100644 --- a/autotests/integration/CMakeLists.txt +++ b/autotests/integration/CMakeLists.txt @@ -39,6 +39,7 @@ integrationTest(NAME testSceneQPainter SRCS scene_qpainter_test.cpp) integrationTest(NAME testNoXdgRuntimeDir SRCS no_xdg_runtime_dir_test.cpp) integrationTest(NAME testScreenChanges SRCS screen_changes_test.cpp) integrationTest(NAME testModiferOnlyShortcut SRCS modifier_only_shortcut_test.cpp) +integrationTest(NAME testTabBox SRCS tabbox_test.cpp) if (XCB_ICCCM_FOUND) integrationTest(NAME testMoveResize SRCS move_resize_window_test.cpp LIBS XCB::ICCCM) diff --git a/autotests/integration/tabbox_test.cpp b/autotests/integration/tabbox_test.cpp new file mode 100644 index 0000000000..388afaaa8c --- /dev/null +++ b/autotests/integration/tabbox_test.cpp @@ -0,0 +1,142 @@ +/******************************************************************** +KWin - the KDE window manager +This file is part of the KDE project. + +Copyright (C) 2016 Martin Gräßlin + +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 . +*********************************************************************/ +#include "kwin_wayland_test.h" +#include "cursor.h" +#include "input.h" +#include "platform.h" +#include "screens.h" +#include "shell_client.h" +#include "tabbox/tabbox.h" +#include "wayland_server.h" +#include "workspace.h" + +#include +#include + +#include + +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(); + + void testCapsLock(); +}; + +void TabBoxTest::initTestCase() +{ + qRegisterMetaType(); + qRegisterMetaType(); + QSignalSpy workspaceCreatedSpy(kwinApp(), &Application::workspaceCreated); + QVERIFY(workspaceCreatedSpy.isValid()); + kwinApp()->platform()->setInitialWindowSize(QSize(1280, 1024)); + QVERIFY(waylandServer()->init(s_socketName.toLocal8Bit())); + + 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(); + QVERIFY(workspaceCreatedSpy.wait()); + waylandServer()->initWorkspace(); +} + +void TabBoxTest::init() +{ + QVERIFY(Test::setupWaylandConnection(s_socketName)); + screens()->setCurrent(0); + KWin::Cursor::setPos(QPoint(640, 512)); +} + +void TabBoxTest::cleanup() +{ + Test::destroyWaylandConnection(); +} + +void TabBoxTest::testCapsLock() +{ + // this test verifies that Alt+tab works correctly also when Capslock is on + // bug 368590 + + // first create two windows + QScopedPointer surface1(Test::createSurface()); + QScopedPointer shellSurface1(Test::createShellSurface(Test::ShellSurfaceType::WlShell, surface1.data())); + auto c1 = Test::renderAndWaitForShown(surface1.data(), QSize(100, 50), Qt::blue); + QVERIFY(c1); + QVERIFY(c1->isActive()); + QScopedPointer surface2(Test::createSurface()); + QScopedPointer shellSurface2(Test::createShellSurface(Test::ShellSurfaceType::XdgShellV5, surface2.data())); + auto c2 = Test::renderAndWaitForShown(surface2.data(), QSize(100, 50), Qt::red); + QVERIFY(c2); + QVERIFY(c2->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()); + + // 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++); + QEXPECT_FAIL("", "bug 368590", Continue); + QCOMPARE(tabboxClosedSpy.count(), 1); + QEXPECT_FAIL("", "bug 368590", Continue); + 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); + + surface2.reset(); + QVERIFY(Test::waitForWindowDestroyed(c2)); + surface1.reset(); + QVERIFY(Test::waitForWindowDestroyed(c1)); +} + +WAYLANDTEST_MAIN(TabBoxTest) +#include "tabbox_test.moc" diff --git a/tabbox/tabbox.h b/tabbox/tabbox.h index 2c77ef5cd6..ac11f2d169 100644 --- a/tabbox/tabbox.h +++ b/tabbox/tabbox.h @@ -113,7 +113,7 @@ private: AbstractClient* m_client; }; -class TabBox : public QObject +class KWIN_EXPORT TabBox : public QObject { Q_OBJECT public: