2020-08-02 22:22:19 +00:00
|
|
|
/*
|
|
|
|
KWin - the KDE window manager
|
|
|
|
This file is part of the KDE project.
|
2016-07-14 07:45:03 +00:00
|
|
|
|
2020-08-02 22:22:19 +00:00
|
|
|
SPDX-FileCopyrightText: 2016 Martin Gräßlin <mgraesslin@kde.org>
|
2016-07-14 07:45:03 +00:00
|
|
|
|
2020-08-02 22:22:19 +00:00
|
|
|
SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
*/
|
2016-07-14 07:45:03 +00:00
|
|
|
#include "kwin_wayland_test.h"
|
2022-03-23 10:13:38 +00:00
|
|
|
|
2016-07-14 07:45:03 +00:00
|
|
|
#include "cursor.h"
|
|
|
|
#include "deleted.h"
|
2022-04-14 12:33:28 +00:00
|
|
|
#include "output.h"
|
2022-03-23 10:13:38 +00:00
|
|
|
#include "platform.h"
|
2016-07-14 07:45:03 +00:00
|
|
|
#include "screenedge.h"
|
|
|
|
#include "wayland_server.h"
|
|
|
|
#include "workspace.h"
|
2022-04-22 17:54:31 +00:00
|
|
|
#include "x11window.h"
|
2016-07-14 07:45:03 +00:00
|
|
|
#include <kwineffects.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();
|
2017-03-28 20:01:16 +00:00
|
|
|
void testScreenEdgeShowX11Touch_data();
|
|
|
|
void testScreenEdgeShowX11Touch();
|
2016-07-14 07:45:03 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
void ScreenEdgeClientShowTest::initTestCase()
|
|
|
|
{
|
2022-04-22 17:39:12 +00:00
|
|
|
qRegisterMetaType<KWin::Window *>();
|
2022-03-23 10:13:38 +00:00
|
|
|
qRegisterMetaType<KWin::Deleted *>();
|
2020-07-07 09:32:29 +00:00
|
|
|
QSignalSpy applicationStartedSpy(kwinApp(), &Application::started);
|
|
|
|
QVERIFY(applicationStartedSpy.isValid());
|
2016-07-14 07:45:03 +00:00
|
|
|
kwinApp()->platform()->setInitialWindowSize(QSize(1280, 1024));
|
2020-12-09 13:06:15 +00:00
|
|
|
QVERIFY(waylandServer()->init(s_socketName));
|
2019-08-26 21:16:53 +00:00
|
|
|
QMetaObject::invokeMethod(kwinApp()->platform(), "setVirtualOutputs", Qt::DirectConnection, Q_ARG(int, 2));
|
2016-07-14 07:45:03 +00:00
|
|
|
|
2017-06-19 19:54:11 +00:00
|
|
|
// 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);
|
|
|
|
|
2016-07-14 07:45:03 +00:00
|
|
|
kwinApp()->start();
|
2020-07-07 09:32:29 +00:00
|
|
|
QVERIFY(applicationStartedSpy.wait());
|
2021-08-31 07:03:05 +00:00
|
|
|
const auto outputs = kwinApp()->platform()->enabledOutputs();
|
|
|
|
QCOMPARE(outputs.count(), 2);
|
|
|
|
QCOMPARE(outputs[0]->geometry(), QRect(0, 0, 1280, 1024));
|
|
|
|
QCOMPARE(outputs[1]->geometry(), QRect(1280, 0, 1280, 1024));
|
2016-07-14 07:45:03 +00:00
|
|
|
setenv("QT_QPA_PLATFORM", "wayland", true);
|
2021-05-08 00:08:22 +00:00
|
|
|
Test::initWaylandWorkspace();
|
2016-07-14 07:45:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ScreenEdgeClientShowTest::init()
|
|
|
|
{
|
2021-08-28 18:58:29 +00:00
|
|
|
workspace()->setActiveOutput(QPoint(640, 512));
|
2020-04-02 16:18:01 +00:00
|
|
|
Cursors::self()->mouse()->setPos(QPoint(640, 512));
|
2016-07-14 07:45:03 +00:00
|
|
|
QVERIFY(waylandServer()->clients().isEmpty());
|
|
|
|
}
|
|
|
|
|
|
|
|
struct XcbConnectionDeleter
|
|
|
|
{
|
|
|
|
static inline void cleanup(xcb_connection_t *pointer)
|
|
|
|
{
|
|
|
|
xcb_disconnect(pointer);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
void ScreenEdgeClientShowTest::testScreenEdgeShowHideX11_data()
|
|
|
|
{
|
|
|
|
QTest::addColumn<QRect>("windowGeometry");
|
2017-03-08 22:54:58 +00:00
|
|
|
QTest::addColumn<QRect>("resizedWindowGeometry");
|
2016-07-14 07:45:03 +00:00
|
|
|
QTest::addColumn<quint32>("location");
|
|
|
|
QTest::addColumn<QPoint>("triggerPos");
|
|
|
|
|
2017-03-08 22:54:58 +00:00
|
|
|
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);
|
2016-07-14 07:45:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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<xcb_connection_t, XcbConnectionDeleter> 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());
|
2022-04-22 17:54:31 +00:00
|
|
|
X11Window *client = windowCreatedSpy.last().first().value<X11Window *>();
|
2016-07-14 07:45:03 +00:00
|
|
|
QVERIFY(client);
|
|
|
|
QVERIFY(!client->isDecorated());
|
2019-09-27 10:01:10 +00:00
|
|
|
QCOMPARE(client->frameGeometry(), windowGeometry);
|
2016-07-14 07:45:03 +00:00
|
|
|
QVERIFY(!client->hasStrut());
|
|
|
|
QVERIFY(!client->isHiddenInternal());
|
|
|
|
|
2016-07-14 08:54:35 +00:00
|
|
|
QSignalSpy effectsWindowAdded(effects, &EffectsHandler::windowAdded);
|
|
|
|
QVERIFY(effectsWindowAdded.isValid());
|
|
|
|
QVERIFY(effectsWindowAdded.wait());
|
|
|
|
|
2016-07-14 07:45:03 +00:00
|
|
|
// 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());
|
|
|
|
|
2016-07-14 08:54:35 +00:00
|
|
|
QSignalSpy effectsWindowHiddenSpy(effects, &EffectsHandler::windowHidden);
|
|
|
|
QVERIFY(effectsWindowHiddenSpy.isValid());
|
2022-04-22 17:54:31 +00:00
|
|
|
QSignalSpy clientHiddenSpy(client, &X11Window::windowHidden);
|
2016-07-14 08:54:35 +00:00
|
|
|
QVERIFY(clientHiddenSpy.isValid());
|
|
|
|
QVERIFY(clientHiddenSpy.wait());
|
|
|
|
QVERIFY(client->isHiddenInternal());
|
|
|
|
QCOMPARE(effectsWindowHiddenSpy.count(), 1);
|
2016-07-14 07:45:03 +00:00
|
|
|
|
|
|
|
// now trigger the edge
|
2016-07-14 08:54:35 +00:00
|
|
|
QSignalSpy effectsWindowShownSpy(effects, &EffectsHandler::windowShown);
|
|
|
|
QVERIFY(effectsWindowShownSpy.isValid());
|
2016-07-14 07:45:03 +00:00
|
|
|
QFETCH(QPoint, triggerPos);
|
2020-04-02 16:18:01 +00:00
|
|
|
Cursors::self()->mouse()->setPos(triggerPos);
|
2016-07-14 07:45:03 +00:00
|
|
|
QVERIFY(!client->isHiddenInternal());
|
2016-07-14 08:54:35 +00:00
|
|
|
QCOMPARE(effectsWindowShownSpy.count(), 1);
|
2016-07-14 07:45:03 +00:00
|
|
|
|
2017-06-19 19:45:58 +00:00
|
|
|
// go into event loop to trigger xcb_flush
|
|
|
|
QTest::qWait(1);
|
|
|
|
|
2022-03-23 10:13:38 +00:00
|
|
|
// hide window again
|
2020-04-02 16:18:01 +00:00
|
|
|
Cursors::self()->mouse()->setPos(QPoint(640, 512));
|
2017-03-08 22:54:58 +00:00
|
|
|
xcb_change_property(c.data(), XCB_PROP_MODE_REPLACE, w, atom, XCB_ATOM_CARDINAL, 32, 1, &location);
|
|
|
|
xcb_flush(c.data());
|
|
|
|
QVERIFY(clientHiddenSpy.wait());
|
|
|
|
QVERIFY(client->isHiddenInternal());
|
|
|
|
QFETCH(QRect, resizedWindowGeometry);
|
2022-03-23 10:13:38 +00:00
|
|
|
// resizewhile hidden
|
Rework async geometry updates
Window management features were written with synchronous geometry
updates in mind. Currently, this poses a big problem on Wayland because
geometry updates are done in asynchronous fashion there.
At the moment, geometry is updated in a so called pseudo-asynchronous
fashion, meaning that the frame geometry will be reset to the old value
once geometry updates are unblocked. The main drawback of this approach
is that it is too error prone, the data flow is hard to comprehend, etc.
It is worth noting that there is already a machinery to perform async
geometry which is used during interactive move/resize operations.
This change extends the move/resize geometry usage beyond interactive
move/resize to make asynchronous geometry updates less error prone and
easier to comprehend.
With the proposed solution, all geometry updates must be done on the
move/resize geometry first. After that, the new geometry is passed on to
the Client-specific implementation of moveResizeInternal().
To be more specific, the frameGeometry() returns the current frame
geometry, it is primarily useful only to the scene. If you want to move
or resize a window, you need to use moveResizeGeometry() because it
corresponds to the last requested frame geometry.
It is worth noting that the moveResizeGeometry() returns the desired
bounding geometry. The client may commit the xdg_toplevel surface with a
slightly smaller window geometry, for example to enforce a specific
aspect ratio. The client is not allowed to resize beyond the size as
indicated in moveResizeGeometry().
The data flow is very simple: moveResize() updates the move/resize
geometry and calls the client-specific implementation of the
moveResizeInternal() method. Based on whether a configure event is
needed, moveResizeInternal() will update the frameGeometry() either
immediately or after the client commits a new buffer.
Unfortunately, both the compositor and xdg-shell clients try to update
the window geometry. It means that it's possible to have conflicts
between the two. With this change, the compositor's move resize geometry
will be synced only if there are no pending configure events, meaning
that the user doesn't try to resize the window.
2021-04-30 18:26:09 +00:00
|
|
|
client->moveResize(resizedWindowGeometry);
|
2022-03-23 10:13:38 +00:00
|
|
|
// triggerPos shouldn't be valid anymore
|
2020-04-02 16:18:01 +00:00
|
|
|
Cursors::self()->mouse()->setPos(triggerPos);
|
2017-03-08 22:54:58 +00:00
|
|
|
QVERIFY(client->isHiddenInternal());
|
|
|
|
|
2016-07-14 07:45:03 +00:00
|
|
|
// destroy window again
|
2022-04-22 17:54:31 +00:00
|
|
|
QSignalSpy windowClosedSpy(client, &X11Window::windowClosed);
|
2016-07-14 07:45:03 +00:00
|
|
|
QVERIFY(windowClosedSpy.isValid());
|
|
|
|
xcb_unmap_window(c.data(), w);
|
|
|
|
xcb_destroy_window(c.data(), w);
|
|
|
|
xcb_flush(c.data());
|
|
|
|
QVERIFY(windowClosedSpy.wait());
|
|
|
|
}
|
|
|
|
|
2017-03-28 20:01:16 +00:00
|
|
|
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
|
|
|
|
QScopedPointer<xcb_connection_t, XcbConnectionDeleter> 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());
|
2022-04-22 17:54:31 +00:00
|
|
|
X11Window *client = windowCreatedSpy.last().first().value<X11Window *>();
|
2017-03-28 20:01:16 +00:00
|
|
|
QVERIFY(client);
|
|
|
|
QVERIFY(!client->isDecorated());
|
2019-09-27 10:01:10 +00:00
|
|
|
QCOMPARE(client->frameGeometry(), windowGeometry);
|
2017-03-28 20:01:16 +00:00
|
|
|
QVERIFY(!client->hasStrut());
|
|
|
|
QVERIFY(!client->isHiddenInternal());
|
|
|
|
|
|
|
|
QSignalSpy effectsWindowAdded(effects, &EffectsHandler::windowAdded);
|
|
|
|
QVERIFY(effectsWindowAdded.isValid());
|
|
|
|
QVERIFY(effectsWindowAdded.wait());
|
|
|
|
|
|
|
|
// 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());
|
|
|
|
|
|
|
|
QSignalSpy effectsWindowHiddenSpy(effects, &EffectsHandler::windowHidden);
|
|
|
|
QVERIFY(effectsWindowHiddenSpy.isValid());
|
2022-04-22 17:54:31 +00:00
|
|
|
QSignalSpy clientHiddenSpy(client, &X11Window::windowHidden);
|
2017-03-28 20:01:16 +00:00
|
|
|
QVERIFY(clientHiddenSpy.isValid());
|
|
|
|
QVERIFY(clientHiddenSpy.wait());
|
|
|
|
QVERIFY(client->isHiddenInternal());
|
|
|
|
QCOMPARE(effectsWindowHiddenSpy.count(), 1);
|
|
|
|
|
|
|
|
// now trigger the edge
|
|
|
|
QSignalSpy effectsWindowShownSpy(effects, &EffectsHandler::windowShown);
|
|
|
|
QVERIFY(effectsWindowShownSpy.isValid());
|
|
|
|
quint32 timestamp = 0;
|
|
|
|
QFETCH(QPoint, touchDownPos);
|
|
|
|
QFETCH(QPoint, targetPos);
|
2022-03-10 10:27:35 +00:00
|
|
|
Test::touchDown(0, touchDownPos, timestamp++);
|
|
|
|
Test::touchMotion(0, targetPos, timestamp++);
|
|
|
|
Test::touchUp(0, timestamp++);
|
2017-03-28 20:01:16 +00:00
|
|
|
QVERIFY(effectsWindowShownSpy.wait());
|
|
|
|
QVERIFY(!client->isHiddenInternal());
|
|
|
|
QCOMPARE(effectsWindowShownSpy.count(), 1);
|
|
|
|
|
|
|
|
// destroy window again
|
2022-04-22 17:54:31 +00:00
|
|
|
QSignalSpy windowClosedSpy(client, &X11Window::windowClosed);
|
2017-03-28 20:01:16 +00:00
|
|
|
QVERIFY(windowClosedSpy.isValid());
|
|
|
|
xcb_unmap_window(c.data(), w);
|
|
|
|
xcb_destroy_window(c.data(), w);
|
|
|
|
xcb_flush(c.data());
|
|
|
|
QVERIFY(windowClosedSpy.wait());
|
|
|
|
}
|
|
|
|
|
2016-07-14 07:45:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
WAYLANDTEST_MAIN(KWin::ScreenEdgeClientShowTest)
|
|
|
|
#include "screenedge_client_show_test.moc"
|