autotests: Rework _KDE_NET_WM_SCREEN_EDGE_SHOW test

This commit is contained in:
Vlad Zahorodnii 2023-04-30 17:39:28 +03:00
parent fdf89fd11a
commit 1d1ccc3770
4 changed files with 168 additions and 262 deletions

View file

@ -108,7 +108,6 @@ integrationTest(NAME testStruts SRCS struts_test.cpp LIBS XCB::ICCCM)
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)
integrationTest(NAME testX11DesktopWindow SRCS desktop_window_x11_test.cpp LIBS XCB::ICCCM)
integrationTest(NAME testXwaylandInput SRCS xwayland_input_test.cpp LIBS XCB::ICCCM)
integrationTest(NAME testWindowRules SRCS window_rules_test.cpp LIBS XCB::ICCCM)

View file

@ -1,259 +0,0 @@
/*
KWin - the KDE window manager
This file is part of the KDE project.
SPDX-FileCopyrightText: 2016 Martin Gräßlin <mgraesslin@kde.org>
SPDX-License-Identifier: GPL-2.0-or-later
*/
#include "kwin_wayland_test.h"
#include "core/output.h"
#include "core/outputbackend.h"
#include "libkwineffects/kwineffects.h"
#include "pointer_input.h"
#include "screenedge.h"
#include "wayland_server.h"
#include "workspace.h"
#include "x11window.h"
#include <netwm.h>
#include <xcb/xcb_icccm.h>
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 testScreenEdgeShowX11Touch_data();
void testScreenEdgeShowX11Touch();
};
void ScreenEdgeClientShowTest::initTestCase()
{
qRegisterMetaType<KWin::Window *>();
QSignalSpy applicationStartedSpy(kwinApp(), &Application::started);
QVERIFY(waylandServer()->init(s_socketName));
QMetaObject::invokeMethod(kwinApp()->outputBackend(), "setVirtualOutputs", Qt::DirectConnection, Q_ARG(QVector<QRect>, QVector<QRect>() << QRect(0, 0, 1280, 1024) << QRect(1280, 0, 1280, 1024)));
// set custom config which disable touch edge
KSharedConfig::Ptr config = KSharedConfig::openConfig(QString(), KConfig::SimpleConfig);
KConfigGroup group = config->group("TabBox");
group.writeEntry(QStringLiteral("TouchBorderActivate"), "9");
group.sync();
kwinApp()->setConfig(config);
kwinApp()->start();
QVERIFY(applicationStartedSpy.wait());
const auto outputs = workspace()->outputs();
QCOMPARE(outputs.count(), 2);
QCOMPARE(outputs[0]->geometry(), QRect(0, 0, 1280, 1024));
QCOMPARE(outputs[1]->geometry(), QRect(1280, 0, 1280, 1024));
setenv("QT_QPA_PLATFORM", "wayland", true);
}
void ScreenEdgeClientShowTest::init()
{
workspace()->setActiveOutput(QPoint(640, 512));
input()->pointer()->warp(QPoint(640, 512));
QVERIFY(waylandServer()->windows().isEmpty());
}
void ScreenEdgeClientShowTest::testScreenEdgeShowHideX11_data()
{
QTest::addColumn<QRect>("windowGeometry");
QTest::addColumn<QRect>("resizedWindowGeometry");
QTest::addColumn<quint32>("location");
QTest::addColumn<QPoint>("triggerPos");
QTest::newRow("bottom/left") << QRect(50, 1004, 1180, 20) << QRect(150, 1004, 1000, 20) << 2u << QPoint(100, 1023);
QTest::newRow("bottom/right") << QRect(1330, 1004, 1180, 20) << QRect(1410, 1004, 1000, 20) << 2u << QPoint(1400, 1023);
QTest::newRow("top/left") << QRect(50, 0, 1180, 20) << QRect(150, 0, 1000, 20) << 0u << QPoint(100, 0);
QTest::newRow("top/right") << QRect(1330, 0, 1180, 20) << QRect(1410, 0, 1000, 20) << 0u << QPoint(1400, 0);
QTest::newRow("left") << QRect(0, 10, 20, 1000) << QRect(0, 70, 20, 800) << 3u << QPoint(0, 50);
QTest::newRow("right") << QRect(2540, 10, 20, 1000) << QRect(2540, 70, 20, 800) << 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
Test::XcbConnectionPtr c = Test::createX11Connection();
QVERIFY(!xcb_connection_has_error(c.get()));
// atom for the screenedge show hide functionality
Xcb::Atom atom(QByteArrayLiteral("_KDE_NET_WM_SCREEN_EDGE_SHOW"), false, c.get());
xcb_window_t windowId = xcb_generate_id(c.get());
QFETCH(QRect, windowGeometry);
xcb_create_window(c.get(), XCB_COPY_FROM_PARENT, windowId, 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.get(), windowId, &hints);
NETWinInfo info(c.get(), windowId, rootWindow(), NET::WMAllProperties, NET::WM2AllProperties);
info.setWindowType(NET::Dock);
xcb_map_window(c.get(), windowId);
xcb_flush(c.get());
QSignalSpy windowCreatedSpy(workspace(), &Workspace::windowAdded);
QVERIFY(windowCreatedSpy.wait());
X11Window *window = windowCreatedSpy.last().first().value<X11Window *>();
QVERIFY(window);
QVERIFY(!window->isDecorated());
QCOMPARE(window->frameGeometry(), windowGeometry);
QVERIFY(!window->hasStrut());
QVERIFY(!window->isHiddenInternal());
QSignalSpy effectsWindowAdded(effects, &EffectsHandler::windowAdded);
QVERIFY(effectsWindowAdded.wait());
// now try to hide
QFETCH(quint32, location);
xcb_change_property(c.get(), XCB_PROP_MODE_REPLACE, windowId, atom, XCB_ATOM_CARDINAL, 32, 1, &location);
xcb_flush(c.get());
QSignalSpy effectsWindowHiddenSpy(effects, &EffectsHandler::windowHidden);
QSignalSpy clientHiddenSpy(window, &X11Window::windowHidden);
QVERIFY(clientHiddenSpy.wait());
QVERIFY(window->isHiddenInternal());
QCOMPARE(effectsWindowHiddenSpy.count(), 1);
// now trigger the edge
QSignalSpy effectsWindowShownSpy(effects, &EffectsHandler::windowShown);
QFETCH(QPoint, triggerPos);
input()->pointer()->warp(triggerPos);
QVERIFY(!window->isHiddenInternal());
QCOMPARE(effectsWindowShownSpy.count(), 1);
// go into event loop to trigger xcb_flush
QTest::qWait(1);
// hide window again
input()->pointer()->warp(QPoint(640, 512));
xcb_change_property(c.get(), XCB_PROP_MODE_REPLACE, windowId, atom, XCB_ATOM_CARDINAL, 32, 1, &location);
xcb_flush(c.get());
QVERIFY(clientHiddenSpy.wait());
QVERIFY(window->isHiddenInternal());
QFETCH(QRect, resizedWindowGeometry);
// resizewhile hidden
window->moveResize(resizedWindowGeometry);
// triggerPos shouldn't be valid anymore
input()->pointer()->warp(triggerPos);
QVERIFY(window->isHiddenInternal());
// destroy window again
QSignalSpy windowClosedSpy(window, &X11Window::closed);
xcb_unmap_window(c.get(), windowId);
xcb_destroy_window(c.get(), windowId);
xcb_flush(c.get());
QVERIFY(windowClosedSpy.wait());
}
void ScreenEdgeClientShowTest::testScreenEdgeShowX11Touch_data()
{
QTest::addColumn<QRect>("windowGeometry");
QTest::addColumn<quint32>("location");
QTest::addColumn<QPoint>("touchDownPos");
QTest::addColumn<QPoint>("targetPos");
QTest::newRow("bottom/left") << QRect(50, 1004, 1180, 20) << 2u << QPoint(100, 1023) << QPoint(100, 540);
QTest::newRow("bottom/right") << QRect(1330, 1004, 1180, 20) << 2u << QPoint(1400, 1023) << QPoint(1400, 520);
QTest::newRow("top/left") << QRect(50, 0, 1180, 20) << 0u << QPoint(100, 0) << QPoint(100, 350);
QTest::newRow("top/right") << QRect(1330, 0, 1180, 20) << 0u << QPoint(1400, 0) << QPoint(1400, 400);
QTest::newRow("left") << QRect(0, 10, 20, 1000) << 3u << QPoint(0, 50) << QPoint(400, 50);
QTest::newRow("right") << QRect(2540, 10, 20, 1000) << 1u << QPoint(2559, 60) << QPoint(2200, 60);
}
void ScreenEdgeClientShowTest::testScreenEdgeShowX11Touch()
{
// 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 touch screen swipe gesture is triggered
// create the test window
Test::XcbConnectionPtr c = Test::createX11Connection();
QVERIFY(!xcb_connection_has_error(c.get()));
// atom for the screenedge show hide functionality
Xcb::Atom atom(QByteArrayLiteral("_KDE_NET_WM_SCREEN_EDGE_SHOW"), false, c.get());
xcb_window_t windowId = xcb_generate_id(c.get());
QFETCH(QRect, windowGeometry);
xcb_create_window(c.get(), XCB_COPY_FROM_PARENT, windowId, 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.get(), windowId, &hints);
NETWinInfo info(c.get(), windowId, rootWindow(), NET::WMAllProperties, NET::WM2AllProperties);
info.setWindowType(NET::Dock);
xcb_map_window(c.get(), windowId);
xcb_flush(c.get());
QSignalSpy windowCreatedSpy(workspace(), &Workspace::windowAdded);
QVERIFY(windowCreatedSpy.wait());
X11Window *window = windowCreatedSpy.last().first().value<X11Window *>();
QVERIFY(window);
QVERIFY(!window->isDecorated());
QCOMPARE(window->frameGeometry(), windowGeometry);
QVERIFY(!window->hasStrut());
QVERIFY(!window->isHiddenInternal());
QSignalSpy effectsWindowAdded(effects, &EffectsHandler::windowAdded);
QVERIFY(effectsWindowAdded.wait());
// now try to hide
QFETCH(quint32, location);
xcb_change_property(c.get(), XCB_PROP_MODE_REPLACE, windowId, atom, XCB_ATOM_CARDINAL, 32, 1, &location);
xcb_flush(c.get());
QSignalSpy effectsWindowHiddenSpy(effects, &EffectsHandler::windowHidden);
QSignalSpy clientHiddenSpy(window, &X11Window::windowHidden);
QVERIFY(clientHiddenSpy.wait());
QVERIFY(window->isHiddenInternal());
QCOMPARE(effectsWindowHiddenSpy.count(), 1);
// now trigger the edge
QSignalSpy effectsWindowShownSpy(effects, &EffectsHandler::windowShown);
quint32 timestamp = 0;
QFETCH(QPoint, touchDownPos);
QFETCH(QPoint, targetPos);
Test::touchDown(0, touchDownPos, timestamp++);
Test::touchMotion(0, targetPos, timestamp++);
Test::touchUp(0, timestamp++);
QVERIFY(effectsWindowShownSpy.wait());
QVERIFY(!window->isHiddenInternal());
QCOMPARE(effectsWindowShownSpy.count(), 1);
// destroy window again
QSignalSpy windowClosedSpy(window, &X11Window::closed);
xcb_unmap_window(c.get(), windowId);
xcb_destroy_window(c.get(), windowId);
xcb_flush(c.get());
QVERIFY(windowClosedSpy.wait());
}
}
WAYLANDTEST_MAIN(KWin::ScreenEdgeClientShowTest)
#include "screenedge_client_show_test.moc"

