From 5e1e2be5e8dfdee8ccb1c8df194c840cb3c29452 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Gr=C3=A4=C3=9Flin?= Date: Thu, 14 Jul 2016 09:45:03 +0200 Subject: [PATCH] [autotests/integration] Add new test case for screenedge client show A test to simulate auto-hiding panels. Preparation step for making the slidingpopups effect working again for auto-hiding panels. The test case simulates creating a panel at the screen edge, hides it through the property and shows it again through the edge. --- autotests/integration/CMakeLists.txt | 1 + .../screenedge_client_show_test.cpp | 164 ++++++++++++++++++ 2 files changed, 165 insertions(+) create mode 100644 autotests/integration/screenedge_client_show_test.cpp diff --git a/autotests/integration/CMakeLists.txt b/autotests/integration/CMakeLists.txt index 8845f5f1f4..347c7a7a69 100644 --- a/autotests/integration/CMakeLists.txt +++ b/autotests/integration/CMakeLists.txt @@ -43,4 +43,5 @@ if (XCB_ICCCM_FOUND) integrationTest(NAME testShade SRCS shade_test.cpp LIBS XCB::ICCCM) integrationTest(NAME testDontCrashAuroraeDestroyDeco SRCS dont_crash_aurorae_destroy_deco.cpp LIBS XCB::ICCCM) integrationTest(NAME testPlasmaWindow SRCS plasmawindow_test.cpp LIBS XCB::ICCCM) + integrationTest(NAME testScreenEdgeClientShow SRCS screenedge_client_show_test.cpp LIBS XCB::ICCCM) endif() diff --git a/autotests/integration/screenedge_client_show_test.cpp b/autotests/integration/screenedge_client_show_test.cpp new file mode 100644 index 0000000000..297d2b3567 --- /dev/null +++ b/autotests/integration/screenedge_client_show_test.cpp @@ -0,0 +1,164 @@ +/******************************************************************** +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 "platform.h" +#include "client.h" +#include "cursor.h" +#include "deleted.h" +#include "screenedge.h" +#include "screens.h" +#include "wayland_server.h" +#include "workspace.h" +#include "shell_client.h" +#include + +#include +#include + +namespace KWin +{ + +static const QString s_socketName = QStringLiteral("wayland_test_kwin_screenedge_client_show-0"); + +class ScreenEdgeClientShowTest : public QObject +{ + Q_OBJECT +private Q_SLOTS: + void initTestCase(); + void init(); + void testScreenEdgeShowHideX11_data(); + void testScreenEdgeShowHideX11(); +}; + +void ScreenEdgeClientShowTest::initTestCase() +{ + qRegisterMetaType(); + qRegisterMetaType(); + qRegisterMetaType(); + QSignalSpy workspaceCreatedSpy(kwinApp(), &Application::workspaceCreated); + QVERIFY(workspaceCreatedSpy.isValid()); + kwinApp()->platform()->setInitialWindowSize(QSize(1280, 1024)); + QMetaObject::invokeMethod(kwinApp()->platform(), "setOutputCount", Qt::DirectConnection, Q_ARG(int, 2)); + QVERIFY(waylandServer()->init(s_socketName.toLocal8Bit())); + + kwinApp()->start(); + QVERIFY(workspaceCreatedSpy.wait()); + QCOMPARE(screens()->count(), 2); + QCOMPARE(screens()->geometry(0), QRect(0, 0, 1280, 1024)); + QCOMPARE(screens()->geometry(1), QRect(1280, 0, 1280, 1024)); + setenv("QT_QPA_PLATFORM", "wayland", true); + waylandServer()->initWorkspace(); +} + +void ScreenEdgeClientShowTest::init() +{ + screens()->setCurrent(0); + Cursor::setPos(QPoint(640, 512)); + QVERIFY(waylandServer()->clients().isEmpty()); +} + + +struct XcbConnectionDeleter +{ + static inline void cleanup(xcb_connection_t *pointer) + { + xcb_disconnect(pointer); + } +}; + +void ScreenEdgeClientShowTest::testScreenEdgeShowHideX11_data() +{ + QTest::addColumn("windowGeometry"); + QTest::addColumn("location"); + QTest::addColumn("triggerPos"); + + QTest::newRow("bottom/left") << QRect(50, 1004, 1180, 20) << 2u << QPoint(100, 1023); + QTest::newRow("bottom/right") << QRect(1330, 1004, 1180, 20) << 2u << QPoint(1400, 1023); + QTest::newRow("top/left") << QRect(50, 0, 1180, 20) << 0u << QPoint(100, 0); + QTest::newRow("top/right") << QRect(1330, 0, 1180, 20) << 0u << QPoint(1400, 0); + QTest::newRow("left") << QRect(0, 10, 20, 1000) << 3u << QPoint(0, 50); + QTest::newRow("right") << QRect(2540, 10, 20, 1000) << 1u << QPoint(2559, 60); +} + +void ScreenEdgeClientShowTest::testScreenEdgeShowHideX11() +{ + // this test creates a window which borders the screen and sets the screenedge show hint + // that should trigger a show of the window whenever the cursor is pushed against the screen edge + + // create the test window + QScopedPointer c(xcb_connect(nullptr, nullptr)); + QVERIFY(!xcb_connection_has_error(c.data())); + // atom for the screenedge show hide functionality + Xcb::Atom atom(QByteArrayLiteral("_KDE_NET_WM_SCREEN_EDGE_SHOW"), false, c.data()); + + xcb_window_t w = xcb_generate_id(c.data()); + QFETCH(QRect, windowGeometry); + 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 info(c.data(), w, rootWindow(), NET::WMAllProperties, NET::WM2AllProperties); + info.setWindowType(NET::Dock); + xcb_map_window(c.data(), w); + xcb_flush(c.data()); + + QSignalSpy windowCreatedSpy(workspace(), &Workspace::clientAdded); + QVERIFY(windowCreatedSpy.isValid()); + QVERIFY(windowCreatedSpy.wait()); + Client *client = windowCreatedSpy.last().first().value(); + QVERIFY(client); + QVERIFY(!client->isDecorated()); + QCOMPARE(client->geometry(), windowGeometry); + QVERIFY(!client->hasStrut()); + QVERIFY(!client->isHiddenInternal()); + + // now try to hide + QFETCH(quint32, location); + xcb_change_property(c.data(), XCB_PROP_MODE_REPLACE, w, atom, XCB_ATOM_CARDINAL, 32, 1, &location); + xcb_flush(c.data()); + + // we don't have a signal yet, so QTRY_VERIFY it is + QTRY_VERIFY(client->isHiddenInternal()); + + // now trigger the edge + QFETCH(QPoint, triggerPos); + Cursor::setPos(triggerPos); + QVERIFY(!client->isHiddenInternal()); + + // destroy window again + QSignalSpy windowClosedSpy(client, &Client::windowClosed); + QVERIFY(windowClosedSpy.isValid()); + xcb_unmap_window(c.data(), w); + xcb_destroy_window(c.data(), w); + xcb_flush(c.data()); + QVERIFY(windowClosedSpy.wait()); +} + +} + +WAYLANDTEST_MAIN(KWin::ScreenEdgeClientShowTest) +#include "screenedge_client_show_test.moc"