kwin/autotests/integration/x11_window_test.cpp

981 lines
42 KiB
C++
Raw Normal View History

2020-08-02 22:22:19 +00:00
/*
KWin - the KDE window manager
This file is part of the KDE project.
2020-08-02 22:22:19 +00:00
SPDX-FileCopyrightText: 2016 Martin Gräßlin <mgraesslin@kde.org>
2020-08-02 22:22:19 +00:00
SPDX-License-Identifier: GPL-2.0-or-later
*/
#include "kwin_wayland_test.h"
#include "atoms.h"
2023-08-31 12:23:42 +00:00
#include "compositor.h"
#include "cursor.h"
2023-11-17 08:59:08 +00:00
#include "effect/effectloader.h"
#include "wayland_server.h"
#include "workspace.h"
#include "x11window.h"
#include <KWayland/Client/surface.h>
#include <netwm.h>
#include <xcb/xcb_icccm.h>
using namespace KWin;
static const QString s_socketName = QStringLiteral("wayland_test_x11_window-0");
class X11WindowTest : public QObject
{
Q_OBJECT
private Q_SLOTS:
void initTestCase_data();
void initTestCase();
void init();
void cleanup();
void testMinimumSize();
void testMaximumSize();
void testResizeIncrements();
void testResizeIncrementsNoBaseSize();
void testTrimCaption_data();
void testTrimCaption();
void testFullscreenLayerWithActiveWaylandWindow();
void testFocusInWithWaylandLastActiveWindow();
void testCaptionChanges();
void testCaptionWmName();
void testFullscreenWindowGroups();
void testActivateFocusedWindow();
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
void testReentrantMoveResize();
};
void X11WindowTest::initTestCase_data()
{
QTest::addColumn<qreal>("scale");
QTest::newRow("normal") << 1.0;
QTest::newRow("scaled2x") << 2.0;
}
void X11WindowTest::initTestCase()
{
2022-04-22 17:39:12 +00:00
qRegisterMetaType<KWin::Window *>();
QSignalSpy applicationStartedSpy(kwinApp(), &Application::started);
QVERIFY(waylandServer()->init(s_socketName));
Test::setOutputConfig({QRect(0, 0, 1280, 1024)});
kwinApp()->setConfig(KSharedConfig::openConfig(QString(), KConfig::SimpleConfig));
kwinApp()->start();
QVERIFY(applicationStartedSpy.wait());
QVERIFY(KWin::Compositor::self());
}
void X11WindowTest::init()
{
QVERIFY(Test::setupWaylandConnection());
}
void X11WindowTest::cleanup()
{
Test::destroyWaylandConnection();
}
void X11WindowTest::testMinimumSize()
{
// This test verifies that the minimum size constraint is correctly applied.
QFETCH_GLOBAL(qreal, scale);
kwinApp()->setXwaylandScale(scale);
// Create an xcb window.
Test::XcbConnectionPtr c = Test::createX11Connection();
QVERIFY(!xcb_connection_has_error(c.get()));
const QRect windowGeometry(0, 0, 100, 200);
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, 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_size_hints_set_min_size(&hints, windowGeometry.width(), windowGeometry.height());
xcb_icccm_set_wm_normal_hints(c.get(), windowId, &hints);
xcb_map_window(c.get(), windowId);
xcb_flush(c.get());
QSignalSpy windowCreatedSpy(workspace(), &Workspace::windowAdded);
QVERIFY(windowCreatedSpy.wait());
2022-04-23 19:51:16 +00:00
X11Window *window = windowCreatedSpy.last().first().value<X11Window *>();
QVERIFY(window);
QVERIFY(window->isDecorated());
QSignalSpy interactiveMoveResizeStartedSpy(window, &Window::interactiveMoveResizeStarted);
QSignalSpy interactiveMoveResizeSteppedSpy(window, &Window::interactiveMoveResizeStepped);
QSignalSpy interactiveMoveResizeFinishedSpy(window, &Window::interactiveMoveResizeFinished);
2022-04-23 19:51:16 +00:00
QSignalSpy frameGeometryChangedSpy(window, &Window::frameGeometryChanged);
// Begin resize.
QCOMPARE(workspace()->moveResizeWindow(), nullptr);
2022-04-23 19:51:16 +00:00
QVERIFY(!window->isInteractiveResize());
workspace()->slotWindowResize();
2022-04-23 19:51:16 +00:00
QCOMPARE(workspace()->moveResizeWindow(), window);
QCOMPARE(interactiveMoveResizeStartedSpy.count(), 1);
2022-04-23 19:51:16 +00:00
QVERIFY(window->isInteractiveResize());
const QPointF cursorPos = KWin::Cursors::self()->mouse()->pos();
2022-04-23 19:51:16 +00:00
window->keyPressEvent(Qt::Key_Left);
window->updateInteractiveMoveResize(KWin::Cursors::self()->mouse()->pos());
QCOMPARE(KWin::Cursors::self()->mouse()->pos(), cursorPos + QPoint(-8, 0));
QCOMPARE(interactiveMoveResizeSteppedSpy.count(), 0);
QVERIFY(!frameGeometryChangedSpy.wait(10));
QCOMPARE(window->clientSize().width(), 100 / scale);
2022-04-23 19:51:16 +00:00
window->keyPressEvent(Qt::Key_Right);
window->updateInteractiveMoveResize(KWin::Cursors::self()->mouse()->pos());
QCOMPARE(KWin::Cursors::self()->mouse()->pos(), cursorPos);
QCOMPARE(interactiveMoveResizeSteppedSpy.count(), 0);
QVERIFY(!frameGeometryChangedSpy.wait(10));
QCOMPARE(window->clientSize().width(), 100 / scale);
2022-04-23 19:51:16 +00:00
window->keyPressEvent(Qt::Key_Right);
window->updateInteractiveMoveResize(KWin::Cursors::self()->mouse()->pos());
QCOMPARE(KWin::Cursors::self()->mouse()->pos(), cursorPos + QPoint(8, 0));
QCOMPARE(interactiveMoveResizeSteppedSpy.count(), 1);
QVERIFY(frameGeometryChangedSpy.wait());
// whilst X11 window size goes through scale, the increment is a logical value kwin side
QCOMPARE(window->clientSize().width(), 100 / scale + 8);
2022-04-23 19:51:16 +00:00
window->keyPressEvent(Qt::Key_Up);
window->updateInteractiveMoveResize(KWin::Cursors::self()->mouse()->pos());
QCOMPARE(KWin::Cursors::self()->mouse()->pos(), cursorPos + QPoint(8, -8));
QCOMPARE(interactiveMoveResizeSteppedSpy.count(), 1);
QVERIFY(!frameGeometryChangedSpy.wait(10));
QCOMPARE(window->clientSize().height(), 200 / scale);
2022-04-23 19:51:16 +00:00
window->keyPressEvent(Qt::Key_Down);
window->updateInteractiveMoveResize(KWin::Cursors::self()->mouse()->pos());
QCOMPARE(KWin::Cursors::self()->mouse()->pos(), cursorPos + QPoint(8, 0));
QCOMPARE(interactiveMoveResizeSteppedSpy.count(), 1);
QVERIFY(!frameGeometryChangedSpy.wait(10));
QCOMPARE(window->clientSize().height(), 200 / scale);
2022-04-23 19:51:16 +00:00
window->keyPressEvent(Qt::Key_Down);
window->updateInteractiveMoveResize(KWin::Cursors::self()->mouse()->pos());
QCOMPARE(KWin::Cursors::self()->mouse()->pos(), cursorPos + QPoint(8, 8));
QCOMPARE(interactiveMoveResizeSteppedSpy.count(), 2);
QVERIFY(frameGeometryChangedSpy.wait());
QCOMPARE(window->clientSize().height(), 200 / scale + 8);
// Finish the resize operation.
QCOMPARE(interactiveMoveResizeFinishedSpy.count(), 0);
2022-04-23 19:51:16 +00:00
window->keyPressEvent(Qt::Key_Enter);
QCOMPARE(interactiveMoveResizeFinishedSpy.count(), 1);
QCOMPARE(workspace()->moveResizeWindow(), nullptr);
2022-04-23 19:51:16 +00:00
QVERIFY(!window->isInteractiveResize());
// Destroy the window.
QSignalSpy windowClosedSpy(window, &X11Window::closed);
xcb_unmap_window(c.get(), windowId);
xcb_destroy_window(c.get(), windowId);
xcb_flush(c.get());
QVERIFY(windowClosedSpy.wait());
c.reset();
}
void X11WindowTest::testMaximumSize()
{
// This test verifies that the maximum size constraint is correctly applied.
QFETCH_GLOBAL(qreal, scale);
kwinApp()->setXwaylandScale(scale);
// Create an xcb window.
Test::XcbConnectionPtr c = Test::createX11Connection();
QVERIFY(!xcb_connection_has_error(c.get()));
const QRect windowGeometry(0, 0, 100, 200);
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, 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_size_hints_set_max_size(&hints, windowGeometry.width(), windowGeometry.height());
xcb_icccm_set_wm_normal_hints(c.get(), windowId, &hints);
xcb_map_window(c.get(), windowId);
xcb_flush(c.get());
QSignalSpy windowCreatedSpy(workspace(), &Workspace::windowAdded);
QVERIFY(windowCreatedSpy.wait());
2022-04-23 19:51:16 +00:00
X11Window *window = windowCreatedSpy.last().first().value<X11Window *>();
QVERIFY(window);
QVERIFY(window->isDecorated());
QSignalSpy interactiveMoveResizeStartedSpy(window, &Window::interactiveMoveResizeStarted);
QSignalSpy interactiveMoveResizeSteppedSpy(window, &Window::interactiveMoveResizeStepped);
QSignalSpy interactiveMoveResizeFinishedSpy(window, &Window::interactiveMoveResizeFinished);
2022-04-23 19:51:16 +00:00
QSignalSpy frameGeometryChangedSpy(window, &Window::frameGeometryChanged);
// Begin resize.
QCOMPARE(workspace()->moveResizeWindow(), nullptr);
2022-04-23 19:51:16 +00:00
QVERIFY(!window->isInteractiveResize());
workspace()->slotWindowResize();
2022-04-23 19:51:16 +00:00
QCOMPARE(workspace()->moveResizeWindow(), window);
QCOMPARE(interactiveMoveResizeStartedSpy.count(), 1);
2022-04-23 19:51:16 +00:00
QVERIFY(window->isInteractiveResize());
const QPointF cursorPos = KWin::Cursors::self()->mouse()->pos();
2022-04-23 19:51:16 +00:00
window->keyPressEvent(Qt::Key_Right);
window->updateInteractiveMoveResize(KWin::Cursors::self()->mouse()->pos());
QCOMPARE(KWin::Cursors::self()->mouse()->pos(), cursorPos + QPoint(8, 0));
QCOMPARE(interactiveMoveResizeSteppedSpy.count(), 0);
QVERIFY(!frameGeometryChangedSpy.wait(10));
QCOMPARE(window->clientSize().width(), 100 / scale);
2022-04-23 19:51:16 +00:00
window->keyPressEvent(Qt::Key_Left);
window->updateInteractiveMoveResize(KWin::Cursors::self()->mouse()->pos());
QCOMPARE(KWin::Cursors::self()->mouse()->pos(), cursorPos);
QVERIFY(!interactiveMoveResizeSteppedSpy.wait(10));
QCOMPARE(interactiveMoveResizeSteppedSpy.count(), 0);
QCOMPARE(window->clientSize().width(), 100 / scale);
2022-04-23 19:51:16 +00:00
window->keyPressEvent(Qt::Key_Left);
window->updateInteractiveMoveResize(KWin::Cursors::self()->mouse()->pos());
QCOMPARE(KWin::Cursors::self()->mouse()->pos(), cursorPos + QPoint(-8, 0));
QCOMPARE(interactiveMoveResizeSteppedSpy.count(), 1);
QVERIFY(frameGeometryChangedSpy.wait());
QCOMPARE(window->clientSize().width(), 100 / scale - 8);
2022-04-23 19:51:16 +00:00
window->keyPressEvent(Qt::Key_Down);
window->updateInteractiveMoveResize(KWin::Cursors::self()->mouse()->pos());
QCOMPARE(KWin::Cursors::self()->mouse()->pos(), cursorPos + QPoint(-8, 8));
QCOMPARE(interactiveMoveResizeSteppedSpy.count(), 1);
QVERIFY(!frameGeometryChangedSpy.wait(10));
QCOMPARE(window->clientSize().height(), 200 / scale);
2022-04-23 19:51:16 +00:00
window->keyPressEvent(Qt::Key_Up);
window->updateInteractiveMoveResize(KWin::Cursors::self()->mouse()->pos());
QCOMPARE(KWin::Cursors::self()->mouse()->pos(), cursorPos + QPoint(-8, 0));
QCOMPARE(interactiveMoveResizeSteppedSpy.count(), 1);
QVERIFY(!frameGeometryChangedSpy.wait(10));
QCOMPARE(window->clientSize().height(), 200 / scale);
2022-04-23 19:51:16 +00:00
window->keyPressEvent(Qt::Key_Up);
window->updateInteractiveMoveResize(KWin::Cursors::self()->mouse()->pos());
QCOMPARE(KWin::Cursors::self()->mouse()->pos(), cursorPos + QPoint(-8, -8));
QCOMPARE(interactiveMoveResizeSteppedSpy.count(), 2);
QVERIFY(frameGeometryChangedSpy.wait());
QCOMPARE(window->clientSize().height(), 200 / scale - 8);
// Finish the resize operation.
QCOMPARE(interactiveMoveResizeFinishedSpy.count(), 0);
2022-04-23 19:51:16 +00:00
window->keyPressEvent(Qt::Key_Enter);
QCOMPARE(interactiveMoveResizeFinishedSpy.count(), 1);
QCOMPARE(workspace()->moveResizeWindow(), nullptr);
2022-04-23 19:51:16 +00:00
QVERIFY(!window->isInteractiveResize());
// Destroy the window.
QSignalSpy windowClosedSpy(window, &X11Window::closed);
xcb_unmap_window(c.get(), windowId);
xcb_destroy_window(c.get(), windowId);
xcb_flush(c.get());
QVERIFY(windowClosedSpy.wait());
c.reset();
}
void X11WindowTest::testResizeIncrements()
{
// This test verifies that the resize increments constraint is correctly applied.
QFETCH_GLOBAL(qreal, scale);
kwinApp()->setXwaylandScale(scale);
// Create an xcb window.
Test::XcbConnectionPtr c = Test::createX11Connection();
QVERIFY(!xcb_connection_has_error(c.get()));
const QRect windowGeometry(0, 0, 100, 200);
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, 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_size_hints_set_base_size(&hints, windowGeometry.width(), windowGeometry.height());
xcb_icccm_size_hints_set_resize_inc(&hints, 3, 5);
xcb_icccm_set_wm_normal_hints(c.get(), windowId, &hints);
xcb_map_window(c.get(), windowId);
xcb_flush(c.get());
QSignalSpy windowCreatedSpy(workspace(), &Workspace::windowAdded);
QVERIFY(windowCreatedSpy.wait());
2022-04-23 19:51:16 +00:00
X11Window *window = windowCreatedSpy.last().first().value<X11Window *>();
QVERIFY(window);
QVERIFY(window->isDecorated());
QSignalSpy interactiveMoveResizeStartedSpy(window, &Window::interactiveMoveResizeStarted);
QSignalSpy interactiveMoveResizeSteppedSpy(window, &Window::interactiveMoveResizeStepped);
QSignalSpy interactiveMoveResizeFinishedSpy(window, &Window::interactiveMoveResizeFinished);
2022-04-23 19:51:16 +00:00
QSignalSpy frameGeometryChangedSpy(window, &Window::frameGeometryChanged);
// Begin resize.
QCOMPARE(workspace()->moveResizeWindow(), nullptr);
2022-04-23 19:51:16 +00:00
QVERIFY(!window->isInteractiveResize());
workspace()->slotWindowResize();
2022-04-23 19:51:16 +00:00
QCOMPARE(workspace()->moveResizeWindow(), window);
QCOMPARE(interactiveMoveResizeStartedSpy.count(), 1);
2022-04-23 19:51:16 +00:00
QVERIFY(window->isInteractiveResize());
const QPointF cursorPos = KWin::Cursors::self()->mouse()->pos();
2022-04-23 19:51:16 +00:00
window->keyPressEvent(Qt::Key_Right);
window->updateInteractiveMoveResize(KWin::Cursors::self()->mouse()->pos());
QCOMPARE(KWin::Cursors::self()->mouse()->pos(), cursorPos + QPoint(8, 0));
QCOMPARE(interactiveMoveResizeSteppedSpy.count(), 1);
QVERIFY(frameGeometryChangedSpy.wait());
// 100 + 8 logical pixels, rounded to resize increments. This will differ on scale
const qreal horizontalResizeInc = 3 / scale;
const qreal verticalResizeInc = 5 / scale;
const qreal expectedHorizontalResizeInc = std::floor(8. / horizontalResizeInc) * horizontalResizeInc;
const qreal expectedVerticalResizeInc = std::floor(8. / verticalResizeInc) * verticalResizeInc;
QCOMPARE(window->clientSize(), QSizeF(100, 200) / scale + QSizeF(expectedHorizontalResizeInc, 0));
2022-04-23 19:51:16 +00:00
window->keyPressEvent(Qt::Key_Down);
window->updateInteractiveMoveResize(KWin::Cursors::self()->mouse()->pos());
QCOMPARE(KWin::Cursors::self()->mouse()->pos(), cursorPos + QPoint(8, 8));
QCOMPARE(interactiveMoveResizeSteppedSpy.count(), 2);
QVERIFY(frameGeometryChangedSpy.wait());
QCOMPARE(window->clientSize(), QSize(100, 200) / scale + QSizeF(expectedHorizontalResizeInc, expectedVerticalResizeInc));
// Finish the resize operation.
QCOMPARE(interactiveMoveResizeFinishedSpy.count(), 0);
2022-04-23 19:51:16 +00:00
window->keyPressEvent(Qt::Key_Enter);
QCOMPARE(interactiveMoveResizeFinishedSpy.count(), 1);
QCOMPARE(workspace()->moveResizeWindow(), nullptr);
2022-04-23 19:51:16 +00:00
QVERIFY(!window->isInteractiveResize());
// Destroy the window.
QSignalSpy windowClosedSpy(window, &X11Window::closed);
xcb_unmap_window(c.get(), windowId);
xcb_destroy_window(c.get(), windowId);
xcb_flush(c.get());
QVERIFY(windowClosedSpy.wait());
c.reset();
}
void X11WindowTest::testResizeIncrementsNoBaseSize()
{
QFETCH_GLOBAL(qreal, scale);
kwinApp()->setXwaylandScale(scale);
// Create an xcb window.
Test::XcbConnectionPtr c = Test::createX11Connection();
QVERIFY(!xcb_connection_has_error(c.get()));
const QRect windowGeometry(0, 0, 100, 200);
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, 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_size_hints_set_min_size(&hints, windowGeometry.width(), windowGeometry.height());
xcb_icccm_size_hints_set_resize_inc(&hints, 3, 5);
xcb_icccm_set_wm_normal_hints(c.get(), windowId, &hints);
xcb_map_window(c.get(), windowId);
xcb_flush(c.get());
QSignalSpy windowCreatedSpy(workspace(), &Workspace::windowAdded);
QVERIFY(windowCreatedSpy.wait());
2022-04-23 19:51:16 +00:00
X11Window *window = windowCreatedSpy.last().first().value<X11Window *>();
QVERIFY(window);
QVERIFY(window->isDecorated());
QSignalSpy interactiveMoveResizeStartedSpy(window, &Window::interactiveMoveResizeStarted);
QSignalSpy interactiveMoveResizeSteppedSpy(window, &Window::interactiveMoveResizeStepped);
QSignalSpy interactiveMoveResizeFinishedSpy(window, &Window::interactiveMoveResizeFinished);
2022-04-23 19:51:16 +00:00
QSignalSpy frameGeometryChangedSpy(window, &Window::frameGeometryChanged);
// Begin resize.
QCOMPARE(workspace()->moveResizeWindow(), nullptr);
2022-04-23 19:51:16 +00:00
QVERIFY(!window->isInteractiveResize());
workspace()->slotWindowResize();
2022-04-23 19:51:16 +00:00
QCOMPARE(workspace()->moveResizeWindow(), window);
QCOMPARE(interactiveMoveResizeStartedSpy.count(), 1);
2022-04-23 19:51:16 +00:00
QVERIFY(window->isInteractiveResize());
const QPointF cursorPos = KWin::Cursors::self()->mouse()->pos();
2022-04-23 19:51:16 +00:00
window->keyPressEvent(Qt::Key_Right);
window->updateInteractiveMoveResize(KWin::Cursors::self()->mouse()->pos());
QCOMPARE(KWin::Cursors::self()->mouse()->pos(), cursorPos + QPoint(8, 0));
QCOMPARE(interactiveMoveResizeSteppedSpy.count(), 1);
QVERIFY(frameGeometryChangedSpy.wait());
// 100 + 8 pixels, rounded to resize increments. This will differ on scale
const qreal horizontalResizeInc = 3 / scale;
const qreal verticalResizeInc = 5 / scale;
const qreal expectedHorizontalResizeInc = std::floor(8. / horizontalResizeInc) * horizontalResizeInc;
const qreal expectedVerticalResizeInc = std::floor(8. / verticalResizeInc) * verticalResizeInc;
QCOMPARE(window->clientSize(), QSizeF(100, 200) / scale + QSizeF(expectedHorizontalResizeInc, 0));
2022-04-23 19:51:16 +00:00
window->keyPressEvent(Qt::Key_Down);
window->updateInteractiveMoveResize(KWin::Cursors::self()->mouse()->pos());
QCOMPARE(KWin::Cursors::self()->mouse()->pos(), cursorPos + QPoint(8, 8));
QCOMPARE(interactiveMoveResizeSteppedSpy.count(), 2);
QVERIFY(frameGeometryChangedSpy.wait());
QCOMPARE(window->clientSize(), QSizeF(100, 200) / scale + QSizeF(expectedHorizontalResizeInc, expectedVerticalResizeInc));
// Finish the resize operation.
QCOMPARE(interactiveMoveResizeFinishedSpy.count(), 0);
2022-04-23 19:51:16 +00:00
window->keyPressEvent(Qt::Key_Enter);
QCOMPARE(interactiveMoveResizeFinishedSpy.count(), 1);
QCOMPARE(workspace()->moveResizeWindow(), nullptr);
2022-04-23 19:51:16 +00:00
QVERIFY(!window->isInteractiveResize());
// Destroy the window.
QSignalSpy windowClosedSpy(window, &X11Window::closed);
xcb_unmap_window(c.get(), windowId);
xcb_destroy_window(c.get(), windowId);
xcb_flush(c.get());
QVERIFY(windowClosedSpy.wait());
c.reset();
}
void X11WindowTest::testTrimCaption_data()
{
QFETCH_GLOBAL(qreal, scale);
kwinApp()->setXwaylandScale(scale);
QTest::addColumn<QByteArray>("originalTitle");
QTest::addColumn<QByteArray>("expectedTitle");
QTest::newRow("simplified")
<< QByteArrayLiteral("Was tun, wenn Schüler Autismus haben?\342\200\250\342\200\250\342\200\250 Marlies Hübner - Mozilla Firefox")
<< QByteArrayLiteral("Was tun, wenn Schüler Autismus haben? Marlies Hübner - Mozilla Firefox");
QTest::newRow("with emojis")
<< QByteArrayLiteral("\bTesting non\302\255printable:\177, emoij:\360\237\230\203, non-characters:\357\277\276")
<< QByteArrayLiteral("Testing nonprintable:, emoij:\360\237\230\203, non-characters:");
}
void X11WindowTest::testTrimCaption()
{
QFETCH_GLOBAL(qreal, scale);
kwinApp()->setXwaylandScale(scale);
// this test verifies that caption is properly trimmed
// create an xcb window
Test::XcbConnectionPtr c = Test::createX11Connection();
QVERIFY(!xcb_connection_has_error(c.get()));
const QRect windowGeometry(0, 0, 100, 200);
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, 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 winInfo(c.get(), windowId, rootWindow(), NET::Properties(), NET::Properties2());
QFETCH(QByteArray, originalTitle);
winInfo.setName(originalTitle);
xcb_map_window(c.get(), windowId);
xcb_flush(c.get());
2022-04-23 19:51:16 +00:00
// we should get a window for it
QSignalSpy windowCreatedSpy(workspace(), &Workspace::windowAdded);
QVERIFY(windowCreatedSpy.wait());
2022-04-23 19:51:16 +00:00
X11Window *window = windowCreatedSpy.first().first().value<X11Window *>();
QVERIFY(window);
QCOMPARE(window->window(), windowId);
QFETCH(QByteArray, expectedTitle);
2022-04-23 19:51:16 +00:00
QCOMPARE(window->caption(), QString::fromUtf8(expectedTitle));
// and destroy the window again
xcb_unmap_window(c.get(), windowId);
xcb_flush(c.get());
QSignalSpy windowClosedSpy(window, &X11Window::closed);
QVERIFY(windowClosedSpy.wait());
xcb_destroy_window(c.get(), windowId);
c.reset();
}
void X11WindowTest::testFullscreenLayerWithActiveWaylandWindow()
{
QFETCH_GLOBAL(qreal, scale);
kwinApp()->setXwaylandScale(scale);
// this test verifies that an X11 fullscreen window does not stay in the active layer
// when a Wayland window is active, see BUG: 375759
QCOMPARE(workspace()->outputs().count(), 1);
// first create an X11 window
Test::XcbConnectionPtr c = Test::createX11Connection();
QVERIFY(!xcb_connection_has_error(c.get()));
const QRect windowGeometry(0, 0, 100, 200);
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, 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);
xcb_map_window(c.get(), windowId);
xcb_flush(c.get());
2022-04-23 19:51:16 +00:00
// we should get a window for it
QSignalSpy windowCreatedSpy(workspace(), &Workspace::windowAdded);
QVERIFY(windowCreatedSpy.wait());
2022-04-23 19:51:16 +00:00
X11Window *window = windowCreatedSpy.first().first().value<X11Window *>();
QVERIFY(window);
QCOMPARE(window->window(), windowId);
QVERIFY(!window->isFullScreen());
QVERIFY(window->isActive());
QCOMPARE(window->layer(), NormalLayer);
workspace()->slotWindowFullScreen();
2022-04-23 19:51:16 +00:00
QVERIFY(window->isFullScreen());
QCOMPARE(window->layer(), ActiveLayer);
QCOMPARE(workspace()->stackingOrder().last(), window);
// now let's open a Wayland window
std::unique_ptr<KWayland::Client::Surface> surface(Test::createSurface());
std::unique_ptr<Test::XdgToplevel> shellSurface(Test::createXdgToplevelSurface(surface.get()));
auto waylandWindow = Test::renderAndWaitForShown(surface.get(), QSize(100, 50), Qt::blue);
2022-04-23 19:51:16 +00:00
QVERIFY(waylandWindow);
QVERIFY(waylandWindow->isActive());
QCOMPARE(waylandWindow->layer(), NormalLayer);
QCOMPARE(workspace()->stackingOrder().last(), waylandWindow);
QCOMPARE(workspace()->stackingOrder().last(), waylandWindow);
QCOMPARE(window->layer(), NormalLayer);
// now activate fullscreen again
2022-04-23 19:51:16 +00:00
workspace()->activateWindow(window);
QTRY_VERIFY(window->isActive());
QCOMPARE(window->layer(), ActiveLayer);
QCOMPARE(workspace()->stackingOrder().last(), window);
QCOMPARE(workspace()->stackingOrder().last(), window);
// activate wayland window again
2022-04-23 19:51:16 +00:00
workspace()->activateWindow(waylandWindow);
QTRY_VERIFY(waylandWindow->isActive());
QCOMPARE(workspace()->stackingOrder().last(), waylandWindow);
QCOMPARE(workspace()->stackingOrder().last(), waylandWindow);
// back to x window
2022-04-23 19:51:16 +00:00
workspace()->activateWindow(window);
QTRY_VERIFY(window->isActive());
// remove fullscreen
2022-04-23 19:51:16 +00:00
QVERIFY(window->isFullScreen());
workspace()->slotWindowFullScreen();
2022-04-23 19:51:16 +00:00
QVERIFY(!window->isFullScreen());
// and fullscreen again
workspace()->slotWindowFullScreen();
2022-04-23 19:51:16 +00:00
QVERIFY(window->isFullScreen());
QCOMPARE(workspace()->stackingOrder().last(), window);
QCOMPARE(workspace()->stackingOrder().last(), window);
// activate wayland window again
2022-04-23 19:51:16 +00:00
workspace()->activateWindow(waylandWindow);
QTRY_VERIFY(waylandWindow->isActive());
QCOMPARE(workspace()->stackingOrder().last(), waylandWindow);
QCOMPARE(workspace()->stackingOrder().last(), waylandWindow);
// back to X11 window
2022-04-23 19:51:16 +00:00
workspace()->activateWindow(window);
QTRY_VERIFY(window->isActive());
// remove fullscreen
2022-04-23 19:51:16 +00:00
QVERIFY(window->isFullScreen());
workspace()->slotWindowFullScreen();
2022-04-23 19:51:16 +00:00
QVERIFY(!window->isFullScreen());
// and fullscreen through X API
NETWinInfo info(c.get(), windowId, kwinApp()->x11RootWindow(), NET::Properties(), NET::Properties2());
info.setState(NET::FullScreen, NET::FullScreen);
NETRootInfo rootInfo(c.get(), NET::Properties());
2022-04-23 19:51:16 +00:00
rootInfo.setActiveWindow(windowId, NET::FromApplication, XCB_CURRENT_TIME, XCB_WINDOW_NONE);
xcb_flush(c.get());
2022-04-23 19:51:16 +00:00
QTRY_VERIFY(window->isFullScreen());
QCOMPARE(workspace()->stackingOrder().last(), window);
QCOMPARE(workspace()->stackingOrder().last(), window);
// activate wayland window again
2022-04-23 19:51:16 +00:00
workspace()->activateWindow(waylandWindow);
QTRY_VERIFY(waylandWindow->isActive());
QCOMPARE(workspace()->stackingOrder().last(), waylandWindow);
QCOMPARE(workspace()->stackingOrder().last(), waylandWindow);
QCOMPARE(window->layer(), NormalLayer);
// close the window
shellSurface.reset();
surface.reset();
QVERIFY(Test::waitForWindowClosed(waylandWindow));
2022-04-23 19:51:16 +00:00
QTRY_VERIFY(window->isActive());
QCOMPARE(window->layer(), ActiveLayer);
// and destroy the window again
xcb_unmap_window(c.get(), windowId);
xcb_flush(c.get());
}
void X11WindowTest::testFocusInWithWaylandLastActiveWindow()
{
// this test verifies that Workspace::allowWindowActivation does not crash if last client was a Wayland client
QFETCH_GLOBAL(qreal, scale);
kwinApp()->setXwaylandScale(scale);
// create an X11 window
Test::XcbConnectionPtr c = Test::createX11Connection();
QVERIFY(!xcb_connection_has_error(c.get()));
const QRect windowGeometry(0, 0, 100, 200);
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, 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);
xcb_map_window(c.get(), windowId);
xcb_flush(c.get());
2022-04-23 19:51:16 +00:00
// we should get a window for it
QSignalSpy windowCreatedSpy(workspace(), &Workspace::windowAdded);
QVERIFY(windowCreatedSpy.wait());
2022-04-23 19:51:16 +00:00
X11Window *window = windowCreatedSpy.first().first().value<X11Window *>();
QVERIFY(window);
QCOMPARE(window->window(), windowId);
QVERIFY(window->isActive());
// create Wayland window
std::unique_ptr<KWayland::Client::Surface> surface(Test::createSurface());
std::unique_ptr<Test::XdgToplevel> shellSurface(Test::createXdgToplevelSurface(surface.get()));
auto waylandWindow = Test::renderAndWaitForShown(surface.get(), QSize(100, 50), Qt::blue);
2022-04-23 19:51:16 +00:00
QVERIFY(waylandWindow);
QVERIFY(waylandWindow->isActive());
// activate no window
workspace()->setActiveWindow(nullptr);
2022-04-23 19:51:16 +00:00
QVERIFY(!waylandWindow->isActive());
QVERIFY(!workspace()->activeWindow());
// and close Wayland window again
shellSurface.reset();
surface.reset();
QVERIFY(Test::waitForWindowClosed(waylandWindow));
2022-04-23 19:51:16 +00:00
// and try to activate the x11 window through X11 api
const auto cookie = xcb_set_input_focus_checked(c.get(), XCB_INPUT_FOCUS_NONE, windowId, XCB_CURRENT_TIME);
auto error = xcb_request_check(c.get(), cookie);
QVERIFY(!error);
2022-04-23 19:51:16 +00:00
// this accesses m_lastActiveWindow on trying to activate
QTRY_VERIFY(window->isActive());
// and destroy the window again
xcb_unmap_window(c.get(), windowId);
xcb_flush(c.get());
}
void X11WindowTest::testCaptionChanges()
{
QFETCH_GLOBAL(qreal, scale);
kwinApp()->setXwaylandScale(scale);
// verifies that caption is updated correctly when the X11 window updates it
// BUG: 383444
Test::XcbConnectionPtr c = Test::createX11Connection();
QVERIFY(!xcb_connection_has_error(c.get()));
const QRect windowGeometry(0, 0, 100, 200);
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, 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, kwinApp()->x11RootWindow(), NET::Properties(), NET::Properties2());
info.setName("foo");
xcb_map_window(c.get(), windowId);
xcb_flush(c.get());
2022-04-23 19:51:16 +00:00
// we should get a window for it
QSignalSpy windowCreatedSpy(workspace(), &Workspace::windowAdded);
QVERIFY(windowCreatedSpy.wait());
2022-04-23 19:51:16 +00:00
X11Window *window = windowCreatedSpy.first().first().value<X11Window *>();
QVERIFY(window);
QCOMPARE(window->window(), windowId);
QCOMPARE(window->caption(), QStringLiteral("foo"));
2022-04-23 19:51:16 +00:00
QSignalSpy captionChangedSpy(window, &X11Window::captionChanged);
info.setName("bar");
xcb_flush(c.get());
QVERIFY(captionChangedSpy.wait());
2022-04-23 19:51:16 +00:00
QCOMPARE(window->caption(), QStringLiteral("bar"));
// and destroy the window again
QSignalSpy windowClosedSpy(window, &X11Window::closed);
xcb_unmap_window(c.get(), windowId);
xcb_flush(c.get());
QVERIFY(windowClosedSpy.wait());
xcb_destroy_window(c.get(), windowId);
c.reset();
}
void X11WindowTest::testCaptionWmName()
{
QFETCH_GLOBAL(qreal, scale);
kwinApp()->setXwaylandScale(scale);
// this test verifies that a caption set through WM_NAME is read correctly
// open glxgears as that one only uses WM_NAME
QSignalSpy windowAddedSpy(workspace(), &Workspace::windowAdded);
QProcess glxgears;
glxgears.setProgram(QStringLiteral("glxgears"));
glxgears.start();
QVERIFY(glxgears.waitForStarted());
QVERIFY(windowAddedSpy.wait());
QCOMPARE(windowAddedSpy.count(), 1);
2023-03-21 17:47:58 +00:00
QCOMPARE(workspace()->windows().count(), 1);
Window *glxgearsWindow = workspace()->windows().first();
2022-04-23 19:51:16 +00:00
QCOMPARE(glxgearsWindow->caption(), QStringLiteral("glxgears"));
glxgears.terminate();
QVERIFY(glxgears.waitForFinished());
}
void X11WindowTest::testFullscreenWindowGroups()
{
// this test creates an X11 window and puts it to full screen
// then a second window is created which is in the same window group
// BUG: 388310
QFETCH_GLOBAL(qreal, scale);
kwinApp()->setXwaylandScale(scale);
Test::XcbConnectionPtr c = Test::createX11Connection();
QVERIFY(!xcb_connection_has_error(c.get()));
const QRect windowGeometry(0, 0, 100, 200);
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, 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);
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());
2022-04-23 19:51:16 +00:00
X11Window *window = windowCreatedSpy.first().first().value<X11Window *>();
QVERIFY(window);
QCOMPARE(window->window(), windowId);
QCOMPARE(window->isActive(), true);
2022-04-23 19:51:16 +00:00
QCOMPARE(window->isFullScreen(), false);
QCOMPARE(window->layer(), NormalLayer);
workspace()->slotWindowFullScreen();
2022-04-23 19:51:16 +00:00
QCOMPARE(window->isFullScreen(), true);
QCOMPARE(window->layer(), ActiveLayer);
// now let's create a second window
windowCreatedSpy.clear();
xcb_window_t w2 = xcb_generate_id(c.get());
xcb_create_window(c.get(), XCB_COPY_FROM_PARENT, w2, 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 hints2;
memset(&hints2, 0, sizeof(hints2));
xcb_icccm_size_hints_set_position(&hints2, 1, windowGeometry.x(), windowGeometry.y());
xcb_icccm_size_hints_set_size(&hints2, 1, windowGeometry.width(), windowGeometry.height());
xcb_icccm_set_wm_normal_hints(c.get(), w2, &hints2);
xcb_change_property(c.get(), XCB_PROP_MODE_REPLACE, w2, atoms->wm_client_leader, XCB_ATOM_WINDOW, 32, 1, &windowId);
xcb_map_window(c.get(), w2);
xcb_flush(c.get());
QVERIFY(windowCreatedSpy.wait());
2022-04-23 19:51:16 +00:00
X11Window *window2 = windowCreatedSpy.first().first().value<X11Window *>();
QVERIFY(window2);
QVERIFY(window != window2);
QCOMPARE(window2->window(), w2);
QCOMPARE(window2->isActive(), true);
QCOMPARE(window2->group(), window->group());
// first window should be moved back to normal layer
QCOMPARE(window->isActive(), false);
QCOMPARE(window->isFullScreen(), true);
QCOMPARE(window->layer(), NormalLayer);
// activating the fullscreen window again, should move it to active layer
2022-04-23 19:51:16 +00:00
workspace()->activateWindow(window);
QTRY_COMPARE(window->layer(), ActiveLayer);
}
void X11WindowTest::testActivateFocusedWindow()
{
// The window manager may call XSetInputFocus() on a window that already has focus, in which
// case no FocusIn event will be generated and the window won't be marked as active. This test
// verifies that we handle that subtle case properly.
QFETCH_GLOBAL(qreal, scale);
kwinApp()->setXwaylandScale(scale);
Test::XcbConnectionPtr connection = Test::createX11Connection();
QVERIFY(!xcb_connection_has_error(connection.get()));
QSignalSpy windowCreatedSpy(workspace(), &Workspace::windowAdded);
const QRect windowGeometry(0, 0, 100, 200);
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());
// Create the first test window.
const xcb_window_t windowId1 = xcb_generate_id(connection.get());
xcb_create_window(connection.get(), XCB_COPY_FROM_PARENT, windowId1, rootWindow(),
windowGeometry.x(), windowGeometry.y(),
windowGeometry.width(), windowGeometry.height(),
0, XCB_WINDOW_CLASS_INPUT_OUTPUT, XCB_COPY_FROM_PARENT, 0, nullptr);
xcb_icccm_set_wm_normal_hints(connection.get(), windowId1, &hints);
xcb_change_property(connection.get(), XCB_PROP_MODE_REPLACE, windowId1,
2022-04-23 19:51:16 +00:00
atoms->wm_client_leader, XCB_ATOM_WINDOW, 32, 1, &windowId1);
xcb_map_window(connection.get(), windowId1);
xcb_flush(connection.get());
QVERIFY(windowCreatedSpy.wait());
2022-04-23 19:51:16 +00:00
X11Window *window1 = windowCreatedSpy.first().first().value<X11Window *>();
QVERIFY(window1);
QCOMPARE(window1->window(), windowId1);
QCOMPARE(window1->isActive(), true);
// Create the second test window.
const xcb_window_t windowId2 = xcb_generate_id(connection.get());
xcb_create_window(connection.get(), XCB_COPY_FROM_PARENT, windowId2, rootWindow(),
windowGeometry.x(), windowGeometry.y(),
windowGeometry.width(), windowGeometry.height(),
0, XCB_WINDOW_CLASS_INPUT_OUTPUT, XCB_COPY_FROM_PARENT, 0, nullptr);
xcb_icccm_set_wm_normal_hints(connection.get(), windowId2, &hints);
xcb_change_property(connection.get(), XCB_PROP_MODE_REPLACE, windowId2,
2022-04-23 19:51:16 +00:00
atoms->wm_client_leader, XCB_ATOM_WINDOW, 32, 1, &windowId2);
xcb_map_window(connection.get(), windowId2);
xcb_flush(connection.get());
QVERIFY(windowCreatedSpy.wait());
2022-04-23 19:51:16 +00:00
X11Window *window2 = windowCreatedSpy.last().first().value<X11Window *>();
QVERIFY(window2);
QCOMPARE(window2->window(), windowId2);
QCOMPARE(window2->isActive(), true);
// When the second test window is destroyed, the window manager will attempt to activate the
2022-04-23 19:51:16 +00:00
// next window in the focus chain, which is the first window.
xcb_set_input_focus(connection.get(), XCB_INPUT_FOCUS_POINTER_ROOT, windowId1, XCB_CURRENT_TIME);
xcb_destroy_window(connection.get(), windowId2);
xcb_flush(connection.get());
QVERIFY(Test::waitForWindowClosed(window2));
2022-04-23 19:51:16 +00:00
QVERIFY(window1->isActive());
// Destroy the first test window.
xcb_destroy_window(connection.get(), windowId1);
xcb_flush(connection.get());
QVERIFY(Test::waitForWindowClosed(window1));
}
void X11WindowTest::testReentrantMoveResize()
{
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
// This test verifies that calling moveResize() from a slot connected directly
// to the frameGeometryChanged() signal won't cause an infinite recursion.
QFETCH_GLOBAL(qreal, scale);
kwinApp()->setXwaylandScale(scale);
// Create a test window.
Test::XcbConnectionPtr c = Test::createX11Connection();
QVERIFY(!xcb_connection_has_error(c.get()));
const QRect windowGeometry(0, 0, 100, 200);
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, 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);
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());
2022-04-23 19:51:16 +00:00
X11Window *window = windowCreatedSpy.first().first().value<X11Window *>();
QVERIFY(window);
QCOMPARE(window->pos(), QPoint(0, 0));
2022-04-23 19:51:16 +00:00
// Let's pretend that there is a script that really wants the window to be at (100, 100).
connect(window, &Window::frameGeometryChanged, this, [window]() {
window->moveResize(QRectF(QPointF(100, 100), window->size()));
});
// Trigger the lambda above.
2022-04-23 19:51:16 +00:00
window->move(QPoint(40, 50));
2022-04-23 19:51:16 +00:00
// Eventually, the window will end up at (100, 100).
QCOMPARE(window->pos(), QPoint(100, 100));
// Destroy the test window.
xcb_destroy_window(c.get(), windowId);
xcb_flush(c.get());
QVERIFY(Test::waitForWindowClosed(window));
}
WAYLANDTEST_MAIN(X11WindowTest)
#include "x11_window_test.moc"