View file

@ -10,6 +10,7 @@
#include "kwin_wayland_test.h"
#include "atoms.h"
#include "core/outputbackend.h"
#include "cursor.h"
#include "effectloader.h"
@ -25,6 +26,8 @@
#include <QAction>
#include <xcb/xcb_icccm.h>
Q_DECLARE_METATYPE(KWin::ElectricBorder)
namespace KWin
@ -63,6 +66,7 @@ private Q_SLOTS:
void testClientEdge();
void testObjectEdge_data();
void testObjectEdge();
void testKdeNetWmScreenEdgeShow();
};
void ScreenEdgesTest::initTestCase()
@ -344,6 +348,170 @@ void ScreenEdgesTest::testObjectEdge()
QCOMPARE(spy.count(), 2);
}
static void enableAutoHide(xcb_connection_t *connection, xcb_window_t windowId, ElectricBorder border)
{
if (border == ElectricNone) {
xcb_delete_property(connection, windowId, atoms->kde_screen_edge_show);
} else {
uint32_t value = 0;
switch (border) {
case ElectricTop:
value = 0;
break;
case ElectricRight:
value = 1;
break;
case ElectricBottom:
value = 2;
break;
case ElectricLeft:
value = 3;
break;
default:
Q_UNREACHABLE();
}
xcb_change_property(connection, XCB_PROP_MODE_REPLACE, windowId, atoms->kde_screen_edge_show, XCB_ATOM_CARDINAL, 32, 1, &value);
}
}
class ScreenEdgePropertyMonitor : public QObject
{
Q_OBJECT
public:
ScreenEdgePropertyMonitor(xcb_connection_t *c, xcb_window_t window)
: QObject()
, m_connection(c)
, m_window(window)
, m_notifier(new QSocketNotifier(xcb_get_file_descriptor(m_connection), QSocketNotifier::Read, this))
{
connect(m_notifier, &QSocketNotifier::activated, this, &ScreenEdgePropertyMonitor::processXcbEvents);
connect(QCoreApplication::eventDispatcher(), &QAbstractEventDispatcher::aboutToBlock, this, &ScreenEdgePropertyMonitor::processXcbEvents);
connect(QCoreApplication::eventDispatcher(), &QAbstractEventDispatcher::awake, this, &ScreenEdgePropertyMonitor::processXcbEvents);
}
Q_SIGNALS:
void withdrawn();
private:
void processXcbEvents()
{
while (auto event = xcb_poll_for_event(m_connection)) {
const uint8_t eventType = event->response_type & ~0x80;
switch (eventType) {
case XCB_PROPERTY_NOTIFY: {
auto propertyNotifyEvent = reinterpret_cast<xcb_property_notify_event_t *>(event);
if (propertyNotifyEvent->window == m_window && propertyNotifyEvent->atom == atoms->kde_screen_edge_show && propertyNotifyEvent->state == XCB_PROPERTY_DELETE) {
Q_EMIT withdrawn();
}
break;
}
}
free(event);
}
}
xcb_connection_t *m_connection;
xcb_window_t m_window;
QSocketNotifier *m_notifier;
};
void ScreenEdgesTest::testKdeNetWmScreenEdgeShow()
{
// This test verifies that _KDE_NET_WM_SCREEN_EDGE_SHOW is handled properly. Note that
// _KDE_NET_WM_SCREEN_EDGE_SHOW has oneshot effect. It's deleted when the window is shown.
Test::XcbConnectionPtr c = Test::createX11Connection();
QVERIFY(!xcb_connection_has_error(c.get()));
// Create a test window at the bottom of the screen.
const QRect windowGeometry(0, 1024 - 30, 1280, 30);
const uint32_t values[] = {XCB_EVENT_MASK_PROPERTY_CHANGE};
xcb_window_t windowId = xcb_generate_id(c.get());
xcb_create_window(c.get(), XCB_COPY_FROM_PARENT, windowId, rootWindow(),
windowGeometry.x(),
windowGeometry.y(),
windowGeometry.width(),
windowGeometry.height(),
0, XCB_WINDOW_CLASS_INPUT_OUTPUT,
XCB_COPY_FROM_PARENT,
XCB_CW_EVENT_MASK, values);
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.get(), windowId, &hints);
xcb_change_property(c.get(), XCB_PROP_MODE_REPLACE, windowId, atoms->wm_client_leader, XCB_ATOM_WINDOW, 32, 1, &windowId);
xcb_map_window(c.get(), windowId);
xcb_flush(c.get());
QSignalSpy windowCreatedSpy(workspace(), &Workspace::windowAdded);
QVERIFY(windowCreatedSpy.wait());
Window *window = windowCreatedSpy.first().first().value<Window *>();
QVERIFY(window);
ScreenEdgePropertyMonitor screenEdgeMonitor(c.get(), windowId);
QSignalSpy withdrawnSpy(&screenEdgeMonitor, &ScreenEdgePropertyMonitor::withdrawn);
QSignalSpy windowShownSpy(window, &Window::windowShown);
QSignalSpy windowHiddenSpy(window, &Window::windowHidden);
quint32 timestamp = 0;
// The window will be shown when the pointer approaches its reserved screen edge.
{
enableAutoHide(c.get(), windowId, ElectricBottom);
xcb_flush(c.get());
QVERIFY(windowHiddenSpy.wait());
QVERIFY(!window->isShown());
Test::pointerMotion(QPointF(640, 1024), timestamp++);
QVERIFY(withdrawnSpy.wait());
QVERIFY(window->isShown());
Test::pointerMotion(QPointF(640, 512), timestamp++);
QVERIFY(window->isShown());
}
// The window will be shown when swiping on the touch screen.
{
enableAutoHide(c.get(), windowId, ElectricBottom);
xcb_flush(c.get());
QVERIFY(windowHiddenSpy.wait());
QVERIFY(!window->isShown());
Test::touchDown(0, QPointF(640, 1023), timestamp++);
Test::touchMotion(0, QPointF(640, 512), timestamp++);
Test::touchUp(0, timestamp++);
QVERIFY(withdrawnSpy.wait());
QVERIFY(window->isShown());
}
// If the screen edge is destroyed (can happen when the screen layout changes), the window will be shown.
{
enableAutoHide(c.get(), windowId, ElectricBottom);
xcb_flush(c.get());
QVERIFY(windowHiddenSpy.wait());
QVERIFY(!window->isShown());
workspace()->screenEdges()->recreateEdges();
QVERIFY(withdrawnSpy.wait());
QVERIFY(window->isShown());
}
// The window will be shown and hidden in response to changing _KDE_NET_WM_SCREEN_EDGE_SHOW.
{
enableAutoHide(c.get(), windowId, ElectricBottom);
xcb_flush(c.get());
QVERIFY(windowHiddenSpy.wait());
QVERIFY(!window->isShown());
enableAutoHide(c.get(), windowId, ElectricNone);
xcb_flush(c.get());
QVERIFY(windowShownSpy.wait());
QVERIFY(window->isShown());
}
}
} // namespace KWin
WAYLANDTEST_MAIN(KWin::ScreenEdgesTest)

View file

@ -124,8 +124,6 @@ void XWaylandInputTest::testPointerEnterLeaveSsd()
X11EventReaderHelper eventReader(c.get());
QSignalSpy enteredSpy(&eventReader, &X11EventReaderHelper::entered);
QSignalSpy leftSpy(&eventReader, &X11EventReaderHelper::left);
// atom for the screenedge show hide functionality
Xcb::Atom atom(QByteArrayLiteral("_KDE_NET_WM_SCREEN_EDGE_SHOW"), false, c.get());
xcb_window_t windowId = xcb_generate_id(c.get());
const QRect windowGeometry = QRect(0, 0, 100, 200);